startup: lower v_cmp_class_f16 and v_cmpx_class_f16 (issue #1855) #2085
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2092"
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 ChazY11 on 2026-11-25T00:10:04Z.
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.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:13:48Z.
Review: COMMENTED
Review of head
4b15ae0930(comment only).Scope:
tools/startup/gfx2hlsl.pylowersv_cmp_class_f16/v_cmpx_class_f16through a newclass16helper on the raw half word.abs/negact on bit 15. A float-printed operand is refused.CMakeLists.txtonly registers the new test.tests/startup_gfx2hlsl_cmp_class_f16_check.pybuilds 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 conflictsMutations (reverted afterwards):
0x0400u->0x0800uinclass16: killed (the 65536-half agreement check reports MISMATCH).^ 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.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T00:17:48Z.
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 comment
so the platforms are green in both directions, not just the Linux side you ran.
Your
0x0400→0x0800mutation is the better version of what I ranI mutated the three category bits the issue listed (
-inf/+inf, quiet/signaling NaN,-subnormal/+subnormal) and separately caught theabs/negmixups,but I did not mutate the normal/denormal boundary itself — which is the one threshold that has no name in the issue, and the one where a wrong
exponent bias would hide: an off-by-one there turns every denormal into a normal and the class table still "looks right" for the values a fixture
usually picks. It is killed by the 65,536-half sweep, which is the point of sweeping all of them rather than sampling.
The one behavioural gap I know about, stated so it is not a surprise later
A pair operand is accepted and the low word is used:
The binary32 path does the same thing, so it predates this PR and I left it alone rather than mixing a second behaviour in. If you would rather the half
form refuse a 64-bit source — an f16 operand is 16 bits, so a pair is arguably malformed — that is a two-line change and I will add it here, but it
would then differ from
v_cmp_class_f32until that one is changed too.What is still unestablished, in your terms
Nothing in the test says the emitted HLSL computes the right predicate on a device. If you want that closed before merge, say so and I will add the draw
fixture as a separate PR rather than widening this one; the value check evaluates the helper text in Python, and I would rather that stay labelled as
what it is.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T00:28:44Z.
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.