# Timing: ticks, stalls, the external bus, and speed One **tick** is one system clock: 26.590906 MHz on an NTSC console (MAME `jaguar` lists `gpu` and `dsp` at 26,590,906 Hz), 26 MHz on CoJag (MAME `fishfren` lists both at 26,000,000 Hz). The libretro project's Verilator calibration agrees that one netlist `clk` tick is one system clock (`gpu-timing-verilator-results.md` §0, second-hand). The GPU, Blitter, OP and memory controller share that clock; the DSP runs from Jerry's copy of it. Every number below carries its source. **No hardware-captured timing exists for either processor**; the best available is the netlist read by hand (and, second-hand, one Verilator campaign on the GPU). Settling the constants is rung 2's job ([validation.md](validation.md)). ## What the manual states (manufacturer) - Peak one instruction per tick; "a well written GPU program can usually achieve ... around three-quarters of the peak", and stall-heavy code "around half" (TRM p.61). - Write cycles per instruction (the "Register Usage" lines, TRM p.44-58): ALU results cycle 3; MOVE, MOVEQ, MOVETA, MOVEFA, MOVE PC cycle 2; MOVEI cycle 3; LOAD from local RAM cycle 3-4, indexed 5-6; DIV cycle 18; external loads "subject to bus latency". - Stalls (TRM p.62), each "one clock" unless stated: reading the previous instruction's result; using the previous instruction's flags; a write-back that no operand of the next instruction matches; two write-backs at once; reading a divide's result early (1-16); a DIV while one runs (1-16); reading a pending load (at most 1 internal, several external); a load/store while one internal or two external are pending; **after an indexed store (1)**; **after a jump or jr ("three clock cycles if executing out of internal memory")**; an unfetched next instruction (external code only); an MMULT while the CPU accesses GPU space. - Indexed addressing has "a two tick overhead ... as the address has to be computed" (TRM p.37). - MMULT runs "at a burst rate of ... one multiply per tick" (TRM p.42). - Divide: two bits per tick, 16 ticks (TRM p.42). - MOVEI: three words; interrupts locked out while the two data words are fetched (TRM p.39). - Code in external memory: the processor fetches a long (two instructions) per bus cycle and "will normally give up the bus between program fetches" unless BUS_HOG (CTRL bit 11, TRM p.61). Operand transfers can use DMA priority (DMAEN); program fetches never do (TRM p.37). - The DSP's external interface is **16 bits** wide ("its bus bandwidth is lower as it has a 16-bit interface", TRM p.97): a long costs two bus cycles. ## What the netlist adds (read by hand; the libretro reading agrees) `reference/src/virtualjaguar-libretro/docs/gpu-timing-spec.md` (2026, GPL-3 repository, a netlist reading with evidence tags) is the most careful public analysis; its rules agree with what I read where I read the same lines: | Item | Ticks | Evidence | | --- | --- | --- | | straight-line code from local RAM | 1 per instruction, one long fetched every 2 | TRM; libretro §14 (Verilator, NOP stream) | | taken JUMP, local RAM | +2 dead ticks after the delay slot (bound 2-3) | libretro R12, read from `PREFETCH.NET` (`force0` flush, refill); TRM says 3 | | taken JR, local RAM | +3 (one more than JUMP: target computed a tick later) | libretro R13; `PREFETCH.NET` 10/9/91 | | not-taken jump | 1 (+1 if the flags are one instruction old) | libretro R14 | | MOVEI | 3 (opcode + two data words through `imm1`/`imm2` of `EXECON.NET`) | libretro R16 | | DIV | issue 1, `div_active` 16 ticks, write-back the tick after: result usable at about 18 | `DIVIDE.NET`; libretro R15 from `SBOARD.NET` l.369-403 | | local LOAD | ready at +3 (indexed +5) | TRM; libretro §11 | | run of g local loads back to back | g - 1 extra ticks | libretro §14 (Verilator) | | external LOAD (GPU) | **7 + D** ticks from issue to a usable result, D = memory cycle length (9 on a DRAM page hit) | libretro §14, Verilator, **second-hand** (rig unpublished) | | back-to-back register-writing ALU instructions, disjoint registers | **2 ticks each** (write-back port conflict) | libretro §14, Verilator, second-hand; contradicts the manual's peak claim in practice (C5) | | MMULT | about 2 ticks per element plus setup | libretro R17: mechanism read, constant inferred, not simulated | | BUS_HOG | holds the request 4 more ticks after an external fetch | libretro R20 from `GATEWAY.NET` l.262-270 (not read by me) | | interrupt entry | 6 injected instructions + the jump's refill: "about 4-6 ticks + refetch" | libretro §10: inference | The rows marked second-hand come from a Verilator rig the libretro project describes but does not publish; their own §15 says the rig "is in no checkout". Treat them as **leads to reproduce**, not as values to encode. ## The external bus: what the core needs from the board The processor does not decide how long an external cycle takes; Tom's memory controller and arbiter do (board, `jaguar-python/docs/bus-arbitration.md`). What the core must model is the processor's side: - The **gateway** handles one bus transaction at a time; a GPU program fetch and a data load may both be pending (libretro R21, `GPU_MEM.NET`; not read by me). Up to two external loads/stores can be outstanding before the stream stalls (TRM p.62); a load's destination is scoreboarded until the data arrives, so independent instructions keep running (TRM p.37). - **Cost per transaction**: grant latency (who else owns the bus, priority levels 2 GPU / 7 GPU-DMA / 4 DSP / 8 DSP-DMA) + memory cycle length (DRAM 2 on a page hit, 3-7 more on a row change by DRAMSPEED; ROM 5-10 by ROMSPEED; I/O 4-18 by IOSPEED: board's table from TRM p.7, 10) + the gateway's return. The board computes the first two; the core adds its own fixed part (the "7" of 7 + D if that figure survives rung 2). - **DSP**: every long is two 16-bit transactions; a phrase four (TRM p.97). - **External program fetch**: each long costs a full transaction, below data loads in priority; with BUS_HOG the transactions chain. libretro estimates 6 to 15+ ticks per instruction pair (R22, inference). So the contract hands the board one call per external transaction and lets the board say when it completes ([handoff-brief.md](handoff-brief.md)). The local RAM never touches the bus: an access to local space costs only the local-bus priority (CPU slave > operand > fetch). ## What MAME does (a detector, not a timing reference) One count per instruction, plus 3 for a taken JUMP/JR ("3 wait states guaranteed"), DIV instant, no pipeline, no scoreboard, no bus cost, interrupt entry instant (`jaguar.cpp`). Its counts are useless for timing; its traces are useful for **order of execution** only ([mame-oracle.md](mame-oracle.md)). Virtual Jaguar has per-opcode tables tuned by hand to make Flip Out and Rayman work ([pipeline-and-bugs.md](pipeline-and-bugs.md)). ## Speed: two 26.6 MHz processors in pure Python The arithmetic, honestly: - Peak demand: 26.6 million instructions per second **per processor**, 53 million for both, on top of the 68000's ~1.5 million and the Blitter and OP. Real code runs nearer half the peak (TRM p.61; libretro's 0.5 IPC), but an idle processor in a spin loop still issues instructions every tick, and games keep the DSP busy (Tempest 2000's DSP ran 1.4 million instructions in MAME before the 16 MB cap, never idle, [mame-oracle.md](mame-oracle.md)). - The family's measured reference: `m68000-python` runs about 1.4 million instructions per second on CPython and 33 million on PyPy (its README, 2026-09-25), with a much cheaper per-instruction budget than a pipeline model needs. - A JRISC core that models write-back timing and the scoreboard does more work per instruction than an instruction-at-a-time 68000. Expect, as an extrapolation and not a measurement: **CPython well under 1% of real time, PyPy perhaps 10-40% of real time for one processor, less for both.** The first rung that runs a real program must measure it. - That is acceptable under the family's rule (reference cores are correct, not fast; speed is the `-fast` forks' job). Things that keep the reference usable without bending it: skip a processor whose GO bit is clear (most of the time for the GPU in many games); predecode local RAM into a 2,048-entry (GPU) or 4,096-entry (DSP) table invalidated on write; account ticks by rule (an instruction's stalls computed from the scoreboard state) rather than looping per tick; and a `run_until(tick)` API so the board advances each processor in batches between bus events. None of these changes a result.