1 # RUN: llvm-mc %s -triple=riscv32 -riscv-no-aliases -show-encoding \
2 # RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
3 # RUN: llvm-mc %s -triple riscv64 -riscv-no-aliases -show-encoding \
4 # RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
5 # RUN: llvm-mc -filetype=obj -triple=riscv32 < %s \
6 # RUN: | llvm-objdump -M no-aliases -d -r - \
7 # RUN: | FileCheck -check-prefixes=CHECK-OBJ,CHECK-ASM-AND-OBJ %s
8 # RUN: llvm-mc -filetype=obj -triple=riscv64 < %s \
9 # RUN: | llvm-objdump -M no-aliases -d -r - \
10 # RUN: | FileCheck -check-prefixes=CHECK-OBJ,CHECK-ASM-AND-OBJ %s
14 # CHECK-ASM-AND-OBJ: lui a0, 2
15 # CHECK-ASM: encoding: [0x37,0x25,0x00,0x00]
17 # CHECK-ASM-AND-OBJ: lui s11, 552960
18 # CHECK-ASM: encoding: [0xb7,0x0d,0x00,0x87]
19 lui s11
, (0x87000000>>12)
20 # CHECK-ASM-AND-OBJ: lui a0, 0
21 # CHECK-ASM: encoding: [0x37,0x05,0x00,0x00]
23 # CHECK-ASM-AND-OBJ: lui s11, 552960
24 # CHECK-ASM: encoding: [0xb7,0x0d,0x00,0x87]
25 lui s11
, (0x87000000>>12)
26 # CHECK-ASM-AND-OBJ: lui s11, 552960
27 # CHECK-ASM: encoding: [0xb7,0x0d,0x00,0x87]
28 lui s11
, %hi
(0x87000000)
29 # CHECK-ASM-AND-OBJ: lui t0, 1048575
30 # CHECK-ASM: encoding: [0xb7,0xf2,0xff,0xff]
32 # CHECK-ASM-AND-OBJ: lui gp, 0
33 # CHECK-ASM: encoding: [0xb7,0x01,0x00,0x00]
35 # CHECK-ASM: lui a0, %hi(foo)
36 # CHECK-ASM: encoding: [0x37,0bAAAA0101,A,A]
37 # CHECK-OBJ: lui a0, 0
38 # CHECK-OBJ: R_RISCV_HI20 foo
40 # CHECK-ASM-AND-OBJ: lui a0, 30
41 # CHECK-ASM: encoding: [0x37,0xe5,0x01,0x00]
43 # CHECK-ASM-AND-OBJ: lui a0, 31
44 # CHECK-ASM: encoding: [0x37,0xf5,0x01,0x00]
47 # CHECK-ASM-AND-OBJ: auipc a0, 2
48 # CHECK-ASM: encoding: [0x17,0x25,0x00,0x00]
50 # CHECK-ASM-AND-OBJ: auipc s11, 552960
51 # CHECK-ASM: encoding: [0x97,0x0d,0x00,0x87]
52 auipc s11
, (0x87000000>>12)
53 # CHECK-ASM-AND-OBJ: auipc t0, 1048575
54 # CHECK-ASM: encoding: [0x97,0xf2,0xff,0xff]
56 # CHECK-ASM-AND-OBJ: auipc gp, 0
57 # CHECK-ASM: encoding: [0x97,0x01,0x00,0x00]
59 # CHECK-ASM: auipc a0, %pcrel_hi(foo)
60 # CHECK-ASM: encoding: [0x17,0bAAAA0101,A,A]
61 # CHECK-OBJ: auipc a0, 0
62 # CHECK-OBJ: R_RISCV_PCREL_HI20 foo
63 auipc a0
, %pcrel_hi
(foo
)
64 # CHECK-ASM-AND-OBJ: auipc a0, 30
65 # CHECK-ASM: encoding: [0x17,0xe5,0x01,0x00]
68 # CHECK-ASM-AND-OBJ: jal a2, 1048574
69 # CHECK-ASM: encoding: [0x6f,0xf6,0xff,0x7f]
71 # CHECK-ASM-AND-OBJ: jal a3, 256
72 # CHECK-ASM: encoding: [0xef,0x06,0x00,0x10]
74 # CHECK-ASM: jal a0, foo
75 # CHECK-ASM: encoding: [0x6f,0bAAAA0101,A,A]
76 # CHECK-OBJ: jal a0, 0
77 # CHECK-OBJ: R_RISCV_JAL foo
79 # CHECK-ASM: jal a0, a0
80 # CHECK-ASM: encoding: [0x6f,0bAAAA0101,A,A]
81 # CHECK-OBJ: jal a0, 0
82 # CHECK-OBJ: R_RISCV_JAL a0
84 # CHECK-ASM-AND-OBJ: jal a0, 30
85 # CHECK-ASM: encoding: [0x6f,0x05,0xe0,0x01]
87 # CHECK-ASM-AND-OBJ: jal s0, 0
88 # CHECK-ASM: encoding: [0x6f,0x04,0x00,0x00]
90 # CHECK-ASM-AND-OBJ: jal s0, 156
91 # CHECK-ASM: encoding: [0x6f,0x04,0xc0,0x09]
93 # CHECK-ASM: encoding: [0x6f,0bAAAA0000,A,A]
94 # CHECK-OBJ: jal zero, 0
97 # CHECK-ASM-AND-OBJ: jalr a0, -2048(a1)
98 # CHECK-ASM: encoding: [0x67,0x85,0x05,0x80]
100 # CHECK-ASM-AND-OBJ: jalr a0, -2048(a1)
101 # CHECK-ASM: encoding: [0x67,0x85,0x05,0x80]
102 jalr a0
, %lo
(2048)(a1
)
103 # CHECK-ASM-AND-OBJ: jalr t2, 2047(t1)
104 # CHECK-ASM: encoding: [0xe7,0x03,0xf3,0x7f]
106 # CHECK-ASM-AND-OBJ: jalr sp, 256(zero)
107 # CHECK-ASM: encoding: [0x67,0x01,0x00,0x10]
109 # CHECK-ASM-AND-OBJ: jalr a1, 30(a2)
110 # CHECK-ASM: encoding: [0xe7,0x05,0xe6,0x01]
113 # CHECK-ASM-AND-OBJ: beq s1, s1, 102
114 # CHECK-ASM: encoding: [0x63,0x83,0x94,0x06]
116 # CHECK-ASM-AND-OBJ: bne a4, a5, -4096
117 # CHECK-ASM: encoding: [0x63,0x10,0xf7,0x80]
119 # CHECK-ASM-AND-OBJ: blt sp, gp, 4094
120 # CHECK-ASM: encoding: [0xe3,0x4f,0x31,0x7e]
122 # CHECK-ASM-AND-OBJ: bge s2, ra, -224
123 # CHECK-ASM: encoding: [0xe3,0x50,0x19,0xf2]
125 # CHECK-ASM-AND-OBJ: bltu zero, zero, 0
126 # CHECK-ASM: encoding: [0x63,0x60,0x00,0x00]
128 # CHECK-ASM-AND-OBJ: bgeu s8, sp, 512
129 # CHECK-ASM: encoding: [0x63,0x70,0x2c,0x20]
131 # CHECK-ASM-AND-OBJ: bgeu t0, t1, 30
132 # CHECK-ASM: encoding: [0x63,0xff,0x62,0x00]
135 # CHECK-ASM-AND-OBJ: lb s3, 4(ra)
136 # CHECK-ASM: encoding: [0x83,0x89,0x40,0x00]
138 # CHECK-ASM-AND-OBJ: lb s3, 4(ra)
139 # CHECK-ASM: encoding: [0x83,0x89,0x40,0x00]
141 # CHECK-ASM-AND-OBJ: lh t1, -2048(zero)
142 # CHECK-ASM: encoding: [0x03,0x13,0x00,0x80]
144 # CHECK-ASM-AND-OBJ: lh t1, -2048(zero)
145 # CHECK-ASM: encoding: [0x03,0x13,0x00,0x80]
147 # CHECK-ASM-AND-OBJ: lh t1, 0(zero)
148 # CHECK-ASM: encoding: [0x03,0x13,0x00,0x00]
150 # CHECK-ASM-AND-OBJ: lh t1, -2048(zero)
151 # CHECK-ASM: encoding: [0x03,0x13,0x00,0x80]
152 lh t1
, %lo
(2048)(zero
)
153 # CHECK-ASM-AND-OBJ: lh sp, 2047(a0)
154 # CHECK-ASM: encoding: [0x03,0x11,0xf5,0x7f]
156 # CHECK-ASM-AND-OBJ: lw a0, 97(a2)
157 # CHECK-ASM: encoding: [0x03,0x25,0x16,0x06]
159 # CHECK-ASM: lbu s5, %lo(foo)(s6)
160 # CHECK-ASM: encoding: [0x83,0x4a,0bAAAA1011,A]
161 # CHECK-OBJ: lbu s5, 0(s6)
162 # CHECK-OBJ: R_RISCV_LO12
164 # CHECK-ASM: lhu t3, %pcrel_lo(foo)(t3)
165 # CHECK-ASM: encoding: [0x03,0x5e,0bAAAA1110,A]
166 # CHECK-OBJ: lhu t3, 0(t3)
167 # CHECK-OBJ: R_RISCV_PCREL_LO12
168 lhu t3
, %pcrel_lo
(foo
)(t3
)
169 # CHECK-ASM-AND-OBJ: lb t0, 30(t1)
170 # CHECK-ASM: encoding: [0x83,0x02,0xe3,0x01]
172 # CHECK-ASM-AND-OBJ: lb s0, 0(s1)
173 # CHECK-ASM: encoding: [0x03,0x84,0x04,0x00]
175 # CHECK-ASM-AND-OBJ: lb s0, 156(s1)
176 # CHECK-ASM: encoding: [0x03,0x84,0xc4,0x09]
179 # CHECK-ASM-AND-OBJ: sb a0, 2047(a2)
180 # CHECK-ASM: encoding: [0xa3,0x0f,0xa6,0x7e]
182 # CHECK-ASM-AND-OBJ: sh t3, -2048(t5)
183 # CHECK-ASM: encoding: [0x23,0x10,0xcf,0x81]
185 # CHECK-ASM-AND-OBJ: sh t3, -2048(t5)
186 # CHECK-ASM: encoding: [0x23,0x10,0xcf,0x81]
188 # CHECK-ASM-AND-OBJ: sh t3, 0(t5)
189 # CHECK-ASM: encoding: [0x23,0x10,0xcf,0x01]
191 # CHECK-ASM-AND-OBJ: sh t3, -2048(t5)
192 # CHECK-ASM: encoding: [0x23,0x10,0xcf,0x81]
194 # CHECK-ASM-AND-OBJ: sw ra, 999(zero)
195 # CHECK-ASM: encoding: [0xa3,0x23,0x10,0x3e]
197 # CHECK-ASM-AND-OBJ: sw a0, 30(t0)
198 # CHECK-ASM: encoding: [0x23,0xaf,0xa2,0x00]
200 # CHECK-ASM-AND-OBJ: sw s0, 0(s1)
201 # CHECK-ASM: encoding: [0x23,0xa0,0x84,0x00]
203 # CHECK-ASM-AND-OBJ: sw s0, 156(s1)
204 # CHECK-ASM: encoding: [0x23,0xae,0x84,0x08]
207 # CHECK-ASM-AND-OBJ: addi ra, sp, 2
208 # CHECK-ASM: encoding: [0x93,0x00,0x21,0x00]
210 # CHECK-ASM: addi ra, sp, %lo(foo)
211 # CHECK-ASM: encoding: [0x93,0x00,0bAAAA0001,A]
212 # CHECK-OBJ: addi ra, sp, 0
213 # CHECK-OBJ: R_RISCV_LO12
214 addi ra
, sp
, %lo
(foo
)
215 # CHECK-ASM-AND-OBJ: addi ra, sp, 30
216 # CHECK-ASM: encoding: [0x93,0x00,0xe1,0x01]
218 # CHECK-ASM-AND-OBJ: addi ra, sp, 0
219 # CHECK-ASM: encoding: [0x93,0x00,0x01,0x00]
221 # CHECK-ASM-AND-OBJ: addi ra, sp, 156
222 # CHECK-ASM: encoding: [0x93,0x00,0xc1,0x09]
223 addi ra
, sp
, (0xff-99)
224 # CHECK-ASM-AND-OBJ: slti a0, a2, -20
225 # CHECK-ASM: encoding: [0x13,0x25,0xc6,0xfe]
227 # CHECK-ASM-AND-OBJ: sltiu s2, s3, 80
228 # CHECK-ASM: encoding: [0x13,0xb9,0x09,0x05]
230 # CHECK-ASM-AND-OBJ: xori tp, t1, -99
231 # CHECK-ASM: encoding: [0x13,0x42,0xd3,0xf9]
233 # CHECK-ASM-AND-OBJ: ori a0, a1, -2048
234 # CHECK-ASM: encoding: [0x13,0xe5,0x05,0x80]
236 # CHECK-ASM-AND-OBJ: ori a0, a1, -2048
237 # CHECK-ASM: encoding: [0x13,0xe5,0x05,0x80]
239 # CHECK-ASM-AND-OBJ: ori a0, a1, 0
240 # CHECK-ASM: encoding: [0x13,0xe5,0x05,0x00]
242 # CHECK-ASM-AND-OBJ: ori a0, a1, -2048
243 # CHECK-ASM: encoding: [0x13,0xe5,0x05,0x80]
244 ori a0
, a1
, %lo
(2048)
245 # CHECK-ASM-AND-OBJ: andi ra, sp, 2047
246 # CHECK-ASM: encoding: [0x93,0x70,0xf1,0x7f]
248 # CHECK-ASM-AND-OBJ: andi ra, sp, 2047
249 # CHECK-ASM: encoding: [0x93,0x70,0xf1,0x7f]
252 # CHECK-ASM-AND-OBJ: slli t3, t3, 31
253 # CHECK-ASM: encoding: [0x13,0x1e,0xfe,0x01]
255 # CHECK-ASM-AND-OBJ: srli a0, a4, 0
256 # CHECK-ASM: encoding: [0x13,0x55,0x07,0x00]
258 # CHECK-ASM-AND-OBJ: srai a2, sp, 15
259 # CHECK-ASM: encoding: [0x13,0x56,0xf1,0x40]
261 # CHECK-ASM-AND-OBJ: slli t3, t3, 30
262 # CHECK-ASM: encoding: [0x13,0x1e,0xee,0x01]
265 # CHECK-ASM-AND-OBJ: add ra, zero, zero
266 # CHECK-ASM: encoding: [0xb3,0x00,0x00,0x00]
268 # CHECK-ASM-AND-OBJ: add ra, zero, zero
269 # CHECK-ASM: encoding: [0xb3,0x00,0x00,0x00]
271 # CHECK-ASM-AND-OBJ: sub t0, t2, t1
272 # CHECK-ASM: encoding: [0xb3,0x82,0x63,0x40]
274 # CHECK-ASM-AND-OBJ: sll a5, a4, a3
275 # CHECK-ASM: encoding: [0xb3,0x17,0xd7,0x00]
277 # CHECK-ASM-AND-OBJ: slt s0, s0, s0
278 # CHECK-ASM: encoding: [0x33,0x24,0x84,0x00]
280 # CHECK-ASM-AND-OBJ: sltu gp, a0, a1
281 # CHECK-ASM: encoding: [0xb3,0x31,0xb5,0x00]
283 # CHECK-ASM-AND-OBJ: xor s2, s2, s8
284 # CHECK-ASM: encoding: [0x33,0x49,0x89,0x01]
286 # CHECK-ASM-AND-OBJ: xor s2, s2, s8
287 # CHECK-ASM: encoding: [0x33,0x49,0x89,0x01]
289 # CHECK-ASM-AND-OBJ: srl a0, s0, t0
290 # CHECK-ASM: encoding: [0x33,0x55,0x54,0x00]
292 # CHECK-ASM-AND-OBJ: sra t0, s2, zero
293 # CHECK-ASM: encoding: [0xb3,0x52,0x09,0x40]
295 # CHECK-ASM-AND-OBJ: or s10, t1, ra
296 # CHECK-ASM: encoding: [0x33,0x6d,0x13,0x00]
298 # CHECK-ASM-AND-OBJ: and a0, s2, s3
299 # CHECK-ASM: encoding: [0x33,0x75,0x39,0x01]
302 # CHECK-ASM-AND-OBJ: fence iorw, iorw
303 # CHECK-ASM: encoding: [0x0f,0x00,0xf0,0x0f]
305 # CHECK-ASM-AND-OBJ: fence io, rw
306 # CHECK-ASM: encoding: [0x0f,0x00,0x30,0x0c]
308 # CHECK-ASM-AND-OBJ: fence r, w
309 # CHECK-ASM: encoding: [0x0f,0x00,0x10,0x02]
311 # CHECK-ASM-AND-OBJ: fence w, ir
312 # CHECK-ASM: encoding: [0x0f,0x00,0xa0,0x01]
314 # CHECK-ASM-AND-OBJ: fence.tso
315 # CHECK-ASM: encoding: [0x0f,0x00,0x30,0x83]
318 # CHECK-ASM-AND-OBJ: fence.i
319 # CHECK-ASM: encoding: [0x0f,0x10,0x00,0x00]
322 # CHECK-ASM-AND-OBJ: ecall
323 # CHECK-ASM: encoding: [0x73,0x00,0x00,0x00]
325 # CHECK-ASM-AND-OBJ: ebreak
326 # CHECK-ASM: encoding: [0x73,0x00,0x10,0x00]
328 # CHECK-ASM-AND-OBJ: unimp
329 # CHECK-ASM: encoding: [0x73,0x10,0x00,0xc0]
334 # CHECK-ASM-AND-OBJ: csrrw t0, 4095, t1
335 # CHECK-ASM: encoding: [0xf3,0x12,0xf3,0xff]
337 # CHECK-ASM-AND-OBJ: csrrw s0, 4095, s1
338 # CHECK-ASM: encoding: [0x73,0x94,0xf4,0xff]
339 csrrw s0
, ~
(-4096), s1
340 # CHECK-ASM-AND-OBJ: csrrw s0, fflags, s1
341 # CHECK-ASM: encoding: [0x73,0x94,0x14,0x00]
343 # CHECK-ASM-AND-OBJ: csrrs s0, cycle, zero
344 # CHECK-ASM: encoding: [0x73,0x24,0x00,0xc0]
346 # CHECK-ASM-AND-OBJ: csrrs s3, fflags, s5
347 # CHECK-ASM: encoding: [0xf3,0xa9,0x1a,0x00]
349 # CHECK-ASM-AND-OBJ: csrrc sp, ustatus, ra
350 # CHECK-ASM: encoding: [0x73,0xb1,0x00,0x00]
352 # CHECK-ASM-AND-OBJ: csrrwi a5, ustatus, 0
353 # CHECK-ASM: encoding: [0xf3,0x57,0x00,0x00]
355 # CHECK-ASM-AND-OBJ: csrrsi t2, 4095, 31
356 # CHECK-ASM: encoding: [0xf3,0xe3,0xff,0xff]
358 # CHECK-ASM-AND-OBJ: csrrci t1, sscratch, 5
359 # CHECK-ASM: encoding: [0x73,0xf3,0x02,0x14]