startup: lower v_add_co_u32, v_sub_co_u32 and v_subrev_co_u32 in gfx2hlsl #2115
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2123"
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 denn0x on 2026-11-25T00:53:56Z.
Part of #1723
The VOP3b add and subtract forms with a carry out and no carry-in were refused by
tools/startup/gfx2hlsl.pyas unknown instructions. They are now lowered from the AMD RDNA 2 ISA description:v_add_co_u32D = S0 + S1v_sub_co_u32D = S0 - S1S1 > S0v_subrev_co_u32D = S1 - S0S0 > S1vccor of the SGPR destination. The SGPR becomes a lane mask and is recorded as varying (#1931), so av_readfirstlane_b32of a copy of it is refused; D is not proven uniform either.aandwbefore either destination is written, so a destination may overlap a source.execis not known, an inactive lane keeps D and writes a 0 carry, as the compare lowering does.clamp, other modifiers, anexeccarry-out and a wrong operand count are refused.The carry-in forms are not part of this change:
v_add_co_ci_u32is in #2033 andv_sub_co_ci_u32/v_subrev_co_ci_u32are in #2041. The two changes touch different handlers and do not depend on each other.New test
tests/startup_gfx2hlsl_add_sub_co_check.py, registered asstartup_gfx2hlsl_add_sub_co_controlsinCMakeLists.txt,AGENTS.mdand the Python job, and described indocs/experiments.md. It decodes synthetic VOP3b words for the three forms with an SGPR and avcc_locarry-out and evaluates the emitted lines with the restricted evaluator ofstartup_gfx2hlsl_bit_alu_check.pyon 384 edge-value inputs against Python references written from the ISA description. It also checks the exec-masked form, an overlapping destination, the readfirstlane refusals for D and the carry-out copy, and the refusals above. Negative control: a borrow with the comparison reversed disagrees with the reference.Verification (branch head
c31d1ef2onmain246a875d, Windows 11 Pro 10.0.26300, Python 3.13):python -B tests/startup_gfx2hlsl_add_sub_co_check.py-> exit 0 (add/sub co forms: 6 forms match the ISA references on 384 inputs; exec, overlap and refusals checked). Onmainthe same test fails withUnsupported: v_add_co_u32.tests/startup_gfx2hlsl_*_check.py,tests/startup_translator_check.py,tests/docs_links_check.pyandtests/startup_tools_lint_check.py tools/startup-> 33 scripts, all exit 0.git diff --check main..HEAD-> clean.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:51:17Z.
Review: COMMENTED
Review of head
c31d1ef26dffa1b9fe5de1c7401a7ff78ec266ba.Summary: The lowering of
v_add_co_u32,v_sub_co_u32andv_subrev_co_u32matches the ISA semantics. I found no correctness bugs. There is one blocker for merge (conflicts) and one coverage note.Commands executed locally (Linux):
python3 tests/startup_gfx2hlsl_add_sub_co_check.py-> pass ("6 forms match the ISA references on 384 inputs; exec, overlap and refusals checked")python3 tests/docs_links_check.py-> pass (18 files, 395 links)python3 tests/bidi_controls_check.py-> pass (1424 files)git diff --check origin/main...HEAD-> cleangh pr checks 2123: Linux Python checks, gfx1013 fixtures and Windows build/test all pass.w = b > achanged tob >= ain the sub/subrev borrow -> test fails (4 checks). Killed.(a+b) < achanged to<= a-> test fails (4 checks). Killed.git checkout -- ..Findings
P1
CONFLICTING.git merge-tree origin/main HEADreports conflicts inAGENTS.md,CMakeLists.txt,docs/experiments.mdand.github/workflows/windows.yml. These are registry lines (the new test entry) that collided with other merged changes.tools/startup/gfx2hlsl.pymerges cleanly. A rebase is needed before this can land.P2
Nits / notes
tools/startup/gfx2hlsl.pycarry_out_op: the carry-out destination check accepts onlyvcc,vcc_loand a single SGPR up to s105. This is correct and refuses theexeccarry-out as described. Pairs of SGPRs (wave64 masks) are not special-cased. This is fine as the code already treats the destination as a lane mask.aandware computed beforeset_v/set_s, so overlap of D or SDST with a source is safe. The overlap test covers it.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T03:21:38Z.
Review: COMMENTED
Re-review of head
1527e76124f203c9673f855564d5b1e63b75c0e6(previous review was onc31d1ef2).Summary: The earlier P1 (merge conflicts) is resolved. The branch is now rebased on main and merges cleanly. The lowering still matches the ISA semantics for
v_add_co_u32,v_sub_co_u32andv_subrev_co_u32. No new findings.Commands executed locally (Linux):
git merge-tree --write-tree origin/main HEAD-> clean, no conflicts.gh pr viewreportsMERGEABLE.python3 tests/startup_gfx2hlsl_add_sub_co_check.py-> pass ("6 forms match the ISA references on 384 inputs; exec, overlap and refusals checked")python3 tests/docs_links_check.py-> pass (18 files, 404 links)python3 tests/bidi_controls_check.py-> pass (1466 files)git diff --check origin/main...HEAD-> cleangh pr checks 2123: Linux Python checks, gfx1013 fixtures and Windows build/test pass. The /O2 job and the chart publish job are skipped.w = b > achanged tob >= a-> test fails (4 checks). Killed.(a+b) < achanged to<= a-> test fails (4 checks). Killed.git checkout -- .(worktree clean).Findings
P1
P2
Nits / notes
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-25T03:17:10Z.
Thanks for the review. I rebased the branch on current
main(166d8666); the new head is1527e761. The conflicts were only the registry lines for the new check inAGENTS.md,CMakeLists.txt,docs/experiments.mdandwindows.yml, and I kept both sides of each. After the rebase,tests/startup_gfx2hlsl_add_sub_co_check.py, every othertests/startup_gfx2hlsl_*_check.py,tests/startup_translator_check.py,tests/docs_links_check.pyand the tools lint pass, andgit diff --checkis clean.On the WARP readback: I agree it would add confidence. I would keep this PR to the Python-level lowering and its reference model, which compares all six forms on 384 inputs. A draw check could follow in a separate PR that covers the other carry ops too.
Imported from R0Y00/Xbox2Windows. Originally posted by stan495 on 2026-11-25T05:42:09Z.
Review: APPROVED
Verified head
1527e761on Windows x64 (Python 3.12).python -B tests/startup_gfx2hlsl_add_sub_co_check.py-> passed (add/sub co forms: 6 forms match the ISA references on 384 inputs; exec, overlap and refusals checked)python -B tests/docs_links_check.py-> passed (18 Markdown files, 404 links)Verdict: Approved at
1527e761.