# CP1: the floating-point unit ## What it is (DOC unless marked) - 32 single-precision registers $f0-$f31 (YAPSPD 4.4.1; Copetti: "thirty-two 32-bit registers and an independent 8-stage pipeline" (the pipeline figure is his, unsourced: HYPOTHESIS). - **Single precision only:** no .d or .ps formats, no 64-bit FPU registers (vfpu-docs: "Lack of 64 bit FPU support (only single float support)"). The instruction list is ABS, ADD, SUB, MUL, DIV, SQRT, MOV, NEG, CVT.S.W, CVT.W.S, ROUND/TRUNC/CEIL/FLOOR.W.S, the 16 C.cond.S compares, BC1F/BC1T/BC1FL/BC1TL, LWC1/SWC1, MFC1/MTC1/CFC1/CTC1 (ghidra-allegrex `allegrexFloat.sinc`, tier 5; to be confirmed against the tests, U18). - Control registers: FIR (0), FCCR (25), FEXR (26), FENR (28), FCSR (31) and FCR1-30 otherwise unused (YAPSPD 4.4.2). MIPS32 defines FCCR/FEXR/FENR as views of FCSR; whether the Allegrex implements those views is tested by `cpu/fpu/fcr` (TEST ROM). - One condition bit (no FCC1-7) as far as the instruction list shows (U18). ## What the tests decide (TEST ROM, pspautotests `tests/cpu/fpu/`, recorded on a PSP) | Test | Lines of expected output | Decides | | --- | ---: | --- | | `fpu` | many (62,800 bytes) | results of every arithmetic op on a value grid | | `denormal` | 15,218 bytes | denormal inputs and outputs: flushed or kept | | `rounding`, `roundmode` | 7,306 / 20,376 bytes | the rounding of ROUND/TRUNC/CEIL/FLOOR and **whether FCSR's RM field changes arithmetic** | | `fpu_nan` | 426 bytes | the default NaN and NaN propagation | | `fcr` | 2,122 bytes | FIR value, writable FCSR bits, the FCCR/FEXR/FENR views | | `fpu_branch`, `fpu_branch_hazard` | | BC1x after C.cond: how many instructions before the bit is visible | The VFPU documentation says of floating point in general that rounding is "hardwired to round to nearest" and denormals are flushed to zero. That paragraph sits in the VFPU's chapter and says "the FPU"; whether it describes CP1, the VFPU or both is a contradiction to settle by `roundmode` and `denormal` (C4). The specification takes nothing from that paragraph for CP1 until those tests are read. ## Exceptions FCSR's enable bits and the Unimplemented Operation exception: whether the Allegrex traps at all on FPU exceptions is unknown (U19). The kernel's FPU exception handler exists (YAPSPD 4.4.2 names `interruptman` as a user of FCR6...), which suggests some trap path. ## Modelling (for the specification) Python floats are doubles. Single-precision arithmetic is done exactly by: unpack to integers, operate, round once to binary32 by hand (or via `struct.pack('