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

Closed
github-bot wants to merge 2 commits from gh-pr/18/head into gh-pr/18/base
Owner

@⁠ka1qux on GitHub · 2026-11-23 23:12 UTC · original
ka1qux:host-cpu-emulation → main · +740 −10 · 6 files · 2 commits · closed without merging

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

**@⁠ka1qux** on GitHub · 2026-11-23 23:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/18) `ka1qux:host-cpu-emulation` → `main` · +740 −10 · 6 files · 2 commits · closed without merging ## 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)
The title's code is built for Zen 2 and uses CLZERO, SSE4a (INSERTQ,
EXTRQ), MONITORX/MWAITX and RDPRU. On a CPU without them the title died
7 s into boot with an illegal instruction (0xC000001D) at a CLZERO.

victory-loader::cpu installs a vectored 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 is patched, and a
host that has the instruction never enters the handler. The two loops
compilers build around CLZERO run whole in one exception. MWAITX yields
and returns instead of sleeping; RDPRU reports the time-stamp counter.

`victory run` says at start which instructions the host lacks, names
each at its 1st, 2nd, 4th... use, and prints totals when the title
exits. Tests execute the real instructions, through the handler or
natively.

On a Core i5-13600KF one run now goes as far as on the AMD machine: 30
fps to the loading screen, then the world and the host GPU failure.

Docs: "Host CPU" in docs/architecture.md (table, design, limits,
measurements); README status, requirements and what a 0xc000001d crash
means.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
With device-removed data on, every named host buffer's address range is
kept, and a page fault is reported against them: the buffers it lies in,
those ending closest below it and those starting closest above, with the
distances. A fault just past a buffer's end is an access that ran off
it; one far from every buffer is not ours to overrun. Upload and shared
buffers get names so they are counted.

Two runs into the world faulted at the same address, 433 MB below the
lowest of 559 buffers and in no live or freed allocation.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:46:41 +00:00
github-bot closed this pull request 2026-11-26 03:46:41 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-23 23:14 UTC · original

Already fixed, thanks anyways

**@⁠Marvisak** on GitHub · 2026-11-23 23:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/18#issuecomment-7116730503) Already fixed, thanks anyways

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!18
No description provided.