Repository navigation
startup: lower gfx2hlsl f32 SDWA compares with DWORD selections - #2212
Conversation
compare() refused every v_cmp_*_f32_sdwa and v_cmpx_*_f32_sdwa until the f32 predicates were exact on NaN (R0Y00#1930, R0Y00#1949). DWORD selections now read the register as binary32 with neg/abs as in the e64 form, so a src0_sel:DWORD src1_sel:DWORD compare emits the e64 text, NaN bit test included. Byte and word selections are refused: the selected field is always +0 or a denormal, so the result depends on the binary32 denormal mode, which gfx2hlsl does not read. pixel_aot refuses the same forms. sext() is integer-only and refused; LLVM 15 does not decode the bit on a float source. clamp, omod, dst_sel and dst_unused stay refused, and class compares are unchanged. LLVM's SIPeepholeSDWA models the sub-dword case as zero-extension read as binary32 bits; the RDNA 2 ISA guide gives only the SDWAB fields. tests/startup_gfx2hlsl_f32_sdwa_check.py: - builds every f32 SDWA form and checks the 720 DWORD/DWORD forms against the e64 text and the ISA reference: 256 NaN/denormal pairs under the IEEE, FXC and DXC models; - refuses all 34,560 byte/word forms with the denormal-mode message; - uses the text before R0Y00#1930/R0Y00#1949 as its negative control; - draws 30 DWORD fixtures with default-flag FXC ps_5_1 and DXC ps_6_0. The vopc_sdwa and f32_lg checks no longer assert the blanket refusal. They now check that DWORD selections lower as the e64 form and that byte/word selections are refused with the new message. Refs R0Y00#1906 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tedin7
left a comment
There was a problem hiding this comment.
Review of head eda692a6a23a561915e1a179d94cb6e162664914.
Result: no P1, no P2. Looks correct to me.
What I checked
tools/startup/gfx2hlsl.py: DWORD f32 SDWA compares reuse the e64 text and modifiers. BYTE/WORD selections andsext()on a float source are refused with distinct reasons. The earlier blanket refusal is removed. This matches the reasoning in the new comment: a sub-dword field zero-extended as binary32 bits is always +0 or a denormal, so the result depends on the denormal mode..github/workflows/windows.yml: the new check is added in both places that list its siblingf32_nancheck.binaryanddecodeentries are in the Python-check matrix, and the file is in the later script list. Both mirror the existing entries and I found no missing third spot.CMakeLists.txt: a pure-Python CTest pluswarpandhardwaredraw tests, in the same shape asstartup_gfx2hlsl_f32_nan_*. The draw tests useoffscreen_checkreadback compared pixel by pixel with the CPU reference, not string-only HLSL checks.tests/startup_gfx2hlsl_f32_lg_check.pyandtests/startup_gfx2hlsl_vopc_sdwa_check.py: the edits only move the old "f32 SDWA is refused" expectations. Title and body are neutral, with no clean-room concerns.
Commands executed locally (Linux)
python3 -B tests/startup_gfx2hlsl_f32_sdwa_check.py(pure part): PASSpython3 -B tests/startup_gfx2hlsl_f32_sdwa_check.py binary llvm-mc-19: PASS.llvm-mc-15andlibLLVM-15are not installed here, so thedecodemode was not run locally.tests/startup_gfx2hlsl_f32_lg_check.pyandtests/startup_gfx2hlsl_vopc_sdwa_check.py(binary llvm-mc-19): PASSpython3 tests/docs_links_check.py: 18 files, 407 links, OKpython3 tests/bidi_controls_check.py: OKgit diff --check origin/main...HEAD: clean
Mutations (both caught)
- Disabling the BYTE/WORD refusal in
compare_sdwa_sources: the pure check exits 1. - Disabling the
sext()refusal: the pure check exits 1.
Windows (real D3D12)
x2w_pipe.py win2025 2212 --regex "startup_gfx2hlsl_(f32_sdwa|f32_nan|vopc_sdwa|f32_lg)"
- dev: 12/12 passed. This includes
startup_gfx2hlsl_f32_sdwa_warpand_hardware. - release
/O2: 12/12 passed.
CI at review time
Python checks on Linux: pass. The Windows build and the gfx1013 job were still pending.
Nits
- None blocking. Optionally, say in the PR body that
decodemode needs LLVM 15, because Linux runners with a newer LLVM cannot run it.
AI-assisted; commands listed were executed locally.
|
Ran this head (
Each run printed the same 211 ok lines and 76 AI-assisted. |
Refs #1906
What
Since #1915,
compare()intools/startup/gfx2hlsl.pyhas refused everyv_cmp_*_f32_sdwaandv_cmpx_*_f32_sdwawith<name>: f32 SDWA compares are not lowered. Now that #1930 and #1949 are onmain, every f32 predicate in the table is exact on NaN under default-flag FXC and DXC. This PR lowers the DWORD SDWA forms through that table and refuses the byte and word forms with a reason.src0_sel:DWORD src1_sel:DWORD, any neg/absBYTE_norWORD_nselect on either source<name>: f32 SDWA byte/word selection depends on the binary32 denormal modesext()on a float source<name>: sext() on a float sourceclamp,mul:2,div:2,dst_sel,dst_unused; a missing or repeated selectv_cmp_tru_f32_sdwa; class comparesWhy
The startup cache compiles
gfx2hlsloutput with FXC and no flags, and since #1930 and #1949 the f32 predicates are exact on NaN under those defaults. The SDWA forms were refused only because no one had checked them against that text. The owner's last comment on #1906 keeps the ordinary f32 predicates on this issue.SDWA float semantics
gfx2hlsldoes not read that mode;tools/pixel_aot.pyrefuses the same forms.sext()is integer-only and refused.Sources:
SIPeepholeSDWAmodels the sub-dword case as zero-extension read as binary32 bits. It foldsv_and_b32 0xffffandv_lshrrev_b32 16into thesrc_selof a float compare and keeps the compare's neg/abs (test/CodeGen/AMDGPU/sdwa-peephole-instr.mir,vopc_instructions).AMDGPUModifierSyntax.rst: calls SDWAsext"Valid for integer operands only". LLVM 15's disassembler rejects the sext bit on a float source, which thedecodemode checks.Tests
New file
tests/startup_gfx2hlsl_f32_sdwa_check.py, registered asstartup_gfx2hlsl_f32_sdwaandstartup_gfx2hlsl_f32_sdwa_{warp,hardware}(SKIP_RETURN_CODE 77). The pure-Python check is added to the CI Python job, andbinary llvm-mc-15/decode libLLVM-15.so.1are added to the LLVM 15 job. Thedecodemode needs LLVM 15 (libLLVM-15): its sext-bit refusal check depends on LLVM 15's disassembler, so a runner with a newer LLVM can runbinarybut notdecode.Controls (pure Python, ~1 s). Every f32 SDWA form is built from the VOP_SDWA9Be fields and decoded: 15 table conditions × (v_cmp into
vcc_lo, v_cmp into an SGPR, v_cmpx into EXEC) × 7 × 7 selects × 4 × 4 neg/abs = 35,280 forms.-s3) and an inline constant (neg(1.0)) with DWORD selects; the same with WORD_1 or BYTE_1 is refused.sext(),clamp, omod anddst_*refusals, and the decoder refusing the sext bit.Draws (
draw). Each pixel builds one source word from x and one from y, so the 16 × 16 pixels cover every pair.cmp_<cond>(15 fixtures) writes four DWORD/DWORD results,(a, b),(-a, |b|),(-|a|, -b)and(|a|, b), intovcc_lo,s6ands8.cmpx_<cond>(15 fixtures) keeps a pixel throughv_cmpx_<cond>_f32_sdwa -v3, |v4| src0_sel:DWORD src1_sel:DWORD.ps_5_1and DXCps_6_0.Updated, not deleted:
startup_gfx2hlsl_vopc_sdwa:sext()on a float source and ofclamp/mul:2on a float compare.startup_gfx2hlsl_f32_lg: the 16 lg/nlg SDWA refusals now check the e64 text.Results
Tested at commit
eda692a6onmainab9a020c(after #2204). Environment: Windows 11 build 26300, Windows SDK 10.0.26100.0 FXC and DXC 1.8.2502.11, D3D12 debug layer on (debug_errors=0 debug_warnings=0).ps_5_1(default)ps_6_0(default)1002:7550), 32.0.31044.16The six
f,oandufixtures do not depend on denormals. The other 24 matched the flushed image on both adapters and with both compilers. Each draw run makes 210 checks, all ok. WARP and the RX 9070 XT agree in every cell, including the recorded ones.Negative controls
Text before #1930/#1949, on the same operands: lg/nlg as
!=, the n-forms as!(a OP b), o/u as reflexive compares.Pure Python: it fails all 128 guarded DWORD condition × modifier pairs under the model of the compiler that broke it, and matches that model. lg/nlg already fail under IEEE.
Draws, asserted: it fails every guarded fixture against both images on the compiler that broke it (lg/nlg on both compilers; 40 checks per adapter). For example, FXC
cmp_nlton the RX 9070 XT givespixel mismatch (10,0): expected 3f800000,3f800000,3f800000,3f800000 actual 00000000,00000000,00000000,00000000 / 156 of 256 pixels differ. It also matches that compiler's model image for lg/nlg and the four n-forms (16 checks per adapter).Draws, recorded only (o/u under DXC): the faithful pre-startup: keep gfx2hlsl f32 n-forms, o and u exact under FXC and DXC #1949 text keeps each source's modifiers, and DXC folds
x == xonly for some operand shapes:cmp_o/cmp_u: folded for(a, b)and(-a, |b|)but not for(-|a|, -b)or(|a|, b).cmpx_o/cmpx_u: the|b|side folded but not the-aside.The text still fails against the ISA images (asserted), but it does not match the full-fold model, so that comparison is recorded only. The nan check draws the old o/u text on the plain words, where DXC folds both sides.
Unmodified
maintranslator: the new check fails with 10 MISMATCH lines (f32 SDWA compares are not lowered) and FAIL.Recorded, not asserted:
/Gisand-Gis: every fixture matched every pixel.Environment
llvm-mcand LLVM-C.dll.out/pe-env.1002:7550), driver 32.0.31044.16; D3D12 debug layer on.Skips
None. No test in the
^startup_gfx2hlsl_run returned 77.Not covered
gfx2hlsldoes not read. No local cache contains such a form today.v_cmp_class_*_sdwais unchanged (startup: lower binary32 class SDWA compares #1969, startup: add the SDWA forms of v_cmp_class_f16 in gfx2hlsl #2020).v_cmp_tru_f32and the f16/f64 compares in SDWA form stay refused.AI-assisted.
🤖 Generated with Claude Code