Skip to content

shader: lower eight SDWA bit and 24-bit multiply forms - #1572

Closed
itzJaack wants to merge 4 commits into
R0Y00:mainfrom
itzJaack:shader/sdwa-bit-operations
Closed

itzJaack wants to merge 4 commits into
R0Y00:mainfrom
itzJaack:shader/sdwa-bit-operations

Conversation

@itzJaack

@itzJaack itzJaack commented Nov 24, 2026 •

Copy link
Copy Markdown

Translate eight additional SDWA integer forms. The first group covers bit reversal and low, high unsigned, and high signed bit scans. The second group covers signed and unsigned 24-bit products, both low and high halves. Both reuse the existing instruction semantics and SDWA source selection and destination placement. The draw fixtures exercise sign extension, the no-bit sentinel, destination preservation, and signed versus unsigned high products.

Verification at 9b68efd

  • python -B tests/pixel_aot_check.py passed locally on Windows. The SDWA integer fixture now exercises 23 forms.
  • DXC compiled both generated pixel fixtures as ps_6_0.
  • On an RTX 5070 Ti, D3D12 compute wrappers around the emitted expressions matched independent Python reference words across 65,536 input tuples per group (524,288 output words total). The compute dispatch tests the arithmetic and subword handling. The repository pixel draw is covered separately by the existing pixel_aot_sdwa_integer_ CTest cases.

AI Driven - Specs: AMD Ryzen 7 9850X3D | NVIDIA GeForce RTX 5070 Ti | 16 GB DDR5 | Windows 11 Pro | Model: 6.2 Astra Medium

AI Driven - Specs: AMD Ryzen 7 9850X3D | NVIDIA GeForce RTX 5070 Ti | 16 GB DDR5 | Windows 11 Pro | Model: 6.2 Astra Medium
@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-24T14:33:06.243731Z 74cb16c 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.

AI Driven - Specs: AMD Ryzen 7 9850X3D | NVIDIA GeForce RTX 5070 Ti | 16 GB DDR5 | Windows 11 Pro | Model: 6.2 Astra Medium
AI Driven - Specs: AMD Ryzen 7 9850X3D | NVIDIA GeForce RTX 5070 Ti | 16 GB DDR5 | Windows 11 Pro | Model: 6.2 Astra Medium
@itzJaack itzJaack changed the title shader: lower four SDWA bit operations in pixel shaders shader: lower eight SDWA bit and 24-bit multiply forms Nov 24, 2026

@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: 74cb16c7e4

ℹ️ 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/pixel_aot.py
# of the result into its dst_sel, so each form is its e32 operation on the extracted words, placed like a move.
SDWA_INT = {
**{op: INTEGER[op] for op in ("and_b32", "or_b32", "xor_b32", "xnor_b32", "not_b32",
"bfrev_b32", "ffbl_b32", "ffbh_u32", "ffbh_i32",

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 Update the public SDWA capability documentation

These four newly accepted forms change the translator's public capability, but docs/experiments.md:5639 still lists fifteen supported SDWA integer operations, says other integer SDWA spellings are refused, and describes four fixture programs rather than the new five. The published support boundary and reproduction description therefore contradict the tool. Update that section with the new bit-scan forms and their validation limits, keeping the existing GPU results distinct from the still-unverified pixel draws. Root AGENTS.md explicitly requires a README or experiment-documentation update when a public capability changes.

AGENTS.md reference: AGENTS.md:L191-L192

Useful? React with 👍 / 👎.

AI Driven - Specs: AMD Ryzen 7 9850X3D | NVIDIA GeForce RTX 5070 Ti | 16 GB DDR5 | Windows 11 Pro | Model: 6.2 Astra Medium

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good overall. Reviewed the SDWA bit-scan and 24-bit multiply lowering in tools/pixel_aot.py and the tests in tests/pixel_aot_check.py, tests/form_coverage_check.py, and tests/rdna2_tools_check.py at 0bad6806e50a333a90984daee51139c83fdb124b.

Semantic & Edge-Case Review

  • Helper emission & operand handling: Adding bfrev_b32, ffbl_b32, ffbh_u32, ffbh_i32, mul_i32_i24, mul_u32_u24, mul_hi_i32_i24, and mul_hi_u32_u24 to SDWA_INT and updating helpers from both INTEGER_HELPERS and MUL24_HELPERS ensures dpp_ffbh_u32, dpp_ffbh_i32, mul24_u32, mul24_i32, mul24_hi_u32, and mul24_hi_i32 are emitted when used in SDWA form.
  • SDWA source/destination modifiers: sdwa_source() and sdwa_dest() apply BYTE_*/WORD_*/DWORD extraction with optional sext() and UNUSED_PAD/UNUSED_PRESERVE placement, while SDWA_INT_OPERANDS continues to reject clamp, UNUSED_SEXT, inline constants, and untracked UNUSED_PRESERVE destinations.
  • Negative & binary coverage: SDWA_INT_WRONG covers lost sext, unsigned-for-signed high product, ignored byte selection/placement, and zero-vs-sentinel (-1) on v_ffbh_u32_sdwa; check_controls() and TestRdna2Scanner verify clamp rejection.

Verification

  • Linux (LLVM 19):
    • python3 -B tests/pixel_aot_check.py, python3 -B tests/rdna2_tools_check.py (141 tests, 18 skipped), python3 -B tests/docs_links_check.py, python3 -B tests/bidi_controls_check.py — passed.
    • llvm-mc-19 / llvm-objcopy-19 / libLLVM-19.so binary round-trip for multiply24 and bit_scan SDWA groups — passed.
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Debug (--preset dev): offscreen_check built (3.64s), ctest --preset dev -R '^pixel_aot_sdwa_integer_' 2/2 passed (1.97s).
    • Release /O2 (--preset release): offscreen_check built (1.00s), ctest --preset release -R '^pixel_aot_sdwa_integer_' 2/2 passed (1.88s).
    • tests/pixel_aot_check.py (13.4s) and tests/form_coverage_check.py (42.9s) — passed.

AI-assisted; commands listed were executed locally.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review at head 0bad6806e50a333a90984daee51139c83fdb124b. Verdict: not merging yet. Two blockers that are not code defects.

Executed locally:

  • git merge-tree --write-tree --name-only origin/main HEAD: clean, no conflicts.
  • gh pr checks 1572: Windows build and test, Linux Python checks, and gfx1013 fixtures all pass.
  • git diff --stat origin/main...HEAD: 4 files, +52/-6, all under tools/ and tests/.
  • Read the full diff. The lowering reuses the existing integer and 24-bit multiply helpers, and the new tests carry negative controls. The earlier review on this head covers the Linux and Win2025 runs.
  • safe-merge-check: G6 and G7 block.

Findings:

  • P1 (open thread, tools/pixel_aot.py): docs/experiments.md still lists fifteen supported SDWA integer operations and says other integer SDWA spellings are refused. The eight newly accepted forms make that text wrong. Please update the capability note and fixture counts.
  • Competing work: #1612 (SDWA lowering, same area) is open. Please sequence the two so only one lands the shared SDWA table change.

No logic defects found in the lowering itself. Merge held until the docs P1 thread is resolved and #1612 is sequenced.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

@itzJaack could you rebase this branch onto current main and force-push?

GitHub reports head 0bad6806 as conflicting with main, so it cannot be merged as is.

Files that conflict with current main (b1a644ae):

  • tests/form_coverage_check.py

Commands run locally:

git fetch origin main pull/1572/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 1572 --json mergeable   # CONFLICTING

Once it is rebased and CI is green it will be re-checked right away.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Possible duplicate: current main already lowers these eight SDWA forms.

  • SDWA_INT_EXTRA in tools/pixel_aot.py (landed with pixel_aot: lower 12 integer SDWA forms (bitscan, sat_pk, mul24, co_ci) #2550) covers bfrev_b32, ffbl_b32, ffbh_u32, ffbh_i32, mul_u32_u24, mul_i32_i24, mul_hi_u32_u24, mul_hi_i32_i24.
  • Matching fixtures and mutations are in tests/pixel_aot_check.py (SDWA_INT_EXTRA_PROGRAMS, SDWA_INT_EXTRA_MUTATIONS) and tests/form_coverage_check.py.
  • This PR adds the same eight ops to SDWA_INT instead, and conflicts with main in tests/form_coverage_check.py.

Commands executed:

  • git fetch origin main
  • git grep -n -E "SDWA_INT_EXTRA|bfrev_b32|mul_hi_i32_i24" origin/main -- tools tests

I did not push to this branch. @itzJaack, if you see a form that main does not cover, please reduce the PR to that delta; otherwise it can be closed. Leaving the decision to @R0Y00.

AI-assisted; commands listed were executed locally.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Main now contains all eight lowering forms through #2550 (1151986). I integrated current main locally and ran the form coverage suite. The old broad SDWA table takes precedence over the newer extended handler, and the existing UNUSED_SEXT refusal control for v_bfrev_b32 fails. Please keep the main lowering and its controls. If your independent bit-scan or signed/unsigned multiply vectors add coverage, a test-only update can retain those vectors and credit without registering the forms in both handlers. #1612 is closed, so the remaining overlap is #2550.

@itzJaack itzJaack closed this Nov 26, 2026
@itzJaack
itzJaack deleted the shader/sdwa-bit-operations branch November 26, 2026 12:46
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.

3 participants