# Timing: dual issue, latencies, stalls, and the modelling level Sources: SM section 8 (tables 8.1-8.3, figures 8.1-8.3), HM section 8 (the same text for the SH7750). Tier 2. ## What the manual gives - **Two pipes, six groups** (SM 8.2, table 8.1): MT (MOV, CMP, TST, NOP, CLRT, SETT), EX (integer ALU and shifts), BR (BF, BT, BRA, BSR and their /S forms), LS (loads, stores, FMOV, FLDI, FABS/FNEG, PREF, OCB*, MOVCA.L, LDS/STS FPUL), FE (floating-point arithmetic, FIPR, FTRV, FRCHG, FSCHG), CO (everything that serialises: JMP, JSR, RTS, RTE, BRAF, BSRF, TRAPA, SLEEP, the multiplies, MAC, LDC/STC of control registers, LDS to FPSCR/PR/MAC, TAS.B, the GBR-relative logical ops, double-precision FCMP). - **Pairing** (SM table 8.2): two instructions fetched together issue in the same cycle unless both are in the same group (MT pairs with MT; EX, BR, LS and FE do not pair with themselves) or either is CO. - **Per instruction** (SM table 8.3): issue rate, latency, execution pattern (figure 8.2: 43 patterns, from "1-step operation" to TRAPA's 7 issue cycles and FTRV's), the locked pipeline stage, when the lock starts and how many cycles it lasts. The table has 234 numbered rows, the same count as the forms in SM section 7's code tables (isa.md): the generator can join the two tables row for row and fail on any mismatch. - **Stall rules** (SM 8.3): flow dependency stalls by the latency; output dependency by latency-1 or latency-2; anti-flow dependency (5 cycles after FTRV, 2 after a double-precision FADD/FSUB/FMUL); resource locks; exceptional cases (an FPU result stored right after: latency -1; a load feeding SHAD/SHLD: +1; a short-latency result feeding a double-precision op, FIPR or FTRV: raised to 2). - **Penalties outside the table**: ITLB misses, I-cache misses (no issue meanwhile), data misses and accesses to memory-mapped control registers (a pipeline freeze until the data arrives), "largely dependent on the user's memory subsystems" (SM 8.3); and idle cycles for crossing between clock domains (SM 8.3, last paragraph). ## What the manual does not give - Which two instructions are "fetched simultaneously": the pairing applies to an aligned pair in the fetch unit; how a branch target in the second half, or an I-cache miss, breaks pairs is not tabulated (U7). - The exact freeze length for each memory access as a function of the BSC's settings and the B:I ratio (U8). - Whether table 8.3 is exact for the SH7091 (U1). ## Proposed modelling level (axis B) **Instruction level with an issue model**: each instruction's effect is computed whole; time is charged by a small scheduler that applies tables 8.1-8.3 (pairing, latency, locks) per instruction, plus transaction-level memory penalties from the caches, the store queues and the board's bus answer. Not a stage-by-stage pipeline: no judge we can run sees inside a stage (as vr4300-python's brief argued for the VR4300), and the stage model would cost several times the speed of an already very slow core (see the handoff brief's "Domains and speed"). Why not plain "one instruction, one cycle": games' timing loops and the board's raster and interrupt timing depend on how many cycles code takes; an IPC of 1.0 against a real 0.6-1.8 shifts every timed event. The issue model is cheap (table lookups) and exactly the "timing as data" the JIT proposal asks a specification to declare. ## A detector's figure MAME 0.285 charges 1.281 cycles per SH-4 instruction over frames 1000-1003 of the boot ROM (7,817,016 instructions in 10,010,009 cycles; `scripts/mame_trace.py --start 1000 --frames 1` gave the same 1.281 over one frame, 2,605,142 instructions), and 1.357 over the first three frames from reset (7,376,144 in 10,010,008) (OBSERVED; docs/mame-oracle.md). MAME does not appear to model dual issue; its count is not the chip's, and 90 % of the window is a 20-PC wait loop. No game workload has been measured; no hardware cycle count exists in anything we hold.