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

Merged
legacy-code-archaeologist merged 1 commit from upstream-pr/1134 into main 2026-11-24 02:16:02 +00:00
legacy-code-archaeologist commented 2026-11-24 01:41:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-24T01:41:18Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6572663194 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1134). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-24T01:41:18Z. --- ## 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)
upstream-sync closed this pull request 2026-11-24 06:46:31 +00:00
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
R0Y00/Xbox2Windows!1127
No description provided.