blob: b14bb6df24f881a90fbe7f54da45d2b6f37046a7 [file] [log] [blame]
Dale Johannesen09a2ffe2008-09-02 21:19:30 +00001// Test frontend handling of __sync builtins.
2// Modified from a gcc testcase.
3// RUN: %llvmgcc -S %s -o - | grep atomic | count 192
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 8
8
9// Currently this is implemented only for Alpha, X86, PowerPC.
10// Add your target here if it doesn't work.
11// This version of the test does not include long long.
12// XFAIL: sparc|arm|ia64
13
14signed char sc;
15unsigned char uc;
16signed short ss;
17unsigned short us;
18signed int si;
19unsigned int ui;
20signed long sl;
21unsigned long ul;
22
23void 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 (&sl, 1);
32 (void) __sync_fetch_and_add (&ul, 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 (&sl, 1);
41 (void) __sync_fetch_and_sub (&ul, 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 (&sl, 1);
50 (void) __sync_fetch_and_or (&ul, 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 (&sl, 1);
59 (void) __sync_fetch_and_xor (&ul, 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 (&sl, 1);
68 (void) __sync_fetch_and_and (&ul, 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 (&sl, 1);
77 (void) __sync_fetch_and_nand (&ul, 1);
78}
79
80void 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 sl = __sync_fetch_and_add (&sl, 11);
89 ul = __sync_fetch_and_add (&ul, 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 sl = __sync_fetch_and_sub (&sl, 11);
98 ul = __sync_fetch_and_sub (&ul, 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 sl = __sync_fetch_and_or (&sl, 11);
107 ul = __sync_fetch_and_or (&ul, 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 sl = __sync_fetch_and_xor (&sl, 11);
116 ul = __sync_fetch_and_xor (&ul, 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 sl = __sync_fetch_and_and (&sl, 11);
125 ul = __sync_fetch_and_and (&ul, 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 sl = __sync_fetch_and_nand (&sl, 11);
134 ul = __sync_fetch_and_nand (&ul, 11);
135}
136
137void 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 sl = __sync_add_and_fetch (&sl, uc);
146 ul = __sync_add_and_fetch (&ul, 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 sl = __sync_sub_and_fetch (&sl, uc);
155 ul = __sync_sub_and_fetch (&ul, 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 sl = __sync_or_and_fetch (&sl, uc);
164 ul = __sync_or_and_fetch (&ul, 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 sl = __sync_xor_and_fetch (&sl, uc);
173 ul = __sync_xor_and_fetch (&ul, 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 sl = __sync_and_and_fetch (&sl, uc);
182 ul = __sync_and_and_fetch (&ul, 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 sl = __sync_nand_and_fetch (&sl, uc);
191 ul = __sync_nand_and_fetch (&ul, uc);
192}
193
194void 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 sl = __sync_val_compare_and_swap (&sl, uc, sc);
203 ul = __sync_val_compare_and_swap (&ul, 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 (&sl, uc, sc);
212 ui = __sync_bool_compare_and_swap (&ul, uc, sc);
213}
214
215void 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 sl = __sync_lock_test_and_set (&sl, 1);
224 ul = __sync_lock_test_and_set (&ul, 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 (&sl);
235 __sync_lock_release (&ul);
236}