Skip to content

startup: gfx2hlsl lowers f32 lg/nlg compares as unordered (wrong for NaN) #1920

Done

Description

@MasterDomino

tools/startup/gfx2hlsl.py compare() lowers the f32 conditions lg as a != b and nlg as !(a != b). In the gfx10 ISA:

  • V_CMP_LG_F32 is "less or greater", i.e. ordered and not equal: false when either operand is NaN.
  • V_CMP_NLG_F32 is its negation: true when either operand is NaN.

HLSL != is unordered (true with NaN), so both lowerings give the opposite result whenever an operand is NaN. This applies to the plain, _e64 and (with #1915) SDWA forms of v_cmp_lg_f32, v_cmpx_lg_f32, v_cmp_nlg_f32 and v_cmpx_nlg_f32. The other conditions in the table (eq, lt, le, gt, ge, neq, nlt, nle, ngt, nge, o, u) map correctly. One local shader cache on current main uses v_cmp_nlg_f32_e64 3 times.

Scope. Lower lg as (a < b || a > b) and nlg as its negation. Keep the other conditions unchanged. Check how pixel_aot lowers lg/nlg and keep the two consistent; if pixel_aot has the same issue, note it rather than mixing both into one PR.

Acceptance.

  • An exhaustive check of every f32 condition in the table over values including ±0, ±denormal, ±inf and quiet and signalling NaN in either operand, against a reference built from the ISA definitions.
  • A source-built draw on WARP and hardware where v_cmp_lg_f32 and v_cmp_nlg_f32 with a NaN operand decide pixel output, checked pixel by pixel.
  • A negative control restoring the != lowering must fail both.

I'd like to take this. It builds on #1915's restructured compare(), so I'll stack it on that branch, or rebase once #1915 lands.

AI-assisted.

Activity

  1. MasterDomino commented on Nov 24, 2026

    @MasterDomino
    CollaboratorAuthor

    PR: #1930. lg is now ordered-and-unequal behind a bit-level NaN test of both source words, nlg its negation; other conditions unchanged. One finding that shaped it: DXC without -Gis marks the float compares fast, and on the RX 9070 XT a < b || a > b alone returned 1 for lg and nlg on all 156 NaN pairs — hence the bit test (pixel_aot already lowers lg this way). Checks: 510 f32 forms × 256 value pairs (±0, denormals, ±inf, quiet/signalling/payload NaN) against the ISA reference; draws with 88 unequal, 12 equal and 156 NaN pairs — FXC and DXC, WARP and RX 9070 XT, every pixel matches; the old != lowering fails every fixture. f32 SDWA compares stay refused.

    AI-assisted.

  2. added a commit that references this issue on Nov 24, 2026
    fc9517a
  3. added 2 commits that reference this issue on Nov 25, 2026
    718fa87
    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