cpu: accept FTZ and DAZ in host-MXCSR profile #1045

Closed
romn4rch wants to merge 3 commits from upstream-pr/1052 into main
romn4rch commented 2026-11-23 23:30:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by romn4rch on 2026-11-23T23:30:43Z.


Change

The host-MXCSR profile previously refused both denormal controls, preventing opt-in translated code from matching native FTZ behavior and from using DAZ where supported. This change adds Mxcsr(reject, denormals=True): FTZ is accepted on x64 SSE2, while DAZ is gated by a per-load FXSAVE/MXCSR_MASK probe. Existing default refusals, exception checks, caller-state restoration, and VEX exclusions remain unchanged. FTZ and DAZ fixtures run separately so unsupported DAZ does not hide FTZ results.

The fixture uses runtime-fed synthetic binary32 operands, with negative controls for ignored loads/stores, FTZ/DAZ rejection, and ignoring a synthetic mask without DAZ.

Fixes #1048

Verification

  • python -B -m py_compile tests\cpu\mxcsr.py tools\ffx_version_query.py - passed.
  • python -B tests\docs_links_check.py - passed; checked 15 Markdown files and 235 links.
  • python -B tests\form_coverage_check.py - passed.
  • python -B tests\bidi_controls_check.py - passed; checked 885 tracked files.
  • git diff --check - passed.
  • Direct iced-x86 source-generation smoke checks for the default/opt-in profiles, VEX refusals, control replacements, and signed-subnormal expected bits - passed.
  • ctest --preset dev --no-tests=error -R '^cpu_aot_mxcsr(_daz)?$' -V - not run: this host lacks cl.exe, ml64.exe, and a configured dev build.

Evidence and follow-up

The MASM fixture generates its inputs at runtime and compares native and translated ADDPS results to fixed binary32 expectations. It checks signed FTZ outputs, signed DAZ inputs, all four FTZ/DAZ combinations under two rounding modes, read-back, and caller restoration. On hosts without DAZ, the translated path verifies refusal and the DAZ-specific CTest reports capability skip 77; FTZ remains independently testable. docs/experiments.md documents the behavior and reproduction command; the README has no MXCSR-specific capability row. No hardware run was performed.

AI-assisted: implemented with GitHub Copilot.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

Inline source-generation smoke command

