# CP1: the floating-point unit Sources: UM chapters 7, 8 and 17 (tier 2); n64brew: COP1 (tier 3, facts only); nemu64-test `cop1` (88 tests) and `timing` (COP1 timing), MIT, tier 3; krom's `CP1` tests (Unlicense, tier 3, verdicts on screen with hardware photos beside some). ## Model - 32 registers of 64 bits with Status.FR=1 ("full mode"); with FR=0, 16 even registers hold doubles and odd numbers address the upper halves (the R4000 rule). FCR0 (0x0B00 on retail units, n64brew) and FCR31 (FCSR: rounding mode, flags, enables, cause, the condition bit C, FS "flush denormals to zero"). - Formats S, D (IEEE 754), W, L (integers); conversions between them (UM Table 7-14 lists which exist: CVT.S.fmt from D/W/L, CVT.D from S/W/L, CVT.W and CVT.L from S/D, ROUND, TRUNC, CEIL, FLOOR to W and L). - "Fully conforms" to IEEE 754-1985 **with system software** (UM p.47): the hardware raises the **Unimplemented Operation** exception (FCSR cause bit E, which cannot be masked) for cases it leaves to software. n64brew: COP1 > Special Cases lists them from hardware tests: qNaN inputs, subnormal inputs, sNaN conversions to integers, out-of-range conversions, and subnormal results unless FS=1 with underflow and inexact disabled. These rules decide what a game sees, because libultra's handler is in the game: the core models the hardware's exception, never IEEE results where the hardware traps. Tier 3; nemu64-test `cop1` is the judge. - Python floats are IEEE doubles: S arithmetic needs explicit rounding to single precision (`struct` round-trip or a hand rounding function), and the rounding mode (FCSR RM: nearest, zero, +inf, -inf) needs hand-written rounding for all four, since Python only rounds to nearest. This is the FPU's main build cost (U10). - Half mode with odd registers: n64brew: COP1 > Full Mode vs Half Mode describes what each instruction class does (tier 3). ## Timing (UM Table 7-14, p.233) Pipeline cycles: ADD/SUB 3 (S and D), MUL 5 (S) / 8 (D), DIV and SQRT 29 (S) / 58 (D), ABS/MOV/NEG 1, ROUND/TRUNC/CEIL/FLOOR 5, CVT.S.D 2, CVT.S from W/L 5, CVT.D.S 1, CVT.D from W/L 5, CVT.W/L 5, C.cond 1. "If the result ... is needed by the subsequent instruction, one additional pipeline clock is required"; trivial cases (an input whose result is obvious) "take two pipeline clocks" (footnote 2). nemu64-test's COP1 timing test says the same in its comment ("If a trivial special case is detected ... 2 cycles"), and "it is unclear how slow exception throwing operations are" (U11). ## The multiplication bug Early steppings give wrong results for some FP multiplies with special operands (start-here.md item 4). It is a property of a revision (PRId 0x0B10 boards), so it would be a machine-row switch, off by default, with no judge we can run (U9).