Skip to content

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

Done

Description

@MasterDomino

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.

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 startup: lower gfx2hlsl f32 lg/nlg compares as ordered #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.

Activity

  1. R0Y00 commented on Nov 24, 2026

    @R0Y00
    Owner

    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.

  2. MasterDomino commented on Nov 24, 2026

    @MasterDomino
    CollaboratorAuthor

    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.

  3. added a commit that references this issue on Nov 24, 2026
    583178d
  4. added a commit that references this issue on Nov 25, 2026
    e8a77f8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions