Expand description
The VR4300 integer ALU as pure functions (T-11-002).
Kept free of pipeline and register-file state on purpose: every rule here is
a property of the arithmetic, so it can be tested exhaustively without
constructing a machine. The pipeline calls these from EX.
§The two rules that dominate MIPS III
32-bit results are sign-extended into the 64-bit register. Every *W-class
operation produces a 32-bit value that is then sign-extended to 64 bits before
it reaches the register file. Skipping this is the single most common source
of MIPS III emulator bugs, because it is invisible until a program compares or
branches on the upper half.
The documented errata are reproduced, not corrected. SRA/SRAV and the
MULT/DIV sign-extension bugs are real hardware behavior that software can
observe and depend on. Implementing them “correctly” per the manual is the bug
— see sra and mult. Each is pinned by a test that fails if it is
“fixed”, so the intent survives a well-meaning future reader.
Structs§
- HiLo
- The
HI/LOregister pair, written by every multiply and divide.
Enums§
- MulDiv
- The multiply/divide family, for cost lookup.
Constants§
- MFHI_
MFLO_ HAZARD_ INSTRUCTIONS - How many instructions after
MFHI/MFLOmust not writeHI/LO.
Functions§
- add
ADD— 32-bit signed add, traps on overflow.- addu
ADDU— 32-bit add, no trap. TheUmeans “unchecked”, not “unsigned”: the result is still sign-extended as a signed 32-bit value.- and
AND— bitwise and, full 64-bit.- dadd
DADD— 64-bit signed add, traps on overflow.- daddu
DADDU— 64-bit add, no trap.- ddiv
DDIV— 64-bit signed divide.- ddivu
DDIVU— 64-bit unsigned divide.- div
DIV— 32-bit signed divide. Reproduces the VR4300 sign-extension erratum.- divu
DIVU— 32-bit unsigned divide. No erratum applies.- dmult
DMULT— 64-bit signed multiply, full 128-bit result.- dmultu
DMULTU— 64-bit unsigned multiply, full 128-bit result.- dsll
DSLL— 64-bit shift left logical.- dsra
DSRA— 64-bit shift right arithmetic.sais the effective0..64amount; seedsllon theDSRA/DSRA32encoding split.- dsrl
DSRL— 64-bit shift right logical.sais the effective0..64amount; seedsllon theDSRL/DSRL32encoding split.- dsub
DSUB— 64-bit signed subtract, traps on overflow.- dsubu
DSUBU— 64-bit subtract, no trap.- lui
LUI— load upper immediate.- muldiv_
stall_ cycles - Pipeline stall in
PCycles for a multiply or divide (UM Table 3-12). - mult
MULT— 32-bit signed multiply. Reproduces the VR4300 sign-extension erratum.- multu
MULTU— 32-bit unsigned multiply. Both operands are taken as their low 32 bits, zero-extended; no erratum applies.- nor
NOR— bitwise nor, full 64-bit. MIPS has noNOT;NOR rd, rs, $0is it.- or
OR— bitwise or, full 64-bit.- sext32
- Sign-extend a 32-bit result into the 64-bit register file.
- sll
SLL— 32-bit shift left logical, result sign-extended.- slt
SLT— set on less than, signed 64-bit comparison.- sltu
SLTU— set on less than, unsigned 64-bit comparison.- sra
SRA— 32-bit shift right arithmetic. Reproduces the VR4300 erratum.- srl
SRL— 32-bit shift right logical, result sign-extended.- sub
SUB— 32-bit signed subtract, traps on overflow.- subu
SUBU— 32-bit subtract, no trap.- xor
XOR— bitwise exclusive or, full 64-bit.