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

Merged
legacy-code-archaeologist merged 2 commits from upstream-pr/1057 into main 2026-11-24 00:10:41 +00:00
legacy-code-archaeologist commented 2026-11-23 23:39:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-23T23:39:15Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6571145884 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1057). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-23T23:39:15Z. --- ## 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)
upstream-sync closed this pull request 2026-11-24 06:46:03 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1050
No description provided.