cpu: lower VLDMXCSR and VSTMXCSR in the host-MXCSR profile #1134

Manually merged
github merged 1 commit from gh-pr/1134/head into gh-pr/1134/base 2026-11-26 22:44:20 +00:00
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-24 01:41 UTC · original
legacy-code-archaeologist:cpu/lower-vmxcsr → main · +395 −7 · 9 files · 1 commits · merged 2026-11-24 02:16 UTC

Change

As agreed in #1093, VLDMXCSR and VSTMXCSR share the host-MXCSR opt-in in tools/ffx_version_query.py.

  • Lowering: the VEX.128 forms with vvvv 1111 lower exactly like LDMXCSR and STMXCSR, with the same word checks, statuses, fault behavior and caller-word restoration in mxcsr_entry.
  • Default profile: it still refuses them.
  • Undefined VEX forms never reach the lowering: iced decodes VEX.L = 1, another vvvv, another pp or map, and a register operand as invalid. VEX.W is ignored, as the instruction defines, so c4 e1 f8 ae 10 is still VLDMXCSR.
  • No AVX needed: the translated code uses SSE MXCSR access, so the host does not need AVX for the translation.

Tests

Two tests, so a native capability skip cannot hide a failure of the translated path:

  • cpu_aot_vmxcsr (vmxcsr.asm) never runs native VEX code and has no capability skip.
    • It runs the rules of cpu_aot_mxcsr against their fixed expectations on VEX copies of its exports: all four rounding modes with and without sticky flags, the four refused words, the caller-word restore after return, refusal and both fault sites, and the marker after a refusal.
    • Two exports mix the forms (LDMXCSR then VSTMXCSR, and VLDMXCSR then STMXCSR). Their read-back must equal the loaded word, and a refused VEX load must stop before the legacy read-back.
    • It also checks the default-profile refusal of each of the 12 MXCSR instructions in every export on its own, the six malformed encodings, the noload and fixed controls, and an /O2 build with minimum MXCSR instruction counts.
  • cpu_aot_vmxcsr_native compares the same exports with native execution.
    • It exits 77 on a host without AVX, OSXSAVE or XCR0 SSE and AVX state, which the native harness checks with has_avx_os.
    • It asserts that a VLDMXCSR patched to VEX.L = 1 raises STATUS_ILLEGAL_INSTRUCTION (0xC000001D) in a child process. Both the 3-byte C4 and the 2-byte C5 prefix are handled; ML64 emits C4 for [r9+d].

tests/cpu/mxcsr.py gains the VEX mnemonics in its instruction walks, and lifted_violation(native=None) skips only the native comparison. The output and checks of cpu_aot_mxcsr are unchanged.

Verification

At d1791fe (on main a7710b7) on Windows 11 Pro (build 26100), Intel Core i7-6820HQ (AVX, OSXSAVE), MSVC 19.52, Python 3.12:

  • ctest --preset dev --no-tests=error -R '^cpu_aot_(mxcsr|mxcsr_denormals|vmxcsr|vmxcsr_native)$' -V: 4/4 pass. The output includes:
    • the default profile refuses each of the 12 MXCSR instructions of every export on its own: 7 VLDMXCSR, 3 VSTMXCSR, 1 LDMXCSR, 1 STMXCSR;
    • native reference: VLDMXCSR with VEX.L=1 raises STATUS_ILLEGAL_INSTRUCTION in a child process.
  • ctest --preset release --no-tests=error -R '^cpu_aot_(mxcsr|vmxcsr|vmxcsr_native)$': 3/3 pass. Only these tests' targets were built in release.
  • ctest --preset dev --no-tests=error -R '^cpu_' -j 4: 212 of 213 pass, with three capability skips.
    • The failure is cpu_shim_shadow_hardware in its native run, independent of this change and reported in #799.
  • tools/form_coverage.py on a JUnit run of that suite no longer lists vldmxcsr or vstmxcsr.
  • tests/docs_links_check.py, tests/bidi_controls_check.py and tests/form_coverage_check.py pass.

Not run: a host without AVX. The translated part is built not to execute native VEX code, but it was not run on such a host.

Refs #1093

  • I did not include game files, dumps, distribution links or secrets.

AI-assisted: written with Claude Code; diff reviewed by a fresh agent; checked and submitted by the account owner.

