basic-thumb2-instructions.s revision ad2dad930d450d721209531175b0cbfdc8402558
1@ RUN: llvm-mc -triple=thumbv7-apple-darwin -show-encoding < %s | FileCheck %s 2 .syntax unified 3 .globl _func 4 5@ Check that the assembler can handle the documented syntax from the ARM ARM. 6@ For complex constructs like shifter operands, check more thoroughly for them 7@ once then spot check that following instructions accept the form generally. 8@ This gives us good coverage while keeping the overall size of the test 9@ more reasonable. 10 11 12@ FIXME: Some 3-operand instructions have a 2-operand assembly syntax. 13 14_func: 15@ CHECK: _func 16 17@------------------------------------------------------------------------------ 18@ ADC (immediate) 19@------------------------------------------------------------------------------ 20 adc r0, r1, #4 21 adcs r0, r1, #0 22 adc r1, r2, #255 23 adc r3, r7, #0x00550055 24 adc r8, r12, #0xaa00aa00 25 adc r9, r7, #0xa5a5a5a5 26 adc r5, r3, #0x87000000 27 adc r4, r2, #0x7f800000 28 adc r4, r2, #0x00000680 29 30@ CHECK: adc r0, r1, #4 @ encoding: [0x41,0xf1,0x04,0x00] 31@ CHECK: adcs r0, r1, #0 @ encoding: [0x51,0xf1,0x00,0x00] 32@ CHECK: adc r1, r2, #255 @ encoding: [0x42,0xf1,0xff,0x01] 33@ CHECK: adc r3, r7, #5570645 @ encoding: [0x47,0xf1,0x55,0x13] 34@ CHECK: adc r8, r12, #2852170240 @ encoding: [0x4c,0xf1,0xaa,0x28] 35@ CHECK: adc r9, r7, #2779096485 @ encoding: [0x47,0xf1,0xa5,0x39] 36@ CHECK: adc r5, r3, #2264924160 @ encoding: [0x43,0xf1,0x07,0x45] 37@ CHECK: adc r4, r2, #2139095040 @ encoding: [0x42,0xf1,0xff,0x44] 38@ CHECK: adc r4, r2, #1664 @ encoding: [0x42,0xf5,0xd0,0x64] 39 40@------------------------------------------------------------------------------ 41@ ADC (register) 42@------------------------------------------------------------------------------ 43 adc r4, r5, r6 44 adcs r4, r5, r6 45 adc.w r9, r1, r3 46 adcs.w r9, r1, r3 47 adc r0, r1, r3, ror #4 48 adcs r0, r1, r3, lsl #7 49 adc.w r0, r1, r3, lsr #31 50 adcs.w r0, r1, r3, asr #32 51 52@ CHECK: adc.w r4, r5, r6 @ encoding: [0x45,0xeb,0x06,0x04] 53@ CHECK: adcs.w r4, r5, r6 @ encoding: [0x55,0xeb,0x06,0x04] 54@ CHECK: adc.w r9, r1, r3 @ encoding: [0x41,0xeb,0x03,0x09] 55@ CHECK: adcs.w r9, r1, r3 @ encoding: [0x51,0xeb,0x03,0x09] 56@ CHECK: adc.w r0, r1, r3, ror #4 @ encoding: [0x41,0xeb,0x33,0x10] 57@ CHECK: adcs.w r0, r1, r3, lsl #7 @ encoding: [0x51,0xeb,0xc3,0x10] 58@ CHECK: adc.w r0, r1, r3, lsr #31 @ encoding: [0x41,0xeb,0xd3,0x70] 59@ CHECK: adcs.w r0, r1, r3, asr #32 @ encoding: [0x51,0xeb,0x23,0x00] 60 61 62@------------------------------------------------------------------------------ 63@ ADD (immediate) 64@------------------------------------------------------------------------------ 65 itet eq 66 addeq r1, r2, #4 67 addwne r5, r3, #1023 68 addeq r4, r5, #293 69 add r2, sp, #1024 70 add r2, r8, #0xff00 71 add r2, r3, #257 72 addw r2, r3, #257 73 add r12, r6, #0x100 74 addw r12, r6, #0x100 75 adds r1, r2, #0x1f0 76 77@ CHECK: itet eq @ encoding: [0x0a,0xbf] 78@ CHECK: addeq r1, r2, #4 @ encoding: [0x11,0x1d] 79@ CHECK: addwne r5, r3, #1023 @ encoding: [0x03,0xf2,0xff,0x35] 80@ CHECK: addweq r4, r5, #293 @ encoding: [0x05,0xf2,0x25,0x14] 81@ CHECK: add.w r2, sp, #1024 @ encoding: [0x0d,0xf5,0x80,0x62] 82@ CHECK: add.w r2, r8, #65280 @ encoding: [0x08,0xf5,0x7f,0x42] 83@ CHECK: addw r2, r3, #257 @ encoding: [0x03,0xf2,0x01,0x12] 84@ CHECK: addw r2, r3, #257 @ encoding: [0x03,0xf2,0x01,0x12] 85@ CHECK: add.w r12, r6, #256 @ encoding: [0x06,0xf5,0x80,0x7c] 86@ CHECK: addw r12, r6, #256 @ encoding: [0x06,0xf2,0x00,0x1c] 87@ CHECK: adds.w r1, r2, #496 @ encoding: [0x12,0xf5,0xf8,0x71] 88 89 90@------------------------------------------------------------------------------ 91@ ADD (register) 92@------------------------------------------------------------------------------ 93 add r1, r2, r8 94 add r5, r9, r2, asr #32 95 adds r7, r3, r1, lsl #31 96 adds.w r0, r3, r6, lsr #25 97 add.w r4, r8, r1, ror #12 98 99@ CHECK: add.w r1, r2, r8 @ encoding: [0x02,0xeb,0x08,0x01] 100@ CHECK: add.w r5, r9, r2, asr #32 @ encoding: [0x09,0xeb,0x22,0x05] 101@ CHECK: adds.w r7, r3, r1, lsl #31 @ encoding: [0x13,0xeb,0xc1,0x77] 102@ CHECK: adds.w r0, r3, r6, lsr #25 @ encoding: [0x13,0xeb,0x56,0x60] 103@ CHECK: add.w r4, r8, r1, ror #12 @ encoding: [0x08,0xeb,0x31,0x34] 104 105 106@------------------------------------------------------------------------------ 107@ FIXME: ADR 108@------------------------------------------------------------------------------ 109 110@------------------------------------------------------------------------------ 111@ AND (immediate) 112@------------------------------------------------------------------------------ 113 and r2, r5, #0xff000 114 ands r3, r12, #0xf 115 and r1, #0xff 116 and r1, r1, #0xff 117 118@ CHECK: and r2, r5, #1044480 @ encoding: [0x05,0xf4,0x7f,0x22] 119@ CHECK: ands r3, r12, #15 @ encoding: [0x1c,0xf0,0x0f,0x03] 120@ CHECK: and r1, r1, #255 @ encoding: [0x01,0xf0,0xff,0x01] 121@ CHECK: and r1, r1, #255 @ encoding: [0x01,0xf0,0xff,0x01] 122 123 124@------------------------------------------------------------------------------ 125@ AND (register) 126@------------------------------------------------------------------------------ 127 and r4, r9, r8 128 and r1, r4, r8, asr #3 129 ands r2, r1, r7, lsl #1 130 ands.w r4, r5, r2, lsr #20 131 and.w r9, r12, r1, ror #17 132 133@ CHECK: and.w r4, r9, r8 @ encoding: [0x09,0xea,0x08,0x04] 134@ CHECK: and.w r1, r4, r8, asr #3 @ encoding: [0x04,0xea,0xe8,0x01] 135@ CHECK: ands.w r2, r1, r7, lsl #1 @ encoding: [0x11,0xea,0x47,0x02] 136@ CHECK: ands.w r4, r5, r2, lsr #20 @ encoding: [0x15,0xea,0x12,0x54] 137@ CHECK: and.w r9, r12, r1, ror #17 @ encoding: [0x0c,0xea,0x71,0x49] 138 139@------------------------------------------------------------------------------ 140@ ASR (immediate) 141@------------------------------------------------------------------------------ 142 asr r2, r3, #12 143 asrs r8, r3, #32 144 asrs.w r2, r3, #1 145 asr r2, r3, #4 146 asrs r2, r12, #15 147 148 asr r3, #19 149 asrs r8, #2 150 asrs.w r7, #5 151 asr.w r12, #21 152 153@ CHECK: asr.w r2, r3, #12 @ encoding: [0x4f,0xea,0x23,0x32] 154@ CHECK: asrs.w r8, r3, #32 @ encoding: [0x5f,0xea,0x23,0x08] 155@ CHECK: asrs.w r2, r3, #1 @ encoding: [0x5f,0xea,0x63,0x02] 156@ CHECK: asr.w r2, r3, #4 @ encoding: [0x4f,0xea,0x23,0x12] 157@ CHECK: asrs.w r2, r12, #15 @ encoding: [0x5f,0xea,0xec,0x32] 158 159@ CHECK: asr.w r3, r3, #19 @ encoding: [0x4f,0xea,0xe3,0x43] 160@ CHECK: asrs.w r8, r8, #2 @ encoding: [0x5f,0xea,0xa8,0x08] 161@ CHECK: asrs.w r7, r7, #5 @ encoding: [0x5f,0xea,0x67,0x17] 162@ CHECK: asr.w r12, r12, #21 @ encoding: [0x4f,0xea,0x6c,0x5c] 163 164 165@------------------------------------------------------------------------------ 166@ ASR (register) 167@------------------------------------------------------------------------------ 168 asr r3, r4, r2 169 asr.w r1, r2 170 asrs r3, r4, r8 171 172@ CHECK: asr.w r3, r4, r2 @ encoding: [0x44,0xfa,0x02,0xf3] 173@ CHECK: asr.w r1, r1, r2 @ encoding: [0x41,0xfa,0x02,0xf1] 174@ CHECK: asrs.w r3, r4, r8 @ encoding: [0x54,0xfa,0x08,0xf3] 175 176 177@------------------------------------------------------------------------------ 178@ B 179@------------------------------------------------------------------------------ 180 b.w _bar 181 beq.w _bar 182 it eq 183 beq.w _bar 184 bmi.w #-183396 185 186@ CHECK: b.w _bar @ encoding: [A,0xf0'A',A,0x90'A'] 187 @ fixup A - offset: 0, value: _bar, kind: fixup_t2_uncondbranch 188@ CHECK: beq.w _bar @ encoding: [A,0xf0'A',A,0x80'A'] 189 @ fixup A - offset: 0, value: _bar, kind: fixup_t2_condbranch 190@ CHECK: it eq @ encoding: [0x08,0xbf] 191@ CHECK: b.w _bar @ encoding: [A,0xf0'A',A,0x90'A'] 192 @ fixup A - offset: 0, value: _bar, kind: fixup_t2_uncondbranch 193@ CHECK: bmi.w #-183396 @ encoding: [0x13,0xf5,0xce,0xa9] 194 195 196@------------------------------------------------------------------------------ 197@ BFC 198@------------------------------------------------------------------------------ 199 bfc r5, #3, #17 200 it lo 201 bfccc r5, #3, #17 202 203@ CHECK: bfc r5, #3, #17 @ encoding: [0x6f,0xf3,0xd3,0x05] 204@ CHECK: it lo @ encoding: [0x38,0xbf] 205@ CHECK: bfclo r5, #3, #17 @ encoding: [0x6f,0xf3,0xd3,0x05] 206 207 208@------------------------------------------------------------------------------ 209@ BFI 210@------------------------------------------------------------------------------ 211 bfi r5, r2, #3, #17 212 it ne 213 bfine r5, r2, #3, #17 214 215@ CHECK: bfi r5, r2, #3, #17 @ encoding: [0x62,0xf3,0xd3,0x05] 216@ CHECK: it ne @ encoding: [0x18,0xbf] 217@ CHECK: bfine r5, r2, #3, #17 @ encoding: [0x62,0xf3,0xd3,0x05] 218 219 220@------------------------------------------------------------------------------ 221@ BIC 222@------------------------------------------------------------------------------ 223 bic r10, r1, #0xf 224 bic r12, r3, r6 225 bic r11, r2, r6, lsl #12 226 bic r8, r4, r1, lsr #11 227 bic r7, r5, r7, lsr #15 228 bic r6, r7, r9, asr #32 229 bic r5, r6, r8, ror #1 230 231 @ destination register is optional 232 bic r1, #0xf 233 bic r1, r1 234 bic r4, r2, lsl #31 235 bic r6, r3, lsr #12 236 bic r7, r4, lsr #7 237 bic r8, r5, asr #15 238 bic r12, r6, ror #29 239 240@ CHECK: bic r10, r1, #15 @ encoding: [0x21,0xf0,0x0f,0x0a] 241@ CHECK: bic.w r12, r3, r6 @ encoding: [0x23,0xea,0x06,0x0c] 242@ CHECK: bic.w r11, r2, r6, lsl #12 @ encoding: [0x22,0xea,0x06,0x3b] 243@ CHECK: bic.w r8, r4, r1, lsr #11 @ encoding: [0x24,0xea,0xd1,0x28] 244@ CHECK: bic.w r7, r5, r7, lsr #15 @ encoding: [0x25,0xea,0xd7,0x37] 245@ CHECK: bic.w r6, r7, r9, asr #32 @ encoding: [0x27,0xea,0x29,0x06] 246@ CHECK: bic.w r5, r6, r8, ror #1 @ encoding: [0x26,0xea,0x78,0x05] 247 248@ CHECK: bic r1, r1, #15 @ encoding: [0x21,0xf0,0x0f,0x01] 249@ CHECK: bic.w r1, r1, r1 @ encoding: [0x21,0xea,0x01,0x01] 250@ CHECK: bic.w r4, r4, r2, lsl #31 @ encoding: [0x24,0xea,0xc2,0x74] 251@ CHECK: bic.w r6, r6, r3, lsr #12 @ encoding: [0x26,0xea,0x13,0x36] 252@ CHECK: bic.w r7, r7, r4, lsr #7 @ encoding: [0x27,0xea,0xd4,0x17] 253@ CHECK: bic.w r8, r8, r5, asr #15 @ encoding: [0x28,0xea,0xe5,0x38] 254@ CHECK: bic.w r12, r12, r6, ror #29 @ encoding: [0x2c,0xea,0x76,0x7c] 255 256 257@------------------------------------------------------------------------------ 258@ BXJ 259@------------------------------------------------------------------------------ 260 bxj r5 261 it ne 262 bxjne r7 263 264@ CHECK: bxj r5 @ encoding: [0xc5,0xf3,0x00,0x8f] 265@ CHECK: it ne @ encoding: [0x18,0xbf] 266@ CHECK: bxjne r7 @ encoding: [0xc7,0xf3,0x00,0x8f] 267 268 269@------------------------------------------------------------------------------ 270@ CBZ/CBNZ 271@------------------------------------------------------------------------------ 272 cbnz r7, #6 273 cbnz r7, #12 274 cbz r6, _bar 275 cbnz r6, _bar 276 277@ CHECK: cbnz r7, #6 @ encoding: [0x1f,0xb9] 278@ CHECK: cbnz r7, #12 @ encoding: [0x37,0xb9] 279@ CHECK: cbz r6, _bar @ encoding: [0x06'A',0xb1'A'] 280 @ fixup A - offset: 0, value: _bar, kind: fixup_arm_thumb_cb 281@ CHECK: cbnz r6, _bar @ encoding: [0x06'A',0xb9'A'] 282 @ fixup A - offset: 0, value: _bar, kind: fixup_arm_thumb_cb 283 284 285@------------------------------------------------------------------------------ 286@ CDP/CDP2 287@------------------------------------------------------------------------------ 288 cdp p7, #1, c1, c1, c1, #4 289 cdp2 p7, #1, c1, c1, c1, #4 290 291@ CHECK: cdp p7, #1, c1, c1, c1, #4 @ encoding: [0x11,0xee,0x81,0x17] 292@ CHECK: cdp2 p7, #1, c1, c1, c1, #4 @ encoding: [0x11,0xfe,0x81,0x17] 293 294 295@------------------------------------------------------------------------------ 296@ CLREX 297@------------------------------------------------------------------------------ 298 clrex 299 it ne 300 clrexne 301 302@ CHECK: clrex @ encoding: [0xbf,0xf3,0x2f,0x8f] 303@ CHECK: it ne @ encoding: [0x18,0xbf] 304@ CHECK: clrexne @ encoding: [0xbf,0xf3,0x2f,0x8f] 305 306 307@------------------------------------------------------------------------------ 308@ IT 309@------------------------------------------------------------------------------ 310@ Test encodings of a few full IT blocks, not just the IT instruction 311 312 iteet eq 313 addeq r0, r1, r2 314 nopne 315 subne r5, r6, r7 316 addeq r1, r2, #4 317 318@ CHECK: iteet eq @ encoding: [0x0d,0xbf] 319@ CHECK: addeq r0, r1, r2 @ encoding: [0x88,0x18] 320@ CHECK: nopne @ encoding: [0x00,0xbf] 321@ CHECK: subne r5, r6, r7 @ encoding: [0xf5,0x1b] 322@ CHECK: addeq r1, r2, #4 @ encoding: [0x11,0x1d] 323