startup: lower the binary32 class comparison #1791
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1798"
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 triggered02 on 2026-11-24T18:49:47Z.
Fixes #1797. Next group from the refusal census (#870): 2 shaders, both the binary32 class comparison.
Change
v_cmp_class_f32/v_cmpx_class_f32tested which binary32 class a value falls in against a mask, and had no lowering.tools/pixel_aot.pyalready carried the ten-class helper, so it is ported from there:compare()grows a branch lowering the predicate to(class32(value) & mask) != 0u, with the mask read as an integer operand and the value as a float:The census
-1mask is the inline constant meaning "every class"; a literal mask (0x00000300u= +normal|+inf) and a register mask take the same path.Test
startup_gfx2hlsl_cmp_classbuilds VOPC-in-VOP3 encodings from the checked-in decoder's layout (0b110101prefix, opcode[25:16], scalar destinationw0[7:0], sources inw1), decodes them, then translates. Nine checks: both spellings decode and lower, the non-exec form writes VCC, thev_cmpx_form writes EXEC and clearsexec_known, a literal mask and a register mask reach the helper, and the helper is in the common preamble with the quiet/signaling NaN distinction.Fail-first:
&→|fails a register mask is read as an integer; renaming the helper fails the class helper is emitted in the common preamble.What this does not establish
ClassFlagson hardware — they are ported frompixel_aot.pyunchanged, and the census mask (-1) does not exercise individual bits.v_cmp_class_f16/_f64,v_cmpx_class_f16, and DXC/draw results are out of scope.Merge note
#1755 changes
compare()'s signature to takemods; this branch is based on main before it. Both touch the same function, so expect a trivial conflict — resolution keeps themodsargument and this class branch.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T18:53:06Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
ed12196da7ℹ️ 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".
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T18:50:02Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
ed12196ℹ️ 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.
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T18:58:42Z.
All three addressed in
05bce5c0.P1 — operand order. You're right and it was the substantive one: the ISA puts the value in SRC0 and the class-bit mask in SRC1 (the decoder agrees —
src1_is_float = is_float and not is_classin_decode_vopc_sdwa), so I had them swapped:P2 — narrowed EXEC. The class branch now intersects with
execwhenexec_knownis false, matching the generic compare path:P2 —
_e32cmpx. Accepted as the two-operand form and routed to EXEC:Test: the encodings now follow the ISA operand order (value SRC0, mask SRC1 — literal and register masks both), plus the
_e32form and an explicit narrowed-EXEC case. 13 checks.Fail-first, all three confirmed:
dev
startup_gfx2hlsl*+startup_translator13/13, docs links pass.Thank you for catching the swap — a class compare with the operands reversed produces a plausible-looking predicate that would have been very hard to spot in a draw, and my test inherited the same mistake, which is exactly why it passed.
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T18:53:06Z.
Code review location:
tools/startup/gfx2hlsl.py; line 968VOPC syntax places the float to classify in SRC0 and the class-bit mask in SRC1; the existing
tools/pixel_aot.pylowering also parses them asvalue, classes. This code instead treats SRC0 as the mask and SRC1 as the value, sov_cmp_class_f32 ... v1, 0x200emitsclass32(0x200) & v1rather than testingv1for +inf, producing incorrect predicates. Keep the sources in ISA order.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T18:53:07Z.
Code review location:
tools/startup/gfx2hlsl.py; line 972cmpxIf a previous
v_cmpxors_and_saveexechas narrowed EXEC, this assignment replaces it with the class predicate and can reactivate lanes that were already masked off. The generic compare path intersects a new predicate withexecwhenexec_knownis false; apply the same intersection here forv_cmpx_class_f32.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T18:53:07Z.
Code review location:
tools/startup/gfx2hlsl.py; line 965_e32classcmpxinstructionsThe
_e32VOPC decoder formatsv_cmpx_class_f32without a destination because it writes EXEC implicitly, soStage.onepasses only the two source operands. This guard rejects that valid form before lowering; handle the implicit EXEC destination as the generic compare path does.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:14:08Z.
Review: COMMENTED
Peer review of head
05bce5c0511fed9e6fb79180d3251c3d31efd7c3(PRODUCTION_REVIEW_ONLY, technical comment only).No P1. One P2 (test coverage of the class semantics).
Lowering: no defect found.
class32()(tools/startup/gfx2hlsl.py, common preamble) maps the ten classes to the right bits: signaling NaN 0x1, quiet NaN 0x2, -inf 0x4, -normal 0x8, -subnormal 0x10, -0 0x20, +0 0x40, +subnormal 0x80, +normal 0x100, +inf 0x200.compare()the float operand is SRC0 and the integer mask is SRC1, as in the instruction encoding. A narrowed EXEC is intersected with the predicate. The_e32v_cmpx_class_f32form with two operands writes EXEC and clearsexec_known. The_sdwaspelling and operand counts other than 2 (cmpx only) or 3 are still refused.P2:
tests/startup_gfx2hlsl_cmp_class_check.pydoes not check the class semantics.Every check is a substring match on the emitted text (for example
'0x00400000u' in common,'class32(F(v4)) & v0' in emitted). Nothing evaluates the helper, so a wrong class bit passes. I applied three one-line mutations to the helper ingfx2hlsl.py, one at a time:0x4uand0x200u): the check still passes (rc=0).? 0x2u : 0x1uto? 0x1u : 0x2u): rc=0.Only a change to the text the test greps for fails: changing
&to|in the predicate gives rc=1.The Windows run does not cover this either. It builds
offscreen_checkonly for the dev and release presets, andstartup_gfx2hlsl_cmp_classis the same Python text check.Suggestion: add a value-level check that evaluates the emitted helper for the ten class representatives plus both NaN kinds and both zeros. The existing bit-ALU and shift checks in the tree already compare emitted helpers against a reference in Python, which is a pattern to reuse. Separately, an abs/neg modifier on SRC0 is not exercised by any case.
Commands run (Linux, in the prepared worktree):
git diff --check <merge-base>...HEAD: cleantests/docs_links_check.py,tests/bidi_controls_check.py,tests/startup_gfx2hlsl_cmp_class_check.py,tests/startup_translator_check.py: all passclass32()against an independent classifier: 0 differencesgit checkout -- .; the tree is clean05bce5c0, from the coordinator's log:--preset dev):startup_gfx2hlsl_cmp_classandstartup_translator2/2 passed/O2(--preset release): 2/2 passedstartup_gfx2hlsl_cmp_class_check.py: rc=0main.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:29:21Z.
Review: COMMENTED
Retest of head
107b6410fadf2217dbafc7978e7e642c9f0a7491(previous review was on05bce5c0511fed9e6fb79180d3251c3d31efd7c3). PRODUCTION_REVIEW_ONLY, technical comment only.Result: the earlier P2 is closed. No P1/P2 remain.
Delta
05bce5c0->107b6410: onlytests/startup_gfx2hlsl_cmp_class_check.pychanged (+174/-3); the lowering and helper intools/startup/gfx2hlsl.pyare byte-identical to the version I reviewed.class32body with a small expression evaluator and compares it to an independent binary32 classifier written from the bit layout. The grid has 68626 patterns: the edge values, every exponent for both signs with six mantissa shapes (including the quiet/signaling boundary), and a stride over the full 32-bit space.class32(abs(F(v4)))andclass32((-F(v4))).Mutations on the helper, each run against the new check (and restored with
git checkout -- .):&changed to|in the predicate: rc=1 (text checks).Commands run (Linux, in the prepared worktree):
git diff --check <merge-base>...HEAD: cleantests/docs_links_check.py,tests/bidi_controls_check.py,tests/startup_gfx2hlsl_cmp_class_check.py,tests/startup_translator_check.py: all pass107b6410, from the coordinator's log:--preset dev):startup_gfx2hlsl_cmp_classandstartup_translator2/2 passed/O2(--preset release): 2/2 passedstartup_gfx2hlsl_cmp_class_check.py: rc=0mainthe merge has no content conflicts (git merge-tree).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T19:19:46Z.
P2 addressed in
107b6410. Your criticism of the test was right, and the mutations you ran are exactly the evidence it was missing: three wrong class bits passed the old text checks.What changed: the test now checks the helper by value.
uint/booldeclarations,if (...) return ...;, ternaries,& | ^ == != >= <= > < + -,asuint), which runs the emitted helper body for each bit pattern.0, 1, 0x3FFFFF, 0x400000, 0x7FFFFE, 0x7FFFFF), then a strided sweep over the whole 32-bit space.Fail-first, the three mutations you listed:
All three still pass the substring checks, which is precisely why they now fail on values.
Abs/neg SRC0: added. These modifiers arrive as operand text (
|v4|,-v4), not as a modifier list, so the helper must see the modified bits:Thanks also for compiling
class32()independently and comparing it against your classifier across the full space with edge values — that is stronger evidence for the lowering than anything my test does, and it is good to know the two agree.One process note on my side: the first family run after your review showed nine failures, which turned out to be a stale CMake configure from another branch in my tree, not the change — after reconfiguring,
startup_gfx2hlsl*+startup_translatorare 13/13 at107b6410.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T21:48:02Z.
Integrated the binary32 class lowering with #1755 and the integer SDWA and shift paths. The helper matches the independent model on 68,626 patterns. The controls preserve the value-first operand order, incoming EXEC and the two-source e32 compare. Nearby op_sel, VOPC SDWA, b64 shift, m0 and translator checks pass.