1 // Test frontend handling of __sync builtins.
2 // Modified from a gcc testcase.
3 // RUN: %llvmgcc -S %s -o - | grep atomic | count 150
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 6
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.
21 void test_op_ignore (void)
23 (void) __sync_fetch_and_add (&sc
, 1);
24 (void) __sync_fetch_and_add (&uc
, 1);
25 (void) __sync_fetch_and_add (&ss
, 1);
26 (void) __sync_fetch_and_add (&us
, 1);
27 (void) __sync_fetch_and_add (&si
, 1);
28 (void) __sync_fetch_and_add (&ui
, 1);
30 (void) __sync_fetch_and_sub (&sc
, 1);
31 (void) __sync_fetch_and_sub (&uc
, 1);
32 (void) __sync_fetch_and_sub (&ss
, 1);
33 (void) __sync_fetch_and_sub (&us
, 1);
34 (void) __sync_fetch_and_sub (&si
, 1);
35 (void) __sync_fetch_and_sub (&ui
, 1);
37 (void) __sync_fetch_and_or (&sc
, 1);
38 (void) __sync_fetch_and_or (&uc
, 1);
39 (void) __sync_fetch_and_or (&ss
, 1);
40 (void) __sync_fetch_and_or (&us
, 1);
41 (void) __sync_fetch_and_or (&si
, 1);
42 (void) __sync_fetch_and_or (&ui
, 1);
44 (void) __sync_fetch_and_xor (&sc
, 1);
45 (void) __sync_fetch_and_xor (&uc
, 1);
46 (void) __sync_fetch_and_xor (&ss
, 1);
47 (void) __sync_fetch_and_xor (&us
, 1);
48 (void) __sync_fetch_and_xor (&si
, 1);
49 (void) __sync_fetch_and_xor (&ui
, 1);
51 (void) __sync_fetch_and_and (&sc
, 1);
52 (void) __sync_fetch_and_and (&uc
, 1);
53 (void) __sync_fetch_and_and (&ss
, 1);
54 (void) __sync_fetch_and_and (&us
, 1);
55 (void) __sync_fetch_and_and (&si
, 1);
56 (void) __sync_fetch_and_and (&ui
, 1);
58 (void) __sync_fetch_and_nand (&sc
, 1);
59 (void) __sync_fetch_and_nand (&uc
, 1);
60 (void) __sync_fetch_and_nand (&ss
, 1);
61 (void) __sync_fetch_and_nand (&us
, 1);
62 (void) __sync_fetch_and_nand (&si
, 1);
63 (void) __sync_fetch_and_nand (&ui
, 1);
66 void test_fetch_and_op (void)
68 sc
= __sync_fetch_and_add (&sc
, 11);
69 uc
= __sync_fetch_and_add (&uc
, 11);
70 ss
= __sync_fetch_and_add (&ss
, 11);
71 us
= __sync_fetch_and_add (&us
, 11);
72 si
= __sync_fetch_and_add (&si
, 11);
73 ui
= __sync_fetch_and_add (&ui
, 11);
75 sc
= __sync_fetch_and_sub (&sc
, 11);
76 uc
= __sync_fetch_and_sub (&uc
, 11);
77 ss
= __sync_fetch_and_sub (&ss
, 11);
78 us
= __sync_fetch_and_sub (&us
, 11);
79 si
= __sync_fetch_and_sub (&si
, 11);
80 ui
= __sync_fetch_and_sub (&ui
, 11);
82 sc
= __sync_fetch_and_or (&sc
, 11);
83 uc
= __sync_fetch_and_or (&uc
, 11);
84 ss
= __sync_fetch_and_or (&ss
, 11);
85 us
= __sync_fetch_and_or (&us
, 11);
86 si
= __sync_fetch_and_or (&si
, 11);
87 ui
= __sync_fetch_and_or (&ui
, 11);
89 sc
= __sync_fetch_and_xor (&sc
, 11);
90 uc
= __sync_fetch_and_xor (&uc
, 11);
91 ss
= __sync_fetch_and_xor (&ss
, 11);
92 us
= __sync_fetch_and_xor (&us
, 11);
93 si
= __sync_fetch_and_xor (&si
, 11);
94 ui
= __sync_fetch_and_xor (&ui
, 11);
96 sc
= __sync_fetch_and_and (&sc
, 11);
97 uc
= __sync_fetch_and_and (&uc
, 11);
98 ss
= __sync_fetch_and_and (&ss
, 11);
99 us
= __sync_fetch_and_and (&us
, 11);
100 si
= __sync_fetch_and_and (&si
, 11);
101 ui
= __sync_fetch_and_and (&ui
, 11);
103 sc
= __sync_fetch_and_nand (&sc
, 11);
104 uc
= __sync_fetch_and_nand (&uc
, 11);
105 ss
= __sync_fetch_and_nand (&ss
, 11);
106 us
= __sync_fetch_and_nand (&us
, 11);
107 si
= __sync_fetch_and_nand (&si
, 11);
108 ui
= __sync_fetch_and_nand (&ui
, 11);
111 void test_op_and_fetch (void)
113 sc
= __sync_add_and_fetch (&sc
, uc
);
114 uc
= __sync_add_and_fetch (&uc
, uc
);
115 ss
= __sync_add_and_fetch (&ss
, uc
);
116 us
= __sync_add_and_fetch (&us
, uc
);
117 si
= __sync_add_and_fetch (&si
, uc
);
118 ui
= __sync_add_and_fetch (&ui
, uc
);
120 sc
= __sync_sub_and_fetch (&sc
, uc
);
121 uc
= __sync_sub_and_fetch (&uc
, uc
);
122 ss
= __sync_sub_and_fetch (&ss
, uc
);
123 us
= __sync_sub_and_fetch (&us
, uc
);
124 si
= __sync_sub_and_fetch (&si
, uc
);
125 ui
= __sync_sub_and_fetch (&ui
, uc
);
127 sc
= __sync_or_and_fetch (&sc
, uc
);
128 uc
= __sync_or_and_fetch (&uc
, uc
);
129 ss
= __sync_or_and_fetch (&ss
, uc
);
130 us
= __sync_or_and_fetch (&us
, uc
);
131 si
= __sync_or_and_fetch (&si
, uc
);
132 ui
= __sync_or_and_fetch (&ui
, uc
);
134 sc
= __sync_xor_and_fetch (&sc
, uc
);
135 uc
= __sync_xor_and_fetch (&uc
, uc
);
136 ss
= __sync_xor_and_fetch (&ss
, uc
);
137 us
= __sync_xor_and_fetch (&us
, uc
);
138 si
= __sync_xor_and_fetch (&si
, uc
);
139 ui
= __sync_xor_and_fetch (&ui
, uc
);
141 sc
= __sync_and_and_fetch (&sc
, uc
);
142 uc
= __sync_and_and_fetch (&uc
, uc
);
143 ss
= __sync_and_and_fetch (&ss
, uc
);
144 us
= __sync_and_and_fetch (&us
, uc
);
145 si
= __sync_and_and_fetch (&si
, uc
);
146 ui
= __sync_and_and_fetch (&ui
, uc
);
148 sc
= __sync_nand_and_fetch (&sc
, uc
);
149 uc
= __sync_nand_and_fetch (&uc
, uc
);
150 ss
= __sync_nand_and_fetch (&ss
, uc
);
151 us
= __sync_nand_and_fetch (&us
, uc
);
152 si
= __sync_nand_and_fetch (&si
, uc
);
153 ui
= __sync_nand_and_fetch (&ui
, uc
);
156 void test_compare_and_swap (void)
158 sc
= __sync_val_compare_and_swap (&sc
, uc
, sc
);
159 uc
= __sync_val_compare_and_swap (&uc
, uc
, sc
);
160 ss
= __sync_val_compare_and_swap (&ss
, uc
, sc
);
161 us
= __sync_val_compare_and_swap (&us
, uc
, sc
);
162 si
= __sync_val_compare_and_swap (&si
, uc
, sc
);
163 ui
= __sync_val_compare_and_swap (&ui
, uc
, sc
);
165 ui
= __sync_bool_compare_and_swap (&sc
, uc
, sc
);
166 ui
= __sync_bool_compare_and_swap (&uc
, uc
, sc
);
167 ui
= __sync_bool_compare_and_swap (&ss
, uc
, sc
);
168 ui
= __sync_bool_compare_and_swap (&us
, uc
, sc
);
169 ui
= __sync_bool_compare_and_swap (&si
, uc
, sc
);
170 ui
= __sync_bool_compare_and_swap (&ui
, uc
, sc
);
173 void test_lock (void)
175 sc
= __sync_lock_test_and_set (&sc
, 1);
176 uc
= __sync_lock_test_and_set (&uc
, 1);
177 ss
= __sync_lock_test_and_set (&ss
, 1);
178 us
= __sync_lock_test_and_set (&us
, 1);
179 si
= __sync_lock_test_and_set (&si
, 1);
180 ui
= __sync_lock_test_and_set (&ui
, 1);
182 __sync_synchronize ();
184 __sync_lock_release (&sc
);
185 __sync_lock_release (&uc
);
186 __sync_lock_release (&ss
);
187 __sync_lock_release (&us
);
188 __sync_lock_release (&si
);
189 __sync_lock_release (&ui
);