1/* Validate that each of the __sync builtins compiles. This won't 2 necessarily link, since the target might not support the builtin, 3 so this may result in external library calls. */ 4 5signed char sc; 6unsigned char uc; 7signed short ss; 8unsigned short us; 9signed int si; 10unsigned int ui; 11signed long sl; 12unsigned long ul; 13signed long long sll; 14unsigned long long ull; 15void *vp; 16int *ip; 17struct S { struct S *next; int x; } *sp; 18 19void test_op_ignore (void) 20{ 21 (void) __sync_fetch_and_add (&sc, 1); 22 (void) __sync_fetch_and_add (&uc, 1); 23 (void) __sync_fetch_and_add (&ss, 1); 24 (void) __sync_fetch_and_add (&us, 1); 25 (void) __sync_fetch_and_add (&si, 1); 26 (void) __sync_fetch_and_add (&ui, 1); 27 (void) __sync_fetch_and_add (&sl, 1); 28 (void) __sync_fetch_and_add (&ul, 1); 29 (void) __sync_fetch_and_add (&sll, 1); 30 (void) __sync_fetch_and_add (&ull, 1); 31 32 (void) __sync_fetch_and_sub (&sc, 1); 33 (void) __sync_fetch_and_sub (&uc, 1); 34 (void) __sync_fetch_and_sub (&ss, 1); 35 (void) __sync_fetch_and_sub (&us, 1); 36 (void) __sync_fetch_and_sub (&si, 1); 37 (void) __sync_fetch_and_sub (&ui, 1); 38 (void) __sync_fetch_and_sub (&sl, 1); 39 (void) __sync_fetch_and_sub (&ul, 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 (&sl, 1); 50 (void) __sync_fetch_and_or (&ul, 1); 51 (void) __sync_fetch_and_or (&sll, 1); 52 (void) __sync_fetch_and_or (&ull, 1); 53 54 (void) __sync_fetch_and_xor (&sc, 1); 55 (void) __sync_fetch_and_xor (&uc, 1); 56 (void) __sync_fetch_and_xor (&ss, 1); 57 (void) __sync_fetch_and_xor (&us, 1); 58 (void) __sync_fetch_and_xor (&si, 1); 59 (void) __sync_fetch_and_xor (&ui, 1); 60 (void) __sync_fetch_and_xor (&sl, 1); 61 (void) __sync_fetch_and_xor (&ul, 1); 62 (void) __sync_fetch_and_xor (&sll, 1); 63 (void) __sync_fetch_and_xor (&ull, 1); 64 65 (void) __sync_fetch_and_and (&sc, 1); 66 (void) __sync_fetch_and_and (&uc, 1); 67 (void) __sync_fetch_and_and (&ss, 1); 68 (void) __sync_fetch_and_and (&us, 1); 69 (void) __sync_fetch_and_and (&si, 1); 70 (void) __sync_fetch_and_and (&ui, 1); 71 (void) __sync_fetch_and_and (&sl, 1); 72 (void) __sync_fetch_and_and (&ul, 1); 73 (void) __sync_fetch_and_and (&sll, 1); 74 (void) __sync_fetch_and_and (&ull, 1); 75 76 (void) __sync_fetch_and_nand (&sc, 1); 77 (void) __sync_fetch_and_nand (&uc, 1); 78 (void) __sync_fetch_and_nand (&ss, 1); 79 (void) __sync_fetch_and_nand (&us, 1); 80 (void) __sync_fetch_and_nand (&si, 1); 81 (void) __sync_fetch_and_nand (&ui, 1); 82 (void) __sync_fetch_and_nand (&sl, 1); 83 (void) __sync_fetch_and_nand (&ul, 1); 84 (void) __sync_fetch_and_nand (&sll, 1); 85 (void) __sync_fetch_and_nand (&ull, 1); 86} 87 88void test_fetch_and_op (void) 89{ 90 sc = __sync_fetch_and_add (&sc, 11); 91 uc = __sync_fetch_and_add (&uc, 11); 92 ss = __sync_fetch_and_add (&ss, 11); 93 us = __sync_fetch_and_add (&us, 11); 94 si = __sync_fetch_and_add (&si, 11); 95 ui = __sync_fetch_and_add (&ui, 11); 96 sl = __sync_fetch_and_add (&sl, 11); 97 ul = __sync_fetch_and_add (&ul, 11); 98 sll = __sync_fetch_and_add (&sll, 11); 99 ull = __sync_fetch_and_add (&ull, 11); 100 101 sc = __sync_fetch_and_sub (&sc, 11); 102 uc = __sync_fetch_and_sub (&uc, 11); 103 ss = __sync_fetch_and_sub (&ss, 11); 104 us = __sync_fetch_and_sub (&us, 11); 105 si = __sync_fetch_and_sub (&si, 11); 106 ui = __sync_fetch_and_sub (&ui, 11); 107 sl = __sync_fetch_and_sub (&sl, 11); 108 ul = __sync_fetch_and_sub (&ul, 11); 109 sll = __sync_fetch_and_sub (&sll, 11); 110 ull = __sync_fetch_and_sub (&ull, 11); 111 112 sc = __sync_fetch_and_or (&sc, 11); 113 uc = __sync_fetch_and_or (&uc, 11); 114 ss = __sync_fetch_and_or (&ss, 11); 115 us = __sync_fetch_and_or (&us, 11); 116 si = __sync_fetch_and_or (&si, 11); 117 ui = __sync_fetch_and_or (&ui, 11); 118 sl = __sync_fetch_and_or (&sl, 11); 119 ul = __sync_fetch_and_or (&ul, 11); 120 sll = __sync_fetch_and_or (&sll, 11); 121 ull = __sync_fetch_and_or (&ull, 11); 122 123 sc = __sync_fetch_and_xor (&sc, 11); 124 uc = __sync_fetch_and_xor (&uc, 11); 125 ss = __sync_fetch_and_xor (&ss, 11); 126 us = __sync_fetch_and_xor (&us, 11); 127 si = __sync_fetch_and_xor (&si, 11); 128 ui = __sync_fetch_and_xor (&ui, 11); 129 sl = __sync_fetch_and_xor (&sl, 11); 130 ul = __sync_fetch_and_xor (&ul, 11); 131 sll = __sync_fetch_and_xor (&sll, 11); 132 ull = __sync_fetch_and_xor (&ull, 11); 133 134 sc = __sync_fetch_and_and (&sc, 11); 135 uc = __sync_fetch_and_and (&uc, 11); 136 ss = __sync_fetch_and_and (&ss, 11); 137 us = __sync_fetch_and_and (&us, 11); 138 si = __sync_fetch_and_and (&si, 11); 139 ui = __sync_fetch_and_and (&ui, 11); 140 sl = __sync_fetch_and_and (&sl, 11); 141 ul = __sync_fetch_and_and (&ul, 11); 142 sll = __sync_fetch_and_and (&sll, 11); 143 ull = __sync_fetch_and_and (&ull, 11); 144 145 sc = __sync_fetch_and_nand (&sc, 11); 146 uc = __sync_fetch_and_nand (&uc, 11); 147 ss = __sync_fetch_and_nand (&ss, 11); 148 us = __sync_fetch_and_nand (&us, 11); 149 si = __sync_fetch_and_nand (&si, 11); 150 ui = __sync_fetch_and_nand (&ui, 11); 151 sl = __sync_fetch_and_nand (&sl, 11); 152 ul = __sync_fetch_and_nand (&ul, 11); 153 sll = __sync_fetch_and_nand (&sll, 11); 154 ull = __sync_fetch_and_nand (&ull, 11); 155} 156 157void test_op_and_fetch (void) 158{ 159 sc = __sync_add_and_fetch (&sc, uc); 160 uc = __sync_add_and_fetch (&uc, uc); 161 ss = __sync_add_and_fetch (&ss, uc); 162 us = __sync_add_and_fetch (&us, uc); 163 si = __sync_add_and_fetch (&si, uc); 164 ui = __sync_add_and_fetch (&ui, uc); 165 sl = __sync_add_and_fetch (&sl, uc); 166 ul = __sync_add_and_fetch (&ul, uc); 167 sll = __sync_add_and_fetch (&sll, uc); 168 ull = __sync_add_and_fetch (&ull, uc); 169 170 sc = __sync_sub_and_fetch (&sc, uc); 171 uc = __sync_sub_and_fetch (&uc, uc); 172 ss = __sync_sub_and_fetch (&ss, uc); 173 us = __sync_sub_and_fetch (&us, uc); 174 si = __sync_sub_and_fetch (&si, uc); 175 ui = __sync_sub_and_fetch (&ui, uc); 176 sl = __sync_sub_and_fetch (&sl, uc); 177 ul = __sync_sub_and_fetch (&ul, uc); 178 sll = __sync_sub_and_fetch (&sll, uc); 179 ull = __sync_sub_and_fetch (&ull, uc); 180 181 sc = __sync_or_and_fetch (&sc, uc); 182 uc = __sync_or_and_fetch (&uc, uc); 183 ss = __sync_or_and_fetch (&ss, uc); 184 us = __sync_or_and_fetch (&us, uc); 185 si = __sync_or_and_fetch (&si, uc); 186 ui = __sync_or_and_fetch (&ui, uc); 187 sl = __sync_or_and_fetch (&sl, uc); 188 ul = __sync_or_and_fetch (&ul, uc); 189 sll = __sync_or_and_fetch (&sll, uc); 190 ull = __sync_or_and_fetch (&ull, uc); 191 192 sc = __sync_xor_and_fetch (&sc, uc); 193 uc = __sync_xor_and_fetch (&uc, uc); 194 ss = __sync_xor_and_fetch (&ss, uc); 195 us = __sync_xor_and_fetch (&us, uc); 196 si = __sync_xor_and_fetch (&si, uc); 197 ui = __sync_xor_and_fetch (&ui, uc); 198 sl = __sync_xor_and_fetch (&sl, uc); 199 ul = __sync_xor_and_fetch (&ul, uc); 200 sll = __sync_xor_and_fetch (&sll, uc); 201 ull = __sync_xor_and_fetch (&ull, uc); 202 203 sc = __sync_and_and_fetch (&sc, uc); 204 uc = __sync_and_and_fetch (&uc, uc); 205 ss = __sync_and_and_fetch (&ss, uc); 206 us = __sync_and_and_fetch (&us, uc); 207 si = __sync_and_and_fetch (&si, uc); 208 ui = __sync_and_and_fetch (&ui, uc); 209 sl = __sync_and_and_fetch (&sl, uc); 210 ul = __sync_and_and_fetch (&ul, uc); 211 sll = __sync_and_and_fetch (&sll, uc); 212 ull = __sync_and_and_fetch (&ull, uc); 213 214 sc = __sync_nand_and_fetch (&sc, uc); 215 uc = __sync_nand_and_fetch (&uc, uc); 216 ss = __sync_nand_and_fetch (&ss, uc); 217 us = __sync_nand_and_fetch (&us, uc); 218 si = __sync_nand_and_fetch (&si, uc); 219 ui = __sync_nand_and_fetch (&ui, uc); 220 sl = __sync_nand_and_fetch (&sl, uc); 221 ul = __sync_nand_and_fetch (&ul, uc); 222 sll = __sync_nand_and_fetch (&sll, uc); 223 ull = __sync_nand_and_fetch (&ull, uc); 224} 225 226void test_compare_and_swap (void) 227{ 228 sc = __sync_val_compare_and_swap (&sc, uc, sc); 229 uc = __sync_val_compare_and_swap (&uc, uc, sc); 230 ss = __sync_val_compare_and_swap (&ss, uc, sc); 231 us = __sync_val_compare_and_swap (&us, uc, sc); 232 si = __sync_val_compare_and_swap (&si, uc, sc); 233 ui = __sync_val_compare_and_swap (&ui, uc, sc); 234 sl = __sync_val_compare_and_swap (&sl, uc, sc); 235 ul = __sync_val_compare_and_swap (&ul, uc, sc); 236 sll = __sync_val_compare_and_swap (&sll, uc, sc); 237 ull = __sync_val_compare_and_swap (&ull, uc, sc); 238 239 ui = __sync_bool_compare_and_swap (&sc, uc, sc); 240 ui = __sync_bool_compare_and_swap (&uc, uc, sc); 241 ui = __sync_bool_compare_and_swap (&ss, uc, sc); 242 ui = __sync_bool_compare_and_swap (&us, uc, sc); 243 ui = __sync_bool_compare_and_swap (&si, uc, sc); 244 ui = __sync_bool_compare_and_swap (&ui, uc, sc); 245 ui = __sync_bool_compare_and_swap (&sl, uc, sc); 246 ui = __sync_bool_compare_and_swap (&ul, uc, sc); 247 ui = __sync_bool_compare_and_swap (&sll, uc, sc); 248 ui = __sync_bool_compare_and_swap (&ull, uc, sc); 249} 250 251void test_lock (void) 252{ 253 sc = __sync_lock_test_and_set (&sc, 1); 254 uc = __sync_lock_test_and_set (&uc, 1); 255 ss = __sync_lock_test_and_set (&ss, 1); 256 us = __sync_lock_test_and_set (&us, 1); 257 si = __sync_lock_test_and_set (&si, 1); 258 ui = __sync_lock_test_and_set (&ui, 1); 259 sl = __sync_lock_test_and_set (&sl, 1); 260 ul = __sync_lock_test_and_set (&ul, 1); 261 sll = __sync_lock_test_and_set (&sll, 1); 262 ull = __sync_lock_test_and_set (&ull, 1); 263 264 __sync_synchronize (); 265 266 __sync_lock_release (&sc); 267 __sync_lock_release (&uc); 268 __sync_lock_release (&ss); 269 __sync_lock_release (&us); 270 __sync_lock_release (&si); 271 __sync_lock_release (&ui); 272 __sync_lock_release (&sl); 273 __sync_lock_release (&ul); 274 __sync_lock_release (&sll); 275 __sync_lock_release (&ull); 276} 277