startup: lower gfx2hlsl f32 lg/nlg compares as ordered #1923
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1930"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T21:37:31Z.
Fixes #1920
What / Why
In the gfx10 ISA
V_CMP_LG_F32is "less or greater": ordered and not equal, false when either source is NaN.V_CMP_NLG_F32is its negation, true when either source is NaN.compare()intools/startup/gfx2hlsl.pylowered them asa != band!(a != b). HLSL!=is unordered, so both gave the opposite result on every NaN pair, in the plain and_e64forms ofv_cmpandv_cmpx.Change
lgis now(ORDERED && (a < b || a > b))andnlgis!(ORDERED && (a < b || a > b)). ORDERED is(w & 0x7fffffffu) <= 0x7f800000ufor both source words, taken before the neg/abs modifiers (the modifiers never change whether a word is NaN).-Gisemitsfcmp fast/fcmp onefor the plain less-or-greater. On the RX 9070 XT (driver 32.0.31044.16), that build of thecmpfixture returned 1 for both lg and nlg on all 156 NaN pairs. FXC on both backends and DXC on WARP gave the ordered result. This is recorded by the draw (see below). The production path compiles with FXCps_5_1.Tests
Commit under test:
fc9517aaonmainb96960b7(rebased after #1915 merged; the change itself is unchanged froma22cfaa8). After the rebase:startup_gfx2hlsl_*33/33 including both draws,binarywith llvm-mc 15.0.7 PASS.tests/startup_gfx2hlsl_f32_lg_check.py(no arguments, pure Python):510 f32 forms x 256 pairs (130560 evaluations) equal the ISA reference: ok.binary <llvm-mc>/decode <libLLVM>: LLVM 15 assembles the 510 decoded forms and the 5 pixel fixtures to the same words. The LLVM C API disassembles them to the same text. tools/disasm_rdna2.py prints the unuseds0sdst of a gfx10v_cmpx_*_e64; this is normalized as a known difference.draw, registered asstartup_gfx2hlsl_f32_lg_{warp,hardware}):cmpwritesv_cmp_lg_f32_e32,v_cmp_nlg_f32_e64 -a, |b|,v_cmp_lg_f32_e64 -|a|, -bandv_cmp_nlg_f32_e32as 1.0/0.0.cmpx_{lg,nlg}_{e32,e64}keep or discard pixels.ps_5_1and DXCps_6_0and checked pixel by pixel withoffscreen_check --startup-pixel-words. lg is 1 on unequal pairs and 0 on equal and NaN pairs; nlg is the opposite.startup_gfx2hlsl_f32_lgstartup_gfx2hlsl_f32_lg_warp: WARP (Microsoft Basic Render Driver, 10.0.26100.9818), debug layer on, 0 errorsstartup_gfx2hlsl_f32_lg_hardware: AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31044.16, debug layer on, 0 errorsEnvironment: Windows 11 Home 10.0.26300, Windows SDK 10.0.26100.0 fxc/dxc, LLVM 15 (llvm-mc), LLVM C API.
Other runs:
ctest --preset dev --no-tests=error -R '^startup_' -j 4: 262 passed, 0 failed, 4 skipped. The skips are capability skips (77) instartup_view_heap_{warp,hardware}andstartup_logical_view_{warp,hardware}, unrelated to this change. This includes all 30startup_gfx2hlsl_*tests.tests/startup_gfx2hlsl_f32_lg_check.py binary <llvm-mc>anddecode <LLVM-C.dll>: PASS.tests/docs_links_check.pyandtests/bidi_controls_check.py: pass.Negative controls
!=lowering restored.v_cmp_lg_f32_e32 vcc_lo, v1, v2withF(v1) != F(v2), a=00000000 b=7fc00000 gives 1, the ISA gives 0. It matches its own unordered model.cmpon the RX 9070 XT with FXC givespixel mismatch (10,0): expected 00000000,3f800000,00000000,3f800000 actual 3f800000,00000000,3f800000,00000000 / 156 of 256 pixels differ. Acmpx_*fixture gives 166 differing pixels against the denormals-kept image.'{0} != {1}'/'!({0} != {1})', the pure-Python check fails (510 f32 forms ... : MISMATCH, firstv_cmp_lg_f32_e32a=00000000 b=7fc00000 gives 1, ISA 0), and so does the WARP FXCcmpdraw.cmpfails withpixel mismatch (10,0): expected 00000000,3f800000,00000000,3f800000 actual 3f800000,3f800000,3f800000,3f800000 / 156 of 256 pixels differ.Not covered
tools/pixel_aot.pydoes not have this bug. ItsCOMPAREtable already lowerslgas({0} < {1} || {0} > {1})behind the same bit-level ordered test (f32_comparison), andnlgas({0} == {1} || isnan({0}) || isnan({1})). No change was made there./Gis/-Gis), observed in compiler output only and not yet in a draw:!(a < b)(nlt) to DXBCge, which is ordered, so it is false on NaN where nlt is true. The same pattern likely affectsnle,ngtandnge.u(a != a || b != b) to the constant 0 (andopresumably to true).🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T21:53:31Z.
Ran it, broke the ordered lowering four ways
Windows 11 build 26300.9974, device-free:
Mutations to
tools/startup/gfx2hlsl.py, each reverted:lgback to{0} != {1}(the old unordered text)nlgas the same expression instead of its negation<= 0x7f800000u→<= 0x7fffffff({2} && …)→(…))The third is the one I wanted:
0x7f800000(infinity) must still count as not NaN, so a<-versus-<=slip is a realsemantic change, and the fixture separates it from the fully-dropped case. Both fail, for different reasons.
What I checked by reading, not by guessing
INLINE = {0: 128, …, 0x3f800000: 242}with the value→(inline code, literal)helper at line 223. So the ORDERED term is exercised for encodings that are not SGPR/VGPR pairs, which is where a naive
word(tok)would break.0x7fc00000,0x7f800001), so the CPU reference is not justtesting the quiet case.
lt,eq,le,gt,ne,nge,o,uunchanged, and thetest compares them.
What I cannot verify
The DXC
-Gisobservation — that a driver foldsfcmp fastback to unordered on an RX 9070 XT — is a hardware measurement I haveno way to reproduce, and the production path is FXC
ps_5_1anyway. The bit test costs nothing in that path, so "required onthe DXC path, harmless on FXC" is the right conclusion either way; I am only flagging that this part of the description rests on
your measurement, not on mine.
One small note
nlgrepeats the whole ordered expression rather than negating a named local:Correct, and the evaluator in the test covers it. If the emitted text ever gets long enough to matter for
fxc, a temporary wouldread better — not a request, just an observation while the shape is fresh.
Verdict
Reviewed. The NaN semantics are the whole point of the change and they are pinned on both ends of the ORDERED test, in both
directions (accept-and-verify and refuse-by-mutation). No objections.
Notes
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T22:00:52Z.
Resolved the workflow overlap with #1925, keeping both Python and LLVM registrations. The integrated candidate passes the lg/nlg, scalar complement and class comparison controls. Default FXC/DXC draws passed on WARP and RTX 4060 Laptop with the expected old-lowering mismatches. This keeps the remaining predicate work in #1936 independent.