Emulate the console CPU's AMD-only instructions on Intel CPUs #150
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/153"
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?
Imported from ivall/xcl. Originally posted by ShyVortex on 2026-11-23T16:52:15Z.
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
upstream-sync referenced this pull request2026-11-24 06:58:21 +00:00
Imported from ivall/xcl. Originally posted by ShyVortex on 2026-11-23T16:55:55Z.
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