| 1 |
/* Test the atomic exchange expansion, shared state space. */ |
| 2 |
|
| 3 |
/* { dg-do compile } */ |
| 4 |
/* { dg-options "-Wno-long-long" } */ |
| 5 |
|
| 6 |
enum memmodel |
| 7 |
{ |
| 8 |
MEMMODEL_SEQ_CST = 5 |
| 9 |
}; |
| 10 |
|
| 11 |
unsigned char u8 __attribute__((shared)); |
| 12 |
unsigned short u16 __attribute__((shared)); |
| 13 |
unsigned int u32 __attribute__((shared)); |
| 14 |
unsigned long long int u64 __attribute__((shared)); |
| 15 |
|
| 16 |
int |
| 17 |
main() |
| 18 |
{ |
| 19 |
__atomic_exchange_n (&u8, 0, MEMMODEL_SEQ_CST); |
| 20 |
__atomic_exchange_n (&u16, 0, MEMMODEL_SEQ_CST); |
| 21 |
__atomic_exchange_n (&u32, 0, MEMMODEL_SEQ_CST); |
| 22 |
__atomic_exchange_n (&u64, 0, MEMMODEL_SEQ_CST); |
| 23 |
|
| 24 |
return 0; |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
/* Not ptx-native, fallback to libatomic. |
| 29 |
Libatomic uses generic addressing with a global lock and membar.sys barriers. |
| 30 |
We could implement these more efficiently by cloning libatomic for .shared, |
| 31 |
using a per-CTA lock and membar.cta barrier. But we'd expect |
| 32 |
performance-critical code to use the ptx-native atomic sizes 32 and 64 bit, |
| 33 |
so that doesn't seem to be worth the trouble. */ |
| 34 |
/* { dg-final { scan-assembler-times "(?n)call .* __atomic_exchange_1" 1 } } */ |
| 35 |
/* { dg-final { scan-assembler-times "(?n)call .* __atomic_exchange_2" 1 } } */ |
| 36 |
|
| 37 |
/* { dg-final { scan-assembler-times "atom.shared.exch.b32" 1 } } */ |
| 38 |
/* { dg-final { scan-assembler-times "atom.shared.exch.b64" 1 } } */ |
| 39 |
/* { dg-final { scan-assembler-times "membar.cta" 4 } } */ |