OSDN Git Service

PR testsuite/51258
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / simulate-thread / atomic-other-longlong.c
1 /* { dg-do link } */
2 /* { dg-require-effective-target sync_long_long_runtime } */
3 /* { dg-options "" } */
4 /* { dg-final { simulate-thread } } */
5
6
7 #include <stdio.h>
8 #include "simulate-thread.h"
9
10 /* Test all the __sync routines for proper atomicity on 8 byte values.  */
11
12 unsigned long long zero = 0;
13 unsigned long long max = ~0;
14
15 unsigned long long changing_value = 0;
16 unsigned long long value = 0;
17 unsigned long long ret;
18
19 void test_abort()
20 {
21   static int reported = 0;
22   if (!reported)
23     {
24       printf ("FAIL: improper execution of __sync builtin.\n");
25       reported = 1;
26     }
27 }
28
29 void simulate_thread_other_threads ()
30 {
31 }
32
33 int simulate_thread_step_verify ()
34 {
35   if (value != zero && value != max)
36     {
37       printf ("FAIL: invalid intermediate result for value.\n");
38       return 1;
39     }
40   return 0;
41 }
42
43 int simulate_thread_final_verify ()
44 {
45   if (value != 0)
46     {
47       printf ("FAIL: invalid final result for value.\n");
48       return 1;
49     }
50   return 0;
51 }
52
53 /* All values written to 'value' alternate between 'zero' and 'max'. Any other
54    value detected by simulate_thread_step_verify() between instructions would indicate
55    that the value was only partially written, and would thus fail this 
56    atomicity test.  
57
58    This function tests each different __atomic routine once, with the
59    exception of the load instruction which requires special testing.  */
60 __attribute__((noinline))
61 void simulate_thread_main()
62 {
63   ret = __atomic_exchange_n (&value, max, __ATOMIC_SEQ_CST);
64   if (ret != zero || value != max)
65     test_abort();
66
67   __atomic_store_n (&value, zero, __ATOMIC_SEQ_CST);
68   if (value != zero)
69     test_abort();
70
71   ret = __atomic_fetch_add (&value, max, __ATOMIC_SEQ_CST);
72   if (value != max || ret != zero)
73     test_abort ();
74
75   ret = __atomic_fetch_sub (&value, max, __ATOMIC_SEQ_CST);
76   if (value != zero || ret != max)
77     test_abort ();
78
79   ret = __atomic_fetch_or (&value, max, __ATOMIC_SEQ_CST);
80   if (value != max || ret != zero)
81     test_abort ();
82
83   ret = __atomic_fetch_and (&value, max, __ATOMIC_SEQ_CST);
84   if (value != max || ret != max)
85     test_abort ();
86
87   ret = __atomic_fetch_xor (&value, max, __ATOMIC_SEQ_CST);
88   if (value != zero || ret != max)
89     test_abort ();
90
91   ret = __atomic_add_fetch (&value, max, __ATOMIC_SEQ_CST);
92   if (value != max || ret != max)
93     test_abort ();
94
95   ret = __atomic_sub_fetch (&value, max, __ATOMIC_SEQ_CST);
96   if (value != zero || ret != zero)
97     test_abort ();
98
99   ret = __atomic_or_fetch (&value, max, __ATOMIC_SEQ_CST);
100   if (value != max || ret != max)
101     test_abort ();
102
103   ret = __atomic_and_fetch (&value, max, __ATOMIC_SEQ_CST);
104   if (value != max || ret != max)
105     test_abort ();
106
107   ret = __atomic_xor_fetch (&value, max, __ATOMIC_SEQ_CST);
108   if (value != zero || ret != zero)
109     test_abort ();
110 }
111
112 int main ()
113 {
114   simulate_thread_main ();
115   simulate_thread_done ();
116   return 0;
117 }