shader: lower s_sext_i32_i8/i16, s_cmov_b32/b64 and s_cmovk_i32 in gfx2hlsl (Part of #1723) #2064

Merged
tedin7 merged 5 commits from upstream-pr/2071 into main 2026-11-25 01:57:23 +00:00
tedin7 commented 2026-11-25 00:01:10 +00:00 (Migrated from github.com)

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


Part of #1723

What this unblocks: batch 3 item #2, five scalar opcodes (s_sext_i32_i8, s_sext_i32_i16, s_cmov_b32, s_cmov_b64, s_cmovk_i32) that startup shaders hit and gfx2hlsl refused.

s_sext_i32_i8/i16 sign-extend the low 8/16 bits and set SCC to result != 0. s_cmov_b32/b64 and s_cmovk_i32 write SCC ? source : old destination and leave SCC alone; s_cmovk_i32 sign-extends its 16-bit immediate. Lane-mask operands, m0/exec/vcc destinations and the discard destination are refused.

Verification:

  • python3 -B tests/startup_gfx2hlsl_s_sext_cmov_check.py -> all ok (on origin/main the same test fails with AssertionError: refused: s_sext_i32_i8)
  • python3 -B tests/startup_gfx2hlsl_s_lshl_add_check.py -> exit 0
  • python3 -B tests/startup_gfx2hlsl_bit_alu_check.py -> exit 0
  • python3 -B tests/startup_gfx2hlsl_op_refusals_check.py -> exit 0
  • python3 -B tests/startup_gfx2hlsl_refusals_check.py -> exit 0
  • Not run: a Win2025 build; the change is Python only and registered as startup_gfx2hlsl_s_sext_cmov in CMakeLists.txt.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6593953210 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2071). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:01:10Z. --- Part of #1723 What this unblocks: batch 3 item #2, five scalar opcodes (`s_sext_i32_i8`, `s_sext_i32_i16`, `s_cmov_b32`, `s_cmov_b64`, `s_cmovk_i32`) that startup shaders hit and gfx2hlsl refused. `s_sext_i32_i8/i16` sign-extend the low 8/16 bits and set SCC to `result != 0`. `s_cmov_b32/b64` and `s_cmovk_i32` write `SCC ? source : old destination` and leave SCC alone; `s_cmovk_i32` sign-extends its 16-bit immediate. Lane-mask operands, `m0`/`exec`/`vcc` destinations and the discard destination are refused. Verification: - `python3 -B tests/startup_gfx2hlsl_s_sext_cmov_check.py` -> `all ok` (on origin/main the same test fails with `AssertionError: refused: s_sext_i32_i8`) - `python3 -B tests/startup_gfx2hlsl_s_lshl_add_check.py` -> exit 0 - `python3 -B tests/startup_gfx2hlsl_bit_alu_check.py` -> exit 0 - `python3 -B tests/startup_gfx2hlsl_op_refusals_check.py` -> exit 0 - `python3 -B tests/startup_gfx2hlsl_refusals_check.py` -> exit 0 - Not run: a Win2025 build; the change is Python only and registered as `startup_gfx2hlsl_s_sext_cmov` in CMakeLists.txt. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-25 01:01:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:10:18Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: adf137b943

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

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

Review: COMMENTED


No description provided.

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

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

Review: COMMENTED


No description provided.

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

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

Review: COMMENTED


No description provided.

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

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:01:24Z.


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-25T00:10:21.260018Z adf137b 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:7148051177 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2071#issuecomment-7148051177). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:01:24Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"adf137b94390c38348f0a22bea29479250e82168","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-25T00:10:21.260018Z">2026-11-25T00:10:21.260018Z</relative-time> | `adf137b` | 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:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:10:18Z.

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

@@ -1886,6 +1923,9 @@ def declarations(self):
     's_min_i32': ('uint(min(int({0}), int({1})))', None), 's_max_i32': ('uint(max(int({0}), int({1})))', None),
     's_bfe_u32': ('({0} >> ({1} & 31)) & ((1u << (({1} >> 16) & 127)) - 1)', '$ != 0'),
     's_brev_b32': ('reversebits({0})', None),
