startup: lower the binary32 class comparison #1791

Merged
triggered02 merged 7 commits from upstream-pr/1798 into main 2026-11-24 21:51:53 +00:00
triggered02 commented 2026-11-24 18:49:47 +00:00 (Migrated from github.com)

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_f32 tested which binary32 class a value falls in against a mask, and had no lowering. tools/pixel_aot.py already carried the ten-class helper, so it is ported from there:

uint class32(float value) {   // signaling NaN, quiet NaN, -inf, -normal, -denormal, -0, +0, +denormal, +normal, +inf
    uint bits = asuint(value), magnitude = bits & 0x7fffffffu;
    bool negative = bits >= 0x80000000u;
    if (magnitude > 0x7f800000u) return (bits & 0x00400000u) != 0u ? 0x2u : 0x1u;
    if (magnitude == 0x7f800000u) return negative ? 0x4u : 0x200u;
    if (magnitude >= 0x00800000u) return negative ? 0x8u : 0x100u;
    if (magnitude != 0u) return negative ? 0x10u : 0x80u;
    return negative ? 0x20u : 0x40u;
}

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:

v_cmp_class_f32_e64 vcc_lo, -1, v4   -> vcc  = (((class32(F(v4)) & 0xffffffffu) != 0u) ? 1u : 0u);
v_cmpx_class_f32_e64 vcc_lo, -1, v4  -> exec = (...);   (and clears the straight-line EXEC assumption)

The census -1 mask 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_class builds VOPC-in-VOP3 encodings from the checked-in decoder's layout (0b110101 prefix, opcode [25:16], scalar destination w0[7:0], sources in w1), decodes them, then translates. Nine checks: both spellings decode and lower, the non-exec form writes VCC, the v_cmpx_ form writes EXEC and clears exec_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.

