startup: v_mul_hi_u32 has no lowering (1 of the remaining loading-screen shader refusals) #1785

Closed
opened 2026-11-24 18:43:49 +00:00 by triggered02 · 2 comments
triggered02 commented 2026-11-24 18:43:49 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T18:43:49Z.


Found in the refreshed refusal census on main (#870 thread). 1 refused shader, and the operation had no lowering at all.

Problem

v_mul_hi_u32 (the high 32 bits of an unsigned 32x32 product) was refused outright, including the census form with a literal operand:

v_mul_hi_u32 v1, v0, 0xaaaaaaab
-> REFUSED: v_mul_hi_u32

tools/pixel_aot.py already implements this operation for the pixel AOT path with a halfword-product helper; tools/startup/gfx2hlsl.py did not have it.

Fix

The lowering calls a helper added to the shader preamble:

uint mul_hi_u32(uint a, uint b) {
    uint la = a & 0xffffu, lb = b & 0xffffu;
    uint middle = (a >> 16) * lb + ((la * lb) >> 16);
    return (a >> 16) * (b >> 16) + (middle >> 16) + (((middle & 0xffffu) + la * (b >> 16)) >> 16);
}

It is computed from halfword products because these shader stages have no 64-bit multiply, and the low half of a * b is not the high half — so a plain * would be silently wrong.

Measured

VOP3A encodings built in the test (0b110101 prefix, opcode 0x16a), main at b9f355f1:

form before after
v_mul_hi_u32 v1, v1, v2 refused v1 = mul_hi_u32(v1, v2);
v_mul_hi_u32 v1, v0, 0xaaaaaaab refused v1 = mul_hi_u32(v0, 0xaaaaaaabu);
v_mul_lo_u32 v1, v1, v2 v1 = v1 * v2; unchanged

Done when

  • Both the register form and the literal form lower to the helper.
  • The helper is in the preamble the generated shader is built with, and uses halfword products.
  • A ctest starts from synthetic encoded instructions, decodes, then translates, and fails if the lowering uses a plain multiply or the helper is missing.
  • docs/experiments.md records the change.

Not in this slice: v_mul_hi_i32 (its signed correction), the 24-bit _u24 forms, and DXC/draw results.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6588927416 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1792). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T18:43:49Z. --- Found in the refreshed refusal census on main (#870 thread). **1** refused shader, and the operation had no lowering at all. ## Problem `v_mul_hi_u32` (the high 32 bits of an unsigned 32x32 product) was refused outright, including the census form with a literal operand: ``` v_mul_hi_u32 v1, v0, 0xaaaaaaab -> REFUSED: v_mul_hi_u32 ``` `tools/pixel_aot.py` already implements this operation for the pixel AOT path with a halfword-product helper; `tools/startup/gfx2hlsl.py` did not have it. ## Fix The lowering calls a helper added to the shader preamble: ```hlsl uint mul_hi_u32(uint a, uint b) { uint la = a & 0xffffu, lb = b & 0xffffu; uint middle = (a >> 16) * lb + ((la * lb) >> 16); return (a >> 16) * (b >> 16) + (middle >> 16) + (((middle & 0xffffu) + la * (b >> 16)) >> 16); } ``` It is computed from halfword products because these shader stages have no 64-bit multiply, and the low half of `a * b` is not the high half — so a plain `*` would be silently wrong. ## Measured VOP3A encodings built in the test (`0b110101` prefix, opcode `0x16a`), `main` at `b9f355f1`: | form | before | after | |---|---|---| | `v_mul_hi_u32 v1, v1, v2` | refused | `v1 = mul_hi_u32(v1, v2);` | | `v_mul_hi_u32 v1, v0, 0xaaaaaaab` | refused | `v1 = mul_hi_u32(v0, 0xaaaaaaabu);` | | `v_mul_lo_u32 v1, v1, v2` | `v1 = v1 * v2;` | unchanged | ## Done when - Both the register form and the literal form lower to the helper. - The helper is in the preamble the generated shader is built with, and uses halfword products. - A ctest starts from **synthetic** encoded instructions, decodes, then translates, and fails if the lowering uses a plain multiply or the helper is missing. - `docs/experiments.md` records the change. Not in this slice: `v_mul_hi_i32` (its signed correction), the 24-bit `_u24` forms, and DXC/draw results. AI-assisted (Claude Code).
winne42 commented 2026-11-25 07:01:14 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by winne42 on 2026-11-25T06:45:25Z.


I compared #1747 (f2e319ce) and #1793 (6782e724) on top of current main (1949b265). This adds to the comparison on #1793 and the maintainer's merge note on #1747. The new part is what each test does once the PR is rebased onto the helper main already has from #2176.

Translator change: both PRs add the same VEC_U entry, 'v_mul_hi_u32': (2, 'mul_hi_u32({0}, {1})'). After a rebase, neither should add a helper of its own:

  • #1793's helper text is byte-identical to main's, so its gfx2hlsl.py hunk reduces to the VEC_U line.
  • #1747's helper (al/bl/m) merges into gfx2hlsl.py without a textual conflict. The result defines mul_hi_u32 twice, which is the FXC/DXC redefinition noted in the review on #1747. A plain rebase that keeps both sides would not show it until the shader compiles.

Each PR's own test on the resolved merge (main + the VEC_U line + the PR's tests/startup_gfx2hlsl_mul_hi_check.py, default mode, Linux, Python 3):

#1747 #1793
default mode fails: eval_emitted_helper matches only uint al = …, bl = …, m = … and asserts on main's la/lb/middle body passes, 20169 helper pairs

So #1747 also needs its test parser ported to main's helper. The review on #1747 says that was done locally, but the PR head doesn't have it yet.

