1 // Test frontend handling of __sync builtins.
2 // Modified from a gcc testcase.
3 // RUN: %llvmgcc -S %s -o - | grep atomic | count 242
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 92
7 // RUN: %llvmgcc -S %s -o - | grep volatile | count 10
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
23 unsigned long long ull;
25 void test_op_ignore (void)
27 (void) __sync_fetch_and_add (&sc, 1);
28 (void) __sync_fetch_and_add (&uc, 1);
29 (void) __sync_fetch_and_add (&ss, 1);
30 (void) __sync_fetch_and_add (&us, 1);
31 (void) __sync_fetch_and_add (&si, 1);
32 (void) __sync_fetch_and_add (&ui, 1);
33 (void) __sync_fetch_and_add (&sl, 1);
34 (void) __sync_fetch_and_add (&ul, 1);
35 (void) __sync_fetch_and_add (&sll, 1);
36 (void) __sync_fetch_and_add (&ull, 1);
38 (void) __sync_fetch_and_sub (&sc, 1);
39 (void) __sync_fetch_and_sub (&uc, 1);
40 (void) __sync_fetch_and_sub (&ss, 1);
41 (void) __sync_fetch_and_sub (&us, 1);
42 (void) __sync_fetch_and_sub (&si, 1);
43 (void) __sync_fetch_and_sub (&ui, 1);
44 (void) __sync_fetch_and_sub (&sl, 1);
45 (void) __sync_fetch_and_sub (&ul, 1);
46 (void) __sync_fetch_and_sub (&sll, 1);
47 (void) __sync_fetch_and_sub (&ull, 1);
49 (void) __sync_fetch_and_or (&sc, 1);
50 (void) __sync_fetch_and_or (&uc, 1);
51 (void) __sync_fetch_and_or (&ss, 1);
52 (void) __sync_fetch_and_or (&us, 1);
53 (void) __sync_fetch_and_or (&si, 1);
54 (void) __sync_fetch_and_or (&ui, 1);
55 (void) __sync_fetch_and_or (&sl, 1);
56 (void) __sync_fetch_and_or (&ul, 1);
57 (void) __sync_fetch_and_or (&sll, 1);
58 (void) __sync_fetch_and_or (&ull, 1);
60 (void) __sync_fetch_and_xor (&sc, 1);
61 (void) __sync_fetch_and_xor (&uc, 1);
62 (void) __sync_fetch_and_xor (&ss, 1);
63 (void) __sync_fetch_and_xor (&us, 1);
64 (void) __sync_fetch_and_xor (&si, 1);
65 (void) __sync_fetch_and_xor (&ui, 1);
66 (void) __sync_fetch_and_xor (&sl, 1);
67 (void) __sync_fetch_and_xor (&ul, 1);
68 (void) __sync_fetch_and_xor (&sll, 1);
69 (void) __sync_fetch_and_xor (&ull, 1);
71 (void) __sync_fetch_and_and (&sc, 1);
72 (void) __sync_fetch_and_and (&uc, 1);
73 (void) __sync_fetch_and_and (&ss, 1);
74 (void) __sync_fetch_and_and (&us, 1);
75 (void) __sync_fetch_and_and (&si, 1);
76 (void) __sync_fetch_and_and (&ui, 1);
77 (void) __sync_fetch_and_and (&sl, 1);
78 (void) __sync_fetch_and_and (&ul, 1);
79 (void) __sync_fetch_and_and (&sll, 1);
80 (void) __sync_fetch_and_and (&ull, 1);
82 (void) __sync_fetch_and_nand (&sc, 1);
83 (void) __sync_fetch_and_nand (&uc, 1);
84 (void) __sync_fetch_and_nand (&ss, 1);
85 (void) __sync_fetch_and_nand (&us, 1);
86 (void) __sync_fetch_and_nand (&si, 1);
87 (void) __sync_fetch_and_nand (&ui, 1);
88 (void) __sync_fetch_and_nand (&sl, 1);
89 (void) __sync_fetch_and_nand (&ul, 1);
90 (void) __sync_fetch_and_nand (&sll, 1);
91 (void) __sync_fetch_and_nand (&ull, 1);
94 void test_fetch_and_op (void)
96 sc = __sync_fetch_and_add (&sc, 11);
97 uc = __sync_fetch_and_add (&uc, 11);
98 ss = __sync_fetch_and_add (&ss, 11);
99 us = __sync_fetch_and_add (&us, 11);
100 si = __sync_fetch_and_add (&si, 11);
101 ui = __sync_fetch_and_add (&ui, 11);
102 sl = __sync_fetch_and_add (&sl, 11);
103 ul = __sync_fetch_and_add (&ul, 11);
104 sll = __sync_fetch_and_add (&sll, 11);
105 ull = __sync_fetch_and_add (&ull, 11);
107 sc = __sync_fetch_and_sub (&sc, 11);
108 uc = __sync_fetch_and_sub (&uc, 11);
109 ss = __sync_fetch_and_sub (&ss, 11);
110 us = __sync_fetch_and_sub (&us, 11);
111 si = __sync_fetch_and_sub (&si, 11);
112 ui = __sync_fetch_and_sub (&ui, 11);
113 sl = __sync_fetch_and_sub (&sl, 11);
114 ul = __sync_fetch_and_sub (&ul, 11);
115 sll = __sync_fetch_and_sub (&sll, 11);
116 ull = __sync_fetch_and_sub (&ull, 11);
118 sc = __sync_fetch_and_or (&sc, 11);
119 uc = __sync_fetch_and_or (&uc, 11);
120 ss = __sync_fetch_and_or (&ss, 11);
121 us = __sync_fetch_and_or (&us, 11);
122 si = __sync_fetch_and_or (&si, 11);
123 ui = __sync_fetch_and_or (&ui, 11);
124 sl = __sync_fetch_and_or (&sl, 11);
125 ul = __sync_fetch_and_or (&ul, 11);
126 sll = __sync_fetch_and_or (&sll, 11);
127 ull = __sync_fetch_and_or (&ull, 11);
129 sc = __sync_fetch_and_xor (&sc, 11);
130 uc = __sync_fetch_and_xor (&uc, 11);
131 ss = __sync_fetch_and_xor (&ss, 11);
132 us = __sync_fetch_and_xor (&us, 11);
133 si = __sync_fetch_and_xor (&si, 11);
134 ui = __sync_fetch_and_xor (&ui, 11);
135 sl = __sync_fetch_and_xor (&sl, 11);
136 ul = __sync_fetch_and_xor (&ul, 11);
137 sll = __sync_fetch_and_xor (&sll, 11);
138 ull = __sync_fetch_and_xor (&ull, 11);
140 sc = __sync_fetch_and_and (&sc, 11);
141 uc = __sync_fetch_and_and (&uc, 11);
142 ss = __sync_fetch_and_and (&ss, 11);
143 us = __sync_fetch_and_and (&us, 11);
144 si = __sync_fetch_and_and (&si, 11);
145 ui = __sync_fetch_and_and (&ui, 11);
146 sl = __sync_fetch_and_and (&sl, 11);
147 ul = __sync_fetch_and_and (&ul, 11);
148 sll = __sync_fetch_and_and (&sll, 11);
149 ull = __sync_fetch_and_and (&ull, 11);
151 sc = __sync_fetch_and_nand (&sc, 11);
152 uc = __sync_fetch_and_nand (&uc, 11);
153 ss = __sync_fetch_and_nand (&ss, 11);
154 us = __sync_fetch_and_nand (&us, 11);
155 si = __sync_fetch_and_nand (&si, 11);
156 ui = __sync_fetch_and_nand (&ui, 11);
157 sl = __sync_fetch_and_nand (&sl, 11);
158 ul = __sync_fetch_and_nand (&ul, 11);
159 sll = __sync_fetch_and_nand (&sll, 11);
160 ull = __sync_fetch_and_nand (&ull, 11);
163 void test_op_and_fetch (void)
165 sc = __sync_add_and_fetch (&sc, uc);
166 uc = __sync_add_and_fetch (&uc, uc);
167 ss = __sync_add_and_fetch (&ss, uc);
168 us = __sync_add_and_fetch (&us, uc);
169 si = __sync_add_and_fetch (&si, uc);
170 ui = __sync_add_and_fetch (&ui, uc);
171 sl = __sync_add_and_fetch (&sl, uc);
172 ul = __sync_add_and_fetch (&ul, uc);
173 sll = __sync_add_and_fetch (&sll, uc);
174 ull = __sync_add_and_fetch (&ull, uc);
176 sc = __sync_sub_and_fetch (&sc, uc);
177 uc = __sync_sub_and_fetch (&uc, uc);
178 ss = __sync_sub_and_fetch (&ss, uc);
179 us = __sync_sub_and_fetch (&us, uc);
180 si = __sync_sub_and_fetch (&si, uc);
181 ui = __sync_sub_and_fetch (&ui, uc);
182 sl = __sync_sub_and_fetch (&sl, uc);
183 ul = __sync_sub_and_fetch (&ul, uc);
184 sll = __sync_sub_and_fetch (&sll, uc);
185 ull = __sync_sub_and_fetch (&ull, uc);
187 sc = __sync_or_and_fetch (&sc, uc);
188 uc = __sync_or_and_fetch (&uc, uc);
189 ss = __sync_or_and_fetch (&ss, uc);
190 us = __sync_or_and_fetch (&us, uc);
191 si = __sync_or_and_fetch (&si, uc);
192 ui = __sync_or_and_fetch (&ui, uc);
193 sl = __sync_or_and_fetch (&sl, uc);
194 ul = __sync_or_and_fetch (&ul, uc);
195 sll = __sync_or_and_fetch (&sll, uc);
196 ull = __sync_or_and_fetch (&ull, uc);
198 sc = __sync_xor_and_fetch (&sc, uc);
199 uc = __sync_xor_and_fetch (&uc, uc);
200 ss = __sync_xor_and_fetch (&ss, uc);
201 us = __sync_xor_and_fetch (&us, uc);
202 si = __sync_xor_and_fetch (&si, uc);
203 ui = __sync_xor_and_fetch (&ui, uc);
204 sl = __sync_xor_and_fetch (&sl, uc);
205 ul = __sync_xor_and_fetch (&ul, uc);
206 sll = __sync_xor_and_fetch (&sll, uc);
207 ull = __sync_xor_and_fetch (&ull, uc);
209 sc = __sync_and_and_fetch (&sc, uc);
210 uc = __sync_and_and_fetch (&uc, uc);
211 ss = __sync_and_and_fetch (&ss, uc);
212 us = __sync_and_and_fetch (&us, uc);
213 si = __sync_and_and_fetch (&si, uc);
214 ui = __sync_and_and_fetch (&ui, uc);
215 sl = __sync_and_and_fetch (&sl, uc);
216 ul = __sync_and_and_fetch (&ul, uc);
217 sll = __sync_and_and_fetch (&sll, uc);
218 ull = __sync_and_and_fetch (&ull, uc);
220 sc = __sync_nand_and_fetch (&sc, uc);
221 uc = __sync_nand_and_fetch (&uc, uc);
222 ss = __sync_nand_and_fetch (&ss, uc);
223 us = __sync_nand_and_fetch (&us, uc);
224 si = __sync_nand_and_fetch (&si, uc);
225 ui = __sync_nand_and_fetch (&ui, uc);
226 sl = __sync_nand_and_fetch (&sl, uc);
227 ul = __sync_nand_and_fetch (&ul, uc);
228 sll = __sync_nand_and_fetch (&sll, uc);
229 ull = __sync_nand_and_fetch (&ull, uc);
232 void test_compare_and_swap (void)
234 sc = __sync_val_compare_and_swap (&sc, uc, sc);
235 uc = __sync_val_compare_and_swap (&uc, uc, sc);
236 ss = __sync_val_compare_and_swap (&ss, uc, sc);
237 us = __sync_val_compare_and_swap (&us, uc, sc);
238 si = __sync_val_compare_and_swap (&si, uc, sc);
239 ui = __sync_val_compare_and_swap (&ui, uc, sc);
240 sl = __sync_val_compare_and_swap (&sl, uc, sc);
241 ul = __sync_val_compare_and_swap (&ul, uc, sc);
242 sll = __sync_val_compare_and_swap (&sll, uc, sc);
243 ull = __sync_val_compare_and_swap (&ull, uc, sc);
245 ui = __sync_bool_compare_and_swap (&sc, uc, sc);
246 ui = __sync_bool_compare_and_swap (&uc, uc, sc);
247 ui = __sync_bool_compare_and_swap (&ss, uc, sc);
248 ui = __sync_bool_compare_and_swap (&us, uc, sc);
249 ui = __sync_bool_compare_and_swap (&si, uc, sc);
250 ui = __sync_bool_compare_and_swap (&ui, uc, sc);
251 ui = __sync_bool_compare_and_swap (&sl, uc, sc);
252 ui = __sync_bool_compare_and_swap (&ul, uc, sc);
253 ui = __sync_bool_compare_and_swap (&sll, uc, sc);
254 ui = __sync_bool_compare_and_swap (&ull, uc, sc);
257 void test_lock (void)
259 sc = __sync_lock_test_and_set (&sc, 1);
260 uc = __sync_lock_test_and_set (&uc, 1);
261 ss = __sync_lock_test_and_set (&ss, 1);
262 us = __sync_lock_test_and_set (&us, 1);
263 si = __sync_lock_test_and_set (&si, 1);
264 ui = __sync_lock_test_and_set (&ui, 1);
265 sl = __sync_lock_test_and_set (&sl, 1);
266 ul = __sync_lock_test_and_set (&ul, 1);
267 sll = __sync_lock_test_and_set (&sll, 1);
268 ull = __sync_lock_test_and_set (&ull, 1);
270 __sync_synchronize ();
272 __sync_lock_release (&sc);
273 __sync_lock_release (&uc);
274 __sync_lock_release (&ss);
275 __sync_lock_release (&us);
276 __sync_lock_release (&si);
277 __sync_lock_release (&ui);
278 __sync_lock_release (&sl);
279 __sync_lock_release (&ul);
280 __sync_lock_release (&sll);
281 __sync_lock_release (&ull);