Repository navigation
feat: PS1 recompiler (#91) - #112
Merged
Merged
Conversation
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Contributor
Author
|
/code-review (high): one bug fixed in the last commit: a second No change for the rest:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #91
The PS1 recompiler (ADR 0021): a game's EXE becomes a C module that the runtime runs wherever it has code, with our interpreter for the rest. Recompiled code ends every program in the same state as the interpreter, cycle for cycle.
What's in it
recompilers/ps1/analysis.{h,cpp}: functions from the entry point,jal/baltargets and--entry; blocks; tail calls; jump tables (thelui/addiutable address, the index added, the load, asltiubound); branches that always or never go.recompilers/ps1/emit_c.{h,cpp}andps1_recomp <exe | cue> -o out.c [--entry hex]: one C function per guest function with aswitchon pc into its blocks, exact cycle counts, static load delays, an inlined RAM/scratchpad fast path, C calls forjal.runtimes/ps1/recomp/guest.h(the C ABI;ps1_cpuis now the interpreter's own state),helpers.h(what generated code inlines),dispatch.{h,cpp}(Recompiled: entry table, hash check of each function's words, the bus stamps code pages on every RAM write from the CPU or DMA, the interpreter for everything else, logging of misses and changed code).System::use_module, the plugin's--module,ps1_shot --module.Tests
ps1_programs_recompiled: every test program recompiled and run both ways; CPU state, exceptions, RAM and scratchpad must match. New programsrecomp_calls(a jump table, recursion, function pointers) andrecomp_smc(code copied and patched at run time).ps1_recomp_fuzz: 32 random programs (ps1_fuzz_exe): every instruction form, I/O reads and writes, stores with the cache isolated, exceptions, timer IRQs, loads in flight at branch targets and returns.ps1_analysis_test: flow, registers, functions, blocks, tail calls, jump tables, EXE loading.ps1_runtime_rom: a module loads through the plugin, and a file that isn't one fails the load.Mutants (run locally)
27 mutants of
emit_c.cpp,dispatch.cpp,helpers.handanalysis.cpp; 26 caught:lwl/lwrmerge),sra/sltisignedness,bgez, the deadline check (the test hangs), the code-page check on stores,jalr's link,after_call's load and exit checks;after_access's interrupt and code checks;The first runs left 7 alive, and the random programs were extended for them: DMA that raises its IRQ inside the access and clears a word of the code ahead, loads in flight at targets, returns and I/O accesses, near branch targets so most blocks run. One survives: the fast path's user-mode check on loads. Recompiled code is never entered in user mode, and
mtc0/rfealways return to the interpreter, so the check can't be reached; it stays as a safety check.Not covered: DMA writing over the code of the function that is running, except at its very end (the random programs clear a word just ahead of the pc there).
Ridge Racer (USA)
Recompiled from the owner's dump read in place, output kept local (not committed): 214 functions, 2569 blocks. At 3000 frames on Linux (release build) the frame hash matches the interpreter's; about half the time (27.5 s against 13.9 s; 30.9 s against 15.5 s in a second run); about 85% of the cycles after boot run recompiled. The rest is the BIOS's kernel calls and code reached through pointers, for #92's
--entrylist. Overlays aren't recompiled yet.Checks
:launcher:assembleDebug