# Domains, channels, execution architecture and speed Phase 0: nothing here is measured on a PSP or a PSP core; none exists in the family. MEASURED means a sibling's recorded measurement (file named) or a third party's hardware measurement; HYPOTHESIS means an estimate with its arithmetic shown. Every emulator technique named here is an implementation choice, never hardware evidence. The method follows n64-python's execution-architecture.md (time-keeping, not decode, is the cost of an exact interpreter) and the late-era proposal (slices, a shared state format). ## Time base (decision P9, provisional) The PSP's clocks change at run time: games set PLL, CPU and bus frequencies through `scePowerSetClockFrequency` (1-333 MHz CPU, 1-167 MHz bus, `cpufreq <= pllfreq`, `busfreq*2 <= pllfreq`: pspsdk `psppower.h`). No fixed integer unit makes every setting exact. Proposal: **time is counted in PLL cycles, re-based at each clock change.** A clock change is a sync point for every domain (all are brought to the same instant, then the new ratios apply). Between changes, the CPU and bus clocks are integer divisions of the PLL (HYPOTHESIS: the divider structure is U5), so every domain's time is exact. The display's and audio's own crystals, if separate, are converted at their channels (U14). ## Domains and channels (under the HLE boundary of hle-vs-lle.md) | Domain | Time base | Parts | Why one domain | | --- | --- | --- | --- | | **A. CPU and kernel** | PLL / CPU cycles | main Allegrex (caches, VFPU), the HLE kernel and scheduler, DDR, scratchpad, eDRAM as memory, DMA bookkeeping, interrupt and timer events, **the GE's front end** (list processor, state registers, the timing model, signal/finish/end interrupts), display timing (hsync, vsync) | the kernel, the CPU and the GE's control registers meet at every syscall, interrupt and list update; splitting them would make each a cross-thread sync | | **B. GE back end** | the order of primitives | rasterisation, texturing, blending into VRAM/DDR | a producer: nothing it does is visible until a join (a CPU or DMA read of memory it writes, a display line, a list reading memory it wrote) | | **C. Audio** | output samples | the PCM channels' mix, the SRC channel, SAS synthesis | its outputs go only to the speaker, except buffer state that the HLE answers from the schedule (when a blocking output returns, `GetRestSample`) | | **D. Decoders** | per call | AVC (H.264), ATRAC3/3+, MP3, AAC: host functions | each call's result must exist when the call returns or when the game first reads the buffer; work may run ahead on a worker | | **E. UMD and Memory Stick I/O** | event times | the read-time model; host file access | meets A only at the I/O manager's completion events | | *(LLE only)* ME | ME cycles | second Allegrex, ME eDRAM, AVC, VME | meets A at DDR, the ME control block, INT 31 | | *(LLE only)* syscon, Lepton | their own | MCUs | serial and ATAPI links | **Channels and sync points:** SYSCALL (A only: the kernel is in A); GE register writes and the list's stall address (A, front end); every RDRAM-style join between A and B through a **hazard map** over DDR and VRAM pages, as n64-python's RDP design (a CPU cache refill, write-back or uncached access to a page with pending back-end writes joins; a CPU write to a page the back end has yet to read joins or snapshots it); VRAM reads by the display at each line's fetch time (joins only when the GE is drawing into the displayed buffer); audio and decoder results at the HLE call that returns them; I/O completions as events. **Determinism:** every gate case runs single-threaded and threaded, with identical traces (charter). ## The need, with the arithmetic | Component | Guest rate (basis) | Desktop budget | Phone app | Phone browser | | --- | --- | ---: | ---: | ---: | | Allegrex at 222 MHz, IPC 0.5-0.8 | 111-178 M instr/s (allegrex-python handoff-brief) | 28-45 cycles/instr | 22-36 | 13-22 | | Allegrex at 333 MHz, IPC 0.5-0.8 | 167-266 M instr/s | 19-30 | 15-24 | 9-14 | | VFPU share | unknown (U15); heavy in 3D games | included above, but a VFPU op costs several times an ALU op | | | | GE vertices | 0.5-3 M vertices/s (HYPOTHESIS: 5-25 k vertices a frame at 60 fps, more with skinning and patches) | 1,700-10,000 cycles/vertex | 1,300-8,000 | 800-4,800 | | GE pixels | 480x272x60 = 7.8 M visible pixels/s, x2-4 overdraw = **16-31 M shaded pixels/s** (HYPOTHESIS) | 160-310 cycles/pixel | 130-250 | 77-150 | | Audio | 8 channels + SRC at 44.1-48 kHz; SAS up to 32 voices (HYPOTHESIS) = ~1.5 M voice-samples/s | ~3,300 | | | | AVC (FMV) | 480x272 at 30 fps | a host decoder: a few % of a core (HYPOTHESIS) | | | | Python specification | 0.1-0.2 M instr/s (sh2-python, MEASURED in sh2-rust docs/status.md) | 1/550 to 1/2,700 of real time | | | Budgets are desktop-equivalent host cycles on one core: desktop 5.0e9/R, phone app 4.0e9/R, phone browser 2.4e9/R (n64-python's assumptions: a phone core 0.8x a desktop core, the browser 0.6x of that; sh2-rust measured wasm at 0.55-0.65x native). What an exact implementation costs (HYPOTHESIS unless marked): - **CPU:** 25-60 host cycles an instruction with cheap time-keeping (timing as tables, one deadline compare, fetch work once per I-cache line); 89-145 with an SH-2-style stage scheduler (MEASURED, sh2-rust-fast). VFPU instructions: 2-10x an ALU instruction (16 lanes for a 4x4 matrix op, flush-to-zero and NaN rules; SIMD with FTZ natively, a software flush in wasm SIMD128). - **GE back end:** 100-300 host cycles a pixel for a software rasteriser with texture fetch, CLUT, blend, dither and depth (HYPOTHESIS, the same order as psx-python's GPU and n64-python's RDP estimates). - **HLE calls:** native code; a few hundred to a few thousand cycles each, at 10-100 k calls a second (HYPOTHESIS): negligible next to the CPU. ## Backends per component (tiers by their proof) | Component | x-python / x-rust | -fast (bus-cycle identical) | turbo (observables identical) | concession | | --- | --- | --- | --- | --- | | Allegrex | interpreter, one handler per decode row, timing as data | packed decode, cost tables, deadline compare; cached interpreter keyed by I-cache line (exact: the I-cache sees no stores; invalidated by refills, CACHE ops, DMA into code, state loads); memoized block timing | block compilation, `recompile: native` and `wasm` | none needed for exactness | | VFPU | per lane, exact FTZ/NaN rules, transcendentals from FITTED tables | SIMD per register group (SSE/NEON, wasm SIMD128) | | host libm for transcendentals would be a concession (changes results) | | HLE kernel | functional model, stated costs | the same code, optimised layouts | idle fast-forward: when every thread waits and the CPU is in HALT, time jumps to the next event (exact: nothing runs) | coarser syscall timing | | GE front end | list walk on A | the same, cheaper | | | | GE back end | software rasteriser, sequential: the judge | front/back split with joins at the hazard map; banded threads where no state crosses pixels | GPU compute held to per-pixel CRCs at joins, proven per device (`gpu_backend: verified | failed | absent`, late-era proposal L6) | upscaling, texture replacement | | Audio, decoders | in order, on A | on producer threads, joined at the returning call | | | | UMD timing | event model | | | instant loads (a named concession: some games' loading screens and timers change) | ## Verdict without recompilation (`recompile: none`) - **Desktop native:** the CPU domain needs 28-45 cycles an instruction at 222 MHz and 19-30 at 333 MHz. An exact -fast interpreter with cheap time-keeping (25-60) reaches **222 MHz games, not busy 333 MHz games**. The GE back end on 1-2 threads; audio and decoders on another. Idle fast-forward under HLE may rescue part of the 333 MHz gap (U16: the fraction of each frame games spend halted). - **Phone app (no JIT allowed):** at the edge at 222 MHz (22-36 cycles), **not real time** for busy 333 MHz games. The GE needs Metal compute or 2 cores. - **Phone browser:** **not real time** at either clock (9-22 cycles an instruction against 25-60): `recompile: wasm` (turbo) is required, with WebGPU or worker-thread rasterising. - **The Python specification** runs test programs and slices only: at 0.1-0.2 M instructions/s an emulated second takes 9-45 minutes. Games are gated by slices from states written by a Rust tier (late-era proposal L1-L3). The capability record will say plainly: `recompile: none` meets real time on desktop for 222 MHz games, and not for 333 MHz games on phones or in a browser. This is the first family board where that sentence is expected before measuring: PSP emulation is conventionally JIT-based for this reason (PPSSPP ships JIT backends and, where executable memory is forbidden, an IR interpreter: OBSERVED from its public build options, not run). ## Measure first (in this order) 1. allegrex-rust's instructions/s and profile split on a CPU test loop. 2. The fraction of frames games spend in HALT under the HLE kernel (U16), from a Rust tier on a few games' first minutes. 3. Syscalls per second and their spread by library. 4. The software GE's ns per pixel on captured display lists; joins per frame. 5. VFPU instruction share in 3D games.