Repository navigation
shader: lower the binary16 SDWA comparisons - #1680
rm-NoobInCoding wants to merge 3 commits into
Conversation
v_cmp_*_f16_sdwa (16 predicates) and v_cmp_class_f16_sdwa were refused. WORD_1 now selects the high half of a source and WORD_0 or DWORD the low half the e32 form reads; -, |x| and -|x| apply after the selection, and the existing binary16 comparison and class16 test run on the result. Registers only; byte selections, sext(), constants, a class mask with another selection or a modifier, and v_cmpx stay refused. draw-sdwa-f16-compare exports the 16 predicates under three selection and modifier mixes and four class tests on ten input sets whose halves both carry binary16 values, with selections-ignored and modifiers-ignored references that must mismatch. The shader scanner accepts the same forms.
tedin7
left a comment
There was a problem hiding this comment.
Review of head a8a670616c9f2b9f4ce679094d391e3fb0c6cbf2.
Linux limits. Linux x86_64, llvm-mc-19 (CI pins 15), Python 3.14. No Windows, no DXC, no GPU, so I could NOT run the new draw-sdwa-f16-compare / pixel_aot_sdwa_f16_compare_<adapter> tests. The NaN, -0/+0 and sign-handling claims are only checked by those draws; I checked the translation text and the machine encodings.
What I ran
- New static check
check_sdwa_f16_compare_lowering()fromtests/pixel_aot_check.py, called directly: passes in 0.1 s. - Binary: assembled the SDWA forms with
llvm-mc-19 -mcpu=gfx1010(WORD_1/WORD_0/DWORD,-v,|v|,-|v|, SGPR destination,v_cmp_class_f16_sdwawith WORD_1 and DWORD) and decoded each back with the in-treedisasm_rdna2.decode_instruction: all round-trip to the same text.sext(v18)is not accepted byllvm-mc-19for these float compares, matching the PR's refusal. - Mutation 1 (src0 high ignored:
highs=(False, sel1 == "WORD_1")): the static check FAILED, as intended. - Mutation 2 (src1 high ignored:
highs=(sel0 == "WORD_1", False)): the static check STILL PASSED. - Mutation 3 (class test ignores WORD_1:
high=False): the static check STILL PASSED. - Everything restored with
git checkout -- ..
Findings
- The only text-level WORD_1 assertion covers src0 of
v_cmp_lt. A wrong src1 selection and a wrong class-test selection are caught only by the GPU draws (SDWA_F16_SETSandSDWA_F16_WRONG_MODELScover src1 and class), which run on Windows. On a Linux or no-GPU run they are unguarded. A one-line text assertion forsrc0_sel:WORD_0 src1_sel:WORD_1and one forv_cmp_class_f16_sdwa ... src0_sel:WORD_1would close that. -,|x|,-|x|are applied after the high-half selection (f16_cmp_operand,(word >> 16u)first, then abs/neg on the 16 bits). That is the SDWA order I expect; confirm with the draws.- NaN handling: the ordered relations require
num16of both, the negated forms are!ordered || !rel, so a NaN in either half is unordered. -0 vs +0 compares equal through the widened float. Both rely on the existingf16_comparison, whose behavior the new draws exercise; I did not re-derive them on a GPU. - Refusals (byte selections,
sext, constants,v_cmpx, class mask with WORD selection, exec as destination, v106) are covered bymust_reject.tools/scan_unsupported_shaders.pyhas two new regexes that match the same shapes.
Verdict: the lowering looks right, and the binary forms are valid. The Linux-runnable guard is weaker than the PR text suggests. Not approving.
AI-assisted; commands listed were executed locally.
The static check asserted WORD_1 only for src0 of v_cmp_lt_f16_sdwa, so a lowering that ignored the src1 selection or the class-test selection was caught only by the GPU draws. Assert the exact operands of a src1-only WORD_1 comparison, and of class tests with WORD_1 and WORD_0 (the modifier applied after the selection, the mask read whole), so each selection is checked without a GPU.
|
Thanks, agreed: the text-level guard only covered src0. Fixed in
Your three mutations, rerun against
With the lowering restored: |
check_binary assembled no v_cmp_*_f16_sdwa program, so the LLVM 15 job never saw the new forms. Add the sdwa_f16_compares program to its fixtures: it is assembled, disassembled with LLVM 15 and must translate exactly like its source text.
tedin7
left a comment
There was a problem hiding this comment.
Review of head 377919df1c8212935299b297f572289892686f97 (3 commits on main: the lowering a8a67061 I reviewed before, plus e182ad78 and 377919df, both tests only; the delta from a8a6706 is +24/-5 in tests/pixel_aot_check.py).
Linux limits. Linux x86_64, llvm-mc-19 and llvm-objcopy-19 (CI pins 15), Python 3.14. No CMake configure and no ctest (the two new pixel_aot_sdwa_f16_compare_<adapter> registrations are unexercised), no Windows, no DXC, no GPU. The draw-sdwa-f16-compare draws, the "12 draws from one compile" and the RTX 4070 and WARP results are not reproduced by me. The NaN, signed-zero and denormal behaviour is only checked by those draws.
Earlier findings, now addressed. My review of a8a6706 showed that ignoring WORD_1 on src1, or in the class test, still passed the text-level check. e182ad78 pins the exact operands for both selections and for the class test with and without the modifier; 377919df adds the SDWA program to the binary fixtures.
What I ran on this head
check_sdwa_f16_compare_lowering()called directly: PASS.- The new fixture round trip, run by itself:
sdwa_f16_compares()(234 instructions, 52 SDWA lines) assembled withllvm-mc-19 -mcpu=gfx1013, objcopy'd, disassembled with the in-treedisassemble()against libLLVM 19, thentranslate_intof the decoded text equalstranslate_intof the source text. The fullbinarymode with llvm-mc-19 stops earlier incheck_f16_cvt_int16_binary(v_cvt_f16_i16_e32 v1, 0xfff0, an unrelated check; likely LLVM 19 against 15 formatting, which I did not confirm), so I did not get a fullbinarypass. - Four local mutations of
tools/pixel_aot.py, each run against the static check and the round trip, then restored (git statusclean): git diff --check origin/main...HEAD: clean; no non-ASCII bytes added.tests/rdna2_tools_check.py(OK, 18 skipped),tests/bidi_controls_check.pyandtests/docs_links_check.py: pass.git merge-treeagainst current main (68969ed8): no conflicts.
Findings
- None blocking. The text-level guard now distinguishes src0, src1 and class selections, and modifiers applied after the selection. The lowering matches the stated semantics (WORD_1 is the high half, WORD_0 and DWORD the low half; class mask read whole).
- Minor. The docs say the LLVM 15 round trip was not run on the author's host; I could not run 15 either, so the CI
llvm-mc-15path for the new fixture is still unconfirmed. Thedrawresults above stay the author's measurements.
AI-assisted review; commands listed were executed locally.
|
This PR currently has merge conflicts with AI-assisted. |
|
I tried to bring this branch up to date with main so it could go through the full cycle. It no longer merges cleanly, and the conflict is not a mechanical one: #1790 (merged 2026-11-24) already lowers the same slice, the 16 binary16 Resolving it would mean choosing between two implementations of the same lowering, so I did not push anything to this branch. Leaving the decision to @R0Y00 and @rm-NoobInCoding. If this PR still adds something that main lacks (for example the Commands executed: AI-assisted; commands listed were executed locally. |
|
Main already covers the 16 binary16 SDWA predicates and the binary16 class form in #1790, with source-field selection, distinct mask destinations, and a binary round trip. The current comparison controls pass. Thanks for the NaN, signed-zero, and half-selection investigations. Any extra discriminating rows can extend the existing fixture directly. Closing this implementation as superseded. |
Change
tools/pixel_aot.pylowered the SDWA comparisons only for binary32, with whole-dword selections. This PR lowers the 16 binary16 predicatesv_cmp_{f,lt,eq,le,gt,lg,ge,o,u,nge,nlg,ngt,nle,neq,nlt,tru}_f16_sdwaandv_cmp_class_f16_sdwa:WORD_1selects the high half of a source.WORD_0andDWORDleave the low half, which is what the e32 form reads. So a comparison with both selectionsDWORDand no modifier emits the same HLSL as its e32 spelling, and a control asserts this.-,|x|and-|x|apply after the selection.num16on the selected, modified encodings and compare the widened values. The class test readsclass16of the selected, modified half against the mask register.f16_cmp_operand,f16_comparisonandf16_classgain an optional high-half selection; existing callers are unchanged.Refused:
sext();neg(2.0)and similar);execas the destination;DWORD, or with a modifier;v_cmpxSDWA forms.tools/scan_unsupported_shaders.pykeeps its own patterns, so it accepts the same forms.test_sdwa_f16_compare_instructionschecks the accepted and refused spellings.Coverage: +17 gfx1013 and gfx1030 SDWA forms.
Verification
Base
c864f138, patcha8a67061. Windows 11 build 26300,devpreset, DXC 10.0.26100.0, NVIDIA GeForce RTX 4070 (driver 32.0.16.1714) and WARP.plus every platform-independent Python check listed in AGENTS.md.
pixel_aot_sdwa_f16_compare_hardwareandpixel_aot_sdwa_f16_compare_warp: 2/2 passed, no skips. Both coverage records list all 17 forms.pixel_aot_check.pystatic controls, including the newcheck_sdwa_f16_compare_lowering: passed.rdna2_tools_check.py: OK, 18 skipped without LLVM.The fixture (
tests/pixel_aot_check.py draw-sdwa-f16-compare):R32G32B32A32_UINTreadback target. Three words hold the 16 predicates as bits under (src0, src1, src0_sel, src1_sel) = (A, B,WORD_1,WORD_0), (-B, |A|,WORD_1,DWORD) and (-|A|, B,DWORD,WORD_1). The fourth word holds four class tests of C against the mask D.pixel_mismatch. That is 12 draws from one compile.WORD_1makespixel_aot_sdwa_f16_compare_warpfail.LLVM 15 round trip: not run locally (no LLVM with gfx1013 on this host). The first commit did not put the new forms through it:
check_binaryassembled nov_cmp_*_f16_sdwaprogram. A later commit adds thesdwa_f16_comparesprogram to its fixtures, so theAssemble and translate gfx1013 fixturesjob assembles it, disassembles it with LLVM 15, and requires the disassembly to translate exactly like the source text. After review,check_sdwa_f16_compare_loweringalso pins each selection (src0, src1 and the class test) at text level, so a lowering that ignores any one of them fails without a GPU.Evidence and follow-up
All inputs are synthetic. The draws show that the translated shader computes the stated comparisons on desktop GPUs, not that the console does. Related: #1670 lowers the integer SDWA comparisons. The two PRs touch neighbouring code but are independent. The
v_cmpx_*_sdwaforms remain uncovered.Checklist
AI-assisted.