Repository navigation
rdna2spirv, lane_masks, wave64_halves: fix 3-operand short-form v_*_co_ci_u32 operand classification (SHADER-SHORT-CO-CI-MASK-OPERANDS) - #2357
Conversation
…o_ci_u32 operand classification (SHADER-SHORT-CO-CI-MASK-OPERANDS)
|
On an RTX 4090, all 30 short-form carry/borrow dispatches at
Each case read back the per-lane arithmetic result, the population count of the original scalar source, and the population count of the outgoing carry or borrow mask. For example, with scalar source I also tested how this composes with #2355’s bit-set fix. On the clean local merge of the two heads (tree Windows 11, NVIDIA 616.64, Vulkan validation enabled, synthetic shader listings. AI-assisted verification by OpenAI Codex (GPT-6). |
lixonik
left a comment
There was a problem hiding this comment.
Windows 11: 6/6 short-form carry-in/carry-out semantic tests passed, covering the three-operand form, wave32 and wave64. No findings from these checks.
AI-assisted.
wavehs
left a comment
There was a problem hiding this comment.
macOS arm64 check of #2357 (SHADER-SHORT-CO-CI-MASK-OPERANDS). Analysis-only translator change plus one semantic test; the GPU part is MoltenVK/Kosmickrisp.
Tested head e1ca6ccea merged onto main bdbc7e923 as merge 540bafef8 (clean; branch 21 commits behind, git merge-tree clean).
Environment: Apple M3 Pro, arm64 (subgroups 4..32), macOS 27.2.1, CPython 3.15.2, SPIRV-Tools v2026.4, llvm-mc 23.1.5, MoltenVK 1.4.0; KosmicKrisp and lavapipe = Mesa 26.3.0.
The new test passes, and the control shows the bug
python -I tests/semantic/test_short_co_ci_masks.py:Ran 6 tests ... OKat the head and after merging ontobdbc7e923.- Negative control (test kept,
tools/rdna2spirv.py,tools/lane_masks.pyandtools/wave64_halves.pyput back tomain's):FAILED (failures=8, errors=1).- The error is the real failure mode, not just a model mismatch:
test_wave64_short_co_ci_translates_and_runsaborts withrdna2spirv.Unsupported: 64-bit operandonmain, becausewiden_wave64_maskswidenssrc0(an SGPR used as a value) to a pair for the 3-operand spelling. - The analysis tests fail with
AssertionError: 10 unexpectedly found in {10: 'mask'}(lane masks markss10, the source, as a mask destination) forv_add_co_ci_u32,v_sub_co_ci_u32andv_subrev_co_ci_u32in wave32 and wave64, and thewave64_halvestest fails too.
- The error is the real failure mode, not just a model mismatch:
- The four sites the fix touches (lane_masks step, writes_exec, widen_wave64_masks, wave64_halves operands) each have an assertion, so the test is not only an end-to-end check.
No regressions
- Semantic suite: 500 files / 6,367 tests / 0 failed at
mainbdbc7e923; 501 files / 6,373 tests / 0 failed at the merge (+1 file, +6 tests). - GPU fixtures (268): MoltenVK 195 PASS / 3 FAIL / 70 SKIP, KosmicKrisp 190 / 5 / 73, identical at
mainand the merge after normalising the per-run temp directory; same pre-existing failures (cs_fma_fused,cs_imgatomic_ext,ps_ssharpon MV;cs_bvh,cs_bvh32,cs_imgatomic_ext,ps_cndmask_sign_mods,ps_valu16_mad_selon KK).cs_w64_mask_imm.asmandps_ops2.asmusev_*_co_ci_u32, so the 5-operand path is covered there, and its results are unchanged.
Findings
- The same operand assumption is still in two analysis tools:
scripts/audit_shader4_regs.py:216-221(is_dual_dston any_co_op, thendsts = args[:2]) andscripts/vs_input_survey.py:86-88(samelen(args) >= 2test). Given the 3-operand spelling, both treatsrc0as the carry-out destination, exactly what this PR fixes elsewhere. It does not affect corpus reports today because llvm-mc/the disassembler print the_e32form with five operands (vD, vcc_lo, src0, src1, vcc_lo), astests/semantic/test_carry_exec_mask.pyshows; but the translator and its tests accept the short spelling, so an audit run on hand-written.sinput would be wrong. Adding the samelen(args) == 3exclusion plus a line intests/test_audit_shader4_regs.py/tests/test_vs_input_survey.pycloses it. - GPU evidence for the short spelling itself: none of the shaders in
runtime/test/shadersuses the 3-operand form, so the GPU runs above only show the 5-operand path is unchanged. That is expected for an analysis fix (no SPIR-V text changes for correct inputs), but worth saying in the description so nobody reads the green suite as hardware confirmation of the short form.
python -I scripts/check_no_game_data.py on the changed files: clean. git diff --check: clean.
No game files. AI-assisted.
tiguan26
left a comment
There was a problem hiding this comment.
Approving e1ca6cc.
The three-operand short form of v_add/sub/subrev_co_ci_u32 carries in and out through an implicit VCC, and the change teaches that to all three analyses consistently: lane_masks.step and wave64_halves.operands record VCC as its mask definition, writes_exec no longer reads its second operand as a VOP3 carry-out destination, and widen_wave64_masks leaves its operands alone.
test_short_co_ci_masks.py 6 passed (12 subtests). Merged onto main d1dff7949 together with #2397, #2416 and the other three of this series below (no conflicts), on Linux with Python 3.13. The full translator suite (run_semantic_tests.py tests/semantic) on that tree has only the 8 failures main has here (7 in test_fspx_dot4_op_sel_disasm, test_int32_to_f64), and tests/test_translate.py only main's own ps_sdwa_f16_const.asm (an llvm-mc version difference in this environment). AI-assisted (Claude Code, Claude Opus 5.5).
|
Tested
The failures are the same on both sides (the known ones: #1724, #1518 and #1774 on MoltenVK, #2229's on KosmicKrisp). The translator suite passes with no failures. Evidence: MEASURED, 1 run each. This only shows that nothing changes on Apple drivers. It says nothing about the game. AI-assisted (Claude Code, Claude Opus 5.5). |
|
CPU check on Linux, merged with main c0201a8: Heads-up: #2447 fixes the same short form one level earlier. Its AI-assisted (Claude Code); I ran the tests and checked the results. Generated by Claude Code |
Item:
SHADER-SHORT-CO-CI-MASK-OPERANDSProblem
Gen._insn(tools/rdna2spirv.py) explicitly accepts the 3-operand short VOP2 assembler spellingv_add_co_ci_u32 vD, src0, src1(andv_sub_co_ci_u32/v_subrev_co_ci_u32), where carry-out and carry-in are both implicitvccand operand 1 is the 32-bit sourcesrc0. However, four analysis helpers treated operand 1 as the VOP3b carry-out destination:tools/lane_masks.py(step): Calledput(state, a[1], MASK, wave64), falsely markingsrc0(e.g. an SGPR holding plain scalar data) as a lane mask and failing to mark implicitvccasMASK. Downstream scalar ops readingsrc0(e.g.s_bcnt1_i32_b32) then read the wave ballot (32instead ofpopcnt(src0)).tools/rdna2spirv.py(widen_wave64_masks): Always usedat = (1, 4)for_co_ci_, widening a 32-bitsrc0SGPR (a[1]) ton=2in wave64 shaders, which crashed translation withUnsupported("64-bit operand").tools/rdna2spirv.py(writes_exec): Treateda[1]as a destination on allVOP3_TWO_DESTSops, sov_add_co_ci_u32 v1, exec_lo, v0was falsely flagged as writing EXEC.tools/wave64_halves.py(operands): Splitdests, srcs = [a[0], a[1]], list(a[2:])whena[1]was an SGPR/special, droppingsrc0fromsrcs, falsely claimingsrc0was overwritten, and omitting implicit"vcc"from bothdefsanduses.Fix
tools/lane_masks.py: For 3-operandv_*_co_ci_u32, putMASKon implicitvccinstead ofa[1].tools/rdna2spirv.py: Inwiden_wave64_masks, only widen(1, 4)whenlen(a) > 3; inwrites_exec, skip thea[1]destination check for 3-operand*_ci_u32.tools/wave64_halves.py: For 3-operandv_*_co_ci_u32, keepdests = [a[0]]andsrcs = [a[1], a[2]], and append"vcc"todefs(len(srcs) == 2then also adds"vcc"touses).tests/semantic/test_short_co_ci_masks.py: Unit + wave32/wave64 execution regression tests covering all four sites.Verification
AI-assisted: yes.
Environment: Windows 11, Python 3.12.10, CPU-only (no game files, no
spirv-val, not GPU-verified).python -I tests/semantic/test_short_co_ci_masks.py -v-> 6/6 OKpython -I tests/test_lane_masks.py-> OKpython -I tests/semantic/test_wave64_halves.py-> 127/127 OKpython -I tests/test_text_write_line_endings.py-> 3/3 OKpython -m compileall -q tools/rdna2spirv.py tools/lane_masks.py tools/wave64_halves.py tests/semantic/test_short_co_ci_masks.py-> 0python -I scripts/check_no_game_data.py ...-> 0git diff --check-> 0origin/mainfbf100b1):tests/semantic/test_short_co_ci_masks.pyagainstorigin/main'stools/fails all 6 tests (14 assertion failures + 1Unsupported("64-bit operand")crash on wave64).