Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 1 | // Test frontend handling of __sync builtins. |
| 2 | // Modified from a gcc testcase. |
Dale Johannesen | f33ebd2 | 2008-10-12 18:40:49 +0000 | [diff] [blame] | 3 | // RUN: %llvmgcc -S %s -o - | grep atomic | count 200 |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 4 | // RUN: %llvmgcc -S %s -o - | grep p0i8 | count 50 |
| 5 | // RUN: %llvmgcc -S %s -o - | grep p0i16 | count 50 |
Dale Johannesen | f33ebd2 | 2008-10-12 18:40:49 +0000 | [diff] [blame] | 6 | // RUN: %llvmgcc -S %s -o - | grep p0i32 | count 50 |
| 7 | // RUN: %llvmgcc -S %s -o - | grep volatile | count 8 |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 8 | |
| 9 | // Currently this is implemented only for Alpha, X86, PowerPC. |
| 10 | // Add your target here if it doesn't work. |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 11 | // PPC32 does not translate the long long variants, so fails this test. |
Daniel Dunbar | 75657ad | 2009-11-09 16:38:15 +0000 | [diff] [blame] | 12 | // XFAIL: sparc,arm,powerpc |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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; |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 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); |
Dale Johannesen | 7916fad | 2008-08-22 21:47:03 +0000 | [diff] [blame] | 234 | __sync_lock_release (&sll); |
| 235 | __sync_lock_release (&ull); |
| 236 | } |