OSDN Git Service

2012-01-03 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / atomic-compare-exchange-5.c
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 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 }