shader: lower s_lshl1_add_u32 and s_lshl4_add_u32 in gfx2hlsl (Part of #1723) #2020

Merged
tedin7 merged 3 commits from upstream-pr/2027 into main 2026-11-24 23:56:32 +00:00
tedin7 commented 2026-11-24 23:27:02 +00:00 (Migrated from github.com)

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


Part of #1723

What this unblocks: Run 20 census #16 (40/32 pairs).

Lowers s_lshl1_add_u32 .. s_lshl4_add_u32 in tools/startup/gfx2hlsl.py: D = (S0 << N) + S1, with SCC set to the carry out of the wide sum (bits shifted out of S0 count too). SCC is emitted before the destination write, so an in-place destination keeps the right sources. Lane-mask and descriptor-data operands are refused, as for the other SCC-from-word scalar ops.

Verification (commands executed locally):

  • python3 -B tests/startup_gfx2hlsl_s_lshl_add_check.py: all ok (4 ops x 10 operand forms x 1824 value pairs, plus mask refusals). Copied onto a detached origin/main tree it fails (rc=1) for all four ops.
  • Neighbouring checks still pass (rc=0): startup_gfx2hlsl_b64_shift_check.py, startup_gfx2hlsl_bit_alu_check.py, startup_gfx2hlsl_lane_alu.py, startup_gfx2hlsl_scalar_m0_check.py, startup_gfx2hlsl_sop2_complement_check.py.
  • Test registered in CMakeLists.txt as startup_gfx2hlsl_s_lshl_add.
  • Not run: Win2025 / CMake build (this was a local Linux Python run).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6593493986 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2027). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T23:27:02Z. --- Part of #1723 What this unblocks: Run 20 census #16 (40/32 pairs). Lowers `s_lshl1_add_u32` .. `s_lshl4_add_u32` in `tools/startup/gfx2hlsl.py`: `D = (S0 << N) + S1`, with SCC set to the carry out of the wide sum (bits shifted out of S0 count too). SCC is emitted before the destination write, so an in-place destination keeps the right sources. Lane-mask and descriptor-data operands are refused, as for the other SCC-from-word scalar ops. Verification (commands executed locally): - `python3 -B tests/startup_gfx2hlsl_s_lshl_add_check.py`: all ok (4 ops x 10 operand forms x 1824 value pairs, plus mask refusals). Copied onto a detached `origin/main` tree it fails (rc=1) for all four ops. - Neighbouring checks still pass (rc=0): `startup_gfx2hlsl_b64_shift_check.py`, `startup_gfx2hlsl_bit_alu_check.py`, `startup_gfx2hlsl_lane_alu.py`, `startup_gfx2hlsl_scalar_m0_check.py`, `startup_gfx2hlsl_sop2_complement_check.py`. - Test registered in CMakeLists.txt as `startup_gfx2hlsl_s_lshl_add`. - Not run: Win2025 / CMake build (this was a local Linux Python run). AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 00:05:00 +00:00
chatgpt-codex-connector[bot commented 2026-11-25 00:05:00 +00:00 (Migrated from github.com)

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

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d2f0e1df19

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

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


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:31:32.255602Z d2f0e1d 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:7147417932 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2027#issuecomment-7147417932). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:27:16Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"d2f0e1df193500676b46f02e0dd29d7993c321d8","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:31:32.255602Z">2026-11-24T23:31:32.255602Z</relative-time> | `d2f0e1d` | 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>
R0Y00 commented 2026-11-25 01:01:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T23:53:55Z.


The maintainer update resolves the conflict with #2024 and rejects the discard destination for all four shift-add opcodes. Both new SCC producers now use the current uniformity-aware setter. Tests cover a varying source and the discard encoding, and the existing readfirstlane, complement/pack and bit-test cases passed after combining with main. The shift-and-add result and carry agree with the RDNA 2 SOP2 reference.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7147916355 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2027#issuecomment-7147916355). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T23:53:55Z. --- The maintainer update resolves the conflict with #2024 and rejects the discard destination for all four shift-add opcodes. Both new SCC producers now use the current uniformity-aware setter. Tests cover a varying source and the discard encoding, and the existing readfirstlane, complement/pack and bit-test cases passed after combining with main. The shift-and-add result and carry agree with the [RDNA 2 SOP2 reference](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf).
chatgpt-codex-connector[bot commented 2026-11-25 01:02:11 +00:00 (Migrated from github.com)

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

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

@@ -1739,7 +1743,12 @@ def declarations(self):
     's_pack_hh_b32_b16': ('({0} >> 16) | ({1} & 0xffff0000u)', None),
     # s_bfm_b32: a mask of S0[4:0] ones shifted left by S1[4:0]; SCC unchanged.
     's_bfm_b32': ('(((1u << ({0} & 31)) - 1) << ({1} & 31))', None),
+    # s_lshlN_add_u32: (S0 << N) + S1. SCC is the carry out of the 33-bit-wide sum, written from SHIFT_ADD below.
+    's_lshl1_add_u32': ('({0} << 1) + {1}', None), 's_lshl2_add_u32': ('({0} << 2) + {1}', None),
+    's_lshl3_add_u32': ('({0} << 3) + {1}', None), 's_lshl4_add_u32': ('({0} << 4) + {1}', None),

P2 Badge Guard unsupported destinations in the new shift-add lowering

For a shader containing s_lshl1_add_u32 null, 1, 1 (SDST 125), these entries now enter scalar(), whose destination write indexes reg_range('null') even though it returns None. Using the source-built pipeline fixture, translate_to(..., check=False) returns an unsupported result and writes .fail on the parent, but raises an uncaught TypeError here for all four opcodes. The request loop in main() does not catch that exception, so one such shader aborts the remaining cache translations. Handle the discard destination, or reject unsupported destination kinds with Unsupported before reaching the generic scalar writer.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4687996936 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2027#discussion_r4687996936). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:31:30Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 1748 ~~~~diff @@ -1739,7 +1743,12 @@ def declarations(self): 's_pack_hh_b32_b16': ('({0} >> 16) | ({1} & 0xffff0000u)', None), # s_bfm_b32: a mask of S0[4:0] ones shifted left by S1[4:0]; SCC unchanged. 's_bfm_b32': ('(((1u << ({0} & 31)) - 1) << ({1} & 31))', None), + # s_lshlN_add_u32: (S0 << N) + S1. SCC is the carry out of the 33-bit-wide sum, written from SHIFT_ADD below. + 's_lshl1_add_u32': ('({0} << 1) + {1}', None), 's_lshl2_add_u32': ('({0} << 2) + {1}', None), + 's_lshl3_add_u32': ('({0} << 3) + {1}', None), 's_lshl4_add_u32': ('({0} << 4) + {1}', None), ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Guard unsupported destinations in the new shift-add lowering** For a shader containing `s_lshl1_add_u32 null, 1, 1` (SDST 125), these entries now enter `scalar()`, whose destination write indexes `reg_range('null')` even though it returns `None`. Using the source-built pipeline fixture, `translate_to(..., check=False)` returns an unsupported result and writes `.fail` on the parent, but raises an uncaught `TypeError` here for all four opcodes. The request loop in `main()` does not catch that exception, so one such shader aborts the remaining cache translations. Handle the discard destination, or reject unsupported destination kinds with `Unsupported` before reaching the generic scalar writer. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
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!2020
No description provided.