From bf2908429c19f2d5bbcbf22bc2995054966faa41 Mon Sep 17 00:00:00 2001 From: bobcatchris <83428450+bobcatchris@users.noreply.github.com> Date: Sun, 22 Nov 2026 12:30:02 -0600 Subject: [PATCH] hw_oracle: respell ds_cmpst_b32 for GFX11 with the store operand first ds_line already converts ds_cmpst_rtn_b32 to ds_cmpstore_rtn_b32 and swaps the two data operands, but the non-returning ds_cmpst_b32 was left as-is, and GFX11 has no such mnemonic. Measured on gfx1100 that ds_cmpstore_b32 takes the value to store before the compare value. --- tests/test_hw_oracle.py | 12 ++++++++++++ tools/hw_oracle/asm.py | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/tests/test_hw_oracle.py b/tests/test_hw_oracle.py index 74990166c..74cfa2e94 100644 --- a/tests/test_hw_oracle.py +++ b/tests/test_hw_oracle.py @@ -118,6 +118,18 @@ class True16(unittest.TestCase): "v_cvt_f32_f16 v8, v4.h", "v_mov_b32 v8, v4"): self.assertEqual(asm.true16_spelling(same), same) + def test_the_non_returning_compare_and_store_is_respelled_and_swapped_on_gfx11(self): + """GFX11 has no ds_cmpst_b32, and ds_cmpstore_b32 takes the store value before the compare value.""" + self.assertEqual(asm.ds_line("ds_cmpst_b32 v0, v1, v2", "gfx1150"), + "ds_cmpstore_b32 v0, v2, v1") + self.assertEqual(asm.ds_line("ds_cmpst_b32 v0, v1, v2 offset:8", "gfx1100"), + "ds_cmpstore_b32 v0, v2, v1 offset:8") + self.assertEqual(asm.ds_line("ds_cmpst_b32 v0, v1, v2", "gfx1030"), + "ds_cmpst_b32 v0, v1, v2") + # Both changes are needed together: the rename alone would compare v2 and store v1. + with self.assertRaises(ValueError): + asm.ds_line("ds_cmpst_b32 v0, v1", "gfx1150") + def test_error_lines_still_map_back(self): text = "v_mov_b32 v1, 0\nv_cvt_f32_f16 v8, 0x3c00\nv_cvt_f16_f32 v8, v1\nv_mov_b32 v9, 0\n" out = asm.true16_spelling(text) diff --git a/tools/hw_oracle/asm.py b/tools/hw_oracle/asm.py index 33e5ec5f9..ad1fea97b 100644 --- a/tools/hw_oracle/asm.py +++ b/tools/hw_oracle/asm.py @@ -305,6 +305,17 @@ def ds_line(line, arch): raise ValueError(f"cannot swap the operands of {line!r}") dst, addr, cmp_, store, tail = m.groups() rest = f"{dst}, {addr}, {store}, {cmp_}{tail}" + elif op == "ds_cmpst_b32" and family(arch) == "gfx11": + # The non-returning form is renamed as well, and its two data operands swap the same way: GFX10's + # ds_cmpst_b32 vaddr, cmp, store is GFX11's ds_cmpstore_b32 vaddr, store, cmp (measured on gfx1100: with + # M = 7, vaddr = 0 and data v1 = 9, v2 = 7 the dword becomes 9, so the store operand is v1). The rename is + # done here rather than in DS_RENAMED_GFX11 because the swap is only measured on GFX11, and renaming + # without swapping on GFX12 would silently compare and store the wrong way round. + m = re.fullmatch(r"(v\d+),\s*(v\d+),\s*(v\d+)(.*)", rest) + if not m: + raise ValueError(f"cannot swap the operands of {line!r}") + addr, cmp_, store, tail = m.groups() + return f"ds_cmpstore_b32 {addr}, {store}, {cmp_}{tail}" return ds_mnemonic(op, arch) + sep + rest