cpu: cpu_sse2_aot lowers SQRTSD of a negative denormal to the real indefinite under MXCSR.DAZ #2536

Closed
opened 2026-11-25 20:25:18 +00:00 by Asimmimx · 0 comments
Asimmimx commented 2026-11-25 20:25:18 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-25T20:25:18Z.


Commit or build

main at ae5d482a, dev preset. AMD Ryzen 5 5500, Windows 11 build 26300.

Summary

tools/cpu_sse2_aot.py lowers sqrtsd xmm, xmm/m64 through the C helper op_sqrtsd_q. The helper returns 0xFFF8000000000000 for any operand with v < 0.0 and otherwise calls std::sqrt. With MXCSR.DAZ set, the processor reads a denormal source operand as a zero of its sign, so SQRTSD of a negative denormal returns -0 (0x8000000000000000). The lifted function returns the real indefinite instead. A NaN then takes the place of -0 and spreads through later arithmetic.

The sibling helpers op_maxsd_q and op_minsd_q already execute the host instruction for this reason, and tests/cpu/sse2_regs_check.py already checks them under DAZ (check_daz_extrema).

Reproduction

Add op_sqrtsd_reg and op_sqrtsd_mem cases to check_daz_extrema in tests/cpu/sse2_regs_check.py (see the linked PR), then run:

ctest --preset dev --no-tests=error -R '^cpu_aot_sse2_regs$' -V

MXCSR 0x1FC0 (DAZ set). Destination low qword 0x3FF0000000000000, high qword 7; source 0x800123456789ABCD.

Observed (lifted)

got 000000000000f8ff0700000000000000…: low qword 0xFFF8000000000000.

Expected (native DLL, same case)

0000000000000080070000000000000…: low qword 0x8000000000000000 (-0).

A scratch native-vs-lifted sweep of all 67 exports of the SSE2 fixture found no other mismatch. It used 7 MXCSR values (the default, the three other rounding modes, DAZ, FTZ and DAZ+FTZ) and 400 edge or random input pairs per export. The only mismatches were op_sqrtsd_reg and op_sqrtsd_mem under DAZ and under DAZ+FTZ.

Reference

Intel SDM Vol. 1, 10.2.3.4 (Denormals-Are-Zeros): with DAZ set, denormal source operands are treated as zeros of the same sign. The SQRTSD entry gives -0 as the square root of -0.

Not established

  • Behaviour on Intel hardware (not run).
  • Whether any title executes SQRTSD on a negative denormal with DAZ set.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6613062674 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2544). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-25T20:25:18Z. --- ### Commit or build `main` at `ae5d482a`, dev preset. AMD Ryzen 5 5500, Windows 11 build 26300. ### Summary `tools/cpu_sse2_aot.py` lowers `sqrtsd xmm, xmm/m64` through the C helper `op_sqrtsd_q`. The helper returns `0xFFF8000000000000` for any operand with `v < 0.0` and otherwise calls `std::sqrt`. With MXCSR.DAZ set, the processor reads a denormal source operand as a zero of its sign, so SQRTSD of a negative denormal returns -0 (`0x8000000000000000`). The lifted function returns the real indefinite instead. A NaN then takes the place of -0 and spreads through later arithmetic. The sibling helpers `op_maxsd_q` and `op_minsd_q` already execute the host instruction for this reason, and `tests/cpu/sse2_regs_check.py` already checks them under DAZ (`check_daz_extrema`). ### Reproduction Add `op_sqrtsd_reg` and `op_sqrtsd_mem` cases to `check_daz_extrema` in `tests/cpu/sse2_regs_check.py` (see the linked PR), then run: ``` ctest --preset dev --no-tests=error -R '^cpu_aot_sse2_regs$' -V ``` MXCSR 0x1FC0 (DAZ set). Destination low qword 0x3FF0000000000000, high qword 7; source 0x800123456789ABCD. ### Observed (lifted) `got 000000000000f8ff0700000000000000…`: low qword 0xFFF8000000000000. ### Expected (native DLL, same case) `0000000000000080070000000000000…`: low qword 0x8000000000000000 (-0). A scratch native-vs-lifted sweep of all 67 exports of the SSE2 fixture found no other mismatch. It used 7 MXCSR values (the default, the three other rounding modes, DAZ, FTZ and DAZ+FTZ) and 400 edge or random input pairs per export. The only mismatches were `op_sqrtsd_reg` and `op_sqrtsd_mem` under DAZ and under DAZ+FTZ. ### Reference Intel SDM Vol. 1, 10.2.3.4 (Denormals-Are-Zeros): with DAZ set, denormal source operands are treated as zeros of the same sign. The SQRTSD entry gives -0 as the square root of -0. ### Not established - Behaviour on Intel hardware (not run). - Whether any title executes SQRTSD on a negative denormal with DAZ set. AI-assisted (Claude Code).
Sign in to join this conversation.
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#2536
No description provided.