startup: gfx2hlsl f32 nlt/nle/ngt/nge (FXC) and u/o (DXC) compares are wrong on NaN without IEEE-strict compiles #1929

Closed
opened 2026-11-24 21:48:40 +00:00 by MasterDomino · 2 comments
MasterDomino commented 2026-11-24 21:48:40 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T21:48:40Z.


Summary

Six f32 VOPC conditions in tools/startup/gfx2hlsl.py are exact in HLSL but give the wrong result on NaN sources after compilation with default flags. Neither compiler treats float compares as IEEE-strict unless asked: FXC needs /Gis and DXC needs -Gis.

Condition Current lowering Compiler What the compiler emits Result on a NaN pair ISA
nlt / nle / ngt / nge !(a < b) etc. FXC ps_5_1, default flags ge / gt / le / lt (the negation folded into the opposite relation) 0 1
u (a != a || b != b) DXC ps_6_0, default flags constant 0.0 stored to all four channels 0 1
o (a == a && b == b) DXC ps_6_0, default flags folded to true 1 0

The startup cache compiles every gfx2hlsl pair with FXC and no flags (translate_to in tools/startup/gfx2hlsl.py runs fxc /T <profile> /E main), so the FXC row reaches real translated stages. Of 186 locally translated HLSL stages, 3 contain an n-form compare. That is an aggregate count; no other local data is used here. No local stage has u or o, and the DXC row currently affects only DXC builds of the same text (tests and any future DXC path).

This is the same class as #1920 (lg/nlg), where DXC's fast compares broke less-or-greater. #1930 fixes those two with a bit test of both source words.

Measured

