| 1 |
/* PR target/103069 */ |
| 2 |
/* { dg-do run } */ |
| 3 |
/* { dg-additional-options "-O2 -march=x86-64 -mtune=generic" } */ |
| 4 |
|
| 5 |
#include <stdlib.h> |
| 6 |
#include "pr103069-1.c" |
| 7 |
|
| 8 |
#define FUNC_ATOMIC_RELAX(TYPE, OP) \ |
| 9 |
__attribute__ ((noinline, noclone, target ("relax-cmpxchg-loop"))) \ |
| 10 |
TYPE relax_##TYPE##_##OP##_fetch (TYPE *a, TYPE b) \ |
| 11 |
{ \ |
| 12 |
return __atomic_##OP##_fetch (a, b, __ATOMIC_RELAXED); \ |
| 13 |
} \ |
| 14 |
__attribute__ ((noinline, noclone, target ("relax-cmpxchg-loop"))) \ |
| 15 |
TYPE relax_##TYPE##_fetch_##OP (TYPE *a, TYPE b) \ |
| 16 |
{ \ |
| 17 |
return __atomic_fetch_##OP (a, b, __ATOMIC_RELAXED); \ |
| 18 |
} |
| 19 |
|
| 20 |
FUNC_ATOMIC_RELAX (int64_t, and) |
| 21 |
FUNC_ATOMIC_RELAX (int64_t, nand) |
| 22 |
FUNC_ATOMIC_RELAX (int64_t, or) |
| 23 |
FUNC_ATOMIC_RELAX (int64_t, xor) |
| 24 |
FUNC_ATOMIC_RELAX (int, and) |
| 25 |
FUNC_ATOMIC_RELAX (int, nand) |
| 26 |
FUNC_ATOMIC_RELAX (int, or) |
| 27 |
FUNC_ATOMIC_RELAX (int, xor) |
| 28 |
FUNC_ATOMIC_RELAX (short, and) |
| 29 |
FUNC_ATOMIC_RELAX (short, nand) |
| 30 |
FUNC_ATOMIC_RELAX (short, or) |
| 31 |
FUNC_ATOMIC_RELAX (short, xor) |
| 32 |
FUNC_ATOMIC_RELAX (char, and) |
| 33 |
FUNC_ATOMIC_RELAX (char, nand) |
| 34 |
FUNC_ATOMIC_RELAX (char, or) |
| 35 |
FUNC_ATOMIC_RELAX (char, xor) |
| 36 |
|
| 37 |
#define TEST_ATOMIC_FETCH_LOGIC(TYPE, OP) \ |
| 38 |
{ \ |
| 39 |
TYPE a = 11, b = 101, res, exp; \ |
| 40 |
TYPE c = 11, d = 101; \ |
| 41 |
res = relax_##TYPE##_##OP##_fetch (&a, b); \ |
| 42 |
exp = f_##TYPE##_##OP##_fetch (&c, d); \ |
| 43 |
if (res != exp || a != c) \ |
| 44 |
abort (); \ |
| 45 |
a = c = 21, b = d = 92; \ |
| 46 |
res = relax_##TYPE##_fetch_##OP (&a, b); \ |
| 47 |
exp = f_##TYPE##_fetch_##OP (&c, d); \ |
| 48 |
if (res != exp || a != c) \ |
| 49 |
abort (); \ |
| 50 |
} |
| 51 |
|
| 52 |
int main (void) |
| 53 |
{ |
| 54 |
TEST_ATOMIC_FETCH_LOGIC (int64_t, and) |
| 55 |
TEST_ATOMIC_FETCH_LOGIC (int64_t, nand) |
| 56 |
TEST_ATOMIC_FETCH_LOGIC (int64_t, or) |
| 57 |
TEST_ATOMIC_FETCH_LOGIC (int64_t, xor) |
| 58 |
TEST_ATOMIC_FETCH_LOGIC (int, and) |
| 59 |
TEST_ATOMIC_FETCH_LOGIC (int, nand) |
| 60 |
TEST_ATOMIC_FETCH_LOGIC (int, or) |
| 61 |
TEST_ATOMIC_FETCH_LOGIC (int, xor) |
| 62 |
TEST_ATOMIC_FETCH_LOGIC (short, and) |
| 63 |
TEST_ATOMIC_FETCH_LOGIC (short, nand) |
| 64 |
TEST_ATOMIC_FETCH_LOGIC (short, or) |
| 65 |
TEST_ATOMIC_FETCH_LOGIC (short, xor) |
| 66 |
TEST_ATOMIC_FETCH_LOGIC (char, and) |
| 67 |
TEST_ATOMIC_FETCH_LOGIC (char, nand) |
| 68 |
TEST_ATOMIC_FETCH_LOGIC (char, or) |
| 69 |
TEST_ATOMIC_FETCH_LOGIC (char, xor) |
| 70 |
return 0; |
| 71 |
} |