Repository navigation
Description
Claim and design question: how should the shared lowering handle LDMXCSR and STMXCSR?
ldmxcsr and stmxcsr (SSE group) and vldmxcsr and vstmxcsr (AVX group) of docs/coverage/x64_zen2.tsv have no passing fixture, and no translator accepts them. The shared lowering assumes the default MXCSR today. tools/ffx_version_query.py refuses an explicit non-default rounding immediate with unsupported MXCSR rounding mode, and tools/cpu_sse2_aot.py documents round-to-nearest-even. CRT startup and game code commonly read and write MXCSR, for example _controlfp, fesetround, or setting FTZ/DAZ for denormal performance. So these two instructions sit on the path to #870. I found no open issue or PR about them and would like to take a first increment. The model is a design decision, so I'm asking before I start.
Options
- Host passthrough (opt-in profile, like cpu: lower CPUID and XGETBV in an opt-in host-CPU profile #937).
STMXCSR m32stores_mm_getcsr(), andLDMXCSR m32calls_mm_setcsr().- Translated float operations are host SSE instructions, so they follow the new rounding mode and FTZ/DAZ at run time.
- Risk: the C++ compiler may fold or reorder float operations across the MXCSR write unless the generated file uses
#pragma fenv_access(on)(or/fp:strict). A guestLDMXCSRwith reserved bits set raises #GP natively;_mm_setcsrhas to reproduce that, or the lowering has to check the value.
- Fixed default profile.
STMXCSRstores the current guest value, initially0x1F80.LDMXCSRaccepts only values that keep round-to-nearest-even with FTZ and DAZ clear, so only the exception masks and sticky flags may change. Any other value is refused at run time through a named host fault.- This keeps every existing float lowering valid without changes, but programs that set FTZ/DAZ would stop there.
- A guest MXCSR model. MXCSR becomes guest state, read by every float lowering. That is the most faithful option and the most invasive; I would not start there.
Proposed first increment, if you agree with option 1:
- An opt-in keyword, separate from
host_cpuandhost_entropy. #pragma fenv_access(on)in files that use it.- A source-built differential that:
- sets each rounding mode and FTZ/DAZ with
LDMXCSRand reads it back withSTMXCSR; - runs
ADDSS/MULSS/CVTSS2SIon inputs whose results depend on the mode (ties, denormals); - compares native and translated bits;
- restores the caller's MXCSR afterwards.
- sets each rounding mode and FTZ/DAZ with
- Controls: a translation that ignores the write, one that stores a fixed
0x1F80, and a reserved-bitLDMXCSRin a child process (same fault both ways).
Questions
- Which model do you want first: host passthrough, the fixed default with runtime refusal, or something else?
- Should FTZ/DAZ be in scope for the first increment, or only rounding control and the exception masks?
Test host: Intel Skylake (i7-6820HQ) on Windows 11 26100.
AI-assisted (Claude Code).
Activity
R0Y00 commentedon Nov 23, 2026
Please take a narrow opt-in host-MXCSR profile for the shared lowerer. Start with the legacy m32 load/store and a straight-line source-built leaf; VEX spellings can follow with their own encoding and host-capability checks. Use a checked, isolated call boundary that saves and restores the caller's entire MXCSR on normal return and on error, including a guarded memory fault. Keep exceptions masked in this first slice. Refuse unmasked exceptions, unsupported bits and reserved bits before loading the host register, with a distinguishable unsupported outcome. The native reserved-bit child result is a reference observation, not the promised status of the checked entry.
Test all four rounding modes by round-tripping the word and comparing an actual rounding-sensitive operation that is already supported by the shared lowerer, such as a source-built ADDSS halfway case. Keep FTZ/DAZ changes outside the first slice; they can follow with independent signed subnormal input/output cases and a hardware mask check for DAZ. Compare an input selected at runtime, use MSVC floating-environment access in code that observes the mode, and run normal and /O2. The no-op LDMXCSR and fixed STMXCSR controls should both fail. Also check a non-default caller word (including sticky flags) is restored, that adjacent memory is unchanged, and that an invalid requested value cannot run subsequent guest work. Existing fixed-profile generation stays as-is.
Intel instruction reference · MSVC floating-environment pragma
cpu: lower LDMXCSR and STMXCSR in an opt-in host-MXCSR profile
R0Y00 commentedon Nov 23, 2026
The agreed first increment landed in #1009 (44c7a7b). The opt-in legacy m32 leaf profile checks requested MXCSR, observes all four rounding modes, and restores the host word on return, refusal and fault. The source-built comparison covers the fixed-word, skipped-load and same-export fault controls, including /O2. VEX spellings and changing FTZ or DAZ remain separate follow-ups with their own capability and denormal evidence.