Repository navigation
startup: lower v_mul_hi_u32 in gfx2hlsl - #1747
Conversation
tedin7
left a comment
There was a problem hiding this comment.
Peer review at commit 6c6b638e05aa92412733b1f332c66980c5ea297c (PRODUCTION_REVIEW_ONLY).
Assessment
No P1/P2 issues found.
- Semantics & overflow safety (
tools/startup/gfx2hlsl.py):v_mul_hi_u32is added toVEC_U(mul_hi_u32({0}, {1})) and lowered via a 16-bit halfword-splitmul_hi_u32(uint a, uint b)helper inPipeline.common(). Every intermediate term (al * bl,(a >> 16) * bl + ((al * bl) >> 16), and(m & 0xffffu) + al * (b >> 16)) is bounded strictly below2^32, avoiding 32-bit unsigned wraparound across all edge cases including0xffffffff * 0xffffffff(0xfffffffe). Unmodeled modifiers (clamp,mul:2,div:2,op_sel,-v,|v|) and wrong operand counts remain refused.
Verification
- Linux checks:
python3 -B tests/startup_gfx2hlsl_mul_hi_check.py→ 8/8 checksok(361-pair edge grid, carry-drop negative control, low-word mutation control,exec-masked emission, modifier/operand-count refusals)python3 -B tests/startup_gfx2hlsl_mul_hi_check.py binary llvm-mc-19→fixture words match llvm-mcpython3 -B tests/startup_gfx2hlsl_operand_count_check.py→operand count checks: 0 failed(32VEC_F, 35VEC_U)python3 -B tests/docs_links_check.py→Checked 17 Markdown files and 365 links.python3 -B tests/bidi_controls_check.py→Checked 1298 tracked source, script and build/CI files: no bidirectional controls.
- Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at
6c6b638e05aa92412733b1f332c66980c5ea297c:- Debug (
--preset dev):cmake --build --preset dev --target offscreen_check -- -j 8(3.47s),ctest --preset dev -R '^(startup_gfx2hlsl_mul_hi_controls|startup_gfx2hlsl_mul_hi_warp|startup_gfx2hlsl_operand_count|startup_translator)$' --parallel 6 --no-tests=error --output-on-failure→ 4/4 passed (1.11s). - Release
/O2(--preset release):cmake --build --preset release --target offscreen_check -- -j 8(1.10s),ctest --preset release -R '^(startup_gfx2hlsl_mul_hi_controls|startup_gfx2hlsl_mul_hi_warp|startup_gfx2hlsl_operand_count|startup_translator)$' --parallel 6 --no-tests=error --output-on-failure→ 4/4 passed (1.15s).
- Debug (
- Local mutation checks (each reverted immediately):
- Replaced
+ ((al * bl) >> 16)with+ 0uinmul_hi_u32(tools/startup/gfx2hlsl.py) → caught bytests/startup_gfx2hlsl_mul_hi_check.py(rc=1:emitted helper matches reference on 361 edge pairs: MISMATCH). - Lowered
v_mul_hi_u32to{0} * {1}inVEC_U(tools/startup/gfx2hlsl.py) → caught bytests/startup_gfx2hlsl_mul_hi_check.py(rc=1:four lane calls emitted: MISMATCH).
- Replaced
AI-assisted; commands listed were executed locally.
6c6b638 to
f2e319c
Compare
tedin7
left a comment
There was a problem hiding this comment.
Re-review of #1747 at exact head f2e319ce82111d2aec0c39a0ccabcb9ebb4ad652 (fetched from pull/1747/head, HEAD equals current headRefOid; no conflicts with current main). The previous review was at 6c6b638e.
Verdict: no P1/P2 found. Comment only, not an approval.
What changed since the last review
- The head moved only through merges of
main. I diffed the PR's own change (git diff origin/main...<head>fortools/startup/gfx2hlsl.py,tests/startup_gfx2hlsl_mul_hi_check.py,CMakeLists.txt,.github) at both heads: the same 203 added/removed lines, only hunk positions and context differ.git diff 6c6b638e HEAD -- tests/startup_gfx2hlsl_mul_hi_check.pyis empty. - Helper arithmetic re-derived by hand:
m = ah*bl + ((al*bl)>>16)is at most2^32 - 2^17 + 1 + 2^16 - 2, and(m & 0xffff) + al*bhis at most65535 + 2^32 - 2^17 + 1; both stay below2^32, so no 32-bit wraparound, and the sum equals the true high word.
Commands run locally
git diff --check origin/main...HEAD-> exit 0python -B tests/startup_gfx2hlsl_mul_hi_check.py-> 8 checks, allok(361-pair edge grid, carry-drop control, lane mutation control, exec-masked emission, modifier and operand-count refusals)python -B tests/startup_gfx2hlsl_mul_hi_check.py binary llvm-mc-19->fixture words match llvm-mc(llvm-mc-19, the only one on this host; CI pinsllvm-mc-15)startup_gfx2hlsl_operand_count_check.py->operand count checks: 0 failed;startup_translator_check.py->0 failed;startup_gfx2hlsl_bit_alu_check.py-> okdocs_links_check.py->Checked 18 Markdown files and 376 links;bidi_controls_check.py->Checked 1331 tracked source, script and build/CI files: no bidirectional controls
Mutations (applied to tools/startup/gfx2hlsl.py, suite re-run, then git checkout -- .)
| Mutation | Result |
|---|---|
drop + ((al * bl) >> 16) from the helper |
killed (361-pair grid mismatch) |
lower v_mul_hi_u32 as {0} * {1} |
killed (four lane calls emitted) |
drop the (m >> 16) term |
killed (grid mismatch) |
final >> 16 of the cross term changed to >> 15 |
killed (grid mismatch) |
4/4 killed.
Not run (honest limits)
- The FXC/DXC compile and D3D12 draw cases (
startup_gfx2hlsl_mul_hi_warp|hardware) need DXC,offscreen_checkand a D3D12 adapter, none on this Linux host. I did not re-run the Windows results quoted in the earlier review; they were taken at6c6b638e, and since the PR's own diff is unchanged I have no reason to expect a difference, but they are not reproduced at this head by me.
AI-assisted; commands listed were executed locally.
R0Y00
left a comment
There was a problem hiding this comment.
I tested a local merge into 8150d800. The conflicts are in CMakeLists.txt and .github/workflows/windows.yml; the existing registrations and all three new tests fit together. There is also a semantic merge conflict: main already emits a mul_hi_u32 HLSL helper for s_mul_hi_u32. Keeping the helper from both sides produces a function redefinition in FXC (X3003) and DXC. I kept main’s helper, pointed the vector lowering at it, and updated the carry mutation to exercise the shared helper and assert there is exactly one definition.
The resulting Windows Release candidate passed ctest --test-dir <build> --no-tests=error -j 1 -R '^startup_gfx2hlsl_mul_hi_', 3 passed and 0 skipped. FXC and DXC matched all three readback sets on WARP (10.0.26100.9818) and RTX 4060 Laptop (32.0.16.1656), debug layers enabled with zero errors and warnings. Both low-word mutation controls diverged. The focused operand-count and handler-arity controls also passed. Please merge current main into the PR with both sets of registrations, and reuse main’s helper so the refreshed head can get CI.
|
I fast-forwarded the original branch to |
tedin7
left a comment
There was a problem hiding this comment.
Re-review of head aaea481e8b77290e3aa460999b7ff215ef1bfc7b (merge of current main; real diff vs main is 4 files, +233/-1).
Result: no P1, no P2.
Scope checked
tools/startup/gfx2hlsl.py:2922:v_mul_hi_u32added toVEC_Uasmul_hi_u32({0}, {1}). It reuses the existing halfword helper (:3190) already used bys_mul_hi_u32, so no new HLSL math. The helper is correct (high word = ah*bh + (middle>>16) + carry from the low-half cross term).- Modifiers (
clamp,mul:,div:,op_sel, neg/abs) and wrong operand counts stay refused. The exec-masked form is guarded. tests/startup_gfx2hlsl_mul_hi_check.py: CPU evaluation of the emitted helper over 361 edge pairs against(a*b)>>32, a carry-drop control, a low-word mutation control, and FXC 5_1 + DXC 6_0 draw readback on WARP and hardware. The CTest wiring (controls, warp, hardware, SKIP 77) and thewindows.ymlentries match sibling tests.- Clean-room and neutral title: OK. PR is mergeable.
Commands run locally (Linux, in a worktree at this head)
git diff --stat origin/main...HEAD: 4 files, 233 insertions, 1 deletionpython3 tests/startup_gfx2hlsl_mul_hi_check.py: all 8 controls ok, "Self-test passed."python3 tests/docs_links_check.py: 18 Markdown files, 417 links, okpython3 tests/bidi_controls_check.py: 1519 files, no bidi controlsgit diff --check origin/main...HEAD: clean- Mutation: changed the table entry to
mul_hi_u32({1}, {1}). The test failed ("four lane calls emitted"), so it kills the mutation. Reverted withgit checkout -- ..
Not run
binarymode (nollvm-mc-15locally) and thedrawmode (needs Windows). The Windows WARP/hardware draws should be confirmed by the CI job "Build and test on Windows". It was still pending when I checked, as were the Linux and fixture jobs. I did not queue a separate Win2025 run.
Nit (optional)
gfx2hlsl.py:2922: the line is already long. Puttingv_mul_hi_u32on its own line would make later diffs easier to read.
AI-assisted; commands listed were executed locally.
|
@R0D4X could you rebase this branch onto current Why: the PR page still reports 357 changed files against an old base ( Commands run locally on head No code changes requested; the content is unchanged by the rebase. AI-assisted; commands listed were executed locally. |
|
Ran head
On each adapter, all 8 checks printed ok, and both mutation controls failed as expected, so the shared For context on priority: in a local census of start-up shader requests (aggregate counts only), AI-assisted. |
aaea481 to
a60128b
Compare
|
Rebased onto current |
tedin7
left a comment
There was a problem hiding this comment.
Review of head a60128b49e07fec7257912b0829a8256a5c96a90.
P1: duplicate mul_hi_u32 helper, Linux CI is red
tools/startup/gfx2hlsl.py:3857adds a newuint mul_hi_u32(uint, uint)to the shared helper prelude.tools/startup/gfx2hlsl.py:3861already defines the same helper (from the mergeds_mul_hi_u32slice, #2176). The helper block is emitted into every translated shader.- Result: every shader gets two definitions of the same function. HLSL rejects that as a redefinition, so every draw would fail to compile, not only shaders using
v_mul_hi_u32. tests/startup_gfx2hlsl_sop2_complement_check.pyalready catches it. Itsmul_hi_helpercheck fails withAssertionError: return (a >> 16) * (b >> 16) + .... This is the failingRun platform-independent Python checks on Linuxjob.- Fix: delete the new helper at 3857-3858. Keep only the
'v_mul_hi_u32': (2, 'mul_hi_u32({0}, {1})')table entry, which reuses the existing helper. Then re-check that the new test still passes.
Otherwise fine
- The
VEC_Uentry is correct:v_mul_hi_u32is the high 32 bits of the unsigned 64-bit product. The newtests/startup_gfx2hlsl_mul_hi_check.pyalso covers exec masking, refused modifiers and wrong operand counts. It has WARP and hardware draw tests registered inCMakeLists.txt. - Mutation: changing the emitted call to
mul_hi_u32({1}, {0} + 1u)is killed by the lowering check (v_mul_hi_u32: four lane calls emitted). - Mergeable, title is neutral, no clean-room concerns seen.
- A Windows run is not worth queuing until the duplicate is removed. With it, the shaders cannot compile.
Commands executed locally
git diff --stat origin/main...HEAD: 4 files, +234/-1.python3 -B tests/startup_gfx2hlsl_mul_hi_check.py: controls pass.python3 -B tests/startup_gfx2hlsl_sop2_complement_check.py: FAIL (duplicate helper, see P1).python3 tests/docs_links_check.py: ok (447 links).python3 tests/bidi_controls_check.py: ok.git diff --check origin/main...HEAD: clean.- Mutation above, reverted with
git checkout -- ..
AI-assisted; commands listed were executed locally.
Remove the duplicate mul_hi_u32 definition introduced during rebase so v_mul_hi_u32 reuses the shared helper from R0Y00#2176.
tedin7
left a comment
There was a problem hiding this comment.
Review of head 2fadf5e (comment only, no approval or merge).
Scope: adds v_mul_hi_u32 to VEC_U in tools/startup/gfx2hlsl.py. It reuses the mul_hi_u32 helper already emitted for s_mul_hi_u32. It also adds tests/startup_gfx2hlsl_mul_hi_check.py, three CTest entries and CI wiring. The title is neutral and the clean-room and licence side looks fine.
Commands executed locally in the PR worktree:
git diff --stat origin/main...HEAD: 4 files, +231/-1.gh pr checks 1747: the Linux Python job FAILS. Windows build and test pass. The fixtures job passes.python3 -I -B tests/startup_gfx2hlsl_mul_hi_check.py: FAILS incontrols(), test line 124,assert dropped != text(AssertionError).python3 -I -B tests/docs_links_check.py: pass (18 files, 447 links).python3 -I -B tests/bidi_controls_check.py: pass.git diff --check origin/main...HEAD:tests/startup_gfx2hlsl_mul_hi_check.py:110has trailing whitespace.git merge-tree --write-tree origin/main HEAD: conflict in.github/workflows/windows.yml.
Findings:
P1: The new test fails on its own head, so the Linux CI check is red.
tests/startup_gfx2hlsl_mul_hi_check.py:123replaces the text'+ ((al * bl) >> 16)'.- The helper actually emitted in
gfx2hlsl.py(around line 3859) usesla,lbandmiddle. It has noalorbl. The replace changes nothing, and the assert at line 124 fires. - The "carry-drop" control never ran. Target the real expression, for example the
((la * lb) >> 16)term insidemiddle, and keep asserting that the mutated helper mismatches on0xffffffff * 0xffffffff.
P1: The PR is not mergeable. .github/workflows/windows.yml conflicts with main, so a rebase is needed.
P2: A real mutation of the new lowering could not be measured, because the baseline test already fails. Re-run the mutation of 'v_mul_hi_u32': (2, 'mul_hi_u32({0}, {1})') after the P1 fix.
P2: The draw tests (startup_gfx2hlsl_mul_hi_warp and _hardware) only mean something on Windows. A useful WARP result needs the fixed test, so I did not queue the Windows VM here.
Nit: trailing whitespace at test line 110, which git diff --check flags.
The lowering change itself is small and reuses the existing helper. It is the high 32 bits of an unsigned product on uint operands, which looks right. The blockers are the test and the merge state.
AI-assisted; commands listed were executed locally.
tedin7
left a comment
There was a problem hiding this comment.
Review of head 8ed83e67d9846af5e9221af3ce9fae1de727d03c (comment only).
Scope: one-line v_mul_hi_u32 entry in VEC_U of tools/startup/gfx2hlsl.py, reusing the existing mul_hi_u32 helper (already used by s_mul_hi_u32), plus a new check, CMake tests (controls, warp, hardware) and CI wiring.
Commands executed locally:
git diff --stat origin/main...HEAD: 4 files, +231/-1.gh pr checks 1747: Linux Python checks, gfx1013 fixtures and Windows build pass; coverage chart and /O2 skipped.python3 -B tests/startup_gfx2hlsl_mul_hi_check.py: all controls ok (361 edge pairs, refusal of modifiers and operand counts, exec-masked guard, mutation controls).python3 tests/docs_links_check.py: pass.python3 tests/bidi_controls_check.py: pass.git diff --check origin/main...HEAD: reports one finding (see P2).- Mutation 1: removed the carry term
(((middle & 0xffffu) + la * (b >> 16)) >> 16)from the helper ingfx2hlsl.py: check fails at "emitted helper matches reference on 361 edge pairs". - Mutation 2: changed the
v_mul_hi_u32lowering to({0} * {1}): check fails at "four lane calls emitted". Both reverted withgit checkout -- .. ... binary llvm-mc-15: not run,llvm-mc-15is not installed locally (CI covers it and passes). Windows WARP/hardware draw not run by me: the change is a one-line table entry on a helper already exercised bys_mul_hi_u32; the draw tests are wired in CTest for Win2025.
Math check: with a = ah2^16 + la and b = bh2^16 + lb, middle = ah*lb + (la*lb >> 16) fits in 32 bits (max 0xffff0xffff + 0xffff), and (middle & 0xffff) + la*bh also fits (max 0xffff + 0xffff^2 < 2^32). The high word is ahbh + (middle >> 16) + carry, which is correct.
Findings:
- P1: none.
- P2: none.
- nit:
git diff --checkflags trailing whitespace intests/startup_gfx2hlsl_mul_hi_check.py(line 110). Trivial to strip. - nit: the
windows.ymllist entry for the new check sits betweensopk_signextandscalar_brev_foldin the lint file list, not alphabetical. Cosmetic.
No clean-room or title concerns; title is neutral, PR is mergeable.
AI-assisted; commands listed were executed locally.
|
Re-ran the current head
The tree has exactly one AI-assisted. |
|
The halfword lowering also passes when backported to the legacy startup translator from base 2010abb0. I reused this PR's source-built v_mul_hi_u32 fixture through its check_draw entry point, loading the legacy translator and running offscreen_check on both backends.
|
|
Re-reviewed |
|
AMD data point for head
Also: #2425 adds the same AI-assisted; commands listed were executed locally. |
MasterDomino
left a comment
There was a problem hiding this comment.
Approving head 02328b26.
- Change: one
VEC_Uentry that reuses themul_hi_u32helper already onmainfors_mul_hi_u32. Exactly one helper definition is emitted. - CI: green on this head: Windows build and test, gfx1013 fixtures, Linux Python.
- Merge check: the head merges cleanly with current
main, checked locally withgit merge-tree. - Earlier verification: R0Y00's re-review at this head (Release 5/5 on WARP and RTX 4060 Laptop, LLVM round trip), and the NVIDIA Quadro, Intel Gen9 and RTX 4070 runs in this thread.
- Our run at this head: on Windows 11 build 26300, the controls,
binarywith llvm-mc 15.0.7, and FXC/DXC draws on WARP and an AMD Radeon RX 9070 XT (driver 32.0.32029.2010, debug layer on) all pass, and the low-word mutation diverges.
AI-assisted.
|
@R0Y00, a question about merging. I approved this PR at The rules on AI-assisted. |
|
@R0Y00, you can ignore my merge question above. This PR is now merged at It most likely wasn't a branch policy. Our AI-assisted. |
Refs #870
Summary
v_mul_hi_u32(VOP3A unsigned 32x32 -> high-32 vector multiply) intools/startup/gfx2hlsl.pyby adding it toVEC_Uand emitting an overflow-free 16-bit halfword-splitmul_hi_u32(uint a, uint b)helper inPipeline.common()(same decomposition astools/pixel_aot.py, portable across both FXCps_5_1and DXCps_6_0, which have no scalarumulintrinsic).clamp,mul:2,div:2,op_sel,-v,|v|) and wrong operand counts.tests/startup_gfx2hlsl_mul_hi_check.py(modeled ontests/startup_gfx2hlsl_bit_alu_check.py) with:mul_hi_u32helper against((a * b) >> 32), carry-drop negative control (0xffffffff * 0xffffffff), low-word mutation control,exec-masked emission check, and modifier/operand-count refusal controls.binary <llvm-mc>round-trip verification of all fixture encodings for the Ubuntupixel-binaryCI job.draw <dxc> <offscreen_check> <warp|hardware> [fxc]end-to-end FXCps_5_1+ DXCps_6_0offscreen readback tests across 3 draw sets (12 input pairs) plus a GPU low-word mutation control.startup_gfx2hlsl_mul_hi_controls,startup_gfx2hlsl_mul_hi_warp, andstartup_gfx2hlsl_mul_hi_hardwareinCMakeLists.txt, and wiretests/startup_gfx2hlsl_mul_hi_check.pyintopixel-binaryandpython-linuxin.github/workflows/windows.yml.Verification
9ffb8529(upstream/main)6c6b638e10.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_check.py: 8/8 checks ok;startup_gfx2hlsl_operand_count_check.py:0 failedacross 32VEC_Fand 35VEC_Uops;docs_links_check.py: 17 files / 365 links ok;bidi_controls_check.py: 1297 files ok).Observed: 3 passed, 0 skipped, 0 failed (3.20 s total):
startup_gfx2hlsl_mul_hi_controls: passed (0.13 s)startup_gfx2hlsl_mul_hi_warp: passed (0.66 s), both FXCps_5_1and DXCps_6_0matched expected readbacks (fffffffe,00000001,b092ab7b,00000001,00000000,00000000,0000fffe,0000ffff,3fffffff,40000001,0001fffd,52c48c43), low-word mutation failed as expected (actual=00000001,00000000,88cf5b62,00020001),debug_errors=0 debug_warnings=0.startup_gfx2hlsl_mul_hi_hardware: passed (2.38 s) onNVIDIA GeForce RTX 5080(driver32.0.16.2124, D3D12 debug layer enabled), identical readbacks and mutation failure for both FXCps_5_1and DXCps_6_0,debug_errors=0 debug_warnings=0.Note:
tests/startup_gfx2hlsl_mul_hi_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.Scope note: these passing fixtures verify
v_mul_hi_u32lowering and desktop GPU execution in isolation; they do not establish full-game startup.