1 /* Test __atomic routines for existence and proper execution on 8 byte
2    values with each valid memory model.  */
3 /* { dg-do run } */
4 /* { dg-options "" } */
5 
6 /* Test the execution of __atomic_compare_exchange_n builtin for a long_long.  */
7 
8 extern void abort(void);
9 
10 long long v = 0;
11 long long expected = 0;
12 long long max = ~0;
13 long long desired = ~0;
14 long long zero = 0;
15 
16 #define STRONG 0
17 #define WEAK 1
18 
19 int
main()20 main ()
21 {
22 
23   if (!__atomic_compare_exchange_n (&v, &expected, max, STRONG , __ATOMIC_RELAXED, __ATOMIC_RELAXED))
24     abort ();
25   if (expected != 0)
26     abort ();
27 
28   if (__atomic_compare_exchange_n (&v, &expected, 0, STRONG , __ATOMIC_ACQUIRE, __ATOMIC_RELAXED))
29     abort ();
30   if (expected != max)
31     abort ();
32 
33   if (!__atomic_compare_exchange_n (&v, &expected, 0, STRONG , __ATOMIC_RELEASE, __ATOMIC_ACQUIRE))
34     abort ();
35   if (expected != max)
36     abort ();
37   if (v != 0)
38     abort ();
39 
40   if (__atomic_compare_exchange_n (&v, &expected, desired, WEAK, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE))
41     abort ();
42   if (expected != 0)
43     abort ();
44 
45   if (!__atomic_compare_exchange_n (&v, &expected, desired, STRONG , __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
46     abort ();
47   if (expected != 0)
48     abort ();
49   if (v != max)
50     abort ();
51 
52   /* Now test the generic version.  */
53 
54   v = 0;
55 
56   if (!__atomic_compare_exchange (&v, &expected, &max, STRONG, __ATOMIC_RELAXED, __ATOMIC_RELAXED))
57     abort ();
58   if (expected != 0)
59     abort ();
60 
61   if (__atomic_compare_exchange (&v, &expected, &zero, STRONG , __ATOMIC_ACQUIRE, __ATOMIC_RELAXED))
62     abort ();
63   if (expected != max)
64     abort ();
65 
66   if (!__atomic_compare_exchange (&v, &expected, &zero, STRONG , __ATOMIC_RELEASE, __ATOMIC_ACQUIRE))
67     abort ();
68   if (expected != max)
69     abort ();
70   if (v != 0)
71     abort ();
72 
73   if (__atomic_compare_exchange (&v, &expected, &desired, WEAK, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE))
74     abort ();
75   if (expected != 0)
76     abort ();
77 
78   if (!__atomic_compare_exchange (&v, &expected, &desired, STRONG , __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
79     abort ();
80   if (expected != 0)
81     abort ();
82   if (v != max)
83     abort ();
84 
85   return 0;
86 }
87