shader: lower s_sub_u32, s_subb_u32 and s_addc_u32 in gfx2hlsl (Part of #1723) #2039

Closed
tedin7 wants to merge 2 commits from upstream-pr/2046 into main
tedin7 commented 2026-11-24 23:37:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T23:37:48Z.


Part of #1723

What this unblocks: Run 21 scalar carry chains (s_add_u32 + s_addc_u32, s_sub_u32 + s_subb_u32), the 64-bit address and offset arithmetic shaders use.

gfx2hlsl had no lowering for s_addc_u32 and s_subb_u32, and s_add_u32 / s_sub_u32 left SCC at its old value, so a carry chain would have read a stale carry. All four now write the result and the carry or borrow.

  • s_add_u32: SCC = carry out of bit 31.
  • s_sub_u32: SCC = borrow (S1 > S0).
  • s_addc_u32 / s_subb_u32: the old SCC is copied out first, then used for the result and for the new SCC.
  • SCC is computed before the destination is written, so a destination that is also a source still gets the right carry.
  • The uniformity proof follows the new SCC like any other compare result.
  • s_addc_u32 and s_subb_u32 on a lane mask (exec, vcc, an SGPR holding a compare result) are refused.

Changes:

  • tools/startup/gfx2hlsl.py: carry table, lowering of the two carry-in forms, lane-mask refusal.
  • tests/startup_gfx2hlsl_scalar_carry_check.py (new, registered in CMakeLists.txt): runs the emitted lines over boundary value pairs with SCC clear and set, for every destination and source form, against a plain-integer reference.
  • tests/startup_gfx2hlsl_readfirstlane_uniform_check.py: the "unmodelled" case now uses s_add_i32; a new case checks a uniform s_add_u32 carry keeps the proof.

Verification: run locally on Linux (not on Win2025), from the repo root of the branch.

  • python3 -B tests/startup_gfx2hlsl_scalar_carry_check.py: PASS with the change. With tools/startup/gfx2hlsl.py from origin/main: FAIL (all 12 checks).
  • python3 -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py: 0 failed.
  • python3 -B tests/startup_gfx2hlsl_scalar_m0_check.py: passed.
  • python3 -B tests/startup_gfx2hlsl_sop2_complement_check.py: no MISMATCH.
  • Not run: the binary and decode modes (need llvm-mc / libLLVM), and the CMake/CTest registration.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6593640789 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2046). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T23:37:48Z. --- Part of #1723 What this unblocks: Run 21 scalar carry chains (`s_add_u32` + `s_addc_u32`, `s_sub_u32` + `s_subb_u32`), the 64-bit address and offset arithmetic shaders use. `gfx2hlsl` had no lowering for `s_addc_u32` and `s_subb_u32`, and `s_add_u32` / `s_sub_u32` left SCC at its old value, so a carry chain would have read a stale carry. All four now write the result and the carry or borrow. - `s_add_u32`: SCC = carry out of bit 31. - `s_sub_u32`: SCC = borrow (`S1 > S0`). - `s_addc_u32` / `s_subb_u32`: the old SCC is copied out first, then used for the result and for the new SCC. - SCC is computed before the destination is written, so a destination that is also a source still gets the right carry. - The uniformity proof follows the new SCC like any other compare result. - `s_addc_u32` and `s_subb_u32` on a lane mask (`exec`, `vcc`, an SGPR holding a compare result) are refused. Changes: - `tools/startup/gfx2hlsl.py`: carry table, lowering of the two carry-in forms, lane-mask refusal. - `tests/startup_gfx2hlsl_scalar_carry_check.py` (new, registered in `CMakeLists.txt`): runs the emitted lines over boundary value pairs with SCC clear and set, for every destination and source form, against a plain-integer reference. - `tests/startup_gfx2hlsl_readfirstlane_uniform_check.py`: the "unmodelled" case now uses `s_add_i32`; a new case checks a uniform `s_add_u32` carry keeps the proof. Verification: run locally on Linux (not on Win2025), from the repo root of the branch. - `python3 -B tests/startup_gfx2hlsl_scalar_carry_check.py`: PASS with the change. With `tools/startup/gfx2hlsl.py` from `origin/main`: FAIL (all 12 checks). - `python3 -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py`: 0 failed. - `python3 -B tests/startup_gfx2hlsl_scalar_m0_check.py`: passed. - `python3 -B tests/startup_gfx2hlsl_sop2_complement_check.py`: no MISMATCH. - Not run: the `binary` and `decode` modes (need llvm-mc / libLLVM), and the CMake/CTest registration. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-25 01:01:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:44:31Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b69122d8e2

