+@---
+@ Run these test in both Thumb1 and Thumb2 modes, as all of the encodings
+@ should be valid, and parse the same, in both.
+@---
@ RUN: llvm-mc -triple=thumbv6-apple-darwin -show-encoding < %s | FileCheck %s
+@ RUN: llvm-mc -triple=thumbv7-apple-darwin -show-encoding < %s | FileCheck %s
.syntax unified
.globl _func
@ ADD (immediate)
@------------------------------------------------------------------------------
adds r1, r2, #3
+@ When Rd is not explicitly specified, encoding T2 is preferred even though
+@ the literal is in the range [0,7] which would allow encoding T1.
adds r2, #3
adds r2, #8
@ CHECK: adds r1, r2, #3 @ encoding: [0xd1,0x1c]
-@ CHECK: adds r2, r2, #3 @ encoding: [0xd2,0x1c]
+@ CHECK: adds r2, #3 @ encoding: [0x03,0x32]
@ CHECK: adds r2, #8 @ encoding: [0x08,0x32]
@------------------------------------------------------------------------------
-@ FIXME: ADD (SP plus immediate)
+@ ADD (SP plus immediate)
@------------------------------------------------------------------------------
+ add sp, #4
+ add sp, #508
+ add sp, sp, #4
+ add r2, sp, #8
+ add r2, sp, #1020
+
+@ CHECK: add sp, #4 @ encoding: [0x01,0xb0]
+@ CHECK: add sp, #508 @ encoding: [0x7f,0xb0]
+@ CHECK: add sp, #4 @ encoding: [0x01,0xb0]
+@ CHECK: add r2, sp, #8 @ encoding: [0x02,0xaa]
+@ CHECK: add r2, sp, #1020 @ encoding: [0xff,0xaa]
+
+
@------------------------------------------------------------------------------
-@ FIXME: ADD (SP plus register)
+@ ADD (SP plus register)
@------------------------------------------------------------------------------
+ add sp, r3
+ add r2, sp, r2
+
+@ CHECK: add sp, r3 @ encoding: [0x9d,0x44]
+@ CHECK: add r2, sp, r2 @ encoding: [0x6a,0x44]
@------------------------------------------------------------------------------
@ ADR
@------------------------------------------------------------------------------
adr r2, _baz
+ adr r2, #3
@ CHECK: adr r2, _baz @ encoding: [A,0xa2]
@ fixup A - offset: 0, value: _baz, kind: fixup_thumb_adr_pcrel_10
-
+@ CHECK: adr r2, #3 @ encoding: [0x03,0xa2]
@------------------------------------------------------------------------------
@ ASR (immediate)
@------------------------------------------------------------------------------
b _baz
beq _bar
+ b #1838
+ b #-420
+ beq #336
+ beq #160
@ CHECK: b _baz @ encoding: [A,0xe0'A']
@ fixup A - offset: 0, value: _baz, kind: fixup_arm_thumb_br
@ CHECK: beq _bar @ encoding: [A,0xd0]
@ fixup A - offset: 0, value: _bar, kind: fixup_arm_thumb_bcc
+@ CHECK: b #1838 @ encoding: [0x97,0xe3]
+@ CHECK: b #-420 @ encoding: [0x2e,0xe7]
+@ CHECK: beq #336 @ encoding: [0xa8,0xd0]
+@ CHECK: beq #160 @ encoding: [0x50,0xd0]
+@------------------------------------------------------------------------------
+@ BL/BLX
+@------------------------------------------------------------------------------
+ blx #884800
+ blx #1769600
+
+@ CHECK: blx #884800 @ encoding: [0xd8,0xf0,0x20,0xe8]
+@ CHECK: blx #1769600 @ encoding: [0xb0,0xf1,0x40,0xe8]
@------------------------------------------------------------------------------
@ BICS
@ LDR (literal)
@------------------------------------------------------------------------------
ldr r1, _foo
+ ldr r3, #604
+ ldr r3, #368
@ CHECK: ldr r1, _foo @ encoding: [A,0x49]
@ fixup A - offset: 0, value: _foo, kind: fixup_arm_thumb_cp
-
+@ CHECK: ldr r3, #604 @ encoding: [0x97,0x4b]
+@ CHECK: ldr r3, #368 @ encoding: [0x5c,0x4b]
@------------------------------------------------------------------------------
@ LDR (register)
@ CHECK: rsbs r3, r4, #0 @ encoding: [0x63,0x42]
-
-@------------------------------------------------------------------------------
-@ NOP
-@------------------------------------------------------------------------------
- nop
-
-@ CHECK: nop @ encoding: [0xc0,0x46]
-
-
@------------------------------------------------------------------------------
@ ORR
@------------------------------------------------------------------------------
@------------------------------------------------------------------------------
rsbs r1, r3, #0
- rsbs r1, r3, #0 @ encoding: [0x59,0x42]
+@ CHECK: rsbs r1, r3, #0 @ encoding: [0x59,0x42]
+
+
+@------------------------------------------------------------------------------
+@ SBC
+@------------------------------------------------------------------------------
+ sbcs r4, r3
+
+@ CHECK: sbcs r4, r3 @ encoding: [0x9c,0x41]
+
+
+@------------------------------------------------------------------------------
+@ SETEND
+@------------------------------------------------------------------------------
+ setend be
+ setend le
+
+@ CHECK: setend be @ encoding: [0x58,0xb6]
+@ CHECK: setend le @ encoding: [0x50,0xb6]
+
+
+@------------------------------------------------------------------------------
+@ STM
+@------------------------------------------------------------------------------
+ stm r1!, {r2, r6}
+ stm r1!, {r1, r2, r3, r7}
+
+@ CHECK: stm r1!, {r2, r6} @ encoding: [0x44,0xc1]
+@ CHECK: stm r1!, {r1, r2, r3, r7} @ encoding: [0x8e,0xc1]
+
+
+@------------------------------------------------------------------------------
+@ STR (immediate)
+@------------------------------------------------------------------------------
+ str r2, [r7]
+ str r2, [r7, #0]
+ str r5, [r1, #4]
+ str r3, [r7, #124]
+ str r2, [sp]
+ str r3, [sp, #0]
+ str r4, [sp, #20]
+ str r5, [sp, #1020]
+
+@ CHECK: str r2, [r7] @ encoding: [0x3a,0x60]
+@ CHECK: str r2, [r7] @ encoding: [0x3a,0x60]
+@ CHECK: str r5, [r1, #4] @ encoding: [0x4d,0x60]
+@ CHECK: str r3, [r7, #124] @ encoding: [0xfb,0x67]
+@ CHECK: str r2, [sp] @ encoding: [0x00,0x92]
+@ CHECK: str r3, [sp] @ encoding: [0x00,0x93]
+@ CHECK: str r4, [sp, #20] @ encoding: [0x05,0x94]
+@ CHECK: str r5, [sp, #1020] @ encoding: [0xff,0x95]
+
+
+@------------------------------------------------------------------------------
+@ STR (register)
+@------------------------------------------------------------------------------
+ str r2, [r7, r3]
+
+@ CHECK: str r2, [r7, r3] @ encoding: [0xfa,0x50]
+
+
+@------------------------------------------------------------------------------
+@ STRB (immediate)
+@------------------------------------------------------------------------------
+ strb r4, [r3]
+ strb r5, [r6, #0]
+ strb r6, [r7, #31]
+
+@ CHECK: strb r4, [r3] @ encoding: [0x1c,0x70]
+@ CHECK: strb r5, [r6] @ encoding: [0x35,0x70]
+@ CHECK: strb r6, [r7, #31] @ encoding: [0xfe,0x77]
+
+
+@------------------------------------------------------------------------------
+@ STRB (register)
+@------------------------------------------------------------------------------
+ strb r6, [r4, r5]
+
+@ CHECK: strb r6, [r4, r5] @ encoding: [0x66,0x55]
+
+
+@------------------------------------------------------------------------------
+@ STRH (immediate)
+@------------------------------------------------------------------------------
+ strh r3, [r3]
+ strh r4, [r6, #2]
+ strh r5, [r7, #62]
+
+@ CHECK: strh r3, [r3] @ encoding: [0x1b,0x80]
+@ CHECK: strh r4, [r6, #2] @ encoding: [0x74,0x80]
+@ CHECK: strh r5, [r7, #62] @ encoding: [0xfd,0x87]
+
+
+@------------------------------------------------------------------------------
+@ STRH (register)
+@------------------------------------------------------------------------------
+ strh r6, [r2, r6]
+
+@ CHECK: strh r6, [r2, r6] @ encoding: [0x96,0x53]
+
+
+@------------------------------------------------------------------------------
+@ SUB (immediate)
+@------------------------------------------------------------------------------
+ subs r1, r2, #3
+ subs r2, #3
+ subs r2, #8
+
+@ CHECK: subs r1, r2, #3 @ encoding: [0xd1,0x1e]
+@ CHECK: subs r2, #3 @ encoding: [0x03,0x3a]
+@ CHECK: subs r2, #8 @ encoding: [0x08,0x3a]
+
+
+@------------------------------------------------------------------------------
+@ SUB (SP minus immediate)
+@------------------------------------------------------------------------------
+ sub sp, #12
+ sub sp, sp, #508
+
+@ CHECK: sub sp, #12 @ encoding: [0x83,0xb0]
+@ CHECK: sub sp, #508 @ encoding: [0xff,0xb0]
+
+
+@------------------------------------------------------------------------------
+@ SUB (register)
+@------------------------------------------------------------------------------
+ subs r1, r2, r3
+
+@ CHECK: subs r1, r2, r3 @ encoding: [0xd1,0x1a]
+
+
+@------------------------------------------------------------------------------
+@ SVC
+@------------------------------------------------------------------------------
+ svc #0
+ svc #255
+
+@ CHECK: svc #0 @ encoding: [0x00,0xdf]
+@ CHECK: svc #255 @ encoding: [0xff,0xdf]
+
+
+@------------------------------------------------------------------------------
+@ SXTB/SXTH
+@------------------------------------------------------------------------------
+ sxtb r3, r5
+ sxth r3, r5
+
+@ CHECK: sxtb r3, r5 @ encoding: [0x6b,0xb2]
+@ CHECK: sxth r3, r5 @ encoding: [0x2b,0xb2]
+
+
+@------------------------------------------------------------------------------
+@ TST
+@------------------------------------------------------------------------------
+ tst r6, r1
+
+@ CHECK: tst r6, r1 @ encoding: [0x0e,0x42]
+
+
+@------------------------------------------------------------------------------
+@ UXTB/UXTH
+@------------------------------------------------------------------------------
+ uxtb r7, r2
+ uxth r1, r4
+
+@ CHECK: uxtb r7, r2 @ encoding: [0xd7,0xb2]
+@ CHECK: uxth r1, r4 @ encoding: [0xa1,0xb2]
+
+
+@------------------------------------------------------------------------------
+@ WFE/WFI/YIELD
+@------------------------------------------------------------------------------
+ wfe
+ wfi
+ yield
+
+@ CHECK: wfe @ encoding: [0x20,0xbf]
+@ CHECK: wfi @ encoding: [0x30,0xbf]
+@ CHECK: yield @ encoding: [0x10,0xbf]