shader: lower v_sub_co_ci_u32, v_subrev_co_ci_u32 and s_flbit_i32_b32 in gfx2hlsl (Part of #1723) #2034

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

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


Part of #1723

What this unblocks: Run 21 census, the predicted RDNA2 twins v_sub_co_ci_u32, v_subrev_co_ci_u32 and s_flbit_i32_b32.

Branch: x2w-r21-scalar-twins-b (commit e64b04fa, local, not pushed).

Changes in tools/startup/gfx2hlsl.py:

  • v_sub_co_ci_u32: D = S0 - S1 - carry_in, borrow out S0 < S1 + carry_in, written to vcc or an SGPR mask (bit 0, one lane).
  • v_subrev_co_ci_u32: same with S0 and S1 swapped.
  • Both refuse modifiers, a wrong operand count, a non-VGPR destination and a carry-in SGPR that is not a known mask.
  • s_flbit_i32_b32: S0 == 0u ? 0xffffffffu : 31u - firstbithigh(S0), SCC unchanged. Word-only: lane masks are refused, as for s_pack_hh_b32_b16.

Verification:

  • python3 -I tests/startup_gfx2hlsl_sub_co_ci_flbit_check.py -> PASS (new test, registered in CMakeLists.txt as startup_gfx2hlsl_sub_co_ci_flbit).
  • Same test against origin/main tools -> fails with Unsupported: v_sub_co_ci_u32.
  • python3 -I tests/startup_gfx2hlsl_sop2_complement_check.py -> PASS
  • python3 -I tests/startup_gfx2hlsl_vcvt_omod_check.py -> PASS
  • python3 -I tests/startup_gfx2hlsl_bit_alu_check.py -> all lines ok
  • Checked before starting: no v_sub_co_ci, v_subrev_co_ci or s_flbit in tools/startup/ on main.
  • Not run: Win2025 build and CTest (this host is Linux, Python tests only).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6593566379 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2041). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T23:32:26Z. --- Part of #1723 What this unblocks: Run 21 census, the predicted RDNA2 twins `v_sub_co_ci_u32`, `v_subrev_co_ci_u32` and `s_flbit_i32_b32`. Branch: `x2w-r21-scalar-twins-b` (commit e64b04fa, local, not pushed). Changes in `tools/startup/gfx2hlsl.py`: - `v_sub_co_ci_u32`: `D = S0 - S1 - carry_in`, borrow out `S0 < S1 + carry_in`, written to vcc or an SGPR mask (bit 0, one lane). - `v_subrev_co_ci_u32`: same with S0 and S1 swapped. - Both refuse modifiers, a wrong operand count, a non-VGPR destination and a carry-in SGPR that is not a known mask. - `s_flbit_i32_b32`: `S0 == 0u ? 0xffffffffu : 31u - firstbithigh(S0)`, SCC unchanged. Word-only: lane masks are refused, as for `s_pack_hh_b32_b16`. Verification: - `python3 -I tests/startup_gfx2hlsl_sub_co_ci_flbit_check.py` -> PASS (new test, registered in CMakeLists.txt as `startup_gfx2hlsl_sub_co_ci_flbit`). - Same test against `origin/main` tools -> fails with `Unsupported: v_sub_co_ci_u32`. - `python3 -I tests/startup_gfx2hlsl_sop2_complement_check.py` -> PASS - `python3 -I tests/startup_gfx2hlsl_vcvt_omod_check.py` -> PASS - `python3 -I tests/startup_gfx2hlsl_bit_alu_check.py` -> all lines ok - Checked before starting: no `v_sub_co_ci`, `v_subrev_co_ci` or `s_flbit` in `tools/startup/` on main. - Not run: Win2025 build and CTest (this host is Linux, Python tests only). AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-25 00:05:06 +00:00 (Migrated from github.com)

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

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e64b04fa4b

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

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

Review: COMMENTED


No description provided.

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

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

Review: COMMENTED


