Skip to content

startup: lower the 32-bit scalar complement logic ops - #1928

Closed
ChazY11 wants to merge 1 commit into
R0Y00:mainfrom
ChazY11:startup/scalar-complement-b32
Closed

ChazY11 wants to merge 1 commit into
R0Y00:mainfrom
ChazY11:startup/scalar-complement-b32

Conversation

@ChazY11

@ChazY11 ChazY11 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Implements #1919.

Change

tools/startup/gfx2hlsl.py, three entries in SCA, with the shapes the 64-bit forms already use:

's_nand_b32': ('~({0} & {1})', '$ != 0'), 's_nor_b32': ('~({0} | {1})', '$ != 0'),
's_xnor_b32': ('~({0} ^ {1})', '$ != 0'),

Nothing else moves: s_andn2_b32 / s_orn2_b32 / s_not_b32 and every b64 form stay as they are.

Tested

out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_scalar_m0_check.py
startup scalar m0 controls passed      exit 0

ctest --preset dev -R 'startup_gfx2hlsl|startup_translator|startup_flat_param'
100% tests passed, 0 tests failed out of 31

The new cases build SOP2 words from the decoder table (s_nand_b32 0x18, s_nor_b32 0x1a, s_xnor_b32 0x1c) and
translate them:

s_nand_b32 s28, s5, s6   ->  s28 = ~(0x00000004u & s6);  scc = s28 != 0;
s_nor_b32  s28, s5, s6   ->  s28 = ~(0x00000004u | s6);  scc = s28 != 0;
s_xnor_b32 s28, s5, s6   ->  s28 = ~(0x00000004u ^ s6);  scc = s28 != 0;

(I keep the assertion on the shape — s28 = ~( plus the operator, and the exact SCC line — because this fixture's stage
folds s5 to a constant, which is not what the case is about. s_and_b32 is asserted separately as the unchanged neighbour,
with no complement.)

Fail-first

Removing one entry at a time from SCA:

s_nand_b32  exit 1
s_nor_b32   exit 1
s_xnor_b32  exit 1
restored    exit 0

so each of the three is needed on its own; the fixture does not pass because the neighbours happen to be present.

Scope

Two files: +2 lines in the translator table, +16 in the existing scalar check. No new file, no CMake change, no draw mode.

Notes

  • AI-assisted.

s_nand_b32, s_nor_b32 and s_xnor_b32 were refused while their b64 forms
and s_andn2_b32/s_orn2_b32 were translated. Add them to SCA with the
64-bit shapes and the same SCC rule (result != 0).

Refs R0Y00#1919.
@ChazY11

ChazY11 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Closing: #1925 by @MasterDomino is the implementation, and the issue description says "I'd like to take this; PR to follow" — I
claimed it without reading that line, exactly the mistake I made on #1820/#1896. My fault, not theirs.

Their branch also does more than mine: 11 operand forms × 2,184 value pairs against an integer reference for result and SCC,
the lane-mask forms against their and/or/xor siblings, refusals for every still-unlowered SOP2 op, and an LLVM 15 round trip.
Mine was three table entries and three SOP2 words — a cross-check at best, not an implementation.

What I will do instead: run their branch through the encode_sop2 route I proposed, as they asked, and report it on #1925. If
that route disagrees with theirs anywhere, that is worth knowing; if it agrees, an independent second path is still worth
recording.

Two corrections to my earlier comments here, so the thread is not misleading:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant