Skip to content

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

Closed
romn4rch wants to merge 3 commits into
R0Y00:mainfrom
romn4rch:romn4rch-ftz-daz-mxcsr-1048
Closed

romn4rch wants to merge 3 commits into
R0Y00:mainfrom
romn4rch:romn4rch-ftz-daz-mxcsr-1048

Conversation

@romn4rch

Copy link
Copy Markdown
Contributor

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 -

romn4rch and others added 3 commits November 24, 2026 03:29
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@R0Y00

R0Y00 commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thanks for adding the missing native export. I pushed 4f2435d 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 added a commit to legacy-code-archaeologist/Xbox2Windows that referenced this pull request Nov 23, 2026
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>
@R0Y00

R0Y00 commented Nov 24, 2026

Copy link
Copy Markdown
Owner

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.

@R0Y00 R0Y00 closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cpu: accept FTZ and DAZ in the host-MXCSR profile

2 participants