shader: lower s_mulk_i32 and s_addk_i32 in gfx2hlsl (Part of #1723) #2025

Closed
github-bot wants to merge 1 commit from gh-pr/2025/head into gh-pr/2025/base
Owner

@⁠tedin7 on GitHub · 2026-11-24 23:26 UTC · original
tedin7:x2w-r20-s-mulk-addk → main · +157 −0 · 3 files · 1 commits · closed without merging

Part of #1723

What this unblocks: Run 20 census #5 (79/77 pairs).

Lower s_mulk_i32 and s_addk_i32 in tools/startup/gfx2hlsl.py. Both read and write SDST and take a 16-bit immediate. The decoder prints it as unsigned hex, so it is sign-extended first, then routed through the existing two-source scalar lowering (s_mul_i32 / s_add_i32). s_addk_i32 also sets SCC to the signed overflow of the add, computed from the old destination before the result is written. s_mulk_i32 leaves SCC alone. A destination that is not a plain SGPR (m0, exec, vcc) is refused, and so is s_addk_i32 on descriptor data (SCC would depend on it).

Verification:

  • python3 -B tests/startup_gfx2hlsl_s_mulk_addk_check.py on this branch: PASS. The test builds SOPK words from the decoder layout, executes the emitted statements on 32-bit values and compares them with the architectural result for immediates 0, 1, 0x7fff, 0x8000, 0xfffe, 0xffff.
  • The same test against tools/startup/gfx2hlsl.py from origin/main: fails with Unsupported: s_mulk_i32.
  • Every tests/startup_gfx2hlsl_*check.py run one by one on this branch: all pass.
  • Registered as startup_gfx2hlsl_s_mulk_addk in CMakeLists.txt. These were run on Linux, not on Win2025. No ctest run.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 23:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2025) `tedin7:x2w-r20-s-mulk-addk` → `main` · +157 −0 · 3 files · 1 commits · closed without merging Part of #1723 What this unblocks: Run 20 census #5 (79/77 pairs). Lower `s_mulk_i32` and `s_addk_i32` in `tools/startup/gfx2hlsl.py`. Both read and write SDST and take a 16-bit immediate. The decoder prints it as unsigned hex, so it is sign-extended first, then routed through the existing two-source scalar lowering (`s_mul_i32` / `s_add_i32`). `s_addk_i32` also sets SCC to the signed overflow of the add, computed from the old destination before the result is written. `s_mulk_i32` leaves SCC alone. A destination that is not a plain SGPR (m0, exec, vcc) is refused, and so is `s_addk_i32` on descriptor data (SCC would depend on it). Verification: - `python3 -B tests/startup_gfx2hlsl_s_mulk_addk_check.py` on this branch: `PASS`. The test builds SOPK words from the decoder layout, executes the emitted statements on 32-bit values and compares them with the architectural result for immediates 0, 1, 0x7fff, 0x8000, 0xfffe, 0xffff. - The same test against `tools/startup/gfx2hlsl.py` from `origin/main`: fails with `Unsupported: s_mulk_i32`. - Every `tests/startup_gfx2hlsl_*check.py` run one by one on this branch: all pass. - Registered as `startup_gfx2hlsl_s_mulk_addk` in CMakeLists.txt. These were run on Linux, not on Win2025. No ctest run. AI-assisted; commands listed were executed locally.
Sign-extend the 16-bit immediate, reuse the two-source scalar lowering, and set SCC to the signed overflow for s_addk_i32. Adds startup_gfx2hlsl_s_mulk_addk.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:50:33 +00:00
github-bot closed this pull request 2026-11-26 23:50:33 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:27 UTC · original · edited 2026-11-24 23:34 UTC

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:34:51.473613Z 710b1cf 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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:27 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2025#issuecomment-7147414266) · edited 2026-11-24 23:34 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"710b1cf9de268e4ba63109efa4a3f42ca7e964ac","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:34:51.473613Z">2026-11-24T23:34:51.473613Z</relative-time> | `710b1cf` | 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>
@ -1753,0 +1759,4 @@
raise Unsupported('%s with %d operands' % (base, len(ops)))
reg = reg_range(ops[0])
if not reg or reg[0] != 's' or reg[1] != reg[2] or reg[1] > 105:
raise Unsupported('%s destination %s' % (base, ops[0]))
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:34 UTC · original

P1 Badge Reject SOPK arithmetic on projected lane-mask SGPRs

