cpu: accept FTZ and DAZ in the host-MXCSR profile's denormals opt-in #1057

Manually merged
github merged 2 commits from gh-pr/1057/head into gh-pr/1057/base 2026-11-26 22:38:10 +00:00
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-23 23:39 UTC · original
legacy-code-archaeologist:cpu/mxcsr-denormals → main · +378 −9 · 8 files · 2 commits · merged 2026-11-24 00:10 UTC

Change

As agreed in #1048, the host-MXCSR profile from #1009 gets a denormals opt-in, Mxcsr(reject, denormals=True) with mxcsr_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.

  • Probe. Each opted-in entry reads MXCSR_MASK once, with _fxsave64 into a 16-byte-aligned 512-byte area, at offset 28. A stored 0 counts as the architectural default 0xFFBF. The mask is passed to the lowered body as mxcsr_mask.
  • Refusal. LDMXCSR refuses any requested bit outside the mask with status 3 before the host register changes. On a host without DAZ that is the DAZ bit; FTZ is in every mask.
  • Unchanged from #1009: the reserved-bit and unmasked-exception refusals come first, and the boundary restores the caller's whole word on return, refusal and fault.

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 word 0x7FA0.

FTZ case. Normal operands with exact sums of -2^-127 and +2^-127. The sums are 0x80400000 and 0x00400000; with FTZ they are 0x80000000 and 0x00000000.

DAZ case. Signed subnormal operands, each lane with a fixed raw word per combination:

Operands Without DAZ With FTZ With DAZ
2^-126 + (-2^-140) 0x007FFE00 0x00000000 0x00800000
the same, both signs swapped 0x807FFE00 0x80000000 0x80800000
-2^-140 + 0 0x80000200 0x80000000 0x00000000 to nearest, 0x80000000 toward negative infinity

The 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.

  • The native harness reads the host's mask (mxcsr_mask_of). Here it reports 0xFFFF.
  • A host without DAZ runs the FTZ checks, expects every DAZ word to be refused, reports nodaz as not measurable, and exits 77.
  • I checked that path by simulating the harness mask with the sim translation. The output is skip: this host's MXCSR_MASK has no DAZ; the FTZ checks above passed, then exit 77.

Variants:

  • sim replaces only the probed capability with 0xFFBF. It must keep every rule: DAZ is refused before LDMXCSR with every output unchanged, FTZ still works, and the caller's word is restored.
  • noftz and nodaz clear the bit before loading, and must fail.
  • nomask removes 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 with cl /O2 and keeps every rule.

Verification

At 2a7f1b7 (on main d4cbfcd) on Windows 11 Pro (build 26100), Intel Core i7-6820HQ (MXCSR_MASK 0xFFFF), MSVC 19.52, Python 3.12:

  • ctest --preset dev --no-tests=error -R '^cpu_aot_mxcsr_denormals$' -V: passes. cpu_aot_mxcsr still passes.
  • ctest --preset release --no-tests=error -R '^cpu_aot_mxcsr(_denormals)?$': 2/2 pass. Only these tests' targets were built in release.
  • ctest --preset dev --no-tests=error -R '^cpu_' -j 4: 202 of 203 pass, with three capability skips.
    • The failure is cpu_shim_shadow_hardware in its native run, independent of this change and reported in #799.
  • tests/docs_links_check.py, tests/bidi_controls_check.py and tests/form_coverage_check.py pass.

docs/experiments.md gains 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

  • I did not include game files, dumps, distribution links or secrets.

AI-assisted: written with Claude Code; diff reviewed by a fresh agent; checked and submitted by the account owner.

🤖 Generated with Claude Code

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-23 23:39 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1057) `legacy-code-archaeologist:cpu/mxcsr-denormals` → `main` · +378 −9 · 8 files · 2 commits · merged 2026-11-24 00:10 UTC ## Change As agreed in #1048, the host-MXCSR profile from #1009 gets a denormals opt-in, `Mxcsr(reject, denormals=True)` with `mxcsr_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. - **Probe.** Each opted-in entry reads `MXCSR_MASK` once, with `_fxsave64` into a 16-byte-aligned 512-byte area, at offset 28. A stored 0 counts as the architectural default `0xFFBF`. The mask is passed to the lowered body as `mxcsr_mask`. - **Refusal.** LDMXCSR refuses any requested bit outside the mask with status 3 before the host register changes. On a host without DAZ that is the DAZ bit; FTZ is in every mask. - **Unchanged from #1009:** the reserved-bit and unmasked-exception refusals come first, and the boundary restores the caller's whole word on return, refusal and fault. ## Tests `cpu_aot_mxcsr_denormals` ([`mxcsr_denormals.asm`](tests/cpu/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 word `0x7FA0`. **FTZ case.** Normal operands with exact sums of -2^-127 and +2^-127. The sums are `0x80400000` and `0x00400000`; with FTZ they are `0x80000000` and `0x00000000`. **DAZ case.** Signed subnormal operands, each lane with a fixed raw word per combination: | Operands | Without DAZ | With FTZ | With DAZ | |---|---|---|---| | 2^-126 + (-2^-140) | `0x007FFE00` | `0x00000000` | `0x00800000` | | the same, both signs swapped | `0x807FFE00` | `0x80000000` | `0x80800000` | | -2^-140 + 0 | `0x80000200` | `0x80000000` | `0x00000000` to nearest, `0x80000000` toward negative infinity | The 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.** - The native harness reads the host's mask (`mxcsr_mask_of`). Here it reports `0xFFFF`. - A host without DAZ runs the FTZ checks, expects every DAZ word to be refused, reports `nodaz` as not measurable, and exits 77. - I checked that path by simulating the harness mask with the `sim` translation. The output is `skip: this host's MXCSR_MASK has no DAZ; the FTZ checks above passed`, then exit 77. **Variants:** - `sim` replaces only the probed capability with `0xFFBF`. It must keep every rule: DAZ is refused before LDMXCSR with every output unchanged, FTZ still works, and the caller's word is restored. - `noftz` and `nodaz` clear the bit before loading, and must fail. - `nomask` removes 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 with `cl /O2` and keeps every rule. ## Verification At `2a7f1b7` (on `main` `d4cbfcd`) on Windows 11 Pro (build 26100), Intel Core i7-6820HQ (`MXCSR_MASK` `0xFFFF`), MSVC 19.52, Python 3.12: - `ctest --preset dev --no-tests=error -R '^cpu_aot_mxcsr_denormals$' -V`: passes. `cpu_aot_mxcsr` still passes. - `ctest --preset release --no-tests=error -R '^cpu_aot_mxcsr(_denormals)?$'`: 2/2 pass. Only these tests' targets were built in `release`. - `ctest --preset dev --no-tests=error -R '^cpu_' -j 4`: 202 of 203 pass, with three capability skips. - The failure is `cpu_shim_shadow_hardware` in its native run, independent of this change and reported in #799. - `tests/docs_links_check.py`, `tests/bidi_controls_check.py` and `tests/form_coverage_check.py` pass. `docs/experiments.md` gains 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 - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted: written with Claude Code; diff reviewed by a fresh agent; checked and submitted by the account owner. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
As agreed in #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 <[email protected]>
Adapt the separate FTZ and DAZ CTest structure from #1052. Keep the simulated mask bypass observable without requesting DAZ from the real host.

Co-authored-by: romanv9 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:38:09 +00:00
github manually merged commit c36b663f82 into gh-pr/1057/base 2026-11-26 22:38:10 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.