shader: lower compute v_mad_i32_i24 #1589
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1596"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T14:41:36Z.
Change
Refs #1546. This lowers
v_mad_i32_i24in the compute translator (tools/compute_store_aot.py). It is the signed counterpart of the existingv_mad_u32_u24:v_mad_i32_i24 vD, a, b, ccomputessext(a[23:0]) * sext(b[23:0]) + c, modulo 2^32.cis a full 32-bit word.((asuint(asint({0} << 8u) >> 8u) * asuint(asint({1} << 8u) >> 8u)) + {2}). The multiply and the add are done inuint, which gives the same low 32 bits as the signed product and avoids signed-overflow questions.ALUentry, and the opcode appended to the three-source matcher group as(v_mad_u32_u24|v_mad_i32_i24). Thev_mad_u32_u24row-pitch branch is unchanged and still matches only the unsigned form.tests/compute_store_check.pyhad a negative control that expectedv_mad_i32_i24to be refused. Since the opcode is now supported, that control is replaced by the still-unsupported signed 24-bit multiply,v_mul_i32_i24_e32. The control keeps its purpose. The diff is one line; nothing else in that file changes.Fixture. The fixture is in a new
tests/compute_alu_mad_i24_check.py, which imports the helpers oftests/compute_store_check.py. It isREAD_COMPUTEwith its ALU lines replaced.cap = params[0].y = 0x5a876543, which is negative as a 24-bit multiplicand.The inputs exercise the sign and the masking:
ain 74 of the 150 lanes;The expected words come from a separate Python model with exact integers. Three lanes are worked out by hand:
0xab528010a0x9d457413w0xda21042fThese must be rejected:
Controls. These are refused with the existing messages:
clamp,-v1,|v1|,-|s0|and the_e64spelling;v[1:2];v256;v_mul_i32_i24_e32andv_mad_i64_i32;v_mad_u32_u24still lowers to the unsigned expression, and its byte-offset form still givesUnverified row pitch byte offset.The new CTest is
compute_store_aot_alu_mad_i24_${adapter}, registered aftercompute_store_aot_mtbuf_load.docs/experiments.mdgains a "Signed 24-bit multiply-add" subsection, andv_mad_i32_i24is removed from its "stops the lowering" list.Verification
Commit
6c0e5380(main) plus this change,devpreset, Windows 11 Pro build 26300.9974, DXC 1.8.2502.11.1002:73ff), driver 32.0.21045.29003, debug layer enabledtests/docs_links_check.py,tests/bidi_controls_check.py,tests/form_coverage_check.pyandgit diff --checkpass. I did not run the LLVM 15binarymode.Notes
v_mad_u32_u24docs and the GCN/RDNA definition. The AMD ISA PDF could not be fetched from this machine.llvm-mc19 confirms VOP3 opcode 0x142 (the u24 form is 0x143) and refuses neg/abs on it.Unsupported compute instruction: …rather thanUnverified ALU operand. This comes from the existing guard on the shared matcher group.Checklist
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T14:50:43Z.
Review: COMMENTED
Reviewed commit
c634ce57c9dd84f6757a9e212b0f6b747c3a2b0c(shader: lower compute v_mad_i32_i24). No defects found.Technical review
tools/compute_store_aot.py):v_mad_i32_i24lowers to((asuint(asint({0} << 8u) >> 8u) * asuint(asint({1} << 8u) >> 8u)) + {2}), which sign-extends bits[23:0]of both multiplicands via arithmetic shift and computes the modulo-2^32 product and add inuint. Byte-offset operands remain restricted tov_mad_u32_u24.tests/compute_alu_mad_i24_check.py,tests/compute_store_check.py): Exercises VGPR, SGPR, literal (with nonzero top byte), and negative inline-constant sources, checks hand-computed lanes (0,3,31), rejects modifiers (clamp,-v,|v|,_e64), invalid/pending sources,v256destination, neighbouring opcodes (v_mul_i32_i24_e32,v_mad_i64_i32), and verifies CPU-reference and HLSL-mutation failures.Verification
python3 -B tests/compute_alu_mad_i24_check.py controls— passed.python3 -B tests/compute_store_check.py binary llvm-mc-19 llvm-objcopy-19 libLLVM-19.so— passed.python3 tests/docs_links_check.py— passed (16 Markdown files, 344 links).python3 tests/bidi_controls_check.py— passed (1253 files).--preset dev,offscreen_check): 47/47 passed, includingcompute_store_aot_alu_mad_i24_warp(3.74s)./O2(--preset release,offscreen_check): 47/47 passed (66.25s), includingcompute_store_aot_alu_mad_i24_warp(4.21s).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:08:27Z.
Review: COMMENTED
Re-review at
head_sha:8bf16dff04a55ece8e6862af42f773d69fe9f80b(previously reviewed atc634ce57).Findings
No P1/P2. No defect found.
main. I compared the patch of the old commit with the patch of this one (git range-diff, and a diff of the added and removed lines): the PR's own content is unchanged. The only non-context difference is the opcode list in the three-sourcere.fullmatchoflower(): it now readsv_mad_u32_u24|v_xor3_b32|v_max3_u32|v_min3_u32|v_med3_u32|v_med3_i32|v_mad_i32_i24, i.e.v_mad_i32_i24is appended after the opcodes that landed on main in the meantime. I checked that no other opcode was dropped from that list.git merge-treeof the head against currentmain(80f413a7at the time) reports no conflicts (tree83a10ca4).Verified
Limits: Linux x86-64 only. I did not rerun the Windows WARP/hardware
ctestfor this head (no Windows runner in this pass), so thedrawmode is covered only by the unchanged patch content and the earlier Windows results on the previous head.python3 -B tests/compute_alu_mad_i24_check.py controls-> exit 0.llvm-mc-19 -triple=amdgcn-amd-amdhsa -mcpu=gfx1013 -show-encodingassemblesv_mad_i32_i24 v1, v2, v3, v4andv_mad_i32_i24 v1, s2, -1, 0x1234567.python3 -B tests/docs_links_check.py-> 16 files, 351 links OK.git diff --check HEAD^ HEADclean.>> 8uto>> 7ufor the first multiplicand ofv_mad_i32_i24;controlsfails with anAssertionError(exit 1). Restored withgit checkout -- .;git status --shortclean.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:27:25Z.
Review: COMMENTED
Verified at
head_sha:8bf16dff04a55ece8e6862af42f773d69fe9f80b(shader: lower compute v_mad_i32_i24). No P1/P2 defects found.Technical check
tools/compute_store_aot.py,tests/compute_alu_mad_i24_check.py,tests/compute_store_check.py,CMakeLists.txt(test-only),docs/experiments.md. Nosrc/,gfx2hlsl.py, or.github/edits.v_mad_i32_i24lowers to((asuint(asint({0} << 8u) >> 8u) * asuint(asint({1} << 8u) >> 8u)) + {2}), matching RDNA2sext24(S0) * sext24(S1) + S2modulo 2^32. All operands produced byalu_wordare atomic or parenthesized.Verification
git diff --check origin/main...HEAD— clean.python3 -B tests/docs_links_check.py— passed (16 Markdown files, 351 links).python3 -B tests/bidi_controls_check.py— passed (1280 files).python3 -B tests/compute_alu_mad_i24_check.py controls— passed.python3 -B tests/compute_store_check.py binary llvm-mc-19 llvm-objcopy-19 libLLVM-19.so— passed.tools/compute_store_aot.py):asint({0} << 8u) >> 8uwith({0} & 0xffffffu)->tests/compute_alu_mad_i24_check.py controlsfailed (AssertionError).asint({1} << 8u) >> 8uwithasint({1} << 8u) >> 7u->tests/compute_alu_mad_i24_check.py controlsfailed (AssertionError).git checkout -- tools/compute_store_aot.py.--preset dev): 59/59 passed (82.02s), includingcompute_store_aot_alu_mad_i24_warp./O2(--preset release): 59/59 passed (81.12s), includingcompute_store_aot_alu_mad_i24_warp(4.69s).AI-assisted; commands listed were executed locally.