ℹ️ 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:6049246288 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2046#pullrequestreview-6049246288). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:44:31Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `b69122d8e2` <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>
tedin7 commented 2026-11-25 01:01:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:58:56Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049924753 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2046#pullrequestreview-6049924753). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:58:56Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-25 01:01:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:58:58Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049924947 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2046#pullrequestreview-6049924947). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:58:58Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-25 01:01:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:59:00Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049925242 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2046#pullrequestreview-6049925242). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:59:00Z. **Review:** COMMENTED --- _No description provided._
chatgpt-codex-connector[bot commented 2026-11-25 01:01:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:37:57Z.


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-24T23:44:35.026009Z b69122d 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:7147620824 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2046#issuecomment-7147620824). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:37:57Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"b69122d8e248624f3f65b813eba07887d7b63bba","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-24T23:44:35.026009Z">2026-11-24T23:44:35.026009Z</relative-time> | `b69122d` | 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>
ChazY11 commented 2026-11-25 01:01:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T23:44:36Z.


Ran it, broke the four formulas five ways — all caught — and checked them against unbounded arithmetic (200k random cases)

out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_scalar_carry_check.py
PASS      exit 0
mutation result
s_add_u32: (a + b) < a → <= a caught
s_sub_u32: a < b → a <= b caught
s_addc_u32: the carry-in branch (a + b + 1u) <= a → < a caught
s_subb_u32: the borrow-in branch a <= b → a < b caught
s_addc/s_subb stop copying the old SCC into w caught

Every one of those is an off-by-one at exactly one boundary, so the fixture is testing the values that distinguish them rather than mid-range arithmetic.

The four expressions, checked against a reference that cannot wrap

I transcribed SCC_CARRY with HLSL's 32-bit wrapping and compared it with the same instructions computed in Python's unbounded integers, where
the carry is simply the bit above bit 31:

edge cases (0, 1, 2, 0x7fffffff, 0x80000000, 0xfffffffe, 0xffffffff, both SCC values):
  392 cases  mismatches: 0
random 32-bit operands:
  200000 cases  mismatches: 0

and a real carry chain, which is what the PR says it unblocks:

00000000ffffffff + 0000000000000001 = 0000000100000000   ok
7fffffffffffffff + 0000000000000001 = 8000000000000000   ok
0000000000000000 + 0000000000000001 = 0000000000000001   ok

The middle one crosses the sign bit without a signed overflow trip, and the first one carries out of the low word — both are cases a s_add_u32 that
left SCC stale would silently get wrong on the second half.

Two mistakes I made while checking, both mine

  1. First transcription compared unbounded sums: (a + b) < a in Python is false whenever a + b exceeds 32 bits, so it reported 63 false
    mismatches. The formula depends on the target language wrapping, and any test written in Python has to mask explicitly — which is precisely why
    your fixture needs a value checker rather than a textual one.
  2. Then I passed scc_in=True for s_add_u32/s_sub_u32, which have no carry input, producing 50 055 false mismatches out of 200 000. The
    scoping (SCC_CARRY_IN) is part of the spec, not incidental.

Both are recorded here because they are the two ways a reviewer of this PR can fool themselves, and neither is a defect in the patch.

What is not covered

SCC being written before the destination — the ordering claim in the description — is asserted by the fixture ("SCC is computed before the
destination is written"), and my mutations cannot distinguish ordering if the checker only compares final state. If the fixture compares a
destination that is also a source, that is the case that would catch a reordering; I could not confirm which side of that line it sits on from the
text output alone.

Notes

  • AI-assisted review.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7147744338 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2046#issuecomment-7147744338). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T23:44:36Z. --- ## Ran it, broke the four formulas five ways — all caught — and checked them against unbounded arithmetic (200k random cases) ```powershell out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_scalar_carry_check.py PASS exit 0 ``` | mutation | result | |---|---| | `s_add_u32`: `(a + b) < a` → `<= a` | **caught** | | `s_sub_u32`: `a < b` → `a <= b` | **caught** | | `s_addc_u32`: the carry-in branch `(a + b + 1u) <= a` → `< a` | **caught** | | `s_subb_u32`: the borrow-in branch `a <= b` → `a < b` | **caught** | | `s_addc`/`s_subb` stop copying the old SCC into `w` | **caught** | Every one of those is an off-by-one at exactly one boundary, so the fixture is testing the values that distinguish them rather than mid-range arithmetic. ## The four expressions, checked against a reference that cannot wrap I transcribed `SCC_CARRY` with HLSL's 32-bit wrapping and compared it with the same instructions computed in Python's unbounded integers, where the carry is simply the bit above bit 31: ```text edge cases (0, 1, 2, 0x7fffffff, 0x80000000, 0xfffffffe, 0xffffffff, both SCC values): 392 cases mismatches: 0 random 32-bit operands: 200000 cases mismatches: 0 ``` and a real carry chain, which is what the PR says it unblocks: ```text 00000000ffffffff + 0000000000000001 = 0000000100000000 ok 7fffffffffffffff + 0000000000000001 = 8000000000000000 ok 0000000000000000 + 0000000000000001 = 0000000000000001 ok ``` The middle one crosses the sign bit without a signed overflow trip, and the first one carries out of the low word — both are cases a `s_add_u32` that left SCC stale would silently get wrong on the second half. ## Two mistakes I made while checking, both mine 1. **First transcription compared unbounded sums**: `(a + b) < a` in Python is false whenever `a + b` exceeds 32 bits, so it reported 63 false mismatches. The formula depends on the target language wrapping, and any test written in Python has to mask explicitly — which is precisely why your fixture needs a value checker rather than a textual one. 2. **Then I passed `scc_in=True` for `s_add_u32`/`s_sub_u32`**, which have no carry input, producing 50 055 false mismatches out of 200 000. The scoping (`SCC_CARRY_IN`) is part of the spec, not incidental. Both are recorded here because they are the two ways a reviewer of this PR can fool themselves, and neither is a defect in the patch. ## What is not covered SCC being written *before* the destination — the ordering claim in the description — is asserted by the fixture ("SCC is computed before the destination is written"), and my mutations cannot distinguish ordering if the checker only compares final state. If the fixture compares a destination that is also a source, that is the case that would catch a reordering; I could not confirm which side of that line it sits on from the text output alone. ## Notes - AI-assisted review.
chatgpt-codex-connector[bot commented 2026-11-25 01:02:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:44:31Z.

Code review location: tools/startup/gfx2hlsl.py; line 1897

@@ -1874,6 +1894,7 @@ def declarations(self):
     's_lshl_b32': ('{0} << ({1} & 31)', '$ != 0'), 's_lshr_b32': ('{0} >> ({1} & 31)', '$ != 0'),
     's_ashr_i32': ('uint(int({0}) >> ({1} & 31))', '$ != 0'),
     's_add_i32': ('{0} + {1}', None), 's_add_u32': ('{0} + {1}', None), 's_sub_i32': ('{0} - {1}', None), 's_sub_u32': ('{0} - {1}', None),
+    's_addc_u32': ('{0} + {1} + w', None), 's_subb_u32': ('{0} - {1} - w', None),

P1 Badge Propagate carry-in uniformity to the scalar result

When the incoming SCC depends on a lane mask, saving it in w hides that dependency from scalar_expr_uniform(), which does not inspect w. For example, after s_cmp_eq_u32 vcc_lo, 0, s_addc_u32 s3, 0, 0 marks s3 uniform even though its emitted value can differ across lanes. A subsequent move to a VGPR followed by v_readfirstlane_b32 is then incorrectly accepted as a per-lane copy: a synthetic two-lane evaluation produces [0, 1] instead of the broadcast [0, 0]. Preserve the incoming SCC's uniformity when classifying the destination of both carry-in operations.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688132382 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2046#discussion_r4688132382). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:44:31Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 1897 ~~~~diff @@ -1874,6 +1894,7 @@ def declarations(self): 's_lshl_b32': ('{0} << ({1} & 31)', '$ != 0'), 's_lshr_b32': ('{0} >> ({1} & 31)', '$ != 0'), 's_ashr_i32': ('uint(int({0}) >> ({1} & 31))', '$ != 0'), 's_add_i32': ('{0} + {1}', None), 's_add_u32': ('{0} + {1}', None), 's_sub_i32': ('{0} - {1}', None), 's_sub_u32': ('{0} - {1}', None), + 's_addc_u32': ('{0} + {1} + w', None), 's_subb_u32': ('{0} - {1} - w', None), ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Propagate carry-in uniformity to the scalar result** When the incoming SCC depends on a lane mask, saving it in `w` hides that dependency from `scalar_expr_uniform()`, which does not inspect `w`. For example, after `s_cmp_eq_u32 vcc_lo, 0`, `s_addc_u32 s3, 0, 0` marks `s3` uniform even though its emitted value can differ across lanes. A subsequent move to a VGPR followed by `v_readfirstlane_b32` is then incorrectly accepted as a per-lane copy: a synthetic two-lane evaluation produces `[0, 1]` instead of the broadcast `[0, 0]`. Preserve the incoming SCC's uniformity when classifying the destination of both carry-in operations. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-25 01:02:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:44:31Z.

Code review location: tools/startup/gfx2hlsl.py; line 1874

@@ -1860,8 +1871,17 @@ def declarations(self):
 # Scalar ops that write SCC on the hardware (carry, overflow, or which source was selected) but have
 # no SCC template here: the emitted scc keeps its previous value, so the uniformity proof stops
 # trusting it.
-SCC_UNMODELLED = frozenset(('s_add_i32', 's_add_u32', 's_sub_i32', 's_sub_u32',
+SCC_UNMODELLED = frozenset(('s_add_i32', 's_add_u32', 's_sub_i32', 's_sub_u32', 's_addc_u32', 's_subb_u32',

P2 Badge Remove modeled carry-in operations from SCC_UNMODELLED

With uniform operands and a uniform incoming SCC, these entries make scalar() clear scc_uniform before calculating the newly modeled carry. Since both carry-in SCC expressions themselves reference scc, set_scc() can never restore the proof. Consequently, a fully uniform s_add_u32 → s_addc_u32 → s_cselect_b32 → vector move → v_readfirstlane_b32 chain is refused with requires a proven uniform source. Removing the carry-in opcodes from this invalidation makes that same synthetic chain pass; their incoming SCC proof needs to survive until the new dependency calculation.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688132391 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2046#discussion_r4688132391). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:44:31Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 1874 ~~~~diff @@ -1860,8 +1871,17 @@ def declarations(self): # Scalar ops that write SCC on the hardware (carry, overflow, or which source was selected) but have # no SCC template here: the emitted scc keeps its previous value, so the uniformity proof stops # trusting it. -SCC_UNMODELLED = frozenset(('s_add_i32', 's_add_u32', 's_sub_i32', 's_sub_u32', +SCC_UNMODELLED = frozenset(('s_add_i32', 's_add_u32', 's_sub_i32', 's_sub_u32', 's_addc_u32', 's_subb_u32', ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Remove modeled carry-in operations from SCC_UNMODELLED** With uniform operands and a uniform incoming SCC, these entries make `scalar()` clear `scc_uniform` before calculating the newly modeled carry. Since both carry-in SCC expressions themselves reference `scc`, `set_scc()` can never restore the proof. Consequently, a fully uniform `s_add_u32` → `s_addc_u32` → `s_cselect_b32` → vector move → `v_readfirstlane_b32` chain is refused with `requires a proven uniform source`. Removing the carry-in opcodes from this invalidation makes that same synthetic chain pass; their incoming SCC proof needs to survive until the new dependency calculation. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-25 01:02:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:44:31Z.

Code review location: CMakeLists.txt; line 2221

@@ -2216,6 +2216,9 @@ if(EXISTS "${INTAKE_PYTHON}")
     # 32-bit scalar complement logic: s_nand_b32, s_nor_b32 and s_xnor_b32 against an integer reference (#1919).
     add_test(NAME startup_gfx2hlsl_sop2_complement COMMAND "${INTAKE_PYTHON}" -B
         "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_sop2_complement_check.py")
+    # s_add_u32, s_sub_u32, s_addc_u32 and s_subb_u32 result and SCC carry against a reference (#1723).
+    add_test(NAME startup_gfx2hlsl_scalar_carry COMMAND "${INTAKE_PYTHON}" -B
+        "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_scalar_carry_check.py")

P1 Badge Document the new scalar carry capability and reproduction check

This changes the startup translator's supported instructions and SCC behavior, but neither the README nor docs/experiments.md is updated, contrary to the capability-change requirement in the root AGENTS.md. In particular, docs/experiments.md:11644 still describes s_add and s_sub SCC results as unmodeled, contradicting the new unsigned lowering. Update the relevant experiment notes with the supported carry operations, lane-mask limitations, and the new fixture's reproduction command and measured scope.

AGENTS.md reference: AGENTS.md:L211-L212

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688132396 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2046#discussion_r4688132396). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:44:31Z. **Code review location:** `CMakeLists.txt`; line 2221 ~~~~diff @@ -2216,6 +2216,9 @@ if(EXISTS "${INTAKE_PYTHON}") # 32-bit scalar complement logic: s_nand_b32, s_nor_b32 and s_xnor_b32 against an integer reference (#1919). add_test(NAME startup_gfx2hlsl_sop2_complement COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_sop2_complement_check.py") + # s_add_u32, s_sub_u32, s_addc_u32 and s_subb_u32 result and SCC carry against a reference (#1723). + add_test(NAME startup_gfx2hlsl_scalar_carry COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_scalar_carry_check.py") ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Document the new scalar carry capability and reproduction check** This changes the startup translator's supported instructions and SCC behavior, but neither the README nor `docs/experiments.md` is updated, contrary to the capability-change requirement in the root `AGENTS.md`. In particular, `docs/experiments.md:11644` still describes `s_add` and `s_sub` SCC results as unmodeled, contradicting the new unsigned lowering. Update the relevant experiment notes with the supported carry operations, lane-mask limitations, and the new fixture's reproduction command and measured scope. AGENTS.md reference: [AGENTS.md:L211-L212](https://github.com/R0Y00/Xbox2Windows/blob/b69122d8e248624f3f65b813eba07887d7b63bba/AGENTS.md#L211-L212) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-25 01:02:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:58:56Z.

Code review location: tools/startup/gfx2hlsl.py; line 1897

@@ -1874,6 +1894,7 @@ def declarations(self):
     's_lshl_b32': ('{0} << ({1} & 31)', '$ != 0'), 's_lshr_b32': ('{0} >> ({1} & 31)', '$ != 0'),
     's_ashr_i32': ('uint(int({0}) >> ({1} & 31))', '$ != 0'),
     's_add_i32': ('{0} + {1}', None), 's_add_u32': ('{0} + {1}', None), 's_sub_i32': ('{0} - {1}', None), 's_sub_u32': ('{0} - {1}', None),
+    's_addc_u32': ('{0} + {1} + w', None), 's_subb_u32': ('{0} - {1} - w', None),

Fixed in 0365acaa (pending push): the incoming SCC uniformity is saved before the carry write and applied to the s_addc_u32/s_subb_u32 result, so the lane-mask case is refused at v_readfirstlane_b32. Test added in startup_gfx2hlsl_readfirstlane_uniform_check.py. AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688741724 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2046#discussion_r4688741724). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:58:56Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 1897 ~~~~diff @@ -1874,6 +1894,7 @@ def declarations(self): 's_lshl_b32': ('{0} << ({1} & 31)', '$ != 0'), 's_lshr_b32': ('{0} >> ({1} & 31)', '$ != 0'), 's_ashr_i32': ('uint(int({0}) >> ({1} & 31))', '$ != 0'), 's_add_i32': ('{0} + {1}', None), 's_add_u32': ('{0} + {1}', None), 's_sub_i32': ('{0} - {1}', None), 's_sub_u32': ('{0} - {1}', None), + 's_addc_u32': ('{0} + {1} + w', None), 's_subb_u32': ('{0} - {1} - w', None), ~~~~ --- Fixed in 0365acaa (pending push): the incoming SCC uniformity is saved before the carry write and applied to the s_addc_u32/s_subb_u32 result, so the lane-mask case is refused at v_readfirstlane_b32. Test added in startup_gfx2hlsl_readfirstlane_uniform_check.py. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 01:02:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:58:58Z.

Code review location: tools/startup/gfx2hlsl.py; line 1874

@@ -1860,8 +1871,17 @@ def declarations(self):
 # Scalar ops that write SCC on the hardware (carry, overflow, or which source was selected) but have
 # no SCC template here: the emitted scc keeps its previous value, so the uniformity proof stops
 # trusting it.
-SCC_UNMODELLED = frozenset(('s_add_i32', 's_add_u32', 's_sub_i32', 's_sub_u32',
+SCC_UNMODELLED = frozenset(('s_add_i32', 's_add_u32', 's_sub_i32', 's_sub_u32', 's_addc_u32', 's_subb_u32',

Fixed in 0365acaa (pending push): s_addc_u32 and s_subb_u32 are removed from SCC_UNMODELLED; a uniform s_add_u32 -> s_addc_u32 -> s_cselect_b32 chain now passes (test added). AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688741944 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2046#discussion_r4688741944). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:58:58Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 1874 ~~~~diff @@ -1860,8 +1871,17 @@ def declarations(self): # Scalar ops that write SCC on the hardware (carry, overflow, or which source was selected) but have # no SCC template here: the emitted scc keeps its previous value, so the uniformity proof stops # trusting it. -SCC_UNMODELLED = frozenset(('s_add_i32', 's_add_u32', 's_sub_i32', 's_sub_u32', +SCC_UNMODELLED = frozenset(('s_add_i32', 's_add_u32', 's_sub_i32', 's_sub_u32', 's_addc_u32', 's_subb_u32', ~~~~ --- Fixed in 0365acaa (pending push): s_addc_u32 and s_subb_u32 are removed from SCC_UNMODELLED; a uniform s_add_u32 -> s_addc_u32 -> s_cselect_b32 chain now passes (test added). AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 01:02:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:59:00Z.

Code review location: CMakeLists.txt; line 2221

@@ -2216,6 +2216,9 @@ if(EXISTS "${INTAKE_PYTHON}")
     # 32-bit scalar complement logic: s_nand_b32, s_nor_b32 and s_xnor_b32 against an integer reference (#1919).
     add_test(NAME startup_gfx2hlsl_sop2_complement COMMAND "${INTAKE_PYTHON}" -B
         "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_sop2_complement_check.py")
+    # s_add_u32, s_sub_u32, s_addc_u32 and s_subb_u32 result and SCC carry against a reference (#1723).
+    add_test(NAME startup_gfx2hlsl_scalar_carry COMMAND "${INTAKE_PYTHON}" -B
+        "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_scalar_carry_check.py")

Fixed in 0365acaa (pending push): docs/experiments.md now lists the carry-in forms, the lane-mask refusal and the reproduction command (ctest -R startup_gfx2hlsl_scalar_carry). AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688742226 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2046#discussion_r4688742226). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:59:00Z. **Code review location:** `CMakeLists.txt`; line 2221 ~~~~diff @@ -2216,6 +2216,9 @@ if(EXISTS "${INTAKE_PYTHON}") # 32-bit scalar complement logic: s_nand_b32, s_nor_b32 and s_xnor_b32 against an integer reference (#1919). add_test(NAME startup_gfx2hlsl_sop2_complement COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_sop2_complement_check.py") + # s_add_u32, s_sub_u32, s_addc_u32 and s_subb_u32 result and SCC carry against a reference (#1723). + add_test(NAME startup_gfx2hlsl_scalar_carry COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_scalar_carry_check.py") ~~~~ --- Fixed in 0365acaa (pending push): docs/experiments.md now lists the carry-in forms, the lane-mask refusal and the reproduction command (ctest -R startup_gfx2hlsl_scalar_carry). AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 12:01:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:54:41Z.


Thank you @ChazY11 for the run at d58e1d84: five mutations caught and the four formulas checked against unbounded arithmetic over 200k random cases. Recorded as extra evidence for this PR.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7161668186 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2046#issuecomment-7161668186). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T11:54:41Z. --- Thank you @ChazY11 for the run at `d58e1d84`: five mutations caught and the four formulas checked against unbounded arithmetic over 200k random cases. Recorded as extra evidence for this PR. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 14:04:32 +00:00
tedin7 commented 2026-11-25 14:05:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:51:55Z.


Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is.

We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7164402241 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2046#issuecomment-7164402241). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T13:51:55Z. --- Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is. We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here. AI-assisted; commands listed were executed locally.

Pull request closed

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!2039
No description provided.