xref: /llvm-project/llvm/test/MC/ARM/thumb2-branches.s (revision 404843a94dbf2f9d91b9bb1dfc8608a4d7ae58c7)
1@ RUN: llvm-mc -triple=thumbv7-apple-darwin -mcpu=cortex-a8 -show-encoding < %s | FileCheck %s
2
3@------------------------------------------------------------------------------
4@ unconditional branches accept narrow suffix and encode to short encodings
5@------------------------------------------------------------------------------
6
7         b.n    #-2048
8         b.n    #2046
9
10@ CHECK: b	#-2048                  @ encoding: [0x00,0xe4]
11@ CHECK: b	#2046                   @ encoding: [0xff,0xe3]
12
13@------------------------------------------------------------------------------
14@ unconditional branches accept wide suffix and encode to wide encodings
15@------------------------------------------------------------------------------
16
17         b.w    #-2048
18         b.w    #2046
19         b.w    #-1677216
20         b.w    #1677214
21
22@ CHECK: b.w	#-2048                  @ encoding: [0xff,0xf7,0x00,0xbc]
23@ CHECK: b.w	#2046                   @ encoding: [0x00,0xf0,0xff,0xbb]
24@ CHECK: b.w	#-1677216               @ encoding: [0x66,0xf6,0x30,0xbc]
25@ CHECK: b.w	#1677214                @ encoding: [0x99,0xf1,0xcf,0xbb]
26
27@------------------------------------------------------------------------------
28@ unconditional branches without width suffix encode depending of offset size
29@------------------------------------------------------------------------------
30
31         b      #-2048
32         b      #2046
33         b      #-2050
34         b      #2048
35         b      #-1677216
36         b      #1677214
37
38@ CHECK: b	#-2048                  @ encoding: [0x00,0xe4]
39@ CHECK: b	#2046                   @ encoding: [0xff,0xe3]
40@ CHECK: b.w	#-2050                  @ encoding: [0xff,0xf7,0xff,0xbb]
41@ CHECK: b.w	#2048                   @ encoding: [0x00,0xf0,0x00,0xbc]
42@ CHECK: b.w	#-1677216               @ encoding: [0x66,0xf6,0x30,0xbc]
43@ CHECK: b.w	#1677214                @ encoding: [0x99,0xf1,0xcf,0xbb]
44
45@------------------------------------------------------------------------------
46@ unconditional branches with width narrow suffix in IT block
47@------------------------------------------------------------------------------
48
49         it     eq
50         beq.n  #-2048
51         it     ne
52         bne.n  #-2046
53
54@ CHECK: it	eq                      @ encoding: [0x08,0xbf]
55@ CHECK: beq	#-2048                  @ encoding: [0x00,0xe4]
56@ CHECK: it	ne                      @ encoding: [0x18,0xbf]
57@ CHECK: bne	#-2046                  @ encoding: [0x01,0xe4]
58
59@------------------------------------------------------------------------------
60@ unconditional branches with wide suffix in IT block
61@------------------------------------------------------------------------------
62
63         it     gt
64         bgt.w  #-2048
65         it     le
66         ble.w  #2046
67         it     ge
68         bge.w  #-1677216
69         it     lt
70         blt.w  #1677214
71
72@ CHECK: it	gt                      @ encoding: [0xc8,0xbf]
73@ CHECK: bgt.w	#-2048                  @ encoding: [0xff,0xf7,0x00,0xbc]
74@ CHECK: it	le                      @ encoding: [0xd8,0xbf]
75@ CHECK: ble.w	#2046                   @ encoding: [0x00,0xf0,0xff,0xbb]
76@ CHECK: it	ge                      @ encoding: [0xa8,0xbf]
77@ CHECK: bge.w	#-1677216               @ encoding: [0x66,0xf6,0x30,0xbc]
78@ CHECK: it	lt                      @ encoding: [0xb8,0xbf]
79@ CHECK: blt.w	#1677214                @ encoding: [0x99,0xf1,0xcf,0xbb]
80
81@------------------------------------------------------------------------------
82@ conditional branches accept narrow suffix and encode to short encodings
83@------------------------------------------------------------------------------
84
85         beq.n    #-256
86         bne.n    #254
87
88@ CHECK: beq	#-256                   @ encoding: [0x80,0xd0]
89@ CHECK: bne	#254                    @ encoding: [0x7f,0xd1]
90
91@------------------------------------------------------------------------------
92@ unconditional branches accept wide suffix and encode to wide encodings
93@------------------------------------------------------------------------------
94
95         bl.w     #256
96         it ne
97         blne.w   #256
98         bmi.w    #-256
99         bne.w    #254
100         blt.w    #-1048576
101         bge.w    #1048574
102
103@ CHECK: bl	#256                    @ encoding: [0x00,0xf0,0x80,0xf8]
104@ CHECK: it	ne                      @ encoding: [0x18,0xbf]
105@ CHECK: blne	#256                    @ encoding: [0x00,0xf0,0x80,0xf8]
106@ CHECK: bmi.w	#-256                   @ encoding: [0x3f,0xf5,0x80,0xaf]
107@ CHECK: bne.w	#254                    @ encoding: [0x40,0xf0,0x7f,0x80]
108@ CHECK: blt.w	#-1048576               @ encoding: [0xc0,0xf6,0x00,0x80]
109@ CHECK: bge.w	#1048574                @ encoding: [0xbf,0xf2,0xff,0xaf]
110
111@------------------------------------------------------------------------------
112@ unconditional branches without width suffix encode depending of offset size
113@------------------------------------------------------------------------------
114
115         bne     #-256
116         bgt     #254
117         bne     #-258
118         bgt     #256
119         bne     #-1048576
120         bgt     #1048574
121
122@ CHECK: bne	#-256                   @ encoding: [0x80,0xd1]
123@ CHECK: bgt	#254                    @ encoding: [0x7f,0xdc]
124@ CHECK: bne.w	#-258                   @ encoding: [0x7f,0xf4,0x7f,0xaf]
125@ CHECK: bgt.w	#256                    @ encoding: [0x00,0xf3,0x80,0x80]
126@ CHECK: bne.w	#-1048576               @ encoding: [0x40,0xf4,0x00,0x80]
127@ CHECK: bgt.w	#1048574                @ encoding: [0x3f,0xf3,0xff,0xaf]
128
129@------------------------------------------------------------------------------
130@ same branch insturction encoding to conditional or unconditional depending
131@ on whether it is in an IT block or not
132@------------------------------------------------------------------------------
133
134         it     eq
135         addeq  r0, r1
136         bne    #128
137
138@ CHECK: it	eq                      @ encoding: [0x08,0xbf]
139@ CHECK: addeq	r0, r1                  @ encoding: [0x08,0x44]
140@ CHECK: bne	#128                    @ encoding: [0x40,0xd1]
141
142         ite    eq
143         addeq  r0, r1
144         bne    #128
145
146@ CHECK: ite	eq                      @ encoding: [0x0c,0xbf]
147@ CHECK: addeq	r0, r1                  @ encoding: [0x08,0x44]
148@ CHECK: bne	#128                    @ encoding: [0x40,0xe0]
149
150@ RUN: llvm-mc -triple=thumbv7-apple-darwin -mcpu=cortex-a8 -show-encoding < %s | FileCheck %s
151
152@------------------------------------------------------------------------------
153@ unconditional branches accept narrow suffix and encode to short encodings
154@------------------------------------------------------------------------------
155
156         b.n    #-2048
157         b.n    #2046
158
159@ CHECK: b	#-2048                  @ encoding: [0x00,0xe4]
160@ CHECK: b	#2046                   @ encoding: [0xff,0xe3]
161
162@------------------------------------------------------------------------------
163@ unconditional branches accept wide suffix and encode to wide encodings
164@------------------------------------------------------------------------------
165
166         b.w    #-2048
167         b.w    #2046
168         b.w    #-1677216
169         b.w    #1677214
170
171@ CHECK: b.w	#-2048                  @ encoding: [0xff,0xf7,0x00,0xbc]
172@ CHECK: b.w	#2046                   @ encoding: [0x00,0xf0,0xff,0xbb]
173@ CHECK: b.w	#-1677216               @ encoding: [0x66,0xf6,0x30,0xbc]
174@ CHECK: b.w	#1677214                @ encoding: [0x99,0xf1,0xcf,0xbb]
175
176@------------------------------------------------------------------------------
177@ unconditional branches without width suffix encode depending of offset size
178@------------------------------------------------------------------------------
179
180         b      #-2048
181         b      #2046
182         b      #-2050
183         b      #2048
184         b      #-1677216
185         b      #1677214
186
187@ CHECK: b	#-2048                  @ encoding: [0x00,0xe4]
188@ CHECK: b	#2046                   @ encoding: [0xff,0xe3]
189@ CHECK: b.w	#-2050                  @ encoding: [0xff,0xf7,0xff,0xbb]
190@ CHECK: b.w	#2048                   @ encoding: [0x00,0xf0,0x00,0xbc]
191@ CHECK: b.w	#-1677216               @ encoding: [0x66,0xf6,0x30,0xbc]
192@ CHECK: b.w	#1677214                @ encoding: [0x99,0xf1,0xcf,0xbb]
193
194@------------------------------------------------------------------------------
195@ unconditional branches with width narrow suffix in IT block
196@------------------------------------------------------------------------------
197
198         it     eq
199         beq.n  #-2048
200         it     ne
201         bne.n  #-2046
202
203@ CHECK: it	eq                      @ encoding: [0x08,0xbf]
204@ CHECK: beq	#-2048                  @ encoding: [0x00,0xe4]
205@ CHECK: it	ne                      @ encoding: [0x18,0xbf]
206@ CHECK: bne	#-2046                  @ encoding: [0x01,0xe4]
207
208@------------------------------------------------------------------------------
209@ unconditional branches with wide suffix in IT block
210@------------------------------------------------------------------------------
211
212         it     gt
213         bgt.w  #-2048
214         it     le
215         ble.w  #2046
216         it     ge
217         bge.w  #-1677216
218         it     lt
219         blt.w  #1677214
220
221@ CHECK: it	gt                      @ encoding: [0xc8,0xbf]
222@ CHECK: bgt.w	#-2048                  @ encoding: [0xff,0xf7,0x00,0xbc]
223@ CHECK: it	le                      @ encoding: [0xd8,0xbf]
224@ CHECK: ble.w	#2046                   @ encoding: [0x00,0xf0,0xff,0xbb]
225@ CHECK: it	ge                      @ encoding: [0xa8,0xbf]
226@ CHECK: bge.w	#-1677216               @ encoding: [0x66,0xf6,0x30,0xbc]
227@ CHECK: it	lt                      @ encoding: [0xb8,0xbf]
228@ CHECK: blt.w	#1677214                @ encoding: [0x99,0xf1,0xcf,0xbb]
229
230@------------------------------------------------------------------------------
231@ conditional branches accept narrow suffix and encode to short encodings
232@------------------------------------------------------------------------------
233
234         beq.n    #-256
235         bne.n    #254
236
237@ CHECK: beq	#-256                   @ encoding: [0x80,0xd0]
238@ CHECK: bne	#254                    @ encoding: [0x7f,0xd1]
239
240@------------------------------------------------------------------------------
241@ unconditional branches accept wide suffix and encode to wide encodings
242@------------------------------------------------------------------------------
243
244         bmi.w    #-256
245         bne.w    #254
246         blt.w    #-1048576
247         bge.w    #1048574
248
249@ CHECK: bmi.w	#-256                   @ encoding: [0x3f,0xf5,0x80,0xaf]
250@ CHECK: bne.w	#254                    @ encoding: [0x40,0xf0,0x7f,0x80]
251@ CHECK: blt.w	#-1048576               @ encoding: [0xc0,0xf6,0x00,0x80]
252@ CHECK: bge.w	#1048574                @ encoding: [0xbf,0xf2,0xff,0xaf]
253
254@------------------------------------------------------------------------------
255@ unconditional branches without width suffix encode depending of offset size
256@------------------------------------------------------------------------------
257
258         bne     #-256
259         bgt     #254
260         bne     #-258
261         bgt     #256
262         bne     #-1048576
263         bgt     #1048574
264
265@ CHECK: bne	#-256                   @ encoding: [0x80,0xd1]
266@ CHECK: bgt	#254                    @ encoding: [0x7f,0xdc]
267@ CHECK: bne.w	#-258                   @ encoding: [0x7f,0xf4,0x7f,0xaf]
268@ CHECK: bgt.w	#256                    @ encoding: [0x00,0xf3,0x80,0x80]
269@ CHECK: bne.w	#-1048576               @ encoding: [0x40,0xf4,0x00,0x80]
270@ CHECK: bgt.w	#1048574                @ encoding: [0x3f,0xf3,0xff,0xaf]
271
272@------------------------------------------------------------------------------
273@ same branch insturction encoding to conditional or unconditional depending
274@ on whether it is in an IT block or not
275@------------------------------------------------------------------------------
276
277         it     eq
278         addeq  r0, r1
279         bne    #128
280
281@ CHECK: it	eq                      @ encoding: [0x08,0xbf]
282@ CHECK: addeq	r0, r1                  @ encoding: [0x08,0x44]
283@ CHECK: bne	#128                    @ encoding: [0x40,0xd1]
284
285         ite    eq
286         addeq  r0, r1
287         bne    #128
288
289@ CHECK: ite	eq                      @ encoding: [0x0c,0xbf]
290@ CHECK: addeq	r0, r1                  @ encoding: [0x08,0x44]
291@ CHECK: bne	#128                    @ encoding: [0x40,0xe0]
292
293
294@------------------------------------------------------------------------------
295@ Branch targets destined for ARM mode must == 0 (mod 4), otherwise (mod 2).
296@------------------------------------------------------------------------------
297
298        b #2
299        bl #2
300        beq #2
301        cbz r0, #2
302        @ N.b. destination is "align(PC, 4) + imm" so imm is still 4-byte
303        @ aligned even though current PC may not and destination must be.
304        blx #4
305
306@ CHECK: b	#2                      @ encoding: [0x01,0xe0]
307@ CHECK: bl	#2                      @ encoding: [0x00,0xf0,0x01,0xf8]
308@ CHECK: beq	#2                      @ encoding: [0x01,0xd0]
309@ CHECK: cbz	r0, #2                  @ encoding: [0x08,0xb1]
310@ CHECK: blx	#4                      @ encoding: [0x00,0xf0,0x02,0xe8]
311