Every f32 condition the compare table lowers was drawn through gfx2hlsl, one source-built pixel program per condition. The 16 × 16 pixels cover every pair of 16 source words: ±0, ±min denormal, ±1.0, ±max finite, ±inf, ±quiet NaN, ±signalling NaN and ±NaN with a payload. Each image was compared with the ISA reference (denormals kept or flushed) and with a "NaN-blind" model: the n-forms false on NaN, u false and o true.

  • Commit: fc9517aa (#1930's head, on main b96960b7).
  • Compilers: Windows SDK 10.0.26100.0 fxc.exe and dxc.exe.
  • Adapters: Microsoft WARP, and AMD Radeon RX 9070 XT (driver 32.0.31044.16, Windows 11 build 26300, debug layer off).
FXC FXC /Gis DXC DXC -Gis
nlt nle ngt nge NaN-blind, WARP and hardware ISA ISA ISA
u o ISA ISA NaN-blind, WARP and hardware ISA
f lt eq le gt ge neq, and lg nlg (#1930) ISA ISA ISA ISA

WARP and the RX 9070 XT agree in every cell, so the result is decided by the bytecode, not the driver. The FXC listing for nlt ends in ge r0.x, r0.x, r0.y; with /Gis it keeps lt [precise(x)] and inverts the select. The DXC u listing has no fcmp and stores 0.000000e+00 to all four channels; with -Gis the compares stay.

neq is not affected: both compilers turn !(a == b) into an unordered not-equal, which is still true on NaN.

Proposed fix

Make the lowering independent of compiler flags, as #1930 does for lg, rather than add /Gis to the cache build. A flag would change every float operation in every translated stage, not only these compares.

  • nlt / nle / ngt / nge: !(ORDERED && a OP b), the same shape as nlg after #1930. ORDERED is the integer test (w & 0x7fffffffu) <= 0x7f800000u on both source words, read before neg/abs. Any rewrite of the inner relation is then masked by an integer NaN test.
  • o: ORDERED.
  • u: !ORDERED.

The completion condition:

  • A pure-Python control that evaluates the emitted text both under IEEE compares and under the two observed compiler rewrites (the negation folded into the opposite relation; x != x and x == x folded to constants). The new text must hold under all three; the old text must fail under the rewrite that broke it.
  • Pixel-checked draws of every f32 condition, with FXC and DXC, on WARP and hardware. The old text must fail its draw on the compiler where it was measured broken.

I'd like to take this. It builds on #1930's bit test, so the PR will be stacked on that branch.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6592085445 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1936). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T21:48:40Z. --- ## Summary Six f32 VOPC conditions in `tools/startup/gfx2hlsl.py` are exact in HLSL but give the wrong result on NaN sources after compilation with default flags. Neither compiler treats float compares as IEEE-strict unless asked: FXC needs `/Gis` and DXC needs `-Gis`. | Condition | Current lowering | Compiler | What the compiler emits | Result on a NaN pair | ISA | |---|---|---|---|---|---| | `nlt` / `nle` / `ngt` / `nge` | `!(a < b)` etc. | FXC `ps_5_1`, default flags | `ge` / `gt` / `le` / `lt` (the negation folded into the opposite relation) | 0 | 1 | | `u` | `(a != a \|\| b != b)` | DXC `ps_6_0`, default flags | constant `0.0` stored to all four channels | 0 | 1 | | `o` | `(a == a && b == b)` | DXC `ps_6_0`, default flags | folded to true | 1 | 0 | The startup cache compiles every `gfx2hlsl` pair with FXC and no flags (`translate_to` in `tools/startup/gfx2hlsl.py` runs `fxc /T <profile> /E main`), so the FXC row reaches real translated stages. Of 186 locally translated HLSL stages, 3 contain an n-form compare. That is an aggregate count; no other local data is used here. No local stage has `u` or `o`, and the DXC row currently affects only DXC builds of the same text (tests and any future DXC path). This is the same class as #1920 (`lg`/`nlg`), where DXC's fast compares broke less-or-greater. #1930 fixes those two with a bit test of both source words. ## Measured Every f32 condition the compare table lowers was drawn through `gfx2hlsl`, one source-built pixel program per condition. The 16 × 16 pixels cover every pair of 16 source words: ±0, ±min denormal, ±1.0, ±max finite, ±inf, ±quiet NaN, ±signalling NaN and ±NaN with a payload. Each image was compared with the ISA reference (denormals kept or flushed) and with a "NaN-blind" model: the n-forms false on NaN, `u` false and `o` true. - **Commit:** `fc9517aa` (#1930's head, on `main` `b96960b7`). - **Compilers:** Windows SDK 10.0.26100.0 `fxc.exe` and `dxc.exe`. - **Adapters:** Microsoft WARP, and AMD Radeon RX 9070 XT (driver 32.0.31044.16, Windows 11 build 26300, debug layer off). | | FXC | FXC `/Gis` | DXC | DXC `-Gis` | |---|---|---|---|---| | `nlt` `nle` `ngt` `nge` | **NaN-blind**, WARP and hardware | ISA | ISA | ISA | | `u` `o` | ISA | ISA | **NaN-blind**, WARP and hardware | ISA | | `f` `lt` `eq` `le` `gt` `ge` `neq`, and `lg` `nlg` (#1930) | ISA | ISA | ISA | ISA | WARP and the RX 9070 XT agree in every cell, so the result is decided by the bytecode, not the driver. The FXC listing for `nlt` ends in `ge r0.x, r0.x, r0.y`; with `/Gis` it keeps `lt [precise(x)]` and inverts the select. The DXC `u` listing has no `fcmp` and stores `0.000000e+00` to all four channels; with `-Gis` the compares stay. `neq` is not affected: both compilers turn `!(a == b)` into an unordered not-equal, which is still true on NaN. ## Proposed fix Make the lowering independent of compiler flags, as #1930 does for `lg`, rather than add `/Gis` to the cache build. A flag would change every float operation in every translated stage, not only these compares. - **`nlt` / `nle` / `ngt` / `nge`:** `!(ORDERED && a OP b)`, the same shape as `nlg` after #1930. `ORDERED` is the integer test `(w & 0x7fffffffu) <= 0x7f800000u` on both source words, read before neg/abs. Any rewrite of the inner relation is then masked by an integer NaN test. - **`o`:** `ORDERED`. - **`u`:** `!ORDERED`. The completion condition: - A pure-Python control that evaluates the emitted text both under IEEE compares and under the two observed compiler rewrites (the negation folded into the opposite relation; `x != x` and `x == x` folded to constants). The new text must hold under all three; the old text must fail under the rewrite that broke it. - Pixel-checked draws of every f32 condition, with FXC and DXC, on WARP and hardware. The old text must fail its draw on the compiler where it was measured broken. I'd like to take this. It builds on #1930's bit test, so the PR will be stacked on that branch. AI-assisted.
R0Y00 commented 2026-11-24 22:01:05 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T21:53:18Z.


Please take the narrow per-predicate fix on top of #1930. Keep the normal production compiler flags and use bit-level NaN classification for the six reported conditions. Keep the existing denormal reference explicit in the raw-pixel comparison. For the regression, run the default FXC and DXC paths with the pre-fix text as the negative control, and record strict-flag runs as a diagnostic comparison. This separates the localized predicate change from a cache-wide compiler policy change.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7145521058 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1936#issuecomment-7145521058). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T21:53:18Z. --- Please take the narrow per-predicate fix on top of #1930. Keep the normal production compiler flags and use bit-level NaN classification for the six reported conditions. Keep the existing denormal reference explicit in the raw-pixel comparison. For the regression, run the default FXC and DXC paths with the pre-fix text as the negative control, and record strict-flag runs as a diagnostic comparison. This separates the localized predicate change from a cache-wide compiler policy change.
MasterDomino commented 2026-11-24 22:01:07 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T22:00:36Z.


PR: #1949, stacked on #1930 and to be merged after it. It is the narrow per-predicate fix with compiler flags unchanged:

  • nlt/nle/ngt/nge read !(ORDERED && a OP b);
  • o and u read ORDERED and !ORDERED.

Negative control: the default-flag FXC and DXC paths run the pre-fix text. It fails on the compiler that rewrote it (156 NaN pixels on WARP and the RX 9070 XT) and matches that rewrite's image.

Diagnostic (recorded, not checked): with /Gis and -Gis, the pre-fix and the fixed text both match every pixel.

Denormals: the raw-pixel comparison still names the image it matched, kept or flushed. Both backends flushed, consistently across the fixtures whose image depends on it.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7145680328 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1936#issuecomment-7145680328). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T22:00:36Z. --- PR: #1949, stacked on #1930 and to be merged after it. It is the narrow per-predicate fix with compiler flags unchanged: - `nlt`/`nle`/`ngt`/`nge` read `!(ORDERED && a OP b)`; - `o` and `u` read `ORDERED` and `!ORDERED`. **Negative control:** the default-flag FXC and DXC paths run the pre-fix text. It fails on the compiler that rewrote it (156 NaN pixels on WARP and the RX 9070 XT) and matches that rewrite's image. **Diagnostic (recorded, not checked):** with `/Gis` and `-Gis`, the pre-fix and the fixed text both match every pixel. **Denormals:** the raw-pixel comparison still names the image it matched, kept or flushed. Both backends flushed, consistently across the fixtures whose image depends on it. AI-assisted.
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#1929
No description provided.