+    # s_sext_i32_iN: sign-extend the low N bits of S0; SCC = result != 0.
+    's_sext_i32_i8': ('uint(int({0} << 24) >> 24)', '$ != 0'),
+    's_sext_i32_i16': ('uint(int({0} << 16) >> 16)', '$ != 0'),

P1 Badge Preserve SCC when lowering the scalar sign-extends

For shaders that compare before s_sext_i32_i8/i16 and consume that condition afterward, these entries silently replace it with (result != 0). Both RDNA2 instructions preserve SCC, as the existing tools/pixel_aot.py scalar table already models with None. With incoming SCC=1, extending zero followed by s_cmov_b32 therefore incorrectly keeps the old destination instead of moving the source. Set the SCC rule to None and update the new fixture to verify preservation of both incoming SCC states rather than asserting a nonzero-result flag.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688378133 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2071#discussion_r4688378133). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:10:18Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 1928 ~~~~diff @@ -1886,6 +1923,9 @@ def declarations(self): 's_min_i32': ('uint(min(int({0}), int({1})))', None), 's_max_i32': ('uint(max(int({0}), int({1})))', None), 's_bfe_u32': ('({0} >> ({1} & 31)) & ((1u << (({1} >> 16) & 127)) - 1)', '$ != 0'), 's_brev_b32': ('reversebits({0})', None), + # s_sext_i32_iN: sign-extend the low N bits of S0; SCC = result != 0. + 's_sext_i32_i8': ('uint(int({0} << 24) >> 24)', '$ != 0'), + 's_sext_i32_i16': ('uint(int({0} << 16) >> 16)', '$ != 0'), ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Preserve SCC when lowering the scalar sign-extends** For shaders that compare before `s_sext_i32_i8/i16` and consume that condition afterward, these entries silently replace it with `(result != 0)`. Both RDNA2 instructions preserve SCC, as the existing `tools/pixel_aot.py` scalar table already models with `None`. With incoming SCC=1, extending zero followed by `s_cmov_b32` therefore incorrectly keeps the old destination instead of moving the source. Set the SCC rule to `None` and update the new fixture to verify preservation of both incoming SCC states rather than asserting a nonzero-result flag. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-25 01:02:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:10:18Z.

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

@@ -936,6 +936,43 @@ def op_s_cselect_b32(self, ops, mods):
     def op_s_cselect_b64(self, ops, mods):
         self.scalar_select(ops, True)
 
+    def op_s_cmov_b32(self, ops, mods):
+        self.scalar_cmov(ops, mods, False)
+
+    def op_s_cmov_b64(self, ops, mods):
+        self.scalar_cmov(ops, mods, True)
+
+    def op_s_cmovk_i32(self, ops, mods):
+        # SOPK form: the 16-bit immediate is sign-extended to 32 bits.
+        if len(ops) != 2 or mods or not re.fullmatch(r'-?(0x[0-9a-f]+|\d+)', ops[1]):
+            raise Unsupported('s_cmovk_i32 requires a destination and a 16-bit immediate')
+        value = int(ops[1], 0) & 0xffff
+        value = (value - 0x10000 if value & 0x8000 else value) & 0xffffffff
+        self.scalar_cmov([ops[0], '0x%x' % value], mods, False, 's_cmovk_i32')
+
+    def scalar_cmov(self, ops, mods, pair, name=None):
+        """D = SCC ? S0 : D on plain SGPR destinations; SCC is unchanged."""
+        name = name or 's_cmov_b%d' % (64 if pair else 32)
+        if len(ops) != 2 or mods:
+            raise Unsupported('%s requires two unmodified operands' % name)
+        dst, src = reg_range(ops[0]), reg_range(ops[1])
+        if not dst or dst[0] != 's' or dst[1] > 105 or (pair and dst[1] % 2):
+            raise Unsupported('%s destination %s' % (name, ops[0]))
+        if pair and (not src or src[0] != 's' or src[1] > 105 or src[1] % 2 or src[1] == src[2]):
+            raise Unsupported('%s source %s' % (name, ops[1]))
+        if self.is_lane_mask(ops[0]) or self.is_lane_mask(ops[1]) or (
+                src and src[0] == 's' and src[1] > 105):

