Emulate the console CPU's AMD-only instructions on Intel CPUs #153
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!153
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/153/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@ShyVortex on GitHub · 2026-11-23 16:52 UTC · original
ShyVortex:cpu/amd-only-instructions→main· +422 −0 · 4 files · 1 commits · closed without mergingSummary
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
@ShyVortex on GitHub · 2026-11-23 16:55 UTC · original
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.
Pull request closed