# The floating-point and bit-string instructions Keys as in [start-here.md](start-here.md). ## Floating point Eight instructions in format VII, opcode 111110, sub-op in bits 26-31 of the second halfword (DOC: ARCH appendix C (d); STS "Floating-Point"): | Sub-op | Mnemonic | Clocks (ARCH table 5-11) | | --- | --- | --- | | 000000 | CMPF.S | 7-10 | | 000010 | CVT.WS (word to float) | 5-16 | | 000011 | CVT.SW (float to word, rounded) | 9-14 | | 000100 | ADDF.S | 9-28 | | 000101 | SUBF.S | 12-28 | | 000110 | MULF.S | 8-30 | | 000111 | DIVF.S | 44 | | 001011 | TRNC.SW (float to word, toward zero) | 8-14 (ARCH) / 9-14 (STS): C3 | - **Operands and results live in the general registers** (32-bit IEEE 754 single). - **What the TKCW fixes** (DOC: ARCH 2.2.6): FIT, FZT, FVT set (invalid, zero-divide and overflow trap), FUT, FPT clear (underflow and precision never trap), RDI clear, RD = 00 (round to nearest). So the V810 has one rounding mode and three trapping conditions. - **Reserved operands** (FRO, FF60h): NaNs, infinities ("indefinites") and non-zero denormals are rejected as inputs (DOC: STS "Data Types", "Floating-Point"; ARCH 3.1 defines the data type). FRO is the highest-priority condition; only the highest-priority condition's flag is set and its exception raised (DOC: STS). - **Flags:** Z, S and CY from the result (STS: CY and S copy the result's sign bit; OV cleared); the sticky FPU flags FRO, FIV, FZD, FOV, FUD, FPR in PSW are set and never cleared by the instruction (DOC: STS; ARCH per-instruction pages to confirm). - **Underflow** gives zero and sets FUD; **precision loss** sets FPR; neither traps (DOC: ARCH table 6-1 note 5; STS). - **What nobody has documented:** the result written on overflow (STS's editor's note says the result appears to be processed then the trap raised "when writing the exponent"; U9); **which operand values take how many clocks** inside each range (STS: "research is needed"; U10). Without a timing source the core charges a FITTED value per instruction, marked so. **Arithmetic exactness.** Computing in a host double and narrowing with `struct` rounds twice; for single-precision add, subtract, multiply and divide a double has enough bits that the double rounding is harmless (a known IEEE result, to be checked by the rung 0 tests, not assumed), but the V810's own rules (reserved operands rejected, underflow to zero instead of a denormal, no infinities produced) still need explicit code around it. Proposed: a small hand rounding function on integers (sign, exponent, significand), so the spec reads as the hardware's rules rather than the host's; vr4300-python docs/fpu.md weighs the same choice. CVT/TRNC range checks (FIV when the value does not fit a signed word) come from STS. ## Bit strings Format II, opcode 011111, sub-op in the low five bits (DOC: ARCH appendix C (c)): | Sub-op | Instruction | What | | --- | --- | --- | | 00000-00011 | SCH0BSU, SCH0BSD, SCH1BSU, SCH1BSD | search upward/downward for the first 0 or 1 | | 01000-01111 | ORBSU, ANDBSU, XORBSU, MOVBSU, ORNBSU, ANDNBSU, XORNBSU, NOTBSU | dst = dst op src (or op NOT src), upward | - **Registers** (DOC: ARCH 2.1; STS "Bit Strings"): r30 source word address (bits 1-0 cleared first), r29 destination word address (or, for searches, the count of bits skipped), r28 length in bits (unsigned 32-bit; 0 is valid), r27 source bit offset and r26 destination bit offset (bits 31-5 cleared first). - **Interruptible and resumable:** the registers hold the resume word address, offset and remaining length when an interrupt aborts the instruction, and the restore PC is the instruction itself (DOC: ARCH 2.1, table 6-2). The spec therefore steps a bit-string instruction word by word and lets the board's interrupt check run between steps; **at which step boundaries an interrupt is taken** is U11. - **Search results:** the Z flag reports "not found"; r29 counts the skipped bits; the address and offset registers point at the bit found (DOC: ARCH 5.3, the SCH pages, to transcribe as facts in rung 0). - **Address wrap:** a string running past bit 31 of FFFFFFFCh or below bit 0 of 0 wraps around the address space (DOC: STS "Overview"). - **Timing:** ARCH tables 5-12 (searches) and 5-13/5-14 (transfers, by "TYPE1-TYPE7" boundary condition and word count, separately for 32- and 16-bit buses). Table 5-13's TYPE4 16-bit Nth-word entry reads "6N + 36" where the neighbouring rows have 12N: a likely typo (C4). Table 5-13's caption says "without cache hit" where 5-11 and 5-12 say "with cache hit" (C5). - **Which bus accesses a transfer makes** (read source word, read destination word, write destination word, in which order, and whether a word left unchanged is still written) is not in the manual (U12). The Virtual Boy's VIP sees every access, so this matters to the board; a hardware test program is the only judge (see validation.md, "probes"). The VB community reports Mednafen's bit-string results differing from hardware on some cases (a Planet Virtual Boy forum thread found by search; **not read, not pinned**: to locate and cite before relying on it).