P2 Badge Check both halves of 64-bit conditional-move operands

For a register pair, is_lane_mask() checks only its starting SGPR, so a mask stored in the high word bypasses this guard and is treated as a complete 32-bit scalar. With SCC=1, the LLVM-accepted sequence s_mov_b32 s3, exec_lo; s_cmov_b64 s[4:5], s[2:3]; s_lshr_b32 s5, s5, 1 produces zero instead of 0x7fffffff on an all-active wave: the translator stores only the lane's EXEC bit in s3, then copies it into an untagged s5. Check both registers of each source and destination pair before accepting the full-width move.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688378141 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2071#discussion_r4688378141). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:10:18Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 964 ~~~~diff @@ -936,6 +936,43 @@ def op_s_cselect_b32(self, ops, mods): def op_s_cselect_b64(self, ops, mods): self.scalar_select(ops, True) + def op_s_cmov_b32(self, ops, mods): + self.scalar_cmov(ops, mods, False) + + def op_s_cmov_b64(self, ops, mods): + self.scalar_cmov(ops, mods, True) + + def op_s_cmovk_i32(self, ops, mods): + # SOPK form: the 16-bit immediate is sign-extended to 32 bits. + if len(ops) != 2 or mods or not re.fullmatch(r'-?(0x[0-9a-f]+|\d+)', ops[1]): + raise Unsupported('s_cmovk_i32 requires a destination and a 16-bit immediate') + value = int(ops[1], 0) & 0xffff + value = (value - 0x10000 if value & 0x8000 else value) & 0xffffffff + self.scalar_cmov([ops[0], '0x%x' % value], mods, False, 's_cmovk_i32') + + def scalar_cmov(self, ops, mods, pair, name=None): + """D = SCC ? S0 : D on plain SGPR destinations; SCC is unchanged.""" + name = name or 's_cmov_b%d' % (64 if pair else 32) + if len(ops) != 2 or mods: + raise Unsupported('%s requires two unmodified operands' % name) + dst, src = reg_range(ops[0]), reg_range(ops[1]) + if not dst or dst[0] != 's' or dst[1] > 105 or (pair and dst[1] % 2): + raise Unsupported('%s destination %s' % (name, ops[0])) + if pair and (not src or src[0] != 's' or src[1] > 105 or src[1] % 2 or src[1] == src[2]): + raise Unsupported('%s source %s' % (name, ops[1])) + if self.is_lane_mask(ops[0]) or self.is_lane_mask(ops[1]) or ( + src and src[0] == 's' and src[1] > 105): ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Check both halves of 64-bit conditional-move operands** For a register pair, `is_lane_mask()` checks only its starting SGPR, so a mask stored in the high word bypasses this guard and is treated as a complete 32-bit scalar. With SCC=1, the LLVM-accepted sequence `s_mov_b32 s3, exec_lo; s_cmov_b64 s[4:5], s[2:3]; s_lshr_b32 s5, s5, 1` produces zero instead of `0x7fffffff` on an all-active wave: the translator stores only the lane's EXEC bit in `s3`, then copies it into an untagged `s5`. Check both registers of each source and destination pair before accepting the full-width move. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-25 01:02:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:10:18Z.

Code review location: CMakeLists.txt; line 2204

@@ -2199,6 +2199,9 @@ if(EXISTS "${INTAKE_PYTHON}")
     # The scalar shift-and-add forms s_lshl1..4_add_u32 (Run 20 census #16).
     add_test(NAME startup_gfx2hlsl_s_lshl_add COMMAND "${INTAKE_PYTHON}" -B
         "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_s_lshl_add_check.py")