No description provided.

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

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


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:38:18.499370Z e64b04f 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:7147518929 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2041#issuecomment-7147518929). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:32:37Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"e64b04fa4b9f4023f1aa7a26891532b828e8b011","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:38:18.499370Z">2026-11-24T23:38:18.499370Z</relative-time> | `e64b04f` | 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>
chatgpt-codex-connector[bot commented 2026-11-25 01:02:12 +00:00 (Migrated from github.com)

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

Code review location: CMakeLists.txt; line 2187

@@ -2183,6 +2183,8 @@ 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")
+    add_test(NAME startup_gfx2hlsl_sub_co_ci_flbit COMMAND "${INTAKE_PYTHON}" -B
+        "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_sub_co_ci_flbit_check.py")

P1 Badge Document the new startup translation capability

This adds three previously refused startup-translator instruction forms and a new reproduction test, but neither README.md nor docs/experiments.md is updated. AGENTS.md explicitly requires updating one of those documents when a public capability or reproduction command changes. Record the supported forms, refusal boundaries, and regression command, distinguishing the CPU-only verification from unmeasured Windows/GPU behavior.

AGENTS.md reference: AGENTS.md:L210-L211

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688065451 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2041#discussion_r4688065451). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:38:15Z. **Code review location:** `CMakeLists.txt`; line 2187 ~~~~diff @@ -2183,6 +2183,8 @@ 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") + add_test(NAME startup_gfx2hlsl_sub_co_ci_flbit COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_sub_co_ci_flbit_check.py") ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Document the new startup translation capability** This adds three previously refused startup-translator instruction forms and a new reproduction test, but neither `README.md` nor `docs/experiments.md` is updated. `AGENTS.md` explicitly requires updating one of those documents when a public capability or reproduction command changes. Record the supported forms, refusal boundaries, and regression command, distinguishing the CPU-only verification from unmeasured Windows/GPU behavior. AGENTS.md reference: [AGENTS.md:L210-L211](https://github.com/R0Y00/Xbox2Windows/blob/e64b04fa4b9f4023f1aa7a26891532b828e8b011/AGENTS.md#L210-L211) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-25 01:02:12 +00:00 (Migrated from github.com)

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

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

@@ -777,6 +777,54 @@ def src_sym(t):
             self.set_s(d + 1, self.S(r[2]) if r and r[1] != r[2] else '0u')
         return None
 
+    def borrow_mask(self, tok, op, what):
+        """('vcc', None) or ('s', n) for a one-lane borrow mask operand; anything else is refused."""
+        if tok in ('vcc', 'vcc_lo'):
+            return 'vcc', None
+        r = reg_range(tok)
+        if r and r[0] == 's' and r[1] <= r[2] <= r[1] + 1 and r[1] not in (106, 107):
+            return 's', r[1]
+        raise Unsupported('%s %s %s: expected vcc or an SGPR mask' % (op, what, tok))
+
+    def sub_co_ci(self, op, ops, mods, reverse):
+        # d = a - b - borrow_in (subrev: b - a - borrow_in); the borrow out is bit 0 of the destination mask.
+        if mods:
+            raise Unsupported('%s with %s' % (op, mods))
+        if len(ops) != 5:
+            raise Unsupported('%s with %d operands, expected 5' % (op, len(ops)))
+        regs = reg_range(ops[0])
+        if not regs or regs[0] != 'v' or regs[1] != regs[2] or regs[1] > 255:
+            raise Unsupported('%s destination %s: expected a single VGPR' % (op, ops[0]))
+        out_kind, out_n = self.borrow_mask(ops[1], op, 'borrow out')
+        in_kind, in_n = self.borrow_mask(ops[4], op, 'borrow in')
+        if in_kind == 's' and in_n not in self.masks:
+            raise Unsupported('%s borrow in s%d is not a known mask' % (op, in_n))
+        borrow_in = self.u(ops[4]) if in_kind == 'vcc' else self.S(in_n)
+        a, b = self.u(ops[2]), self.u(ops[3])
+        if reverse:
+            a, b = b, a
+        d = regs[1]
+        self.uniform_v.discard(d)
+        self.used_v.add(d)
+        guard = '' if self.exec_known else 'if (exec & 1) '
+        borrow = '(ca < cb || ca - cb < ci) ? 1u : 0u'
+        if not self.exec_known:
+            borrow = '(exec & %s)' % borrow
+        if out_kind == 'vcc':
+            store = 'vcc = %s;' % borrow
+        else:
+            self.used_s.add(out_n)
+            self.sym.pop(out_n, None)
+            self.masks.add(out_n)
+            store = 's%d = %s;' % (out_n, borrow)
+        self.emit('{ uint ca = %s, cb = %s, ci = %s & 1u; %sv%d = ca - cb - ci; %s }' % (a, b, borrow_in, guard, d, store))

P2 Badge Expose the VGPR write to the fetch definite-assignment check

For vertex shaders that start with the modeled fetch call, Pipeline.hlsl_vs() recognizes definitions only when an emitted line starts with vN =. This block-form line instead makes that scan count the destination as a read, so an unconditional subtraction into a fresh VGPR is incorrectly refused. Using the existing stream-fetch fixture, v_sub_co_ci_u32_e32 v12, vcc_lo, v4, v5, vcc_lo fails with vertex stage reads v12 even though both inputs are fetched; initializing v12 beforehand makes it translate. The reverse form fails identically. Update the definition tracking to recognize these writes while preserving the temporary snapshots needed for aliasing.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688065461 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2041#discussion_r4688065461). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:38:15Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 820 ~~~~diff @@ -777,6 +777,54 @@ def src_sym(t): self.set_s(d + 1, self.S(r[2]) if r and r[1] != r[2] else '0u') return None + def borrow_mask(self, tok, op, what): + """('vcc', None) or ('s', n) for a one-lane borrow mask operand; anything else is refused.""" + if tok in ('vcc', 'vcc_lo'): + return 'vcc', None + r = reg_range(tok) + if r and r[0] == 's' and r[1] <= r[2] <= r[1] + 1 and r[1] not in (106, 107): + return 's', r[1] + raise Unsupported('%s %s %s: expected vcc or an SGPR mask' % (op, what, tok)) + + def sub_co_ci(self, op, ops, mods, reverse): + # d = a - b - borrow_in (subrev: b - a - borrow_in); the borrow out is bit 0 of the destination mask. + if mods: + raise Unsupported('%s with %s' % (op, mods)) + if len(ops) != 5: + raise Unsupported('%s with %d operands, expected 5' % (op, len(ops))) + regs = reg_range(ops[0]) + if not regs or regs[0] != 'v' or regs[1] != regs[2] or regs[1] > 255: + raise Unsupported('%s destination %s: expected a single VGPR' % (op, ops[0])) + out_kind, out_n = self.borrow_mask(ops[1], op, 'borrow out') + in_kind, in_n = self.borrow_mask(ops[4], op, 'borrow in') + if in_kind == 's' and in_n not in self.masks: + raise Unsupported('%s borrow in s%d is not a known mask' % (op, in_n)) + borrow_in = self.u(ops[4]) if in_kind == 'vcc' else self.S(in_n) + a, b = self.u(ops[2]), self.u(ops[3]) + if reverse: + a, b = b, a + d = regs[1] + self.uniform_v.discard(d) + self.used_v.add(d) + guard = '' if self.exec_known else 'if (exec & 1) ' + borrow = '(ca < cb || ca - cb < ci) ? 1u : 0u' + if not self.exec_known: + borrow = '(exec & %s)' % borrow + if out_kind == 'vcc': + store = 'vcc = %s;' % borrow + else: + self.used_s.add(out_n) + self.sym.pop(out_n, None) + self.masks.add(out_n) + store = 's%d = %s;' % (out_n, borrow) + self.emit('{ uint ca = %s, cb = %s, ci = %s & 1u; %sv%d = ca - cb - ci; %s }' % (a, b, borrow_in, guard, d, store)) ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Expose the VGPR write to the fetch definite-assignment check** For vertex shaders that start with the modeled fetch call, `Pipeline.hlsl_vs()` recognizes definitions only when an emitted line starts with `vN =`. This block-form line instead makes that scan count the destination as a read, so an unconditional subtraction into a fresh VGPR is incorrectly refused. Using the existing stream-fetch fixture, `v_sub_co_ci_u32_e32 v12, vcc_lo, v4, v5, vcc_lo` fails with `vertex stage reads v12` even though both inputs are fetched; initializing `v12` beforehand makes it translate. The reverse form fails identically. Update the definition tracking to recognize these writes while preserving the temporary snapshots needed for aliasing. 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:59:07Z.

Code review location: CMakeLists.txt; line 2187

@@ -2183,6 +2183,8 @@ 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")
+    add_test(NAME startup_gfx2hlsl_sub_co_ci_flbit COMMAND "${INTAKE_PYTHON}" -B
+        "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_sub_co_ci_flbit_check.py")

Fixed in 00544511 (rebased on current main, pending push to this branch). Docs: new section in docs/experiments.md, plus the check in AGENTS.md and the CI list. Definite-assignment: the borrow-chain block now counts as an unconditional write of its destination, with a translator case in tests/startup_stream_fetch_check.py. CPU-only; Windows/GPU behavior not measured.

AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_sub_co_ci_flbit_check.py, tests/startup_stream_fetch_check.py, tests/startup_translator_check.py, tests/docs_links_check.py.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688743106 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2041#discussion_r4688743106). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:59:07Z. **Code review location:** `CMakeLists.txt`; line 2187 ~~~~diff @@ -2183,6 +2183,8 @@ 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") + add_test(NAME startup_gfx2hlsl_sub_co_ci_flbit COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_sub_co_ci_flbit_check.py") ~~~~ --- Fixed in 00544511 (rebased on current main, pending push to this branch). Docs: new section in docs/experiments.md, plus the check in AGENTS.md and the CI list. Definite-assignment: the borrow-chain block now counts as an unconditional write of its destination, with a translator case in tests/startup_stream_fetch_check.py. CPU-only; Windows/GPU behavior not measured. AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_sub_co_ci_flbit_check.py, tests/startup_stream_fetch_check.py, tests/startup_translator_check.py, tests/docs_links_check.py.
tedin7 commented 2026-11-25 01:02:20 +00:00 (Migrated from github.com)

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

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

@@ -777,6 +777,54 @@ def src_sym(t):
             self.set_s(d + 1, self.S(r[2]) if r and r[1] != r[2] else '0u')
         return None
 
+    def borrow_mask(self, tok, op, what):
+        """('vcc', None) or ('s', n) for a one-lane borrow mask operand; anything else is refused."""
+        if tok in ('vcc', 'vcc_lo'):
+            return 'vcc', None
+        r = reg_range(tok)
+        if r and r[0] == 's' and r[1] <= r[2] <= r[1] + 1 and r[1] not in (106, 107):
+            return 's', r[1]
+        raise Unsupported('%s %s %s: expected vcc or an SGPR mask' % (op, what, tok))
+
+    def sub_co_ci(self, op, ops, mods, reverse):
+        # d = a - b - borrow_in (subrev: b - a - borrow_in); the borrow out is bit 0 of the destination mask.
+        if mods:
+            raise Unsupported('%s with %s' % (op, mods))
+        if len(ops) != 5:
+            raise Unsupported('%s with %d operands, expected 5' % (op, len(ops)))
+        regs = reg_range(ops[0])
+        if not regs or regs[0] != 'v' or regs[1] != regs[2] or regs[1] > 255:
+            raise Unsupported('%s destination %s: expected a single VGPR' % (op, ops[0]))
+        out_kind, out_n = self.borrow_mask(ops[1], op, 'borrow out')
+        in_kind, in_n = self.borrow_mask(ops[4], op, 'borrow in')
+        if in_kind == 's' and in_n not in self.masks:
+            raise Unsupported('%s borrow in s%d is not a known mask' % (op, in_n))
+        borrow_in = self.u(ops[4]) if in_kind == 'vcc' else self.S(in_n)
+        a, b = self.u(ops[2]), self.u(ops[3])
+        if reverse:
+            a, b = b, a
+        d = regs[1]
+        self.uniform_v.discard(d)
+        self.used_v.add(d)
+        guard = '' if self.exec_known else 'if (exec & 1) '
+        borrow = '(ca < cb || ca - cb < ci) ? 1u : 0u'
+        if not self.exec_known:
+            borrow = '(exec & %s)' % borrow
+        if out_kind == 'vcc':
+            store = 'vcc = %s;' % borrow
+        else:
+            self.used_s.add(out_n)
+            self.sym.pop(out_n, None)
+            self.masks.add(out_n)
+            store = 's%d = %s;' % (out_n, borrow)
+        self.emit('{ uint ca = %s, cb = %s, ci = %s & 1u; %sv%d = ca - cb - ci; %s }' % (a, b, borrow_in, guard, d, store))

Fixed in 00544511 (rebased on current main, pending push to this branch). Docs: new section in docs/experiments.md, plus the check in AGENTS.md and the CI list. Definite-assignment: the borrow-chain block now counts as an unconditional write of its destination, with a translator case in tests/startup_stream_fetch_check.py. CPU-only; Windows/GPU behavior not measured.

AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_sub_co_ci_flbit_check.py, tests/startup_stream_fetch_check.py, tests/startup_translator_check.py, tests/docs_links_check.py.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688743365 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2041#discussion_r4688743365). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:59:10Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 820 ~~~~diff @@ -777,6 +777,54 @@ def src_sym(t): self.set_s(d + 1, self.S(r[2]) if r and r[1] != r[2] else '0u') return None + def borrow_mask(self, tok, op, what): + """('vcc', None) or ('s', n) for a one-lane borrow mask operand; anything else is refused.""" + if tok in ('vcc', 'vcc_lo'): + return 'vcc', None + r = reg_range(tok) + if r and r[0] == 's' and r[1] <= r[2] <= r[1] + 1 and r[1] not in (106, 107): + return 's', r[1] + raise Unsupported('%s %s %s: expected vcc or an SGPR mask' % (op, what, tok)) + + def sub_co_ci(self, op, ops, mods, reverse): + # d = a - b - borrow_in (subrev: b - a - borrow_in); the borrow out is bit 0 of the destination mask. + if mods: + raise Unsupported('%s with %s' % (op, mods)) + if len(ops) != 5: + raise Unsupported('%s with %d operands, expected 5' % (op, len(ops))) + regs = reg_range(ops[0]) + if not regs or regs[0] != 'v' or regs[1] != regs[2] or regs[1] > 255: + raise Unsupported('%s destination %s: expected a single VGPR' % (op, ops[0])) + out_kind, out_n = self.borrow_mask(ops[1], op, 'borrow out') + in_kind, in_n = self.borrow_mask(ops[4], op, 'borrow in') + if in_kind == 's' and in_n not in self.masks: + raise Unsupported('%s borrow in s%d is not a known mask' % (op, in_n)) + borrow_in = self.u(ops[4]) if in_kind == 'vcc' else self.S(in_n) + a, b = self.u(ops[2]), self.u(ops[3]) + if reverse: + a, b = b, a + d = regs[1] + self.uniform_v.discard(d) + self.used_v.add(d) + guard = '' if self.exec_known else 'if (exec & 1) ' + borrow = '(ca < cb || ca - cb < ci) ? 1u : 0u' + if not self.exec_known: + borrow = '(exec & %s)' % borrow + if out_kind == 'vcc': + store = 'vcc = %s;' % borrow + else: + self.used_s.add(out_n) + self.sym.pop(out_n, None) + self.masks.add(out_n) + store = 's%d = %s;' % (out_n, borrow) + self.emit('{ uint ca = %s, cb = %s, ci = %s & 1u; %sv%d = ca - cb - ci; %s }' % (a, b, borrow_in, guard, d, store)) ~~~~ --- Fixed in 00544511 (rebased on current main, pending push to this branch). Docs: new section in docs/experiments.md, plus the check in AGENTS.md and the CI list. Definite-assignment: the borrow-chain block now counts as an unconditional write of its destination, with a translator case in tests/startup_stream_fetch_check.py. CPU-only; Windows/GPU behavior not measured. AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_sub_co_ci_flbit_check.py, tests/startup_stream_fetch_check.py, tests/startup_translator_check.py, tests/docs_links_check.py.
upstream-sync closed this pull request 2026-11-25 14:04:31 +00:00
tedin7 commented 2026-11-25 14:05:12 +00:00 (Migrated from github.com)

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


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:7164374142 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2041#issuecomment-7164374142). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T13:50:45Z. --- 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!2034
No description provided.