Repository navigation
Conversation
Titles are compiled for the console's Zen 2 and use instructions Intel CPUs lack: a retail game's memset clears large blocks with CLZERO and its fence waits sleep on MONITORX / MWAITX. On an Intel CPU each one stopped the game with an illegal instruction (0xC000001D). A vectored handler, installed only when the CPU lacks one of them, carries the instruction out and resumes after it: - CLZERO zeroes the 64-byte line at rAX; when it is the body of one of the two loops compilers emit around it, the whole range is cleared at once and execution resumes after the loop (one fault per clear instead of one per line) - MONITORX arms nothing, MWAITX yields (it may wake at any time) - RDPRU returns the TSC for MPERF / APERF Tested on an i7-12700H: the tests run the real instructions, and the retail game that faulted on CLZERO now runs past all of its memset loops. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
|
Closing in favour of #151, which covers the same instructions and more. I've offered the CLZERO loop fast path and the executing tests from this PR there as a follow-up. |
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.
Summary
Titles are compiled for the console's Zen 2 and use AMD-only instructions that Intel CPUs don't have. On an Intel CPU each one stops the game with an illegal instruction (
0xC000001D). A retail game hit this early in boot: itsmemsetclears large blocks withCLZERO, and its fence waits sleep onMONITORX/MWAITX.This adds
amd_insn.rs: a vectored exception handler, installed only when the CPU lacks one of these instructions (so nothing changes on AMD), that carries the instruction out and resumes after it:CLZEROrAX. When it is the body of one of the two loops compilers emit around it (clzero; add rax,0x40; cmp rax,LIM; jbandmov rax,P; add P,0x40; clzero; cmp P,LIM; jb), the whole range is cleared at once and execution resumes after the loop: one fault per clear instead of one per 64 bytesMONITORXMWAITXRDPRUMemory that isn't committed and writable is left to fault as the real instruction would. Decoded sites are cached and logged once.
xcl runprints which instructions are emulated.Testing
On an Intel i7-12700H (no CLZERO / MONITORX / RDPRU):
cargo test -p xcl --lib amd_insn: 3 tests. They execute the real instructions from generated code (both loop shapes, a loneCLZEROwith an unaligned address,MONITORX+MWAITX) and check the exact bytes cleared. On AMD the same tests run natively.CLZEROnow runs past all 5 of itsmemsetloops and itsMONITORXfence wait, and goes on to its graphics and audio setup.Generated with Claude Code