startup: lower v_mul_hi_i32 and s_mul_hi_i32 in gfx2hlsl #2397
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2405"
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 R0D4X on 2026-11-25T15:26:43Z.
Summary
v_mul_hi_i32VOP3A ands_mul_hi_i32SOP2, SCC unchanged) intools/startup/gfx2hlsl.py, completing the signed counterpart tos_mul_hi_u32(#2176) andv_mul_hi_u32(#1747).Pipeline.common()'s existingmul_hi_u32(uint a, uint b)helper via a one-line signed correction (mul_hi_i32(a, b) = mul_hi_u32(a, b) - ((a >> 31) != 0u ? b : 0u) - ((b >> 31) != 0u ? a : 0u)), avoiding any duplicate halfword-product helper.s_mul_hi_u32's whole-word, lane-mask,vcc/exec, symbolic-source, and bounds guards tos_mul_hi_i32, and add an explicit 3-operand count guard fors_mul_hi_{u,i}32so malformed forms raiseUnsupportedinstead ofIndexError.tests/startup_gfx2hlsl_mul_hi_i32_check.pywith:mul_hi_i32helper over a 361-pair edge grid (includingINT_MIN * INT_MIN,INT_MIN * -1,-1 * -1, mixed signs) against((s32(a) * s32(b)) >> 32) & 0xffffffff, sign-correction drop controls, unsigned-multiply mutation controls,exec-masked emission,s_mul_hi_i32SOP2 decode/lowering/mask-overwrite/refusals, and modifier/arity refusals.binary <llvm-mc>round-trip checks for the Ubuntupixel-binaryCI job.draw <dxc> <offscreen_check> <warp|hardware> [fxc]end-to-end FXCps_5_1+ DXCps_6_0offscreen readbacks across 3 draw sets (12 pairs) plus an unsigned-multiply GPU mutation control.startup_gfx2hlsl_mul_hi_i32_{controls,warp,hardware}inCMakeLists.txtand wiretests/startup_gfx2hlsl_mul_hi_i32_check.pyintopixel-binaryandpython-linuxin.github/workflows/windows.yml.Verification
7092683a(upstream/main)29536aa310.0.26300.9974), MSVC19.44.35230, Windows SDK10.0.26100.0, FXC + DXC1.9.2602.17Microsoft Basic Render Driver(1414:008c), driver10.0.26100.9818, D3D12 debug layer enabledNVIDIA GeForce RTX 5080(10de:2c02), driver32.0.16.2124, D3D12 debug layer enabledCommands and Observed Results
startup_gfx2hlsl_mul_hi_i32_check.py: 17/17 checks ok;docs_links_check.py: 19 files / 464 links ok;bidi_controls_check.py: 1723 files ok;startup_tools_lint: passed).drop_sign_a,v_unsigned,s_unsigned,drop_arity_guard) caught (rc=1) and reverted cleanly.dev): 3 passed, 0 skipped, 0 failed (3.47 s:controls0.17 s,warp0.78 s,hardware2.46 s,debug_errors=0 debug_warnings=0).release): 3 passed, 0 skipped, 0 failed (3.02 s:controls0.17 s,warp0.67 s,hardware2.13 s).tests/startup_gfx2hlsl_mul_hi_i32_check.py binary llvm-mc-15was not run locally (llvm-mcis not installed on this Windows host); fixture words were cross-checked againsttools/disasm_rdna2.py/gfx2hlsl.decode()and are exercised by the Ubuntupixel-binaryCI job.v_mul_hi_i32/s_mul_hi_i32lowering and desktop GPU execution in isolation; they do not establish full-game startup.Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T15:43:03Z.
Six mutations, all caught — and the helper's formula checks out against a reference on 100 boundary pairs plus 20 000 random ones
Baseline:
tests/startup_gfx2hlsl_mul_hi_i32_check.pyexit 0.v_mul_hi_i32mapped tomul_hi_u32s_mul_hi_i32mapped tomul_hi_u32- (b if a<0)correction- (a if b<0)correction? a :instead of? b :)len(srcs) != 2refusal disabledThe last one is the one I did not expect to be pinned, because it guards a shape rather than a value; a check that only compared results would miss it.
Independent arithmetic check
The signed multiply-high is built on the unsigned one:
I evaluated that identity in Python against
(sext(a) * sext(b)) >> 32rather than trusting it:So the formula is right, including
INT_MIN x INT_MIN,INT_MIN x -1and the0x80000000sign boundary.Two things the check could add without touching production
1.
mul_hi_i32may already exist. The helper joinsmul_hi_u32in the same helper table, and the diff adds a second definition-shaped string. Ifpixel_aotemitsmul_hi_i32too, a later change to one and not the other would show up as a translation that compiles in one pipeline and not the other. Worth one grep before merge if you have not done it — I checked that the check itself only exercises thegfx2hlslhelper, so nothing pins the two against each other.2. The
word_packlist is now four entries long and hand-maintained.s_pack_hh_b32_b16,s_sext_i32_i8,s_sext_i32_i16,s_mul_hi_u32,s_mul_hi_i32— the reason each is there is that the per-lane mask cannot supply the whole word. A dictionary ({base: reason}) instead of a tuple would keep the reason next to the entry when the sixth one is added; the comment above it already carries the explanation for all of them together, which is fine until one entry needs a different reason.Neither is a blocker; the change is correct and the controls are stronger than most.
AI-assisted; the six mutations and the arithmetic check were run locally on Windows 11 build 26300.9974.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-25T15:55:22Z.
APPROVED: +12/-6 gfx2hlsl.py adding signed mul_hi_i32 via mul_hi_u32+sign correction. word_pack/mask_dest/arity guard updated. 303-line test with 361-pair grid, mutations, GPU draws. ChazY11 review verified formula on 20K pairs and 6 mutations. No game files.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T16:57:15Z.
Closing the loop on the note above:
pixel_aotalready ships the same helper, and the two copies agree todayI flagged in my first comment that
mul_hi_i32may already exist elsewhere. It does:and the
mul_hi_u32under it (pixel_aot.py:850) is the same 16-bit carry decomposition asgfx2hlsl.py:5088, written out with longer names and a comment. So this PR adds the third copy of a formula that already exists twice:The two
mul_hi_i32bodies are textually different (variable names, comment, line breaks) and semantically identical, which is the pairing that drifts: a fix to one reads as "already handled" to anyone looking at the other. I checked that the arithmetic matches rather than assuming it — evaluating both forms against(sext(a) * sext(b)) >> 32over the 100 boundary pairs and 20 000 random pairs gives zero mismatches for either.Two ways to keep them together, in the order I would try them:
pixel_aot's version is the older one, importing it from the other module keeps a single definition and this PR shrinks.precise/legacymoded helpers nearby suggest the two files are not ready to share), a check that evaluates bothmul_hi_i32strings over the same boundary table and compares the results would catch drift without demanding identical text — the text differs legitimately (ftz32andmad32already do, andmad32differs by a wholelegacyargument).I looked at a text-equality check first and dropped it: comparing the six function names the two files share (
class16,class32,ftz32,mad32,mul_hi_u32,pack16_rne) shows four of them legitimately different, so "same name ⇒ same text" would be wrong. Behaviour comparison is the version that survives.Nothing here blocks the PR as it stands.
AI-assisted; the comparison and the arithmetic check were run locally on
mainate06aca8bplus this branch.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T18:31:41Z.
Review: COMMENTED
Review of head
29536aa3(comment only, no approval).Code (tools/startup/gfx2hlsl.py): the signed correction
mul_hi_u32(a,b) - (a<0 ? b : 0) - (b<0 ? a : 0)is the standard identity and is correct modulo 2^32.v_mul_hi_i32(VEC_U) ands_mul_hi_i32(SCA) sit next to their unsigned siblings. The whole-word, lane-mask, vcc/exec and bounds guards ofs_mul_hi_u32are reused. The new operand-count guard also covers the unsigned form. SCC stays unchanged, as for the unsigned op.Test: the new check covers the helper over a 361-pair edge grid (INT_MININT_MIN, INT_MIN-1, -1*-1, mixed signs), refusals, and WARP/hardware readback with an unsigned-multiply mutation control. It is registered in CMakeLists.txt (controls, warp, hardware) and in both lists in windows.yml. The PR's own CI run exercised the changed workflow: pixel-binary, python-linux and the Windows build are green.
Siblings and duplicates: v_mul_hi_u32 and s_mul_hi_u32 are already handled. A search for other open or merged PRs on mul_hi_i32 found none. #532 (draft) and #1278 (merged) cover other integer multiplies. No "depends on" in the body.
Windows results: the body lists WARP and hardware runs on branch commit
29536aa3, which is this exact head. I did not run Windows and did not re-check those results. No startup claim is made. The PR is 30 commits behind main and I did not update it, to keep the head SHA.Commands run locally on this head:
bsign-correction term. The test fails at "emitted helper matches reference on 361 edge pairs".s_mul_hi_i32from the whole-word list. The test fails at "mask-marked SGPR source refused".No blocking findings. Merge is left to @R0Y00 / MasterDomino.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:11:24Z.
Pushed
570e4ea7f: merged currentmaininto this branch (no rebase, no force) so it no longer conflicts.Conflicts resolved, keeping both sides:
tools/startup/gfx2hlsl.py:s_mul_hi_i32joinss_mul_hi_u32in the whole-word / operand-count guards;v_mul_hi_i32sits next tov_mul_hi_u32inVEC_U;mul_hi_i32helper added beside the newfma16o/f16rnhelpers.CMakeLists.txtand.github/workflows/windows.yml: the mul_hi_i32 tests/entry next to main's new ones.Verification:
python3 tests/startup_gfx2hlsl_mul_hi_i32_check.py,tests/startup_gfx2hlsl_mul_hi_check.py,tests/startup_gfx2hlsl_sop2_complement_check.py: pass.x2w_pipe.py win2025 2405 --patch <merge diff> --regex startup_gfx2hlsl_mul_hi: 6/6 passed (mul_hi_i32 controls, warp, hardware; mul_hi controls, warp, hardware).AI-assisted; commands listed were executed locally.