Mutation controls on the #1793 candidate. Each mutation went into main's helper or the lowering, and each one made the test fail:

drop the low-product carry ((la * lb) >> 16)   caught
(middle >> 16) -> (middle & 0xffffu)           caught
lower to '{0} * {1}'                           caught
remove the lowering (refused)                  caught

Against the "Done when" list in this issue:

item #1747 #1793
register and literal forms lower to the helper yes (literal 0x12345678) yes (census literal 0xaaaaaaab)
helper in the preamble, halfword products yes, but needs to reuse main's yes (identical to main's)
ctest from synthetic encodings, fails on plain multiply or missing helper yes, plus an LLVM 15 binary mode yes
docs/experiments.md records the change no yes
WARP and hardware draw (not required here) yes, verified by the maintainer on WARP and RTX 4060 Laptop no

Nits: #1793's CMake comment cites #1781, a merged DirectStorage PR, instead of #1792. #1747 also adds binary llvm-mc-15 to the Linux job in windows.yml, and that hunk conflicts with main too.

Summary: #1793 is the smaller rebase, because it only drops its helper hunk. #1747 has the stronger evidence, its WARP and hardware draws, but it needs the helper removed, the test parser ported and a docs entry. A combined result could take #1747's draw modes and #1793's value-level evaluator and docs row. Which one lands is the maintainer's call.

Not run here: either draw (no Windows or D3D12 on this host) and #1747's binary mode (this host has LLVM 21/22, not 15).

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7155124525 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1792#issuecomment-7155124525). Originally posted by [winne42](https://github.com/winne42) on 2026-11-25T06:45:25Z. --- I compared #1747 (`f2e319ce`) and #1793 (`6782e724`) on top of current `main` (`1949b265`). This adds to the comparison on #1793 and the maintainer's merge note on #1747. The new part is what each test does once the PR is rebased onto the helper `main` already has from #2176. **Translator change:** both PRs add the same `VEC_U` entry, `'v_mul_hi_u32': (2, 'mul_hi_u32({0}, {1})')`. After a rebase, neither should add a helper of its own: - #1793's helper text is byte-identical to `main`'s, so its `gfx2hlsl.py` hunk reduces to the `VEC_U` line. - #1747's helper (`al`/`bl`/`m`) merges into `gfx2hlsl.py` **without a textual conflict**. The result defines `mul_hi_u32` twice, which is the FXC/DXC redefinition noted in the review on #1747. A plain rebase that keeps both sides would not show it until the shader compiles. **Each PR's own test on the resolved merge** (`main` + the `VEC_U` line + the PR's `tests/startup_gfx2hlsl_mul_hi_check.py`, default mode, Linux, Python 3): | | #1747 | #1793 | |---|---|---| | default mode | **fails**: `eval_emitted_helper` matches only `uint al = …, bl = …, m = …` and asserts on `main`'s `la`/`lb`/`middle` body | passes, 20169 helper pairs | So #1747 also needs its test parser ported to `main`'s helper. The review on #1747 says that was done locally, but the PR head doesn't have it yet. **Mutation controls on the #1793 candidate.** Each mutation went into `main`'s helper or the lowering, and each one made the test fail: ``` drop the low-product carry ((la * lb) >> 16) caught (middle >> 16) -> (middle & 0xffffu) caught lower to '{0} * {1}' caught remove the lowering (refused) caught ``` **Against the "Done when" list in this issue:** | item | #1747 | #1793 | |---|---|---| | register and literal forms lower to the helper | yes (literal `0x12345678`) | yes (census literal `0xaaaaaaab`) | | helper in the preamble, halfword products | yes, but needs to reuse `main`'s | yes (identical to `main`'s) | | ctest from synthetic encodings, fails on plain multiply or missing helper | yes, plus an LLVM 15 `binary` mode | yes | | `docs/experiments.md` records the change | **no** | yes | | WARP and hardware draw (not required here) | yes, verified by the maintainer on WARP and RTX 4060 Laptop | no | Nits: #1793's CMake comment cites `#1781`, a merged DirectStorage PR, instead of #1792. #1747 also adds `binary llvm-mc-15` to the Linux job in `windows.yml`, and that hunk conflicts with `main` too. Summary: #1793 is the smaller rebase, because it only drops its helper hunk. #1747 has the stronger evidence, its WARP and hardware draws, but it needs the helper removed, the test parser ported and a docs entry. A combined result could take #1747's draw modes and #1793's value-level evaluator and docs row. Which one lands is the maintainer's call. Not run here: either draw (no Windows or D3D12 on this host) and #1747's `binary` mode (this host has LLVM 21/22, not 15). AI-assisted (Claude Code).
R0Y00 commented 2026-11-25 19:04:14 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T18:40:00Z.


#1747 landed at e06aca8b. The startup translator now lowers both register and encoded literal forms through the existing halfword helper. The source-built tests include the exact 0xaaaaaaab example, LLVM round trip, the carry and low-word controls, and FXC/DXC readback. Windows Release 5/5 passed on WARP and RTX 4060 Laptop, and the required cloud checks passed for the merged candidate. This closes the original lowering scope.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7171224701 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1792#issuecomment-7171224701). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T18:40:00Z. --- #1747 landed at `e06aca8b`. The startup translator now lowers both register and encoded literal forms through the existing halfword helper. The source-built tests include the exact 0xaaaaaaab example, LLVM round trip, the carry and low-word controls, and FXC/DXC readback. Windows Release 5/5 passed on WARP and RTX 4060 Laptop, and the required cloud checks passed for the merged candidate. This closes the original lowering scope.
Sign in to join this conversation.
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#1785
No description provided.