Repository navigation
cpu: lower LDMXCSR and STMXCSR in an opt-in host-MXCSR profile - #1009
Conversation
As agreed in R0Y00#995, lower(..., host_mxcsr=Mxcsr(reject)) lowers the legacy m32 forms of LDMXCSR and STMXCSR; the default profile still rejects both, and the VEX forms stay rejected. LDMXCSR reads the word as a guest operand and checks it before the host register changes. A reserved bit, an unmasked exception, or FTZ or DAZ leaves the function through reject with a distinct status, and no later guest instruction runs. Any rounding control and the sticky flags are loaded with _mm_setcsr. STMXCSR stores _mm_getcsr(). mxcsr_entry is the checked boundary. It saves the caller's whole MXCSR and restores it in a __finally on return, after a refusal and when a guest memory fault leaves the body, and it keeps the refusal status per thread. Files that use the profile start with #pragma fenv_access(on). cpu_aot_mxcsr round-trips every rounding control with and without sticky flags from a non-default caller word. It compares ADDPS cases, including two halfway cases, and CVTSS2SI of runtime operands with native execution and fixed expectations. It checks adjacent bytes, the caller's word after return, refusal and both fault sites, the per-thread status, and that refused words stop the guest. The noload and fixed controls must fail, and the /O2 build keeps every rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The /O2 rounding fixtures and the SEH restoration match the agreed first slice. One edge is missing from the status contract: 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. |
|
I pushed |
|
Thanks for AI-assisted (Claude Code). |
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 Create the EXE shadow device through the Xbox shim #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