When SDST holds a comparison mask, this validation accepts it even though Stage.compare() stores only the current lane's 0/1 projection and records that fact in self.masks. For example, after v_cmp_lt_i32_e64 s4, v0, v1 produces a guest low mask of 0x7fffffff, s_addk_i32 s4, 1 must set SCC, but the emitted expression computes on 0/1 and sets SCC false in every invocation; a following scalar select or SCC branch therefore takes the wrong path. Reject mask-tagged SGPRs before either SOPK lowering, as the complement/pack handlers already do, or model the full mask instead of treating its projection as a numeric word.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:34 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2025#discussion_r4688031003) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Reject SOPK arithmetic on projected lane-mask SGPRs** When SDST holds a comparison mask, this validation accepts it even though `Stage.compare()` stores only the current lane's 0/1 projection and records that fact in `self.masks`. For example, after `v_cmp_lt_i32_e64 s4, v0, v1` produces a guest low mask of `0x7fffffff`, `s_addk_i32 s4, 1` must set SCC, but the emitted expression computes on 0/1 and sets SCC false in every invocation; a following scalar select or SCC branch therefore takes the wrong path. Reject mask-tagged SGPRs before either SOPK lowering, as the complement/pack handlers already do, or model the full mask instead of treating its projection as a numeric word. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -1753,0 +1771,4 @@
word = imm & 0xffffffff
if base == 's_addk_i32':
if self.sym.get(reg[1]):
raise Unsupported('scc from descriptor data')
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:34 UTC · original

P2 Badge Allow numeric symbolic SGPRs through the addk guard

When SDST is initialized by an immediate move or supplied as a root constant, self.sym contains a numeric const or ud entry, not descriptor data. Consequently, the ordinary sequence s_mov_b32 s4, 1; s_addk_i32 s4, 1 raises Unsupported('scc from descriptor data') through the production Stage constructor instead of lowering the addition. Numeric fixed_buffer_word entries are rejected too. Restrict this guard to genuinely non-numeric symbols so the new instruction works on initialized scalar values; the added test misses this because it starts with an empty symbol table.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:34 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2025#discussion_r4688031011) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Allow numeric symbolic SGPRs through the addk guard** When SDST is initialized by an immediate move or supplied as a root constant, `self.sym` contains a numeric `const` or `ud` entry, not descriptor data. Consequently, the ordinary sequence `s_mov_b32 s4, 1; s_addk_i32 s4, 1` raises `Unsupported('scc from descriptor data')` through the production `Stage` constructor instead of lowering the addition. Numeric `fixed_buffer_word` entries are rejected too. Restrict this guard to genuinely non-numeric symbols so the new instruction works on initialized scalar values; the added test misses this because it starts with an empty symbol table. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -2159,1 +2159,4 @@
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_b64_shift_check.py")
# The SOPK arithmetic forms s_mulk_i32 and s_addk_i32 (#1723).
add_test(NAME startup_gfx2hlsl_s_mulk_addk COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_s_mulk_addk_check.py")
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:34 UTC · original

P1 Badge Document the new startup SOPK capability and reproduction check

The patch introduces startup-translator support and a new CTest, but updates neither README.md nor docs/experiments.md. AGENTS.md requires documentation updates when public capabilities or reproduction commands change; the existing SOPK paragraph documents pixel_aot, not this startup lowering. Add the new startup check and its measured scope to the public experiment documentation, distinguishing the Linux emitted-statement evaluation from Windows/DXIL or GPU validation.

AGENTS.md reference: AGENTS.md:L209-L210

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:34 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2025#discussion_r4688031018) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Document the new startup SOPK capability and reproduction check** The patch introduces startup-translator support and a new CTest, but updates neither `README.md` nor `docs/experiments.md`. `AGENTS.md` requires documentation updates when public capabilities or reproduction commands change; the existing SOPK paragraph documents `pixel_aot`, not this startup lowering. Add the new startup check and its measured scope to the public experiment documentation, distinguishing the Linux emitted-statement evaluation from Windows/DXIL or GPU validation. AGENTS.md reference: [AGENTS.md:L209-L210](https://github.com/R0Y00/Xbox2Windows/blob/710b1cf9de268e4ba63109efa4a3f42ca7e964ac/AGENTS.md#L209-L210) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 00:30 UTC · original

Closing as superseded by #2102 which also guards mask/descriptor destinations and adds mutation controls.

**@⁠tedin7** on GitHub · 2026-11-25 00:30 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2025#issuecomment-7148587511) Closing as superseded by #2102 which also guards mask/descriptor destinations and adds mutation controls.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:34 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 710b1cf9de

ℹ️ 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".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:34 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2025#pullrequestreview-6049128913) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `710b1cf9de` <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>

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.