dev:     13/13 startup_gfx2hlsl* + startup_translator passed
release: startup_gfx2hlsl_cmp_class Passed 0.14 s

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

  • That the class bits match LLVM's ClassFlags on hardware — they are ported from pixel_aot.py unchanged, 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 take mods; this branch is based on main before it. Both touch the same function, so expect a trivial conflict — resolution keeps the mods argument and this class branch.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6589028129 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1798). Originally posted by [triggered02](https://github.com/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_f32` tested which binary32 class a value falls in against a mask, and had no lowering. `tools/pixel_aot.py` already carried the ten-class helper, so it is **ported from there**: ```hlsl uint class32(float value) { // signaling NaN, quiet NaN, -inf, -normal, -denormal, -0, +0, +denormal, +normal, +inf uint bits = asuint(value), magnitude = bits & 0x7fffffffu; bool negative = bits >= 0x80000000u; if (magnitude > 0x7f800000u) return (bits & 0x00400000u) != 0u ? 0x2u : 0x1u; if (magnitude == 0x7f800000u) return negative ? 0x4u : 0x200u; if (magnitude >= 0x00800000u) return negative ? 0x8u : 0x100u; if (magnitude != 0u) return negative ? 0x10u : 0x80u; return negative ? 0x20u : 0x40u; } ``` `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: ``` v_cmp_class_f32_e64 vcc_lo, -1, v4 -> vcc = (((class32(F(v4)) & 0xffffffffu) != 0u) ? 1u : 0u); v_cmpx_class_f32_e64 vcc_lo, -1, v4 -> exec = (...); (and clears the straight-line EXEC assumption) ``` The census `-1` mask 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_class` builds VOPC-in-VOP3 encodings from the checked-in decoder's layout (`0b110101` prefix, opcode `[25:16]`, scalar destination `w0[7:0]`, sources in `w1`), decodes them, then translates. Nine checks: both spellings decode and lower, the non-exec form writes VCC, the `v_cmpx_` form writes EXEC and clears `exec_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. ``` dev: 13/13 startup_gfx2hlsl* + startup_translator passed release: startup_gfx2hlsl_cmp_class Passed 0.14 s ``` 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 - That the class bits match LLVM's `ClassFlags` on hardware — they are ported from `pixel_aot.py` unchanged, 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 take `mods`; this branch is based on main before it. Both touch the same function, so expect a trivial conflict — resolution keeps the `mods` argument and this class branch. AI-assisted (Claude Code).
chatgpt-codex-connector[bot commented 2026-11-24 19:01:35 +00:00 (Migrated from github.com)

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

  • 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".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6045386248 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1798#pullrequestreview-6045386248). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T18:53:06Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `ed12196da7` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). 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". </details>
chatgpt-codex-connector[bot commented 2026-11-24 19:01:43 +00:00 (Migrated from github.com)

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.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T18:53:09.910285Z ed12196 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7141215929 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1798#issuecomment-7141215929). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T18:50:02Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"ed12196da719687dca5f87799851481dd500d058","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T18:53:09.910285Z">2026-11-24T18:53:09.910285Z</relative-time> | `ed12196` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
triggered02 commented 2026-11-24 19:01:43 +00:00 (Migrated from github.com)

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_class in _decode_vopc_sdwa), so I had them swapped:

before:  v_cmp_class_f32_e64 vcc_lo, v4, -1   ->  class32(F(0xffffffffu)) & v4      (wrong)
after:   v_cmp_class_f32_e64 vcc_lo, v4, -1   ->  vcc = (((class32(F(v4)) & 0xffffffffu) != 0u) ? 1u : 0u);

P2 — narrowed EXEC. The class branch now intersects with exec when exec_known is false, matching the generic compare path:

exec = (exec & (((class32(F(v4)) & 0x...u) != 0u) ? 1u : 0u));

P2 — _e32 cmpx. Accepted as the two-operand form and routed to EXEC:

v_cmpx_class_f32_e32 v4, v0   ->  exec = (((class32(F(v4)) & v0) != 0u) ? 1u : 0u);

Test: the encodings now follow the ISA operand order (value SRC0, mask SRC1 — literal and register masks both), plus the _e32 form and an explicit narrowed-EXEC case. 13 checks.

Fail-first, all three confirmed:

swap the operands back          -> "a register mask is read as an integer" FAIL
remove the exec intersection    -> "a narrowed exec is intersected with the predicate" FAIL
reject the two-operand form     -> Unsupported: v_cmpx_class_f32 with 2 operands

dev startup_gfx2hlsl* + startup_translator 13/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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7141418248 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1798#issuecomment-7141418248). Originally posted by [triggered02](https://github.com/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_class` in `_decode_vopc_sdwa`), so I had them swapped: ``` before: v_cmp_class_f32_e64 vcc_lo, v4, -1 -> class32(F(0xffffffffu)) & v4 (wrong) after: v_cmp_class_f32_e64 vcc_lo, v4, -1 -> vcc = (((class32(F(v4)) & 0xffffffffu) != 0u) ? 1u : 0u); ``` **P2 — narrowed EXEC.** The class branch now intersects with `exec` when `exec_known` is false, matching the generic compare path: ``` exec = (exec & (((class32(F(v4)) & 0x...u) != 0u) ? 1u : 0u)); ``` **P2 — `_e32` cmpx.** Accepted as the two-operand form and routed to EXEC: ``` v_cmpx_class_f32_e32 v4, v0 -> exec = (((class32(F(v4)) & v0) != 0u) ? 1u : 0u); ``` **Test:** the encodings now follow the ISA operand order (value SRC0, mask SRC1 — literal and register masks both), plus the `_e32` form and an explicit narrowed-EXEC case. 13 checks. **Fail-first, all three confirmed:** ``` swap the operands back -> "a register mask is read as an integer" FAIL remove the exec intersection -> "a narrowed exec is intersected with the predicate" FAIL reject the two-operand form -> Unsupported: v_cmpx_class_f32 with 2 operands ``` dev `startup_gfx2hlsl*` + `startup_translator` 13/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).
chatgpt-codex-connector[bot commented 2026-11-24 19:01:45 +00:00 (Migrated from github.com)

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 968

@@ -959,6 +959,25 @@ def op_v_cvt_pkrtz_f16_f32(self, ops, mods):
         self.set_v(reg_range(ops[0])[1], 'f32tof16(%s) | (f32tof16(%s) << 16)' % (self.f(ops[1]), self.f(ops[2])))
 
     def compare(self, base, ops):
+        # v_cmp_class_f32 / v_cmpx_class_f32 test the binary32 class of SRC1 against the mask in SRC0.
+        # The mask is an integer operand (often the inline -1), the value is read as float.
+        if base in ('v_cmp_class_f32', 'v_cmpx_class_f32'):
+            if len(ops) != 3:
+                raise Unsupported('%s with %d operands' % (base, len(ops)))
+            dst, mask, value = ops
+            cond = '(class32(%s) & %s) != 0u' % (self.f(value), self.u(mask))

P1 Badge Respect the value-first class-compare operands

VOPC syntax places the float to classify in SRC0 and the class-bit mask in SRC1; the existing tools/pixel_aot.py lowering also parses them as value, classes. This code instead treats SRC0 as the mask and SRC1 as the value, so v_cmp_class_f32 ... v1, 0x200 emits class32(0x200) & v1 rather than testing v1 for +inf, producing incorrect predicates. Keep the sources in ISA order.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4684957422 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1798#discussion_r4684957422). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T18:53:06Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 968 ~~~~diff @@ -959,6 +959,25 @@ def op_v_cvt_pkrtz_f16_f32(self, ops, mods): self.set_v(reg_range(ops[0])[1], 'f32tof16(%s) | (f32tof16(%s) << 16)' % (self.f(ops[1]), self.f(ops[2]))) def compare(self, base, ops): + # v_cmp_class_f32 / v_cmpx_class_f32 test the binary32 class of SRC1 against the mask in SRC0. + # The mask is an integer operand (often the inline -1), the value is read as float. + if base in ('v_cmp_class_f32', 'v_cmpx_class_f32'): + if len(ops) != 3: + raise Unsupported('%s with %d operands' % (base, len(ops))) + dst, mask, value = ops + cond = '(class32(%s) & %s) != 0u' % (self.f(value), self.u(mask)) ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Respect the value-first class-compare operands** VOPC syntax places the float to classify in SRC0 and the class-bit mask in SRC1; the existing `tools/pixel_aot.py` lowering also parses them as `value, classes`. This code instead treats SRC0 as the mask and SRC1 as the value, so `v_cmp_class_f32 ... v1, 0x200` emits `class32(0x200) & v1` rather than testing `v1` for +inf, producing incorrect predicates. Keep the sources in ISA order. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-24 19:01:45 +00:00 (Migrated from github.com)

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 972

@@ -959,6 +959,25 @@ def op_v_cvt_pkrtz_f16_f32(self, ops, mods):
         self.set_v(reg_range(ops[0])[1], 'f32tof16(%s) | (f32tof16(%s) << 16)' % (self.f(ops[1]), self.f(ops[2])))
 
     def compare(self, base, ops):
+        # v_cmp_class_f32 / v_cmpx_class_f32 test the binary32 class of SRC1 against the mask in SRC0.
+        # The mask is an integer operand (often the inline -1), the value is read as float.
+        if base in ('v_cmp_class_f32', 'v_cmpx_class_f32'):
+            if len(ops) != 3:
+                raise Unsupported('%s with %d operands' % (base, len(ops)))
+            dst, mask, value = ops
+            cond = '(class32(%s) & %s) != 0u' % (self.f(value), self.u(mask))
+            predicate = '((%s) ? 1u : 0u)' % cond
+            if base == 'v_cmpx_class_f32' or dst in ('exec', 'exec_lo'):
+                self.exec_known = False
+                self.emit('exec = %s;' % predicate)

P2 Badge Preserve the incoming EXEC mask for class cmpx

If a previous v_cmpx or s_and_saveexec has 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 with exec when exec_known is false; apply the same intersection here for v_cmpx_class_f32.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4684957448 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1798#discussion_r4684957448). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T18:53:07Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 972 ~~~~diff @@ -959,6 +959,25 @@ def op_v_cvt_pkrtz_f16_f32(self, ops, mods): self.set_v(reg_range(ops[0])[1], 'f32tof16(%s) | (f32tof16(%s) << 16)' % (self.f(ops[1]), self.f(ops[2]))) def compare(self, base, ops): + # v_cmp_class_f32 / v_cmpx_class_f32 test the binary32 class of SRC1 against the mask in SRC0. + # The mask is an integer operand (often the inline -1), the value is read as float. + if base in ('v_cmp_class_f32', 'v_cmpx_class_f32'): + if len(ops) != 3: + raise Unsupported('%s with %d operands' % (base, len(ops))) + dst, mask, value = ops + cond = '(class32(%s) & %s) != 0u' % (self.f(value), self.u(mask)) + predicate = '((%s) ? 1u : 0u)' % cond + if base == 'v_cmpx_class_f32' or dst in ('exec', 'exec_lo'): + self.exec_known = False + self.emit('exec = %s;' % predicate) ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Preserve the incoming EXEC mask for class `cmpx`** If a previous `v_cmpx` or `s_and_saveexec` has 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 with `exec` when `exec_known` is false; apply the same intersection here for `v_cmpx_class_f32`. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-24 19:01:45 +00:00 (Migrated from github.com)

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

@@ -959,6 +959,25 @@ def op_v_cvt_pkrtz_f16_f32(self, ops, mods):
         self.set_v(reg_range(ops[0])[1], 'f32tof16(%s) | (f32tof16(%s) << 16)' % (self.f(ops[1]), self.f(ops[2])))
 
     def compare(self, base, ops):
+        # v_cmp_class_f32 / v_cmpx_class_f32 test the binary32 class of SRC1 against the mask in SRC0.
+        # The mask is an integer operand (often the inline -1), the value is read as float.
+        if base in ('v_cmp_class_f32', 'v_cmpx_class_f32'):
+            if len(ops) != 3:

P2 Badge Accept two-source _e32 class cmpx instructions

The _e32 VOPC decoder formats v_cmpx_class_f32 without a destination because it writes EXEC implicitly, so Stage.one passes 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 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4684957461 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1798#discussion_r4684957461). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T18:53:07Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 965 ~~~~diff @@ -959,6 +959,25 @@ def op_v_cvt_pkrtz_f16_f32(self, ops, mods): self.set_v(reg_range(ops[0])[1], 'f32tof16(%s) | (f32tof16(%s) << 16)' % (self.f(ops[1]), self.f(ops[2]))) def compare(self, base, ops): + # v_cmp_class_f32 / v_cmpx_class_f32 test the binary32 class of SRC1 against the mask in SRC0. + # The mask is an integer operand (often the inline -1), the value is read as float. + if base in ('v_cmp_class_f32', 'v_cmpx_class_f32'): + if len(ops) != 3: ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Accept two-source `_e32` class `cmpx` instructions** The `_e32` VOPC decoder formats `v_cmpx_class_f32` without a destination because it writes EXEC implicitly, so `Stage.one` passes 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 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-24 20:00:39 +00:00 (Migrated from github.com)

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.
  • I compiled the helper text as C and compared it with an independent exponent/mantissa classifier. I used every 4097th bit pattern over the full 32-bit space plus 13 edge values: 0, -0, smallest and largest subnormals, smallest normal, largest finite, +/-inf, signaling and quiet NaN of both signs. Result: 0 differences.
  • In 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 _e32 v_cmpx_class_f32 form with two operands writes EXEC and clears exec_known. The _sdwa spelling and operand counts other than 2 (cmpx only) or 3 are still refused.

P2: tests/startup_gfx2hlsl_cmp_class_check.py does 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 in gfx2hlsl.py, one at a time:

  • swap the -inf and +inf bits (0x4u and 0x200u): the check still passes (rc=0).
  • swap quiet and signaling NaN (? 0x2u : 0x1u to ? 0x1u : 0x2u): rc=0.
  • swap the -subnormal and +subnormal bits: 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_check only for the dev and release presets, and startup_gfx2hlsl_cmp_class is 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: clean
  • tests/docs_links_check.py, tests/bidi_controls_check.py, tests/startup_gfx2hlsl_cmp_class_check.py, tests/startup_translator_check.py: all pass
  • C port of class32() against an independent classifier: 0 differences
  • Mutations above, each restored with git checkout -- .; the tree is clean
  • Windows Server 2025 (build 26100, MSVC 14.44, WARP) at the same commit 05bce5c0, from the coordinator's log:
    • Debug (--preset dev): startup_gfx2hlsl_cmp_class and startup_translator 2/2 passed
    • Release /O2 (--preset release): 2/2 passed
    • Python check startup_gfx2hlsl_cmp_class_check.py: rc=0
  • The PR is MERGEABLE against current main.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6045707717 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1798#pullrequestreview-6045707717). Originally posted by [tedin7](https://github.com/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. - I compiled the helper text as C and compared it with an independent exponent/mantissa classifier. I used every 4097th bit pattern over the full 32-bit space plus 13 edge values: 0, -0, smallest and largest subnormals, smallest normal, largest finite, +/-inf, signaling and quiet NaN of both signs. Result: 0 differences. - In `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 `_e32` `v_cmpx_class_f32` form with two operands writes EXEC and clears `exec_known`. The `_sdwa` spelling and operand counts other than 2 (cmpx only) or 3 are still refused. **P2: `tests/startup_gfx2hlsl_cmp_class_check.py` does 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 in `gfx2hlsl.py`, one at a time: - swap the -inf and +inf bits (`0x4u` and `0x200u`): the check still passes (rc=0). - swap quiet and signaling NaN (`? 0x2u : 0x1u` to `? 0x1u : 0x2u`): rc=0. - swap the -subnormal and +subnormal bits: 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_check` only for the dev and release presets, and `startup_gfx2hlsl_cmp_class` is 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`: clean - `tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `tests/startup_gfx2hlsl_cmp_class_check.py`, `tests/startup_translator_check.py`: all pass - C port of `class32()` against an independent classifier: 0 differences - Mutations above, each restored with `git checkout -- .`; the tree is clean - Windows Server 2025 (build 26100, MSVC 14.44, WARP) at the same commit `05bce5c0`, from the coordinator's log: - Debug (`--preset dev`): `startup_gfx2hlsl_cmp_class` and `startup_translator` 2/2 passed - Release `/O2` (`--preset release`): 2/2 passed - Python check `startup_gfx2hlsl_cmp_class_check.py`: rc=0 - The PR is MERGEABLE against current `main`. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-24 20:00:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:29:21Z.

Review: COMMENTED


Retest of head 107b6410fadf2217dbafc7978e7e642c9f0a7491 (previous review was on 05bce5c0511fed9e6fb79180d3251c3d31efd7c3). PRODUCTION_REVIEW_ONLY, technical comment only.

Result: the earlier P2 is closed. No P1/P2 remain.

Delta 05bce5c0 -> 107b6410: only tests/startup_gfx2hlsl_cmp_class_check.py changed (+174/-3); the lowering and helper in tools/startup/gfx2hlsl.py are byte-identical to the version I reviewed.

  • The check now evaluates the emitted class32 body 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.
  • It also checks that SRC0 abs and neg arrive as class32(abs(F(v4))) and class32((-F(v4))).

Mutations on the helper, each run against the new check (and restored with git checkout -- .):

  • swap the -inf and +inf bits: rc=1 ("the emitted helper agrees with the binary32 classifier ... MISMATCH"). Before the change this passed.
  • swap quiet and signaling NaN: rc=1. Before the change this passed.
  • swap the -subnormal and +subnormal bits: rc=1. Before the change this passed.
  • & changed to | in the predicate: rc=1 (text checks).

Commands run (Linux, in the prepared worktree):

  • git diff --check <merge-base>...HEAD: clean
  • tests/docs_links_check.py, tests/bidi_controls_check.py, tests/startup_gfx2hlsl_cmp_class_check.py, tests/startup_translator_check.py: all pass
  • The four mutations above
  • Windows Server 2025 (build 26100, MSVC 14.44, WARP) at 107b6410, from the coordinator's log:
    • Debug (--preset dev): startup_gfx2hlsl_cmp_class and startup_translator 2/2 passed
    • Release /O2 (--preset release): 2/2 passed
    • Python check startup_gfx2hlsl_cmp_class_check.py: rc=0
  • Against current main the merge has no content conflicts (git merge-tree).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6045939322 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1798#pullrequestreview-6045939322). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T19:29:21Z. **Review:** COMMENTED --- Retest of head `107b6410fadf2217dbafc7978e7e642c9f0a7491` (previous review was on `05bce5c0511fed9e6fb79180d3251c3d31efd7c3`). PRODUCTION_REVIEW_ONLY, technical comment only. **Result: the earlier P2 is closed. No P1/P2 remain.** Delta `05bce5c0` -> `107b6410`: only `tests/startup_gfx2hlsl_cmp_class_check.py` changed (+174/-3); the lowering and helper in `tools/startup/gfx2hlsl.py` are byte-identical to the version I reviewed. - The check now evaluates the emitted `class32` body 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. - It also checks that SRC0 abs and neg arrive as `class32(abs(F(v4)))` and `class32((-F(v4)))`. Mutations on the helper, each run against the new check (and restored with `git checkout -- .`): - swap the -inf and +inf bits: rc=1 ("the emitted helper agrees with the binary32 classifier ... MISMATCH"). Before the change this passed. - swap quiet and signaling NaN: rc=1. Before the change this passed. - swap the -subnormal and +subnormal bits: rc=1. Before the change this passed. - `&` changed to `|` in the predicate: rc=1 (text checks). Commands run (Linux, in the prepared worktree): - `git diff --check <merge-base>...HEAD`: clean - `tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `tests/startup_gfx2hlsl_cmp_class_check.py`, `tests/startup_translator_check.py`: all pass - The four mutations above - Windows Server 2025 (build 26100, MSVC 14.44, WARP) at `107b6410`, from the coordinator's log: - Debug (`--preset dev`): `startup_gfx2hlsl_cmp_class` and `startup_translator` 2/2 passed - Release `/O2` (`--preset release`): 2/2 passed - Python check `startup_gfx2hlsl_cmp_class_check.py`: rc=0 - Against current `main` the merge has no content conflicts (`git merge-tree`). AI-assisted; commands listed were executed locally.
triggered02 commented 2026-11-24 20:01:17 +00:00 (Migrated from github.com)

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.

  • A Python classifier written from the IEEE binary32 layout (sign, exponent, mantissa) — sNaN/qNaN separated by the quiet bit, ±inf, ±normal, ±subnormal, ±0 — not from the lowering's expressions.
  • A small recursive-descent evaluator for the integer HLSL subset the helper emits (uint/bool declarations, if (...) return ...;, ternaries, & | ^ == != >= <= > < + -, asuint), which runs the emitted helper body for each bit pattern.
  • 68,626 patterns: 18 edge cases, every exponent 0–255 with mantissa boundaries (0, 1, 0x3FFFFF, 0x400000, 0x7FFFFE, 0x7FFFFF), then a strided sweep over the whole 32-bit space.
the emitted helper agrees with the binary32 classifier on 68626 patterns: ok

Fail-first, the three mutations you listed:

swap -inf/+inf bits           -> "the emitted helper agrees with the binary32 classifier ..." FAIL
swap quiet/signaling NaN bits -> FAIL
swap -subnormal/+subnormal    -> FAIL

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:

an absolute value reaches the helper as abs: ok
a negated value reaches the helper as a negation: ok

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_translator are 13/13 at 107b6410.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7141935795 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1798#issuecomment-7141935795). Originally posted by [triggered02](https://github.com/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**. - A Python classifier written from the IEEE binary32 layout (sign, exponent, mantissa) — sNaN/qNaN separated by the quiet bit, ±inf, ±normal, ±subnormal, ±0 — not from the lowering's expressions. - A small recursive-descent evaluator for the integer HLSL subset the helper emits (`uint`/`bool` declarations, `if (...) return ...;`, ternaries, `& | ^ == != >= <= > < + -`, `asuint`), which runs the **emitted helper body** for each bit pattern. - 68,626 patterns: 18 edge cases, every exponent 0–255 with mantissa boundaries (`0, 1, 0x3FFFFF, 0x400000, 0x7FFFFE, 0x7FFFFF`), then a strided sweep over the whole 32-bit space. ``` the emitted helper agrees with the binary32 classifier on 68626 patterns: ok ``` **Fail-first, the three mutations you listed:** ``` swap -inf/+inf bits -> "the emitted helper agrees with the binary32 classifier ..." FAIL swap quiet/signaling NaN bits -> FAIL swap -subnormal/+subnormal -> FAIL ``` 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: ``` an absolute value reaches the helper as abs: ok a negated value reaches the helper as a negation: ok ``` 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_translator` are 13/13 at `107b6410`. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 22:00:45 +00:00
R0Y00 commented 2026-11-24 22:01:05 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7145404376 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1798#issuecomment-7145404376). Originally posted by [R0Y00](https://github.com/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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1791
No description provided.