# Domains and speed Where the DS's **domains** and **channels** fall (charter, "Domains and channels"), and whether the board can reach real time without recompilation (charter, capabilities: `recompile: native | wasm | none`; emulator-lineage `docs/proposals/2026-11-jit.md`, accepted 2026-11-25). Phase 0: nothing here is measured on this board; every speed figure is an **estimate** with its arithmetic shown, and the measured inputs are named. ## Part 1: domains and channels The DS runs on one crystal: the bus at 33.513982 MHz, the ARM9 at twice it, the dot clock at a sixth, the sound timers at a half (GBATEK "DS Memory Timings", "DS Video Stuff", "DS Sound Channels"); the wireless controller has its own clock (late). So the domains are set by who can see whom, not by clocks. | Domain | Time base | Parts | Why | | --- | --- | --- | --- | | **CPUs and bus** | bus cycles (33.51 MHz); the ARM9 counts core cycles inside | arm946es-python (with its TCMs, caches, write buffer), arm7tdmi-python, main RAM, shared WRAM, ARM7 WRAM, the BIOS ROMs, VRAM banking and CPU access to VRAM/palette/OAM, both interrupt controllers, eight DMA channels, eight timers, the maths unit, IPC, keys, the SPI bus and its devices, the RTC, POWCNT, the cartridge slot's transfer engine, **the 2D engines' front ends** (registers, DISPSTAT/VCOUNT, the dot and line counters, the VRAM read slots that delay the ARM9), **the geometry engine** (FIFO, PIPE, command timing, GXSTAT, the matrix and test results), **the sound unit's registers and busy bits** | the two CPUs share memory they both poll and an IPC with edge IRQs; DMA, the geometry FIFO, the cartridge's data-ready and the sound busy bits are seen by a CPU at a cycle. Splitting the CPUs apart would make every shared-memory access a sync point (charter: "tightly coupled processors ... usually stay one domain") | | **2D back ends** | engine-A and engine-B lines | BG/OBJ composition, windows, effects, master brightness, display modes | a **pure producer** from the register-write log and VRAM writes, except capture (below) | | **3D rasteriser** | rendered lines | polygon rasterisation, texturing, depth, translucency, edge marking, fog, anti-aliasing, the 48-line buffer | a pure producer from the swapped polygon and vertex RAM, texture VRAM and the rendering registers; its timing model (RDLINES_COUNT, underflow) is kept in the CPU domain as a per-line budget | | **Sound mixer** | output samples (32.73 kHz, sound.md C1) | channel sample generation, ADPCM, PSG, mixing, bias | a producer from register state over time; capture writes RAM (below) | | **Wireless** (late) | its own clock | MAC, baseband, RF, its RAM | meets the ARM7 at its registers, RAM and IRQ | ### Channels and sync points | Channel | Between | Sync point (where a threaded tier must catch up) | | --- | --- | --- | | 2D register writes, VRAM writes (by CPU or DMA) | CPU domain -> 2D back ends | none for writes: a log the back end drains in order | | capture unit writes into VRAM A-D | 2D back end (and 3D) -> VRAM -> CPU | **join** before any CPU or DMA read of a bank capture writes, and before the next frame's display of it | | SWAP_BUFFERS at V-blank; texture and rendering-register writes | geometry engine (CPU domain) -> rasteriser | the rasteriser starts its frame at line 214 from the swapped buffer: a log entry at V-blank | | 3D output -> BG0 and capture | rasteriser -> 2D back end A | per line, inside the producers (no CPU visibility except via capture) | | RDLINES_COUNT, DISP3DCNT underflow flag | rasteriser timing -> CPU | computed in the CPU domain from the per-line budget, so no join (HYPOTHESIS: the budget model must predict them without the pixels) | | sound register writes | CPU -> mixer | none for writes: a log | | sound capture writes to main RAM | mixer -> CPU | **join** before a CPU or DMA read of the capture buffer (rare: games read back for effects) | | sound channel busy bits | mixer -> CPU | computed in the CPU domain from the timer arithmetic: no join | | wireless registers, RAM, IRQ (late) | wireless <-> ARM7 | every access; the wireless domain schedules its next IRQ | **Order of record** (x-python, serial): the CPU domain runs; within it the two CPUs are interleaved on the bus clock (cpus-and-ipc.md: every shared-location access at its exact bus time); the producers run at the end of each line or frame and at each join. That changes nothing observable and keeps the Python simple. ### Memory kinds (who may write each region: the cached interpreter's invalidation map) | Region | Written by | Code runs from it? | | --- | --- | --- | | ARM9 ITCM | ARM9 stores only (DMA cannot reach TCM) | yes: hot ARM9 code and the IRQ handler | | ARM9 DTCM | ARM9 stores only | no (data only; fetches go past it) | | ARM9 I-cache lines | line fills only; never stores | what the ARM9 executes from cachable regions | | main RAM | both CPUs, eight DMA channels, sound capture, cartridge DMA | yes: the ARM9's game code (cached), the ARM7's code sometimes | | shared WRAM, ARM7 WRAM | the CPUs it is mapped to, DMA | yes: the ARM7's driver code | | VRAM banks (CPU-mapped) | CPUs, DMA, capture | ARM7 code from VRAM C/D is possible, rare | | BIOS ROMs | nobody | yes | For the ARM9, a decoded-instruction cache keyed to the modelled I-cache lines is exact for cached code (arm946es-python handoff-brief.md); ITCM code needs invalidation on ARM9 stores to ITCM, which the core sees; uncached ARM9 code and all ARM7 code need invalidation on writes to their RAM by anyone, which the bus sees. That is the full list. ## Part 2: how many instructions a second | CPU | Ceiling | MAME's model (OBSERVED) | Planning figure | Basis | | --- | ---: | ---: | ---: | --- | | ARM9 | 67.0 M/s (1 per core cycle, TCM and cache only) | 22.3 M/s (flat 3 cycles each) | **40 M/s** | DDI 0165B; GBATEK's "effective bus speed is barely about 8..16MHz" for uncached code; games run hot code from cache and ITCM (HYPOTHESIS) | | ARM7 | 33.5 M/s (1 per cycle from WRAM) | 11.2 M/s | **10 M/s** | the ARM7 runs Nintendo's sound and Wi-Fi driver from WRAM and halts between interrupts (GBATEK: "most of the ARM7's 33MHz horsepower is left unused") (HYPOTHESIS) | | both | 100.5 M/s | 33.5 M/s | **50 M/s** | | ### The other domains' load (estimates) | Domain | Work per emulated second | Estimated cost in Rust, one core | Basis | | --- | --- | --- | --- | | 3D rasteriser | 256 x 192 x 60 = 2.9 M pixels x overdraw 2-4 = **6-12 M pixel operations** (texture, blend, depth, fog, edge) | 10-30 ns each -> 60-360 ms (6-36% of a core) | HYPOTHESIS | | geometry engine | up to 6,144 vertices x 60 = 0.37 M vertices, matrix work per command | ~1 us per vertex -> < 0.4 s worst case, typically far less | HYPOTHESIS | | two 2D engines | 2 x 256 x 192 x 60 = **5.9 M dots**, up to 4 BGs + OBJs each | 5-15 ns per dot -> 30-90 ms | HYPOTHESIS (gba-python's line renderer is the shape) | | sound | 16 channels x 32,730 = **0.52 M channel-samples** | 20-50 ns each -> 10-26 ms | HYPOTHESIS | ## Part 3: is an interpreter enough without recompilation? ### What the family has measured (this machine: an i9-13900K core, release builds, under load) | Interpreter | Measured | Source | | --- | --- | --- | | arm7tdmi-rust (transcription) | 33.9 M instructions/s native (39.6 M fat LTO), 41.5 M wasm32 under Node | arm7tdmi-rust docs/status.md, 2026-11-25, load 58-65 | | arm7tdmi-python (reference) | 0.83 M instructions/s on PyPy | same | | gba-python on PyPy (whole GBA board) | 14.9 ms per frame on Castlevania's title, 17.9 on Golden Sun's (real time 16.7) | gba-python docs/status.md, rung 4, 2026-11-21 | | the family's `-fast` forks over their transcriptions | x1.4 to x1.9 | a2600, megadrive, m68000 | **Estimates**: arm946es-rust 25-40 M/s (it does more per instruction than the ARM7: TCM and cache look-ups on both buses, the write buffer, interlocks); arm7tdmi-rust as measured, 34-40 M/s. In one CPU domain on one thread, the two share a core: at the planning mix (40 M ARM9 + 10 M ARM7) a transcription needs 40/25-40 + 10/34-40 = 1.25-1.9 cores' worth (too slow), `-fast` (x1.4-1.9) 0.66-1.36. | Target | CPU domain, `-fast` (cores needed at the planning mix) | With the turbo tier's cached interpreter (x1.5-3 over `-fast`, HYPOTHESIS) | Producers on other cores | Verdict | | --- | ---: | ---: | --- | --- | | Desktop, native | 0.66-1.36 | 0.22-0.9 | 3D 6-36%, 2D 3-9%, sound 1-3% of a core | **marginal with `-fast`; real time with the cached interpreter**; the ceiling (100 M/s) needs the cached interpreter | | iPhone app, native (x0.8, no JIT) | 0.8-1.7 | 0.28-1.1 | as above, x1.25 | cached interpreter needed; run-ahead doubtful | | Browser (wasm, x0.6), desktop | 1.1-2.3 | 0.37-1.5 | | cached interpreter needed, marginal; threads in the browser need SharedArrayBuffer | | Browser, iPhone Safari | 1.4-2.8 | 0.46-1.9 | | **not real time without recompiling to wasm** for demanding titles | | ARM handheld (A55 class, x0.2) | 3.3-6.8 | 1.1-4.5 | | needs native recompilation (allowed there) | (Device ratios as in psx-python docs/domains.md, all HYPOTHESIS until measured.) **A Python board**: arm7tdmi-python's 0.83 M instructions/s on PyPy against a 50 M/s planning mix puts the CPUs alone at about 1/60 of real time, before the producers; games that halt the ARM7 and wait for V-blank on the ARM9 will do better (gba-python reaches real time on GBA title screens partly for that reason). Estimate **1/20 to 1/100 of real time**: rung cases must be short (seconds of emulated time), as for era 3. So the answer, to be confirmed by measurement: the no-JIT path (Rust `-fast`, then the turbo tier's cached interpreter, then threads at the declared channels) reaches real time on desktop and as an iPhone app; the browser on a phone and low-cost handhelds need recompilation, which the charter allows there (`recompile: wasm | native`) and keeps off by default.