cpu: lower LDMXCSR and STMXCSR in an opt-in host-MXCSR profile #1002
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1009"
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 R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-23T21:09:50Z.
Change
Lowers the legacy
m32forms of LDMXCSR and STMXCSR intools/ffx_version_query.pyas the opt-in host-MXCSR profile agreed in #995. The profile is enabled bylower(..., host_mxcsr=Mxcsr(reject)). The default profile still rejects both instructions, the VEX forms stay rejected, and existing fixed-profile generation is unchanged.LDMXCSR
load_always), so an inaccessible operand faults before anything is loaded.rejectwith a distinct status fromMXCSR_STATUS, and no later guest instruction runs:_mm_setcsr.STMXCSR stores
_mm_getcsr().Checked boundary (
mxcsr_entry)__finally: on a normal return, after a refusal, and when a structured exception such as a guest memory fault leaves the lowered body.<name>_status()returns the refusal status of the calling thread's last call; the status isthread_local.#pragma fenv_access(on)(MXCSR_HEADER).Tests
cpu_aot_mxcsr(mxcsr.asm, native harness for reading and writing the host MXCSR).Rounding. From a non-default caller word (
0x7FA0: round toward zero with the precision flag set), every rounding control is loaded with and without the six sticky flags. Operands the test writes at run time:Together they give a distinct result in each mode. All four lanes and both conversions must match native execution and fixed expectations.
Read-back and memory. STMXCSR must read back the loaded control bits and the requested sticky flags. The bytes next to every stored word must stay unchanged, and the caller's word must be back afterwards.
Boundary. The translated entry must restore the caller's word in each of these cases:
mxcsr_leak);mxcsr_badload) and after a valid load (mxcsr_fault).Refusals. The refused words
0x11F80,0x1D80,0x9F80and0x1FC0must return statuses 1, 2, 3 and 3. Each must stop the guest before its next store, with MXCSR unchanged. A refusal status stays with its thread while another thread calls the same entry successfully.Default profile. It must refuse each LDMXCSR and STMXCSR of the fixture on its own.
Controls (both must fail):
noload: the word is checked but never loaded.fixed: STMXCSR stores0x1F80./O2. The translation is also built withcl /O2and must keep every rule. Every export must still reach at least its source's LDMXCSR and STMXCSR.Native reference. In a child process, a native LDMXCSR of a reserved bit raises a #GP, which Windows reports as
access violation reading 0xFFFFFFFFFFFFFFFF. This is recorded as a reference observation, not as the promised status of the checked entry.Not tested:
fenv_accessitself has no separate negative control. MSVC's own documentation is the basis for it, and the rounding comparisons pass in both the normal and the/O2build.Verification
At
2fca753(onmain8084aee) on Windows 11 Pro (build 26100), Intel Core i7-6820HQ, MSVC 19.52, Python 3.12:ctest --preset dev --no-tests=error -R '^cpu_aot_mxcsr$' -V: passes. The output includes:the default profile refuses each of the 8 MXCSR instructions on its own: 6 LDMXCSR, 2 STMXCSR;noloadcontrol:rounding control 0: lanes/conversions (… 1065353216, 1065353217), (2, -2), expected (… 1065353216, 1065353218, 3, -3);fixedcontrol:entry STMXCSR stored 0x1f80, caller 0x7fa0.ctest --preset dev --no-tests=error -R '^cpu_' -j 4: 191 of 192 pass, with three capability skips (cpu_aot_fences_hints_clwb,cpu_aot_crypto_sha,cpu_shim_chain_hardware).cpu_shim_shadow_hardwarein its native run, independent of this change and reported in #799.tools/form_coverage.pyon a JUnit run of that suite no longer listsldmxcsrorstmxcsr.tests/docs_links_check.py,tests/bidi_controls_check.pyandtests/form_coverage_check.pypass.No README row lists individual lowered instructions, so the README is unchanged.
Out of scope
FTZ and DAZ (refused with status 3), the VEX forms, unmasked exceptions, and AMD hosts (not run).
Refs #995
AI-assisted: written with Claude Code; design and diff reviewed by fresh agents; checked and submitted by the account owner.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T21:12:33Z.
The /O2 rounding fixtures and the SEH restoration match the agreed first slice. One edge is missing from the status contract:
mxcsr_entrycurrently writeslast_statusafter the__finally. If this export first returns a refusal and later faults, the second call restores MXCSR but leaves the first call's refusal visible. Please clear the per-export status at entry or publish the current status in the finally block, and check refusal followed by a fault on the same export/thread. The exception remains the fault result.Please also state the entry environment before the guest's first LDMXCSR (masked exceptions and DAZ/FTZ off, any allowed rounding and sticky flags) and keep the initial opt-in boundary to the tested leaf profile. Use the first-line source coverage marker for the translated fixture, leaving the native-only MXCSR harness out of the coverage count.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T21:24:50Z.
I pushed
6832a9ddto update the refusal status in the same__finallythat restores MXCSR. The new same-thread, same-export control first records a reserved-bit refusal, then takes a guest access violation. It failed on the previous head due to stale status and passes with the fix, including the explicit/O2translation.ctest --preset release --no-tests=error -R '^cpu_aot_mxcsr$' -Vpassed 1/1. The notes now state the starting MXCSR requirements. GitHub CI is running on the updated head.Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-23T21:28:18Z.
Thanks for
6832a9dd. With it on the Skylake host (Windows 11 26100, MSVC 19.52,devpreset),ctest --preset dev --no-tests=error -R '^cpu_aot_mxcsr$' -Vpasses 1/1, including your refusal-then-fault control and the/O2translation.tests/form_coverage_check.pypasses with only the first-line marker counting the translated fixture andmxcsr_harnessleft as native-only.AI-assisted (Claude Code).