Repository navigation
startup: add the SDWA forms of v_cmp_class_f16 in gfx2hlsl - #2020
Conversation
Ran it, broke it five ways — all caught — and checked
|
mutation in the class16 helper |
result |
|---|---|
the NaN branch's two classes swapped (0x2/0x1) |
caught |
the infinity branch's sign swapped (0x4/0x200) |
caught |
the normal threshold 0x0400 → 0x0401 |
caught |
the zero branch's sign swapped (0x20/0x40) |
caught |
the & 0xffffu low-half mask dropped |
caught |
The last one is the one I would have expected to survive: nothing in the fixture needs the upper half to be non-zero for a classification to
differ, so it only fails if the fixture feeds a word whose upper half would change the exponent/mantissa test. Yours does.
The classifier, checked against the format rather than the text
I transcribed the helper and compared it with an independent reading of the ten AMD classes for binary16 (sign, exponent, mantissa fields, no
reuse of your code) over every 16-bit word:
values checked: 65536 mismatches: 0
populations: 0x001 sNaN 1022 0x002 qNaN 1024 0x004 -inf 1 0x008 -normal 30720
0x010 -denormal 1023 0x020 -0 1 0x040 +0 1 0x080 +denormal 1023
0x100 +normal 30720 0x200 +inf 1
single-bit masks agree with populations: True
Those populations are the check I trust most: 30,720 normals per sign and 1,023 denormals per sign are exactly (0x1F-1)·2^10 and 2^10-1, and
1,022 + 1,024 = 2,046 is the NaN space split at mantissa bit 9. A wrong threshold or a swapped branch would break one of those counts, and none did.
Consistency with class32
class32 in the same preamble uses the same ten bits (0x1 sNaN … 0x200 +inf), with (bits & 0x00400000u) for qNaN and 0x00800000u for the
normal threshold. So the two helpers are interchangeable at the mask level, which is what a caller passing an ISA class constant expects — worth
saying in the description, because a divergence there would be silent and would only show up as a wrong predicate for one class.
What the refusals are protecting
The comment lists four spellings that change which bits are classified — abs/neg (sign is bit 15 here, not 31), a float inline constant or literal
(read as binary16 for this opcode), op_sel, and a SDWA byte/WORD_1 selection. Refusing rather than translating them is right: each of those
would make the classifier look at a different half or a different word, and the emitted predicate would be plausible and wrong. src0_sel:WORD_0
being the one accepted non-DWORD selection is consistent with that.
Scope
Text, arithmetic and refusals; no shader was compiled or run, and the ISA quotation (VOPC opcode 143, S1.u[0..9]) is taken from your description
rather than checked against the PDF.
Verdict
Reviewed. Five mutations caught, and the classifier is exact over the whole 16-bit input space.
Notes
- AI-assisted review.
|
Please coordinate with the author of #1856. The register-only path can be independent and should leave #1855 open. The census case uses a plain encoded literal as S0, which this path deliberately rejects. Reuse the existing 0x7c01 fixture and evidence from #1856. Keep encoded NEG and inline float constants refused until the half sign interpretation is verified. A register and an immediate with the same low bits should give the same class in source-built readback, with an independent high-half control. |
|
@triggered02, #1856 got to
If you'd rather merge both into #1856, I'm fine closing #2020 and moving the register tests there instead. AI-assisted (Claude Code). |
|
#2092 has now landed the plain e32/e64 register and encoded-literal path, including the 0x7c01 census form. Please take the current main helper as the base for your proposed split and keep the independently useful SDWA operand selection and negative controls in this PR. |
The plain e32/e64 register and encoded-literal path, including the 0x7c01 census form, landed with R0Y00#2092 and is used unchanged. It still refused the SDWA spelling outright. This lowers v_cmp_class_f16_sdwa and v_cmpx_class_f16_sdwa through the same class16() helper and the same predicate/exec/destination code. src0_sel DWORD and WORD_0 are accepted on a plain register (class16 reads bits [15:0] itself); src1_sel selects and sign-extends the integer mask as the binary32 class compare does. WORD_1, bytes, sext() on src0, the abs/neg spellings, a missing or repeated select, a float source or mask and a bad destination are refused, WORD_1 and bytes with the existing "SDWA form of" reason. New check startup_gfx2hlsl_cmp_class_f16_sdwa_check.py: accepted forms times destination/select/register file against a struct 'e' reference with garbage in the upper half, refusals, and three mutated helpers (upper half read, sNaN/qNaN swapped, +0/-0 swapped) that must disagree. The draw mode (warp and hardware) draws a register with a qNaN upper half, a clean register, the encoded literal 0x7c01, the e32 spelling and both SDWA selects against one reference image; classifying the upper half, swapping sNaN/qNaN and ignoring the BYTE_1 mask select must each fail it. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tedin7
left a comment
There was a problem hiding this comment.
Review of head 3eb7454f87020e57927b634084268b097f1a9a8a
Result: no P1, no P2.
Checked:
class16against the ISA class bits (sNaN 0x1, qNaN 0x2, -inf 0x4, -normal 0x8, -denorm 0x10, -0 0x20, +0 0x40, +denorm 0x80, +normal 0x100, +inf 0x200). Thresholds 0x7c00 / 0x0400 and the sNaN/qNaN split at mantissa bit 9 are correct.compare_class_f16has the same destination handling as the f32 branch: VCC, SGPR (withmasks.add), EXEC for cmpx,exec & ...intersection whileexec_knownis false.- Refusals are conservative: abs/neg, op_sel/clamp, float constants and literals as S0, float masks, SDWA WORD_1, byte, sext and missing
src0_sel, DPP. - Registered in CMake, the Windows workflow and AGENTS.md. Title is neutral and the diff is clean-room.
- CI on this head: Linux checks, gfx1013 fixtures and Windows build all pass.
Commands run locally in a worktree on this head:
python3 -B tests/startup_gfx2hlsl_cmp_class_f16_check.py: PASSpython3 -B tests/startup_gfx2hlsl_cmp_class_check.py(f32 sibling): PASSpython3 tests/docs_links_check.py: PASS (18 files, 388 links)python3 tests/bidi_controls_check.py: PASSgit diff --check origin/main...HEAD: clean
Mutations (each reverted with git checkout -- .; the f16 check fails, rc=1, for every one):
- sNaN/qNaN bit changed from 0x0200 to 0x0100
- normal threshold
>=changed to>at 0x0400 - removal of the
exec &intersection (the sed also touched the f32 line with the same text, so this one is not f16-only)
Nits (not blocking):
- The SDWA path takes
valuefrom the original operand and drops the word returned bycompare_sdwa_sources. That is fine for DWORD and WORD_0, the only selections allowed. If WORD_1 is ever accepted, this line must use the returned word. - The check runs
class16through a Python model of the emitted HLSL. The GPU-side helper is not read back here. This is a bit-only helper, so the risk is low. I did not run a Windows WARP readback for this review. CI Windows build and test passed.
AI-assisted; commands listed were executed locally.
3eb7454 to
e66f5f7
Compare
|
Rebuilt on
One note on your earlier request to keep encoded NEG refused: the plain path from #2092 accepts NEG/ABS as bit-15 operations ( AI-assisted (Claude Code). |
tedin7
left a comment
There was a problem hiding this comment.
Review of head e66f5f74e547427f14d711610fd8938c79feabac.
Scope: one commit on top of main. It lowers the SDWA forms of v_cmp_class_f16 / v_cmpx_class_f16 (accepts src0_sel:DWORD and WORD_0) and adds tests/startup_gfx2hlsl_cmp_class_f16_sdwa_check.py. It also touches CMake, AGENTS.md and windows.yml. The base helper is already on main.
Commands run locally on the checkout:
python3 -B tests/startup_gfx2hlsl_cmp_class_f16_sdwa_check.py: PASSpython3 -B tests/startup_gfx2hlsl_cmp_class_f16_check.py: okpython3 -B tests/startup_gfx2hlsl_vopc_sdwa_check.py: PASSpython3 -B tests/startup_translator_check.py: 0 failedpython3 tests/docs_links_check.py: 398 links okpython3 tests/bidi_controls_check.py: okgit diff --check origin/main...HEAD: clean- CI (
gh pr checks): Linux checks, gfx1013 fixtures and Windows build all pass. The /O2 job and the chart job are skipped. - Mergeable: yes.
Mutation: I added src0_sel:WORD_1 to the accepted selections in tools/startup/gfx2hlsl.py. The new check fails (refused: src0_sel:WORD_1, both the cmp and cmpx variants), so the refusal is guarded. I reverted with git checkout -- ..
Correctness: accepting only DWORD and WORD_0 is right, because class16 reads bits [15:0] and both selections leave them in place. Refusing WORD_1, byte selects, sext and abs/neg is the safe choice. Using the integer path for S0 and rejecting float masks matches the f32 SDWA handling. I found no semantic bug.
P1: none.
P2:
.github/workflows/windows.yml:222: two script names are on one line,...vopc_sdwa_check.py tests/startup_gfx2hlsl_cmp_class_f16_sdwa_check.py \. It runs, but it is probably a mangled edit. Put the new test on its own line with its own\.- The PR title and body still describe the whole base helper ("lower v_cmp_class_f16 and v_cmpx_class_f16"). The diff only adds the SDWA forms. The "Against main ... fails with Unsupported" and "41/41 before the rebase" claims no longer match this diff. Please retitle and rewrite the body to cover only the SDWA slice, with a
Verification:block. The body also carries tool attribution lines that the repo conventions say to keep off GitHub, so please remove them.
Nit:
- Like the base PR, the emitted HLSL for the SDWA path is checked only through the CMake
drawregistration. I did not run the WARP or FXC draw tests here (Linux only). The Windows CI job passed, but please paste the Win2025 draw result forstartup_gfx2hlsl_cmp_class_f16_sdwa_*in the body before this goes Ready.
AI-assisted; commands listed were executed locally.
|
@JB2WIN could you rebase this branch onto current GitHub reports head Files that conflict with current
Commands run locally: Once it is rebased and CI is green it will be re-checked right away. AI-assisted; commands listed were executed locally. |
|
Win2025 WARP receipt for head d1d5078 (merge of main into the branch, conflicts only in workflow list, AGENTS.md and CMakeLists.txt, kept both sides). Dev and release: 373/373 passed, including startup_gfx2hlsl_cmp_class_f16_sdwa and its WARP draw test. Run with --patch because the branch was updated before this push. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
AI-assisted; commands listed were executed locally. |
|
Win2025 WARP receipt for head 8fc1e53 after updating with main (conflicts only in workflow list, AGENTS.md, CMakeLists.txt; both sides kept). The PR's own content is unchanged from the run on d1d5078, which passed 373/373 dev and release including startup_gfx2hlsl_cmp_class_f16_sdwa and its WARP draw test. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
AI-assisted; commands listed were executed locally. |
tedin7
left a comment
There was a problem hiding this comment.
Review of head 8fc1e53 (author's change plus a merge of main).
Checked:
tools/startup/gfx2hlsl.py: the SDWA binary16 class compare now acceptssrc0_sel:DWORDandWORD_0on a plain register and refuses WORD_1, byte selects,sext(), abs/neg spellings, non-register sources and float masks. This matches whereclass16reads its bits.- The new
tests/startup_gfx2hlsl_cmp_class_f16_sdwa_check.pyhas the static refusals plus a D3D12 draw compared against a CPU reference, with negative controls (upper-half classify, sNaN/qNaN swap, ignored BYTE_1 select) that each change the image. - Registered in CMakeLists.txt (static and per-adapter draw), AGENTS.md and the workflow list; the merge kept both sides of each conflict and the sibling
startup_gfx2hlsl_cmp_class_f16_check.pystill passes.
Commands run:
python3 -B tests/startup_gfx2hlsl_cmp_class_f16_sdwa_check.py-> PASSpython3 -B tests/startup_gfx2hlsl_cmp_class_f16_check.py-> PASS- Win2025 WARP dev and release: 373/373 on the previous head, same content (receipts above).
No blocking findings. The merge decision stays with the usual process.
AI-assisted; commands listed were executed locally.
Refs #1723
Change
#2092 landed the plain e32/e64 register and encoded-literal path of
v_cmp_class_f16/v_cmpx_class_f16. This PR adds only the SDWA forms on top. They reuse #2092'sclass16helper and its predicate,execand destination code, so there is no second helper.src0_sel:DWORDandWORD_0on a plain register. Both classify the low half, because the instruction reads S0.f16.src1_selselects the mask word, and the mask is sign-extended.WORD_1and byte selects on src0, which keep startup: lower v_cmp_class_f16 and v_cmpx_class_f16 (issue #1855) #2092's "SDWA form of …" message, so its test is unchanged;sext()on src0;src0_sel,clamp, and anulldestination.Verification
New check
tests/startup_gfx2hlsl_cmp_class_f16_sdwa_check.py, registered asstartup_gfx2hlsl_cmp_class_f16_sdwa(pure),_warpand_hardware, and listed inAGENTS.mdandwindows.yml.-cc1asbytes for gfx1013.struct('e')reference, with garbage in the high half.0x7c01, the e32 spelling, and both SDWA selects (WORD_0 and DWORD).Run on
e66f5f74, on top ofmain6921dcfd:All
tests/startup_gfx2hlsl_*_check.py,tests/startup_translator_check.pyandtests/docs_links_check.pypass.Open
#2092's plain path accepts encoded NEG/ABS as bit-15 operations. This PR refuses them on the SDWA path and leaves the plain path as merged; there is a question about it in the conversation.
startup_gfx2hlsl_cmp_class_f16_check.pyfrom #2092 is registered in CMake but not listed inAGENTS.mdorwindows.yml, which I left alone here.AI-assisted.