diff options
| author | fearkov <289226582+fearkov@users.noreply.github.com> | 2026-11-22 11:15:57 -0400 |
|---|---|---|
| committer | fearkov <289226582+fearkov@users.noreply.github.com> | 2026-11-22 11:16:15 -0400 |
| commit | bb1e9a72a817ffabeee537d69d3be21ec6919653 (patch) | |
| tree | 9ae393ffde7eeb0f703f1524b6e74dac388c5895 | |
| parent | 6a6704df1592e1dc4a3215ddf1423a78adb52045 (diff) | |
Translator: a 64-bit exchange done per dword can tear
buffer_atomic_swap_x2, global_atomic_swap_x2 and ds_wrxchg*_rtn_b64 do one 32-bit exchange per dword, which the comments said leaves the same memory as a 64-bit exchange. Two lanes swapping into one element at once can leave one's low dword with the other's high dword. The claim holds for and/or/xor only, whose bits are independent.
| -rw-r--r-- | tests/semantic/test_buffer_atomics_x2.py | 5 | ||||
| -rw-r--r-- | tests/semantic/test_global_atomics_x2.py | 5 | ||||
| -rw-r--r-- | tools/rdna2spirv.py | 24 |
3 files changed, 20 insertions, 14 deletions
diff --git a/tests/semantic/test_buffer_atomics_x2.py b/tests/semantic/test_buffer_atomics_x2.py index 563c163b6..1fb130fcc 100644 --- a/tests/semantic/test_buffer_atomics_x2.py +++ b/tests/semantic/test_buffer_atomics_x2.py | |||
| @@ -1,8 +1,9 @@ | |||
| 1 | """Value tests for RDNA2 buffer_atomic_{and,or,xor,swap}_x2, run through spirv_mini_interp on the CPU. | 1 | """Value tests for RDNA2 buffer_atomic_{and,or,xor,swap}_x2, run through spirv_mini_interp on the CPU. |
| 2 | 2 | ||
| 3 | M = op(M, DATA) on the 64-bit element (two dwords, low first) at the MUBUF address; with glc the old 64 bits come | 3 | M = op(M, DATA) on the 64-bit element (two dwords, low first) at the MUBUF address; with glc the old 64 bits come |
| 4 | back in vdata[0:1]. The translator does one 32-bit atomic per dword (exact memory for a bitwise op or an exchange) and | 4 | back in vdata[0:1]. The translator does one 32-bit atomic per dword (exact memory for a bitwise op, and for an exchange |
| 5 | checks bounds for the whole 8-byte element, all or nothing. The V# here is raw (OOB_SELECT 3): an access is in range | 5 | by one lane at a time: two lanes swapping into one element at once can tear it) and checks bounds for the whole 8-byte |
| 6 | element, all or nothing. The V# here is raw (OOB_SELECT 3): an access is in range | ||
| 6 | when offset + 8 <= num_records. Standard library only; no GPU, no game files. | 7 | when offset + 8 <= num_records. Standard library only; no GPU, no game files. |
| 7 | """ | 8 | """ |
| 8 | import os | 9 | import os |
diff --git a/tests/semantic/test_global_atomics_x2.py b/tests/semantic/test_global_atomics_x2.py index 13137d868..d0da12d5b 100644 --- a/tests/semantic/test_global_atomics_x2.py +++ b/tests/semantic/test_global_atomics_x2.py | |||
| @@ -1,8 +1,9 @@ | |||
| 1 | """Value tests for RDNA2 global_atomic_{and,or,xor,swap}_x2, run through spirv_mini_interp on the CPU. | 1 | """Value tests for RDNA2 global_atomic_{and,or,xor,swap}_x2, run through spirv_mini_interp on the CPU. |
| 2 | 2 | ||
| 3 | M = op(M, DATA) on the 64-bit element at the global_* address (two dwords, low first); with glc the old 64 bits land in | 3 | M = op(M, DATA) on the 64-bit element at the global_* address (two dwords, low first); with glc the old 64 bits land in |
| 4 | vdst[0:1]. The translator does one 32-bit atomic per dword, which leaves the same memory for a bitwise op or an | 4 | vdst[0:1]. The translator does one 32-bit atomic per dword, which leaves the same memory for a bitwise op, and for an |
| 5 | exchange. The carrying and comparing _x2 forms stay Unsupported. Standard library only; no GPU, no game files. | 5 | exchange by one lane at a time (two lanes swapping into one element at once can tear it). The carrying and comparing |
| 6 | _x2 forms stay Unsupported. Standard library only; no GPU, no game files. | ||
| 6 | """ | 7 | """ |
| 7 | import os | 8 | import os |
| 8 | import random | 9 | import random |
diff --git a/tools/rdna2spirv.py b/tools/rdna2spirv.py index 6806a4b1b..882aff232 100644 --- a/tools/rdna2spirv.py +++ b/tools/rdna2spirv.py | |||
| @@ -1436,8 +1436,10 @@ class Gen: | |||
| 1436 | (RDNA2 ISA, FLAT/GLOBAL). With glc the pre-op value lands in vdst (the first operand); without it there is no | 1436 | (RDNA2 ISA, FLAT/GLOBAL). With glc the pre-op value lands in vdst (the first operand); without it there is no |
| 1437 | vdst. cmpswap takes vdata as a pair {DATA, CMP}: M = (M == CMP) ? DATA : M. Inactive lanes don't touch memory | 1437 | vdst. cmpswap takes vdata as a pair {DATA, CMP}: M = (M == CMP) ? DATA : M. Inactive lanes don't touch memory |
| 1438 | and keep vdst. and/or/xor/swap_x2 work on a 64-bit element (two dwords, low first) as one 32-bit atomic per | 1438 | and keep vdst. and/or/xor/swap_x2 work on a 64-bit element (two dwords, low first) as one 32-bit atomic per |
| 1439 | dword: a bitwise op or an exchange leaves the same memory that way, with no Int64 atomics. The returned pair is | 1439 | dword, with no Int64 atomics. That leaves the same memory for a bitwise op, whose bits are independent, but not |
| 1440 | two reads, so another lane's 64-bit op on the same element between them could be seen half done. The other | 1440 | always for an exchange: two lanes swapping into one element at once can leave one's low dword with the other's |
| 1441 | high dword (A.lo, B.lo, B.hi, A.hi). The returned pair is two reads, so another lane's 64-bit op on the same | ||
| 1442 | element between them could be seen half done. The other | ||
| 1441 | _x2 forms (add/sub/min/max carry or compare across the dwords, cmpswap_x2 compares all 64 bits), inc/dec and | 1443 | _x2 forms (add/sub/min/max carry or compare across the dwords, cmpswap_x2 compares all 64 bits), inc/dec and |
| 1442 | the float atomics stay Unsupported.""" | 1444 | the float atomics stay Unsupported.""" |
| 1443 | kind = op[len("global_atomic_"):] | 1445 | kind = op[len("global_atomic_"):] |
| @@ -1553,10 +1555,11 @@ class Gen: | |||
| 1553 | 1555 | ||
| 1554 | def buffer_atomic_x2(self, op, kind, a, mods): | 1556 | def buffer_atomic_x2(self, op, kind, a, mods): |
| 1555 | """buffer_atomic_{and,or,xor,swap}_x2 vdata[0:1], vaddr, s[V#], soffset: M = op(M, DATA) on the 64-bit element | 1557 | """buffer_atomic_{and,or,xor,swap}_x2 vdata[0:1], vaddr, s[V#], soffset: M = op(M, DATA) on the 64-bit element |
| 1556 | (two dwords, low first); with glc the old 64 bits are returned in vdata. A bitwise op or an exchange leaves the | 1558 | (two dwords, low first); with glc the old 64 bits are returned in vdata. Each dword is its own 32-bit atomic, so |
| 1557 | same memory done one dword at a time, so each dword is its own 32-bit atomic and no Int64 atomics are needed; | 1559 | no Int64 atomics are needed. That leaves the same memory for a bitwise op, whose bits are independent, but an |
| 1558 | the returned pair is two reads, so another lane's 64-bit op on the same element between them could be seen half | 1560 | exchange can tear: two lanes swapping into one element at once can leave one's low dword with the other's high |
| 1559 | done. The bounds check covers the whole 8-byte element, all or nothing, as for a typed element (a 32_32 | 1561 | dword (A.lo, B.lo, B.hi, A.hi). The returned pair is two reads, so another lane's 64-bit op on the same element |
| 1562 | between them could be seen half done. The bounds check covers the whole 8-byte element, all or nothing, as for a typed element (a 32_32 | ||
| 1560 | format): how hardware treats a 64-bit atomic that is only partly in range is not measured.""" | 1563 | format): how hardware treats a 64-bit atomic that is only partly in range is not measured.""" |
| 1561 | vd = a[0] | 1564 | vd = a[0] |
| 1562 | if vd["k"] != "vgpr" or vd.get("n", 1) != 2: | 1565 | if vd["k"] != "vgpr" or vd.get("n", 1) != 2: |
| @@ -2628,10 +2631,11 @@ class Gen: | |||
| 2628 | elif op in ("ds_wrxchg_rtn_b64", "ds_wrxchg2_rtn_b64", "ds_wrxchg2st64_rtn_b64"): | 2631 | elif op in ("ds_wrxchg_rtn_b64", "ds_wrxchg2_rtn_b64", "ds_wrxchg2st64_rtn_b64"): |
| 2629 | # 64-bit exchanges: M[A] = DATA (two dwords, low first) and vdst gets the old 64 bits. wrxchg_rtn_b64 has | 2632 | # 64-bit exchanges: M[A] = DATA (two dwords, low first) and vdst gets the old 64 bits. wrxchg_rtn_b64 has |
| 2630 | # one element at ADDR + offset; the 2 forms have two, at ADDR + offset0/offset1 * 8 (x64 for st64), as | 2633 | # one element at ADDR + offset; the 2 forms have two, at ADDR + offset0/offset1 * 8 (x64 for st64), as |
| 2631 | # ds_write2_b64 addresses them, and vdst is four VGPRs. Each dword is its own 32-bit exchange: the memory | 2634 | # ds_write2_b64 addresses them, and vdst is four VGPRs. Each dword is its own 32-bit exchange, with no Int64 |
| 2632 | # ends as a 64-bit exchange leaves it (both dwords take DATA), with no Int64 atomics on Workgroup memory. | 2635 | # atomics on Workgroup memory. That can tear: two lanes exchanging into one element at once can leave one's |
| 2633 | # The returned pair is two reads, so another lane's 64-bit op on the same element between them could be | 2636 | # low dword with the other's high dword (A.lo, B.lo, B.hi, A.hi), which a 64-bit exchange never does. The |
| 2634 | # seen half done (as for ds_and/or/xor_b64). | 2637 | # returned pair is two reads, so another lane's 64-bit op on the same element between them could be seen |
| 2638 | # half done (as for ds_and/or/xor_b64). | ||
| 2635 | two = op != "ds_wrxchg_rtn_b64" | 2639 | two = op != "ds_wrxchg_rtn_b64" |
| 2636 | d = a[0] | 2640 | d = a[0] |
| 2637 | if d["k"] != "vgpr" or d.get("n") != (4 if two else 2): | 2641 | if d["k"] != "vgpr" or d.get("n") != (4 if two else 2): |