+    # Scalar sign-extends and conditional moves (batch 3 #2).
+    add_test(NAME startup_gfx2hlsl_s_sext_cmov COMMAND "${INTAKE_PYTHON}" -B
+        "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_s_sext_cmov_check.py")

P1 Badge Document the new startup scalar translation capability

This adds five previously refused startup-translator instructions, but neither README.md nor docs/experiments.md changes with the public capability, contrary to the requirement in AGENTS.md. A documentation search finds existing notes for these mnemonics under pixel_aot, not this translator. Update the capability documentation with the supported/refused operand forms and the python3 -B tests/startup_gfx2hlsl_s_sext_cmov_check.py reproduction command, explicitly distinguishing CPU evaluation from Windows/D3D12 validation.

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

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688378148 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2071#discussion_r4688378148). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:10:18Z. **Code review location:** `CMakeLists.txt`; line 2204 ~~~~diff @@ -2199,6 +2199,9 @@ if(EXISTS "${INTAKE_PYTHON}") # The scalar shift-and-add forms s_lshl1..4_add_u32 (Run 20 census #16). add_test(NAME startup_gfx2hlsl_s_lshl_add COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_s_lshl_add_check.py") + # Scalar sign-extends and conditional moves (batch 3 #2). + add_test(NAME startup_gfx2hlsl_s_sext_cmov COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_s_sext_cmov_check.py") ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Document the new startup scalar translation capability** This adds five previously refused startup-translator instructions, but neither `README.md` nor `docs/experiments.md` changes with the public capability, contrary to the requirement in `AGENTS.md`. A documentation search finds existing notes for these mnemonics under `pixel_aot`, not this translator. Update the capability documentation with the supported/refused operand forms and the `python3 -B tests/startup_gfx2hlsl_s_sext_cmov_check.py` reproduction command, explicitly distinguishing CPU evaluation from Windows/D3D12 validation. AGENTS.md reference: [AGENTS.md:L211-L212](https://github.com/R0Y00/Xbox2Windows/blob/adf137b94390c38348f0a22bea29479250e82168/AGENTS.md#L211-L212) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
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-25T01:00:14Z.

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

@@ -1886,6 +1923,9 @@ def declarations(self):
     's_min_i32': ('uint(min(int({0}), int({1})))', None), 's_max_i32': ('uint(max(int({0}), int({1})))', None),
     's_bfe_u32': ('({0} >> ({1} & 31)) & ((1u << (({1} >> 16) & 127)) - 1)', '$ != 0'),
     's_brev_b32': ('reversebits({0})', None),
+    # s_sext_i32_iN: sign-extend the low N bits of S0; SCC = result != 0.
+    's_sext_i32_i8': ('uint(int({0} << 24) >> 24)', '$ != 0'),
+    's_sext_i32_i16': ('uint(int({0} << 16) >> 16)', '$ != 0'),

SCC preservation was fixed in f4ac3e62 (rebased); both sext entries use SCC None and the fixture checks an unset SCC stays unchanged. Latest head dc7d54e2.

AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_s_sext_cmov_check.py

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688750756 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2071#discussion_r4688750756). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:00:14Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 1928 ~~~~diff @@ -1886,6 +1923,9 @@ def declarations(self): 's_min_i32': ('uint(min(int({0}), int({1})))', None), 's_max_i32': ('uint(max(int({0}), int({1})))', None), 's_bfe_u32': ('({0} >> ({1} & 31)) & ((1u << (({1} >> 16) & 127)) - 1)', '$ != 0'), 's_brev_b32': ('reversebits({0})', None), + # s_sext_i32_iN: sign-extend the low N bits of S0; SCC = result != 0. + 's_sext_i32_i8': ('uint(int({0} << 24) >> 24)', '$ != 0'), + 's_sext_i32_i16': ('uint(int({0} << 16) >> 16)', '$ != 0'), ~~~~ --- SCC preservation was fixed in f4ac3e62 (rebased); both sext entries use SCC None and the fixture checks an unset SCC stays unchanged. Latest head dc7d54e2. AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_s_sext_cmov_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-25T01:00:16Z.

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

