1 /* Test __atomic routines for existence and proper execution on 4 byte
2    values with each valid memory model.  */
3 /* { dg-do run } */
4 /* { dg-require-effective-target sync_int_long } */
5 
6 /* Test the execution of the __atomic_X builtin for an int.  */
7 
8 extern void abort(void);
9 
10 int v, count, ret;
11 
main()12 main ()
13 {
14   v = 0;
15   count = 0;
16 
17   if (__atomic_exchange_n (&v, count + 1, __ATOMIC_RELAXED) !=  count++)
18     abort ();
19 
20   if (__atomic_exchange_n (&v, count + 1, __ATOMIC_ACQUIRE) !=  count++)
21     abort ();
22 
23   if (__atomic_exchange_n (&v, count + 1, __ATOMIC_RELEASE) !=  count++)
24     abort ();
25 
26   if (__atomic_exchange_n (&v, count + 1, __ATOMIC_ACQ_REL) !=  count++)
27     abort ();
28 
29   if (__atomic_exchange_n (&v, count + 1, __ATOMIC_SEQ_CST) !=  count++)
30     abort ();
31 
32   /* Now test the generic version.  */
33 
34   count++;
35 
36   __atomic_exchange (&v, &count, &ret, __ATOMIC_RELAXED);
37   if (ret != count - 1 || v != count)
38     abort ();
39   count++;
40 
41   __atomic_exchange (&v, &count, &ret, __ATOMIC_ACQUIRE);
42   if (ret != count - 1 || v != count)
43     abort ();
44   count++;
45 
46   __atomic_exchange (&v, &count, &ret, __ATOMIC_RELEASE);
47   if (ret != count - 1 || v != count)
48     abort ();
49   count++;
50 
51   __atomic_exchange (&v, &count, &ret, __ATOMIC_ACQ_REL);
52   if (ret != count - 1 || v != count)
53     abort ();
54   count++;
55 
56   __atomic_exchange (&v, &count, &ret, __ATOMIC_SEQ_CST);
57   if (ret != count - 1 || v != count)
58     abort ();
59   count++;
60 
61   return 0;
62 }
63