shader: lower v_add_co_ci_u32, v_sub_co_ci_u32 and v_subrev_co_ci_u32 in pixel_aot #853
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/859"
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 alvaroolt on 2026-11-23T14:16:03Z.
Change
tools/pixel_aot.pynow lowers the carry-in add and subtractsv_add_co_ci_u32,v_sub_co_ci_u32andv_subrev_co_ci_u32in both encodings, VOP2 (_e32) and VOP3 (_e64): six gfx1013 forms that the form-coverage report listed as unobserved. They complete the carry chain that #779 started withv_add_co_u32/v_sub_co_u32/v_subrev_co_u32. In that chain, the carry-out written to a lane mask becomes the carry-in of the next 32-bit word, as in 64-bit address arithmetic.v_cndmask_b32uses. The carry-out replaces the condition in its mask.src0 + src1 + carryand carries when either 32-bit step wraps.v_sub_co_ci_u32computessrc0 - src1 - borrowand borrows whensrc1 + borrow > src0(unsigned).subrevswaps the sources.llvmorg-15.0.7).SelectAddcSubbselectsV_ADDC_U32_e64forISD::ADDCARRYandV_SUBB_U32_e64forISD::SUBCARRY.V_SUBBREV_U32is declared withv_subb_u32as its reversed-operand counterpart. The semantics are not checked against the ISA document and not measured on a console._e32reads and writesvcc/vcc_loand takes a VGPR assrc1._e64names both masks, which must have the same width.clampand float modifiers;execor a VGPR as a mask;_e32form with another mask or an SGPRsrc1;tools/scan_unsupported_shaders.py) gains matching patterns.tests/rdna2_tools_check.py,v_add_co_ci_u32_e64 v1, vcc, v2, v3, vcc, is now a supported line. It moved to the accepted list, and the refusal list now uses the same line with an extra operand, plus new DPP, SDWA, clamp and mask cases.Overlap: the open PR #423 covers only the
_dppspellings of these instructions. This PR does not touch them; they stay refused here.Verification
All results are for the working tree at commit
b554187, rebased on8307b9a.ctest --preset dev --no-tests=error -R '^pixel_aot_carry_in_' -Vpixel_aot_carry_in_hardwareandpixel_aot_carry_in_warppassedXBOX2WINDOWS_ADAPTER=Radeon,-R '^pixel_aot_carry_in_hardware$'devctest --preset dev --no-tests=error -j 8releasectest --preset release --no-tests=error -j 4python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <LLVM-C.dll>python -B tests/rdna2_tools_check.pywith LLVM 15The 7 skips are pre-existing capability skips:
bvh_wave64_{hardware,warp},wave_shuffle_warp, andspirv_minlod{,_levels}_{hardware,warp}.Adapters:
All on Windows 11 build 26300, with the debug layer unavailable (Graphics Tools not installed).
Test first: before the change,
tests/form_coverage_check.pyfailed withUnsupported instruction 24: v_add_co_ci_u32_e32 v12, vcc_lo, s46, v19, vcc_lo, and the scanner test failed onv_add_co_ci_u32_e32 v1, vcc_lo, s2, v3, vcc_lo.Evidence and follow-up
The fixture is synthetic: three programs in
tests/pixel_aot_check.py(carry_in_group,draw-carry-in).vcc_loand on (A, D) intos60. It then computes op(C, D,vcc_lo) in_e32and op(D, C,s60) in_e64, with the carry-out ins61. Twov_cndmask_b32_e64selects export the carry-outs as 0.5 or 1.0.vcc_loset, and one with onlys60set.pixel_mismatch. That is 39 draws from 3 compiles. The wrong references cover:{r} < {p}term from the add's carry-out intools/pixel_aot.pymakes the first row reportmismatchon WARP (Expected ['pass', ...], got ['mismatch', ...]).Assumptions: the instruction semantics come from LLVM, as stated above. The draws show what the translated shader computes on desktop GPUs, not what the console computes.
docs/experiments.mdhas a new paragraph with the reproduction command, next to the carry-out paragraph. That paragraph no longer lists the carry-in forms as refused.This change was AI-assisted (Claude Code); I reviewed the diff and the test results.
Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T14:32:35Z.
Independent review of
b554187: draw-carry-in passed on RTX 4060 Laptop and WARP, including the wrong-reference cases. LLVM 15 reassembled the real encodings. The two-step carry and borrow tests agree with a wider integer calculation at wraparound, including a borrow from the incoming bit alone.AMD RDNA 2 section 12.7 confirms the operand order and carry-in for these opcodes. Its reverse-subtract row reverses the result operands but repeats the forward borrow expression. The implementation follows LLVM 15's reverse-subtract pairing and takes the borrow from the actual subtrahend. Keep that distinction in any documentation and keep the console hardware result unclaimed.
https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf