Repository navigation
startup: lower v_cmp_class_f16 and v_cmpx_class_f16 (issue #1855) - #2092
Conversation
The binary16 class comparison had no lowering, so the census form `v_cmp_class_f16_e64 s14, 0x7c01, v0` was refused (R0Y00#870). `tools/pixel_aot.py` already carried the ten-class half helper; it is ported into `Pipeline.common()` as `class16`, next to `class32`, and the class-compare branch dispatches on the mnemonic. The half classes follow bits [15:0] (exponent 5 bits, mantissa 10, quiet bit 0x0200), so the value is the raw operand word rather than a converted float, and `abs`/`neg` act on bit 15. The decoder prints an absolute source as `|v4|` and a negated one as `-v4`, so both spellings are accepted alongside `abs(...)`. v_cmp_class_f16_e64 s14, 0x7c01, v0 -> s14 = (((class16(0x00007c01u) & v0) != 0u) ? 1u : 0u); v_cmpx_class_f16_e64 vcc_lo, v0, -1 -> exec = (((class16(v0) & 0xffffffffu) != 0u) ? 1u : 0u); v_cmpx_class_f16_e32 v0, v5 -> exec = (((class16(v0) & v5) != 0u) ? 1u : 0u); v_cmp_class_f16_e64 s14, |v0|, v1 -> s14 = (((class16((v0 & 0x7fffu)) & v1) != 0u) ? 1u : 0u); v_cmp_class_f16_e64 s14, -v0, v1 -> s14 = (((class16((v0 ^ 0x8000u)) & v1) != 0u) ? 1u : 0u); A float-printed operand is refused by name, because it would otherwise be lowered as its binary32 bit pattern. The test builds the VOPC-in-VOP3 encodings from the checked-in decoder's layout, decodes, translates, then checks the emitted text for each form above, the float-operand refusal, and - value level - a binary16 classifier written from the IEEE half layout against the emitted helper body evaluated over all 65,536 halves. Fail-first, three category-bit mutations (each fails the value check while the text checks pass): swap -inf/+inf bits -> the emitted helper disagrees (exit 1) swap quiet/signaling NaN -> the emitted helper disagrees (exit 1) swap -subnormal/+subnormal -> the emitted helper disagrees (exit 1) Not established here: that the emitted HLSL compiles or computes the right predicate on a device. The value check evaluates the helper text in Python; DXC and WARP were not run for this change.
tedin7
left a comment
There was a problem hiding this comment.
Review of head 4b15ae0 (comment only).
Scope: tools/startup/gfx2hlsl.py lowers v_cmp_class_f16 / v_cmpx_class_f16 through a new class16 helper on the raw half word. abs/neg act on bit 15. A float-printed operand is refused. CMakeLists.txt only registers the new test. tests/startup_gfx2hlsl_cmp_class_f16_check.py builds its instruction bytes from the decoder field layout, with no copied vendor text. Clean-room looks fine.
P1: 0. P2: 0.
Commands executed locally (Linux, in a worktree of this head):
python3 -B tests/startup_gfx2hlsl_cmp_class_f16_check.pyPASS (including the 65536-half classifier agreement check)python3 -B tests/startup_gfx2hlsl_cmp_class_check.pyPASS (binary32 sibling)python3 tests/docs_links_check.pyPASSpython3 tests/bidi_controls_check.pyPASSgit diff --check origin/main...HEADcleangit merge-tree --write-tree --name-only origin/main HEADno conflicts
Mutations (reverted afterwards):
- Normal-half threshold
0x0400u->0x0800uinclass16: killed (the 65536-half agreement check reports MISMATCH). - Negation
^ 0x8000u->^ 0x80000000u: killed (a negated half flips bit 15reports MISMATCH).
Windows CI was still pending when this was written.
AI-assisted; commands listed were executed locally.
|
Thanks — that is a more useful review than the CI alone would have been, and two things in it are new to me. Windows CI finished since your commentso the platforms are green in both directions, not just the Linux side you ran. Your
|
|
I added the reproduction notes and kept this slice to the e32/e64 raw-half forms. The census literal reaches the helper unchanged, ambiguous signed inline values and floating class masks are refused, and half SDWA stays outside this patch. The 65,536-value check, decoded operands and refusal controls passed, along with the existing f32 class and SDWA checks. The SDWA work in #2020 can remain a separate follow-up. |
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>
…per (#2020) The plain e32/e64 register and encoded-literal path, including the 0x7c01 census form, landed with #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> Co-authored-by: tedin7 <tommasoderosa94@gmail.com>
What
Lowers
v_cmp_class_f16andv_cmpx_class_f16intools/startup/gfx2hlsl.py, closing the census refusal in #1855:tools/pixel_aot.pyalready carried the ten-class half helper, so this ports it intoPipeline.common()asclass16, next toclass32, anddispatches the half mnemonics in the class-compare branch.
The two things that make the half form different
0x0200. The value is therefore the rawoperand word, never
self.f(value)— converting would test the wrong bit pattern, and an inline0x7c01would arrive as a binary32 float.abs/negact on bit 15, so they are applied to the raw word before the helper:(v0 & 0x7fffu)and(v0 ^ 0x8000u). The decoder prints anabsolute source as
|v4|and a negated one as-v4, so both spellings are accepted alongsideabs(...).A float-printed operand is refused by name, because lowering it would take its binary32 pattern as if it were a half:
Emitted forms
Test
tests/startup_gfx2hlsl_cmp_class_f16_check.pybuilds the VOPC-in-VOP3 encodings from the checked-in decoder's layout (tools/disasm_rdna2.py,opcodes
0x8fand0x9f), decodes them, translates, and checks the emitted text for each form above. Then it does the value-level check: a binary16classifier written from the IEEE half layout, compared against the emitted helper body evaluated over all 65,536 halves.
Registered as
startup_gfx2hlsl_cmp_class_f16besidestartup_gfx2hlsl_cmp_classinCMakeLists.txt— the same place, and the sameCMake-only route, as the binary32 sibling it mirrors.
Fail-first controls, six of them
Each reverts or breaks one clause, and each fails on the assertion that covers it while the other text checks still pass:
-inf/+infbits-subnormal/+subnormalbitsabsmask0x7fffu→ the float0x7fffffffunegxor0x8000u→ the float0x80000000uself.f()The first three are the ones the issue asked for, and they fail at the value level rather than the text level — which is the point: a wrong class
bit produces plausible-looking HLSL.
Whole family still green
All 28
tests/startup_gfx2hlsl_*_check.pyexit 0 on this branch, including the binary32 siblingstartup_gfx2hlsl_cmp_class_check.py, which sharesthe branch this change edits.
What this does not establish
That the emitted HLSL compiles or computes the right predicate on a device. The value check evaluates the helper text in Python; DXC and WARP were not
run for this change. If you want that, it should be a draw fixture, and I would add it as a separate change rather than implying this one was
executed.
Also unchanged and still shared with the binary32 path: a pair operand (
v[0:1]) is accepted and the low word is used. That predates this change — thebinary32 compare does the same — so I left it alone rather than mixing a second behaviour into this PR.
Refs #1855. AI-assisted.