# Status **Repinned 2026-11-25 to sh2-python `8824075c090795bfb43813a6def540e12095cb3e`** (its local main, not pushed: requests R1 and R2 fixed upstream, docs/requests.md), transcribed in `state.rs`, `cpu.rs`, `cache.rs`, `bsc.rs`, `frt.rs`, `wdt.rs`, `sci.rs`, `dmac.rs` and `core.rs`; see "The repin to 8824075" below the table for its run. The table's rows are the runs at the previous pin, `0d61a66`. **Reference (the table):** sh2-python `0d61a66f2516a596a3c874e1dae79c79347e4ff3` (its main on 2026-11-25), checked by every rung (`scripts/env.sh`: `SH2_PYTHON_PIN`; a different HEAD or a modified src/ tests/ validation/ refuses to judge). **Measured at:** sh2-rust commits `e62817b` to `b81c7aa` on 2026-11-25: `src/` is the same in all of them (only scenarios, scripts and docs moved, and `doctest = false`); the machine shared, load average 75-105 on 32 cores throughout. The gate is `scripts/ladder.sh` (rungs 0-5 and the speed report; `FAULTS=1` adds rung 6). The reference's outputs are cached under `external/reference-cache//`, keyed by scenario and driver; a cold run makes them in about 30 minutes at that load (PyPy, `nice`, `PYPY_GC_NURSERY=1M`), a warm one re-runs only the Rust side. | Rung | Command | What | Count | | --- | --- | --- | --- | | fmt, clippy | `scripts/ladder.sh` (first lines) | rustup stable, `-D warnings` | clean | | tests | `cargo test --release` | rung 0's native checks: 53,752 / 11,784 encodings, the speed loop's states, state round trip, harness | 5 passed | | 0 | `scripts/rung0.sh` | `gen_decode.py --check`; every table entry (65,536 encodings: handler, plan, load-use registers, flags, disassembly at 4n and 4n + 2; 30 classes and plans; 512 on-chip addresses) | 66,078 lines identical | | 1 | `scripts/rung1.sh` | the reference's rung-1 corpus natively against `expected.txt.gz`, by ruling class; each case's result and bus CRC against the reference's | 16,600 / 16,600 (15,949 agreed, 300 undefined-code, 200 slot-illegal, 100 trapa-saved-pc, 45 mac-l-saturation, 6 div1-same-register); 16,600 identical | | 2 | `scripts/rung2.sh` | the four MAME 0.285 traces replayed to the end (the reference's replay.py, transcribed); the first 2,000,000 instructions of each in bus lockstep | the reference's counts exactly (below); 4 / 4 identical (6.72-6.92 M bus callbacks each) | | 3 | `scripts/rung3.sh` | every figure of the reference's tests/test_pipeline.py (109, as drawn and real), its other pipeline programs, the speed loop | 263 scenarios identical (42,088 trace lines) | | 4 | `scripts/rung4.sh` | tests/test_rung4.py's write-buffer and CCR-purge programs, 32xspd's loop, the 160 runnable DN P2 loops (both samples), DN's purge values | 168 scenarios identical (1.84 M steps) | | 5 | `SEED=1 scripts/rung5.sh`, `SEED=2 ...` | seeded fuzz, 40 scenarios a seed, 3,000 steps each, and (with seed 1) the 43 edge scenarios: address-error and odd-space paths, held-off interrupts, external vectors, NMI, SLEEP, DIVU overflow, every register-only ALU/shift/multiply form over boundary operands, MAC saturation, the LRU after a purge, an on-chip register sweep | 80 fuzz + 43 edge scenarios identical (241,739 steps, 658,627 bus cycles: 11,128 fills, 11,066 refreshes, 1,581 DMA, 470 vector fetches, 142 SCI bytes, 20 FTOA/FTOB changes, 1,178 WDTOVF) | | 6 | `python3 scripts/seeded_faults.py` | 93 one-line faults across every file of src/ | 89 of 89 counted caught; 4 equivalent mutants noted (below) | ## The repin to 8824075 (R1, R2) `scripts/ladder.sh` at the new pin, 2026-11-25, load 30-45, the reference cache cold (`external/reference-cache/8824075c0907/`; the old pin's stays in `0d61a66f2516/`): fmt and clippy clean; `cargo test` passed (6 in rung0.rs, one new: a fresh-chip restore of the speed loop continues exactly, cache off and on, minimal harness and 32X bus, 267 states over 200 cached steps as the reference's R1 repro now gives); rung 0 66,078 lines identical; rung 1 16,600 of 16,600 and identical; rung 2 the four replays at the reference's counts exactly (BC Racers 30,164,032 with 58 C12, Doom 34,555,701, Knuckles' Chaotix 32,543,515 with 1,387 `dma-writes`, Virtua Racing Deluxe 31,791,810) and 4 of 4 two-million-instruction lockstep prefixes identical; rung 3 **268 of 268** (263 + 5 `bench-*fresh*`: the speed loop saved half way into a fresh chip, minimal harness and 32X bus, cache off and on, one with the FRT, WDT and a cycle-steal DMA running); rung 4 168 of 168; rung 5 **114 of 114** with seed 1 (40 fuzz, 64 edges: 43 + 12 `edge-dma-ae-*` + the DMAC register sweep with DE and DME allowed + 8 `edge-fresh-*`, 10 `fresh-*`: the fuzz programs with every save-state round trip into a fresh chip) and **50 of 50** with seed 2 (40 + 10 fresh). (The ladder's own run had 106 with seed 1; the 8 `edge-fresh-*` were added after the fault run below and judged with `SEED=1 scripts/rung5.sh`.) **Rung 6 at the new pin: the 19 new or changed faults only** (`seeded_faults.py --only`; the other 92 were last judged at `0d61a66`, above): 18 new faults on the transcribed fix (a burst running on after an address error, AE not set, a faulting write still made, a 16-byte unit checking word alignment, the byte rule at H'FFFFFF00-, SLEEP not ended, vector 9, and each field of `internal` dropped or garbled on load) and fault 69 ("a burst stops after one transfer"), whose text the fix changed. First run: 12 caught (cargo test 4, rung 5 8) and 7 missed: the pending DMA address error, the LRU, the refresh's end, CMF, SSR and CHCR.TE as last read, the NMI edge detector. A same-chip round trip keeps those by itself, and the random fresh-chip programs never saved at a moment that needed them: real blind spots. The 8 `edge-fresh-*` scenarios save at exactly those moments; rerun, **7 of 7 caught**, all by rung 5. So 19 of 19; the control passes every rung. **What changed in the reference's traces** (new cache against old, by scenario key): 486 identical, 38 new (the scenarios above), and 74 of the 80 fuzz traces changed. All 74 because of R1, none because of R2: with the reference's `ChipState.internal` left out of captures (a scratch copy), all 80 fuzz traces are byte for byte the old ones. The cause is that a round trip into the **same** chip was not exact either: `load_state` set the FRT's and WDT's catch-up clocks to `chip.clock`, dropping the counts since their last catch-up (the reference's speed loop: FRC 71 instead of 144 after one round trip at step 300). The fuzz family's DMA addresses are always aligned, so R2 changes none of them. Rung 2's replay traces are identical; only their `.json` timing records differ. ## Rung 2: the MAME replays `sh2-replay` (release, cache off, as the reference's gate), against the reference's docs/validation.md "Rung 2": | Cartridge | Instructions | Interrupts injected | Attributed to MAME | First difference | Seconds | | --- | ---: | ---: | --- | --- | ---: | | BC Racers (USA) | 30,164,032 | 25,200 | 58 `mame-interrupt-after-ldc` (C12), first at #5292129 (log line 12158434) `0206A4EE LDS R1,MACL` | none | 165 | | Doom (Japan, USA) | 34,555,701 | 80 | 0 | none | | | Knuckles' Chaotix (Japan, USA) | 32,543,515 | 61 | 0 (1,387 `dma-writes`, as the reference) | none | | | Virtua Racing Deluxe (USA) | 31,791,810 | 0 | 0 | none | | Every number the reference records, exactly. The lockstep window is 2,000,000 instructions per cart: the first 300,000 are the 32X boot ROM, the same in all four (1,084,366 identical callbacks each), so a shorter window would not reach the games' code. The seeded faults use the 300,000 window (it is the last rung they reach). The replays are bound by reading the 4-5 GB logs (about 180,000 instructions/s). With the cache on (`--cache`, the master boot ROM `32x_m_bios.bin` from `MAME_ROMPATH`'s `32x.zip`, extracted to scratch at run time, `--seed`ed at H'00000000 and the cartridge at H'02000000), as the reference ran them: BC Racers 30,164,032 instructions, the same 58 C12 events, nothing else (190 s); Doom 34,555,701, nothing attributed (240 s). The same as the reference's cache-on replays. Knuckles' Chaotix and Virtua Racing Deluxe were not run with the cache (nor were they in the reference). ## Rung 6: seeded faults `scripts/seeded_faults.py`: 93 one-line faults (an off-by-one, a swapped case, a dropped line, a wrong constant) in the scheduler, the core, every instruction family, the cache, BSC, INTC, DMAC, DIVU, FRT, WDT, SCI, UBC, power, the composition and the disassembler, each built in a copy with fresh timestamps and judged by the rungs in order of cost. - **First run** (91 faults, before the edge family): 79 caught. Of the 12 missed, 4 are equivalent mutants and 8 were real blind spots: execution from on-chip space; a DMA write behind a buffered CPU store when the DMA reads no external memory first; ADDC's carry at exactly 2^32 - 1 and SUBV at exactly -2^31; CMP/STR's top byte; the LRU after a CCR purge; the associative purge (an edge program that was wrong); a VCR's top bit. Random programs and register values never reached them. - **The blind spots closed:** the edge family (rung 5) was written for them; the 8, two replacement faults for the equivalents, and every fault first caught at rung 5 while the edge family's reference traces were being rebuilt were judged again: 32 of 32. - **Result:** 89 of 89 counted faults caught. First catches: cargo test 4, rung 0 8, rung 1 20, rung 3 10, rung 4 5, rung 5 42 (rung 2's MAME prefix is never the first: the cheaper rungs catch everything it would). - **Equivalent (noted, not counted):** MOV.L @Rm+,Rm's guarded increment (the load overwrites Rm); BSRF writing PR before reading Rm (PR is not a general register); the UBC answering unmapped bytes (they can never be written); the modules' reset order reversed (by analysis, what the resets compute in between is recomputed after them; not proven). ## Speed Instructions per second on one core, `scripts/speed.sh` (release, best of 5 runs of 20,000,000 instructions, at sh2-rust `b81c7aa`, 2026-11-25), **load average 79-83 on 32 cores** (other agents' work; the CPU-time column is the better estimate, ±2 % from its 10 ms ticks): | Workload | Wall, best | CPU time, best | States per instruction | | --- | ---: | ---: | ---: | | the reference's `harness_speed` loop, cache off | 37.1 M | 42.6 M | 1.891 | | the same, cache on | 45.3 M | 45.5 M | 1.333 | | the same loop on the 32X's bus (SDRAM + refresh, 16-bit area 0), cache off | 22.6 M | 23.0 M | 4.200 | | the same, cache on | 32.2 M | 40.8 M | 1.333 | | wasm32 under Node 22.19 (V8 12.4), cache off | 21.3 M | | 1.891 | | wasm32 under Node, cache on | 19.6 M | | 1.333 | The ladder's own run at `65ed883` (load 52-73, 12 min 54 s for rungs 0-5 warm) gave, by CPU time: 47.6 M (off), 34.5 M (on), 23.3 M and 46.5 M (32X bus, off / on); wasm 20.7 M and 21.0 M. Run to run on this shared machine the same build moves by up to a third (the cache-on loop 30-45 M), so read the rows as ranges. An earlier wasm run at load ~84 gave 25.7 M / 25.9 M (off / on): the browser's figure is 20-27 M (the rerun at load ~50 below: 27.3 M). The reference on the same loop: PyPy about 0.1 M, CPython about 0.2 M (its docs/validation.md). The loop is tight and runs from the cache; real 32X code (more misses, SDRAM bursts, the slave's contention) will sit nearer the 32X-bus rows. **Against the 32X** (corrected 2026-11-25: the brief's "1.5 M instructions a frame, 90 M a second" was wrong). Each SH-2 runs at 23.01 MHz and issues at most one instruction a state, so the pair's ceiling is 46 M instructions a second; the bench's own states per instruction give the real need: 1.333 states (cache on) is 17.3 M per SH-2, **about 35 M a second for the pair**; 4.2 states (cache off on the 32X's SDRAM) is about 11 M for the pair. Real games sit between, and lower when either CPU waits or sleeps. One core of this interpreter gives 27-45 M natively and 20-27 M as wasm (rerun at load ~50: 42.3 / 44.6 / 37.8 / 27.1 M native, 27.3 / 20.8 M wasm). So natively one core already covers the pair before the 68000, the VDPs and the board (which can run on other threads, charter "Domains and channels"); in the browser it is at the edge of the cache-on need, before the rest of the board. The family's `-fast` forks have won x1.4-x1.9 over their transcriptions; a cached interpreter in a turbo tier (proposals/2026-11-jit.md) is the next lever for the browser, recompilation only if those do not pay. Measured here: the interpreter only; the rest is an estimate. ## Not transcribed The reference's `debug.py`, `trace.py`, `console.py`, `__main__.py` (tools); the lockstep has its own trace format (scripts/reference_trace.py). ## Where to pick up - The reference's `debug.py`/`console.py`/`trace.py` are not transcribed (tools). - Upstream requests R1 and R2 (docs/requests.md) are fixed in sh2-python `8824075` and carried down (the repin above). The next repin goes the same way: change `SH2_PYTHON_PIN`, move the reference cache aside (its directory is keyed by the pin, so nothing old is reused), transcribe the change, run `FAULTS=1 scripts/ladder.sh`. - The pin `8824075` is sh2-python's local main, not yet on GitHub: push sh2-python first. - Not run: the cache-on replays of Knuckles' Chaotix and Virtua Racing Deluxe (the reference did not run them either); a quiet-machine speed measurement; the A/B layout method (that is `-fast`'s, with its scripts/ab.sh).