mirror of
https://github.com/RetroPortingToolKit/psxrecomp
synced 2026-10-26 02:11:36 -04:00
9f8ee72f4d
Compiled code bakes KSEG0 into link values, CPS/IRQ resume PCs and I-cache tags. KUSEG-linked EXEs run KUSEG PCs through those bodies (and their KUSEG seeds are dropped), and overlay code executed at KUSEG/KSEG1 stays interpreted after #417. Until #429, both emitters also charged the uncached KSEG1 fetch only at cache-line leaders, so compiled BIOS ROM code was 4 cycles short on 5,477 of OpenBIOS's 9,592 KSEG1 instruction sites (Beetle and the interp charge every fetch). docs/SEGMENT_AWARE_CODE.md recommends per-segment compiled variants (code identity = full VA, emitter segment as a per-compile constant, exact-segment dispatch, per-instruction fetch in uncached bodies, segment-aware capture and cache keys) over segment-relative emission, which measures +3.2 % / +27.2 % __TEXT on R4 shards. tools/segment_testrom/gen_segment_exe.py emits a synthetic KUSEG-linked PS-X EXE that also works as an oracle probe. The new ctest segment_aware_codegen runs the real recompilers on it and on OpenBIOS and checks emitted PCs, the emitted dispatch lookup and fetch cycles (through runtime/src/psx_icache.c) against a Beetle ReadInstruction transcription. It passes only while the observed gaps equal its ledger (9 today). #429 (rollout A) fixed the BIOS undercharge on master before this landed, so KNOWN_GAPS does not list bios-kseg1-fetch-charge: the OpenBIOS check finds no uncharged KSEG1 site and stays as a regression guard that reports the id as a new gap. The last commit of this series brings the doc up to date with #429. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>