From c53551d6b627d5b21802de58b4a48b8068a8fc6f Mon Sep 17 00:00:00 2001 From: Moriz82 <72836413+Moriz82@users.noreply.github.com> Date: Tue, 24 Nov 2026 15:10:57 -0600 Subject: [PATCH] tests: run raw buffer atomics addressed by soffset alone (TEST-ATOMIC-SOFFSET-BOUNDS) No test ran a buffer atomic with a non-zero scalar offset: all 57 buffer_atomic_* instructions in the tests and the GPU fixtures pass 0 there. The three atomic lowerings (32-bit integer, float min/max, 64-bit _x2) each hand their operands to the shared address code on their own, so dropping the operand in any of them went unnoticed. Add one test that addresses the element through soffset only and checks the documented raw bound on both sides of the limit for each lowering. Test only; the translator is unchanged. The test passes on main. With soffset dropped at the three atomic call sites, the translator suite (470 files, 6,169 tests) fails in this test only, in all 6 of its subtests. On the branch the suite has 0 failing files, and of the other Python test files only tests/test_imhex_patterns.py fails, as on main. AI-assisted (Claude Code). Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 --- .../test_buffer_atomic_fminmax_and_align.py | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/tests/semantic/test_buffer_atomic_fminmax_and_align.py b/tests/semantic/test_buffer_atomic_fminmax_and_align.py index e1399d69a5..f4a5b2902b 100644 --- a/tests/semantic/test_buffer_atomic_fminmax_and_align.py +++ b/tests/semantic/test_buffer_atomic_fminmax_and_align.py @@ -239,18 +239,35 @@ def test_no_float_atomic_capability_and_rejected_forms(self): class AtomicNaturalAlignment(unittest.TestCase): def test_raw_atomic_soffset_only(self): - # No vaddr. The same backed word is in range at N=8 and out of range at N=7. - for num_bytes, old_value, stored_value in ((8, 19, 22), (7, 0, 19)): - with self.subTest(num_bytes=num_bytes): - body = buf_rsrc_lines(TARGET, 0, num_bytes, RAW_W3) + [ - "s_mov_b32 s12, 4", - "v_mov_b32_e32 v2, 3", - "buffer_atomic_add v2, off, s[8:11], s12 glc", - "s_waitcnt vmcnt(0)", - ] + out_store_lines("v2") - mem = run(body, {TARGET: SENTINEL, TARGET + 4: 19}) - self.assertEqual((mem[TARGET], mem[TARGET + 4], mem[OUT]), - (SENTINEL, stored_value, old_value)) + # No vaddr and no instruction offset: the address and the raw bound (offset + soffset + size > NUM_RECORDS, + # docs/buffer_bounds.md) come from soffset alone, in each atomic lowering: 32-bit integer, float min/max + # and 64-bit _x2. The same backed element is in range at N = soffset + size and out of range one byte short. + one, two = 0x3F800000, 0x40000000 + for op, soffset, data, before, after in ( + ("add", 4, (3,), (19,), (22,)), + ("fmax", 4, (two,), (one,), (two,)), + ("swap_x2", 8, (5, 6), (19, 20), (5, 6)), + ): + n = len(data) + reg = "v2" if n == 1 else "v[2:3]" + for num_bytes in (soffset + 4 * n, soffset + 4 * n - 1): + with self.subTest(op=op, num_bytes=num_bytes): + in_range = num_bytes == soffset + 4 * n + body = buf_rsrc_lines(TARGET, 0, num_bytes, RAW_W3) + [ + f"s_mov_b32 s12, {soffset}", + *(f"v_mov_b32_e32 v{2 + i}, {word:#x}" for i, word in enumerate(data)), + f"buffer_atomic_{op} {reg}, off, s[8:11], s12 glc", + "s_waitcnt vmcnt(0)", + ] + out_store_lines(reg, count=n) + memory = {TARGET + 4 * i: SENTINEL for i in range(soffset // 4)} + memory.update({TARGET + soffset + 4 * i: word for i, word in enumerate(before)}) + mem = run(body, memory) + self.assertEqual([mem[TARGET + 4 * i] for i in range(soffset // 4)], + [SENTINEL] * (soffset // 4)) + self.assertEqual(tuple(mem[TARGET + soffset + 4 * i] for i in range(n)), + after if in_range else before) + self.assertEqual(tuple(mem[OUT + 4 * i] for i in range(n)), + before if in_range else (0,) * n) def test_buffer_atomic_32bit_alignment(self): # Measured natively on gfx1036 (wave32 & wave64): (addr & 3) != 0 drops the atomic;