startup: lower the binary16 class comparison #1856
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!1856
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1856/head"
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?
@triggered02 on GitHub · 2026-11-24 19:39 UTC · original
triggered02:startup/cmp-class-f16→main· +660 −0 · 5 files · 4 commits · closed without mergingFixes #1855. Found in the refusal census (#870). 1 refused shader:
Problem
The binary16 class comparison had no lowering. The binary32 form is handled by the class-compare branch (PR #1798), but the half form needs a different helper: the value is the raw binary16 bit pattern in the low half of the operand word, the ten class bits follow the half format (exponent 5 bits, mantissa 10, quiet bit 0x0200), and an
abs/negmodifier acts on bit 15 rather than bit 31.Fix
tools/pixel_aot.pyalready carried the binary16 helper; it is ported intoPipeline.common()asclass16, and the class-compare branch dispatches on the mnemonic:Measured on the branch:
v_cmp_class_f16_e64 s14, 0x7c01, v0s14 = (((class16(0x00007c01u) & v0) != 0u) ? 1u : 0u);v_cmpx_class_f16_e64 vcc_lo, v0, -1exec = (((class16(v0) & 0xffffffffu) != 0u) ? 1u : 0u);v_cmpx_class_f16_e32 v0, v5exec = (((class16(v0) & v5) != 0u) ? 1u : 0u);The
abs/negmodifier forms lower toclass16((v0 & 0x7fffu))andclass16((v0 ^ 0x8000u)). A float-printed operand is refused by name, because it would otherwise be lowered as its binary32 bit pattern.Test
startup_gfx2hlsl_cmp_class_f16builds VOPC-in-VOP3 encodings from the checked-in decoder's layout, decodes them, then translates. Ten checks: the census form, both exec-mask shapes, theabs/neghandling on bit 15, the float-operand refusal, and — value-level — a Python binary16 classifier (written from the IEEE half layout) compared against the emitted helper body evaluated over all 65,536 binary16 patterns.Fail-first, three genuine class-bit mutations (all fail the value-level check while the text checks pass):
Depends on #1798
This branch is based on
startup/cmp-class(#1798) because the class-compare branch andclass32helper are not onmainyet. Merge #1798 first; after that this PR's diff is only theclass16helper, the mnemonic dispatch and the new test.What this does not establish
v_cmp_class_f64and the arithmetic/compare f16 forms that are not class comparisons are out of scope.AI-assisted (Claude Code).
@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 19:39 UTC · original · edited 2026-11-24 19:45 UTC
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
7187e51ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
@ -962,0 +982,4 @@if operand in FLOATS or re.fullmatch(r'-?\d+\.\d+', operand):raise Unsupported('binary16 class operand %s' % value)bits = self.u(operand)if value.startswith('-') and not re.match(r'-[\d.]', value):@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 19:45 UTC · original
When a VOP3 class compare applies NEG to an immediate, the lowering can lose the sign because it infers modifiers from the printed token: for f16, literal
0x7c00becomes-0x7c00, but this check treats the leading-0as a numeric sign and skips the XOR, soclass16sees0x8400(negative normal) instead of0xfc00(-inf). The f32 arm likewise turns a negated inline zero (-0) into positive zero throughself.f. Masks distinguishing those classes therefore produce wrong predicates; preserve the encoded modifier or refuse these numeric forms.Useful? React with 👍 / 👎.
@tedin7 on GitHub · 2026-11-25 12:53 UTC · original
@triggered02 could you rebase this branch onto current
mainand force-push?GitHub reports head
7187e51das conflicting withmain, so it cannot be merged as is.Files that conflict with current
main(cf97bee1):CMakeLists.txtdocs/experiments.mdtests/startup_gfx2hlsl_cmp_class_f16_check.pytools/startup/gfx2hlsl.pyCommands run locally:
Once it is rebased and CI is green it will be re-checked right away.
AI-assisted; commands listed were executed locally.
@triggered02 on GitHub · 2026-11-25 13:22 UTC · original
Closing: this content is already on
main. I checkedorigin/mainand it has theclass16helper, thev_cmp_class_f16/v_cmpx_class_f16dispatch inside the class branch (with thebase.startswith('v_cmpx_')shape) andtests/startup_gfx2hlsl_cmp_class_f16_check.py— i.e. the branch was integrated directly rather than through this PR, which is why the PR still showed as conflicting.For the record, the substance of the branch is in
main:uint class16(uint bits)with the ten binary16 class bits and the quiet bit at 0x0200,abs/negacting on bit 15),Nothing more to do here; thanks for integrating it.
AI-assisted (Claude Code).
@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 19:45 UTC · original · reviewed
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
7187e51d48ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
@tedin7 on GitHub · 2026-11-24 19:51 UTC · original · reviewed
Review of head
7187e51d483bab89ae0d671c091567968feee431.Verdict: 0 P1 / 0 P2. The lowering matches the RDNA 2 class-compare semantics as I read them. Comment only, not an approval.
Linux limits. Linux x86_64, Python 3. No Windows, no DXC, no GPU. I ran the Python checks directly; I did not configure CMake, so the two new
add_testlines (startup_gfx2hlsl_cmp_class,startup_gfx2hlsl_cmp_class_f16) were not executed through ctest. Nothing here compiled the emitted HLSL; the helper agreement checks use the checks' own Python model of it.What I checked
class32andclass16return exactly these. The quiet bit is 0x00400000 (binary32) and 0x0200 (binary16). The thresholds (0x00800000 / 0x0400 for normal) and the infinity/NaN cut (0x7f800000 / 0x7c00) are right.self.u, so-1becomes0xffffffffu._e32v_cmpx_spelling (2 operands, implicit EXEC) is handled. Other operand counts raiseUnsupported.negXORs 0x8000 andabsANDs 0x7fff, and a float-printed operand (1.0,-0.5, ...) is refused. The refusal is the safe choice, because a float literal would otherwise be lowered as binary32 bits.v_cmpx_form clearsexec_known.What I ran at this SHA (worktree at the exact head,
git statusclean after every mutation)python3 -B tests/startup_gfx2hlsl_cmp_class_check.py: PASS (helper agrees with the binary32 classifier on 68626 patterns).python3 -B tests/startup_gfx2hlsl_cmp_class_f16_check.py: PASS (all 65536 binary16 patterns).tests/startup_gfx2hlsl_*_check.pyscripts: exit 0.tests/docs_links_check.py(17 files, 367 links),tests/bidi_controls_check.py(1309 files),git diff --check origin/main...HEAD: clean.tools/startup/gfx2hlsl.py, each followed by both checks and thengit checkout -- .. Every one was caught by at least one check:>=to>negXORs bit 31absmasks 0x7fffffffv_cmpx_keepsexec_knownFindings (non-blocking)
class32helper, its test, its docs paragraph, its CMake entry), which is also the content of open #1798. Whichever lands second will conflict or duplicate. The title and theFixes #1855line name only binary16. Please land #1798 first and rebase, or say here that this PR supersedes it.compare()is called asself.compare(base, ops), so trailing modifiers (clamp,op_sel:[...]) are dropped silently for the class forms. That is also true of the existing generic compare, so it is not new, and I did not find a census form that prints one. #1778 ("refuse a modifier for handlers that do not model one") looks like the right place to cover this; it would be worth checking that it reachescompareonce both are merged.Not run here: ctest, DXC compile of the emitted shader, any Windows or GPU run.
AI-assisted; commands listed were executed locally.
Pull request closed