# Domains and speed Read with the charter's "Domains and channels" and the JIT proposal (emulator-lineage `docs/proposals/2026-11-jit.md`, draft, Aubrey's to accept): its family table already lists the Saturn as "2 SH-2s; 68EC000 sound + SCSP; SCU (+DSP); VDP1; VDP2; CD block", JIT "likely for the SH-2s on weak targets". This page proposes the Saturn's domains, channels and sync points, says which processors need a cached interpreter where recompilation is forbidden (the iPhone), and shows the arithmetic. Everything here is a proposal for the specification to confirm. ## Domains A domain is a part on its own clock (charter). The Saturn has three crystals that do not divide into each other: the PLL for the CPUs, SCU and VDPs (26.87 or 28.64 MHz NTSC), the SCSP's 22.5792 MHz, and the CD block's (20 MHz by OVW) plus the SMPC's 4 MHz (DOC: CMH "NTSC Saturn timing"; OVW). | Domain | Holds | Clock | Why one domain | | --- | --- | --- | --- | | **C: CPU** | master SH-2, slave SH-2, their caches, Work RAM-L/H, boot ROM, the SCU (bus arbiter, DMA, interrupts, timers) and the SCU DSP, the cartridge | PLL | the two SH-2s share one bus and memory with no cache snooping (DOC: DUAL 1.1, 7.0); the SCU arbitrates every access they make outside work RAM. Tightly coupled: the charter's own example | | **V: video** | VDP1 (VRAM, two frame buffers), VDP2 (VRAM, CRAM) | PLL, dot clock / 4 | VDP2 scans out VDP1's display buffer and decides VDP1's frame change; they talk to C only through the B-bus and interrupts | | **S: sound** | 68EC000, SCSP (slots, DSP, timers, MIDI), sound RAM | 22.5792 MHz | own crystal; talks to C through the B-bus window and one interrupt | | **D: CD** | CD block (high-level model, or SH-1 + gate array + drive), MPEG card | its own | own crystal and CPU; talks to C through A-bus CS2 and to S through the CD-DA line | | **M: SMPC** | the system manager (functional), RTC, pad ports | 4 MHz + 32.768 kHz | own clock; talks to C through its registers and two interrupts, and drives reset and clock lines into every domain | Optional split inside V: VDP1 and VDP2 as two domains (VDP1 draws into the back buffer while VDP2 shows the front one; they meet at the frame change and the sprite layer). Optional split inside C: the SCU DSP as its own domain (it reaches the rest only through its ports, its DMA command and its end interrupt; SCU 2.3, ch. 4). Both splits are for `-fast` threads; the specification keeps them inside their domains unless a channel needs naming anyway. ## Channels (where domains meet) | Channel | From -> to | Mechanism | Sync point for | | --- | --- | --- | --- | | B-bus to VDP1/VDP2 | C -> V | SH-2 or SCU-DMA reads and writes of VRAM, frame buffer, CRAM, registers (05C00000-05FBFFFF) | every access (reads of VDP1 EDSR/COPR/frame buffer return what V has drawn so far) | | B-bus to sound | C -> S | reads and writes of sound RAM (05A00000) and SCSP registers (05B00000) | every access | | A-bus CS2 | C <-> D | CD registers and the data transfer register (05800000-058FFFFF) | every access | | SMPC registers | C <-> M | COMREG/SF/IREG/OREG/SR/PDR/DDR/IOSEL/EXLE at 00100000 | every access; SF polling is the hot one | | interrupts into the SCU | V, S, M -> C | V-blank in/out, H-blank in, sprite draw end, sound request, system manager, pad (SCU table 2.1) | the edge's time: C must not run past it | | SCU timers | V -> C | timer 0 counts H-blanks, timer 1 counts dots (SCU 3.4) | derived from V's timing; computable ahead if V's mode is known | | INTBACK start | V -> M | collection starts at V-blank out (SMPC 2.4) | V-blank out | | reset and clock lines | M -> C, S, D | SSHON/OFF, SNDON/OFF, CDON/OFF, SYSRES, CKCHG352/320, NMIREQ | the command's completion time; a clock change re-times C and V | | CD-DA audio | D -> S | the SCSP's digital input (EXTS) | none needed: a timestamped sample FIFO (pure producer) | | light gun | M -> V, C | EXLE: a port pin latches VDP2's HV counter and interrupts the SCU (CMH) | the trigger's time | | MINIT/SINIT | C (SH-2) -> C (other SH-2) | a 16-bit write raises the other CPU's FRT input capture (DUAL 1.2) | inside C: ordinary serial order | **The two SH-2s.** They share the bus and all memory; each has its own 4 KB cache, and the cache does not snoop (DUAL 7.0), so a write by one CPU never updates the other's cache and stale reads are real behaviour the board must reproduce. Because the SH7604's cache is write-through (sh2-python's cache module and HM), every write and every miss is a shared-bus access: roughly one access in every few instructions is a point where the other CPU could observe or interfere. That is why the pair stays one domain and one thread (the charter's advice): the specification interleaves them at bus-transaction level in one order of record (the earlier bus time first, master first on a tie, the BSC's arbitration deciding waits), and only cache hits and on-chip work run without consulting the other CPU. ## Sync points and code invalidation (the JIT proposal's four declarations) - **Sync points**: every row of the channel table above, plus interrupt sampling on both SH-2s and the 68EC000. A block or a thread may run freely up to the next one. - **Memory kinds and writers** (what invalidates compiled or cached code): | Memory | Kind | Written by | | --- | --- | --- | | boot ROM, cartridge ROM | ROM | nobody | | Work RAM-H | RAM, code lives here | both SH-2s, SCU-DMA, SH-2 DMAC (CD transfers), the SCU DSP's DMA | | Work RAM-L | RAM, code possible | both SH-2s, the SH-2 DMAC (SCU-DMA forbidden by SCUF No. 04: what happens if used is U9) | | each SH-2's cache | cache | its own CPU; purged by CCR or the associative purge space (sh2-python models both) | | sound RAM | RAM, 68EC000 code lives here | 68EC000, SCSP DMA, both SH-2s, SCU-DMA | | SCU DSP program RAM | RAM | the CPU through the port, only while the DSP is stopped (SCU 2.3) | | SCSP DSP program (MPRO) | registers | 68EC000 or SH-2 writes to the SCSP register window | | CD block RAM (low-level only) | RAM, SH-1 code? | SH-1, gate array | - **Timing as data**: sh2-python already holds the SH-2's per-instruction pipeline classes and states from PM table 7.2 (the JIT proposal's own example); m68000-python holds the 68000's. The SCU DSP takes one cycle an instruction (to confirm in SCU ch. 4: HYPOTHESIS until checked against a test). - **Restricted semantics**: applies to the CPU cores (sh2-python, a future sh1-python and scudsp-python), not to the board. ## Which processors need a cached interpreter where JIT is forbidden | Processor | Need | Why | | --- | --- | --- | | SH-2 pair | **yes** | the dominant cost (arithmetic below); code runs from Work RAM-H and is invalidated by DMA, by the other CPU and by cache purges, all declared above | | SH-1 (low-level CD block only) | **yes**, or avoid it | 10-13 M instructions a second on top of the pair; the high-level CD block avoids the cost entirely (cdblock.md) | | SCU DSP | predecode only | at most 256 instructions, loadable only while stopped: decode once at load and the "cache" never goes stale while it runs; exact, so it belongs in `-fast` | | SCSP DSP | predecode only | a fixed 128-step program re-run every sample: decode each MPRO word when written. Skipping no-op steps is exact only if a no-op step has no side effect (the TEMP ring pointer moves per sample, not per step: HYPOTHESIS) | | 68EC000 | no | about 1.3 M instructions a second (below); the existing -fast core covers it | ## The arithmetic: instructions per second Clocks: SH-2 28.6364 MHz in 352 mode (26.8741 in 320 mode; SMPC p. 3), SCU DSP half that (OVW 3.2), SCSP 22.5792 MHz, 68EC000 11.2896 MHz (SCSP table 2.2), SH-1 20 MHz (OVW). **SH-2 pair.** An SH-2 issues at most one instruction a state, so the ceiling is 2 x 28.64 M = **57.3 M instructions a second**. Real code runs slower: - MAME 0.285 booting the US BIOS (OBSERVED, `scripts/mame_trace.py --frames 3`, this phase): the master ran 1,078,104 instructions in 1,347,611 of its cycles, 1.25 states an instruction. MAME's SH-2 timing is approximate, so this is a detector's figure. - sh2-rust's benchmark loop (its docs/status.md): 1.333 states an instruction with the cache on, 4.2 with it off on the 32X's SDRAM. - Taking 1.33-2.5 states an instruction for cached game code on Work RAM-H (HYPOTHESIS: no Saturn game has been measured): 28.64 / 1.33 = 21.5 M and 28.64 / 2.5 = 11.5 M per CPU. A busy master with a half-busy slave: about 19 + 10 = **29 M**; both busy at the cached rate: **43 M**. **68EC000.** 11.29 MHz at 8-10 clocks per instruction (a typical 68000 mix, HYPOTHESIS): **1.1-1.4 M**. **SCU DSP.** 14.32 MHz, one instruction a cycle while running: up to **14.3 M** in the frames it runs, 0 when idle (most games run it little or not at all: HYPOTHESIS, to measure by logging DSP starts per game). **SCSP.** DSP: 128 steps x 44,100 = **5.64 M steps** a second whenever a program is loaded. Slots: 32 x 44,100 = **1.41 M slot-samples** a second. **SH-1 (low-level CD only).** 20 MHz at 1.5-2 states an instruction: **10-13 M**. **Totals** (instruction-like steps per emulated second): | Case | SH-2 pair | 68EC000 | SCU DSP | SCSP DSP | SH-1 | Total | | --- | ---: | ---: | ---: | ---: | ---: | ---: | | typical, high-level CD | 29 M | 1.3 M | 1 M | 5.6 M | 0 | **37 M** | | heavy, high-level CD | 43 M | 1.4 M | 14.3 M | 5.6 M | 0 | **64 M** | | heavy, low-level CD | 43 M | 1.4 M | 14.3 M | 5.6 M | 13 M | **77 M** | Video on top: VDP2 shows 453.68 dots x 263 lines x 60 = **7.16 M dots** a second in 352 mode (425.33 x 263 x 60 = 6.71 M in 320 mode), each composed from up to six layers; VDP1 can write up to one pixel a clock (28.6 M a second) at its ceiling (VDP1 p. 21). ## What that means per tier - **saturn-python** (PyPy): sh2-python reports 1.33-2.38 M SH-2 instructions a second (its docs/validation.md, "Speed"), while sh2-rust's status reports the reference at about 0.1 M on PyPy on the same loop (C7: to rerun on a quiet machine). Even at the better figure the SH-2 pair alone is 29 / 1.33 = about **22 times slower than real time**, before VDPs and sound: a frame takes seconds. That is era 3 as the charter describes it: the specification runs short, targeted cases (a BIOS boot, a test program, a few hundred frames of a game), never long play. - **saturn-rust**: sh2-rust gives 22-45 M a second natively and 20-27 M as wasm on one core (its docs/status.md). Native: one core covers the typical pair (29 M) and is at the edge of the heavy case (43 M); V, S and D go on other threads. Browser: 20-27 M is below even the typical pair, before anything else on that thread. - **saturn-rust-fast**: the family's -fast forks have won x1.4-x1.9 (sh2-rust's status); that brings wasm to roughly 28-51 M for the pair, around the typical need. Threads per domain (C, V, S, D) are required here, and the SCU and SCSP DSPs' predecoding. - **saturn-rust-turbo**: the SH-2 cached interpreter (decode once, replay handler sequences, invalidated at the declared writers above) is the first lever on phones and on the no-JIT iPhone; recompilation (native or to WebAssembly) only where allowed and only if the cached interpreter does not pay (JIT proposal, "Targets that forbid recompilation"). None of the speed figures above is measured on a Saturn workload: the 1.33-2.5 states range, the slave's share and the DSPs' duty cycles are hypotheses to replace with the board's own counts once it runs games.