Skip to content

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

Closed
tedin7 wants to merge 1 commit into
R0Y00:mainfrom
tedin7:x2w-r20-s-mulk-addk
Closed

tedin7 wants to merge 1 commit into
R0Y00:mainfrom
tedin7:x2w-r20-s-mulk-addk

Conversation

@tedin7

@tedin7 tedin7 commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread tools/startup/gfx2hlsl.py
Comment on lines +1761 to +1762
if not reg or reg[0] != 's' or reg[1] != reg[2] or reg[1] > 105:
raise Unsupported('%s destination %s' % (base, ops[0]))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 👍 / 👎.

Comment thread tools/startup/gfx2hlsl.py
Comment on lines +1773 to +1774
if self.sym.get(reg[1]):
raise Unsupported('scc from descriptor data')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 👍 / 👎.

Comment thread CMakeLists.txt
Comment on lines +2161 to +2162
add_test(NAME startup_gfx2hlsl_s_mulk_addk COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_s_mulk_addk_check.py")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 👍 / 👎.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

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

@tedin7 tedin7 closed this Nov 25, 2026
tedin7 pushed a commit to tedin7/Xbox2Windows that referenced this pull request Nov 26, 2026
The lowering is already on this branch. Keep the branch code, add the PR's check (passes against it) and register it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant