shader: lower v_ashrrev_i64 and v_mad_i32_i24 in the direct C++ compute path #2994

Manually merged
github merged 1 commit from github-bot/gh-2994 into gh-pr/2994/base 2026-11-27 03:51:28 +00:00 AGit
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-27 03:36 UTC · original
legacy-code-archaeologist:shader/direct-signed-forms → cpp-migration · +228 −3 · 4 files · 1 commits · merged 2026-11-27 03:47 UTC

Change

The direct compute frontend lowered v_lshrrev_b64, v_lshlrev_b64 (#2952) and v_mad_u32_u24, but refused their signed counterparts with direct DXIL lowering for <name>. It now lowers both. Refs #2991, part of the integer-ALU coverage in #2935.

  • v_ashrrev_i64: an arithmetic ashr i64 of S1 by S0[5:0]. The shifted value accepts the same operands as the logical shifts. The one difference follows gfx2hlsl.py's i64_words(signed=True): a 32-bit literal is sign-extended for this form. The logical shifts still zero-extend it.
  • v_mad_i32_i24: sext(S0[23:0]) * sext(S1[23:0]) + S2 modulo 2^32, the gfx2hlsl.py VOP3-table expression. Modifiers stay refused, as for the other integer VOP3 forms.

Verification

Commit f7a27220 on cpp-migration 4ff5e36d, Windows 10.0.26100.9711, dev preset. NVIDIA Quadro M1000M, driver 32.0.15.7371, debug layer unavailable.

  • ctest --preset dev --no-tests=error -R '^native_signed_forms_|^native_shift64_|^native_direct_container$': 3 passed, 2 skipped.
    • native_signed_forms_controls passed. It compiles six v_ashrrev_i64 sources and the multiply-add, and checks the modules with dxc -dumpbin: exactly one ashr i64 per shift program, and an arithmetic shift right with mul i32 for the multiply-add. It also checks that the zero-extended-literal, logical, unsigned and unmasked references each differ.
    • native_signed_forms_hardware and native_shift64_hardware skipped (77). They need shader model 6.6 with wave32. The readback is not measured here.
  • native_shift64_controls passed, so the logical shifts are unchanged.
  • python -B tests/docs_links_check.py: ok.

Evidence and follow-up

The words were assembled with LLVM 15.0.7 (clang -cc1as -triple amdgcn -target-cpu gfx1013 -filetype asm -show-encoding).

Shift dispatches. They reuse native_shift64_check.compute_program and its store layout (8 bytes per lane, 256 bytes per group of 32), with the v_ashrrev_i64 opcode (VOP3 0x301). The amounts are 0, 1, 31, 32, 33 and 63. The sources are inline -1, -16, 64 and 1, the literal 0x80000001, and the negative SGPR pair 0x89abcdef:01234567.

Multiply-add dispatch. With n = lane + 32 * group:

  • S0 = mul_u32_u24(n, 0x05f3d1) ^ 0xa5800000
  • S1 = mul_u32_u24(n, 0x0371) ^ 0x7f9abcde
  • S2 = mul_u32_u24(n, 0x1001)

Bit 23 is set in many factors, and the bits above it are nonzero in all of them.

tools/compute_store_aot.py still refuses v_mad_i32_i24. That is a separate path and is not touched here. The note is docs/experiments/native-direct-signed-forms.md.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

🤖 Generated with Claude Code

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-27 03:36 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2994) `legacy-code-archaeologist:shader/direct-signed-forms` → `cpp-migration` · +228 −3 · 4 files · 1 commits · merged 2026-11-27 03:47 UTC ## Change The direct compute frontend lowered `v_lshrrev_b64`, `v_lshlrev_b64` (#2952) and `v_mad_u32_u24`, but refused their signed counterparts with `direct DXIL lowering for <name>`. It now lowers both. Refs #2991, part of the integer-ALU coverage in #2935. - **`v_ashrrev_i64`:** an arithmetic `ashr i64` of S1 by S0[5:0]. The shifted value accepts the same operands as the logical shifts. The one difference follows `gfx2hlsl.py`'s `i64_words(signed=True)`: a 32-bit literal is sign-extended for this form. The logical shifts still zero-extend it. - **`v_mad_i32_i24`:** sext(S0[23:0]) * sext(S1[23:0]) + S2 modulo 2^32, the `gfx2hlsl.py` VOP3-table expression. Modifiers stay refused, as for the other integer VOP3 forms. ## Verification Commit `f7a27220` on `cpp-migration` `4ff5e36d`, Windows 10.0.26100.9711, `dev` preset. NVIDIA Quadro M1000M, driver 32.0.15.7371, debug layer unavailable. - `ctest --preset dev --no-tests=error -R '^native_signed_forms_|^native_shift64_|^native_direct_container$'`: 3 passed, 2 skipped. - `native_signed_forms_controls` passed. It compiles six `v_ashrrev_i64` sources and the multiply-add, and checks the modules with `dxc -dumpbin`: exactly one `ashr i64` per shift program, and an arithmetic shift right with `mul i32` for the multiply-add. It also checks that the zero-extended-literal, logical, unsigned and unmasked references each differ. - **`native_signed_forms_hardware` and `native_shift64_hardware` skipped (77).** They need shader model 6.6 with wave32. **The readback is not measured here.** - `native_shift64_controls` passed, so the logical shifts are unchanged. - `python -B tests/docs_links_check.py`: ok. ## Evidence and follow-up The words were assembled with LLVM 15.0.7 (`clang -cc1as -triple amdgcn -target-cpu gfx1013 -filetype asm -show-encoding`). **Shift dispatches.** They reuse `native_shift64_check.compute_program` and its store layout (8 bytes per lane, 256 bytes per group of 32), with the `v_ashrrev_i64` opcode (VOP3 0x301). The amounts are 0, 1, 31, 32, 33 and 63. The sources are inline -1, -16, 64 and 1, the literal 0x80000001, and the negative SGPR pair 0x89abcdef:01234567. **Multiply-add dispatch.** With n = lane + 32 * group: - S0 = mul_u32_u24(n, 0x05f3d1) ^ 0xa5800000 - S1 = mul_u32_u24(n, 0x0371) ^ 0x7f9abcde - S2 = mul_u32_u24(n, 0x1001) Bit 23 is set in many factors, and the bits above it are nonzero in all of them. `tools/compute_store_aot.py` still refuses `v_mad_i32_i24`. That is a separate path and is not touched here. The note is `docs/experiments/native-direct-signed-forms.md`. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The direct compute frontend lowered the logical 64-bit shifts and
v_mad_u32_u24 but refused their signed counterparts. v_ashrrev_i64 now
uses the shifted-value rules of the logical shifts with an arithmetic
ashr i64, and sign-extends a 32-bit literal as gfx2hlsl.py's
i64_words(signed=True) does. v_mad_i32_i24 is
sext(S0[23:0]) * sext(S1[23:0]) + S2 modulo 2^32.

tests/native_signed_forms_check.py reuses the native_shift64 program
for six sources and six amounts and adds a multiply-add dispatch with
bit 23 set and nonzero upper bits. Its controls check the modules and
that zero-extended-literal, logical, unsigned and unmasked references
differ.

Refs #2991. AI-assisted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 03:39:28 +00:00
github-bot changed target branch from cpp-migration to gh-pr/2994/base 2026-11-27 03:51:26 +00:00
github manually merged commit f7a272209f into gh-pr/2994/base 2026-11-27 03:51:28 +00:00
Author
Owner

@⁠MasterDomino on GitHub · 2026-11-27 03:47 UTC · original · approved these changes

Review of head f7a27220. CI on the head is green. This is the wave32 SM 6.6 readback that was not measured on your adapter. Approving and merging.

Code read:

  • v_ashrrev_i64: it joins the 64-bit shift path and emits ashr i64. A 32-bit literal is sign-extended only for this form, as gfx2hlsl.py's i64_words(signed=True) does, while the logical shifts keep zero-extending it.
  • v_mad_i32_i24: (x << 8) >> 8 arithmetic on each source, then mul and add modulo 2^32.

Run on AMD: Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010), plus WARP, release. This was tested together with #2989, #2990 and #2992 merged onto cpp-migration 4ff5e36d; all four merge cleanly with each other. ctest --preset release --no-tests=error -R '^(native_.*|startup_compute_dispatch(_.*)?_(warp|hardware)|startup_slot67_indirect_dispatch_warp|startup_compute_translate_e2e_warp|startup_stream_draw.*|startup_native_graphics.*)$' gives 88 tests, 84 passed and 4 skipped (77, WARP has no 32-lane waves).

  • native_signed_forms_hardware passed: "v_ashrrev_i64 by 0, 1, 31, 32, 33 and 63: all 6 sources and guards matched", and "v_mad_i32_i24: 64 words of two groups and the guards matched".
  • native_signed_forms_controls, native_shift64_controls and native_shift64_hardware passed, so the logical shifts are unchanged.

Mutations here:

  • Emitting lshr for v_ashrrev_i64 fails native_signed_forms_hardware: inline -1 shifted by 1 got 0x7fffffff in the high word.
  • Zero-extending the 24-bit factors of v_mad_i32_i24 fails it too ((8, '0x6f000000', '0x91000000')).
  • With each restored, it passes.

Open, not blocking: the literal extension is inherited from the Python translator and is not measured on the console. Signedness-dependent extension of a 64-bit integer literal is an assumption. The fixture's literal case pins it, so a later measurement will show up as a fixture change. I will close #2991 by hand.

AI-assisted; the commands above were run locally.

**@⁠MasterDomino** on GitHub · 2026-11-27 03:47 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2994#pullrequestreview-6083201248) · **approved these changes** Review of head `f7a27220`. CI on the head is green. **This is the wave32 SM 6.6 readback that was not measured on your adapter.** Approving and merging. **Code read:** - **`v_ashrrev_i64`:** it joins the 64-bit shift path and emits `ashr i64`. A 32-bit literal is sign-extended only for this form, as `gfx2hlsl.py`'s `i64_words(signed=True)` does, while the logical shifts keep zero-extending it. - **`v_mad_i32_i24`:** `(x << 8) >> 8` arithmetic on each source, then `mul` and `add` modulo 2^32. **Run on AMD:** Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010), plus WARP, release. This was tested together with #2989, #2990 and #2992 merged onto `cpp-migration` `4ff5e36d`; all four merge cleanly with each other. `ctest --preset release --no-tests=error -R '^(native_.*|startup_compute_dispatch(_.*)?_(warp|hardware)|startup_slot67_indirect_dispatch_warp|startup_compute_translate_e2e_warp|startup_stream_draw.*|startup_native_graphics.*)$'` gives 88 tests, 84 passed and 4 skipped (77, WARP has no 32-lane waves). - `native_signed_forms_hardware` **passed**: "v_ashrrev_i64 by 0, 1, 31, 32, 33 and 63: all 6 sources and guards matched", and "v_mad_i32_i24: 64 words of two groups and the guards matched". - `native_signed_forms_controls`, `native_shift64_controls` and `native_shift64_hardware` passed, so the logical shifts are unchanged. **Mutations here:** - Emitting `lshr` for `v_ashrrev_i64` fails `native_signed_forms_hardware`: inline -1 shifted by 1 got `0x7fffffff` in the high word. - Zero-extending the 24-bit factors of `v_mad_i32_i24` fails it too (`(8, '0x6f000000', '0x91000000')`). - With each restored, it passes. **Open, not blocking:** the literal extension is inherited from the Python translator and is not measured on the console. Signedness-dependent extension of a 64-bit integer literal is an assumption. The fixture's literal case pins it, so a later measurement will show up as a fixture change. I will close #2991 by hand. AI-assisted; the commands above were run locally.
This discussion has been locked. Commenting is limited to contributors.
No description provided.