# Execution architecture and performance strategy: the hardest wall in the family Phase 0, 2026-11-26. The PS2's companion to n64-python's and psx-python's `docs/execution-architecture.md` (`../n64-python`, `../psx-python`), which hold the cost model for synchronisation, the SH-2 evidence and the testing rules for every backend. This page applies them to the PS2 and says plainly where they stop being enough. It builds on [domains.md](domains.md). Tags as there: MEASURED (a sibling's recorded measurement, cited), DOC, OBSERVED, HYPOTHESIS (an estimate with its arithmetic shown). **Nothing here was measured on a PS2 core**; none exists. Every PS2 emulator we know of is a closed box (PCSX2 and DobieStation: GPL-3.0) except Play! (BSD-2-Clause), whose techniques are implementation choices, never evidence. ## The answer - **No target reaches real time for typical 3D games with exact interpreters alone.** The EE's need at typical rates is 17-33 desktop-equivalent host cycles per instruction (8.5 at its dual-issue peak); an exact EE interpreter with timing as data is estimated at 30-70, a cached one with memoized timing at 12-25. VU1 adds up to three more cores' worth, and the GS's fill can exceed a whole desktop CPU. These are HYPOTHESIS until ee-rust-fast measures them, and the order of magnitude is not in doubt: the PS2 does more work per second than every machine before it in this family put together. - **Desktop native**: plausible for light and medium games without recompilation, if the EE's cached interpreter and memoized pairing land near the low end of their estimate, VU1 has its own thread with a content-keyed block cache and exact flag liveness, and the GS back end runs on several threads. Heavy games need `recompile: native` (allowed on desktop) or the GPU back end, or both. - **Phone app** (iOS native: no JIT): **not real time** for typical 3D games, even with every exact technique (marginal at best for light ones); with named concessions (EE coarse timing, VU host floats, a GPU back end with per-mode concessions, idle skipping), some games may reach it. Android apps may JIT and have the same GPU path. The capability record says so. - **Phone browser**: **not real time**; `recompile: wasm` for the EE and VUs, WebGPU for the GS, worker threads (cross-origin isolation for shared memory) and concessions may make lighter games playable. Below real time is the honest default. - **Low-cost ARM handhelds** (about 0.2x a desktop core, psx-python domains.md): no. - **The Python specification** is for test programs and component slices only: 1/500 to 1/12,000 of real time for the EE, a frame in minutes (below). ## Components, backends and tiers | Component | Backends by tier | Sync points | Notes | | --- | --- | --- | --- | | **EE Core** (ee-python) | x-python/x-rust: interpreter with pairing, scoreboard, caches, WBB/UCAB. **-fast**: packed decode, pairing and latency tables, one deadline compare, deferred cycles flushed at each transaction. **Cached interpreter keyed by I-cache line**: exact by construction for cached code (a hit changes no LRF bit: ee-python cop0-tlb-caches.md); invalidated on refill, CACHE operations and TLB writes for mapped code. **Memoized block timing**: the pairing and static stalls of a block for its entry scoreboard state, precomputed. Native and wasm block compilation: turbo | every uncached/accelerated transaction (I/O registers, GS, VIF), DMA bus steals, SPRAM port conflicts, INT0/INT1 at pair boundaries | the wall (numbers below) | | **COP1** | integer arithmetic at every tier; a "host IEEE with clamping" path is a **concession** (it changes LSBs and abnormal results) | none | ee-python fpu.md | | **VU0** | macro: inline in the EE's thread as COP2. Micro: as VU1, but on A's thread (the EE waits on it) | COP2 interlocks; VCALLMS | small share in most games (HYPOTHESIS) | | **VU1** (vu-python, decision E6) | x-python/x-rust: cycle-level LIW interpreter. **-fast**: SIMD lanes (SSE/NEON, wasm SIMD128) with exact truncation and clamping in integer form; **block cache keyed by micro-memory content, start PC and entry pipeline state** (as n64-python keys RSP blocks), with the pipeline's stalls precomputed and **flag liveness** (MAC/status/clip flags computed only where a later instruction in the block, or the block's exit, can read them: exact by construction). Native/wasm compilation: turbo | MSCAL/MSCNT starts, E-bit end, XGKICK (to the GIF arbiter), VIF1 writes into the half of VU1 memory it is running from (a hazard to detect), EE accesses to VU1 memory | domain B's main load | | **VIF0/VIF1, GIF, DMAC** | transactions; UNPACK as table-driven loops in -fast | as domains.md | cheap | | **GS front end** | setup, coverage counts and busy time per primitive (analytic where exact), register state, CSR events, transfers' bookkeeping, PCRTC timing: on domain B's thread at every tier | GIF packets; CSR/SIGLBLID reads; FINISH/SIGNAL/LABEL; V-blank | exact only if the busy time does not depend on pixel results (gs.md U19; decision S3) | | **GS back end** | x-python/x-rust: the software rasteriser, the judge. -fast: SIMD spans, threads by screen tile in primitive order, with a **hazard map over local-memory pages** (pending writes / pending reads), so a texture read of a page with pending writes joins first (the GS's self-reference). turbo: **GPU compute** (Vulkan/Metal/WebGPU), integer arithmetic, local memory as a storage buffer with the exact swizzles, held to identical local memory at every join | joins only: local-to-host transfers, PCRTC scan-out of a buffer being drawn, self-referencing texture reads, CSR FINISH if data-dependent | owns local memory alone; all inputs arrive in the GIF stream, so no hazards against EE RAM | | **IOP** (r3000a-python) | as psx-python's R3000A: -fast interpreter, i-cache-keyed cached interpreter | SIF mailboxes and FIFOs; IOP DMA; IOP interrupts | its own thread (domain D) | | **SPU2** | inline in D, caught up at each access; final mix a producer | SPU2 registers, DMA ch. 4/7, IRQ | psx-python's rule | | **IPU** | functional decode; busy model in A; decode ahead on a producer thread if its time model needs no decoding (ipu.md) | IPU registers, DMA ch. 3/4 | FMV only | | **CDVD (HLE)** | events on D's thread; disc reads prefetched on an I/O thread | CDVD registers, DMA ch. 3, IRQ2 | host I/O touches no observable | ## Threads: unavoidable, and where The charter allows deterministic threads from `-fast` on, synchronised at declared channels. On the PS2 they are not an optimisation but a precondition: no single host core can run the EE, VU1 and the GS together. The plan: | Thread | Runs | Talks to A by | | --- | --- | --- | | A | EE Core, COP1, VU0, DMAC, INTC, timers, IPU front end, SIF EE side | (itself) | | B | VIF1, VU1, GIF arbiter, GS front end, PCRTC timing | DMA slices into VIF1/GIF FIFOs (A produces, B consumes); B's status read by A is a join; interrupts B raises are predicted events | | C1..Cn | GS back end tiles (or the GPU) | command log from B; joins | | D | IOP, IOP DMA, SIO2, SPU2 voices, CDVD front end | SIF mailboxes and FIFOs; INT_SBUS | | producers | audio mix to the host rate, IPU decode ahead, disc reads | joins at their consumers | **Synchronisation strategy (decision S2).** Conservative cross-thread handshakes cost 500-1,500 host cycles each (n64-python's cost model, HYPOTHESIS). The PS2's channels are mostly producer-consumer: - **B runs behind A** as the consumer of A's DMA slices; A's reads of B's state (VIF1_STAT, GIF_STAT, CSR) are joins that wait for B to reach A's time. Exact. It pays only if such reads are rare: games mostly wait for interrupts and V-blank, but some poll (to measure: "Measure first" item 3). - **D (IOP)** either behind A with joins on A's SIF reads, or ahead with a channel-read log and rollback (n64-python's X2 shape) if the IOP's polling of SIF flags makes joins too frequent. Both are exact; the lockstep decides which tier each belongs in. - **XGKICK and PATH3 arbitration** are inside B, so the GIF's input order is computed on one thread from B's own exact timing and A's DMA delivery times, which arrive with each slice as timestamps. That keeps the picture deterministic at any thread count. ## Numbers Desktop-equivalent host cycles per guest operation on one core: desktop 5.0e9 / R, phone app 4.0e9 / R, phone browser 2.4e9 / R (n64-python's and psx-python's ratios, HYPOTHESIS). | Component | Guest rate `R` (basis) | Desktop | Phone app | Browser | Likely cost (HYPOTHESIS) | Host load at that cost | | --- | --- | ---: | ---: | ---: | --- | --- | | EE, dual-issue peak | 589.8 M instr/s (2 x 294.912 MHz, DOC) | 8.5 | 6.8 | 4.1 | exact interpreter 30-70; cached + memoized 12-25 | far beyond one core | | EE, typical | 150-295 M instr/s (0.5-1.0 IPC, HYPOTHESIS; MAME's own charge 258 M in a delay loop, OBSERVED) | 17-33 | 14-27 | 8-16 | as above | cached: 1.8-7.4 G cycles/s = 0.4-1.5 desktop cores on **one** thread | | VU1 | 90-240 M LIW/s (30-80 % busy of 294.912 MHz, HYPOTHESIS) | 21-56 | 17-44 | 10-27 | exact with SIMD 25-60; block cache + flag liveness 8-20 | 0.7-4.8 G cycles/s with the cache = 0.15-1.0 desktop cores | | VU0 micro | 0-90 M LIW/s (0-30 %, HYPOTHESIS) | | | | as VU1 | on thread A, adds to the EE | | GS back end, typical | 100-600 M pixels/s (640 x 448, 4-10x overdraw at 60 Hz plus full-screen passes, HYPOTHESIS) | 8-50 | 7-40 | 4-24 | software, SIMD: 15-50 per pixel | 1.5-30 G cycles/s = 0.3-6 desktop cores | | GS back end, fill peak | 1.18 G textured / 2.36 G untextured pixels/s (GSUM ยง1.3 at 150 MHz; DOC) | 4.2 / 2.1 | 3.4 / 1.7 | 2.0 / 1.0 | 15-50 | 18-118 G cycles/s: **the GPU's case** | | GS front end | 1-10 M primitives/s (HYPOTHESIS; GSUM's ceiling is 75 M flat triangles/s) | 500-5,000 | | | 100-500 per primitive if analytic | 0.1-5 G cycles/s: thread B | | VIF/GIF/DMAC | 5-20 M qwords/s (geometry and textures, HYPOTHESIS; the bus ceiling is 147 M) | 250-1,000 | | | 10-30 per qword | 0.05-0.6 G | | IOP | 17-18 M instr/s (36.864 MHz at ~0.5 IPC; MAME 16.9 M at its 33.87 MHz, OBSERVED) | 280 | 220 | 135 | 25-60 (psx-python) | 0.4-1.1 G: thread D | | SPU2 | 2.3 M voice-samples/s (48 voices x 48 kHz, DOC) | 2,170 | 1,740 | 1,040 | 100-250 | 0.23-0.58 G: thread D | | IPU (FMV) | 33,600 macroblocks/s (ipu.md) | 149,000 | | | 5,000-20,000 | 0.17-0.67 G: producer | | Python spec, EE | 0.05-0.3 M instr/s (PyPy, HYPOTHESIS from vr4300-python 0.02-0.2 and sh2-python 0.1-0.2) | | | | | 1/500-1/12,000 of real time | **Without recompilation, by these estimates:** - **Desktop**: thread A at 0.4-1.5 cores' worth with the cached EE: fits for games near 0.5 IPC, not for those near 1.0. Thread B 0.2-2 cores (VU1 and the GS front end). The GS back end 0.3-6 cores in software: fits on an 8-core desktop for typical scenes, not at fill peaks. Full speed for light and medium games, HYPOTHESIS; heavy games below it. - **Phone app**: thread A alone is 0.45-1.8x a performance core's budget with the cached EE (150-295 M instructions/s x 12-25 cycles / 4.0e9), and 1.1-5.2x with the plain exact interpreter (x 30-70). Only the best case of every estimate fits, for a 0.5-IPC game; VU1 then needs the second performance core and the GS needs Metal compute. **Marginal at best for light games; not real time for typical 3D games without concessions.** - **Browser**: 8-16 cycles per EE instruction available: below any interpreter's cost. **Not real time**; with `recompile: wasm` (allowed: the page hands the browser WebAssembly) and WebGPU, lighter games are possible, HYPOTHESIS. ## Named concessions (off by default; each with a record, charter "Concessions") Proposed for ps2-rust-turbo, in the order they would be tried on weak targets: 1. **EE coarse timing**: a fixed cost per instruction, no pairing, cache or WBB timing. Changes when stores and DMA land relative to the EE. Most PS2 software tolerates it (PCSX2 exposes an EE cycle-rate setting, OBSERVED as a user setting); its recorded cost is the test-program pass list and the picture differences on the slice list. 2. **VU host floats**: SIMD host arithmetic with clamping instead of exact truncation. Changes LSBs and abnormal cases; geometry may jitter. 3. **Coarser A/B synchronisation**: B allowed to run a bounded quantum ahead without rollback. Can reorder GIF arbitration: picture risk, recorded per game. 4. **Inexact idle-loop skipping** (the JIT proposal's concession; the exact fast-forward, late-era L8, is turbo and comes first). 5. **GS GPU back end with named per-mode differences** where a device's driver cannot meet the per-pixel gate (bilinear precision, dithering, page-buffer staleness): each mode a named concession, the rest exact. 6. Enhancements (upscaling, texture filtering beyond the GS's) are concessions too; they are never on by Auto. ## GPU backend: unavoidable For the GS, a GPU back end is not optional on phones and browsers, nor on desktops at fill peaks (the table: up to 118 G cycles/s in software). It is turbo under the late-era method's L6: proven per pixel and per device, with `gpu_backend: verified | failed | absent` in the capability record. What makes the GS harder than the N64's RDP or the PS1's GPU: **self-reference** (textures read from the buffer being drawn, through page buffers whose staleness matters: gs.md), **format-dependent swizzles** (one 4 MB memory read and written in seven formats), and **draw order across primitives within a tile** (blending is order-dependent). The GPU back end bins primitives into tiles in order, runs each tile's primitives in order on one workgroup, keeps local memory in the GS's own layout, and inserts barriers at self-referencing reads. Our own back end, written from the specification (as n64-python's X4); no permissive GPU GS implementation is known to us to compare. ## Deterministic testing across backends As n64-python's document: each backend runs in lockstep with its fallback at block or event boundaries, single- and multi-threaded, with seeded faults aimed at it: - EE: a decoded line kept after CACHE IXIN; a block not dropped after TLBWI; the pairing table's Y stall left out of memoized timing; deferred cycles not flushed before a GS privileged-register write; an MMI lane order swapped in a SIMD path. - VU: a block reused after a VIF MPG changed one word; the entry pipeline state dropped from the key; a MAC flag treated as dead when FMAND reads it; truncation done as round-to-nearest in the SIMD path. - GS: a self-referencing texture read without a join; a tile split that reorders two blended primitives; a swizzle table off by one column; TEXFLUSH ignored. - Threads: a B status read answered before B reached A's time; a SIF flag write seen one IOP cycle early. ## Measure first (in this order) 1. ee-rust's instructions/s on `cpu/ee/alu` and an MMI-heavy test, and its profile split (pairing, scoreboard, fetch, handlers, decode), to compare with the SH-2's. 2. vu-rust's LIW/s on a captured VU1 microprogram slice, plain and with SIMD. 3. Channel rates per emulated second in a few game slices: A's reads of B's state, SIF polls on both sides, VIF1 FIFO back-pressure events. 4. The software GS's ns per pixel by mode on captured GIF streams. 5. Joins per frame for the GPU decision. ## Open decisions for Aubrey (each with my recommendation) - **S1. The capability record states `recompile: none` reaches real time on desktop for light and medium games only, and on no phone or browser target for typical 3D games.** *Recommend* yes: it is what the arithmetic says, and the charter asks for it plainly. - **S2. Threads per domain (A, B, C1..n, D, producers) from ps2-rust-fast on**, with B behind A and joins on A's reads, D behind or ahead by measurement. *Recommend* yes. - **S3. The GS front end's busy time must not depend on pixel results** unless a judge shows it does (gs.md U19). *Recommend* yes, marked HYPOTHESIS (psx P2, n64 X3). - **S4. A GPU back end for the GS in turbo**, our own, proven per pixel and per device. *Recommend* yes; it is the only way to the phone and the browser. - **S5. The six concessions above as the named set**, with "EE coarse timing" first. *Recommend* yes, as names and records to be filled when ps2-rust-turbo exists. - **S6. VU block cache with exact flag liveness in `-fast`** if the lockstep holds the per-cycle trace. *Recommend* yes: it is exact by construction and likely the largest single VU gain. - **S7. Recompilation (native, wasm) for the EE and VU1 is expected, not optional, for any weak target**: it still lives in turbo with the interpreter as fallback (charter), but the PS2 is the first board where the plan says so up front. *Recommend* recording it in the JIT proposal's family table as "**yes**, required on weak targets".