# Status **Forked 2026-11-25** from sh2-rust `fcb9dae` (remote `upstream`, the local checkout), which transcribes sh2-python `8824075`. sh2-rust's own status (its rungs' history, the repin, the rung 2 replay counts, rung 6 at `0d61a66` and `8824075`) is in `git show fcb9dae:docs/status.md`; this file is the fork's. Every number below was measured on 2026-11-25 on the shared i9-13900K (load 7-20 on 32 cores, other agents' work). "Identical" means byte-identical traces: every bus cycle (address, width, kind, the state it starts on, the value), every step's states, the CPU state per slice. Nothing here is a hardware claim. ## The gate `scripts/ladder.sh` (the reference, sh2-python at the pin, judged through its cached traces in `external/reference-cache/8824075c0907/`, copied from sh2-rust; a private clone of sh2-python at the pin in `external/sh2-python-pin` is used when present, because sh2-python's main moved to `97293f6` during this work), plus `scripts/upstream.sh` (rung U, against sh2-rust itself). The fork's defaults for a shared machine: `JOBS=2`, and rung 2 as the 2,000,000-instruction bus-lockstep prefix of each MAME trace (`FULL=1` adds the four full replays, 129 M instructions, about ten minutes on one core: not run here). | Rung | Command | Count at `61c7689` (main) | | --- | --- | --- | | fmt, clippy | `scripts/ladder.sh` | clean | | tests | `cargo test --release` | passed | | 0 | `scripts/rung0.sh` | 66,078 table lines identical | | 1 | `scripts/rung1.sh` | 16,600 of 16,600 against expected.txt.gz; 16,600 lockstep identical | | 2 | `scripts/rung2.sh` (`FULL=0`) | 4 of 4 MAME prefixes, 2 M instructions each (6.72-6.92 M bus callbacks) identical | | 3 | `scripts/rung3.sh` | 268 of 268 | | 4 | `scripts/rung4.sh` | 168 of 168 | | 5 | `SEED=1`, `SEED=2 scripts/rung5.sh` | 114 of 114; 50 of 50 | | U | `scripts/upstream.sh` | 900 of 900 scenarios (every family above plus fuzz and fresh-chip seeds 3-8) and 4 of 4 MAME prefixes of 4 M instructions (13.1-14.4 M callbacks), identical to sh2-rust `fcb9dae` | | 6 | `FAULTS=1 scripts/ladder.sh` or `scripts/seeded_faults.py --jobs 4` | **120 of 120 counted faults caught** (125 faults, 5 equivalent mutants noted, not counted; 2026-11-26, at `49a009d`'s code: section below) | The whole ladder, warm, takes 46 s at load 7-13; rung U 1.5 minutes. ## Rung 6 in the fork `scripts/seeded_faults.py` is sh2-rust's 111 faults plus 14 for the fork's own code, each a one-line break applied to a copy of the crate with fresh timestamps and judged by the rungs in order of cost (as in sh2-rust: cargo test, rung 0, 1, 3, 4, 5, rung 2's 300,000-instruction prefix). Run 2026-11-26 01:43-01:53, `taskset -c 16-23 nice -n 19 seeded_faults.py --jobs 4`, 9 min 18 s wall, load average 8.7 at the start and 18.4 at the end (32 cores). - **Carried over:** of sh2-rust's 111 anchors, only fault 23 ("LDC and friends do not block an interrupt (outside a slot)") no longer occurred exactly once: step 1 made the line `self.no_interrupt = o.blocks;`, which the delay-slot path shares. Its anchor is now the line with the retire before it (`self.retire(o.plan, pc as i64 + 2);`), the same break (no interrupt blocking after an ordinary instruction). The other 110 apply unchanged; the faults on the six tables (`IMPLICIT_PR`, `INTERRUPT_DISABLING`, ...) still reach `step` because the `Op` record is built from those tables. - **New, the fork's code (faults 112-125):** in the `Op` record (cpu.rs) a plan or handler taken from a neighbouring opcode (bit 8, bit 0 flipped), the load destination dropped, the load-use registers dropped, the two swapped, slot-illegal never set, blocking never set; in `step` (core.rs) the delay slot's `no_interrupt = o.blocks` dropped (sh2-rust had no fault on that line); in the plan arrays (pipeline.rs) the MA array one entry late, a three-MA sequence opening two, every MA at the first MA's slot, `Plan.last` one slot late for a plan with no MA, the last MA taken as the first, and `Plan.last` one slot past the last MA. Rung 0 dumps the six source tables, not the record, so these must be caught by behaviour, and were. - **Result:** the unbroken copy passes every rung; **120 of 120 counted faults caught**. First catches: cargo test 14, rung 0 8, rung 1 22, rung 3 21, rung 4 5, rung 5 50 (rung 2's prefix, again, never first). The 13 counted new faults: cargo test 5, rung 1 2, rung 3 5, rung 5 1 (the delay-slot blocking, by the edge family). Fault 23 is caught by rung 3. - **Equivalent (noted, not counted):** sh2-rust's four (MOV.L @Rm+,Rm's guarded increment, BSRF's PR order, the UBC's unmapped bytes, the reset order: reasons in sh2-rust's status and the script) and one of the fork's: fault 124, `Plan.last` = the *first* MA's slot. `retire` opens every remaining MA first (`while p_ma_left != 0`), each `ma_next` advancing the cursor to its slot in increasing order, and `advance` does nothing for a target at or before the cursor; so with any MA the final `advance(p_ex + last)` is a no-op for any `last` up to the final MA's slot (by analysis; `p_slot` moves back only in `load_pipeline_state`, between steps). `Plan.last` matters only when a plan has no MA. Its replacement, fault 125 (one slot past the last MA), is caught by cargo test (`seeded_faults.py --jobs 1 --only 125`, load 15-17). - No fault escaped, so no gate case was added. ## What changed, and what it bought Measured with `scripts/ab.sh` (three code layouts, alternating builds, best of 5 rounds, one pinned CPU: CPU 30, an E-core at 4.3 GHz, the steadiest core on this machine; absolute numbers are lower than an idle P-core's) and `scripts/ab-wasm.sh` (wasm32 under Node 22.19). Workloads: sh2-bench's four (the reference's harness_speed loop, cache off / on, on the minimal harness / on the 32X's bus with SDRAM and refresh). | Step | Commit | Kept? | Native | wasm | | --- | --- | --- | --- | --- | | 1. Decode and dispatch: one packed `Op` record per opcode instead of six tables; plans' MAs in fixed arrays | `67652c5` | yes | x1.117 / x1.053 / x1.048 over its parent | (below, with the fork point) | | 2. The 32X's common bus regions: SDRAM bursts, DMA units and the INTC's request list without allocation | not committed | no | x0.985 / x1.006 / x1.003 | x0.994 | | 3. BusContext copying: bounded by an experiment | not committed | no | x1.005 (bound) | | | (inline hints on the scheduler) | not committed | no | x1.050 / x1.018 / x1.017 | x0.987 | | 4. The cached interpreter (branch `cached-interpreter`, `eb7c747`) | branch only | no | x0.891 / x0.904 / x0.900 | x0.897 | docs/not-kept.md has every ratio and why; docs/cached-interpreter.md the prototype. **Main against the fork point** (`ab.sh fcb9dae`, 5 rounds, load 15-17): | Layout | off | on | 32X off | 32X on | overall | | --- | ---: | ---: | ---: | ---: | ---: | | default | 25.15 → 27.97 M/s | 27.44 → 30.79 | 23.79 → 25.70 | 28.03 → 31.79 | x1.112 | | nf5 | 27.78 → 28.97 | 31.43 → 31.63 | 27.11 → 28.27 | 29.28 → 32.23 | x1.048 | | nf6 | 30.04 → 31.05 | 30.12 → 31.28 | 25.81 → 28.11 | 29.95 → 31.76 | x1.055 | | wasm32, Node | 19.59 → 21.54 | 20.62 → 23.13 | 18.46 → 20.71 | 20.77 → 23.33 | x1.116 | Unpinned (`scripts/speed.sh`, best of 5 by wall time, the scheduler free to use P-cores; noisy, for scale only): at the fork point 57.4 / 62.0 / 49.7 / 62.0 M/s native and 45.1 / 46.1 M/s wasm (cache off / on, load 9); at `61c7689` 62.2 / 64.0 / 50.8 / 63.1 M/s native and 44.3 / 44.8 (minimal harness), 37.9 / 42.2 (32X bus) M/s wasm (load 14-15). **Quiet machine, 2026-11-26** (`49a009d`, exported clean; MEASURED): `scripts/speed.sh` pinned to CPU 30 (an E-core, nobody else on CPUs 29-31), best of 5 by wall time (median), load 14.8-15.5 on the other cores. Native, minimal harness, cache off / on: 28.17 (27.21) / 29.69 (27.00) M/s; 32X bus: 25.88 (25.78) / 29.94 (27.38) M/s. wasm32 under Node 22.19, minimal harness: 22.90 (21.87) / 22.78 (22.38) M/s; 32X bus: 20.63 (20.27) / 22.80 (22.55) M/s. In line with the pinned A/B's figures above (an E-core, so below the unpinned ones). **Against the 32X's need** (about 11-35 M instructions/s for the pair, at most 46 M): natively one core covers it with room, even an E-core; as wasm under Node, 20-23 M/s on an E-core and 38-45 M/s unpinned: enough for the cache-on need only on a fast core, before the rest of the board. The profile (`sh2-profile`, `scripts/profile.py`) after step 1 is flat: the stage scheduler about 37 %, the step's checks about 25 %, the fetch path about 13 %, handlers about 10 %, dispatch about 5 %. The next gains are structural (docs/cached-interpreter.md, "What would pay instead"). ## Tools added in the fork - `scripts/ab.sh`, `scripts/ab.py`: the native A/B across layouts. - `scripts/ab-wasm.sh`: the wasm A/B (`scripts/wasm_bench.mjs` now has the 32X-bus workloads, `sh2_setup` bit 1). - `scripts/upstream.sh`: rung U. - `src/bin/sh2-profile.rs` (feature `profile`), `scripts/profile.py`: a SIGPROF sampler, since `perf` is not allowed here (from gameboy-rust-fast). - On the branch: `scripts/block_faults.py`, `tests/blocks.rs`. ## Where to pick up - Merging sh2-rust: when it repins (sh2-python's main is at `97293f6`, "keep the cache out of the per-step records"), `git merge upstream/main`, move the reference cache aside, update `SH2_PYTHON_PIN` and the private clone, run the ladder and rung U. - The cached interpreter's blind spot (address-array writes) if the branch is taken further. - A realistic workload: the bench is a 15-instruction loop; a replay of real 32X code without the MAME log reading (rung 2's host is bound by reading the 4-5 GB logs) would measure what games do. Needs the board (sega32x-rust) or a captured memory image (machine-local only). - The structural levers for the browser belong to a future sh2-rust-turbo: memoized scheduler timing for blocks that only hit the cache, and threads around the SH-2 pair.