Repository navigation
startup: lower the binary16 class comparison - #1856
triggered02 wants to merge 4 commits into
Conversation
Fixes R0Y00#1797. v_cmp_class_f32 and v_cmpx_class_f32 had no lowering, so both census forms were refused - 2 of the remaining refused shaders in the loading-screen cache (R0Y00#870). The ten-class helper is ported from tools/pixel_aot.py into the shader preamble, and compare() lowers the predicate to (class32(value) & mask) != 0u with the mask read as an integer operand and the value as a float. The non-exec form writes VCC; the v_cmpx_ form writes EXEC and clears the straight-line assumption. Test builds VOPC-in-VOP3 encodings, decodes, then translates: both spellings, a literal mask, a register mask, and the helper's presence and NaN distinction in the common preamble. Fail-first: & -> | fails 'a register mask is read as an integer'; renaming the helper fails 'the class helper is emitted in the common preamble'. Both presets pass.
Review on R0Y00#1798 (1 P1, 2 P2). (P1) The ISA order is value in SRC0 and class-bit mask in SRC1; the branch had them swapped, so 'v_cmp_class_f32 vcc, v4, 0x200' tested class(mask) against the value instead of classifying v4 for +inf. (P2) A narrowed EXEC must stay narrowed: the predicate is now intersected with exec when exec_known is false, as the generic compare path does. (P2) The _e32 cmpx spelling prints no destination because it writes EXEC implicitly, so the two-operand form is accepted and routed to EXEC. The test now encodes the ISA operand order, adds the e32 exec-mask form, and asserts the intersection with a narrowed EXEC. Fail-first: swapping the operands back, removing the intersection, and rejecting the two-operand form each fail the test.
Review on R0Y00#1798 (P2): every class check was a substring match on the emitted text, so a wrong class bit passed. The test now carries a Python classifier written from the IEEE binary32 layout (sign, exponent, mantissa) and a small recursive-descent evaluator for the integer HLSL the helper emits; it runs the emitted helper body over 68626 bit patterns (18 edge cases plus every exponent with mantissa boundaries, plus a strided sweep of the whole 32-bit space) and requires the returned class bits to match the classifier. Fail-first: swapping the -inf/+inf bits, the quiet/signaling NaN bits, or the subnormal bits each fail this check while the old text checks still passed. Also added the abs/neg SRC0 cases: those modifiers arrive as operand text (|v4|, -v4) rather than a modifier list, so the helper must see the modified bits.
Fixes R0Y00#1855. v_cmp_class_f16 and v_cmpx_class_f16 had no lowering, so the census form v_cmp_class_f16_e64 s14, 0x7c01, v0 was refused. tools/pixel_aot.py already carried the binary16 helper; it is ported into Pipeline.common() as class16, and the class-compare branch dispatches on the mnemonic: the value is the raw binary16 bits in the low half of the word, abs/neg act on bit 15, and a float-printed operand is refused (it would be lowered as its binary32 bits). The _e32/_e64 and cmpx shapes share the binary32 path now with a generic v_cmpx_ check. Test builds VOPC encodings, decodes then translates, and checks the helper by value: a Python binary16 classifier against the emitted helper evaluated over all 65536 patterns; the three class-bit mutations fail it. Stacked on R0Y00#1798 (class-compare branch not on main yet).
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour 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. |
There was a problem hiding this comment.
💡 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
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| 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): |
There was a problem hiding this comment.
Preserve NEG on immediate class operands
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 0x7c00 becomes -0x7c00, but this check treats the leading -0 as a numeric sign and skips the XOR, so class16 sees 0x8400 (negative normal) instead of 0xfc00 (-inf). The f32 arm likewise turns a negated inline zero (-0) into positive zero through self.f. Masks distinguishing those classes therefore produce wrong predicates; preserve the encoded modifier or refuse these numeric forms.
Useful? React with 👍 / 👎.
tedin7
left a comment
There was a problem hiding this comment.
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_test lines (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
- ISA class bits, in encoding order: sNaN, qNaN, -inf, -normal, -denormal, -0, +0, +denormal, +normal, +inf = 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200. Both
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. - Operand order is value first, mask second. The mask goes through
self.u, so-1becomes0xffffffffu. - The
_e32v_cmpx_spelling (2 operands, implicit EXEC) is handled. Other operand counts raiseUnsupported. - For binary16 the value is read as raw bits,
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. - When EXEC is not known to be full, the predicate is intersected with it, as the generic compare path does; a
v_cmpx_form clearsexec_known.
What I ran at this SHA (worktree at the exact head, git status clean 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).- All 11 neighbouring
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.- Mutations in
tools/startup/gfx2hlsl.py, each followed by both checks and thengit checkout -- .. Every one was caught by at least one check:
| Mutation | f32 check | f16 check |
|---|---|---|
| f32 sNaN/qNaN result swapped | fail | pass |
| f32 -inf/+inf swapped | fail | pass |
f16 normal threshold >= to > |
pass | fail |
f16 neg XORs bit 31 |
pass | fail |
f16 abs masks 0x7fffffff |
pass | fail |
| EXEC intersection removed | fail | pass |
v_cmpx_ keeps exec_known |
fail | fail |
| f16 float operand allowed | pass | fail |
| mask read as float | fail | pass |
Findings (non-blocking)
- P3, stacking: this branch carries the whole binary32 change (the
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. - P3, modifiers:
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. - P3, evidence: the checks encode the instruction bytes by hand from the decoder's field layout, and the helper is tested against a Python model. Neither confirms HLSL compilation or the draw result. That is the same footing as the neighbouring startup lowering checks.
Not run here: ctest, DXC compile of the emitted shader, any Windows or GPU run.
AI-assisted; commands listed were executed locally.
|
@triggered02 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. |
|
Closing: this content is already on For the record, the substance of the branch is in
Nothing more to do here; thanks for integrating it. AI-assisted (Claude Code). |
Fixes #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).