Skip to content

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

Done

Description

@triggered02

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).

Activity

  1. winne42 commented on Nov 25, 2026

    @winne42
    Contributor

    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:

    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).

  2. R0Y00 commented on Nov 25, 2026

    @R0Y00
    Owner

    #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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions