Repository navigation
cpu: accept FTZ and DAZ in the host-MXCSR profile's denormals opt-in - #1057
Merged
Merged
Conversation
As agreed in R0Y00#1048, Mxcsr(reject, denormals=True) with mxcsr_entry(..., denormals=True) accepts FTZ and DAZ where the host supports them; the default keeps refusing both with status 3. Each entry reads MXCSR_MASK once with FXSAVE into a 16-byte-aligned 512-byte area, treats a zero mask as 0xFFBF and passes it to the lowered body. There LDMXCSR refuses any requested bit outside the mask before the host register changes. Reserved bits and unmasked exceptions keep their refusals, and the boundary restores the caller's word as before. cpu_aot_mxcsr_denormals loads none, FTZ, DAZ and both under two rounding controls. An FTZ case with normal operands and signed tiny sums and a DAZ case with signed subnormal operands are compared with fixed raw words, measured natively, and with native execution. A sim variant replaces only the probed mask and must keep every rule; noftz, nodaz and nomask must break one. A host without DAZ runs the FTZ checks and exits 77. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adapt the separate FTZ and DAZ CTest structure from R0Y00#1052. Keep the simulated mask bypass observable without requesting DAZ from the real host. Co-authored-by: romanv9 <154753195+romanv9@users.noreply.github.com>
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change
As agreed in #1048, the host-MXCSR profile from #1009 gets a denormals opt-in,
Mxcsr(reject, denormals=True)withmxcsr_entry(..., denormals=True). It accepts FTZ and DAZ where the host supports them. The default and the existing statuses are unchanged: without the opt-in, FTZ and DAZ are still refused with status 3, and the generated code is byte-identical to before.MXCSR_MASKonce, with_fxsave64into a 16-byte-aligned 512-byte area, at offset 28. A stored 0 counts as the architectural default0xFFBF. The mask is passed to the lowered body asmxcsr_mask.Tests
cpu_aot_mxcsr_denormals(mxcsr_denormals.asm) loads the four combinations (none, FTZ, DAZ, both), each under round to nearest and toward negative infinity, from the non-default caller word0x7FA0.FTZ case. Normal operands with exact sums of -2^-127 and +2^-127. The sums are
0x80400000and0x00400000; with FTZ they are0x80000000and0x00000000.DAZ case. Signed subnormal operands, each lane with a fixed raw word per combination:
0x007FFE000x000000000x008000000x807FFE000x800000000x808000000x800002000x800000000x00000000to nearest,0x80000000toward negative infinityThe raw words were measured with the native instructions on this host, then fixed in the test. Translated results must equal them and native execution.
Also checked, as in
cpu_aot_mxcsr: STMXCSR reads back the control bits; adjacent bytes stay unchanged; a refusal marker shows guest work runs only after an accepted word; and the caller's word is restored after return and after a guest fault.Capability.
mxcsr_mask_of). Here it reports0xFFFF.nodazas not measurable, and exits 77.simtranslation. The output isskip: this host's MXCSR_MASK has no DAZ; the FTZ checks above passed, then exit 77.Variants:
simreplaces only the probed capability with0xFFBF. It must keep every rule: DAZ is refused before LDMXCSR with every output unchanged, FTZ still works, and the caller's word is restored.noftzandnodazclear the bit before loading, and must fail.nomaskremoves the capability check on the simulated host, so DAZ loads anyway. It must fail:den_add(0x1fc0) on a host without DAZ: return 7, status 0./O2: the translation is also built withcl /O2and keeps every rule.Verification
At
2a7f1b7(onmaind4cbfcd) on Windows 11 Pro (build 26100), Intel Core i7-6820HQ (MXCSR_MASK0xFFFF), MSVC 19.52, Python 3.12:ctest --preset dev --no-tests=error -R '^cpu_aot_mxcsr_denormals$' -V: passes.cpu_aot_mxcsrstill passes.ctest --preset release --no-tests=error -R '^cpu_aot_mxcsr(_denormals)?$': 2/2 pass. Only these tests' targets were built inrelease.ctest --preset dev --no-tests=error -R '^cpu_' -j 4: 202 of 203 pass, with three capability skips.cpu_shim_shadow_hardwarein its native run, independent of this change and reported in Create the EXE shadow device through the Xbox shim #799.tests/docs_links_check.py,tests/bidi_controls_check.pyandtests/form_coverage_check.pypass.docs/experiments.mdgains a paragraph after the MXCSR one. The MXCSR paragraph now says FTZ and DAZ are outside the default profile.Not run: an AMD host, or a physical host without DAZ (only simulated).
Refs #1048
AI-assisted: written with Claude Code; diff reviewed by a fresh agent; checked and submitted by the account owner.
🤖 Generated with Claude Code