# COP1: the EE's single-precision FPU, which is not IEEE 754 Sources: ECUM ch. 8 (Sony EE Core User's Manual 6.0, pp. 155-166, DOC), ECISM's COP1 pages, TX79's C1 pipe chapter, and the judge, ps2autotests `cpu/ee_fpu/*` (ISC; outputs captured on a real PS2, TEST ROM). Play! (BSD-2-Clause) implements truncating add and multiply in `Source/ee/FpAddTruncate.cpp` and `FpMulTruncate.cpp`, which say they are "modified" from LLVM compiler-rt's `addsf3.c`/`mulsf3.c`: a detector of one reading, not evidence. TellowKrinkle's `PS2Float` repository has no licence: not read. ## The format 32-bit single precision, IEEE 754's layout (sign, 8-bit exponent with bias 127, 23-bit fraction with a hidden bit), but (ECUM §8.1.1): - **An exponent field of 255 is an ordinary number**, `(-1)^s x 2^(e-127) x 1.f` for `0 < e <= 255`; Emax is +128. There are **no infinities and no NaNs**. - **An exponent field of 0 is zero**, whatever the fraction: no denormals. Both signed zeros exist and follow IEEE 754's sign rules for add, subtract, multiply, min and max (ECUM Table 8-5). - So the largest magnitude, which the manual calls Fmax, is **7FFFFFFFh** (and FFFFFFFFh negative). ECUM Table 8-4 says division by zero gives "+Fmax or -Fmax" and Table 8-5 lists 7FFFFFFFh/FFFFFFFFh for the same cases: consistent once Fmax is read as the EE's own maximum, not IEEE's 7F7FFFFFh. ## Rounding Round toward zero only; FCR31 bits 1..0 are hard-wired to 01 (ECUM §8.7). The FPU does not keep guard, round and sticky bits, so the result "may differ from the IEEE 754 rounding to 0", "usually" only in the least significant bit, and for saturating cases in more bits (ECUM §8.7, §8.8). **The exact datapath is not documented** (U9): which bits are dropped before the add's alignment shift, how the multiply truncates its partial product. The specification states it as an integer algorithm on sign, exponent and significand, fitted to the judge: 1. ps2autotests `cpu/ee_fpu/arithmetic`, `muldiv`, `sqrt`, `convert`, `compare` (TEST ROM, all values printed as hex words); 2. where the tests do not reach, the reading Play! implements (OBSERVED, tier 5), marked FITTED until a console probe confirms it. ADDA/SUBA/MULA/MADD/MSUB/MADDA/MSUBA use a 32-bit accumulator ACC (ECUM §8.2). Whether MADD.S rounds the product before the add (two truncations) or once is **U10**; the tests' `muldiv` output decides. ## Flags and abnormal results FCR31 (ECUM §8.3.2, Figure 8-5): C (bit 23) for compares; cause flags I (17), D (16), O (15), U (14) for the last arithmetic instruction; sticky SI (6), SD (5), SO (4), SU (3) that stay set until software clears them. **No exception is ever taken**; the flags are the only report (ECUM §1.8, §8.8). FCR0 reads implementation 2Eh and a revision number (ECUM §8.3.1). Abnormal results (ECUM Table 8-4): | Case | Result | Flag | | --- | --- | --- | | x / 0, x != 0 | +-Fmax (sign of x xor sign of 0) | D | | 0 / 0 | +-Fmax | I | | sqrt(negative) | sqrt(\|x\|) | I | | exponent overflow | +-Fmax | O | | exponent underflow | +-0 | U | | CVT.W.S out of range | 7FFFFFFFh or 80000000h | see C1 | **C1:** for a float-to-integer conversion overflow, ECUM Table 8-4 says no flag is set, and Table 8-6 (the IEEE comparison table on the next page) says "I bit (SI bit) is set". Judge: ps2autotests `cpu/ee_fpu/convert` (it prints FCR31 after each case; to check when the test runs). ## Instructions Moves (LWC1, SWC1, MTC1, MFC1, MOV.S, CTC1, CFC1), conversions (CVT.S.W, CVT.W.S), arithmetic (ADD, SUB, MUL, DIV, ABS, NEG, SQRT, RSQRT, the accumulator forms, MAX, MIN), compares C.F, C.EQ, C.LT, C.LE, and BC1F/BC1T/BC1FL/BC1TL (ECUM Table 8-3). Only single precision and word fixed point exist; no doubles (ECUM §8.1). Latencies: 4 cycles for add, multiply, convert, compare and MADD (throughput 1), DIV.S and SQRT.S 8 (throughput 7), RSQRT.S 14 (13), MTC1/MFC1/LWC1 2 (ECUM §2.12). The C1 pipe has 8 stages and runs beside I0 (ECUM §1.3.3). ## How the specification and the Rust tiers do it - **x-python**: integer arithmetic on the three fields, one small function per operation with the rule as prose; no host floats anywhere. Readable and exact by construction. - **x-rust**: the same functions, transcribed. - **-fast**: host floats are tempting but wrong on every input that reaches exponent 255 or needs truncation; the exact path stays integer, with a fast path only where the test is cheap (both exponents in 1..254 and the operation's result provably the same as host round-toward-zero: not true in general for truncation without guard bits, so this needs a proof per operation or a lockstep run over all exponent pairs). Nothing here is a concession; a "use host IEEE" switch would be one (it changes results in games that overflow, which are many: PCSX2 exposes "EE FPU Clamping Mode" and "VU Clamping Mode" as user settings, pcsx2.net docs "Performance Issues", found by search 2026-11-26, OBSERVED). ## Unknowns U9 the truncating datapath of ADD/SUB/MUL; U10 MADD's rounding; U11 RSQRT's precision and its I/D flags for 0 and negative inputs (ECUM Table 8-5 gives the results, not the precision); U12 whether MAX/MIN compare 7FFFFFFFh-class values as ordinary numbers (they should, being ordinary; one test case).