Encoding
These are format VII instructions: four bytes, the first halfword 111110 reg2(5) reg1(5), the second halfword subopcode(6) unused(10). The sub-opcode is bits 15 to 10 of the second halfword;
0x01 and 0x0D to 0x3F are undefined (the core as read raises the invalid-opcode exception). In the table the second halfword is therefore sub << 10: the binutils entry two(0xf800, 0x1000) for ADDF.S has sub-opcode 0x04.
Floating-point values are IEEE 754 single precision held in a general register.
Floating-point
| Mnemonic | Operands | Sub-opcode | Operation | Flags | Exception flags it can set |
|---|---|---|---|---|---|
CMPF.S | r1,r2 | 0x00 | Compare: the flags of r2 - r1; nothing is stored | Z S OV CY | FRO |
CVT.WS | r1,r2 | 0x02 | r2 = r1 (a signed integer) as a float | Z S OV CY | FPR |
CVT.SW | r1,r2 | 0x03 | r2 = r1 (a float) as a signed integer, rounded | Z S OV | FRO FIV FPR |
ADDF.S | r1,r2 | 0x04 | r2 = r2 + r1 | Z S OV CY | FRO FOV FUD FPR |
SUBF.S | r1,r2 | 0x05 | r2 = r2 - r1 | Z S OV CY | FRO FOV FUD FPR |
MULF.S | r1,r2 | 0x06 | r2 = r2 * r1 | Z S OV CY | FRO FOV FUD FPR |
DIVF.S | r1,r2 | 0x07 | r2 = r2 / r1 | Z S OV CY | FRO FIV FZD FOV FUD FPR |
TRNC.SW | r1,r2 | 0x0B | r2 = r1 (a float) as a signed integer, truncated toward zero | Z S OV | FRO FIV FPR |
The flag letters and the exception-flag column are from the Flag box of each instruction in the NEC V810 Family 32-Bit Microprocessor Architecture User’s Manual (U10082EJ1V0UM00, section 5.3); the Mednafen/Beetle core agrees on the instruction names, sub-opcodes and the flags of CVT.SW and TRNC.SW.
In the manual: OV is cleared (0) by every floating-point instruction; S and Z come from the result; CY is set to the same value as S by CMPF.S, CVT.WS, ADDF.S, SUBF.S, MULF.S and DIVF.S but is not affected by CVT.SW and TRNC.SW. The exception flags in the last column are set only when the condition occurs and are otherwise left as they were (their PSW bits are on the registers page). The reserved-operand exception (a denormal number, a NaN or an indefinite operand), the invalid-operation exception (an integer result out of range), zero division and overflow trap through the floating-point vector 0xFFFFFF60; the manual says a precision-degradation flag (FPR) is set without a trap, and that on the V810 family underflow (FUD) and precision degradation (FPR) exceptions do not occur (Table 6-1 notes; TKCW has the underflow and precision traps fixed to 0).
The rounding is “toward nearest” (TKCW RD = 00, fixed on the V810 family); TRNC.SW truncates toward zero.
Clock cycles
NEC Table 5-11, “the minimum execute clock cycles with cache hit, no hazard, and no wait”; the range is the manual’s, the count depends on the operands.
| Instruction | Clocks |
|---|---|
CVT.WS | 5 to 16 |
CVT.SW | 9 to 14 |
TRNC.SW | 8 to 14 |
CMPF.S | 7 to 10 |
ADDF.S | 9 to 28 |
SUBF.S | 12 to 28 |
MULF.S | 8 to 30 |
DIVF.S | 44 |
The viewer shows the lower figure and says the count depends on the operands. The integer and other instructions are in the instruction table notes.
Extended integer instructions
The Mednafen core handles these four only when it emulates the Virtual Boy; they are in the Virtual Boy documentation, and the decoder treats them as ordinary instructions. XB and XH have one register operand (the reg1 field is not used).
| Mnemonic | Operands | Sub-opcode | Operation | Flags |
|---|---|---|---|---|
XB | r2 | 0x08 | Exchange the two low bytes of r2 | not stated |
XH | r2 | 0x09 | Exchange the two halfwords of r2 | not stated |
REV | r1,r2 | 0x0A | r2 = r1 with its 32 bits in reverse order | not stated |
MPYHW | r1,r2 | 0x0C | r2 = r2 * r1 with both taken as signed 16-bit halves (a 32-bit product) | not stated |
Not described
See the status page: the flags and clock counts of the four extended instructions (the NEC manual does not contain them).