| 1 |
/* Test 32-bit fetch and non-fetch atomic operations. */ |
| 2 |
/* { dg-do compile } */ |
| 3 |
/* { dg-options "-mv3-atomics -O2 -masm=normal" } */ |
| 4 |
|
| 5 |
/* Note that GCC optimizes __atomic_add_fetch calls whose return value is not |
| 6 |
used into non-fetching operations that, in BPF, generate fetching |
| 7 |
instructions anyway. See note in gcc/config/bpf/atomic.md on this |
| 8 |
regard. */ |
| 9 |
|
| 10 |
int val; |
| 11 |
|
| 12 |
void |
| 13 |
test_atomic_add (int x) |
| 14 |
{ |
| 15 |
__atomic_add_fetch (&val, x, __ATOMIC_ACQUIRE); |
| 16 |
} |
| 17 |
|
| 18 |
long |
| 19 |
test_used_atomic_add (int x) |
| 20 |
{ |
| 21 |
return __atomic_add_fetch (&val, x, __ATOMIC_ACQUIRE); |
| 22 |
} |
| 23 |
|
| 24 |
void |
| 25 |
test_atomic_sub (int x) |
| 26 |
{ |
| 27 |
__atomic_add_fetch (&val, x, __ATOMIC_ACQUIRE); |
| 28 |
} |
| 29 |
|
| 30 |
long |
| 31 |
test_used_atomic_sub (int x) |
| 32 |
{ |
| 33 |
return __atomic_add_fetch (&val, x, __ATOMIC_ACQUIRE); |
| 34 |
} |
| 35 |
|
| 36 |
void |
| 37 |
test_atomic_and (int x) |
| 38 |
{ |
| 39 |
__atomic_and_fetch (&val, x, __ATOMIC_ACQUIRE); |
| 40 |
} |
| 41 |
|
| 42 |
long |
| 43 |
test_used_atomic_and (int x) |
| 44 |
{ |
| 45 |
return __atomic_and_fetch (&val, x, __ATOMIC_ACQUIRE); |
| 46 |
} |
| 47 |
|
| 48 |
void |
| 49 |
test_atomic_nand (int x) |
| 50 |
{ |
| 51 |
__atomic_nand_fetch (&val, x, __ATOMIC_ACQUIRE); |
| 52 |
} |
| 53 |
|
| 54 |
long |
| 55 |
test_used_atomic_nand (int x) |
| 56 |
{ |
| 57 |
return __atomic_nand_fetch (&val, x, __ATOMIC_ACQUIRE); |
| 58 |
} |
| 59 |
|
| 60 |
void |
| 61 |
test_atomic_or (int x) |
| 62 |
{ |
| 63 |
__atomic_or_fetch (&val, x, __ATOMIC_ACQUIRE); |
| 64 |
} |
| 65 |
|
| 66 |
long |
| 67 |
test_used_atomic_or (int x) |
| 68 |
{ |
| 69 |
return __atomic_or_fetch (&val, x, __ATOMIC_ACQUIRE); |
| 70 |
} |
| 71 |
|
| 72 |
void |
| 73 |
test_atomic_xor (int x) |
| 74 |
{ |
| 75 |
__atomic_xor_fetch (&val, x, __ATOMIC_ACQUIRE); |
| 76 |
} |
| 77 |
|
| 78 |
long |
| 79 |
test_used_atomic_xor (int x) |
| 80 |
{ |
| 81 |
return __atomic_xor_fetch (&val, x, __ATOMIC_ACQUIRE); |
| 82 |
} |
| 83 |
|
| 84 |
/* sub implemented in terms of add. */ |
| 85 |
/* { dg-final { scan-assembler-times "afadd32" 4 } } */ |
| 86 |
/* { dg-final { scan-assembler-times "afand32\t" 2 } } */ |
| 87 |
/* nand must use an exchange loop */ |
| 88 |
/* { dg-final { scan-assembler "acmp32\t" } } */ |
| 89 |
/* { dg-final { scan-assembler-times "afor32\t" 2 } } */ |
| 90 |
/* { dg-final { scan-assembler-times "afxor32\t" 2 } } */ |