# Execution architecture and performance strategy Phase 0, 2026-11-26. This is the PlayStation's short companion to n64-python's `docs/execution-architecture.md` (`../n64-python`), which holds the full reasoning: the cost model for synchronisation, the SH-2 evidence, the testing rules for every backend and the assumptions behind the numbers. This page applies that reasoning to the PlayStation's components and records where the PlayStation differs. It builds on [domains.md](domains.md) and refines its cached-interpreter estimate. Tags as there: MEASURED (a sibling's recorded measurement, cited), DOC, OBSERVED, HYPOTHESIS (an estimate with its arithmetic). Nothing here was measured on a PlayStation core. Emulator techniques are implementation choices, never hardware evidence. Every PlayStation emulator we know of is a closed box under the family's rules: Mednafen, PCSX-Redux and Avocado are GPL-2.0, and DuckStation is CC BY-NC-ND 4.0 (sources.md). None is read. ## The answer The PlayStation is the era-3 machine where **the no-JIT path is enough almost everywhere**, provided the time-keeping lesson of the SH-2 pilot is applied. - **The CPU's whole budget at its ceiling is 148 desktop-equivalent host cycles per instruction** (5.0e9 / 33.87e6). The SH-2 yardstick is sh2-rust-fast, an exact interpreter with a stage scheduler: about 145 cycles per instruction on a 4.3 GHz E-core and about 89 on an idle P-core (MEASURED: sh2-rust-fast docs/status.md). So an SH-2-style R3000A would already fit a desktop at the ceiling. It would fit a phone app (118) with little room, and it would miss a phone's browser (71). - **The lever is the same as on the N64: time-keeping, not decode.** In sh2-rust-fast's profile the scheduler takes 37 %, per-step checks 25 %, the fetch path 13 % and decode 3.6 % (MEASURED: docs/cached-interpreter.md on branch `cached-interpreter`). The R3000A specification is already at instruction level with bus transactions and no stage model (r3000a-python decision 4). The Rust tiers keep it cheap with a per-instruction cost table, a scoreboard for the load delay and the MULT/DIV and GTE interlocks, one deadline compare per instruction, and cycles accumulated until the next transaction. - **Everything the CPU can see at a cycle stays on one thread**: the CPU, the bus, DMA, timers, interrupts, the GPU's front end and the video timing. That is domains.md's CPU-and-bus domain. The SPU stays inline too, because every register access is a sync point and its whole cost is 2-6 % of a core (domains.md). - **Producers move to other cores**: the GPU back end, the final audio mix, MDEC decoding between its DMA input and output, and CD image reads (host I/O, nothing observable). - **Recompilation is a turbo option** for the phone browser's margin (run-ahead) and for low-cost ARM handhelds, where native recompilation is allowed. It is not the plan of record. ## Components | Component | Backends and tiers | Sync points | Notes | | --- | --- | --- | --- | | **R3000A (CW33300)** | x-python, x-rust: interpreter. **-fast**: packed decode, cost table, scoreboard, deadline compare, deferred cycles. **Cached interpreter keyed by i-cache line**: -fast if the lockstep holds. **Memoized block timing**: -fast if exact. Native and wasm block compilation: turbo | non-RAM transactions (I/O, BIOS ROM fetches, uncached RAM), the write queue's drain, DMA bus steals, interrupts at instruction boundaries | domains.md, memory kinds: the i-cache changes only on a refill or an isolated-cache flush, never on a store, so a decoded copy of each line is exact by construction for cached code. It is invalidated on the line's refill and on the flush. Only KSEG1 code is invalidated by RAM writes (HYPOTHESIS, psx-spx tier 3) | | **GTE** | inline in the CPU at every tier. Its fixed command latencies are table data, with the scoreboard stalling an early MFC2/CFC2 or a new command. Fixed-point arithmetic, exact on any host. SIMD for MVMVA/RTPT is optional in -fast | none: a coprocessor in the CPU domain | under 1 % of the CPU budget (domains.md) | | **RAM, scratchpad, BIOS ROM** | flat arrays. The scratchpad is CPU-only and never executable. Memory-control delays come from a table indexed by region and width | DMA into RAM (the hazard map below) | — | | **DMA (channels 0-6)** | transactions. DMA steals the CPU's bus word by word in the order of record (dma-timers-irq.md). Contents may be applied lazily up to the next CPU access to the range, and timing comes from the start time and the block mode | every DMA start and completion; any CPU access to an in-flight range | the PlayStation's CPU waits during most DMA modes, so contention is simpler than the N64's (U1 there) | | **GPU front end** | in the CPU domain at every tier: the FIFO, GPUSTAT, the per-command busy-time model, the display timing | GP0/GP1 writes (logged, no wait); GPUSTAT reads (answered by the front end) | the same split as the N64's RDP. **Open:** whether busy time depends on pixel results (the mask-bit check skips pixels by VRAM content). If it does, the split needs a join per command (decision P2) | | **GPU back end** | x-python, x-rust: the software rasteriser, the judge. -fast: on its own thread, or in bands where no state crosses pixels (the PlayStation GPU has no cross-pixel pipeline hazards documented in gpu.md: HYPOTHESIS, which makes bands much easier than on the N64). turbo: GPU compute, held to identical VRAM (decision P3) | **joins** only: GPUREAD, DMA2 from VRAM, and the scan-out of a buffer being drawn into (per line, only when single-buffered) | owns VRAM alone. All of its inputs are in the command log, since DMA2 to VRAM is logged by the front end, so it has **no WAR or WAW hazards against RAM**. That makes it simpler than the N64's RDP | | **SPU** | inline, caught up at each register access; voice and ADSR stepping in -fast with exact tables; the mix to the host rate as a producer | every SPU register access; DMA4; IRQ9, predicted from the voices' and reverb's next touch of the IRQ address (domains.md) | ADSR levels, ENDX and capture buffers are visible to the CPU, so only the host-rate output is a producer | | **MDEC** | inline in x-python. In -fast it decodes ahead on a thread once DMA0's input is complete, with a join at the DMA1 read or the status read | MDEC ports; DMA0/DMA1 | exact if the decode time model does not depend on the decode's result (HYPOTHESIS: run-length data does change it; then the front end counts codes, which is cheap) | | **CD (HLE controller)** | inline events (response, sector, seek end) on the CPU thread; disc reads prefetched on an I/O thread | the four ports; DMA3; IRQ2 | host I/O never touches observables | | **Scheduler** | one event queue in CPU cycles; the deadline is the queue's head | — | the GPU's video clock runs off the CPU clock. Its ratio comes from a rational step, exact in integers (domains.md: the clocks are not synchronous) | **Refinement of domains.md.** That page assumed a cached interpreter would gain x1.5-3 over -fast. The SH-2 measurement puts decode at 3.6 %. With the i-cache mirror, the R3000A's cached interpreter can also drop the per-fetch tag check, so its gain is the fetch path plus the decode: HYPOTHESIS x1.15-1.4. Memoized timing and the cheap scoreboard are the larger gain, and they belong in -fast when exact. ## Testing across backends As in n64-python's document. Each backend runs in lockstep with its fallback at block or event boundaries (CPU state, time, a CRC of every non-RAM transaction, a VRAM CRC at every join), single-threaded and multi-threaded. Seeded faults aimed at each backend include: - a decoded line kept after an isolated-cache flush; - a KSEG1 block not dropped after a DMA3 write; - a GTE result read one cycle early; - the load delay compiled away in a block; - a VRAM join skipped before a DMA2 read; - a banded triangle with dithering split wrongly; - the SPU's IRQ9 prediction one sample late. ## Numbers Desktop-equivalent host cycles per guest operation, on one core. Desktop is 5.0e9 / R, a phone app 4.0e9 / R (0.8x) and a phone's browser 2.4e9 / R (0.48x). These are HYPOTHESIS ratios, from domains.md and sh2-rust's wasm/native 0.55-0.65. | Component | Guest rate `R` (basis) | Desktop | Phone app | Phone browser | Likely cost (HYPOTHESIS) | Verdict | | --- | --- | ---: | ---: | ---: | --- | --- | | R3000A, ceiling | 33.87 M instr/s (DOC) | 148 | 118 | 71 | 25-60 with cheap time-keeping; 90-145 SH-2-style | fits everywhere with cheap time-keeping; the browser needs it | | R3000A, MAME's rate | 17.0 M instr/s (OBSERVED) | 295 | 236 | 142 | as above | fits everywhere | | GTE | ~0.1 M commands/s (domains.md) | 50,000 | 40,000 | 24,000 | 300-1,500 per command | negligible | | GPU back end | 9-18 M pixels/s (domains.md) | 278-556 | 222-444 | 133-267 | 15-50 per pixel (3-10 ns at 5 GHz) | a fraction of one producer thread everywhere: a GPU backend is not needed for speed | | SPU | 1.06 M voice-samples/s (domains.md) | 4,700 | 3,800 | 2,300 | 100-250 | 2-11 % of the CPU thread: inline | | MDEC (FMV) | 36,000 blocks/s (domains.md) | 139,000 | 111,000 | 67,000 | 5,000-10,000 | 4-15 %: producer thread | | DMA, bus transactions | 1-4 M/s (HYPOTHESIS: i-cache misses, uncached and I/O accesses, DMA words in blocks) | 1,250-5,000 | 1,000-4,000 | 600-2,400 | 10-40 | cheap | | Python spec (scale) | 0.1-0.2 M instr/s (domains.md) | | | | | 1/85 to 1/340 of real time: test EXEs and slices | **Without recompilation:** - **Desktop:** full speed with room, from -fast on. - **Phone app:** full speed (CPU 25-60 against 118). The cached interpreter and memoized timing give the margin for run-ahead's multiplied cost (a frame of run-ahead doubles the CPU's need, so 59 cycles per instruction at the ceiling). - **Phone browser:** at the ceiling only with the cheap time-keeping (71 against 25-60). Run-ahead there needs `recompile: wasm`, or is reported as unavailable in the capability record. - **Low-cost ARM handheld** (about 0.2x: domains.md): 30 cycles at the ceiling. That needs `recompile: native`, which the distro target allows. ## Open decisions for Aubrey (each with my recommendation) - **P1. Time-keeping as specification data for the R3000A and the GTE** (per-instruction costs, load-delay and interlock rules), as n64-python's X1. *Recommend* yes. - **P2. The GPU front end's busy-time model must not depend on pixel results** unless a judge shows that it does (the mask-bit check is the case to test with ps1-tests' `gpu/benchmark`). *Recommend* yes, marked HYPOTHESIS. A data dependence would make the back end join per command. - **P3. No GPU-compute backend for the PlayStation until a target shows it needs one.** The numbers say a software back end on one thread is enough. Upscaling or other enhancements would be concessions. *Recommend* yes ("prune what does not pay", applied in advance). - **P4. MDEC ahead on a thread** only if its decode-time model can be computed from the input stream without decoding. *Recommend* deciding when psx-rust-fast measures FMV load.