$check = "import runpy; from iced_x86 import Decoder; m=runpy.run_path('tests/cpu/mxcsr.py'); m['rejected_vex'](); c=m['lower'](list(Decoder(64, bytes.fromhex('0fae10 0fae19 c3'), ip=0x1000)), ['rax = a;', 'rcx = b;'], {}, {}, {}, host_mxcsr=m['Mxcsr'](m['REJECT'], denormals=True)); assert all(c.count(n) for v in m['CONTROLS'] for n, _ in ([m['CONTROLS'][v]] + ([(m['DAZ_MASK_CHECK'], '')] if v == 'nomask' else []))); assert m['f32'](m['MIN_NORMAL'] - m['SUBNORMAL_INPUT']) == 0x007FFE00; assert m['f32'](-m['MIN_NORMAL'] + m['SUBNORMAL_INPUT']) == 0x807FFE00; print('profile, VEX, control, and signed-subnormal smoke checks passed')"; $check | .\out\pe-env\Scripts\python.exe -
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6571031587 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1052). Originally posted by [romn4rch](https://github.com/romn4rch) on 2026-11-23T23:30:43Z. --- ## Change The host-MXCSR profile previously refused both denormal controls, preventing opt-in translated code from matching native FTZ behavior and from using DAZ where supported. This change adds `Mxcsr(reject, denormals=True)`: FTZ is accepted on x64 SSE2, while DAZ is gated by a per-load `FXSAVE`/`MXCSR_MASK` probe. Existing default refusals, exception checks, caller-state restoration, and VEX exclusions remain unchanged. FTZ and DAZ fixtures run separately so unsupported DAZ does not hide FTZ results. The fixture uses runtime-fed synthetic binary32 operands, with negative controls for ignored loads/stores, FTZ/DAZ rejection, and ignoring a synthetic mask without DAZ. Fixes #1048 ## Verification - `python -B -m py_compile tests\cpu\mxcsr.py tools\ffx_version_query.py` - passed. - `python -B tests\docs_links_check.py` - passed; checked 15 Markdown files and 235 links. - `python -B tests\form_coverage_check.py` - passed. - `python -B tests\bidi_controls_check.py` - passed; checked 885 tracked files. - `git diff --check` - passed. - Direct `iced-x86` source-generation smoke checks for the default/opt-in profiles, VEX refusals, control replacements, and signed-subnormal expected bits - passed. - `ctest --preset dev --no-tests=error -R '^cpu_aot_mxcsr(_daz)?$' -V` - not run: this host lacks `cl.exe`, `ml64.exe`, and a configured `dev` build. ## Evidence and follow-up The MASM fixture generates its inputs at runtime and compares native and translated ADDPS results to fixed binary32 expectations. It checks signed FTZ outputs, signed DAZ inputs, all four FTZ/DAZ combinations under two rounding modes, read-back, and caller restoration. On hosts without DAZ, the translated path verifies refusal and the DAZ-specific CTest reports capability skip 77; FTZ remains independently testable. `docs/experiments.md` documents the behavior and reproduction command; the README has no MXCSR-specific capability row. No hardware run was performed. AI-assisted: implemented with GitHub Copilot. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. ## Inline source-generation smoke command ```powershell $check = "import runpy; from iced_x86 import Decoder; m=runpy.run_path('tests/cpu/mxcsr.py'); m['rejected_vex'](); c=m['lower'](list(Decoder(64, bytes.fromhex('0fae10 0fae19 c3'), ip=0x1000)), ['rax = a;', 'rcx = b;'], {}, {}, {}, host_mxcsr=m['Mxcsr'](m['REJECT'], denormals=True)); assert all(c.count(n) for v in m['CONTROLS'] for n, _ in ([m['CONTROLS'][v]] + ([(m['DAZ_MASK_CHECK'], '')] if v == 'nomask' else []))); assert m['f32'](m['MIN_NORMAL'] - m['SUBNORMAL_INPUT']) == 0x007FFE00; assert m['f32'](-m['MIN_NORMAL'] + m['SUBNORMAL_INPUT']) == 0x807FFE00; print('profile, VEX, control, and signed-subnormal smoke checks passed')"; $check | .\out\pe-env\Scripts\python.exe - ```
upstream-sync closed this pull request 2026-11-24 06:46:02 +00:00
R0Y00 commented 2026-11-24 06:49:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T23:38:32Z.


Thanks for adding the missing native export. I pushed 4f2435d6 on top after reproducing a second failure: with FTZ on and DAZ off, the DAZ probe's tiny sums have signs + and −, so native ADDPS produces +0 and −0 in that order. The normal-input FTZ probe still checks the opposite-sign pair. The opt-in now reads the host mask at the first DAZ load per invocation, with a zeroed aligned area and a byte copy, and does not cache across invocations.

On Windows x64 (MXCSR_MASK=0xFFFF), both native/lifted CTests passed in dev and release, including the separately compiled /O2 DLL, all four mode pairs, and simulated no-DAZ refusal. Command: ctest --preset <dev|release> --no-tests=error -R '^cpu_aot_mxcsr(_daz)?$' --output-on-failure

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7117193997 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1052#issuecomment-7117193997). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T23:38:32Z. --- Thanks for adding the missing native export. I pushed 4f2435d6 on top after reproducing a second failure: with FTZ on and DAZ off, the DAZ probe's tiny sums have signs + and −, so native ADDPS produces +0 and −0 in that order. The normal-input FTZ probe still checks the opposite-sign pair. The opt-in now reads the host mask at the first DAZ load per invocation, with a zeroed aligned area and a byte copy, and does not cache across invocations. On Windows x64 (MXCSR_MASK=0xFFFF), both native/lifted CTests passed in dev and release, including the separately compiled /O2 DLL, all four mode pairs, and simulated no-DAZ refusal. Command: ctest --preset <dev|release> --no-tests=error -R '^cpu_aot_mxcsr(_daz)?$' --output-on-failure
R0Y00 commented 2026-11-24 06:49:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T00:12:12Z.


The shared MXCSR-controlled path landed in #1057, including the co-authored denormal work from this PR. Thanks for the implementation and native comparisons. Closing this overlapping branch now that the consolidated version is on main.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7117814738 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1052#issuecomment-7117814738). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T00:12:12Z. --- The shared MXCSR-controlled path landed in #1057, including the co-authored denormal work from this PR. Thanks for the implementation and native comparisons. Closing this overlapping branch now that the consolidated version is on main.

Pull request closed

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!1045
No description provided.