Repository navigation
startup: lower s_nand_b32, s_nor_b32 and s_xnor_b32 in gfx2hlsl - #1925
Conversation
The scalar table had the 64-bit complement logic ops and the 32-bit s_andn2_b32/s_orn2_b32, but not the 32-bit s_nand_b32, s_nor_b32 and s_xnor_b32. Add them with pixel_aot's lowering text and the logic-op SCC rule (SCC = result != 0). tests/startup_gfx2hlsl_sop2_complement_check.py decodes SOP2 words built here, translates them and evaluates the emitted lines against an integer reference over edge values (result and SCC); checks the mask and vcc_lo/exec_lo forms against the non-complement sibling; runs mutants without the complement and without the SCC write; keeps every SOP2 op with no lowering refused by name; and has binary (llvm-mc) and decode (LLVM C API) round-trip modes. Fixes R0Y00#1919 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
R0Y00
left a comment
There was a problem hiding this comment.
The numeric forms, complements and SCC controls pass on this exact head. Please narrow the new lowering to numeric operands and destinations unless the whole-mask effect can be proven. The mask controls currently pin the sibling HLSL: it reduces the complemented result to a single lane before computing SCC. Guest SCC is true when any bit of the whole 32-bit result is set, so on a mixed VCC mask it can be 1 even for a pixel whose projected result is 0. A following s_cselect or s_cbranch_scc can observe the difference. Please refuse the lane-mask forms for this slice, or show correct behavior for both outcomes on a mixed-mask consumer. Check whether the 12 reported requests use the numeric slice after gating it.
Review follow-up: a vcc_lo/exec_lo operand or destination, or an SGPR holding a compare mask, is the whole wave's mask, and guest SCC is set when any bit of the complemented 32-bit result is; the per-lane projection cannot show that. s_nand_b32, s_nor_b32 and s_xnor_b32 now lower only numeric operands and destinations; the check refuses all mask forms (including an SGPR mask source) and keeps the numeric reference, sibling and mutation controls. Refs R0Y00#1919 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Narrowed to numeric operands and destinations in
The 12 requests after gating: they now stop at What would move them: a lane-mask slice that computes the whole-wave result and SCC from the full 32-bit mask, shown for both outcomes on a mixed-mask For awareness: ChazY11's #1928 adds the same three table entries without a mask gate, so the same point applies there. AI-assisted. |
|
The updated head correctly refuses lane masks. I also checked a tracked descriptor source: the shared symbolic path silently left the old SCC for all three new ops. The added control fails on |
|
Cross-check with the 1. Your check, on your branchgit fetch origin pull/1925/head:review-1925
python -B tests/startup_gfx2hlsl_sop2_complement_check.py
exit 02. My route, on the same branchThe Same text your table produces, and the neighbour is unchanged. Encoding on my side is 3. Mutations I ran against your branchBecause an agreeing second path is weak evidence if neither one fails when the code is wrong, I broke yours three ways and ran
The second one is the useful one: your implementation has both a table entry and a What this does not coverMy route only speaks the four ops above at NoteI had opened #1928 for the same issue before reading the claim line in the description; it is closed. Your branch is the one to
|
|
Thanks for the descriptor-source control and the fix. I pulled AI-assisted. |
R0Y00
left a comment
There was a problem hiding this comment.
Rechecked the exact numeric-only candidate with mask and descriptor refusal controls. The independent result/SCC matrix and both mutation families pass.
What / Why
Fixes #1919. Part of #870.
tools/startup/gfx2hlsl.pylowered the 64-bit scalar complement logic ops (s_nand_b64,s_nor_b64,s_xnor_b64) and the 32-bits_andn2_b32/s_orn2_b32, but nots_nand_b32,s_nor_b32ors_xnor_b32.pixel_aotalready lowers them (#561) and the decoder prints them (#1078). With #1915 applied, 12 requests in one local shader cache stop atunsupported: s_nor_b32.Change
One line in the
SCAtable, next to the other 32-bit logic ops:The expression text is the same as
pixel_aot'sSCALARentries. SCC follows the existing logic-op rule (result != 0). The results stay 32-bituint. Lane-mask forms are refused (review follow-up,9b620015): avcc_lo/exec_looperand or destination, or an SGPR holding a compare mask, is the whole wave's mask, and guest SCC is set when any bit of the complemented 32-bit result is, which the per-lane projection cannot show. These now fail with<op> on a lane mask.New
tests/startup_gfx2hlsl_sop2_complement_check.py, registered asstartup_gfx2hlsl_sop2_complement. It is also added to the platform-independent Python job, to the LLVM 15 job (binaryanddecode) and to the AGENTS.md list.docs/experiments.mdhas a short paragraph on it.Tests
Base:
upstream/main27cf223. Windows 11 build 26300, Python 3.13.1, LLVM 15.0.7 (llvm-mcandLLVM-C.dll).ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_sop2_complement$' -V: passed.ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_': 28/28 passed, with no skips.python -B tests/startup_gfx2hlsl_sop2_complement_check.py: PASS. It covers:rdna2_tools_check.py.pixel_aot's.s_and_b32/s_or_b32/s_xor_b32lines with the operation wrapped in~( ), with the same bookkeeping; the 4 vcc_lo/exec_lo source and destination forms, and an SGPR mask source, are refused with<op> on a lane mask.python -B tests/startup_gfx2hlsl_sop2_complement_check.py binary <llvm-mc 15.0.7>: llvm-mc assembles 90 decoded SOP2 forms to the same words. PASS.python -B tests/startup_gfx2hlsl_sop2_complement_check.py decode <LLVM-C.dll 15.0.7>: LLVM disassembles all 90 forms astools/disasm_rdna2.pydoes. PASS.startup_gfx2hlsl_operand_count,_mad,_capture,_smem_offset,_scalar_m0,_bit_alu,_shift64and_op_refusals, plusstartup_translator,startup_flat_param,docs_linksandbidi_controls. All exit 0.Recount (aggregate only). The
req_*files of one local shader cache were copied into a scratch directory and translated offline: 188 requests, 116 distinct native programs.s_nor_b32appears 11 times in 4 programs,s_nand_b322 times in 1 program ands_xnor_b32not at all.s_nor_b32refusalsmainv_cmpx_le_i32_sdwa)main)v_cmp_class_f32(6 -> 18)#1915 has since merged. With the lane-mask gate, the 12 loading requests now stop at
s_nor_b32 on a lane mask: in this cache 7 of the 11s_nor_b32instances readvcc_lo(6 as the first source, 1 as the second) and 4 are numeric, so the numeric slice alone does not move them. Translated counts and all other refusal counts are unchanged (90 translated). The branch is rebased onto7ca344dcandstartup_gfx2hlsl_*passes 31/31.Negative controls
In-check mutants replace the table entry in memory. Each one fails:
The same results hold for
s_nand_b32ands_xnor_b32.Manual source mutants edit
tools/startup/gfx2hlsl.py, run the check and restore the file. Each exits 1:Run against
main'sgfx2hlsl.py, the check exits 1. Each form reportsrefused: s_nor_b32(ors_nand_b32/s_xnor_b32).Not covered
pixel_aotemits. The scalar draw intests/pixel_aot_check.pycovers that text withs_nand_b32/s_nor_b32/s_xnor_b32mutants. I did not rerun that draw for this change. No newly translated pair exists to compile, because the affected requests stop at the next refusal.s_cselect/s_cbranch_sccfor both outcomes. That would be its own slice, and it is what the 12 loading requests need.SCAop still raisesIndexErrorinstead ofUnsupported. This predates the change and applies to every table entry.🤖 Generated with Claude Code