cpu: how should the shared lowering handle LDMXCSR and STMXCSR? #995
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows#995
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@legacy-code-archaeologist on GitHub · 2026-11-23 20:24 UTC · original
Claim and design question: how should the shared lowering handle
LDMXCSRandSTMXCSR?ldmxcsrandstmxcsr(SSE group) andvldmxcsrandvstmxcsr(AVX group) ofdocs/coverage/x64_zen2.tsvhave no passing fixture, and no translator accepts them. The shared lowering assumes the default MXCSR today.tools/ffx_version_query.pyrefuses an explicit non-default rounding immediate withunsupported MXCSR rounding mode, andtools/cpu_sse2_aot.pydocuments 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
STMXCSR m32stores_mm_getcsr(), andLDMXCSR m32calls_mm_setcsr().#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.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.Proposed first increment, if you agree with option 1:
host_cpuandhost_entropy.#pragma fenv_access(on)in files that use it.LDMXCSRand reads it back withSTMXCSR;ADDSS/MULSS/CVTSS2SIon inputs whose results depend on the mode (ties, denormals);0x1F80, and a reserved-bitLDMXCSRin a child process (same fault both ways).Questions
Test host: Intel Skylake (i7-6820HQ) on Windows 11 26100.
AI-assisted (Claude Code).
@R0Y00 on GitHub · 2026-11-23 20:30 UTC · original
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
@R0Y00 on GitHub · 2026-11-23 21:41 UTC · original
The agreed first increment landed in #1009 (
44c7a7b4). 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.