# Domains and speed: where a readable specification meets its hardest wall Phase 0, 2026-11-25. Every number here is tagged: DOC (a manual or the n64brew wiki), MEASURED (a sibling repository's recorded measurement, cited), or HYPOTHESIS (an estimate whose arithmetic is shown so it can be replaced by a measurement). Nothing here was measured on an N64 or on an N64 core: none exists in the family yet. The short version: **a Python N64 is a specification and a test runner, never a player.** The VR4300 alone needs 50-94 M instructions a second; the family's fastest Python RISC core with a timing model runs 0.02-0.2 M on a board. The RSP and RDP each need as much again. A Python board will run test ROMs and short, targeted slices of games (seconds of emulated time over minutes or hours of wall time). Rust is where it becomes a machine, and even there the RDP is the wall, not the CPU. ## The domains Declared here so the specification is written around them from M1 (charter, "Domains and channels"; JIT proposal, "Boundaries"): | Domain | Clock (DOC: n64brew Clock Timing) | What is in it | | --- | --- | --- | | **CPU** | VR4300 PClock 93.75 MHz (MClock 62.5 MHz x 1.5) | vr4300-python: pipeline, caches, TLB, FPU, SysAD issuer | | **RSP** | RCP clock 62.5 MHz | rsp-python: scalar unit, vector unit, IMEM/DMEM, its DMA engine | | **RDP** | RCP clock 62.5 MHz | the rasteriser/texture/combiner/blender pipeline, TMEM, span buffers, the command DMA | | **RCP interfaces** | 62.5 MHz | MI, PI (+ cartridge, saves), SI (to the PIF), AI, VI, RI and RDRAM | | **PIF + joybus** | ~1.95 MHz (MClock/32) | PIF RAM command processing, controllers, paks, EEPROM, RTC, the CIC exchange | | VI scan-out, AI output | VCLK 48.68 MHz NTSC (X1 x 17 / 5) | pure producers: they read RDRAM at their own rate | Channels between them: - **RDRAM** is the great shared memory: every domain except the PIF reads and writes it, through the RI. It is the hardest channel: it is not a FIFO or a port, so a domain may only run ahead while nothing else could write what it reads. In practice the order of record is set by the RCP's arbitration of RDRAM requests (unknown in detail: U-list in handoff-brief) and the specification serialises it. - CPU <-> RCP: uncached SysAD accesses to RCP registers (each one a sync point), and the MI's interrupt line (Int0). - CPU <-> RSP: SP_STATUS (halt, signals, the semaphore), the SP DMA registers, and IMEM/DMEM (the wiki: single-ported, no arbiter, the VR4300 usually wins a collision: so a CPU access to IMEM/DMEM while the RSP runs is a sync point). - RSP <-> RDP: the XBUS (command lists read from DMEM) and the DPC registers as the RSP's COP0 c8-c15. This is the most frequent channel in a game frame. - RDP -> MI: SYNC_FULL raises the DP interrupt. VI -> MI: the line compare. AI -> MI: a buffer starts. PI, SI -> MI: DMA done. - SI <-> PIF: 64-byte PIF RAM transfers; the joybus frame executes on an RD64B. ## The arithmetic ### The VR4300 - Peak: one instruction per PClock, **93.75 M instructions/s** (DOC: UM five-stage pipeline; n64brew Clock Timing). - Stalls lower the instruction rate but not the work: an interpreter that models them must still compute every stall. Integer multiply 5 PCycles, divide 37, DMULT 8, DDIV 69 (UM Table 3-12); FPU MUL.D 8, DIV.D 58 (UM Table 7-14); I-cache line fill and D-cache misses cost RDRAM time (n64brew: SysAD Interface says RDRAM about 10-20+ clocks, DMEM/IMEM 4-5). HYPOTHESIS: a game's VR4300 retires 0.5-0.8 instructions per PClock, so **47-75 M instructions/s**, and games that wait for the VI in a loop retire the waiting loop at nearly the full rate (the idle loop is instructions too, unless skipped: a concession). - **Need: 50-94 M VR4300 instructions per emulated second**, each with a TLB or segment lookup, a cache tag check on every fetch and data access, and a stall rule. ### The RSP - Peak: one scalar and one vector instruction per cycle at 62.5 MHz (DOC: n64brew RSP specs, dual issue), **125 M instructions/s**; each vector instruction works on 8 lanes of 16 bits with a 48-bit accumulator per lane, so **500 M lane operations/s** at peak. - Load: the RSP runs the graphics microcode (transform, lighting, clipping, building RDP commands) and the audio microcode (ADPCM decode, resampling, mixing) each frame. HYPOTHESIS (no measurement in the family; an N64 profiler such as libdragon's or the RSP's own DPC/RSP counters would give it): busy 30-70% of a frame in 3D games, about half of its instructions vector, so **20-45 M instructions/s, 80-180 M lane operations/s**. ### The RDP, and its per-pixel cost - Throughput (DOC: n64brew RDP Pipeline): 1-cycle mode one pixel per 62.5 MHz clock (**62.5 M pixels/s**), 2-cycle mode one per two (31.25 M), FILL and COPY 64 bits per step (4 pixels at 16 bpp, so up to 250 M pixels/s for clears). - Load. A 320 x 240 frame is 76,800 pixels. HYPOTHESIS: a 3D game draws each pixel 2-3 times (overdraw) plus a FILL clear and a Z clear, at 20-60 frames a second: **3-14 M shaded pixels/s** in 1- or 2-cycle mode, plus 4-9 M filled. - **Per-pixel work** in a software model that follows the pipeline (DOC: the stage list of n64brew RDP Pipeline, 18 stages): rasteriser step and attribute interpolation (RGBA, S, T, W, Z: about 9 adds per pixel), perspective divide (a reciprocal: one table lookup and multiplies), texture coordinate clamp/mirror/mask (per texel), **4 TMEM texel fetches** with format expansion to RGBA32, bilinear filter (3 lerps x 4 channels = 12 multiplies), the combiner ((A-B)*C+D, 4 channels, 1 or 2 cycles = 4-8 multiply-adds plus 9-bit saturation), alpha compare, coverage (4x4 subpixel mask counted through 0xA5A5), the memory colour read, the blender (p*a + m*b, optionally divided), Z decode (18-bit with dz), compare and write, dither, and the RDRAM write with the hidden bits. HYPOTHESIS: **400-1,000 native machine operations per pixel**, so 3-14 M pixels/s is **1.2-14 G native operations a second**: one to several fast host cores for a bit-exact software RDP. This is why the community runs bit-exact RDPs either multithreaded on the CPU (angrylion-rdp-plus: closed box here, its licence is MAME's non-commercial one) or on the GPU in compute shaders (parallel-rdp, MIT). ### What Python can do MEASURED in the family (sh2-python `docs/validation.md`, a shared machine at load 50-70): the SH-2 core runs **610,000 instructions/s on CPython 3.14 and 2,380,000 on PyPy 3.11** on its minimal harness before its pipeline scheduler, **215,000 (CPython) and about 90,000 (PyPy, a JIT pathology not investigated)** after it, and **13,900-27,600 instructions/s** in the 32X board replays. HYPOTHESIS for the N64 Python board, scaling from that: the VR4300 (64-bit registers, TLB/segment lookup, I- and D-cache tag checks, stall rules) at 0.02-0.2 M instructions/s; the RSP's vector instructions at a tenth of that each (8 lanes, accumulator, clamping); a pipeline-faithful RDP at 10-50 µs a pixel on PyPy. | Part | Need per emulated second | Python per emulated second | Slower than real time | | --- | --- | --- | --- | | VR4300 | 50-94 M instructions | 0.02-0.2 M/s | **250x-4,700x** | | RSP | 20-45 M instructions | 0.005-0.05 M/s (vector-heavy) | 400x-9,000x | | RDP | 3-14 M shaded pixels | 20,000-100,000 pixels/s | 30x-700x | So **one emulated frame (16.7 ms) costs on the order of 10 seconds to several minutes** of wall time in Python, before the RDP; a whole frame of a 3D game with the RDP, minutes. A boot to a title screen (IPL3's ~0.5 s plus the game's start-up, several emulated seconds) is an hour-scale run. The 2026-11-25 shared-machine rule (no sweeps; minutes on one core) fits test ROMs and single frames, not games. ### What a Python specification can be on the N64 It **can** be: the readable authority for every behaviour (the deviations of the VR4300, the RSP's lane rules, every RDP stage); the runner of the self-checking test ROMs (nemu64-test's 1,125 tests, krom's suites, n64_pi_dma_test's hardware dumps), each a few emulated frames; the producer of reference traces and pictures for short, targeted slices (a game's first RDP display list from a save state; one audio task); and the source the Rust tiers transcribe. It **cannot** be: a way to play, a way to run a full-library sweep (1,150 images: years of CPU), or a way to find timing bugs that need minutes of play. The family's "sweep a library" habit does not transfer: the N64 gate is **test ROMs plus a curated set of short slices**, each starting from a save state produced by the Rust tier (a Rust state loads into Python, by the snapshot contract), so Python never boots a game for the gate. It **must not** be bent to be faster (charter: x-python must not grow complicated to suit downstream speed). The one concession to speed that is also a readability win is the JIT proposal's restricted handler form, which helps a generated Rust interpreter and a cached interpreter without changing what the Python says. ## Rust, without a JIT (the iPhone rule) Reference points, MEASURED in the family: sh2-rust (a transcription) 30-47 M SH-2 instructions/s natively and 20-27 M as wasm32 under Node (sh2-rust README); m68000-rust-fast 191 M instructions/s on its bench (m68000-rust-fast README). HYPOTHESIS for the N64 tiers: - **vr4300-rust (transcription)**: 20-50 M instructions/s with caches and stall rules, so 0.2-1x real time for the CPU alone on a desktop core. - **vr4300-rust-fast**: exact tables, specialised layouts, the micro-TLB and cache tag checks made cheap, a decoded-instruction cache: 80-200 M/s on a desktop core, which covers the 94 M need with room. - **Cached interpreter** (turbo, no executable memory, allowed everywhere): decode each block once into a sequence of handler pointers with their operands, replay it, invalidate on writes to its physical page (RDRAM writes by the CPU, PI/SP DMA into it) and on CACHE ops. HYPOTHESIS: 1.5-3x over the plain `-fast` interpreter, because decode and dispatch dominate a RISC interpreter's cost. (Revised 2026-11-26 in [execution-architecture.md](execution-architecture.md): the SH-2 pilot measured decode at 3.6 % and time-keeping at over 60 %, so the expected gain is x1.15-1.4, and the lever is the time-keeping.) On an iPhone-class core (about 3 GHz, wide issue) the budget for 94 M instructions/s is **about 30 host cycles per guest instruction** on one core, including the cache model: reachable with a cached interpreter, tight with caches modelled exactly. - **RSP vector unit**: 8 lanes x 16 bits is one 128-bit SIMD register. SSE/NEON in native builds and **WebAssembly SIMD128 in the browser** (which Safari runs, no JIT needed from us) make each vector instruction a handful of host instructions: exact, not a concession, so it belongs in `rsp-rust-fast` (charter: "exact tables, specialised layouts"). With that, the RSP's 20-45 M instructions/s is about one host core. - **RDP**: the wall. A bit-exact software RDP at 1.2-14 G native operations/s needs threads (it parallelises by scanline or by tile: each span reads only TMEM, the command state and its own framebuffer pixels) and SIMD across pixels. On a phone with 2 performance cores and 4 efficiency cores it is at or past the edge in the heavy games. A GPU compute RDP (as parallel-rdp does with Vulkan; Metal on iOS) is the other path; it is exact if it is bit-exact, and it is a host capability, not a concession, but it is a second implementation of the RDP that the gate must hold to the per-pixel output of the specification. - **High-level emulation of microcode** (replacing the RSP's graphics or audio tasks with native code that does what the microcode does) changes results (precision, ordering, timing of the RSP's RDRAM traffic): it is a **concession**, named and off by default (charter), with its cost measured against the low-level run. The JIT proposal already expects it on no-JIT targets. Where a JIT is allowed (desktop native; WebAssembly generated at run time in the browser), the VR4300 and the RSP scalar unit are the natural recompilation targets (block-boundary lockstep, JIT proposal); the RSP vector unit gains more from SIMD than from recompilation. ## Where threads fit The domains above map onto threads from `-fast` on (charter: determinism at any thread count): 1. **RDP on its own thread(s)**, fed by the command list. The RDP's inputs are its command words (from RDRAM or DMEM), TMEM loads (from RDRAM) and the framebuffer and Z buffer it reads back; its outputs are RDRAM writes and the DP interrupt. It can run behind the producer as long as nothing else reads the pixels it writes before it is done: the sync points are SYNC_FULL (the interrupt), any CPU or RSP read of an address the RDP writes, and the VI scan-out of a buffer the RDP writes. Within the RDP, scanline bands on several threads, joined at every command that changes state. This is the biggest win. 2. **RSP on its own thread** between SP_STATUS events: it meets the CPU at SP_STATUS, the semaphore, the DMA registers, IMEM/DMEM accesses and RDRAM; it meets the RDP at the XBUS. A task (one microcode run from start to BREAK) is the natural unit; the RDRAM it touches is mostly its own task buffers, but the CPU may poll RDRAM the RSP writes (audio buffers, task yields), so RDRAM in the RSP's DMA ranges is a sync point. 3. **VI scan-out and AI output as pure producers**: given the register log and RDRAM at the scan time, a frame's picture (with the VI's AA filter, divot, dedither and gamma) and a buffer's samples can be produced beside the emulation. 4. **CPU + interfaces stay one domain**, as the 32X's SH-2 pair does: the CPU's uncached RCP register accesses are too frequent to synchronise across threads. Conservative synchronisation keeps even the per-cycle trace identical (charter). The specification's job, from M1, is to say for each channel which accesses are sync points, and to keep RDRAM access ordered by one arbiter that the Rust tiers can split. ## What this means for the plan - M1-M3 (handoff-brief) are judged by test ROMs only; no game boots in Python as a gate. - The board's capability record (charter) will say plainly: Python not real time on any target; Rust `-fast` real time on desktop with the CPU and RSP, RDP threaded; `recompile: none` on iPhone **probably cannot meet full speed in the heaviest 3D games without the RSP-HLE concession or a GPU RDP** (to be measured, not assumed). - Measure early: the first numbers worth having are vr4300-rust's instructions/s on a CPU-only test ROM and rsp-rust's on an audio task, before any RDP work.