Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +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 150 |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +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 6 |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 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. |
Daniel Dunbar | 75657ad | 2009-11-09 16:38:15 +0000 | [diff] [blame^] | 12 | // XFAIL: sparc,arm |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +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 | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 20 | |
| 21 | void test_op_ignore (void) |
| 22 | { |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 29 | |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 36 | |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 43 | |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 50 | |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 57 | |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void test_fetch_and_op (void) |
| 67 | { |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 74 | |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 81 | |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 88 | |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 95 | |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 102 | |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void test_op_and_fetch (void) |
| 112 | { |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 119 | |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 126 | |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 133 | |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 140 | |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 147 | |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | void test_compare_and_swap (void) |
| 157 | { |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 164 | |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | void test_lock (void) |
| 174 | { |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 181 | |
| 182 | __sync_synchronize (); |
| 183 | |
| 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); |
Dale Johannesen | 09a2ffe | 2008-09-02 21:19:30 +0000 | [diff] [blame] | 190 | } |