@@ -936,6 +936,43 @@ def op_s_cselect_b32(self, ops, mods):
     def op_s_cselect_b64(self, ops, mods):
         self.scalar_select(ops, True)
 
+    def op_s_cmov_b32(self, ops, mods):
+        self.scalar_cmov(ops, mods, False)
+
+    def op_s_cmov_b64(self, ops, mods):
+        self.scalar_cmov(ops, mods, True)
+
+    def op_s_cmovk_i32(self, ops, mods):
+        # SOPK form: the 16-bit immediate is sign-extended to 32 bits.
+        if len(ops) != 2 or mods or not re.fullmatch(r'-?(0x[0-9a-f]+|\d+)', ops[1]):
+            raise Unsupported('s_cmovk_i32 requires a destination and a 16-bit immediate')
+        value = int(ops[1], 0) & 0xffff
+        value = (value - 0x10000 if value & 0x8000 else value) & 0xffffffff
+        self.scalar_cmov([ops[0], '0x%x' % value], mods, False, 's_cmovk_i32')
+
+    def scalar_cmov(self, ops, mods, pair, name=None):
+        """D = SCC ? S0 : D on plain SGPR destinations; SCC is unchanged."""
+        name = name or 's_cmov_b%d' % (64 if pair else 32)
+        if len(ops) != 2 or mods:
+            raise Unsupported('%s requires two unmodified operands' % name)
+        dst, src = reg_range(ops[0]), reg_range(ops[1])
+        if not dst or dst[0] != 's' or dst[1] > 105 or (pair and dst[1] % 2):
+            raise Unsupported('%s destination %s' % (name, ops[0]))
+        if pair and (not src or src[0] != 's' or src[1] > 105 or src[1] % 2 or src[1] == src[2]):
+            raise Unsupported('%s source %s' % (name, ops[1]))
+        if self.is_lane_mask(ops[0]) or self.is_lane_mask(ops[1]) or (
+                src and src[0] == 's' and src[1] > 105):

Fixed in dc7d54e2: s_cmov_b32/b64 now check both halves of the source and destination pairs for a lane mask, with a regression test (fails before, passes after).

AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_s_sext_cmov_check.py

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688750981 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2071#discussion_r4688750981). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:00:16Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 964 ~~~~diff @@ -936,6 +936,43 @@ def op_s_cselect_b32(self, ops, mods): def op_s_cselect_b64(self, ops, mods): self.scalar_select(ops, True) + def op_s_cmov_b32(self, ops, mods): + self.scalar_cmov(ops, mods, False) + + def op_s_cmov_b64(self, ops, mods): + self.scalar_cmov(ops, mods, True) + + def op_s_cmovk_i32(self, ops, mods): + # SOPK form: the 16-bit immediate is sign-extended to 32 bits. + if len(ops) != 2 or mods or not re.fullmatch(r'-?(0x[0-9a-f]+|\d+)', ops[1]): + raise Unsupported('s_cmovk_i32 requires a destination and a 16-bit immediate') + value = int(ops[1], 0) & 0xffff + value = (value - 0x10000 if value & 0x8000 else value) & 0xffffffff + self.scalar_cmov([ops[0], '0x%x' % value], mods, False, 's_cmovk_i32') + + def scalar_cmov(self, ops, mods, pair, name=None): + """D = SCC ? S0 : D on plain SGPR destinations; SCC is unchanged.""" + name = name or 's_cmov_b%d' % (64 if pair else 32) + if len(ops) != 2 or mods: + raise Unsupported('%s requires two unmodified operands' % name) + dst, src = reg_range(ops[0]), reg_range(ops[1]) + if not dst or dst[0] != 's' or dst[1] > 105 or (pair and dst[1] % 2): + raise Unsupported('%s destination %s' % (name, ops[0])) + if pair and (not src or src[0] != 's' or src[1] > 105 or src[1] % 2 or src[1] == src[2]): + raise Unsupported('%s source %s' % (name, ops[1])) + if self.is_lane_mask(ops[0]) or self.is_lane_mask(ops[1]) or ( + src and src[0] == 's' and src[1] > 105): ~~~~ --- Fixed in dc7d54e2: s_cmov_b32/b64 now check both halves of the source and destination pairs for a lane mask, with a regression test (fails before, passes after). AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_s_sext_cmov_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-25T01:00:17Z.

