diff --git a/runtime/test/shaders/cs_w64x_partial_swizzle.asm b/runtime/test/shaders/cs_w64x_partial_swizzle.asm index 44ac9061d..e6025ac93 100644 --- a/runtime/test/shaders/cs_w64x_partial_swizzle.asm +++ b/runtime/test/shaders/cs_w64x_partial_swizzle.asm @@ -1,4 +1,3 @@ -; regen_fixtures: this source has a translator fixture in tests/semantic/fixtures/disasm ; Partial wave64, ds_swizzle_b32 / ds_bpermute_b32 from a lane that doesn't exist: a 40x1x1 group is one wave with ; lanes 0-39 running and 40-63 missing. A source lane that doesn't exist reads 0 (RDNA2 ISA, ds_swizzle/ds_bpermute of ; a lane that isn't running; on gfx1036 through tools/hw_oracle, 40 threads, native wave64: lanes 32-39 of SWAP 8 and diff --git a/tests/semantic/fixtures/disasm/cs_w64x_partial_swizzle.s b/tests/semantic/fixtures/disasm/cs_w64x_partial_swizzle.s index 51e79edb2..c7c54bd67 100644 --- a/tests/semantic/fixtures/disasm/cs_w64x_partial_swizzle.s +++ b/tests/semantic/fixtures/disasm/cs_w64x_partial_swizzle.s @@ -1,59 +1,59 @@ -; cs_w64x_partial_swizzle test fixture generated by tests/semantic/regen_fixtures.py from runtime/test/shaders/cs_w64x_partial_swizzle.asm - v_mbcnt_lo_u32_b32 v1, -1, 0 - v_mbcnt_hi_u32_b32 v1, -1, v1 - v_add_nc_u32_e32 v2, 500, v1 - v_mov_b32_e32 v3, 99 - v_mov_b32_e32 v4, 99 - v_mov_b32_e32 v5, 99 - s_mov_b64 s[6:7], exec - s_bcnt1_i32_b64 s8, exec - v_cmp_gt_u32_e64 s[4:5], 48, v1 - s_and_saveexec_b64 s[10:11], s[4:5] - s_cbranch_execz 9 - ds_swizzle_b32 v3, v2 offset:swizzle(SWAP,8) - ds_swizzle_b32 v5, v2 offset:swizzle(BROADCAST,16,15) - v_xor_b32_e32 v6, 8, v1 - v_lshlrev_b32_e32 v6, 2, v6 - ds_bpermute_b32 v4, v6, v2 - s_waitcnt lgkmcnt(0) - s_mov_b64 exec, s[6:7] - v_cmpx_eq_u32_e32 0, v1 - v_mov_b32_e32 v20, v3 - v_mov_b32_e32 v21, 0 - buffer_store_dword v20, v21, s[0:3], 0 offen - s_mov_b64 exec, s[6:7] - v_cmpx_eq_u32_e32 31, v1 - v_mov_b32_e32 v20, v3 - v_mov_b32_e32 v21, 4 - buffer_store_dword v20, v21, s[0:3], 0 offen - s_mov_b64 exec, s[6:7] - v_cmpx_eq_u32_e32 33, v1 - v_mov_b32_e32 v20, v3 - v_mov_b32_e32 v21, 8 - buffer_store_dword v20, v21, s[0:3], 0 offen - s_mov_b64 exec, s[6:7] - v_cmpx_eq_u32_e32 39, v1 - v_mov_b32_e32 v20, v3 - v_mov_b32_e32 v21, 12 - buffer_store_dword v20, v21, s[0:3], 0 offen - s_mov_b64 exec, s[6:7] - v_cmpx_eq_u32_e32 20, v1 - v_mov_b32_e32 v20, v4 - v_mov_b32_e32 v21, 16 - buffer_store_dword v20, v21, s[0:3], 0 offen - s_mov_b64 exec, s[6:7] - v_cmpx_eq_u32_e32 33, v1 - v_mov_b32_e32 v20, v4 - v_mov_b32_e32 v21, 20 - buffer_store_dword v20, v21, s[0:3], 0 offen - s_mov_b64 exec, s[6:7] - v_cmpx_eq_u32_e32 20, v1 - v_mov_b32_e32 v20, v5 - v_mov_b32_e32 v21, 24 - buffer_store_dword v20, v21, s[0:3], 0 offen - s_mov_b64 exec, s[6:7] - v_cmpx_eq_u32_e32 35, v1 - v_mov_b32_e32 v20, v5 - v_mov_b32_e32 v21, 28 - buffer_store_dword v20, v21, s[0:3], 0 offen - s_endpgm +; cs_w64x_partial_swizzle llvm-mc -triple=amdgcn--amdpal -mcpu=gfx1013 -mattr=+wavefrontsize64,-wavefrontsize32 -show-encoding output for runtime/test/shaders/cs_w64x_partial_swizzle.asm (the s_cbranch_execz needs instruction encodings; test_w64x_partial_swizzle.py checks this listing against the .asm) + v_mbcnt_lo_u32_b32 v1, -1, 0 ; encoding: [0x01,0x00,0x65,0xd7,0xc1,0x00,0x01,0x00] + v_mbcnt_hi_u32_b32 v1, -1, v1 ; encoding: [0x01,0x00,0x66,0xd7,0xc1,0x02,0x02,0x00] + v_add_nc_u32_e32 v2, 0x1f4, v1 ; encoding: [0xff,0x02,0x04,0x4a,0xf4,0x01,0x00,0x00] + v_mov_b32_e32 v3, 0x63 ; encoding: [0xff,0x02,0x06,0x7e,0x63,0x00,0x00,0x00] + v_mov_b32_e32 v4, 0x63 ; encoding: [0xff,0x02,0x08,0x7e,0x63,0x00,0x00,0x00] + v_mov_b32_e32 v5, 0x63 ; encoding: [0xff,0x02,0x0a,0x7e,0x63,0x00,0x00,0x00] + s_mov_b64 s[6:7], exec ; encoding: [0x7e,0x04,0x86,0xbe] + s_bcnt1_i32_b64 s8, exec ; encoding: [0x7e,0x10,0x88,0xbe] + v_cmp_gt_u32_e64 s[4:5], 48, v1 ; encoding: [0x04,0x00,0xc4,0xd4,0xb0,0x02,0x02,0x00] + s_and_saveexec_b64 s[10:11], s[4:5] ; encoding: [0x04,0x24,0x8a,0xbe] + s_cbranch_execz 9 ; encoding: [0x09,0x00,0x88,0xbf] + ds_swizzle_b32 v3, v2 offset:swizzle(SWAP,8) ; encoding: [0x1f,0x20,0xd4,0xd8,0x02,0x00,0x00,0x03] + ds_swizzle_b32 v5, v2 offset:swizzle(BROADCAST,16,15) ; encoding: [0xf0,0x01,0xd4,0xd8,0x02,0x00,0x00,0x05] + v_xor_b32_e32 v6, 8, v1 ; encoding: [0x88,0x02,0x0c,0x3a] + v_lshlrev_b32_e32 v6, 2, v6 ; encoding: [0x82,0x0c,0x0c,0x34] + ds_bpermute_b32 v4, v6, v2 ; encoding: [0x00,0x00,0xcc,0xda,0x06,0x02,0x00,0x04] + s_waitcnt lgkmcnt(0) ; encoding: [0x7f,0xc0,0x8c,0xbf] + s_mov_b64 exec, s[6:7] ; encoding: [0x06,0x04,0xfe,0xbe] + v_cmpx_eq_u32_e32 0, v1 ; encoding: [0x80,0x02,0xa4,0x7d] + v_mov_b32_e32 v20, v3 ; encoding: [0x03,0x03,0x28,0x7e] + v_mov_b32_e32 v21, 0 ; encoding: [0x80,0x02,0x2a,0x7e] + buffer_store_dword v20, v21, s[0:3], 0 offen ; encoding: [0x00,0x10,0x70,0xe0,0x15,0x14,0x00,0x80] + s_mov_b64 exec, s[6:7] ; encoding: [0x06,0x04,0xfe,0xbe] + v_cmpx_eq_u32_e32 31, v1 ; encoding: [0x9f,0x02,0xa4,0x7d] + v_mov_b32_e32 v20, v3 ; encoding: [0x03,0x03,0x28,0x7e] + v_mov_b32_e32 v21, 4 ; encoding: [0x84,0x02,0x2a,0x7e] + buffer_store_dword v20, v21, s[0:3], 0 offen ; encoding: [0x00,0x10,0x70,0xe0,0x15,0x14,0x00,0x80] + s_mov_b64 exec, s[6:7] ; encoding: [0x06,0x04,0xfe,0xbe] + v_cmpx_eq_u32_e32 33, v1 ; encoding: [0xa1,0x02,0xa4,0x7d] + v_mov_b32_e32 v20, v3 ; encoding: [0x03,0x03,0x28,0x7e] + v_mov_b32_e32 v21, 8 ; encoding: [0x88,0x02,0x2a,0x7e] + buffer_store_dword v20, v21, s[0:3], 0 offen ; encoding: [0x00,0x10,0x70,0xe0,0x15,0x14,0x00,0x80] + s_mov_b64 exec, s[6:7] ; encoding: [0x06,0x04,0xfe,0xbe] + v_cmpx_eq_u32_e32 39, v1 ; encoding: [0xa7,0x02,0xa4,0x7d] + v_mov_b32_e32 v20, v3 ; encoding: [0x03,0x03,0x28,0x7e] + v_mov_b32_e32 v21, 12 ; encoding: [0x8c,0x02,0x2a,0x7e] + buffer_store_dword v20, v21, s[0:3], 0 offen ; encoding: [0x00,0x10,0x70,0xe0,0x15,0x14,0x00,0x80] + s_mov_b64 exec, s[6:7] ; encoding: [0x06,0x04,0xfe,0xbe] + v_cmpx_eq_u32_e32 20, v1 ; encoding: [0x94,0x02,0xa4,0x7d] + v_mov_b32_e32 v20, v4 ; encoding: [0x04,0x03,0x28,0x7e] + v_mov_b32_e32 v21, 16 ; encoding: [0x90,0x02,0x2a,0x7e] + buffer_store_dword v20, v21, s[0:3], 0 offen ; encoding: [0x00,0x10,0x70,0xe0,0x15,0x14,0x00,0x80] + s_mov_b64 exec, s[6:7] ; encoding: [0x06,0x04,0xfe,0xbe] + v_cmpx_eq_u32_e32 33, v1 ; encoding: [0xa1,0x02,0xa4,0x7d] + v_mov_b32_e32 v20, v4 ; encoding: [0x04,0x03,0x28,0x7e] + v_mov_b32_e32 v21, 20 ; encoding: [0x94,0x02,0x2a,0x7e] + buffer_store_dword v20, v21, s[0:3], 0 offen ; encoding: [0x00,0x10,0x70,0xe0,0x15,0x14,0x00,0x80] + s_mov_b64 exec, s[6:7] ; encoding: [0x06,0x04,0xfe,0xbe] + v_cmpx_eq_u32_e32 20, v1 ; encoding: [0x94,0x02,0xa4,0x7d] + v_mov_b32_e32 v20, v5 ; encoding: [0x05,0x03,0x28,0x7e] + v_mov_b32_e32 v21, 24 ; encoding: [0x98,0x02,0x2a,0x7e] + buffer_store_dword v20, v21, s[0:3], 0 offen ; encoding: [0x00,0x10,0x70,0xe0,0x15,0x14,0x00,0x80] + s_mov_b64 exec, s[6:7] ; encoding: [0x06,0x04,0xfe,0xbe] + v_cmpx_eq_u32_e32 35, v1 ; encoding: [0xa3,0x02,0xa4,0x7d] + v_mov_b32_e32 v20, v5 ; encoding: [0x05,0x03,0x28,0x7e] + v_mov_b32_e32 v21, 28 ; encoding: [0x9c,0x02,0x2a,0x7e] + buffer_store_dword v20, v21, s[0:3], 0 offen ; encoding: [0x00,0x10,0x70,0xe0,0x15,0x14,0x00,0x80] + s_endpgm ; encoding: [0x00,0x00,0x81,0xbf] diff --git a/tests/semantic/test_w64x_partial_swizzle.py b/tests/semantic/test_w64x_partial_swizzle.py index d2bbe9fa8..7bd5bb8ab 100644 --- a/tests/semantic/test_w64x_partial_swizzle.py +++ b/tests/semantic/test_w64x_partial_swizzle.py @@ -18,11 +18,16 @@ from pathlib import Path from unittest.mock import patch sys.path.insert(0, str(Path(__file__).resolve().parent)) -from support import rdna2spirv, translate_lines # noqa: E402 +import check_absent_lane_ub as checker # noqa: E402 +from support import rdna2spirv, translate_lines, translate_listing # noqa: E402 from test_wave64_emulate_opt import VSHARP, run_emulated_workgroup # noqa: E402 +ROOT = Path(__file__).resolve().parents[2] POISON = 0xDEADBEEF FIXTURE = Path(__file__).with_name("fixtures") / "w64x_partial_swizzle.asm" +DISASM_FIXTURE = Path(__file__).with_name("fixtures") / "disasm" / "cs_w64x_partial_swizzle.s" +GPU_ASM = ROOT / "runtime" / "test" / "shaders" / "cs_w64x_partial_swizzle.asm" +GPU_EXPECTED = [508, 523, 0, 0, 528, 0, 531, 0] def translate(threads, emulate=True): @@ -72,6 +77,30 @@ class PartialWaveSwizzle(unittest.TestCase): plain = translate(64) self.assertEqual(translate(64), plain) + def test_disasm_fixture_matches_asm_and_translates(self): + """The pre-disassembled GPU test listing has the `; encoding:` bytes `s_cbranch_execz` needs.""" + def mnemonics(lines): + return [re.sub(r"_e32$", "", ln.split()[0]) for ln in lines] + + asm = [ln.strip() for ln in GPU_ASM.read_text(encoding="utf-8").splitlines() + if ln.strip() and not ln.lstrip().startswith(";")] + raw = DISASM_FIXTURE.read_bytes() + listing = [ln.strip() for ln in raw.decode("utf-8").splitlines()[1:] if ln.strip()] + self.assertEqual(mnemonics(listing), mnemonics(asm)) + + fssm = bytearray(0x148) + struct.pack_into("<4I", fssm, 0x138, 0x8, 40, 1, 1) + for emulate in (False, True): + with self.subTest(emulate=emulate): + with patch.object(rdna2spirv, "WAVE64_EMULATE", emulate): + spv = translate_listing("cs_w64x_partial_swizzle", raw, fssm=bytes(fssm)) + self.assertIn("OpEntryPoint", spv) + self.assertEqual(checker.check_absent_lane_ub(spv), []) + if emulate: + mem, _ = run_emulated_workgroup(spv, (40, 1, 1), push_constants=VSHARP + [0] * 28) + got = [mem.get(4 * i, 0) for i in range(len(GPU_EXPECTED))] + self.assertEqual(got, GPU_EXPECTED) + if __name__ == "__main__": unittest.main()