# The VFPU (vector floating-point unit) Sources: the PSP VFPU documentation (vfpu-docs, GPL-3.0: **facts only**, nothing transcribed, its pseudo-C included), its reference outputs measured on PSP-1000 and PSP-3000 units (GPL-3.0 data: facts), YAPSPD 4.5 and 4.9 (DOC), pspautotests `tests/cpu/vfpu/` (TEST ROM: 33 tests with outputs recorded on a PSP), and ghidra-allegrex's VFPU Sleigh (tier 5, encodings only). ## What it is - **128 registers of 32 bits**, viewed as 8 matrices of 4x4 (vfpu-docs, "Register set"). An operand names a single (S), a row or column vector of 2, 3 or 4 elements (R/C), or a 2x2, 3x3 or 4x4 matrix, normal or transposed (M/E). Vectors never cross matrices; pairs and trios have 128 addressing patterns, quads 64; 2x2 and 3x3 matrices 64, 4x4 only 16. - **Control registers 128-143:** PFXS, PFXT, PFXD (the prefix registers), CC (condition bits), INF4, REV (read only), RCX0-RCX7 (the pseudo-random generator's state) (vfpu-docs; YAPSPD 4.5.2). - **269 instruction forms** (counted from vfpu-docs' headings): loads and stores (LV.S, LV.Q, LVL.Q, LVR.Q, SV.S, SV.Q, SVL.Q, SVR.Q), arithmetic per lane, dot products, cross products, quaternion multiply, matrix multiply and transforms (VMMUL, VTFMn, VHTFMn), transcendentals (VSIN, VCOS, VASIN, VEXP2, VLOG2, VRCP, VRSQ, VSQRT and their negated forms), conversions (float, int, half, packed colour formats 4444/5551/5650), compares and conditional moves on CC, random numbers, constants (VCST), branches on CC (BVF, BVT and likely forms, in COP2), moves to and from the CPU (MFV/MTV, MFVC/MTVC), VNOP, VFLUSH, VSYNC. - **Prefixes.** VPFXS and VPFXT rewrite the next instruction's source operands per lane (swizzle, absolute value, negation, or one of the constants 0, 1, 2, 3, 1/2, 1/3, 1/4, 1/6 and their negatives); VPFXD saturates (0..1 or -1..1) or masks each output lane. A prefix is state held until consumed. Which instructions honour which prefixes is measured (`reference-outputs/prefix_compat.txt`, MEASURED by vfpu-docs' author), and pspautotests probes the corners: `prefix_consume`, `prefix_branch` (a prefix across a branch and its delay slot), `prefix_lanes` (prefix fields for lanes beyond the vector's size), `prefix_load`, `prefix_sat`, `prefix_unpack`, `prefix_ctrl`, `prefixes`. - **Number format.** IEEE-754 single precision, rounding fixed to nearest, denormals flushed to zero on input and output (vfpu-docs, "Floating point format"; see fpu.md C4 for whether this also holds for CP1). `signed_zero`, `nan_gen`, `specials`, `minmax_zero`, `minmax_tie` decide the edges. - **Approximate operations.** The transcendentals and reciprocals are not correctly rounded: for VSIN "the lowest 3 mantissa bits seem to be innacurate ... absolute error is smaller than 4.8e-07" (vfpu-docs, `vsin.s`). A specification that matches hardware therefore needs **the hardware's exact bit patterns**, not a libm call. pspautotests' `cpu/vfpu/exact` (added 2026-09-23: "bit patterns of the VFPU's rcp, rsq, sqrt, sin/cos") is the judge; how the hardware computes them is unknown to us (U20). This is the hardest part of the core and the one most likely to stay FITTED. - **Register overlap.** VMMUL, VTFMn, VHTFMn, VQMUL and VCRSP give wrong results when the output overlaps an input, because they write partial results (decomposed into dot products); a second group allows only identical overlap (vfpu-docs, "Register hazards"; `reference-outputs/reg_compat.txt`; pspautotests `overlap`, `overlap_vcrsp`). The specification models the decomposition, so overlap gives the hardware's wrong answer rather than a raised error. - **Hazards without interlocks.** MFVC and VMFVC read CC one cycle late after VCMP: "you will need to interleave at least one VFPU instruction" (vfpu-docs, `mfvc`; pspautotests `vbranch_hazard`). This is a visible pipeline effect the timing-as-data model must carry as a rule, not as a cost. - **Errata (DOC: vfpu-docs "Known VFPU bugs/errata"):** - VHTFM2.P and VHTFM3.T write the wrong lanes when rd >= 64, on every model, deterministically. - LVL.Q and LVR.Q on the **PSP-1000** write a stale coprocessor-bus value into the CP1 register whose number is the low 5 bits of the VFPU destination (fixed in PSP-2000 and later). A cross-unit bug: CP1 is corrupted by a COP2 load. - **Timing:** single issue, pipelined; most operations throughput 1; latencies per instruction in `reference-outputs/inst_cycles.txt` (MEASURED, PSP-3000), for example VSIN latency 7 (vfpu-docs). Prefix instructions cost one cycle and add no latency. ## Recommendation: the VFPU is part of the core (decision A2) **Recommend `allegrex_python.vfpu`, a module of this core, switched on per instance** (`Allegrex(vfpu=True)` for the main CPU, `vfpu=False` for the Media Engine), not its own repository. Reasons, each from the evidence above: 1. **It is in the CPU's decoder.** Its instructions occupy primary opcodes 0x18-0x1B, 0x32, 0x34-0x37, 0x3A and 0x3C-0x3F as well as COP2 (0x12) (vfpu-docs encodings; Sleigh). A separate core would need the CPU to hand it most of the opcode space. 2. **It uses the CPU's load/store unit and data cache.** LV.Q/SV.Q move 128 bits through the CPU's memory path; their timing is in the CPU's memory table (`mem_cycles.txt`). 3. **It branches the CPU.** BVT/BVF test CC in the CPU's branch unit, with delay slots (`delayslot/branch.expected` has BVT/BVF rows). 4. **Its prefixes interact with the CPU's control flow** (`prefix_branch`). 5. **A documented bug crosses into CP1** (LVL.Q/LVR.Q on PSP-1000), reproducible only if CP1 and the VFPU are in one model. 6. **No second user exists.** The chip rule extracts a non-CPU chip when a second family board needs it; the VFPU exists only in the PSP's main Allegrex (and in the PS Vita's PSP mode, which is the same core). The ME's copy has none (Copetti). The r3000a-python precedent agrees: its GTE is `r3000a_python.gte`, a module of the core, for the same reasons (decision 1 of that brief). What stays open inside the recommendation: whether the VFPU's state (128 registers, 16 control registers, prefix state) is one `VfpuState` record inside the core's `ChipState` (recommended, so a state round-trips whole), and whether the ME instance really lacks the VFPU or only lacks its use (U11: a test on the ME decides; none is held).