Code review location: CMakeLists.txt; line 2204

@@ -2199,6 +2199,9 @@ if(EXISTS "${INTAKE_PYTHON}")
     # The scalar shift-and-add forms s_lshl1..4_add_u32 (Run 20 census #16).
     add_test(NAME startup_gfx2hlsl_s_lshl_add COMMAND "${INTAKE_PYTHON}" -B
         "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_s_lshl_add_check.py")
+    # Scalar sign-extends and conditional moves (batch 3 #2).
+    add_test(NAME startup_gfx2hlsl_s_sext_cmov COMMAND "${INTAKE_PYTHON}" -B
+        "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_s_sext_cmov_check.py")

Fixed in dc7d54e2: README row plus a docs/experiments.md section list supported and refused forms, the reproduction command, and state that this is CPU evaluation only, not Windows/D3D12 validation.

AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_s_sext_cmov_check.py

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688751128 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2071#discussion_r4688751128). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:00:17Z. **Code review location:** `CMakeLists.txt`; line 2204 ~~~~diff @@ -2199,6 +2199,9 @@ if(EXISTS "${INTAKE_PYTHON}") # The scalar shift-and-add forms s_lshl1..4_add_u32 (Run 20 census #16). add_test(NAME startup_gfx2hlsl_s_lshl_add COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_s_lshl_add_check.py") + # Scalar sign-extends and conditional moves (batch 3 #2). + add_test(NAME startup_gfx2hlsl_s_sext_cmov COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_s_sext_cmov_check.py") ~~~~ --- Fixed in dc7d54e2: README row plus a docs/experiments.md section list supported and refused forms, the reproduction command, and state that this is CPU evaluation only, not Windows/D3D12 validation. AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_s_sext_cmov_check.py
upstream-sync closed this pull request 2026-11-25 02:01:37 +00:00
R0Y00 commented 2026-11-25 02:02:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T01:35:38Z.


I resolved the CTest conflict and kept both registrations. The conditional move now uses the same signed SOPK immediate parser as the merged sign-extension change, and register pairs are checked for width, alignment, and range before use. On Windows the scalar sext/cmov, SOPK, cselect, mask overwrite, scalar arity, and documentation checks passed. The SOPK fixture still rejects an out-of-range immediate.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7149727405 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2071#issuecomment-7149727405). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T01:35:38Z. --- I resolved the CTest conflict and kept both registrations. The conditional move now uses the same signed SOPK immediate parser as the merged sign-extension change, and register pairs are checked for width, alignment, and range before use. On Windows the scalar sext/cmov, SOPK, cselect, mask overwrite, scalar arity, and documentation checks passed. The SOPK fixture still rejects an out-of-range immediate.
R0Y00 commented 2026-11-25 02:02:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T01:52:04Z.


The overlapping updates left s_cmovk truncating out-of-range text and loosened pair checks. I kept your CTest update and restored the shared SOPK parser and exact pair validation, with five refusals in the dedicated cmov test. Valid binary cmov cases, SOPK, cselect, mask overwrite and scalar arity pass.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7150050801 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2071#issuecomment-7150050801). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T01:52:04Z. --- The overlapping updates left s_cmovk truncating out-of-range text and loosened pair checks. I kept your CTest update and restored the shared SOPK parser and exact pair validation, with five refusals in the dedicated cmov test. Valid binary cmov cases, SOPK, cselect, mask overwrite and scalar arity 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!2064
No description provided.