Run on Intel hosts: emulate the console CPU's AMD-only instructions #18

Closed
ka1qux wants to merge 2 commits from upstream-pr/18 into main
ka1qux commented 2026-11-23 23:12:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ka1qux on 2026-11-23T23:12:10Z.


Problem

On a CPU without AMD's own instructions (every Intel CPU), the title died 7 s into boot with an illegal instruction (0xC000001D) at a CLZERO. The title's code is built for Zen 2 and also uses SSE4a (INSERTQ, EXTRQ), MONITORX/MWAITX and RDPRU.

Change

victory-loader::cpu installs a vectored exception handler, ahead of the crash reporter's, that carries the refused instruction out on the faulting thread's saved registers and resumes after it.

  • Nothing in the image is patched, and a host that has the instruction never enters the handler, so AMD hosts are unaffected.
  • The two loops compilers build around CLZERO run whole in one exception instead of one per 64 bytes.
  • victory run logs which instructions the host lacks, names each at its 1st, 2nd, 4th... use, and prints totals when the title exits.

The second commit is diagnostics only (VICTORY_D3D12_DRED): a GPU page fault is reported against every named host buffer's address range, so a fault just past a buffer's end names the buffer.

Testing

  • cargo test -p victory-loader: 6 new tests execute the real instructions, through the handler on a CPU that lacks them and natively on one that has them.
  • One machine, Core i5-13600KF with an RX 7800 XT: the title now runs at 30 fps to the loading screen and reaches the world, where the host GPU fails as the README already describes. In that 2 min 17 s run: over 65,000 CLZERO exceptions, over 32,000 MONITORX/MWAITX pairs, over 4,000 INSERTQ, about 1 µs each.
  • Not tested on an AMD CPU.

Limits

  • MWAITX yields and returns instead of sleeping, so a thread waiting with it spins.
  • RDPRU returns the time-stamp counter for both registers.
  • RDPRU and EXTRQ were exercised by the tests only; the title did not reach them.
  • The instruction sites were found by byte matches in the executable, not confirmed with a disassembler; CLZERO, MONITORX/MWAITX and INSERTQ were then confirmed by the run.

Details are in the new "Host CPU" section of docs/architecture.md.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6570769716 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/18). Originally posted by [ka1qux](https://github.com/ka1qux) on 2026-11-23T23:12:10Z. --- ## Problem On a CPU without AMD's own instructions (every Intel CPU), the title died 7 s into boot with an illegal instruction (`0xC000001D`) at a `CLZERO`. The title's code is built for Zen 2 and also uses SSE4a (`INSERTQ`, `EXTRQ`), `MONITORX`/`MWAITX` and `RDPRU`. ## Change `victory-loader::cpu` installs a vectored exception handler, ahead of the crash reporter's, that carries the refused instruction out on the faulting thread's saved registers and resumes after it. - Nothing in the image is patched, and a host that has the instruction never enters the handler, so AMD hosts are unaffected. - The two loops compilers build around `CLZERO` run whole in one exception instead of one per 64 bytes. - `victory run` logs which instructions the host lacks, names each at its 1st, 2nd, 4th... use, and prints totals when the title exits. The second commit is diagnostics only (`VICTORY_D3D12_DRED`): a GPU page fault is reported against every named host buffer's address range, so a fault just past a buffer's end names the buffer. ## Testing - `cargo test -p victory-loader`: 6 new tests execute the real instructions, through the handler on a CPU that lacks them and natively on one that has them. - One machine, Core i5-13600KF with an RX 7800 XT: the title now runs at 30 fps to the loading screen and reaches the world, where the host GPU fails as the README already describes. In that 2 min 17 s run: over 65,000 `CLZERO` exceptions, over 32,000 `MONITORX`/`MWAITX` pairs, over 4,000 `INSERTQ`, about 1 µs each. - Not tested on an AMD CPU. ## Limits - `MWAITX` yields and returns instead of sleeping, so a thread waiting with it spins. - `RDPRU` returns the time-stamp counter for both registers. - `RDPRU` and `EXTRQ` were exercised by the tests only; the title did not reach them. - The instruction sites were found by byte matches in the executable, not confirmed with a disassembler; `CLZERO`, `MONITORX`/`MWAITX` and `INSERTQ` were then confirmed by the run. Details are in the new "Host CPU" section of `docs/architecture.md`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:50:56 +00:00
Marvisak commented 2026-11-24 06:54:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-23T23:14:43Z.


Already fixed, thanks anyways

<!-- greyfinch-sync:Marvisak/VIctory:comment:7116730503 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/18#issuecomment-7116730503). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-23T23:14:43Z. --- Already fixed, thanks anyways

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!18
No description provided.