Debian Codegraph @

gcc/testsuite/gcc.target/i386/pr103069-4.c

raw
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-3.c"
7
8 #define FUNC_CMPXCHG_RELAX(TYPE) \
9 __attribute__ ((noinline, noclone, target ("relax-cmpxchg-loop"))) \
10 TYPE relax_##TYPE##_cmpxchg (TYPE *lock, TYPE newval, TYPE oldval) \
11 { \
12 do \
13 { \
14 newval = oldval | 1; \
15 } while (! __atomic_compare_exchange_n (lock, &oldval, newval, \
16 0, __ATOMIC_RELEASE, \
17 __ATOMIC_RELAXED)); \
18 return *lock; \
19 }
20
21 FUNC_CMPXCHG_RELAX (int64_t)
22 FUNC_CMPXCHG_RELAX (int)
23 FUNC_CMPXCHG_RELAX (short)
24 FUNC_CMPXCHG_RELAX (char)
25
26 #define TEST_CMPXCHG_LOOP(TYPE) \
27 { \
28 TYPE a = 11, b = 20, c = 11, res, exp; \
29 TYPE d = 11, e = 20, f = 11; \
30 res = relax_##TYPE##_cmpxchg (&a, b, c); \
31 exp = f_##TYPE##_cmpxchg (&d, e, f); \
32 if (res != exp || a != d) \
33 abort (); \
34 }
35
36 int main (void)
37 {
38 TEST_CMPXCHG_LOOP (int64_t)
39 TEST_CMPXCHG_LOOP (int)
40 TEST_CMPXCHG_LOOP (short)
41 TEST_CMPXCHG_LOOP (char)
42 return 0;
43 }