From 9eae5d1017980960b00d7bce13b429b68498bbb8 Mon Sep 17 00:00:00 2001 From: ChazY11 <246129015+ChazY11@users.noreply.github.com> Date: Wed, 25 Nov 2026 05:28:26 +0800 Subject: [PATCH] startup: lower the 32-bit scalar complement logic ops 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 #1919. --- tests/startup_gfx2hlsl_scalar_m0_check.py | 16 ++++++++++++++++ tools/startup/gfx2hlsl.py | 2 ++ 2 files changed, 18 insertions(+) diff --git a/tests/startup_gfx2hlsl_scalar_m0_check.py b/tests/startup_gfx2hlsl_scalar_m0_check.py index 0e0b8f5080..f2e6b4c84c 100644 --- a/tests/startup_gfx2hlsl_scalar_m0_check.py +++ b/tests/startup_gfx2hlsl_scalar_m0_check.py @@ -47,6 +47,9 @@ SOP2_AND_B64 = 0x0f SOP2_LSHL_B32 = 0x1e SOP2_BFM_B32 = 0x24 +SOP2_NAND_B32 = 0x18 +SOP2_NOR_B32 = 0x1a +SOP2_XNOR_B32 = 0x1c SOPK_MOVK_I32 = 0x00 @@ -183,6 +186,19 @@ def controls(): st_bfm_const = run_seq(encode_sop2(SOP2_BFM_B32, M0, 5, 128 + 2)) assert st_bfm_const.lines == ['m0 = 0x0000003cu;'], st_bfm_const.lines + # s_nand_b32 / s_nor_b32 / s_xnor_b32: the 32-bit complement logic ops, SCC = result != 0 (#1919). + # The sources a fixture stage folds to a constant are not the point here: the complement form and the + # SCC update are. + for opcode, operator in ((SOP2_NAND_B32, '&'), (SOP2_NOR_B32, '|'), (SOP2_XNOR_B32, '^')): + st_logic = run_seq(encode_sop2(opcode, 28, 5, 6)) + assert len(st_logic.lines) == 2, st_logic.lines + assert st_logic.lines[0].startswith('s28 = ~(') and ' %s ' % operator in st_logic.lines[0], st_logic.lines + assert st_logic.lines[1] == 'scc = s28 != 0;', st_logic.lines + + # The neighbour stays as it was: a plain AND with the same SCC rule, no complement. + st_and = run_seq(encode_sop2(0x0e, 28, 5, 6)) + assert not st_and.lines[0].startswith('s28 = ~(') and st_and.lines[1] == 'scc = s28 != 0;', st_and.lines + st_bfm_dyn = run_seq(encode_sop2(SOP2_BFM_B32, M0, 8, 128 + 2)) assert any(line.startswith('m0 = ') and 'ud1' in line for line in st_bfm_dyn.lines), st_bfm_dyn.lines diff --git a/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index 66bba52e5e..a1ce74077d 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -1476,6 +1476,8 @@ def declarations(self): 's_mov_b32': ('{0}', None), 's_mov_b64': ('{0}', None), 's_movk_i32': ('{0}', None), 's_and_b32': ('{0} & {1}', '$ != 0'), 's_or_b32': ('{0} | {1}', '$ != 0'), 's_xor_b32': ('{0} ^ {1}', '$ != 0'), 's_andn2_b32': ('{0} & ~{1}', '$ != 0'), 's_orn2_b32': ('{0} | ~{1}', '$ != 0'), 's_not_b32': ('~{0}', '$ != 0'), + 's_nand_b32': ('~({0} & {1})', '$ != 0'), 's_nor_b32': ('~({0} | {1})', '$ != 0'), + 's_xnor_b32': ('~({0} ^ {1})', '$ != 0'), 's_and_b64': ('{0} & {1}', '$ != 0'), 's_or_b64': ('{0} | {1}', '$ != 0'), 's_xor_b64': ('{0} ^ {1}', '$ != 0'), 's_andn2_b64': ('{0} & ~{1}', '$ != 0'), 's_orn2_b64': ('{0} | ~{1}', '$ != 0'), 's_not_b64': ('~{0}', '$ != 0'), 's_nand_b64': ('~({0} & {1})', '$ != 0'), 's_nor_b64': ('~({0} | {1})', '$ != 0'), 's_xnor_b64': ('~({0} ^ {1})', '$ != 0'),