The method of doing the matching with a 'select' instruction was wrong. The
[oota-llvm.git] / test / FrontendC / Atomics.c
1 // Test frontend handling of __sync builtins.
2 // Modified from a gcc testcase.
3 // RUN: %llvmgcc -S %s -o - | grep atomic | count 200
4 // RUN: %llvmgcc -S %s -o - | grep p0i8 | count 50
5 // RUN: %llvmgcc -S %s -o - | grep p0i16 | count 50
6 // RUN: %llvmgcc -S %s -o - | grep p0i32 | count 50
7 // RUN: %llvmgcc -S %s -o - | grep volatile | count 8
8
9 // Currently this is implemented only for Alpha, X86, PowerPC.
10 // Add your target here if it doesn't work.
11 // PPC32 does not translate the long long variants, so fails this test.
12 // XFAIL: sparc|arm|ia64|powerpc
13
14 signed char sc;
15 unsigned char uc;
16 signed short ss;
17 unsigned short us;
18 signed int si;
19 unsigned int ui;
20 signed long long sll;
21 unsigned long long ull;
22
23 void test_op_ignore (void)
24 {
25   (void) __sync_fetch_and_add (&sc, 1);
26   (void) __sync_fetch_and_add (&uc, 1);
27   (void) __sync_fetch_and_add (&ss, 1);
28   (void) __sync_fetch_and_add (&us, 1);
29   (void) __sync_fetch_and_add (&si, 1);
30   (void) __sync_fetch_and_add (&ui, 1);
31   (void) __sync_fetch_and_add (&sll, 1);
32   (void) __sync_fetch_and_add (&ull, 1);
33
34   (void) __sync_fetch_and_sub (&sc, 1);
35   (void) __sync_fetch_and_sub (&uc, 1);
36   (void) __sync_fetch_and_sub (&ss, 1);
37   (void) __sync_fetch_and_sub (&us, 1);
38   (void) __sync_fetch_and_sub (&si, 1);
39   (void) __sync_fetch_and_sub (&ui, 1);
40   (void) __sync_fetch_and_sub (&sll, 1);
41   (void) __sync_fetch_and_sub (&ull, 1);
42
43   (void) __sync_fetch_and_or (&sc, 1);
44   (void) __sync_fetch_and_or (&uc, 1);
45   (void) __sync_fetch_and_or (&ss, 1);
46   (void) __sync_fetch_and_or (&us, 1);
47   (void) __sync_fetch_and_or (&si, 1);
48   (void) __sync_fetch_and_or (&ui, 1);
49   (void) __sync_fetch_and_or (&sll, 1);
50   (void) __sync_fetch_and_or (&ull, 1);
51
52   (void) __sync_fetch_and_xor (&sc, 1);
53   (void) __sync_fetch_and_xor (&uc, 1);
54   (void) __sync_fetch_and_xor (&ss, 1);
55   (void) __sync_fetch_and_xor (&us, 1);
56   (void) __sync_fetch_and_xor (&si, 1);
57   (void) __sync_fetch_and_xor (&ui, 1);
58   (void) __sync_fetch_and_xor (&sll, 1);
59   (void) __sync_fetch_and_xor (&ull, 1);
60
61   (void) __sync_fetch_and_and (&sc, 1);
62   (void) __sync_fetch_and_and (&uc, 1);
63   (void) __sync_fetch_and_and (&ss, 1);
64   (void) __sync_fetch_and_and (&us, 1);
65   (void) __sync_fetch_and_and (&si, 1);
66   (void) __sync_fetch_and_and (&ui, 1);
67   (void) __sync_fetch_and_and (&sll, 1);
68   (void) __sync_fetch_and_and (&ull, 1);
69
70   (void) __sync_fetch_and_nand (&sc, 1);
71   (void) __sync_fetch_and_nand (&uc, 1);
72   (void) __sync_fetch_and_nand (&ss, 1);
73   (void) __sync_fetch_and_nand (&us, 1);
74   (void) __sync_fetch_and_nand (&si, 1);
75   (void) __sync_fetch_and_nand (&ui, 1);
76   (void) __sync_fetch_and_nand (&sll, 1);
77   (void) __sync_fetch_and_nand (&ull, 1);
78 }
79
80 void test_fetch_and_op (void)
81 {
82   sc = __sync_fetch_and_add (&sc, 11);
83   uc = __sync_fetch_and_add (&uc, 11);
84   ss = __sync_fetch_and_add (&ss, 11);
85   us = __sync_fetch_and_add (&us, 11);
86   si = __sync_fetch_and_add (&si, 11);
87   ui = __sync_fetch_and_add (&ui, 11);
88   sll = __sync_fetch_and_add (&sll, 11);
89   ull = __sync_fetch_and_add (&ull, 11);
90
91   sc = __sync_fetch_and_sub (&sc, 11);
92   uc = __sync_fetch_and_sub (&uc, 11);
93   ss = __sync_fetch_and_sub (&ss, 11);
94   us = __sync_fetch_and_sub (&us, 11);
95   si = __sync_fetch_and_sub (&si, 11);
96   ui = __sync_fetch_and_sub (&ui, 11);
97   sll = __sync_fetch_and_sub (&sll, 11);
98   ull = __sync_fetch_and_sub (&ull, 11);
99
100   sc = __sync_fetch_and_or (&sc, 11);
101   uc = __sync_fetch_and_or (&uc, 11);
102   ss = __sync_fetch_and_or (&ss, 11);
103   us = __sync_fetch_and_or (&us, 11);
104   si = __sync_fetch_and_or (&si, 11);
105   ui = __sync_fetch_and_or (&ui, 11);
106   sll = __sync_fetch_and_or (&sll, 11);
107   ull = __sync_fetch_and_or (&ull, 11);
108
109   sc = __sync_fetch_and_xor (&sc, 11);
110   uc = __sync_fetch_and_xor (&uc, 11);
111   ss = __sync_fetch_and_xor (&ss, 11);
112   us = __sync_fetch_and_xor (&us, 11);
113   si = __sync_fetch_and_xor (&si, 11);
114   ui = __sync_fetch_and_xor (&ui, 11);
115   sll = __sync_fetch_and_xor (&sll, 11);
116   ull = __sync_fetch_and_xor (&ull, 11);
117
118   sc = __sync_fetch_and_and (&sc, 11);
119   uc = __sync_fetch_and_and (&uc, 11);
120   ss = __sync_fetch_and_and (&ss, 11);
121   us = __sync_fetch_and_and (&us, 11);
122   si = __sync_fetch_and_and (&si, 11);
123   ui = __sync_fetch_and_and (&ui, 11);
124   sll = __sync_fetch_and_and (&sll, 11);
125   ull = __sync_fetch_and_and (&ull, 11);
126
127   sc = __sync_fetch_and_nand (&sc, 11);
128   uc = __sync_fetch_and_nand (&uc, 11);
129   ss = __sync_fetch_and_nand (&ss, 11);
130   us = __sync_fetch_and_nand (&us, 11);
131   si = __sync_fetch_and_nand (&si, 11);
132   ui = __sync_fetch_and_nand (&ui, 11);
133   sll = __sync_fetch_and_nand (&sll, 11);
134   ull = __sync_fetch_and_nand (&ull, 11);
135 }
136
137 void test_op_and_fetch (void)
138 {
139   sc = __sync_add_and_fetch (&sc, uc);
140   uc = __sync_add_and_fetch (&uc, uc);
141   ss = __sync_add_and_fetch (&ss, uc);
142   us = __sync_add_and_fetch (&us, uc);
143   si = __sync_add_and_fetch (&si, uc);
144   ui = __sync_add_and_fetch (&ui, uc);
145   sll = __sync_add_and_fetch (&sll, uc);
146   ull = __sync_add_and_fetch (&ull, uc);
147
148   sc = __sync_sub_and_fetch (&sc, uc);
149   uc = __sync_sub_and_fetch (&uc, uc);
150   ss = __sync_sub_and_fetch (&ss, uc);
151   us = __sync_sub_and_fetch (&us, uc);
152   si = __sync_sub_and_fetch (&si, uc);
153   ui = __sync_sub_and_fetch (&ui, uc);
154   sll = __sync_sub_and_fetch (&sll, uc);
155   ull = __sync_sub_and_fetch (&ull, uc);
156
157   sc = __sync_or_and_fetch (&sc, uc);
158   uc = __sync_or_and_fetch (&uc, uc);
159   ss = __sync_or_and_fetch (&ss, uc);
160   us = __sync_or_and_fetch (&us, uc);
161   si = __sync_or_and_fetch (&si, uc);
162   ui = __sync_or_and_fetch (&ui, uc);
163   sll = __sync_or_and_fetch (&sll, uc);
164   ull = __sync_or_and_fetch (&ull, uc);
165
166   sc = __sync_xor_and_fetch (&sc, uc);
167   uc = __sync_xor_and_fetch (&uc, uc);
168   ss = __sync_xor_and_fetch (&ss, uc);
169   us = __sync_xor_and_fetch (&us, uc);
170   si = __sync_xor_and_fetch (&si, uc);
171   ui = __sync_xor_and_fetch (&ui, uc);
172   sll = __sync_xor_and_fetch (&sll, uc);
173   ull = __sync_xor_and_fetch (&ull, uc);
174
175   sc = __sync_and_and_fetch (&sc, uc);
176   uc = __sync_and_and_fetch (&uc, uc);
177   ss = __sync_and_and_fetch (&ss, uc);
178   us = __sync_and_and_fetch (&us, uc);
179   si = __sync_and_and_fetch (&si, uc);
180   ui = __sync_and_and_fetch (&ui, uc);
181   sll = __sync_and_and_fetch (&sll, uc);
182   ull = __sync_and_and_fetch (&ull, uc);
183
184   sc = __sync_nand_and_fetch (&sc, uc);
185   uc = __sync_nand_and_fetch (&uc, uc);
186   ss = __sync_nand_and_fetch (&ss, uc);
187   us = __sync_nand_and_fetch (&us, uc);
188   si = __sync_nand_and_fetch (&si, uc);
189   ui = __sync_nand_and_fetch (&ui, uc);
190   sll = __sync_nand_and_fetch (&sll, uc);
191   ull = __sync_nand_and_fetch (&ull, uc);
192 }
193
194 void test_compare_and_swap (void)
195 {
196   sc = __sync_val_compare_and_swap (&sc, uc, sc);
197   uc = __sync_val_compare_and_swap (&uc, uc, sc);
198   ss = __sync_val_compare_and_swap (&ss, uc, sc);
199   us = __sync_val_compare_and_swap (&us, uc, sc);
200   si = __sync_val_compare_and_swap (&si, uc, sc);
201   ui = __sync_val_compare_and_swap (&ui, uc, sc);
202   sll = __sync_val_compare_and_swap (&sll, uc, sc);
203   ull = __sync_val_compare_and_swap (&ull, uc, sc);
204
205   ui = __sync_bool_compare_and_swap (&sc, uc, sc);
206   ui = __sync_bool_compare_and_swap (&uc, uc, sc);
207   ui = __sync_bool_compare_and_swap (&ss, uc, sc);
208   ui = __sync_bool_compare_and_swap (&us, uc, sc);
209   ui = __sync_bool_compare_and_swap (&si, uc, sc);
210   ui = __sync_bool_compare_and_swap (&ui, uc, sc);
211   ui = __sync_bool_compare_and_swap (&sll, uc, sc);
212   ui = __sync_bool_compare_and_swap (&ull, uc, sc);
213 }
214
215 void test_lock (void)
216 {
217   sc = __sync_lock_test_and_set (&sc, 1);
218   uc = __sync_lock_test_and_set (&uc, 1);
219   ss = __sync_lock_test_and_set (&ss, 1);
220   us = __sync_lock_test_and_set (&us, 1);
221   si = __sync_lock_test_and_set (&si, 1);
222   ui = __sync_lock_test_and_set (&ui, 1);
223   sll = __sync_lock_test_and_set (&sll, 1);
224   ull = __sync_lock_test_and_set (&ull, 1);
225
226   __sync_synchronize ();
227
228   __sync_lock_release (&sc);
229   __sync_lock_release (&uc);
230   __sync_lock_release (&ss);
231   __sync_lock_release (&us);
232   __sync_lock_release (&si);
233   __sync_lock_release (&ui);
234   __sync_lock_release (&sll);
235   __sync_lock_release (&ull);
236 }