Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion tests/rdna2_tools_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_golden_vectors(self):
("000080bf", "s_nop", "s_nop 0"),
("000081bf", "s_endpgm", "s_endpgm"),
("000082bf", "s_branch", "s_branch label_0x4"),
("7f008cbf", "s_waitcnt", "s_waitcnt vmcnt(7) lgkmcnt(0)"),
("7f008cbf", "s_waitcnt", "s_waitcnt vmcnt(15) lgkmcnt(0)"),
("000382be", "s_mov_b32", "s_mov_b32 s2, s0"),
("000482be", "s_mov_b64", "s_mov_b64 s2, s0"),
("00008080", "s_sub_u32", "s_sub_u32 s0, s0, s0"),
Expand Down Expand Up @@ -300,6 +300,31 @@ def test_compressed_export_keeps_unpaired_mask(self):
self.assertEqual(records[0]["assembly"],
f"exp mrt0 {registers} done compr vm en:{mask:#x}")

def test_waitcnt_uses_gfx10_counter_fields(self):
# GFX10 s_waitcnt simm16: vmcnt [3:0] and [15:14], expcnt [6:4], lgkmcnt [13:8].
vectors = [
# Printed by LLVM 15.0.7 (MC/Disassembler/AMDGPU/gfx10_dasm_all.txt).
("00008cbf", "s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)"),
("34128cbf", "s_waitcnt vmcnt(4) expcnt(3) lgkmcnt(18)"),
("51c18cbf", "s_waitcnt vmcnt(49) expcnt(5) lgkmcnt(1)"),
# Encoded by LLVM 15.0.7 (MC/AMDGPU/gfx10_asm_sop.s); bit 7 is unused.
("d1c18cbf", "s_waitcnt vmcnt(49) expcnt(5) lgkmcnt(1)"),
# One counter each; the others at their maximum are omitted.
("703f8cbf", "s_waitcnt vmcnt(0)"),
("707f8cbf", "s_waitcnt vmcnt(16)"),
("7f3f8cbf", "s_waitcnt vmcnt(15)"),
("0fff8cbf", "s_waitcnt expcnt(0)"),
("7fc08cbf", "s_waitcnt lgkmcnt(0)"),
("7fff8cbf", "s_waitcnt vmcnt(63) expcnt(7) lgkmcnt(63)"),
]
for hex_str, expected in vectors:
with self.subTest(encoding=hex_str):
records = disasm_rdna2(bytes.fromhex(hex_str + "000081bf"))
self.assertEqual([(r["opcode"], r["length"]) for r in records],
[("s_waitcnt", 4), ("s_endpgm", 4)])
self.assertEqual(records[0]["assembly"], expected)
self.assertTrue(is_instruction_supported(expected))

def test_literal_operands_keep_stream_aligned(self):
# SOP1, SOP2, VOP1, VOP2 (src0 == 255) and v_fmaak_f32 each consume a trailing 32-bit literal.
stream = bytes.fromhex(
Expand Down
10 changes: 7 additions & 3 deletions tools/disasm_rdna2.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,9 +956,13 @@ def decode_instruction(data: bytes, offset: int) -> tuple[int, str, str, str]:
elif op_name == "s_nop":
asm = f"s_nop {simm}"
elif op_name == "s_waitcnt":
vm = (simm >> 4) & 0xf
lgkm = (simm >> 8) & 0x3f
asm = f"s_waitcnt vmcnt({vm}) lgkmcnt({lgkm})"
# GFX10 split: vmcnt is simm16[3:0] plus [15:14], expcnt [6:4], lgkmcnt [13:8].
# Like LLVM, omit counters at their "no wait" maximum unless all three are.
counters = (("vmcnt", (simm & 0xf) | ((simm >> 10) & 0x30), 0x3f),
("expcnt", (simm >> 4) & 0x7, 0x7),
("lgkmcnt", (simm >> 8) & 0x3f, 0x3f))
waits = [f"{name}({value})" for name, value, limit in counters if value != limit]
asm = "s_waitcnt " + " ".join(waits or (f"{name}({value})" for name, value, _ in counters))
elif op_name.startswith("s_cbranch") or op_name == "s_branch":
target = offset + 4 + signed_simm * 4
asm = f"{op_name} label_0x{target:x}"
Expand Down
Loading