# Execution architecture and performance strategy Phase 0, 2026-11-26. Aubrey's aim for this board: "construct a comprehensible, testable model of the machine, and then find the fastest way to execute that model". This document is the second half: for every component, the backends that could run the model, which tier each one belongs to under the charter, where its synchronisation points fall and what they cost, how each backend is tested against the specification, and a numbers table with its arithmetic shown. It builds on [domains-and-speed.md](domains-and-speed.md) (the domains, the channels and the need) and refines two of its estimates (marked below). Nothing here was measured on an N64 or on an N64 core: none exists in the family yet. Every figure is tagged. MEASURED means a sibling repository's recorded measurement, with its file named; DOC means a manual or the n64brew wiki; OBSERVED means another emulator's behaviour, or a design read in a permissive emulator's source; HYPOTHESIS means an estimate whose arithmetic is shown so a measurement can replace it. **Every emulator technique named here is an implementation choice, never hardware evidence.** Where a technique is described from another project, the project is named with its licence: readable where permissive (ares: ISC; cen64: BSD-3-Clause, except its `rdp/`, which is angrylion's and is not fetched; parallel-rdp: MIT), or a closed box (MAME, mupen64plus, gopher64, simple64, Project64, angrylion-rdp-plus), whose source is never opened and whose behaviour is named only as OBSERVED. ## The answer in one page **Synchronisation, not decode, is the cost of an exact N64.** The family's one measured era-3 interpreter shows it. sh2-rust-fast, profiled with its cache on, spends about 37 % of its time in the stage scheduler, 25 % in per-step checks (events, DMA, interrupts, address errors) and 13 % in the fetch path. The handlers take 10 %, dispatch 5 % and the decode load 3.6 % (MEASURED: sh2-rust-fast docs/status.md, and docs/cached-interpreter.md on branch `cached-interpreter`). A cached interpreter that kept every fetch could remove only the decode, and it came out about 10 % slower (x0.89-0.91 native, x0.897 wasm). At 29.7 M instructions/s on a 4.3 GHz E-core, that is about 145 host cycles per SH-2 instruction (4.3e9 / 29.69e6). About 54 of those cycles go to the scheduler, 36 to the checks, 19 to the fetch, 15 to the handlers and 5 to the decode. The VR4300's whole budget at its peak rate is **53 host cycles per instruction on a 5 GHz desktop core, 43 on a phone app and 26 in a phone's browser** (numbers table below). An SH-2-style scheduler alone would spend all of it. So the N64's execution architecture is first a **time-keeping architecture**: 1. **Time is charged per instruction from data, not by simulating stages.** vr4300-python's decision 2 already chose an instruction-level model with stall rules (vr4300-python handoff-brief). The Rust tiers make that a table lookup plus a small scoreboard: the static cost of each instruction, the load-use and multiply/divide interlocks from register numbers, and dynamic costs only at cache misses and uncached transactions. 2. **One deadline compare replaces the per-step checks.** Every domain publishes the earliest moment it could change something another domain sees: its next event, or its next channel access. The CPU runs until `now >= deadline`, or until its own next channel access. The deadline is recomputed only when a channel is touched, and that is exact because nothing outside a channel can change the CPU's inputs. 3. **Fetch work drops from once per instruction to once per I-cache line.** The VR4300's caches are direct-mapped and have no LRU (vr4300-python timing.md), so a cache hit changes no state that software can see. A decoded line can therefore skip the tag check for the 7 instructions after the first. The SH-2 could not do this, because its fetches update an LRU that the address array exposes. 4. **Threads only where one side can run far ahead.** The CPU, the RSP and the RCP registers poll each other within a few cycles. A conservative cross-core handshake costs about 500-1,500 host cycles (HYPOTHESIS: a cache-line round trip between cores). A polling loop can make 9 M channel reads a second. Those parts therefore stay on one thread, or the RSP runs **ahead** on its own thread with an exact rollback. The RDP's pixel work, the VI's filters and the AI are producers, and those go to other cores or to the GPU. 5. **The RDP splits into a timing front end and a pixel back end.** The front end walks edges and spans, runs at command arrival on the CPU's thread, and gives the cycle counts, DPC registers and DP interrupt time. The back end shades pixels and may run behind it on threads or on the GPU. The two meet only at **joins**: the CPU, the RSP, a DMA or the VI reading pixels, or another master overwriting memory the back end has yet to read. This is the PlayStation GPU's front-end/back-end split (psx-python domains.md), carried over. Whether it stays exact depends on one open question: is the RDP's timing a function of geometry and modes alone (U7, decision X3)? Without recompilation, by these estimates: desktop native reaches full speed with the cheap time-keeping above, the RSP speculative on a second core and the RDP threaded. A phone app is at the edge in heavy 3D games. A phone's browser cannot hold the VR4300's peak rate with an exact interpreter (26 cycles per instruction), so it needs "recompile to wasm", the GPU RDP and probably a named concession. All of this is to be measured, and the first measurements are listed at the end. ## Time base and the order of record - **One integer time base for every domain:** the half-PClock, 187.5 MHz. This is the VR4300's own count (vr4300-python handoff-brief: one SClock is 3 half-PClocks at the N64's 2:3 ratio). An RCP cycle at 62.5 MHz is 3 units and a PClock is 2 units, so every domain's time is exact in it. The joybus at MClock/32 is 96 units per bit clock (DOC: n64brew Clock Timing). - **The order of record** (x-python, serial): the CPU domain steps, and at each channel access it first runs the other domain up to the CPU's time ("catch up at the channel", as in sega32x-python and psx-python). Producers run at joins and at frame ends. That order is the definition. Every later backend must reach the same states at the same moments, or the same observables at the same moments in turbo. - **The event queue** holds timed events: VI line compare, AI buffer start, the completions of PI, SI and SP DMA, Count = Compare, RDP SYNC_FULL done (from the front end), the PIF's joybus completion. The queue's head is the **deadline**. ## The cost model for synchronisation Let `I` be the instructions between two sync points, `c` the host cycles per instruction spent on time-keeping, and `S` the cost of one sync. The overhead per instruction is `c + S / I`. | Sync kind | `S`, host cycles | Where it fits | Basis | | --- | ---: | --- | --- | | Deadline compare, same thread | 1-3 | every instruction, or once per block with a cycle bound | HYPOTHESIS: a compare and a predictable branch | | Inline catch-up (call the other domain's `run_until`) | 20-100 of overhead, plus the other domain's own work | channel accesses on the CPU thread: RCP registers, SP, DPC | HYPOTHESIS: a call, a state load, a loop exit | | Cross-thread conservative handshake, both threads spinning | 500-1,500 | channels touched less than ~1 in 10,000 cycles | HYPOTHESIS: about 100-300 ns of cache-line round trips between cores on one die | | Cross-thread, a sleeping thread woken by the OS | 25,000-250,000 | never in the hot path; frame-level hand-offs only | HYPOTHESIS: 5-50 µs per OS wake | | GPU join (submit, fence, read back) | 0.5-5 M (0.1-1 ms) | a few per frame at most | HYPOTHESIS; parallel-rdp's README stresses host-visible memory import (VK_EXT_external_memory_host) to make these cheaper | What it implies: - **The CPU, the RCP registers and the RSP poll each other densely.** A loop such as `lw SP_STATUS; andi; beqz; nop` makes one uncached RCP read every 4 instructions, plus the read's 5-6 PClock latency (DOC: n64brew memory map, unattributed). That is about 9 M reads per emulated second while it spins (93.75e6 / ~10 PClocks). At 500 cycles a handshake, it would cost 4.7 G host cycles a second, so a conservative cross-thread CPU/RSP split cannot pay. These channels stay inline. Alternatively the other side is kept **ahead** (below), so that the CPU's reads find their answer already computed. - **A read and a write ask different things of the other domain.** When the CPU reads another domain's state, that domain must have reached the CPU's time; being ahead is fine. When the CPU writes, the other domain must not yet have used state that the write changes. So a domain that runs ahead keeps a short log of the channel state it has read, each entry with its time. A CPU write that lands before one of those reads forces a **rollback**: restore the domain's snapshot and replay. That is exact. With the rollback the per-cycle trace is identical, so by the charter's rule ("a tier is defined by its proof") it is a `-fast` technique if the lockstep proves it, and turbo otherwise. - **Producers** (the RDP back end, the VI filters, the AI) touch nothing that the CPU reads until a join. Only they move to other cores cheaply. ## Components Each section gives the backends, their tiers and the sync points. Tiers follow the charter: what keeps every bus cycle identical goes in `-fast`; what keeps only the observable contract goes in turbo; recompilation is a turbo fast path with the interpreter as fallback; anything that changes results is a named concession, off by default. ### VR4300 (vr4300-python, then -rust, -rust-fast, -rust-turbo) | Backend | Tier | What it changes | Sync | Notes | | --- | --- | --- | --- | --- | | Interpreter (handler per decode row, stall rules, caches, TLB, write buffer) | x-python, x-rust | nothing: it is the specification and its transcription | every non-RDRAM SysAD transaction; RDRAM transactions while another master's window is open; interrupts at instruction boundaries (vr4300-python handoff-brief) | x-python at 0.02-0.2 M instructions/s (HYPOTHESIS, domains-and-speed.md) | | Exact fast interpreter: packed decode record, per-instruction cost table, scoreboard interlocks, one deadline compare, deferred cycle accumulation flushed at each transaction | x-rust-fast | layouts only; every bus cycle identical | as above | the SH-2 lesson: the time-keeping is the work | | Cached interpreter keyed by I-cache line (decoded line mirrors the cached line; dropped when that line refills, is invalidated by CACHE, or the TLB entry that mapped it changes) | x-rust-fast if exact by lockstep (it removes no bus cycle: I-cache hits make none) | fetch tag check once per line; micro-TLB lookup once per block | as above, plus: block entry checks `now + bound < deadline` | **exact by construction for cached code** if DMA does not snoop the I-cache. HYPOTHESIS: games call osInvalICache after loading code, which suggests no snooping (vr4300-python timing.md); a test ROM decides it. Uncached (kseg1) code is invalidated by RDRAM writes to its page | | Memoized block timing (static cycles of a block for its entry scoreboard state, added at once; dynamic costs added only at misses and transactions) | -fast if exact (the SH-2 study's "memoize the scheduler, not the decode") | removes per-instruction time-keeping in straight-line code | block exits at the first transaction or miss | ares's recompilers keep a "deferred clock" flushed at sync points (OBSERVED, ISC source: `ares/n64/rsp/recompiler.cpp` notes) | | Block compilation to native code | turbo, `recompile: native` | dispatch and register traffic | blocks end at every declared sync point; a cycle counter is checked at block entry against the deadline | ares: SLJIT-based recompiler; blocks indexed by RDRAM section, with dirty flags per section and per line, and the running block ended when it writes its own section (OBSERVED, `ares/n64/cpu/cpu.hpp`, ISC) | | Block compilation to WebAssembly | turbo, `recompile: wasm` | as above, in the browser | as above | many blocks go into one module per hot region, because module compiles cost milliseconds (HYPOTHESIS; v86 does run-time wasm for x86, JIT proposal) | | Idle-loop **fast-forward**, exact: a polling loop whose only input is one channel value, whose next change time is known (the other domain is ahead), and whose cycles per iteration are fixed | turbo (it skips reads that the contract reconstructs: the same value at known cycles) | skips iterations; interrupts and Count/Compare still fire at their exact cycles | the loop's exit | distinct from the JIT proposal's **idle-loop skipping**, which is inexact and a concession | The fallback for every row above is the row before it, as the charter requires. Invalidation sources, from the memory kinds (handoff-brief): the CPU's own stores (only uncached code sees them before a refill), PI, SP and SI DMA into RDRAM, the RDP's writes, CACHE operations, TLB writes (TLBWI, TLBWR) for mapped code (GoldenEye runs mapped code; HYPOTHESIS until the board shows it), and a state load. **Refinement of domains-and-speed.md.** That page estimated a cached interpreter at "1.5-3x over the plain -fast interpreter, because decode and dispatch dominate". The SH-2 evidence contradicts the reason: decode was 3.6 %. The VR4300 cached interpreter's expected gain is the fetch path plus the decode, HYPOTHESIS x1.15-1.4. The larger gain is the time-keeping, which belongs in `-fast` if it stays exact. ### R4300 FPU (COP1, inside vr4300) Rust's `f32`/`f64` follow IEEE 754 for the basic operations, the same standard the VR4300 follows. Rounding modes, flush-to-zero, unimplemented-operation exceptions and the N64-visible cause bits do not map onto host flags (vr4300-python fpu.md). The exact path is software checks around host arithmetic. Fast paths are allowed only where the inputs cannot reach a special case, and that test is itself a few compares. wasm has no rounding mode control, so non-nearest modes take the software path there. Nothing here is a concession; it is all `-fast` work. ### RSP (rsp-python, then -rust, -rust-fast, -rust-turbo) The RSP is the natural **reusable engine**. Its code lives in 4 KB of IMEM written only by DMA and by CPU stores. It has no caches and no interrupts, so its timing within a block depends only on the pipeline state at entry. Its tasks repeat every frame. | Backend | Tier | Notes | | --- | --- | --- | | Interpreter, lane by lane, 48-bit accumulators, the pipeline's dual-issue and latency rules | x-python, x-rust | readable first (rsp-python decision 2) | | Vector unit in SIMD: one 128-bit register per vector register; SSE4.1 or NEON natively, **WebAssembly SIMD128** in the browser | x-rust-fast (exact, only a layout) | 8 lanes x 16 bits fit one register. Clamping and accumulator splitting are exact integer operations. cen64 does this with SSE intrinsics (OBSERVED, BSD-3-Clause, `rsp/vfunctions.c`) | | Cached interpreter with memoized timing: blocks keyed by **IMEM content hash, start PC and entry pipeline state**; timing precomputed per key | -fast if exact by lockstep; turbo otherwise | ares keys RSP blocks by IMEM hash, pipeline hash and start address, with a dirty mask over IMEM (OBSERVED, `ares/n64/rsp/rsp.hpp`, `recompiler.cpp`, ISC) | | Block compilation (native or wasm) | turbo, `recompile: native` / `wasm` | the vector unit gains more from SIMD than from compilation; the scalar unit and dispatch gain from compilation | | RSP on its own thread, **ahead of the CPU**, with a channel-read log and rollback | -fast if the lockstep holds the per-cycle trace, turbo otherwise | the CPU's SP_STATUS polls then read a value already computed; a CPU write to SP_STATUS, SP DMA registers or IMEM/DMEM that lands before an RSP read in the log forces a rollback (snapshot: 8 KB plus registers) | | Microcode HLE (graphics or audio tasks replaced by native code) | **concession**, off by default (rsp-python decision 3) | changes precision, ordering and the timing of RDRAM traffic; recorded cost measured against the low-level run | **IMEM uploads and invalidation.** libultra's task start DMAs a boot microcode and then the task's microcode into IMEM for each task (HYPOTHESIS from the libdragon and libultra model; the board will measure it). Microcode overlays also DMA new code into IMEM while the task runs. Invalidation by address alone would throw away every decoded block several times a frame. Keying by content instead: - each SP DMA into IMEM marks its range dirty; a CPU store into IMEM does the same; - at a block's entry, if its range is dirty, its bytes are hashed again (4 KB at most; a few microseconds, a few times a frame: HYPOTHESIS, negligible), and the block is looked up in a content-addressed pool that outlives the upload; - so a microcode uploaded again finds its decoded blocks and timing still there. This is "microcode-level caching" without HLE, and it is exact, because a block is reused only for byte-identical code with an identical entry pipeline state. **RSP sync points:** COP0 reads and writes (SP and DPC registers); SP DMA starts and completions; BREAK; DMEM writes that the RDP's XBUS may read (only while DPC_STATUS selects XBUS and DPC_CURRENT has not passed them); and the CPU's IMEM/DMEM accesses (the collision rule, rsp.md, U16). ### RDP (in the board; n64-python, n64-rust, -fast, -turbo) **The judge is the software rasteriser in the specification.** It works pixel by pixel through the pipeline stages, models the hazards (RH#001-004, the 2-cycle bugs) as the one-pixel lags they come from, and keeps the sync-corruption tables as data (handoff-brief decision 4; rdp.md). Every other backend is held to it. | Backend | Tier | Notes | | --- | --- | --- | | Software rasteriser, sequential | x-python, x-rust | the judge | | Front end / back end split: edge walk, spans, timing, DPC counters and the hazard map on the CPU's thread; shading in a back end that may lag behind | -fast (the RDRAM contents at every join are identical; the per-cycle trace is identical if the joins are exact) | needs X3: timing must depend on geometry and modes only | | Back end in scanline bands on N threads | -fast if exact | **only where no state crosses pixels.** The hazards the specification models (COMBINED read in cycle 0, TEXEL1 in 1-cycle mode, the 2-cycle cross-talk, state changes without the required sync) carry shaded values from one pixel to the next, so a primitive in such a mode cannot be split. The front end can tell from SET_COMBINE, SET_OTHER_MODES and the sync stream, and sends such primitives to sequential code | | Back end on the GPU (Vulkan, Metal, WebGPU compute), integer arithmetic only | turbo (a second implementation held to the per-pixel observables) | below | | Upscaling, texture replacement, "enhancements" | concessions (they change the video output) | host presentation outside the observable contract is not allowed | **GPU compute held to identical per-pixel observables.** The observable contract, for the RDP: - every RDRAM byte **and hidden bit** the back end writes, as seen at each join; - the DP interrupt's cycle, and DPC_STATUS, DPC_CURRENT and the DPC_CLOCK/BUFBUSY/ PIPEBUSY/TMEM counters at each CPU or RSP read. These come from the front end, so the GPU never decides them; - the VI's picture, which reads that memory. The gate replays command lists (captured from the board: start state, command words, the RDRAM pages they read) through the GPU backend and through the software rasteriser, and compares CRCs of every page written, with the hidden plane, at every join. GPUs and drivers differ. parallel-rdp's README records some AMD drivers that fail its conformance without a workaround for 8/16-bit arithmetic (OBSERVED, README at `1cecd04`). So a GPU backend is **proven per device**: the host runs a short conformance set on start-up and uses the GPU path only if every CRC matches (decision X5). **The CPU/RDP sync problem, stated.** The back end lags the front end. Four hazards must be caught: 1. **RAW: reading RDP output.** The CPU (uncached, or a cache fill), the RSP's DMA, a PI DMA from RDRAM, or the VI reads memory the back end has yet to write. The read must wait until the back end has finished every command the front end had started before the reader's time. 2. **WAR: overwriting RDP input.** The CPU, a DMA or the RSP writes memory the back end has yet to read: a texture source for LOAD_TILE or LOAD_BLOCK, a command list in RDRAM, or a colour or Z buffer that is read back. The back end must take the old bytes, either by joining first or by copying the page before the write. 3. **WAW: both writing.** The CPU and the RDP write the same buffer, for example a HUD drawn by the CPU over an RDP frame. The order of record decides, so the back end must finish before the CPU's write lands. 4. **Racing the beam.** Single-buffered drawing: the VI fetches line `y` at a known time, and the picture depends on how far the RDP had drawn. The front end knows which lines the back end will have written by that time, so the VI producer joins per line, and only when its buffer is being drawn into. **The mechanism:** a **hazard map** over RDRAM pages (1 KiB: HYPOTHESIS, to be tuned), with two bits per page: "the back end has pending writes" and "the back end has pending reads". The map is consulted on RDRAM transactions only: cache fills, write-backs, uncached accesses and DMA units. Cache hits never consult it, and the VR4300's caches make RDRAM transactions rare (numbers table). On a hit in the map the reader joins, or the writer snapshots the page. Joins are cheap for a threaded CPU back end. For a GPU they are expensive (0.1-1 ms), so a GPU backend pays only for games with few joins a frame. The host measures joins per frame and falls back to the CPU back end when they grow; that switch changes nothing observable. ### RDRAM and its 9th bit DOC: each RDRAM byte has a 9th bit, used only by the RDP and the VI. It holds the coverage of a 16-bit colour buffer, and Z's 18 bits are a 16-bit word plus its two hidden bits (rdp.md). The CPU reaches it only in MI EBus mode (n64brew RDRAM, MIPS Interface). **What the CPU's normal-mode writes do to the hidden bits is not on the wiki.** It is a new unknown, to add as U18. ares sets the hidden bits from the data on CPU writes (OBSERVED: `ares/n64/rdram/hidden.hpp`, ISC; tier 5, not hardware). That reading is HYPOTHESIS until a test ROM decides it, for example a CPU write followed by an EBus-mode read. **The memory model, cheap in every tier:** - **x-python**: two planes, `data: bytearray` and `hidden: bytearray` (one 0/1 entry per byte), and one method per access kind that says what it does to each plane. That is readable, and the cost does not matter there. - **x-rust**: the same two planes, transcribed. - **-fast**: the main plane as a flat byte array with big-endian word access, and the hidden plane **packed**: one bit per byte, so 512 KiB for 8 MiB. The CPU never touches the hidden plane on a cache hit. It touches it only at an RDRAM transaction: a 16-byte write-back updates 16 bits, which is one or two packed bytes. The RDP back end reads and writes both planes per pixel. The GPU backend keeps the hidden plane as its own buffer, as parallel-rdp does (OBSERVED, `rdp_device.hpp`: `begin_read_hidden_rdram`). - **Save states** hold both planes. So the 9th bit costs the CPU's hot path nothing. The caches already batch the CPU's accesses into transactions, and the hidden plane rides on those. ### DMA engines (PI, SI, SP, AI fetch, VI fetch) Transactions with durations (interfaces.md). A DMA's RDRAM effect may be applied **lazily**. The destination range is marked in flight in the hazard map, and the copy is brought up to the current time when anything touches that range: a CPU read, or a fetch by the cached interpreter. Otherwise the copy happens at the completion event. PI_DRAM_ADDR and PI_CART_ADDR advance as the specification says, computed from the start time and the rate rather than stepped. This is exact and `-fast` if the lockstep holds. **RDRAM contention (U1) decides whether this stays cheap.** If the specification models a CPU miss's latency as depending on which other masters are using RDRAM at that cycle, every miss becomes a sync point with every master. The design that keeps both exactness and parallelism is a **reservation table**. A DMA, the VI's line fetch and the AI's fetch each reserve their RDRAM time when they start, so their usage is known ahead. The RDP's usage is not known ahead (it depends on rasterising), and that is the hard part of decision X3. ### VI and AI Pure producers (domains-and-speed.md). The VI's filters (AA, divot, dedither, gamma) run per output pixel from the RDRAM state at each line's fetch time and the register log. They can run on a thread, or as a GPU fragment pass, held to the picture's CRC. The AI reads its buffer at known times. Both are `-fast`. ### PIF, SI and joybus Rare and slow (MClock/32). They stay inline on the CPU thread. An SI DMA's joybus frame is computed whole when it starts, and its result becomes visible at the completion event. ### The scheduler, summarised | Layer | Runs on | Talks to the CPU thread by | | --- | --- | --- | | VR4300, RCP registers, MI, PI, SI, PIF, DMA bookkeeping, RDP front end, hazard map, event queue | thread A | (itself) | | RSP (inline in A, or on thread B ahead of A with a rollback log) | A or B | channel-read log, rollback | | RDP back end (bands or GPU) | threads C.. or the GPU | command log, joins | | VI filters, AI | thread D | register log, line joins | Determinism (charter): every gate case runs single-threaded and multi-threaded, with identical traces. ## Deterministic testing across backends - **Lockstep against the interpreter at block or event boundaries.** Every backend in the tables above runs beside its fallback, with the same case table, and writes one line per boundary: CPU state, time, a CRC of every non-RDRAM transaction with its time, a CRC of RDRAM transactions where contention is modelled, and a picture CRC per join. For the cached interpreter and the compiler the boundary is every block exit (JIT proposal, proof 1). For threads it is every channel access. For the GPU RDP it is every join. - **Bus-stream equality where the contract needs it:** every value read from another domain's state, at the same cycle. RDRAM accesses that nobody else can see before the next join may be merged; that is the room the JIT has. - **Seeded faults aimed at each backend.** Each fault is one line, and each must be caught: - VR4300: a decoded line kept after a CACHE Hit_Invalidate; a block not dropped on TLBWI; the deadline computed one RCP cycle late; deferred cycles not flushed before an uncached read; the LDI interlock left out of the memoized timing; a branch-likely's nullified slot compiled as executed. - RSP: a block reused after an IMEM DMA changed one word; the entry pipeline state dropped from the key; a SIMD clamp using a signed saturate where the lane rule is unsigned; a rollback that misses a CPU write to DMEM. - RDP: a hazard-mode primitive banded in parallel; a page left out of the hazard map; a GPU path that drops the hidden plane; a join skipped before a VI line fetch. - RDRAM: hidden bits not written on a write-back. - Threads: the RSP's read log trimmed one entry early. - **Invalidation tests** (JIT proposal, proof 4): self-modifying code (cached and uncached), PI DMA into code then osInvalICache, RSP overlays, a CPU store into IMEM while the RSP is halted and while it runs. - **Never reported as hardware accuracy.** "The GPU RDP matches the software RDP" is a differential claim. ## Techniques studied, as implementation choices | Technique | Where seen | Licence: how it may be used | What it is evidence of | | --- | --- | --- | --- | | Recompiler on a portable JIT library (SLJIT), blocks per RDRAM section with dirty flags, the running block ended on writes into its own section | ares `ares/n64/cpu` | ISC: readable, code with notice | an implementation choice only | | RSP blocks keyed by IMEM hash, pipeline hash and PC; dirty mask over IMEM; deferred clock accounting flushed at helper calls and block ends | ares `ares/n64/rsp/recompiler.cpp` (its header notes) | ISC | an implementation choice only | | Hidden RDRAM bits set from the data bits on CPU writes | ares `ares/n64/rdram/hidden.hpp` | ISC | one emulator's reading of hardware: OBSERVED, tier 5 | | Vector unit in SSE intrinsics | cen64 `rsp/` | BSD-3-Clause (except `rdp/`, angrylion's: not fetched) | an implementation choice | | GPU compute RDP: tile binning, per-tile compute, hidden RDRAM as its own buffer, timeline sync with host-visible memory | parallel-rdp | MIT: readable, code with notice; lineage below | an implementation choice; its picture is tier 5 | | Dynamic recompilers, HLE graphics | mupen64plus, gopher64, simple64, Project64 | GPL or other closed boxes: never read | run only, as detectors | | Multithreaded software RDP | angrylion-rdp-plus | MAME's old non-commercial licence: closed box, run only from emu-tools-gpl2 if ever | a detector | ## parallel-rdp: lineage and validation (checked 2026-11-26) - **Licence:** MIT, "Copyright (c) 2020 Themaister" (its LICENSE). 64 files carry the MIT header (counted at `1cecd04`). - **Lineage, in the author's words (README at `1cecd04`):** "While paraLLEl-RDP uses Angrylion-Plus as an implementation reference, it is not a port, and not a derived codebase of said project. It is written from scratch by studying Angrylion-Plus and trying to understand what is going on." - **Validation history:** its conformance suite (about 150 fuzz tests) and `rdp-validate-dump` pass only when parallel-rdp's output is **bit-exact with angrylion's** (README). The author's posts give angrylion as the accuracy target (libretro.com posts, found by search 2026-11-26). We found no statement that it was validated against hardware. The README also lists **intentional differences** from angrylion where the RDP's behaviour depends on cycle-level pipeline effects: COMBINED in the first cycle cleared to zero; MemoryColor in the first 2-cycle blender cycle; alpha test and TEXEL1 cross-pixel reads in 2-cycle mode; LODFrac in 1-cycle mode; TexLOD in COPY mode. Most of these overlap the hazards our specification proposes to model: RH#002 and RH#003, and the 2-cycle bugs (rdp.md, where n64brew notes them as "not emulated by ares", which uses parallel-rdp). - **Our fetch:** the repository declares angrylion-rdp-plus (and Granite) as git submodules. In `reference/src/parallel-rdp` both submodule directories are **empty** (`git submodule status`: not initialised, checked 2026-11-26), so no angrylion source is held in this MIT repository. Its test drivers (`replayer_driver_angrylion.cpp`, `conformance_utils.hpp`) are MIT files that call angrylion as a library. One shader comment names angrylion's coverage layout as different from its own (`shaders/interpolation.h`). - **Author respect:** no statement about AI use in parallel-rdp's README, nor on angrylion-rdp-plus's GitHub page (read 2026-11-26). - **Verdict.** - *Licence:* use is allowed: readable, and code may be taken with its MIT notice. - *Provenance:* its knowledge descends from angrylion, a non-commercial source. The author's account rules out porting angrylion's code but not learning from it. Anything we take from parallel-rdp (a table, a formula, a layout) is recorded in provenance.md as "parallel-rdp (MIT), angrylion-informed by its author's account", so a later reader can tell where it came from. - *As a judge:* comparing outputs is fine. Its picture is tier 5 and **not independent of angrylion's**. Where the two agree, that is one emulator lineage agreeing with itself, not two witnesses. - *As a turbo backend as-is:* it would fail our per-pixel gate on the hazard modes by design, because it resolves them differently on purpose. Using it would need those modes as named concessions, or the front end sending those primitives to the software back end. - *Recommendation:* our own GPU back end, written from our specification, with parallel-rdp read only for its GPU techniques (binning, memory sync), under its notice (decision X4). ## Numbers **Host assumptions (HYPOTHESIS):** - A desktop core runs at 5.0 GHz. This machine's P-cores reach 5.8 GHz, and its E-cores measured 4.3 GHz (sh2-rust-fast). - A phone app's core gives 0.8x a desktop core's single-thread throughput, and the phone's browser 0.6x of that, so 0.48x (psx-python domains.md; sh2-rust measured wasm at 0.55-0.65x native). - All budgets are therefore in **desktop-equivalent host cycles per guest operation, on one core**: desktop `5.0e9 / R`, phone app `4.0e9 / R`, phone browser `2.4e9 / R`, where `R` is the guest rate. **Measured yardstick:** sh2-rust-fast (an exact SH-2 with a stage scheduler) costs about 145 cycles per instruction on an E-core (4.3e9 / 29.69e6), or about 89 on an idle P-core (about 5.5e9 / 62 M, unpinned: noisy). The breakdown is in "The answer in one page". | Component | Guest rate `R` (basis) | Desktop | Phone app | Phone browser | Exact interpreter's likely cost | Verdict | | --- | --- | ---: | ---: | ---: | --- | --- | | VR4300, peak | 93.75 M instr/s (DOC) | 53 | 43 | 26 | 25-60 with cheap time-keeping (HYPOTHESIS); 90-145 with an SH-2-style scheduler (MEASURED yardstick) | the time-keeping design decides it; browser needs `wasm` | | VR4300, typical | 60 M instr/s (HYPOTHESIS: 0.5-0.8 IPC, domains-and-speed.md) | 83 | 67 | 40 | as above | desktop and phone app fit; browser at the edge | | RSP, busy | 45 M instr/s (HYPOTHESIS: 30-70 % busy) | 111 | 89 | 53 | scalar 20-40; vector with SIMD 30-60 per instruction (HYPOTHESIS) | one core everywhere with SIMD; on the CPU thread it shares the VR4300's budget | | RSP vector lane ops | 180 M lane-ops/s (domains-and-speed.md) | 28 per lane | 22 | 13 | scalar Python-style lanes: 10-20 per lane, too slow in a browser; SIMD: ~2-4 per lane | SIMD is required (exact, -fast) | | CPU + RSP on **one** thread | 60 + 45 = 105 M/s | 48 | 38 | 23 | sum of the above | does not fit the browser; tight on a phone: hence the RSP ahead on thread B | | RDP front end | 0.15-0.7 M spans/s (HYPOTHESIS: 3-14 M pixels / ~20 pixels a span) | 7,100 per span | 5,700 | 3,400 | 200-1,000 per span (HYPOTHESIS) | cheap; stays on thread A | | RDP back end, typical | 14 M shaded pixels/s (domains-and-speed.md upper) | 357 per pixel | 286 | 171 | 160-400 (HYPOTHESIS: 400-1,000 operations at IPC ~2.5) | desktop 0.5-1.1 cores; phone 0.6-1.4; browser 0.9-2.3 (wasm SIMD helps) | | RDP back end, fill-bound worst case | 62.5 M pixels/s (DOC: 1-cycle peak) | 80 | 64 | 38 | 160-400 | 2-5 cores desktop, 2.5-6 phone, 4-10 browser: the GPU's case | | VI filters | 4.6 M pixels/s (320 x 240 x 60) | 1,085 | 868 | 521 | 50-150 (HYPOTHESIS) | a fraction of a producer thread | | AI | 0.1 M samples/s (48 kHz stereo) | 50,000 | 40,000 | 24,000 | negligible | | | RDRAM transactions (CPU misses, write-backs, uncached; DMA units) | 1-3 M/s (HYPOTHESIS: 2-5 % of 60 M instructions miss, plus DMA) | 1,700 per transaction | 1,300 | 800 | arbitration, hazard map, hidden bits: 20-60 (HYPOTHESIS) | cheap if contention uses reservations (X3) | | Channel syncs (uncached RCP accesses, SP/DPC) | 0.1-9 M/s (9 M while polling: cost model above) | 556 at 9 M | 444 | 267 | inline 20-100; cross-thread 500-1,500 | inline, or the other side ahead; never a conservative cross-thread handshake | | Python spec (for scale) | VR4300 0.02-0.2 M instr/s (domains-and-speed.md) | | | | | 1/470 to 1/4,700 of the peak rate: slices only | **What the table says, without recompilation:** - **Desktop:** VR4300 on thread A at 25-60 cycles against 53-83: fits *if* the time-keeping is cheap. The RSP ahead on thread B, the RDP back end on 1-2 threads, the VI on one: full speed, HYPOTHESIS. - **Phone app:** the VR4300 at 43-67 cycles is tight and needs the cached interpreter and memoized timing. The RSP on a second performance core. The RDP back end needs 1-2 cores, or Metal compute in fill-heavy scenes. At the edge in heavy 3D games. - **Phone browser:** the VR4300 at 26-40 cycles is below an exact interpreter's likely cost, so it needs `recompile: wasm` (allowed: the page hands Safari wasm, it does not map executable memory itself; JIT proposal). The RDP needs WebGPU compute or 2+ worker threads. Expect a named concession in the heaviest games (RSP HLE, or coarser sync), or a lower rate stated in the capability record. The capability record will say this plainly once measured, as the charter requires: `recompile: none` meets full speed on desktop, probably on a phone app, and not in a phone's browser. ## Measure first (in this order) 1. vr4300-rust's instructions/s on a CPU-only test ROM (nemu64-test's `arithmetic`), and the profile split (scheduler, checks, fetch, handlers, decode), so it can be compared with the SH-2's. 2. rsp-rust's instructions/s on one audio task, plain and with SIMD (rsp-rust-fast). 3. The board's channel-access rate per emulated second in a game slice: uncached RCP reads and writes, SP_STATUS polls, RDRAM transactions. These are the inputs to the cost model. 4. The software RDP's ns per pixel on a captured display list, by cycle mode. 5. Joins per frame in a few games, for the GPU decision. ## Open decisions for Aubrey (each with my recommendation) - **X1. Time-keeping as specification data.** The VR4300 and RSP specifications state each instruction's static cost and stall rules as data, which the Rust tiers turn into tables and memoized block timing. *Recommend* yes. It is decision 2 of vr4300-python and the JIT proposal's "timing as data", and the SH-2 measurement says it is the lever. - **X2. RSP ahead of the CPU with rollback**, as a `-fast` technique when the lockstep holds the per-cycle trace. *Recommend* yes, after rsp-rust-fast's SIMD. It is the only way the RSP gets its own core without a cross-thread handshake on every poll. - **X3. The RDP's timing model must not depend on shaded pixel values** (Z results, alpha compare, coverage), unless a judge shows that it does. *Recommend* yes, marked HYPOTHESIS, with U7 widened to cover it. If a judge shows data-dependent timing, the front/back split loses exactness, and the GPU backend becomes a timing concession or a per-command join. - **X4. Our own GPU back end rather than parallel-rdp as-is.** *Recommend* our own, in turbo, written from the specification, with parallel-rdp (MIT) read for its techniques and credited. parallel-rdp resolves the hazard modes differently on purpose, and its validation is against angrylion, not hardware. Using it as-is would make those modes concessions. - **X5. GPU backends proven per device.** The host runs a conformance set at start-up and uses the GPU path only on a pass; the capability record gains `gpu_backend: verified | failed | absent`. *Recommend* yes. It is a capability change, so Aubrey's call. - **X6. Exact idle-loop fast-forward** is turbo, not a concession, when its conditions hold (one channel input, a known next change, fixed iteration cost). The JIT proposal's inexact skipping stays a concession. *Recommend* recording the distinction in the JIT proposal's concessions list. - **X7. U18, the hidden bits under normal-mode CPU writes:** add it to the handoff brief's unknowns, with a test ROM to write (a CPU write, then an EBus-mode read). *Recommend* yes.