shader: lower binary64 comparisons and class tests in direct compute #3624
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3624"
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 Ammmae0x on 2026-11-30T16:20:50Z.
Lower
v_cmp_*_f64,v_cmpx_*_f64(all 16 predicates) andv_cmp_class_f64/v_cmpx_class_f64in the direct C++ compute path (src/gfx1013_direct_compute.inl), following PR #3529 (v_ldexp_f64), PR #3530 (v_min_f64/v_max_f64) andtools/pixel_aot.py(cmp_f64).Refs #2935, #3518
What changed
double, noi64, nofcmp, and neitherDoublePrecisionFloatShaderOpsnorInt64ShaderOps.(0, 0x80000000)), so the 16 predicates reduce to unsigned 32-bit comparisons.-0.0 == +0.0; NaNs are unordered except foruand the negated predicates;f/trureturn constant false/true.0x001, qNaN0x002, -Inf0x004, -normal0x008, -subnormal0x010, -00x020, +00x040, +subnormal0x080, +normal0x100, +Inf0x200);-0stays distinct from+0, andabs/negonsrc[0]flips the sign bit before the check.half_binaryMODE tracking, so a flushing or conditional MODE is refused.0(+0.0) and inline binary64 constants240..247. Refused:248(1/(2*pi)), integer inline constants129..208and239, odd SGPR pairs, VCC/EXEC pairs,v255, 32-bit literals,clamp,omod,op_sel,subword,neg/abson the class mask source, and the pixel stage / graphics input.write_ballot, sov_cmp_*writes VCC (or an SGPR) andv_cmpx_*writes EXEC, in wave32 and wave64.Fixture
tests/native_cmp_f64_check.py model|ir|controls|hardware, registered intests/cmake/native_cmp_f64.cmakeandtests/checks/python-linux/native_cmp_f64.txt.docs/experiments/native-direct-cmp-f64.mdhas the full note.model(Linux): 10,842 predicate/class rows cross-checked against Python float semantics over boundary values, abs/neg modifiers checked, word builders round-tripped through decoders, ten self-mutations killed.ir: 82 cases through all 16 e32 predicates, 22 cases through all 16 e64 predicates, both class forms, three cmpx forms, SGPR pairs, inline constants and modifiers (1,812 ballot stores at contiguous addresses), plus the same program as a wave64 container (the exchange is present). Nodouble, noi64, nofcmpin the@main()body (the module metadata carries the DXIL shader-flags bitmask asi64 524304, so thei64/fcmpchecks are scoped to the body). The class path pins the exacticmp uge i32 <ssa>, 2146435072line, so mutating thatugeback toeqfails even before hardware. The IR interpreter cannot value-check a ballot, so values are verified bymodelandhardware.controls: all 34 forms compile; 17 refusals checked with an exact error substring and a non-zero exit code. The compiled module contains nodouble, noi64, nofcmp, and contains the ballot and integer key-comparison idioms.hardware: 15 dispatches (four e32 predicate groups, four e64 groups with VGPR/SGPR/inline/modifier sources, class, three cmpx groups, one lane-varyinglt, one wave64 dispatch, one e64 dispatch covering all eight inline constants240..247) compared word for word against the reference. The wave64 dispatch saves EXEC tos[14:15]and restores it to all ones before storing thev_cmpxmasks, with two cmpx cases (lt, all-zeros mask;eq, all-ones mask).Mutation audit
Every guard, condition and constant added in
src/gfx1013_direct_compute.inlis pinned by a named test (100% kill by design; verified on Windows MSVC + RTX 4050 in WIN-VERIFY below):v_cmp_/v_cmpx_+_f64): dropping either alternative routes that form tocomparison()("direct comparison width") — killed by the controls positive program (all 34 forms).clamp,omod,op_sel,subword(SDWA),abson src2,neg/abson the class mask source. (pixel_stage/graphics_input/dpp_control/permutedare not constructible throughcompile_dxilcompute; theEncoding::Vopccheck is provably redundant — the decoder only producesVopcfor these opcodes.)!half_mode_known,mode_bits ^ 0xf0u, mask0x8000ccu): dropping either check lets the flushing or conditional MODE program compile — killed by the two MODE refusals; changing0xf0urefuses the default MODE in the positive program.pair(): VGPR bound< 511pinned by thev255refusal; SGPR bound<= 104and evenness pinned by the odd-SGPR and VCC-pair refusals;128pinned by the ir inline cases;240..247bounds pinned by the248and239refusals; each inline table entry pinned by the hardware e64 inline cases.apply_mods: theand 0x7FFFFFFF/xor 0x80000000constants and the per-source bit test are pinned by the hardware e64 modifier cases and by the model abs/neg cross-check.0x7FFFFFFF, quiet bit0x80000, Inf bound0x7FF00000, subnormal bound0x00100000and all ten class bit values are pinned by the hardware class dispatch (32 combos, one single-bit mask per value) and by the model mutations (quiet-inverted, zero-swapped, Inf-bound, subnormal-bound). The Inf arm uses a separatea_lo == 0check, notempty— usingemptywould classify Inf as NaN.+0/-0cases; the key sign bit by the model mutation and the hardware sign cases; high-first comparison by the model mutation (low-first) and the hardware high-equal/low-differ cases; high+low equality by the model mutation (high-only) and the same hardware cases; each of the 16 predicate expressions by the hardware e32+e64 dispatches and the exhaustive model cross-check against float semantics.half_binary): dropping the addition lets the conditional-MODE program compile — killed by the two conditional-MODE refusals (onecmp, onecmpx).write_ballot/return: dropping either leaves the result unwritten or double-lowers the form — killed by the hardware dispatches / the controls positive program.Model mutations killed on Linux (10): no-zero-canonicalisation, inverted sign handling, NaN-includes-Inf, low-word-first comparison, inverted quiet-bit test, swapped zero class bits, missing key sign bit, high-word-only equality, wrong Inf bound, wrong subnormal bound.
Fix (first WIN-VERIFY round)
The first Windows run (RTX 4050, SHA
29f7131e) caught one real C++ bug and three fixture bugs, all fixed in2df3a4e7(plus a merge oforigin/maincf43986d, clean, no conflicts):class64testedmagnitude == 0x7FF00000, so a quiet NaN whose high-word payload bits make the magnitude larger (e.g.0x7FF8000000001234) fell through tonormalinstead ofqNaN/sNaN(hardware dispatches 8 and 11). Fixed withis_inf_or_nan = magnitude >= 0x7FF00000and a separateis_inf(magnitude == 0x7FF00000 && lo == 0). The class dispatch now also covers a sNaN with high-word payload bits (0x7FF4000000000000) and a qNaN with a zero low word (0x7FF8000000000000), replacing the two redundant normal cases (SMALLEST_NORMAL,NEG_DBL_MAX) in the 32-combo row, andir()/controls()pin theicmp uge i32line so the mutation fails before hardware.ir()asserted'i64 'over the whole module, but the DXIL metadata carries the shader-flags bitmask asi64 524304. Thei64/fcmpchecks are now scoped to the@main()body (ascontrols()already did);'double'is still checked over the whole module.s_denorm_modein theflushing MODErefusal refuses at the mode write itself with the binary16 message, so the expected substring is nowrounding or denormal mode(as innative_ldexp_f64_check.py/native_minmax_f64_check.py); the conditional MODE refusals still expect the binary64 message.request64()bound 7 user SGPRs, shiftinggroup.xtos7while the wave64 prologue reads it froms5(unbound numeric SGPR s5on the wave64 dispatch). It now binds 5, likerequest().241,243,245,247) in the ir program and in the new e64 hardware dispatch over all eight inline constants.Fix (second WIN-VERIFY round)
The second Windows run (MSVC + RTX 4050, SHA
2df3a4e7) passednative_cmp_f64_controls(all 34 forms compile, all 17 refusals with exact messages) and hardware dispatches 0..12 (includinghw_classandcmpx_class), and caught two remaining fixture bugs, both fixed in930bdf16(plus a merge oforigin/main7f13a4cd, clean, no conflicts):F.storemasks offsets to 12 bits, so the 1,812-store ir program wrapped offsets>= 4096back onto 0 andF.interpretreturned duplicate addresses.ir_programis factored into Parts 1/2/3 andir()now dumps the wave32 program in three chunks of<= 1,024stores each (the e32 sweep in two chunks of 64 and 18 cases, Parts 2+3 in their own dump), each asserting contiguous addresses from 0; the wave64 program (852 stores, no sweep) still fits in one dump. The value-path needles are checked on every chunk; the class needles and theicmp ugepin only on the e64 chunk, the only one with class forms.hw_wave64stored EXEC (s126/s127) right afterv_cmpx_lt_f64, which sets EXEC = 0 (+0.0 < -0.0is false), so the stores were predicated off and slots 8 & 9 stayedSENTINEL. EXEC is now saved tos[14:15]and restored to all ones before storing the mask, ashw_cmpx()does, and a secondv_cmpx_eq_f64case (all-ones mask) is added, keeping the dispatch at exactly 16 slots.Fix (third WIN-VERIFY round)
The third Windows run (MSVC + RTX 4050, SHA
930bdf16) passednative_cmp_f64_controls, all 15hardware dispatches (including
hw_wave64) and all three wave32 ir chunks; only the wave64container dump remained, failing at
+0x8withnative compute +0x8: direct descriptor address outside bound table. Fixed incd7efc5e:container_computebinds the descriptor table ats0(words(3, 0, 1, 0, 0)), butF.preamble()reads the table froms4andgroup.xfroms5. The wave64 dump now builds itscontainer with a new
wave64_container()matchingF.compute_container'ss4/0x8alayout:words(3, 0, 1, 0, 4),0atrecord + 20(wave32 flag clear) and(0x8a, 64, 1, 1)atrecord + 120. The layout is pinned on Linux by decoding the DXBC (_dxbc_body) and assertingthe table entry, the flag and the group; the old
s0layout fails the pin.sop1(4, 126, 193)incode64:sop1(3, 126, 193)iss_mov_b32and only setsEXEC_LO, leaving lanes 32..63 inactive.ir_programtakes anexec_initparameter (defaulting to the wave32 form); only the wave64 program overrides it.The wave64 program differs from the old one in exactly that one word (right after the
12-word preamble).
Measurement
Measured on 30.11.2026,
main7f13a4cdplus this change, on Linux:tests/native_cmp_f64_check.py modelpasses (10,842 rows, ten mutations killed); fullrun_checks_parallel.py --from-dir tests/checks/python-linux71/71;form_coverage_check.py,docs_links_check.py(189 files / 740 links),bidi_controls_check.py(2,738 files) pass;diff --checkclean;git merge-tree --write-tree origin/main HEADexits 0. Their,controlsandhardwaremodes need a Windows build and are not measured here. The third Windows run passed controls, all 15 hardware dispatches and the three wave32 ir chunks on930bdf16; re-verified on Windows below.Windows Verification (
cd7efc5e)cd7efc5e85d547c0b51e03ac162971e54cd9f2e5(git merge-tree --write-tree upstream/main HEADexit0,git diff --checkexit0).NVIDIA GeForce RTX 4050 Laptop GPU(vendor=10de device=28e1, driver32.0.15.9186).XBOX2WINDOWS_ADAPTER=NVIDIA):dev: 3/3 passed in7.51 s(native_cmp_f64_ir1.62 s,native_cmp_f64_controls1.07 s,native_cmp_f64_hardware4.68 s— 15/15 dispatches matched 2064 words each).release: 3/3 passed in6.43 s(native_cmp_f64_ir0.74 s,native_cmp_f64_controls1.02 s,native_cmp_f64_hardware4.56 s).native_cmp_f64_check.py model(10842rows, 10 mutations killed),form_coverage_check.py,docs_links_check.py(189 files, 740 links),bidi_controls_check.py(2738 files) all passed.Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T20:26:33Z.
Review: APPROVED
Reviewed
cd7efc5eby reading the diff; not built or run.Verdict: approve. All 16 predicates and the class mask match the binary64 rules, and the guards are conservative. No MUST, no SHOULD.
src/gfx1013_direct_compute.inl:4149-4180): the ordered ones areordered && rel, andnge/ngt/nle/nlg/nlt/neqare!(ordered && rel), so they are true on NaN. Truth table checked row by row.(0, 0x80000000)makes-0 == +0, and-min_subnormalstill keys below zero.magnitude > 0x7FF00000 || (== && lo != 0), the same asv_min_f64.:4092-4108): the>= 0x7FF00000fix with a separateis_inf(== && lo == 0) is right. Quiet is hi bit 19 (bit 51 of the value), normal ismagnitude >= 0x00100000, and the ten bit values match the class32 order.abs/negare allowed on the value source and refused on the mask source.write_ballot(i.dst, ...)is used the same way as the existing_i64compare path, so VCC/SGPR destinations,v_cmpx→ EXEC and the wave64 pair checks are shared._f64VOPC only, with literal255, odd SGPRs, VCC/EXEC pairs andv255refused. The MODE gate also refuses a non-default rounding mode, which a comparison never reads.Tests:
modelchecks 10,842 rows against Python float semantics, with ten self-mutations.iris structural: the interpreter cannot value-check a ballot, so it pins the integer-only IR, theicmp ugeclass line and the store layout.controlscompiles all 34 forms and pins 17 refusals.hardwareruns 15 dispatches word for word, including a lane-varyinglt, wave64 and all eight inline constants, so it is the only value check of the C++ lowering. CI ran onlymodel. Thenative_cmp_f64_*CTest entries are not in the Windowsprpreset filter, soir/controls/hardwarehave only the author's RTX 4050 run at this head.