startup: lower s_nand_b32, s_nor_b32 and s_xnor_b32 in gfx2hlsl #1918
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1925"
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 MasterDomino on 2026-11-24T21:29:05Z.
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/main27cf223d. 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)800a8e34)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
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T21:32:11Z.
Review: CHANGES_REQUESTED
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.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T21:47:04Z.
Review: APPROVED
Rechecked the exact numeric-only candidate with mask and descriptor refusal controls. The independent result/SCC matrix and both mutation families pass.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T21:36:00Z.
Narrowed to numeric operands and destinations in
9b620015:s_nand_b32,s_nor_b32ands_xnor_b32with avcc_lo/exec_looperand or destination, or an SGPR holding a compare mask, now fail with<op> on a lane mask.startup_gfx2hlsl_*31/31;binarywith llvm-mc 15.0.7 PASS.The 12 requests after gating: they 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 only 4 are numeric, so the numeric slice does not move them. Translated and other refusal counts are unchanged (90 translated). The description is updated.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
s_cselect/s_cbranch_sccconsumer. I'd keep that as its own issue.For awareness: ChazY11's #1928 adds the same three table entries without a mask gate, so the same point applies there.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T21:42:50Z.
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
9b620015and passes once that input is refused, alongside the numeric, mask and scalar m0 controls.Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T21:46:38Z.
Cross-check with the
encode_sop2route, as you asked. Two independent paths, and they agree.1. Your check, on your branch
2. My route, on the same branch
The
startup_gfx2hlsl_scalar_m0_check.pyencode_sop2path builds the SOP2 word, decodes it withdisasm_rdna2and runs thetranslator, so it never touches your table or your fixture:
Same text your table produces, and the neighbour is unchanged. Encoding on my side is
0x80000000 | op << 23 | sdst << 16 | ssrc1 << 8 | ssrc0with opcodes0x18,0x1a,0x1c,0x0efrom the decoder table, so this is not a copy of yourexpectations.
3. Mutations I ran against your branch
Because an agreeing second path is weak evidence if neither one fails when the code is wrong, I broke yours three ways and ran
your fixture each time:
's_nand_b32': ('~({0} & {1})', '$ != 0')→ drop the~word_complement = base in ('s_nand_b32', 's_nor_b32', 's_xnor_b32')→False's_nand_b32': (…, '$ != 0')→(…, None)(SCC dropped)The second one is the useful one: your implementation has both a table entry and a
word_complementcode path, so a fixture thatonly compared emitted text against a table-derived expectation could pass while the code path was dead. Yours does not.
What this does not cover
My route only speaks the four ops above at
sdst=28, ssrc0=5, ssrc1=6; it says nothing about your 11 operand forms, the2,184 value pairs, the lane-mask forms, the refusals or the LLVM round trip. Those rest on your fixture alone.
Note
I had opened #1928 for the same issue before reading the claim line in the description; it is closed. Your branch is the one to
merge — the cross-check above is the part I could still contribute.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T21:46:40Z.
Thanks for the descriptor-source control and the fix. I pulled
34105de4locally: all 17tests/startup_gfx2hlsl_*_check.pycontrols pass on it, includingstartup_gfx2hlsl_sop2_complement_check.pywith the new symbolic-input refusal. I have nothing further to change on this slice. The whole-wave SCC lowering for the lane-mask forms stays a separate follow-up.AI-assisted.