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