🤖 Generated with Claude Code

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-24 01:41 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1134) `legacy-code-archaeologist:cpu/lower-vmxcsr` → `main` · +395 −7 · 9 files · 1 commits · merged 2026-11-24 02:16 UTC ## Change As agreed in #1093, VLDMXCSR and VSTMXCSR share the host-MXCSR opt-in in `tools/ffx_version_query.py`. - **Lowering:** the VEX.128 forms with `vvvv` 1111 lower exactly like LDMXCSR and STMXCSR, with the same word checks, statuses, fault behavior and caller-word restoration in `mxcsr_entry`. - **Default profile:** it still refuses them. - **Undefined VEX forms** never reach the lowering: iced decodes VEX.L = 1, another `vvvv`, another `pp` or map, and a register operand as invalid. VEX.W is ignored, as the instruction defines, so `c4 e1 f8 ae 10` is still VLDMXCSR. - **No AVX needed:** the translated code uses SSE MXCSR access, so the host does not need AVX for the translation. ## Tests Two tests, so a native capability skip cannot hide a failure of the translated path: - **`cpu_aot_vmxcsr`** ([`vmxcsr.asm`](tests/cpu/vmxcsr.asm)) never runs native VEX code and has no capability skip. - It runs the rules of `cpu_aot_mxcsr` against their fixed expectations on VEX copies of its exports: all four rounding modes with and without sticky flags, the four refused words, the caller-word restore after return, refusal and both fault sites, and the marker after a refusal. - Two exports mix the forms (`LDMXCSR` then `VSTMXCSR`, and `VLDMXCSR` then `STMXCSR`). Their read-back must equal the loaded word, and a refused VEX load must stop before the legacy read-back. - It also checks the default-profile refusal of each of the 12 MXCSR instructions in every export on its own, the six malformed encodings, the `noload` and `fixed` controls, and an `/O2` build with minimum MXCSR instruction counts. - **`cpu_aot_vmxcsr_native`** compares the same exports with native execution. - It exits 77 on a host without AVX, OSXSAVE or XCR0 SSE and AVX state, which the native harness checks with `has_avx_os`. - It asserts that a VLDMXCSR patched to VEX.L = 1 raises `STATUS_ILLEGAL_INSTRUCTION` (`0xC000001D`) in a child process. Both the 3-byte `C4` and the 2-byte `C5` prefix are handled; ML64 emits `C4` for `[r9+d]`. `tests/cpu/mxcsr.py` gains the VEX mnemonics in its instruction walks, and `lifted_violation(native=None)` skips only the native comparison. The output and checks of `cpu_aot_mxcsr` are unchanged. ## Verification At `d1791fe` (on `main` `a7710b7`) on Windows 11 Pro (build 26100), Intel Core i7-6820HQ (AVX, OSXSAVE), MSVC 19.52, Python 3.12: - `ctest --preset dev --no-tests=error -R '^cpu_aot_(mxcsr|mxcsr_denormals|vmxcsr|vmxcsr_native)$' -V`: 4/4 pass. The output includes: - `the default profile refuses each of the 12 MXCSR instructions of every export on its own: 7 VLDMXCSR, 3 VSTMXCSR, 1 LDMXCSR, 1 STMXCSR`; - `native reference: VLDMXCSR with VEX.L=1 raises STATUS_ILLEGAL_INSTRUCTION in a child process`. - `ctest --preset release --no-tests=error -R '^cpu_aot_(mxcsr|vmxcsr|vmxcsr_native)$'`: 3/3 pass. Only these tests' targets were built in `release`. - `ctest --preset dev --no-tests=error -R '^cpu_' -j 4`: 212 of 213 pass, with three capability skips. - The failure is `cpu_shim_shadow_hardware` in its native run, independent of this change and reported in #799. - `tools/form_coverage.py` on a JUnit run of that suite no longer lists `vldmxcsr` or `vstmxcsr`. - `tests/docs_links_check.py`, `tests/bidi_controls_check.py` and `tests/form_coverage_check.py` pass. **Not run:** a host without AVX. The translated part is built not to execute native VEX code, but it was not run on such a host. Refs #1093 - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted: written with Claude Code; diff reviewed by a fresh agent; checked and submitted by the account owner. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
As agreed in #1093, the VEX.128 forms share the host-MXCSR opt-in and
lower exactly like LDMXCSR and STMXCSR, with the same word checks,
statuses, fault behavior and caller-word restoration. The default
profile refuses them. iced decodes the undefined VEX forms (VEX.L = 1,
another vvvv, pp or map, a register operand) as invalid; VEX.W is
ignored. The translated code uses SSE MXCSR access and needs no AVX.

cpu_aot_vmxcsr runs the rules of cpu_aot_mxcsr against their fixed
expectations on VEX copies of its exports, and on two exports that mix
the legacy and VEX forms. It also checks the default-profile refusal of
every MXCSR instruction, six malformed encodings, the noload and fixed
controls and an /O2 build. It runs no native VEX code and has no
capability skip. cpu_aot_vmxcsr_native compares with native execution
and asserts that a VEX.L = 1 VLDMXCSR raises STATUS_ILLEGAL_INSTRUCTION
in a child process. It exits 77 without AVX, OSXSAVE or XCR0 SSE and AVX
state. mxcsr.py gains the VEX mnemonics and an optional native
comparison; cpu_aot_mxcsr is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:44:18 +00:00
github manually merged commit d1791fe384 into gh-pr/1134/base 2026-11-26 22:44:20 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.