# Domains and speed Two questions in one file, because the answer to the second depends on the first: where the PlayStation's **domains** and **channels** fall (charter, "Domains and channels"), and whether the board can be fast enough without recompilation (charter, capabilities: `recompile: native | wasm | none`; emulator-lineage `docs/proposals/2026-11-jit.md`, accepted 2026-11-25). Phase 0: nothing here is measured on this board, because the board does not exist. Every speed figure is an **estimate** with its arithmetic shown; the measured inputs are named. ## Part 1: domains and channels The PlayStation's parts sit on few clocks: the CPU clock (33.8688 MHz, which also clocks the SPU, DMA and timers), the GPU's video clock (53.69 / 53.20 MHz, **not** synchronous with the CPU: psx-spx timers "the GPU clock isn't in sync with the CPU clock"), and the CD side's own clocks (the DSP's crystal, and the sub-CPU at a quarter of the DSP's FSOF). | Domain | Time base | Parts | Why it is one domain | | --- | --- | --- | --- | | **CPU and bus** | CPU cycles | r3000a-python (core, GTE, i-cache, scratchpad), RAM, BIOS ROM, memory control, DMA controller, interrupt controller, root counters, SIO0/SIO1 and the pads and cards, the GPU's **front end** (FIFO, GPUSTAT, the per-command busy-time model) and **video timing** (dot, line and frame counters) | DMA steals the CPU's bus word by word and stalls its reads (dma-timers-irq.md); the timers count the GPU's dot clock and HBLANK; GPUSTAT is polled constantly. All of this is visible to the CPU at a cycle, so splitting it would make every access a sync point | | **GPU back end** | the order of GP0 commands | rasteriser, VRAM, texture and CLUT caches, scan-out of pixels | a **pure producer** (charter): it turns the command log into VRAM contents and pictures. Nothing it does is visible to the CPU except through VRAM read-back | | **SPU** | 44.1 kHz samples (768 CPU cycles) | SPU, 512 KB sound RAM, reverb, the CD audio mix | its own state; the CPU meets it only at its registers, DMA4 and IRQ9 | | **CD** | CD sector time (1/75 or 1/150 s) and the controller's delays (HLE) or the sub-CPU's clock (LLE) | controller, decoder and sector buffer, drive and disc image | meets the CPU only at four byte ports, DMA3 and IRQ2; feeds audio to the SPU | | **MDEC** | its own decode time | the macroblock decoder | meets the CPU only at its two ports and DMA0/DMA1 | ### Channels and sync points | Channel | Between | Sync point (where a threaded tier must catch up) | | --- | --- | --- | | GP0 commands, GP1 control | CPU front end -> GPU back end | **none for writes**: commands go into a log the back end drains; the front end computes busy time itself | | GPUREAD (VRAM -> CPU), DMA2 from VRAM, VRAM-to-VRAM copies that a later CPU read depends on | GPU back end -> CPU | **join**: the back end must have drawn everything before the read | | VBLANK, HBLANK, dot clock | video timing (in the CPU domain) -> timers, IRQ0 | none (same domain) | | SPU registers (1F801C00h-1FFFh) read or written | CPU <-> SPU | every access: the SPU is run to the CPU's cycle | | DMA4 (sound RAM) | CPU bus <-> SPU | each block; the SPU also stops the CPU's DMA when it is not ready | | IRQ9 (SPU IRQ address reached) | SPU -> CPU | the SPU must predict the cycle it next touches the IRQ address, or run ahead of the CPU at most to that cycle | | CD ports 1F801800h-03h | CPU <-> CD | every access | | DMA3 (sector data) | CD -> CPU bus | each block | | IRQ2 | CD -> CPU | the CD domain schedules its next event (response, sector, seek end) and the CPU domain may not pass it | | CD-DA / XA audio | CD -> SPU | a sample FIFO, consumed at 44.1 kHz: a producer-consumer channel with a known rate | | MDEC ports, DMA0/DMA1 | CPU bus <-> MDEC | each access / block | **Order of record** (x-python, serial): the CPU domain runs; at every sync point it runs the other domain up to the CPU's cycle first (the "catch up at the channel" pattern of sega32x-python and segacd-python's domains.md). The GPU back end, being a producer, runs at the end of each frame and at each join in Python; that changes nothing observable and keeps the Python simple. ### Memory kinds (who may write each region: the cached interpreter's invalidation map) | Region | Written by | Notes | | --- | --- | --- | | BIOS ROM | nobody | code never invalidated | | Main RAM (2 MB, mirrored) | CPU stores (through the write queue), DMA0-6 into RAM (CD sectors via DMA3, MDEC output via DMA1, GPU VRAM read-back via DMA2, OTC via DMA6) | **all game code lives here** and is loaded by DMA3 from the CD | | i-cache | refills only; never by stores (r3000a-python cop0-and-caches.md) | stale code keeps running until a flush (Formula One 2001) | | Scratchpad | CPU only | not executable | | VRAM | GPU back end only | | | Sound RAM | SPU only (transfers, capture buffers, reverb) | | | CD sector buffer | CD domain only | | A useful consequence for a cached interpreter: for code in KUSEG/KSEG0 (all game code), what executes is the **i-cache's** content, which changes only on a refill or a flush, not on a store. A decoded-instruction cache that mirrors i-cache lines is therefore exact by construction for cached code: it is invalidated exactly when the modelled i-cache line is refilled or flushed. Only KSEG1 (uncached) code needs invalidation on RAM writes, and the BIOS's ROM code never does. (HYPOTHESIS until the cached interpreter exists: it rests on psx-spx's "stores do not affect the i-cache", tier 3.) ## Part 2: how many instructions a second the CPU needs **Peak.** The CW33300 issues at most one instruction per cycle (LR33300 ch.1, DOC), at 33.8688 MHz: **33.87 M instructions per second** is the hard upper bound. It is reached only by code running entirely from the i-cache with no loads that stall, no MULT/DIV/GTE waits and no DMA holding the bus. **What real code needs is less, and unknown until our board measures it.** Every i-cache miss refills from RAM at about 5 cycles per access (ps1-tests access-time, TEST ROM: 5.14-5.3 cycles per load), every load whose value is needed at once stalls, every uncached fetch (BIOS code, KSEG1) costs 7.6-25 cycles, DIV takes 36. The only whole-machine figure we have is MAME's, which is a model: **16.95 M instructions per emulated second** in every window measured (two BIOS-intro windows of 1.001 s: 16,951,337 and 16,951,336; a quickloaded test EXE: 33,967,249 in 2.006 s), i.e. 1.998 cycles per instruction (OBSERVED, mame-oracle.md in r3000a-python). So, for planning: | Case | Instructions/s | Basis | | --- | ---: | --- | | ceiling | 33.9 M | 1 per cycle (DOC) | | MAME's model | 17.0 M | OBSERVED, closed box | | planning figure | **34 M** | budget for the ceiling: tight cached loops (polling, decompression, GTE setup) do run near 1 per cycle for whole frames, and the interpreter has to keep up then | The GTE adds little: its commands are 5-44 cycles of fixed arithmetic (gte.md); a game issuing ~100,000 RTPT a second (300,000 vertices) costs well under 1% of the CPU budget in a compiled tier (estimate: ~0.3 us per command in Rust, 0.03 s per second). ### The other domains' load (estimates) | Domain | Work per emulated second | Estimated cost in Rust, one core | Basis | | --- | --- | --- | --- | | GPU back end | 320x240 x overdraw 2-4 x 60 fps = **9-18 M pixels** (textured, blended) | 3-10 ns/pixel -> 30-180 ms (3-18% of a core) | HYPOTHESIS: a scalar software rasteriser with texture fetch, CLUT, blend, dither and mask | | SPU | 24 voices x 44,100 = **1.06 M voice-samples** + reverb | 20-50 ns each -> 20-55 ms (2-6%) | HYPOTHESIS | | MDEC (during FMV) | 320x240 x 30 fps = 2.3 M pixels = 36,000 8x8 blocks | ~1-2 us/block -> 36-72 ms (4-7%) | HYPOTHESIS | | CD (HLE) | 75-150 sectors | negligible | | ## Part 3: is an interpreter enough without recompilation? ### What the family has measured (on this machine: i9-13900K, one core, release builds) | Interpreter | Measured | Source | | --- | --- | --- | | sh2-rust (a plain transcription, not optimised) | **30-47 M SH-2 instructions/s native**, 20-27 M as wasm32 under Node | sh2-rust README and docs/status.md, 2026-11-25, load 50-83 | | m68000-rust-fast | 191 M instructions/s synthetic (a 68000, ~29 cycles per instruction: simpler per-cycle work) | memory notes, m68000-rust-fast | | z80-rust (plain) | ~50 M instructions/s | z80-rust README | | the family's `-fast` forks over their transcriptions | x1.4 to x1.9 | a2600 x1.886, megadrive x1.398 (x1.58 PGO), m68000 x1.384 | | sh2-python (the reference) | ~0.1-0.2 M instructions/s (PyPy/CPython) | sh2-rust docs/status.md | The SH-2 is the right yardstick: a 32-bit RISC with delay slots, a cache and a transaction-level bus, transcribed from a readable Python specification in the family's style. An R3000A transcription should land in the same range (simpler decode, no flags; but a load-delay record, a write queue and an i-cache tag check on every fetch). **Estimate: r3000a-rust 30-50 M instructions/s native, 20-30 M as wasm.** ### The answer, by target (estimates; `recompile: none` throughout) Ratios assumed (HYPOTHESIS, to be measured on the devices): a recent iPhone (A17/A18 class) runs single-threaded code at ~0.8x this desktop core; WebAssembly in a browser at ~0.6x of native (sh2-rust measured 20-27 M wasm vs 30-47 M native on the same machine: 0.55-0.65x); a low-cost ARM Linux handheld (Cortex-A55 class) at ~0.2x. | Target | x-rust (transcription) | x-rust-fast (x1.4-1.9) | turbo with a cached interpreter (x1.5-3 over -fast, HYPOTHESIS) | Need | Verdict | | --- | ---: | ---: | ---: | ---: | --- | | Desktop, native | 30-50 M | 42-95 M | 63-285 M | 17-34 M | **real time from x-rust-fast on, CPU on one core, GPU/SPU on others** | | iPhone app, native (no JIT allowed) | 24-40 M | 34-76 M | 50-230 M | 17-34 M | -fast probably enough; cached interpreter gives margin for run-ahead | | Browser (wasm), desktop | 18-30 M | 25-57 M | 38-170 M | 17-34 M | -fast marginal at the ceiling; cached interpreter needed for margin | | Browser (wasm), iPhone Safari | 14-24 M | 20-46 M | 30-140 M | 17-34 M | **cached interpreter needed**; run-ahead doubtful without "recompile to wasm" | | ARM handheld (A55 class), native Linux | 6-10 M | 8-19 M | 13-57 M | 17-34 M | interpreter alone **not enough** at the ceiling; there native recompilation is allowed (`recompile: native`) | (Revised 2026-11-26 in [execution-architecture.md](execution-architecture.md): the SH-2 pilot measured decode at 3.6 % of an exact interpreter's time and time-keeping at over 60 %, so the cached interpreter's own gain is more likely x1.15-1.4. The larger lever is cheap time-keeping in `-fast`. The verdicts above stand on that basis.) Threads matter as much as the CPU: on every target above the CPU domain needs most of one core, and the GPU back end, SPU and MDEC together need roughly another 10-30% of a core (Part 2): that work moves to other cores from `x-rust-fast` on (charter: deterministic threads), and the GPU back end is a pure producer, the easiest kind to move. ### "A slow Rust PSX"? Honestly, by these estimates: - **Natively, no.** The plain transcription's CPU alone is near real time on this desktop (30-50 M against a 17-34 M need) before any optimisation, and the family's `-fast` record (x1.4-1.9) plus a GPU thread puts the whole board at roughly 1.5-3x real time on desktop and around real time to 2x on a recent phone, **without recompilation**. - **In a phone's browser, it is at the edge** unless the turbo tier's cached interpreter pays as hoped (the same conclusion sh2-rust reached for the 32X). That is where the proposal's "recompile to WebAssembly" is worth measuring. - **On low-cost handhelds, an interpreter will not hold the ceiling**; the distro target (ROCKNIX-like, Linux) allows native recompilation, which the charter's capability contract covers. - **The Python specification is slow, by design**: at 0.1-0.2 M instructions/s it runs the CPU at **1/85 to 1/340 of real time** (17-34 M needed). Booting the BIOS to its shell (~10 emulated seconds) would take on the order of **30-60 minutes** under PyPy. Python rungs must therefore use side-loaded test EXEs, short windows and save points; long runs belong to the Rust tiers' lockstep, as era 3 in the charter foresees. The numbers that would replace these estimates, in order: r3000a-rust's instructions per second on the SST corpus and on the BIOS boot (rung speed script, as sh2-rust's `scripts/speed.sh`); psx-python's own cycles-per-instruction over a BIOS boot and a game's first minute (replacing MAME's 1.998); the GPU back end's pixels per second from ps1-tests `gpu/benchmark`; and a phone run.