1 // Copyright 2015, VIXL authors
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 // * Redistributions of source code must retain the above copyright notice,
8 // this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright notice,
10 // this list of conditions and the following disclaimer in the documentation
11 // and/or other materials provided with the distribution.
12 // * Neither the name of ARM Limited nor the names of its contributors may be
13 // used to endorse or promote products derived from this software without
14 // specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND
17 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27
28 #include <cstdio>
29 #include <cstring>
30 #include <string>
31
32 #include "test-runner.h"
33
34 #include "aarch64/disasm-aarch64.h"
35 #include "aarch64/macro-assembler-aarch64.h"
36 #include "test-disasm-aarch64.h"
37
38 namespace vixl {
39 namespace aarch64 {
40
TEST(bootstrap)41 TEST(bootstrap) {
42 SETUP();
43
44 // Instructions generated by C compiler, disassembled by objdump, and
45 // reformatted to suit our disassembly style.
46 COMPARE(dci(0xa9ba7bfd), "stp x29, x30, [sp, #-96]!");
47 COMPARE(dci(0x910003fd), "mov x29, sp");
48 COMPARE(dci(0x9100e3a0), "add x0, x29, #0x38 (56)");
49 COMPARE(dci(0xb900001f), "str wzr, [x0]");
50 COMPARE(dci(0x528000e1), "mov w1, #0x7");
51 COMPARE(dci(0xb9001c01), "str w1, [x0, #28]");
52 COMPARE(dci(0x390043a0), "strb w0, [x29, #16]");
53 COMPARE(dci(0x790027a0), "strh w0, [x29, #18]");
54 COMPARE(dci(0xb9400400), "ldr w0, [x0, #4]");
55 COMPARE(dci(0x0b000021), "add w1, w1, w0");
56 COMPARE(dci(0x531b6800), "lsl w0, w0, #5");
57 COMPARE(dci(0x521e0400), "eor w0, w0, #0xc");
58 COMPARE(dci(0x72af0f00), "movk w0, #0x7878, lsl #16");
59 COMPARE(dci(0xd360fc00), "lsr x0, x0, #32");
60 COMPARE(dci(0x13037c01), "asr w1, w0, #3");
61 COMPARE(dci(0x4b000021), "sub w1, w1, w0");
62 COMPARE(dci(0x2a0103e0), "mov w0, w1");
63 COMPARE(dci(0x93407c00), "sxtw x0, w0");
64 COMPARE(dci(0x2a000020), "orr w0, w1, w0");
65 COMPARE(dci(0xa8c67bfd), "ldp x29, x30, [sp], #96");
66
67 CLEANUP();
68 }
69
70
TEST(mov_mvn)71 TEST(mov_mvn) {
72 SETUP();
73
74 COMPARE_MACRO(Mov(w0, Operand(0x1234)), "mov w0, #0x1234");
75 COMPARE_MACRO(Mov(x1, Operand(0x1234)), "mov x1, #0x1234");
76 COMPARE_MACRO(Mov(w2, Operand(w3)), "mov w2, w3");
77 COMPARE_MACRO(Mov(x4, Operand(x5)), "mov x4, x5");
78 COMPARE_MACRO(Mov(w6, Operand(w7, LSL, 5)), "lsl w6, w7, #5");
79 COMPARE_MACRO(Mov(x8, Operand(x9, ASR, 42)), "asr x8, x9, #42");
80 COMPARE_MACRO(Mov(w10, Operand(w11, UXTB)), "uxtb w10, w11");
81 COMPARE_MACRO(Mov(x12, Operand(x13, UXTB, 1)), "ubfiz x12, x13, #1, #8");
82 COMPARE_MACRO(Mov(w14, Operand(w15, SXTH, 2)), "sbfiz w14, w15, #2, #16");
83 COMPARE_MACRO(Mov(x16, Operand(x17, SXTW, 3)), "sbfiz x16, x17, #3, #32");
84
85 COMPARE_MACRO(Mvn(w0, Operand(0x101)), "mov w0, #0xfffffefe");
86 COMPARE_MACRO(Mvn(x1, Operand(0xfff1)), "mov x1, #0xffffffffffff000e");
87 COMPARE_MACRO(Mvn(w2, Operand(w3)), "mvn w2, w3");
88 COMPARE_MACRO(Mvn(x4, Operand(x5)), "mvn x4, x5");
89 COMPARE_MACRO(Mvn(w6, Operand(w7, LSL, 12)), "mvn w6, w7, lsl #12");
90 COMPARE_MACRO(Mvn(x8, Operand(x9, ASR, 63)), "mvn x8, x9, asr #63");
91
92 CLEANUP();
93 }
94
TEST(mvn_macro)95 TEST(mvn_macro) {
96 SETUP();
97
98 // Mvn uses the destination register as a scratch if it can. This only occurs
99 // when `operand.IsExtendedRegister()`.
100 COMPARE_MACRO(Mvn(x0, Operand(w1, SXTW)),
101 "sxtw x0, w1\n"
102 "mvn x0, x0");
103 COMPARE_MACRO(Mvn(x0, Operand(x0, SXTW)),
104 "sxtw x0, w0\n"
105 "mvn x0, x0");
106 }
107
108
TEST(move_immediate)109 TEST(move_immediate) {
110 SETUP();
111
112 COMPARE(movz(w0, 0x1234), "mov w0, #0x1234");
113 COMPARE(movz(x1, 0xabcd0000), "mov x1, #0xabcd0000");
114 COMPARE(movz(x2, 0x555500000000), "mov x2, #0x555500000000");
115 COMPARE(movz(x3, 0xaaaa000000000000), "mov x3, #0xaaaa000000000000");
116 COMPARE(movz(x4, 0xabcd, 16), "mov x4, #0xabcd0000");
117 COMPARE(movz(x5, 0x5555, 32), "mov x5, #0x555500000000");
118 COMPARE(movz(x6, 0xaaaa, 48), "mov x6, #0xaaaa000000000000");
119
120 COMPARE(movk(w7, 0x1234), "movk w7, #0x1234");
121 COMPARE(movk(x8, 0xabcd0000), "movk x8, #0xabcd, lsl #16");
122 COMPARE(movk(x9, 0x555500000000), "movk x9, #0x5555, lsl #32");
123 COMPARE(movk(x10, 0xaaaa000000000000), "movk x10, #0xaaaa, lsl #48");
124 COMPARE(movk(w11, 0xabcd, 16), "movk w11, #0xabcd, lsl #16");
125 COMPARE(movk(x12, 0x5555, 32), "movk x12, #0x5555, lsl #32");
126 COMPARE(movk(x13, 0xaaaa, 48), "movk x13, #0xaaaa, lsl #48");
127
128 COMPARE(movn(w14, 0x1234), "mov w14, #0xffffedcb");
129 COMPARE(movn(x15, 0xabcd0000), "mov x15, #0xffffffff5432ffff");
130 COMPARE(movn(x16, 0x555500000000), "mov x16, #0xffffaaaaffffffff");
131 COMPARE(movn(x17, 0xaaaa000000000000), "mov x17, #0x5555ffffffffffff");
132 COMPARE(movn(w18, 0xabcd, 16), "mov w18, #0x5432ffff");
133 COMPARE(movn(x19, 0x5555, 32), "mov x19, #0xffffaaaaffffffff");
134 COMPARE(movn(x20, 0xaaaa, 48), "mov x20, #0x5555ffffffffffff");
135
136 COMPARE(movk(w21, 0), "movk w21, #0x0");
137 COMPARE(movk(x22, 0, 0), "movk x22, #0x0");
138 COMPARE(movk(w23, 0, 16), "movk w23, #0x0, lsl #16");
139 COMPARE(movk(x24, 0, 32), "movk x24, #0x0, lsl #32");
140 COMPARE(movk(x25, 0, 48), "movk x25, #0x0, lsl #48");
141
142 COMPARE(movz(x26, 0, 48), "movz x26, #0x0");
143 COMPARE(movn(x27, 0, 48), "movn x27, #0x0");
144 COMPARE(movn(w28, 0xffff), "movn w28, #0xffff");
145
146 CLEANUP();
147 }
148
149
TEST(move_immediate_2)150 TEST(move_immediate_2) {
151 SETUP();
152
153 // Move instructions expected for certain immediates. This is really a macro
154 // assembler test, to ensure it generates immediates efficiently.
155 COMPARE_MACRO(Mov(w0, 0), "mov w0, #0x0");
156 COMPARE_MACRO(Mov(w0, 0x0000ffff), "mov w0, #0xffff");
157 COMPARE_MACRO(Mov(w0, 0x00010000), "mov w0, #0x10000");
158 COMPARE_MACRO(Mov(w0, 0xffff0000), "mov w0, #0xffff0000");
159 COMPARE_MACRO(Mov(w0, 0x0001ffff), "mov w0, #0x1ffff");
160 COMPARE_MACRO(Mov(w0, 0xffff8000), "mov w0, #0xffff8000");
161 COMPARE_MACRO(Mov(w0, 0xfffffffe), "mov w0, #0xfffffffe");
162 COMPARE_MACRO(Mov(w0, 0xffffffff), "mov w0, #0xffffffff");
163 COMPARE_MACRO(Mov(w0, 0x00ffff00), "mov w0, #0xffff00");
164 COMPARE_MACRO(Mov(w0, 0xfffe7fff), "mov w0, #0xfffe7fff");
165 COMPARE_MACRO(Mov(w0, 0xfffeffff), "mov w0, #0xfffeffff");
166 COMPARE_MACRO(Mov(w0, 0xffff7fff), "mov w0, #0xffff7fff");
167
168 COMPARE_MACRO(Mov(x0, 0), "mov x0, #0x0");
169 COMPARE_MACRO(Mov(x0, 0x0000ffff), "mov x0, #0xffff");
170 COMPARE_MACRO(Mov(x0, 0x00010000), "mov x0, #0x10000");
171 COMPARE_MACRO(Mov(x0, 0xffff0000), "mov x0, #0xffff0000");
172 COMPARE_MACRO(Mov(x0, 0x0001ffff), "mov x0, #0x1ffff");
173 COMPARE_MACRO(Mov(x0, 0xffff8000), "mov x0, #0xffff8000");
174 COMPARE_MACRO(Mov(x0, 0xfffffffe), "mov x0, #0xfffffffe");
175 COMPARE_MACRO(Mov(x0, 0xffffffff), "mov x0, #0xffffffff");
176 COMPARE_MACRO(Mov(x0, 0x00ffff00), "mov x0, #0xffff00");
177 COMPARE_MACRO(Mov(x0, 0xffff000000000000), "mov x0, #0xffff000000000000");
178 COMPARE_MACRO(Mov(x0, 0x0000ffff00000000), "mov x0, #0xffff00000000");
179 COMPARE_MACRO(Mov(x0, 0x00000000ffff0000), "mov x0, #0xffff0000");
180 COMPARE_MACRO(Mov(x0, 0xffffffffffff0000), "mov x0, #0xffffffffffff0000");
181 COMPARE_MACRO(Mov(x0, 0xffffffff0000ffff), "mov x0, #0xffffffff0000ffff");
182 COMPARE_MACRO(Mov(x0, 0xffff0000ffffffff), "mov x0, #0xffff0000ffffffff");
183 COMPARE_MACRO(Mov(x0, 0x0000ffffffffffff), "mov x0, #0xffffffffffff");
184 COMPARE_MACRO(Mov(x0, 0xfffe7fffffffffff), "mov x0, #0xfffe7fffffffffff");
185 COMPARE_MACRO(Mov(x0, 0xfffeffffffffffff), "mov x0, #0xfffeffffffffffff");
186 COMPARE_MACRO(Mov(x0, 0xffff7fffffffffff), "mov x0, #0xffff7fffffffffff");
187 COMPARE_MACRO(Mov(x0, 0xfffffffe7fffffff), "mov x0, #0xfffffffe7fffffff");
188 COMPARE_MACRO(Mov(x0, 0xfffffffeffffffff), "mov x0, #0xfffffffeffffffff");
189 COMPARE_MACRO(Mov(x0, 0xffffffff7fffffff), "mov x0, #0xffffffff7fffffff");
190 COMPARE_MACRO(Mov(x0, 0xfffffffffffe7fff), "mov x0, #0xfffffffffffe7fff");
191 COMPARE_MACRO(Mov(x0, 0xfffffffffffeffff), "mov x0, #0xfffffffffffeffff");
192 COMPARE_MACRO(Mov(x0, 0xffffffffffff7fff), "mov x0, #0xffffffffffff7fff");
193 COMPARE_MACRO(Mov(x0, 0xffffffffffffffff), "mov x0, #0xffffffffffffffff");
194
195 COMPARE_MACRO(Movk(w0, 0x1234, 0), "movk w0, #0x1234");
196 COMPARE_MACRO(Movk(x1, 0x2345, 0), "movk x1, #0x2345");
197 COMPARE_MACRO(Movk(w2, 0x3456, 16), "movk w2, #0x3456, lsl #16");
198 COMPARE_MACRO(Movk(x3, 0x4567, 16), "movk x3, #0x4567, lsl #16");
199 COMPARE_MACRO(Movk(x4, 0x5678, 32), "movk x4, #0x5678, lsl #32");
200 COMPARE_MACRO(Movk(x5, 0x6789, 48), "movk x5, #0x6789, lsl #48");
201
202 CLEANUP();
203 }
204
205
TEST(add_immediate)206 TEST(add_immediate) {
207 SETUP();
208
209 COMPARE(add(w0, w1, Operand(0xff)), "add w0, w1, #0xff (255)");
210 COMPARE(add(x2, x3, Operand(0x3ff)), "add x2, x3, #0x3ff (1023)");
211 COMPARE(add(w4, w5, Operand(0xfff)), "add w4, w5, #0xfff (4095)");
212 COMPARE(add(x6, x7, Operand(0x1000)), "add x6, x7, #0x1000 (4096)");
213 COMPARE(add(w8, w9, Operand(0xff000)), "add w8, w9, #0xff000 (1044480)");
214 COMPARE(add(x10, x11, Operand(0x3ff000)),
215 "add x10, x11, #0x3ff000 (4190208)");
216 COMPARE(add(w12, w13, Operand(0xfff000)),
217 "add w12, w13, #0xfff000 (16773120)");
218 COMPARE(adds(w14, w15, Operand(0xff)), "adds w14, w15, #0xff (255)");
219 COMPARE(adds(x16, x17, Operand(0xaa000)), "adds x16, x17, #0xaa000 (696320)");
220
221 COMPARE(cmn(w18, Operand(0xff)), "cmn w18, #0xff (255)");
222 COMPARE(cmn(x19, Operand(0xff000)), "cmn x19, #0xff000 (1044480)");
223 COMPARE(add(w0, wsp, Operand(0)), "mov w0, wsp");
224 COMPARE(add(sp, x0, Operand(0)), "mov sp, x0");
225
226 COMPARE(add(w1, wsp, Operand(8)), "add w1, wsp, #0x8 (8)");
227 COMPARE(add(x2, sp, Operand(16)), "add x2, sp, #0x10 (16)");
228 COMPARE(add(wsp, wsp, Operand(42)), "add wsp, wsp, #0x2a (42)");
229 COMPARE(cmn(sp, Operand(24)), "cmn sp, #0x18 (24)");
230 COMPARE(adds(wzr, wsp, Operand(9)), "cmn wsp, #0x9 (9)");
231
232 // Instructions in the add/sub immediate space, but unallocated due to shift
233 // value out of range.
234 COMPARE(dci(0x11800400), "unallocated (Unallocated)");
235 COMPARE(dci(0x11c00400), "unallocated (Unallocated)");
236
237 CLEANUP();
238 }
239
240
TEST(sub_immediate)241 TEST(sub_immediate) {
242 SETUP();
243
244 COMPARE(sub(w0, w1, Operand(0xff)), "sub w0, w1, #0xff (255)");
245 COMPARE(sub(x2, x3, Operand(0x3ff)), "sub x2, x3, #0x3ff (1023)");
246 COMPARE(sub(w4, w5, Operand(0xfff)), "sub w4, w5, #0xfff (4095)");
247 COMPARE(sub(x6, x7, Operand(0x1000)), "sub x6, x7, #0x1000 (4096)");
248 COMPARE(sub(w8, w9, Operand(0xff000)), "sub w8, w9, #0xff000 (1044480)");
249 COMPARE(sub(x10, x11, Operand(0x3ff000)),
250 "sub x10, x11, #0x3ff000 (4190208)");
251 COMPARE(sub(w12, w13, Operand(0xfff000)),
252 "sub w12, w13, #0xfff000 (16773120)");
253 COMPARE(subs(w14, w15, Operand(0xff)), "subs w14, w15, #0xff (255)");
254 COMPARE(subs(x16, x17, Operand(0xaa000)), "subs x16, x17, #0xaa000 (696320)");
255 COMPARE(cmp(w18, Operand(0xff)), "cmp w18, #0xff (255)");
256 COMPARE(cmp(x19, Operand(0xff000)), "cmp x19, #0xff000 (1044480)");
257
258 COMPARE(sub(w1, wsp, Operand(8)), "sub w1, wsp, #0x8 (8)");
259 COMPARE(sub(x2, sp, Operand(16)), "sub x2, sp, #0x10 (16)");
260 COMPARE(sub(wsp, wsp, Operand(42)), "sub wsp, wsp, #0x2a (42)");
261 COMPARE(cmp(sp, Operand(24)), "cmp sp, #0x18 (24)");
262 COMPARE(subs(wzr, wsp, Operand(9)), "cmp wsp, #0x9 (9)");
263
264 CLEANUP();
265 }
266
267
TEST(add_shifted)268 TEST(add_shifted) {
269 SETUP();
270
271 COMPARE(add(w0, w1, Operand(w2)), "add w0, w1, w2");
272 COMPARE(add(x3, x4, Operand(x5)), "add x3, x4, x5");
273 COMPARE(add(w6, w7, Operand(w8, LSL, 1)), "add w6, w7, w8, lsl #1");
274 COMPARE(add(x9, x10, Operand(x11, LSL, 2)), "add x9, x10, x11, lsl #2");
275 COMPARE(add(w12, w13, Operand(w14, LSR, 3)), "add w12, w13, w14, lsr #3");
276 COMPARE(add(x15, x16, Operand(x17, LSR, 4)), "add x15, x16, x17, lsr #4");
277 COMPARE(add(w18, w19, Operand(w20, ASR, 5)), "add w18, w19, w20, asr #5");
278 COMPARE(add(x21, x22, Operand(x23, ASR, 6)), "add x21, x22, x23, asr #6");
279 COMPARE(cmn(w24, Operand(w25)), "cmn w24, w25");
280 COMPARE(cmn(x26, Operand(x27, LSL, 63)), "cmn x26, x27, lsl #63");
281
282 COMPARE(add(x0, sp, Operand(x1)), "add x0, sp, x1");
283 COMPARE(add(w2, wsp, Operand(w3)), "add w2, wsp, w3");
284 COMPARE(add(x4, sp, Operand(x5, LSL, 1)), "add x4, sp, x5, lsl #1");
285 COMPARE(add(x4, xzr, Operand(x5, LSL, 1)), "add x4, xzr, x5, lsl #1");
286 COMPARE(add(w6, wsp, Operand(w7, LSL, 3)), "add w6, wsp, w7, lsl #3");
287 COMPARE(adds(xzr, sp, Operand(x8, LSL, 4)), "cmn sp, x8, lsl #4");
288 COMPARE(adds(xzr, xzr, Operand(x8, LSL, 5)), "cmn xzr, x8, lsl #5");
289
290 CLEANUP();
291 }
292
293
TEST(sub_shifted)294 TEST(sub_shifted) {
295 SETUP();
296
297 COMPARE(sub(w0, w1, Operand(w2)), "sub w0, w1, w2");
298 COMPARE(sub(x3, x4, Operand(x5)), "sub x3, x4, x5");
299 COMPARE(sub(w6, w7, Operand(w8, LSL, 1)), "sub w6, w7, w8, lsl #1");
300 COMPARE(sub(x9, x10, Operand(x11, LSL, 2)), "sub x9, x10, x11, lsl #2");
301 COMPARE(sub(w12, w13, Operand(w14, LSR, 3)), "sub w12, w13, w14, lsr #3");
302 COMPARE(sub(x15, x16, Operand(x17, LSR, 4)), "sub x15, x16, x17, lsr #4");
303 COMPARE(sub(w18, w19, Operand(w20, ASR, 5)), "sub w18, w19, w20, asr #5");
304 COMPARE(sub(x21, x22, Operand(x23, ASR, 6)), "sub x21, x22, x23, asr #6");
305 COMPARE(cmp(w24, Operand(w25)), "cmp w24, w25");
306 COMPARE(cmp(x26, Operand(x27, LSL, 63)), "cmp x26, x27, lsl #63");
307 COMPARE(neg(w28, Operand(w29)), "neg w28, w29");
308 COMPARE(neg(x30, Operand(x0, LSR, 62)), "neg x30, x0, lsr #62");
309 COMPARE(negs(w1, Operand(w2)), "negs w1, w2");
310 COMPARE(negs(x3, Operand(x4, ASR, 61)), "negs x3, x4, asr #61");
311
312 COMPARE(sub(x0, sp, Operand(x1)), "sub x0, sp, x1");
313 COMPARE(sub(w2, wsp, Operand(w3)), "sub w2, wsp, w3");
314 COMPARE(sub(x4, sp, Operand(x5, LSL, 1)), "sub x4, sp, x5, lsl #1");
315 COMPARE(sub(x4, xzr, Operand(x5, LSL, 1)), "neg x4, x5, lsl #1");
316 COMPARE(sub(w6, wsp, Operand(w7, LSL, 3)), "sub w6, wsp, w7, lsl #3");
317 COMPARE(subs(xzr, sp, Operand(x8, LSL, 4)), "cmp sp, x8, lsl #4");
318 COMPARE(subs(xzr, xzr, Operand(x8, LSL, 5)), "cmp xzr, x8, lsl #5");
319
320 CLEANUP();
321 }
322
323
TEST(add_extended)324 TEST(add_extended) {
325 SETUP();
326
327 COMPARE(add(w0, w1, Operand(w2, UXTB)), "add w0, w1, w2, uxtb");
328 COMPARE(adds(x3, x4, Operand(w5, UXTB, 1)), "adds x3, x4, w5, uxtb #1");
329 COMPARE(add(w6, w7, Operand(w8, UXTH, 2)), "add w6, w7, w8, uxth #2");
330 COMPARE(adds(x9, x10, Operand(x11, UXTW, 3)), "adds x9, x10, w11, uxtw #3");
331 COMPARE(add(x12, x13, Operand(x14, UXTX, 4)), "add x12, x13, x14, uxtx #4");
332 COMPARE(adds(w15, w16, Operand(w17, SXTB, 4)), "adds w15, w16, w17, sxtb #4");
333 COMPARE(add(x18, x19, Operand(x20, SXTB, 3)), "add x18, x19, w20, sxtb #3");
334 COMPARE(adds(w21, w22, Operand(w23, SXTH, 2)), "adds w21, w22, w23, sxth #2");
335 COMPARE(add(x24, x25, Operand(x26, SXTW, 1)), "add x24, x25, w26, sxtw #1");
336 COMPARE(adds(x27, x28, Operand(x29, SXTX)), "adds x27, x28, x29, sxtx");
337 COMPARE(cmn(w0, Operand(w1, UXTB, 2)), "cmn w0, w1, uxtb #2");
338 COMPARE(cmn(x2, Operand(x3, SXTH, 4)), "cmn x2, w3, sxth #4");
339
340 COMPARE(add(w0, wsp, Operand(w1, UXTB)), "add w0, wsp, w1, uxtb");
341 COMPARE(add(x2, sp, Operand(x3, UXTH, 1)), "add x2, sp, w3, uxth #1");
342 COMPARE(add(wsp, wsp, Operand(w4, UXTW, 2)), "add wsp, wsp, w4, lsl #2");
343 COMPARE(cmn(sp, Operand(xzr, UXTX, 3)), "cmn sp, xzr, lsl #3");
344 COMPARE(cmn(sp, Operand(xzr, LSL, 4)), "cmn sp, xzr, lsl #4");
345
346 CLEANUP();
347 }
348
349
TEST(sub_extended)350 TEST(sub_extended) {
351 SETUP();
352
353 COMPARE(sub(w0, w1, Operand(w2, UXTB)), "sub w0, w1, w2, uxtb");
354 COMPARE(subs(x3, x4, Operand(w5, UXTB, 1)), "subs x3, x4, w5, uxtb #1");
355 COMPARE(sub(w6, w7, Operand(w8, UXTH, 2)), "sub w6, w7, w8, uxth #2");
356 COMPARE(subs(x9, x10, Operand(x11, UXTW, 3)), "subs x9, x10, w11, uxtw #3");
357 COMPARE(sub(x12, x13, Operand(x14, UXTX, 4)), "sub x12, x13, x14, uxtx #4");
358 COMPARE(subs(w15, w16, Operand(w17, SXTB, 4)), "subs w15, w16, w17, sxtb #4");
359 COMPARE(sub(x18, x19, Operand(x20, SXTB, 3)), "sub x18, x19, w20, sxtb #3");
360 COMPARE(subs(w21, w22, Operand(w23, SXTH, 2)), "subs w21, w22, w23, sxth #2");
361 COMPARE(sub(x24, x25, Operand(x26, SXTW, 1)), "sub x24, x25, w26, sxtw #1");
362 COMPARE(subs(x27, x28, Operand(x29, SXTX)), "subs x27, x28, x29, sxtx");
363 COMPARE(cmp(w0, Operand(w1, SXTB, 1)), "cmp w0, w1, sxtb #1");
364 COMPARE(cmp(x2, Operand(x3, UXTH, 3)), "cmp x2, w3, uxth #3");
365
366 COMPARE(sub(w0, wsp, Operand(w1, UXTB)), "sub w0, wsp, w1, uxtb");
367 COMPARE(sub(x2, sp, Operand(x3, UXTH, 1)), "sub x2, sp, w3, uxth #1");
368 COMPARE(sub(wsp, wsp, Operand(w4, UXTW, 2)), "sub wsp, wsp, w4, lsl #2");
369 COMPARE(cmp(sp, Operand(xzr, UXTX, 3)), "cmp sp, xzr, lsl #3");
370 COMPARE(cmp(sp, Operand(xzr, LSL, 4)), "cmp sp, xzr, lsl #4");
371
372 CLEANUP();
373 }
374
375
TEST(adc_subc_ngc)376 TEST(adc_subc_ngc) {
377 SETUP();
378
379 COMPARE(adc(w0, w1, Operand(w2)), "adc w0, w1, w2");
380 COMPARE(adc(x3, x4, Operand(x5)), "adc x3, x4, x5");
381 COMPARE(adcs(w6, w7, Operand(w8)), "adcs w6, w7, w8");
382 COMPARE(adcs(x9, x10, Operand(x11)), "adcs x9, x10, x11");
383 COMPARE(sbc(w12, w13, Operand(w14)), "sbc w12, w13, w14");
384 COMPARE(sbc(x15, x16, Operand(x17)), "sbc x15, x16, x17");
385 COMPARE(sbcs(w18, w19, Operand(w20)), "sbcs w18, w19, w20");
386 COMPARE(sbcs(x21, x22, Operand(x23)), "sbcs x21, x22, x23");
387 COMPARE(ngc(w24, Operand(w25)), "ngc w24, w25");
388 COMPARE(ngc(x26, Operand(x27)), "ngc x26, x27");
389 COMPARE(ngcs(w28, Operand(w29)), "ngcs w28, w29");
390 COMPARE(ngcs(x30, Operand(x0)), "ngcs x30, x0");
391
392 CLEANUP();
393 }
394
395
TEST(rmif)396 TEST(rmif) {
397 SETUP();
398
399 COMPARE(rmif(x0, 3, ZCVFlag), "rmif x0, #3, #nZCV");
400 COMPARE(rmif(x1, 63, NCFlag), "rmif x1, #63, #NzCv");
401
402 CLEANUP();
403 }
404
405
TEST(setf8_setf16)406 TEST(setf8_setf16) {
407 SETUP();
408
409 COMPARE(setf8(w0), "setf8 w0");
410 COMPARE(setf16(w1), "setf16 w1");
411
412 CLEANUP();
413 }
414
415
TEST(mul_and_div)416 TEST(mul_and_div) {
417 SETUP();
418
419 COMPARE(mul(w0, w1, w2), "mul w0, w1, w2");
420 COMPARE(mul(x3, x4, x5), "mul x3, x4, x5");
421 COMPARE(mul(w30, w0, w1), "mul w30, w0, w1");
422 COMPARE(mul(x30, x0, x1), "mul x30, x0, x1");
423 COMPARE(mneg(w0, w1, w2), "mneg w0, w1, w2");
424 COMPARE(mneg(x3, x4, x5), "mneg x3, x4, x5");
425 COMPARE(mneg(w30, w0, w1), "mneg w30, w0, w1");
426 COMPARE(mneg(x30, x0, x1), "mneg x30, x0, x1");
427 COMPARE(smull(x0, w0, w1), "smull x0, w0, w1");
428 COMPARE(smull(x30, w30, w0), "smull x30, w30, w0");
429 COMPARE(smulh(x0, x1, x2), "smulh x0, x1, x2");
430 COMPARE(umulh(x0, x2, x1), "umulh x0, x2, x1");
431
432 COMPARE(sdiv(w0, w1, w2), "sdiv w0, w1, w2");
433 COMPARE(sdiv(x3, x4, x5), "sdiv x3, x4, x5");
434 COMPARE(udiv(w6, w7, w8), "udiv w6, w7, w8");
435 COMPARE(udiv(x9, x10, x11), "udiv x9, x10, x11");
436
437 CLEANUP();
438 }
439
440
TEST(madd)441 TEST(madd) {
442 SETUP();
443
444 COMPARE(madd(w0, w1, w2, w3), "madd w0, w1, w2, w3");
445 COMPARE(madd(w30, w21, w22, w16), "madd w30, w21, w22, w16");
446 COMPARE(madd(x0, x1, x2, x3), "madd x0, x1, x2, x3");
447 COMPARE(madd(x30, x21, x22, x16), "madd x30, x21, x22, x16");
448
449 COMPARE(smaddl(x0, w1, w2, x3), "smaddl x0, w1, w2, x3");
450 COMPARE(smaddl(x30, w21, w22, x16), "smaddl x30, w21, w22, x16");
451 COMPARE(umaddl(x0, w1, w2, x3), "umaddl x0, w1, w2, x3");
452 COMPARE(umaddl(x30, w21, w22, x16), "umaddl x30, w21, w22, x16");
453 COMPARE(umull(x0, w1, w2), "umull x0, w1, w2");
454 COMPARE(umull(x30, w21, w22), "umull x30, w21, w22");
455
456 CLEANUP();
457 }
458
459
TEST(msub)460 TEST(msub) {
461 SETUP();
462
463 COMPARE(msub(w0, w1, w2, w3), "msub w0, w1, w2, w3");
464 COMPARE(msub(w30, w21, w22, w16), "msub w30, w21, w22, w16");
465 COMPARE(msub(x0, x1, x2, x3), "msub x0, x1, x2, x3");
466 COMPARE(msub(x30, x21, x22, x16), "msub x30, x21, x22, x16");
467
468 COMPARE(smsubl(x0, w1, w2, x3), "smsubl x0, w1, w2, x3");
469 COMPARE(smsubl(x30, w21, w22, x16), "smsubl x30, w21, w22, x16");
470 COMPARE(umsubl(x0, w1, w2, x3), "umsubl x0, w1, w2, x3");
471 COMPARE(umsubl(x30, w21, w22, x16), "umsubl x30, w21, w22, x16");
472
473 CLEANUP();
474 }
475
476
TEST(dp_1_source)477 TEST(dp_1_source) {
478 SETUP();
479
480 COMPARE(rbit(w0, w1), "rbit w0, w1");
481 COMPARE(rbit(x2, x3), "rbit x2, x3");
482 COMPARE(rev16(w4, w5), "rev16 w4, w5");
483 COMPARE(rev16(x6, x7), "rev16 x6, x7");
484 COMPARE(rev32(x8, x9), "rev32 x8, x9");
485 COMPARE(rev64(x10, x11), "rev x10, x11");
486 COMPARE(rev(w12, w13), "rev w12, w13");
487 COMPARE(rev(x14, x15), "rev x14, x15");
488 COMPARE(clz(w16, w17), "clz w16, w17");
489 COMPARE(clz(x18, x19), "clz x18, x19");
490 COMPARE(cls(w20, w21), "cls w20, w21");
491 COMPARE(cls(x22, x23), "cls x22, x23");
492 COMPARE(pacia(x24, x25), "pacia x24, x25");
493 COMPARE(pacia(x26, sp), "pacia x26, sp");
494 COMPARE(pacib(x27, x28), "pacib x27, x28");
495 COMPARE(pacib(x29, sp), "pacib x29, sp");
496 COMPARE(pacda(x30, x0), "pacda x30, x0");
497 COMPARE(pacda(x1, sp), "pacda x1, sp");
498 COMPARE(pacdb(x2, x3), "pacdb x2, x3");
499 COMPARE(pacdb(x4, sp), "pacdb x4, sp");
500 COMPARE(paciza(x5), "paciza x5");
501 COMPARE(pacizb(x6), "pacizb x6");
502 COMPARE(pacdza(x7), "pacdza x7");
503 COMPARE(pacdzb(x8), "pacdzb x8");
504 COMPARE(autia(x9, x10), "autia x9, x10");
505 COMPARE(autia(x11, sp), "autia x11, sp");
506 COMPARE(autib(x12, x13), "autib x12, x13");
507 COMPARE(autib(x14, sp), "autib x14, sp");
508 COMPARE(autda(x15, x16), "autda x15, x16");
509 COMPARE(autda(x17, sp), "autda x17, sp");
510 COMPARE(autdb(x18, x19), "autdb x18, x19");
511 COMPARE(autdb(x20, sp), "autdb x20, sp");
512 COMPARE(autiza(x21), "autiza x21");
513 COMPARE(autizb(x22), "autizb x22");
514 COMPARE(autdza(x23), "autdza x23");
515
516 CLEANUP();
517 }
518
519
TEST(bitfield)520 TEST(bitfield) {
521 SETUP();
522
523 COMPARE(sxtb(w0, w1), "sxtb w0, w1");
524 COMPARE(sxtb(x2, x3), "sxtb x2, w3");
525 COMPARE(sxth(w4, w5), "sxth w4, w5");
526 COMPARE(sxth(x6, x7), "sxth x6, w7");
527 COMPARE(sxtw(x8, x9), "sxtw x8, w9");
528 COMPARE(sxtb(x0, w1), "sxtb x0, w1");
529 COMPARE(sxth(x2, w3), "sxth x2, w3");
530 COMPARE(sxtw(x4, w5), "sxtw x4, w5");
531
532 COMPARE(uxtb(w10, w11), "uxtb w10, w11");
533 COMPARE(uxtb(x12, x13), "uxtb x12, w13");
534 COMPARE(uxth(w14, w15), "uxth w14, w15");
535 COMPARE(uxth(x16, x17), "uxth x16, w17");
536 COMPARE(uxtw(x18, x19), "ubfx x18, x19, #0, #32");
537
538 COMPARE(asr(w20, w21, 10), "asr w20, w21, #10");
539 COMPARE(asr(x22, x23, 20), "asr x22, x23, #20");
540 COMPARE(lsr(w24, w25, 10), "lsr w24, w25, #10");
541 COMPARE(lsr(x26, x27, 20), "lsr x26, x27, #20");
542 COMPARE(lsl(w28, w29, 10), "lsl w28, w29, #10");
543 COMPARE(lsl(x30, x0, 20), "lsl x30, x0, #20");
544
545 COMPARE(sbfiz(w1, w2, 1, 20), "sbfiz w1, w2, #1, #20");
546 COMPARE(sbfiz(x3, x4, 2, 19), "sbfiz x3, x4, #2, #19");
547 COMPARE(sbfx(w5, w6, 3, 18), "sbfx w5, w6, #3, #18");
548 COMPARE(sbfx(x7, x8, 4, 17), "sbfx x7, x8, #4, #17");
549 COMPARE(bfi(w9, w10, 5, 16), "bfi w9, w10, #5, #16");
550 COMPARE(bfi(x11, x12, 6, 15), "bfi x11, x12, #6, #15");
551 COMPARE(bfxil(w13, w14, 7, 14), "bfxil w13, w14, #7, #14");
552 COMPARE(bfxil(x15, x16, 8, 13), "bfxil x15, x16, #8, #13");
553 COMPARE(ubfiz(w17, w18, 9, 12), "ubfiz w17, w18, #9, #12");
554 COMPARE(ubfiz(x19, x20, 10, 11), "ubfiz x19, x20, #10, #11");
555 COMPARE(ubfx(w21, w22, 11, 10), "ubfx w21, w22, #11, #10");
556 COMPARE(ubfx(x23, x24, 12, 9), "ubfx x23, x24, #12, #9");
557 COMPARE(bfc(w25, 13, 8), "bfc w25, #13, #8");
558 COMPARE(bfc(x26, 14, 7), "bfc x26, #14, #7");
559
560 CLEANUP();
561 }
562
563
TEST(crc32b)564 TEST(crc32b) {
565 SETUP();
566
567 COMPARE(crc32b(w0, w1, w2), "crc32b w0, w1, w2");
568 COMPARE(crc32b(w0, w11, w22), "crc32b w0, w11, w22");
569 COMPARE(crc32b(w10, w20, w30), "crc32b w10, w20, w30");
570
571 CLEANUP();
572 }
573
574
TEST(crc32h)575 TEST(crc32h) {
576 SETUP();
577
578 COMPARE(crc32h(w1, w2, w3), "crc32h w1, w2, w3");
579 COMPARE(crc32h(w2, w13, w23), "crc32h w2, w13, w23");
580 COMPARE(crc32h(w11, w12, w15), "crc32h w11, w12, w15");
581
582 CLEANUP();
583 }
584
585
TEST(crc32w)586 TEST(crc32w) {
587 SETUP();
588
589 COMPARE(crc32w(w2, w3, w4), "crc32w w2, w3, w4");
590 COMPARE(crc32w(w3, w14, w24), "crc32w w3, w14, w24");
591 COMPARE(crc32w(w13, w13, w16), "crc32w w13, w13, w16");
592
593 CLEANUP();
594 }
595
596
TEST(crc32x)597 TEST(crc32x) {
598 SETUP();
599
600 COMPARE(crc32x(w3, w4, x5), "crc32x w3, w4, x5");
601 COMPARE(crc32x(w4, w15, x25), "crc32x w4, w15, x25");
602 COMPARE(crc32x(w14, w14, x30), "crc32x w14, w14, x30");
603
604 CLEANUP();
605 }
606
607
TEST(crc32cb)608 TEST(crc32cb) {
609 SETUP();
610
611 COMPARE(crc32cb(w4, w5, w6), "crc32cb w4, w5, w6");
612 COMPARE(crc32cb(w5, w16, w26), "crc32cb w5, w16, w26");
613 COMPARE(crc32cb(w15, w15, w5), "crc32cb w15, w15, w5");
614
615 CLEANUP();
616 }
617
618
TEST(crc32ch)619 TEST(crc32ch) {
620 SETUP();
621
622 COMPARE(crc32ch(w5, w6, w7), "crc32ch w5, w6, w7");
623 COMPARE(crc32ch(w6, w17, w27), "crc32ch w6, w17, w27");
624 COMPARE(crc32ch(w16, w16, w2), "crc32ch w16, w16, w2");
625
626 CLEANUP();
627 }
628
629
TEST(crc32cw)630 TEST(crc32cw) {
631 SETUP();
632
633 COMPARE(crc32cw(w6, w7, w8), "crc32cw w6, w7, w8");
634 COMPARE(crc32cw(w7, w18, w28), "crc32cw w7, w18, w28");
635 COMPARE(crc32cw(w17, w17, w3), "crc32cw w17, w17, w3");
636
637 CLEANUP();
638 }
639
640
TEST(crc32cx)641 TEST(crc32cx) {
642 SETUP();
643
644 COMPARE(crc32cx(w7, w8, x9), "crc32cx w7, w8, x9");
645 COMPARE(crc32cx(w8, w19, x29), "crc32cx w8, w19, x29");
646 COMPARE(crc32cx(w18, w18, x4), "crc32cx w18, w18, x4");
647
648 CLEANUP();
649 }
650
651
TEST(extract)652 TEST(extract) {
653 SETUP();
654
655 COMPARE(extr(w0, w1, w2, 0), "extr w0, w1, w2, #0");
656 COMPARE(extr(x3, x4, x5, 1), "extr x3, x4, x5, #1");
657 COMPARE(extr(w6, w7, w8, 31), "extr w6, w7, w8, #31");
658 COMPARE(extr(x9, x10, x11, 63), "extr x9, x10, x11, #63");
659 COMPARE(extr(w12, w13, w13, 10), "ror w12, w13, #10");
660 COMPARE(extr(x14, x15, x15, 42), "ror x14, x15, #42");
661
662 CLEANUP();
663 }
664
665
TEST(logical_immediate)666 TEST(logical_immediate) {
667 SETUP();
668 #define RESULT_SIZE (256)
669
670 char result[RESULT_SIZE];
671
672 // Test immediate encoding - 64-bit destination.
673 // 64-bit patterns.
674 uint64_t value = 0x7fffffff;
675 for (int i = 0; i < 64; i++) {
676 snprintf(result, RESULT_SIZE, "and x0, x0, #0x%" PRIx64, value);
677 COMPARE(and_(x0, x0, Operand(value)), result);
678 value = ((value & 1) << 63) | (value >> 1); // Rotate right 1 bit.
679 }
680
681 // 32-bit patterns.
682 value = 0x00003fff00003fff;
683 for (int i = 0; i < 32; i++) {
684 snprintf(result, RESULT_SIZE, "and x0, x0, #0x%" PRIx64, value);
685 COMPARE(and_(x0, x0, Operand(value)), result);
686 value = ((value & 1) << 63) | (value >> 1); // Rotate right 1 bit.
687 }
688
689 // 16-bit patterns.
690 value = 0x001f001f001f001f;
691 for (int i = 0; i < 16; i++) {
692 snprintf(result, RESULT_SIZE, "and x0, x0, #0x%" PRIx64, value);
693 COMPARE(and_(x0, x0, Operand(value)), result);
694 value = ((value & 1) << 63) | (value >> 1); // Rotate right 1 bit.
695 }
696
697 // 8-bit patterns.
698 value = 0x0e0e0e0e0e0e0e0e;
699 for (int i = 0; i < 8; i++) {
700 snprintf(result, RESULT_SIZE, "and x0, x0, #0x%" PRIx64, value);
701 COMPARE(and_(x0, x0, Operand(value)), result);
702 value = ((value & 1) << 63) | (value >> 1); // Rotate right 1 bit.
703 }
704
705 // 4-bit patterns.
706 value = 0x6666666666666666;
707 for (int i = 0; i < 4; i++) {
708 snprintf(result, RESULT_SIZE, "and x0, x0, #0x%" PRIx64, value);
709 COMPARE(and_(x0, x0, Operand(value)), result);
710 value = ((value & 1) << 63) | (value >> 1); // Rotate right 1 bit.
711 }
712
713 // 2-bit patterns.
714 COMPARE(and_(x0, x0, Operand(0x5555555555555555)),
715 "and x0, x0, #0x5555555555555555");
716 COMPARE(and_(x0, x0, Operand(0xaaaaaaaaaaaaaaaa)),
717 "and x0, x0, #0xaaaaaaaaaaaaaaaa");
718
719 // Test immediate encoding - 32-bit destination.
720 COMPARE(and_(w0, w0, Operand(0xff8007ff)),
721 "and w0, w0, #0xff8007ff"); // 32-bit pattern.
722 COMPARE(and_(w0, w0, Operand(0xf87ff87f)),
723 "and w0, w0, #0xf87ff87f"); // 16-bit pattern.
724 COMPARE(and_(w0, w0, Operand(0x87878787)),
725 "and w0, w0, #0x87878787"); // 8-bit pattern.
726 COMPARE(and_(w0, w0, Operand(0x66666666)),
727 "and w0, w0, #0x66666666"); // 4-bit pattern.
728 COMPARE(and_(w0, w0, Operand(0x55555555)),
729 "and w0, w0, #0x55555555"); // 2-bit pattern.
730
731 // Test other instructions.
732 COMPARE(tst(w1, Operand(0x11111111)), "tst w1, #0x11111111");
733 COMPARE(tst(x2, Operand(0x8888888888888888)), "tst x2, #0x8888888888888888");
734 COMPARE(orr(w7, w8, Operand(0xaaaaaaaa)), "orr w7, w8, #0xaaaaaaaa");
735 COMPARE(orr(x9, x10, Operand(0x5555555555555555)),
736 "orr x9, x10, #0x5555555555555555");
737 COMPARE(eor(w15, w16, Operand(0x00000001)), "eor w15, w16, #0x1");
738 COMPARE(eor(x17, x18, Operand(0x0000000000000003)), "eor x17, x18, #0x3");
739 COMPARE(ands(w23, w24, Operand(0x0000000f)), "ands w23, w24, #0xf");
740 COMPARE(ands(x25, x26, Operand(0x800000000000000f)),
741 "ands x25, x26, #0x800000000000000f");
742
743 // Test inverse.
744 COMPARE(bic(w3, w4, Operand(0x20202020)), "and w3, w4, #0xdfdfdfdf");
745 COMPARE(bic(x5, x6, Operand(0x4040404040404040)),
746 "and x5, x6, #0xbfbfbfbfbfbfbfbf");
747 COMPARE(orn(w11, w12, Operand(0x40004000)), "orr w11, w12, #0xbfffbfff");
748 COMPARE(orn(x13, x14, Operand(0x8181818181818181)),
749 "orr x13, x14, #0x7e7e7e7e7e7e7e7e");
750 COMPARE(eon(w19, w20, Operand(0x80000001)), "eor w19, w20, #0x7ffffffe");
751 COMPARE(eon(x21, x22, Operand(0xc000000000000003)),
752 "eor x21, x22, #0x3ffffffffffffffc");
753 COMPARE(bics(w27, w28, Operand(0xfffffff7)), "ands w27, w28, #0x8");
754 COMPARE(bics(x29, x0, Operand(0xfffffffeffffffff)),
755 "ands x29, x0, #0x100000000");
756
757 // Test stack pointer.
758 COMPARE(and_(wsp, wzr, Operand(7)), "and wsp, wzr, #0x7");
759 COMPARE(ands(xzr, xzr, Operand(7)), "tst xzr, #0x7");
760 COMPARE(orr(sp, xzr, Operand(15)), "orr sp, xzr, #0xf");
761 COMPARE(eor(wsp, w0, Operand(31)), "eor wsp, w0, #0x1f");
762
763 // Test move aliases.
764 COMPARE(orr(w0, wzr, Operand(0x00000780)), "orr w0, wzr, #0x780");
765 COMPARE(orr(w1, wzr, Operand(0x00007800)), "orr w1, wzr, #0x7800");
766 COMPARE(orr(w2, wzr, Operand(0x00078000)), "mov w2, #0x78000");
767 COMPARE(orr(w3, wzr, Operand(0x00780000)), "orr w3, wzr, #0x780000");
768 COMPARE(orr(w4, wzr, Operand(0x07800000)), "orr w4, wzr, #0x7800000");
769 COMPARE(orr(x5, xzr, Operand(0xffffffffffffc001)),
770 "orr x5, xzr, #0xffffffffffffc001");
771 COMPARE(orr(x6, xzr, Operand(0xfffffffffffc001f)),
772 "mov x6, #0xfffffffffffc001f");
773 COMPARE(orr(x7, xzr, Operand(0xffffffffffc001ff)),
774 "mov x7, #0xffffffffffc001ff");
775 COMPARE(orr(x8, xzr, Operand(0xfffffffffc001fff)),
776 "mov x8, #0xfffffffffc001fff");
777 COMPARE(orr(x9, xzr, Operand(0xffffffffc001ffff)),
778 "orr x9, xzr, #0xffffffffc001ffff");
779
780 CLEANUP();
781 }
782
783
TEST(logical_shifted)784 TEST(logical_shifted) {
785 SETUP();
786
787 COMPARE(and_(w0, w1, Operand(w2)), "and w0, w1, w2");
788 COMPARE(and_(x3, x4, Operand(x5, LSL, 1)), "and x3, x4, x5, lsl #1");
789 COMPARE(and_(w6, w7, Operand(w8, LSR, 2)), "and w6, w7, w8, lsr #2");
790 COMPARE(and_(x9, x10, Operand(x11, ASR, 3)), "and x9, x10, x11, asr #3");
791 COMPARE(and_(w12, w13, Operand(w14, ROR, 4)), "and w12, w13, w14, ror #4");
792
793 COMPARE(bic(w15, w16, Operand(w17)), "bic w15, w16, w17");
794 COMPARE(bic(x18, x19, Operand(x20, LSL, 5)), "bic x18, x19, x20, lsl #5");
795 COMPARE(bic(w21, w22, Operand(w23, LSR, 6)), "bic w21, w22, w23, lsr #6");
796 COMPARE(bic(x24, x25, Operand(x26, ASR, 7)), "bic x24, x25, x26, asr #7");
797 COMPARE(bic(w27, w28, Operand(w29, ROR, 8)), "bic w27, w28, w29, ror #8");
798
799 COMPARE(orr(w0, w1, Operand(w2)), "orr w0, w1, w2");
800 COMPARE(orr(x3, x4, Operand(x5, LSL, 9)), "orr x3, x4, x5, lsl #9");
801 COMPARE(orr(w6, w7, Operand(w8, LSR, 10)), "orr w6, w7, w8, lsr #10");
802 COMPARE(orr(x9, x10, Operand(x11, ASR, 11)), "orr x9, x10, x11, asr #11");
803 COMPARE(orr(w12, w13, Operand(w14, ROR, 12)), "orr w12, w13, w14, ror #12");
804
805 COMPARE(orn(w15, w16, Operand(w17)), "orn w15, w16, w17");
806 COMPARE(orn(x18, x19, Operand(x20, LSL, 13)), "orn x18, x19, x20, lsl #13");
807 COMPARE(orn(w21, w22, Operand(w23, LSR, 14)), "orn w21, w22, w23, lsr #14");
808 COMPARE(orn(x24, x25, Operand(x26, ASR, 15)), "orn x24, x25, x26, asr #15");
809 COMPARE(orn(w27, w28, Operand(w29, ROR, 16)), "orn w27, w28, w29, ror #16");
810
811 COMPARE(eor(w0, w1, Operand(w2)), "eor w0, w1, w2");
812 COMPARE(eor(x3, x4, Operand(x5, LSL, 17)), "eor x3, x4, x5, lsl #17");
813 COMPARE(eor(w6, w7, Operand(w8, LSR, 18)), "eor w6, w7, w8, lsr #18");
814 COMPARE(eor(x9, x10, Operand(x11, ASR, 19)), "eor x9, x10, x11, asr #19");
815 COMPARE(eor(w12, w13, Operand(w14, ROR, 20)), "eor w12, w13, w14, ror #20");
816
817 COMPARE(eon(w15, w16, Operand(w17)), "eon w15, w16, w17");
818 COMPARE(eon(x18, x19, Operand(x20, LSL, 21)), "eon x18, x19, x20, lsl #21");
819 COMPARE(eon(w21, w22, Operand(w23, LSR, 22)), "eon w21, w22, w23, lsr #22");
820 COMPARE(eon(x24, x25, Operand(x26, ASR, 23)), "eon x24, x25, x26, asr #23");
821 COMPARE(eon(w27, w28, Operand(w29, ROR, 24)), "eon w27, w28, w29, ror #24");
822
823 COMPARE(ands(w0, w1, Operand(w2)), "ands w0, w1, w2");
824 COMPARE(ands(x3, x4, Operand(x5, LSL, 1)), "ands x3, x4, x5, lsl #1");
825 COMPARE(ands(w6, w7, Operand(w8, LSR, 2)), "ands w6, w7, w8, lsr #2");
826 COMPARE(ands(x9, x10, Operand(x11, ASR, 3)), "ands x9, x10, x11, asr #3");
827 COMPARE(ands(w12, w13, Operand(w14, ROR, 4)), "ands w12, w13, w14, ror #4");
828
829 COMPARE(bics(w15, w16, Operand(w17)), "bics w15, w16, w17");
830 COMPARE(bics(x18, x19, Operand(x20, LSL, 5)), "bics x18, x19, x20, lsl #5");
831 COMPARE(bics(w21, w22, Operand(w23, LSR, 6)), "bics w21, w22, w23, lsr #6");
832 COMPARE(bics(x24, x25, Operand(x26, ASR, 7)), "bics x24, x25, x26, asr #7");
833 COMPARE(bics(w27, w28, Operand(w29, ROR, 8)), "bics w27, w28, w29, ror #8");
834
835 COMPARE(tst(w0, Operand(w1)), "tst w0, w1");
836 COMPARE(tst(w2, Operand(w3, ROR, 10)), "tst w2, w3, ror #10");
837 COMPARE(tst(x0, Operand(x1)), "tst x0, x1");
838 COMPARE(tst(x2, Operand(x3, ROR, 42)), "tst x2, x3, ror #42");
839
840 COMPARE(orn(w0, wzr, Operand(w1)), "mvn w0, w1");
841 COMPARE(orn(w2, wzr, Operand(w3, ASR, 5)), "mvn w2, w3, asr #5");
842 COMPARE(orn(x0, xzr, Operand(x1)), "mvn x0, x1");
843 COMPARE(orn(x2, xzr, Operand(x3, ASR, 42)), "mvn x2, x3, asr #42");
844
845 COMPARE(orr(w0, wzr, Operand(w1)), "mov w0, w1");
846 COMPARE(orr(x0, xzr, Operand(x1)), "mov x0, x1");
847 COMPARE(orr(w16, wzr, Operand(w17, LSL, 1)), "orr w16, wzr, w17, lsl #1");
848 COMPARE(orr(x16, xzr, Operand(x17, ASR, 2)), "orr x16, xzr, x17, asr #2");
849
850 CLEANUP();
851 }
852
853
TEST(dp_2_source)854 TEST(dp_2_source) {
855 SETUP();
856
857 COMPARE(lslv(w0, w1, w2), "lsl w0, w1, w2");
858 COMPARE(lslv(x3, x4, x5), "lsl x3, x4, x5");
859 COMPARE(lsrv(w6, w7, w8), "lsr w6, w7, w8");
860 COMPARE(lsrv(x9, x10, x11), "lsr x9, x10, x11");
861 COMPARE(asrv(w12, w13, w14), "asr w12, w13, w14");
862 COMPARE(asrv(x15, x16, x17), "asr x15, x16, x17");
863 COMPARE(rorv(w18, w19, w20), "ror w18, w19, w20");
864 COMPARE(rorv(x21, x22, x23), "ror x21, x22, x23");
865 COMPARE(pacga(x24, x25, x26), "pacga x24, x25, x26");
866 COMPARE(pacga(x27, x28, sp), "pacga x27, x28, sp");
867
868 CLEANUP();
869 }
870
871
TEST(adr)872 TEST(adr) {
873 SETUP();
874
875 COMPARE_PREFIX(adr(x0, INT64_C(0)), "adr x0, #+0x0");
876 COMPARE_PREFIX(adr(x1, 1), "adr x1, #+0x1");
877 COMPARE_PREFIX(adr(x2, -1), "adr x2, #-0x1");
878 COMPARE_PREFIX(adr(x3, 4), "adr x3, #+0x4");
879 COMPARE_PREFIX(adr(x4, -4), "adr x4, #-0x4");
880 COMPARE_PREFIX(adr(x5, 0x000fffff), "adr x5, #+0xfffff");
881 COMPARE_PREFIX(adr(x6, -0x00100000), "adr x6, #-0x100000");
882 COMPARE_PREFIX(adr(xzr, INT64_C(0)), "adr xzr, #+0x0");
883
884 CLEANUP();
885 }
886
887
TEST(adrp)888 TEST(adrp) {
889 SETUP();
890
891 COMPARE_PREFIX(adrp(x0, INT64_C(0)), "adrp x0, #+0x0");
892 COMPARE_PREFIX(adrp(x1, 1), "adrp x1, #+0x1000");
893 COMPARE_PREFIX(adrp(x2, -1), "adrp x2, #-0x1000");
894 COMPARE_PREFIX(adrp(x3, 4), "adrp x3, #+0x4000");
895 COMPARE_PREFIX(adrp(x4, -4), "adrp x4, #-0x4000");
896 COMPARE_PREFIX(adrp(x5, 0x000fffff), "adrp x5, #+0xfffff000");
897 COMPARE_PREFIX(adrp(x6, -0x00100000), "adrp x6, #-0x100000000");
898 COMPARE_PREFIX(adrp(xzr, INT64_C(0)), "adrp xzr, #+0x0");
899
900 CLEANUP();
901 }
902
903
TEST(branch)904 TEST(branch) {
905 SETUP();
906
907 #define INST_OFF(x) (INT64_C(x) >> kInstructionSizeLog2)
908 COMPARE_PREFIX(b(INST_OFF(0x4)), "b #+0x4");
909 COMPARE_PREFIX(b(INST_OFF(-0x4)), "b #-0x4");
910 COMPARE_PREFIX(b(INST_OFF(0x7fffffc)), "b #+0x7fffffc");
911 COMPARE_PREFIX(b(INST_OFF(-0x8000000)), "b #-0x8000000");
912 COMPARE_PREFIX(b(INST_OFF(0xffffc), eq), "b.eq #+0xffffc");
913 COMPARE_PREFIX(b(INST_OFF(-0x100000), mi), "b.mi #-0x100000");
914 COMPARE_PREFIX(b(INST_OFF(0xffffc), al), "b.al #+0xffffc");
915 COMPARE_PREFIX(b(INST_OFF(-0x100000), nv), "b.nv #-0x100000");
916 COMPARE_PREFIX(bl(INST_OFF(0x4)), "bl #+0x4");
917 COMPARE_PREFIX(bl(INST_OFF(-0x4)), "bl #-0x4");
918 COMPARE_PREFIX(bl(INST_OFF(0xffffc)), "bl #+0xffffc");
919 COMPARE_PREFIX(bl(INST_OFF(-0x100000)), "bl #-0x100000");
920 COMPARE_PREFIX(cbz(w0, INST_OFF(0xffffc)), "cbz w0, #+0xffffc");
921 COMPARE_PREFIX(cbz(x1, INST_OFF(-0x100000)), "cbz x1, #-0x100000");
922 COMPARE_PREFIX(cbnz(w2, INST_OFF(0xffffc)), "cbnz w2, #+0xffffc");
923 COMPARE_PREFIX(cbnz(x3, INST_OFF(-0x100000)), "cbnz x3, #-0x100000");
924 COMPARE_PREFIX(tbz(w4, 0, INST_OFF(0x7ffc)), "tbz w4, #0, #+0x7ffc");
925 COMPARE_PREFIX(tbz(x5, 63, INST_OFF(-0x8000)), "tbz x5, #63, #-0x8000");
926 COMPARE_PREFIX(tbz(w6, 31, INST_OFF(0)), "tbz w6, #31, #+0x0");
927 COMPARE_PREFIX(tbz(x7, 31, INST_OFF(0x4)), "tbz w7, #31, #+0x4");
928 COMPARE_PREFIX(tbz(x8, 32, INST_OFF(0x8)), "tbz x8, #32, #+0x8");
929 COMPARE_PREFIX(tbnz(w8, 0, INST_OFF(0x7ffc)), "tbnz w8, #0, #+0x7ffc");
930 COMPARE_PREFIX(tbnz(x9, 63, INST_OFF(-0x8000)), "tbnz x9, #63, #-0x8000");
931 COMPARE_PREFIX(tbnz(w10, 31, INST_OFF(0)), "tbnz w10, #31, #+0x0");
932 COMPARE_PREFIX(tbnz(x11, 31, INST_OFF(0x4)), "tbnz w11, #31, #+0x4");
933 COMPARE_PREFIX(tbnz(x12, 32, INST_OFF(0x8)), "tbnz x12, #32, #+0x8");
934 COMPARE(br(x0), "br x0");
935 COMPARE(blr(x1), "blr x1");
936 COMPARE(ret(x2), "ret x2");
937 COMPARE(ret(lr), "ret");
938
939 COMPARE(braaz(x0), "braaz x0");
940 COMPARE(brabz(x1), "brabz x1");
941 COMPARE(blraaz(x2), "blraaz x2");
942 COMPARE(blrabz(x3), "blrabz x3");
943 COMPARE(retaa(), "retaa");
944 COMPARE(retab(), "retab");
945 COMPARE(braa(x4, x5), "braa x4, x5");
946 COMPARE(braa(x6, sp), "braa x6, sp");
947 COMPARE(brab(x7, x8), "brab x7, x8");
948 COMPARE(brab(x9, sp), "brab x9, sp");
949 COMPARE(blraa(x10, x11), "blraa x10, x11");
950 COMPARE(blraa(x12, sp), "blraa x12, sp");
951 COMPARE(blrab(x13, x14), "blrab x13, x14");
952 COMPARE(blrab(x15, sp), "blrab x15, sp");
953
954 CLEANUP();
955 }
956
957
TEST(load_store)958 TEST(load_store) {
959 SETUP();
960
961 COMPARE(ldr(w0, MemOperand(x1)), "ldr w0, [x1]");
962 COMPARE(ldr(w2, MemOperand(x3, 4)), "ldr w2, [x3, #4]");
963 COMPARE(ldr(w4, MemOperand(x5, 16380)), "ldr w4, [x5, #16380]");
964 COMPARE(ldr(x6, MemOperand(x7)), "ldr x6, [x7]");
965 COMPARE(ldr(x8, MemOperand(x9, 8)), "ldr x8, [x9, #8]");
966 COMPARE(ldr(x10, MemOperand(x11, 32760)), "ldr x10, [x11, #32760]");
967 COMPARE(str(w12, MemOperand(x13)), "str w12, [x13]");
968 COMPARE(str(w14, MemOperand(x15, 4)), "str w14, [x15, #4]");
969 COMPARE(str(w16, MemOperand(x17, 16380)), "str w16, [x17, #16380]");
970 COMPARE(str(x18, MemOperand(x19)), "str x18, [x19]");
971 COMPARE(str(x20, MemOperand(x21, 8)), "str x20, [x21, #8]");
972 COMPARE(str(x22, MemOperand(x23, 32760)), "str x22, [x23, #32760]");
973
974 COMPARE(ldr(w0, MemOperand(x1, 4, PreIndex)), "ldr w0, [x1, #4]!");
975 COMPARE(ldr(w2, MemOperand(x3, 255, PreIndex)), "ldr w2, [x3, #255]!");
976 COMPARE(ldr(w4, MemOperand(x5, -256, PreIndex)), "ldr w4, [x5, #-256]!");
977 COMPARE(ldr(x6, MemOperand(x7, 8, PreIndex)), "ldr x6, [x7, #8]!");
978 COMPARE(ldr(x8, MemOperand(x9, 255, PreIndex)), "ldr x8, [x9, #255]!");
979 COMPARE(ldr(x10, MemOperand(x11, -256, PreIndex)), "ldr x10, [x11, #-256]!");
980 COMPARE(str(w12, MemOperand(x13, 4, PreIndex)), "str w12, [x13, #4]!");
981 COMPARE(str(w14, MemOperand(x15, 255, PreIndex)), "str w14, [x15, #255]!");
982 COMPARE(str(w16, MemOperand(x17, -256, PreIndex)), "str w16, [x17, #-256]!");
983 COMPARE(str(x18, MemOperand(x19, 8, PreIndex)), "str x18, [x19, #8]!");
984 COMPARE(str(x20, MemOperand(x21, 255, PreIndex)), "str x20, [x21, #255]!");
985 COMPARE(str(x22, MemOperand(x23, -256, PreIndex)), "str x22, [x23, #-256]!");
986 COMPARE(str(x24, MemOperand(x25, 0, PreIndex)), "str x24, [x25, #0]!");
987 COMPARE(str(w26, MemOperand(x27, 0, PreIndex)), "str w26, [x27, #0]!");
988
989 COMPARE(ldr(w0, MemOperand(x1, 4, PostIndex)), "ldr w0, [x1], #4");
990 COMPARE(ldr(w2, MemOperand(x3, 255, PostIndex)), "ldr w2, [x3], #255");
991 COMPARE(ldr(w4, MemOperand(x5, -256, PostIndex)), "ldr w4, [x5], #-256");
992 COMPARE(ldr(x6, MemOperand(x7, 8, PostIndex)), "ldr x6, [x7], #8");
993 COMPARE(ldr(x8, MemOperand(x9, 255, PostIndex)), "ldr x8, [x9], #255");
994 COMPARE(ldr(x10, MemOperand(x11, -256, PostIndex)), "ldr x10, [x11], #-256");
995 COMPARE(str(w12, MemOperand(x13, 4, PostIndex)), "str w12, [x13], #4");
996 COMPARE(str(w14, MemOperand(x15, 255, PostIndex)), "str w14, [x15], #255");
997 COMPARE(str(w16, MemOperand(x17, -256, PostIndex)), "str w16, [x17], #-256");
998 COMPARE(str(x18, MemOperand(x19, 8, PostIndex)), "str x18, [x19], #8");
999 COMPARE(str(x20, MemOperand(x21, 255, PostIndex)), "str x20, [x21], #255");
1000 COMPARE(str(x22, MemOperand(x23, -256, PostIndex)), "str x22, [x23], #-256");
1001 COMPARE(str(x24, MemOperand(x25, 0, PostIndex)), "str x24, [x25], #0");
1002 COMPARE(str(w26, MemOperand(x27, 0, PostIndex)), "str w26, [x27], #0");
1003
1004 COMPARE(ldr(w24, MemOperand(sp)), "ldr w24, [sp]");
1005 COMPARE(ldr(x25, MemOperand(sp, 8)), "ldr x25, [sp, #8]");
1006 COMPARE(str(w26, MemOperand(sp, 4, PreIndex)), "str w26, [sp, #4]!");
1007 COMPARE(str(x27, MemOperand(sp, -8, PostIndex)), "str x27, [sp], #-8");
1008
1009 COMPARE(ldrsw(x0, MemOperand(x1)), "ldrsw x0, [x1]");
1010 COMPARE(ldrsw(x2, MemOperand(x3, 8)), "ldrsw x2, [x3, #8]");
1011 COMPARE(ldrsw(x4, MemOperand(x5, 42, PreIndex)), "ldrsw x4, [x5, #42]!");
1012 COMPARE(ldrsw(x6, MemOperand(x7, -11, PostIndex)), "ldrsw x6, [x7], #-11");
1013
1014 CLEANUP();
1015 }
1016
1017
TEST(load_store_regoffset)1018 TEST(load_store_regoffset) {
1019 SETUP();
1020
1021 COMPARE(ldr(w0, MemOperand(x1, w2, UXTW)), "ldr w0, [x1, w2, uxtw]");
1022 COMPARE(ldr(w3, MemOperand(x4, w5, UXTW, 2)), "ldr w3, [x4, w5, uxtw #2]");
1023 COMPARE(ldr(w6, MemOperand(x7, x8)), "ldr w6, [x7, x8]");
1024 COMPARE(ldr(w9, MemOperand(x10, x11, LSL, 2)), "ldr w9, [x10, x11, lsl #2]");
1025 COMPARE(ldr(w12, MemOperand(x13, w14, SXTW)), "ldr w12, [x13, w14, sxtw]");
1026 COMPARE(ldr(w15, MemOperand(x16, w17, SXTW, 2)),
1027 "ldr w15, [x16, w17, sxtw #2]");
1028 COMPARE(ldr(w18, MemOperand(x19, x20, SXTX)), "ldr w18, [x19, x20, sxtx]");
1029 COMPARE(ldr(w21, MemOperand(x22, x23, SXTX, 2)),
1030 "ldr w21, [x22, x23, sxtx #2]");
1031 COMPARE(ldr(x0, MemOperand(x1, w2, UXTW)), "ldr x0, [x1, w2, uxtw]");
1032 COMPARE(ldr(x3, MemOperand(x4, w5, UXTW, 3)), "ldr x3, [x4, w5, uxtw #3]");
1033 COMPARE(ldr(x6, MemOperand(x7, x8)), "ldr x6, [x7, x8]");
1034 COMPARE(ldr(x9, MemOperand(x10, x11, LSL, 3)), "ldr x9, [x10, x11, lsl #3]");
1035 COMPARE(ldr(x12, MemOperand(x13, w14, SXTW)), "ldr x12, [x13, w14, sxtw]");
1036 COMPARE(ldr(x15, MemOperand(x16, w17, SXTW, 3)),
1037 "ldr x15, [x16, w17, sxtw #3]");
1038 COMPARE(ldr(x18, MemOperand(x19, x20, SXTX)), "ldr x18, [x19, x20, sxtx]");
1039 COMPARE(ldr(x21, MemOperand(x22, x23, SXTX, 3)),
1040 "ldr x21, [x22, x23, sxtx #3]");
1041
1042 COMPARE(str(w0, MemOperand(x1, w2, UXTW)), "str w0, [x1, w2, uxtw]");
1043 COMPARE(str(w3, MemOperand(x4, w5, UXTW, 2)), "str w3, [x4, w5, uxtw #2]");
1044 COMPARE(str(w6, MemOperand(x7, x8)), "str w6, [x7, x8]");
1045 COMPARE(str(w9, MemOperand(x10, x11, LSL, 2)), "str w9, [x10, x11, lsl #2]");
1046 COMPARE(str(w12, MemOperand(x13, w14, SXTW)), "str w12, [x13, w14, sxtw]");
1047 COMPARE(str(w15, MemOperand(x16, w17, SXTW, 2)),
1048 "str w15, [x16, w17, sxtw #2]");
1049 COMPARE(str(w18, MemOperand(x19, x20, SXTX)), "str w18, [x19, x20, sxtx]");
1050 COMPARE(str(w21, MemOperand(x22, x23, SXTX, 2)),
1051 "str w21, [x22, x23, sxtx #2]");
1052 COMPARE(str(x0, MemOperand(x1, w2, UXTW)), "str x0, [x1, w2, uxtw]");
1053 COMPARE(str(x3, MemOperand(x4, w5, UXTW, 3)), "str x3, [x4, w5, uxtw #3]");
1054 COMPARE(str(x6, MemOperand(x7, x8)), "str x6, [x7, x8]");
1055 COMPARE(str(x9, MemOperand(x10, x11, LSL, 3)), "str x9, [x10, x11, lsl #3]");
1056 COMPARE(str(x12, MemOperand(x13, w14, SXTW)), "str x12, [x13, w14, sxtw]");
1057 COMPARE(str(x15, MemOperand(x16, w17, SXTW, 3)),
1058 "str x15, [x16, w17, sxtw #3]");
1059 COMPARE(str(x18, MemOperand(x19, x20, SXTX)), "str x18, [x19, x20, sxtx]");
1060 COMPARE(str(x21, MemOperand(x22, x23, SXTX, 3)),
1061 "str x21, [x22, x23, sxtx #3]");
1062
1063 COMPARE(ldrb(w0, MemOperand(x1, w2, UXTW)), "ldrb w0, [x1, w2, uxtw]");
1064 COMPARE(ldrb(w6, MemOperand(x7, x8)), "ldrb w6, [x7, x8]");
1065 COMPARE(ldrb(w12, MemOperand(x13, w14, SXTW)), "ldrb w12, [x13, w14, sxtw]");
1066 COMPARE(ldrb(w18, MemOperand(x19, x20, SXTX)), "ldrb w18, [x19, x20, sxtx]");
1067 COMPARE(strb(w0, MemOperand(x1, w2, UXTW)), "strb w0, [x1, w2, uxtw]");
1068 COMPARE(strb(w6, MemOperand(x7, x8)), "strb w6, [x7, x8]");
1069 COMPARE(strb(w12, MemOperand(x13, w14, SXTW)), "strb w12, [x13, w14, sxtw]");
1070 COMPARE(strb(w18, MemOperand(x19, x20, SXTX)), "strb w18, [x19, x20, sxtx]");
1071
1072 COMPARE(ldrh(w0, MemOperand(x1, w2, UXTW)), "ldrh w0, [x1, w2, uxtw]");
1073 COMPARE(ldrh(w3, MemOperand(x4, w5, UXTW, 1)), "ldrh w3, [x4, w5, uxtw #1]");
1074 COMPARE(ldrh(w6, MemOperand(x7, x8)), "ldrh w6, [x7, x8]");
1075 COMPARE(ldrh(w9, MemOperand(x10, x11, LSL, 1)),
1076 "ldrh w9, [x10, x11, lsl #1]");
1077 COMPARE(ldrh(w12, MemOperand(x13, w14, SXTW)), "ldrh w12, [x13, w14, sxtw]");
1078 COMPARE(ldrh(w15, MemOperand(x16, w17, SXTW, 1)),
1079 "ldrh w15, [x16, w17, sxtw #1]");
1080 COMPARE(ldrh(w18, MemOperand(x19, x20, SXTX)), "ldrh w18, [x19, x20, sxtx]");
1081 COMPARE(ldrh(w21, MemOperand(x22, x23, SXTX, 1)),
1082 "ldrh w21, [x22, x23, sxtx #1]");
1083 COMPARE(strh(w0, MemOperand(x1, w2, UXTW)), "strh w0, [x1, w2, uxtw]");
1084 COMPARE(strh(w3, MemOperand(x4, w5, UXTW, 1)), "strh w3, [x4, w5, uxtw #1]");
1085 COMPARE(strh(w6, MemOperand(x7, x8)), "strh w6, [x7, x8]");
1086 COMPARE(strh(w9, MemOperand(x10, x11, LSL, 1)),
1087 "strh w9, [x10, x11, lsl #1]");
1088 COMPARE(strh(w12, MemOperand(x13, w14, SXTW)), "strh w12, [x13, w14, sxtw]");
1089 COMPARE(strh(w15, MemOperand(x16, w17, SXTW, 1)),
1090 "strh w15, [x16, w17, sxtw #1]");
1091 COMPARE(strh(w18, MemOperand(x19, x20, SXTX)), "strh w18, [x19, x20, sxtx]");
1092 COMPARE(strh(w21, MemOperand(x22, x23, SXTX, 1)),
1093 "strh w21, [x22, x23, sxtx #1]");
1094
1095 COMPARE(ldr(x0, MemOperand(sp, wzr, SXTW)), "ldr x0, [sp, wzr, sxtw]");
1096 COMPARE(str(x1, MemOperand(sp, xzr)), "str x1, [sp, xzr]");
1097
1098 CLEANUP();
1099 }
1100
1101
TEST(load_store_byte)1102 TEST(load_store_byte) {
1103 SETUP();
1104
1105 COMPARE(ldrb(w0, MemOperand(x1)), "ldrb w0, [x1]");
1106 COMPARE(ldrb(x2, MemOperand(x3)), "ldrb w2, [x3]");
1107 COMPARE(ldrb(w4, MemOperand(x5, 4095)), "ldrb w4, [x5, #4095]");
1108 COMPARE(ldrb(w6, MemOperand(x7, 255, PreIndex)), "ldrb w6, [x7, #255]!");
1109 COMPARE(ldrb(w8, MemOperand(x9, -256, PreIndex)), "ldrb w8, [x9, #-256]!");
1110 COMPARE(ldrb(w10, MemOperand(x11, 255, PostIndex)), "ldrb w10, [x11], #255");
1111 COMPARE(ldrb(w12, MemOperand(x13, -256, PostIndex)),
1112 "ldrb w12, [x13], #-256");
1113 COMPARE(ldrb(w14, MemOperand(x15, 0, PreIndex)), "ldrb w14, [x15, #0]!");
1114 COMPARE(ldrb(w16, MemOperand(x17, 0, PostIndex)), "ldrb w16, [x17], #0");
1115 COMPARE(strb(w14, MemOperand(x15)), "strb w14, [x15]");
1116 COMPARE(strb(x16, MemOperand(x17)), "strb w16, [x17]");
1117 COMPARE(strb(w18, MemOperand(x19, 4095)), "strb w18, [x19, #4095]");
1118 COMPARE(strb(w20, MemOperand(x21, 255, PreIndex)), "strb w20, [x21, #255]!");
1119 COMPARE(strb(w22, MemOperand(x23, -256, PreIndex)),
1120 "strb w22, [x23, #-256]!");
1121 COMPARE(strb(w24, MemOperand(x25, 255, PostIndex)), "strb w24, [x25], #255");
1122 COMPARE(strb(w26, MemOperand(x27, -256, PostIndex)),
1123 "strb w26, [x27], #-256");
1124 COMPARE(strb(w27, MemOperand(x28, 0, PreIndex)), "strb w27, [x28, #0]!");
1125 COMPARE(strb(w29, MemOperand(x30, 0, PostIndex)), "strb w29, [x30], #0");
1126 COMPARE(ldrb(w28, MemOperand(sp, 3, PostIndex)), "ldrb w28, [sp], #3");
1127 COMPARE(strb(x29, MemOperand(sp, -42, PreIndex)), "strb w29, [sp, #-42]!");
1128 COMPARE(ldrsb(w0, MemOperand(x1)), "ldrsb w0, [x1]");
1129 COMPARE(ldrsb(x2, MemOperand(x3, 8)), "ldrsb x2, [x3, #8]");
1130 COMPARE(ldrsb(w4, MemOperand(x5, 42, PreIndex)), "ldrsb w4, [x5, #42]!");
1131 COMPARE(ldrsb(x6, MemOperand(x7, -11, PostIndex)), "ldrsb x6, [x7], #-11");
1132 COMPARE(ldrsb(w8, MemOperand(x9, 0, PreIndex)), "ldrsb w8, [x9, #0]!");
1133 COMPARE(ldrsb(x10, MemOperand(x11, 0, PostIndex)), "ldrsb x10, [x11], #0");
1134
1135 CLEANUP();
1136 }
1137
1138
TEST(load_store_half)1139 TEST(load_store_half) {
1140 SETUP();
1141
1142 COMPARE(ldrh(w0, MemOperand(x1)), "ldrh w0, [x1]");
1143 COMPARE(ldrh(x2, MemOperand(x3)), "ldrh w2, [x3]");
1144 COMPARE(ldrh(w4, MemOperand(x5, 8190)), "ldrh w4, [x5, #8190]");
1145 COMPARE(ldrh(w6, MemOperand(x7, 255, PreIndex)), "ldrh w6, [x7, #255]!");
1146 COMPARE(ldrh(w8, MemOperand(x9, -256, PreIndex)), "ldrh w8, [x9, #-256]!");
1147 COMPARE(ldrh(w10, MemOperand(x11, 255, PostIndex)), "ldrh w10, [x11], #255");
1148 COMPARE(ldrh(w12, MemOperand(x13, -256, PostIndex)),
1149 "ldrh w12, [x13], #-256");
1150 COMPARE(ldrh(w14, MemOperand(x15, 0, PreIndex)), "ldrh w14, [x15, #0]!");
1151 COMPARE(ldrh(w16, MemOperand(x17, 0, PostIndex)), "ldrh w16, [x17], #0");
1152 COMPARE(strh(w14, MemOperand(x15)), "strh w14, [x15]");
1153 COMPARE(strh(x16, MemOperand(x17)), "strh w16, [x17]");
1154 COMPARE(strh(w18, MemOperand(x19, 8190)), "strh w18, [x19, #8190]");
1155 COMPARE(strh(w20, MemOperand(x21, 255, PreIndex)), "strh w20, [x21, #255]!");
1156 COMPARE(strh(w22, MemOperand(x23, -256, PreIndex)),
1157 "strh w22, [x23, #-256]!");
1158 COMPARE(strh(w24, MemOperand(x25, 255, PostIndex)), "strh w24, [x25], #255");
1159 COMPARE(strh(w26, MemOperand(x27, -256, PostIndex)),
1160 "strh w26, [x27], #-256");
1161 COMPARE(strh(w27, MemOperand(x28, 0, PreIndex)), "strh w27, [x28, #0]!");
1162 COMPARE(strh(w29, MemOperand(x30, 0, PostIndex)), "strh w29, [x30], #0");
1163 COMPARE(ldrh(w28, MemOperand(sp, 3, PostIndex)), "ldrh w28, [sp], #3");
1164 COMPARE(strh(x29, MemOperand(sp, -42, PreIndex)), "strh w29, [sp, #-42]!");
1165 COMPARE(ldrh(w30, MemOperand(x0, 255)), "ldurh w30, [x0, #255]");
1166 COMPARE(ldrh(x1, MemOperand(x2, -256)), "ldurh w1, [x2, #-256]");
1167 COMPARE(strh(w3, MemOperand(x4, 255)), "sturh w3, [x4, #255]");
1168 COMPARE(strh(x5, MemOperand(x6, -256)), "sturh w5, [x6, #-256]");
1169 COMPARE(ldrsh(w0, MemOperand(x1)), "ldrsh w0, [x1]");
1170 COMPARE(ldrsh(w2, MemOperand(x3, 8)), "ldrsh w2, [x3, #8]");
1171 COMPARE(ldrsh(w4, MemOperand(x5, 42, PreIndex)), "ldrsh w4, [x5, #42]!");
1172 COMPARE(ldrsh(x6, MemOperand(x7, -11, PostIndex)), "ldrsh x6, [x7], #-11");
1173 COMPARE(ldrsh(w8, MemOperand(x9, 0, PreIndex)), "ldrsh w8, [x9, #0]!");
1174 COMPARE(ldrsh(x10, MemOperand(x11, 0, PostIndex)), "ldrsh x10, [x11], #0");
1175
1176 CLEANUP();
1177 }
1178
TEST(load_store_unscaled)1179 TEST(load_store_unscaled) {
1180 SETUP();
1181
1182 // If an unscaled-offset instruction is requested, it is used, even if the
1183 // offset could be encoded in a scaled-offset instruction.
1184 COMPARE(ldurb(w0, MemOperand(x1)), "ldurb w0, [x1]");
1185 COMPARE(ldurb(x2, MemOperand(x3, 1)), "ldurb w2, [x3, #1]");
1186 COMPARE(ldurb(w4, MemOperand(x5, 255)), "ldurb w4, [x5, #255]");
1187 COMPARE(sturb(w14, MemOperand(x15)), "sturb w14, [x15]");
1188 COMPARE(sturb(x16, MemOperand(x17, 1)), "sturb w16, [x17, #1]");
1189 COMPARE(sturb(w18, MemOperand(x19, 255)), "sturb w18, [x19, #255]");
1190 COMPARE(ldursb(w0, MemOperand(x1)), "ldursb w0, [x1]");
1191 COMPARE(ldursb(w2, MemOperand(x3, 1)), "ldursb w2, [x3, #1]");
1192 COMPARE(ldursb(x2, MemOperand(x3, 255)), "ldursb x2, [x3, #255]");
1193
1194 COMPARE(ldurh(w0, MemOperand(x1)), "ldurh w0, [x1]");
1195 COMPARE(ldurh(x2, MemOperand(x3, 2)), "ldurh w2, [x3, #2]");
1196 COMPARE(ldurh(w4, MemOperand(x5, 254)), "ldurh w4, [x5, #254]");
1197 COMPARE(sturh(w14, MemOperand(x15)), "sturh w14, [x15]");
1198 COMPARE(sturh(x16, MemOperand(x17, 2)), "sturh w16, [x17, #2]");
1199 COMPARE(sturh(w18, MemOperand(x19, 254)), "sturh w18, [x19, #254]");
1200 COMPARE(ldursh(w0, MemOperand(x1)), "ldursh w0, [x1]");
1201 COMPARE(ldursh(w2, MemOperand(x3, 2)), "ldursh w2, [x3, #2]");
1202 COMPARE(ldursh(x4, MemOperand(x5, 254)), "ldursh x4, [x5, #254]");
1203
1204 COMPARE(ldur(w0, MemOperand(x1)), "ldur w0, [x1]");
1205 COMPARE(ldur(w2, MemOperand(x3, 4)), "ldur w2, [x3, #4]");
1206 COMPARE(ldur(w4, MemOperand(x5, 248)), "ldur w4, [x5, #248]");
1207 COMPARE(stur(w12, MemOperand(x13)), "stur w12, [x13]");
1208 COMPARE(stur(w14, MemOperand(x15, 4)), "stur w14, [x15, #4]");
1209 COMPARE(stur(w16, MemOperand(x17, 248)), "stur w16, [x17, #248]");
1210 COMPARE(ldursw(x0, MemOperand(x1)), "ldursw x0, [x1]");
1211 COMPARE(ldursw(x2, MemOperand(x3, 4)), "ldursw x2, [x3, #4]");
1212 COMPARE(ldursw(x4, MemOperand(x5, 248)), "ldursw x4, [x5, #248]");
1213
1214 COMPARE(ldur(x6, MemOperand(x7)), "ldur x6, [x7]");
1215 COMPARE(ldur(x8, MemOperand(x9, 8)), "ldur x8, [x9, #8]");
1216 COMPARE(ldur(x10, MemOperand(x11, 248)), "ldur x10, [x11, #248]");
1217 COMPARE(stur(x18, MemOperand(x19)), "stur x18, [x19]");
1218 COMPARE(stur(x20, MemOperand(x21, 8)), "stur x20, [x21, #8]");
1219 COMPARE(stur(x22, MemOperand(x23, 248)), "stur x22, [x23, #248]");
1220
1221 COMPARE(ldur(b0, MemOperand(x1)), "ldur b0, [x1]");
1222 COMPARE(ldur(h2, MemOperand(x3, -1)), "ldur h2, [x3, #-1]");
1223 COMPARE(ldur(s4, MemOperand(x5, 2)), "ldur s4, [x5, #2]");
1224 COMPARE(ldur(d6, MemOperand(x7, -3)), "ldur d6, [x7, #-3]");
1225 COMPARE(ldur(q8, MemOperand(x9, 4)), "ldur q8, [x9, #4]");
1226 COMPARE(stur(b10, MemOperand(x11)), "stur b10, [x11]");
1227 COMPARE(stur(h12, MemOperand(x13, -1)), "stur h12, [x13, #-1]");
1228 COMPARE(stur(s14, MemOperand(x15, 2)), "stur s14, [x15, #2]");
1229 COMPARE(stur(d16, MemOperand(x17, -3)), "stur d16, [x17, #-3]");
1230 COMPARE(stur(q18, MemOperand(x19, 4)), "stur q18, [x19, #4]");
1231
1232 // Normal loads and stores are converted to unscaled loads and stores if the
1233 // offset requires it.
1234 COMPARE(ldr(w0, MemOperand(x1, 1)), "ldur w0, [x1, #1]");
1235 COMPARE(ldr(w2, MemOperand(x3, -1)), "ldur w2, [x3, #-1]");
1236 COMPARE(ldr(w4, MemOperand(x5, 255)), "ldur w4, [x5, #255]");
1237 COMPARE(ldr(w6, MemOperand(x7, -256)), "ldur w6, [x7, #-256]");
1238 COMPARE(ldr(x8, MemOperand(x9, 1)), "ldur x8, [x9, #1]");
1239 COMPARE(ldr(x10, MemOperand(x11, -1)), "ldur x10, [x11, #-1]");
1240 COMPARE(ldr(x12, MemOperand(x13, 255)), "ldur x12, [x13, #255]");
1241 COMPARE(ldr(x14, MemOperand(x15, -256)), "ldur x14, [x15, #-256]");
1242 COMPARE(str(w16, MemOperand(x17, 1)), "stur w16, [x17, #1]");
1243 COMPARE(str(w18, MemOperand(x19, -1)), "stur w18, [x19, #-1]");
1244 COMPARE(str(w20, MemOperand(x21, 255)), "stur w20, [x21, #255]");
1245 COMPARE(str(w22, MemOperand(x23, -256)), "stur w22, [x23, #-256]");
1246 COMPARE(str(x24, MemOperand(x25, 1)), "stur x24, [x25, #1]");
1247 COMPARE(str(x26, MemOperand(x27, -1)), "stur x26, [x27, #-1]");
1248 COMPARE(str(x28, MemOperand(x29, 255)), "stur x28, [x29, #255]");
1249 COMPARE(str(x30, MemOperand(x0, -256)), "stur x30, [x0, #-256]");
1250 COMPARE(ldr(w0, MemOperand(sp, 1)), "ldur w0, [sp, #1]");
1251 COMPARE(str(x1, MemOperand(sp, -1)), "stur x1, [sp, #-1]");
1252 COMPARE(ldrb(w2, MemOperand(x3, -2)), "ldurb w2, [x3, #-2]");
1253 COMPARE(ldrsb(w4, MemOperand(x5, -3)), "ldursb w4, [x5, #-3]");
1254 COMPARE(ldrsb(x6, MemOperand(x7, -4)), "ldursb x6, [x7, #-4]");
1255 COMPARE(ldrh(w8, MemOperand(x9, -5)), "ldurh w8, [x9, #-5]");
1256 COMPARE(ldrsh(w10, MemOperand(x11, -6)), "ldursh w10, [x11, #-6]");
1257 COMPARE(ldrsh(x12, MemOperand(x13, -7)), "ldursh x12, [x13, #-7]");
1258 COMPARE(ldrsw(x14, MemOperand(x15, -8)), "ldursw x14, [x15, #-8]");
1259
1260 CLEANUP();
1261 }
1262
1263
TEST(load_store_unscaled_option)1264 TEST(load_store_unscaled_option) {
1265 SETUP();
1266
1267 // Just like load_store_unscaled, but specify the scaling option explicitly.
1268 LoadStoreScalingOption options[] = {PreferUnscaledOffset,
1269 RequireUnscaledOffset};
1270
1271 for (size_t i = 0; i < sizeof(options) / sizeof(options[0]); i++) {
1272 LoadStoreScalingOption option = options[i];
1273
1274 // If an unscaled-offset instruction is requested, it is used, even if the
1275 // offset could be encoded in a scaled-offset instruction.
1276 COMPARE(ldurb(w0, MemOperand(x1), option), "ldurb w0, [x1]");
1277 COMPARE(ldurb(x2, MemOperand(x3, 1), option), "ldurb w2, [x3, #1]");
1278 COMPARE(ldurb(w4, MemOperand(x5, 255), option), "ldurb w4, [x5, #255]");
1279 COMPARE(sturb(w14, MemOperand(x15), option), "sturb w14, [x15]");
1280 COMPARE(sturb(x16, MemOperand(x17, 1), option), "sturb w16, [x17, #1]");
1281 COMPARE(sturb(w18, MemOperand(x19, 255), option), "sturb w18, [x19, #255]");
1282 COMPARE(ldursb(w0, MemOperand(x1), option), "ldursb w0, [x1]");
1283 COMPARE(ldursb(w2, MemOperand(x3, 1), option), "ldursb w2, [x3, #1]");
1284 COMPARE(ldursb(x2, MemOperand(x3, 255), option), "ldursb x2, [x3, #255]");
1285
1286 COMPARE(ldurh(w0, MemOperand(x1), option), "ldurh w0, [x1]");
1287 COMPARE(ldurh(x2, MemOperand(x3, 2), option), "ldurh w2, [x3, #2]");
1288 COMPARE(ldurh(w4, MemOperand(x5, 254), option), "ldurh w4, [x5, #254]");
1289 COMPARE(sturh(w14, MemOperand(x15), option), "sturh w14, [x15]");
1290 COMPARE(sturh(x16, MemOperand(x17, 2), option), "sturh w16, [x17, #2]");
1291 COMPARE(sturh(w18, MemOperand(x19, 254), option), "sturh w18, [x19, #254]");
1292 COMPARE(ldursh(w0, MemOperand(x1), option), "ldursh w0, [x1]");
1293 COMPARE(ldursh(w2, MemOperand(x3, 2), option), "ldursh w2, [x3, #2]");
1294 COMPARE(ldursh(x4, MemOperand(x5, 254), option), "ldursh x4, [x5, #254]");
1295
1296 COMPARE(ldur(w0, MemOperand(x1), option), "ldur w0, [x1]");
1297 COMPARE(ldur(w2, MemOperand(x3, 4), option), "ldur w2, [x3, #4]");
1298 COMPARE(ldur(w4, MemOperand(x5, 248), option), "ldur w4, [x5, #248]");
1299 COMPARE(stur(w12, MemOperand(x13), option), "stur w12, [x13]");
1300 COMPARE(stur(w14, MemOperand(x15, 4), option), "stur w14, [x15, #4]");
1301 COMPARE(stur(w16, MemOperand(x17, 248), option), "stur w16, [x17, #248]");
1302 COMPARE(ldursw(x0, MemOperand(x1), option), "ldursw x0, [x1]");
1303 COMPARE(ldursw(x2, MemOperand(x3, 4), option), "ldursw x2, [x3, #4]");
1304 COMPARE(ldursw(x4, MemOperand(x5, 248), option), "ldursw x4, [x5, #248]");
1305
1306 COMPARE(ldur(x6, MemOperand(x7), option), "ldur x6, [x7]");
1307 COMPARE(ldur(x8, MemOperand(x9, 8), option), "ldur x8, [x9, #8]");
1308 COMPARE(ldur(x10, MemOperand(x11, 248), option), "ldur x10, [x11, #248]");
1309 COMPARE(stur(x18, MemOperand(x19), option), "stur x18, [x19]");
1310 COMPARE(stur(x20, MemOperand(x21, 8), option), "stur x20, [x21, #8]");
1311 COMPARE(stur(x22, MemOperand(x23, 248), option), "stur x22, [x23, #248]");
1312
1313 COMPARE(ldur(b0, MemOperand(x1), option), "ldur b0, [x1]");
1314 COMPARE(ldur(h2, MemOperand(x3, 2), option), "ldur h2, [x3, #2]");
1315 COMPARE(ldur(s4, MemOperand(x5, 4), option), "ldur s4, [x5, #4]");
1316 COMPARE(ldur(d6, MemOperand(x7, 8), option), "ldur d6, [x7, #8]");
1317 COMPARE(ldur(q8, MemOperand(x9, 16), option), "ldur q8, [x9, #16]");
1318 COMPARE(stur(b10, MemOperand(x11), option), "stur b10, [x11]");
1319 COMPARE(stur(h12, MemOperand(x13, 2), option), "stur h12, [x13, #2]");
1320 COMPARE(stur(s14, MemOperand(x15, 4), option), "stur s14, [x15, #4]");
1321 COMPARE(stur(d16, MemOperand(x17, 8), option), "stur d16, [x17, #8]");
1322 COMPARE(stur(q18, MemOperand(x19, 16), option), "stur q18, [x19, #16]");
1323 }
1324
1325 // Normal loads and stores are converted to unscaled loads and stores if the
1326 // offset requires it. PreferScaledOffset is the default for these cases, so
1327 // the behaviour here is the same when no option is specified.
1328 LoadStoreScalingOption option = PreferScaledOffset;
1329 COMPARE(ldr(w0, MemOperand(x1, 1), option), "ldur w0, [x1, #1]");
1330 COMPARE(ldr(w2, MemOperand(x3, -1), option), "ldur w2, [x3, #-1]");
1331 COMPARE(ldr(w4, MemOperand(x5, 255), option), "ldur w4, [x5, #255]");
1332 COMPARE(ldr(w6, MemOperand(x7, -256), option), "ldur w6, [x7, #-256]");
1333 COMPARE(ldr(x8, MemOperand(x9, 1), option), "ldur x8, [x9, #1]");
1334 COMPARE(ldr(x10, MemOperand(x11, -1), option), "ldur x10, [x11, #-1]");
1335 COMPARE(ldr(x12, MemOperand(x13, 255), option), "ldur x12, [x13, #255]");
1336 COMPARE(ldr(x14, MemOperand(x15, -256), option), "ldur x14, [x15, #-256]");
1337 COMPARE(str(w16, MemOperand(x17, 1), option), "stur w16, [x17, #1]");
1338 COMPARE(str(w18, MemOperand(x19, -1), option), "stur w18, [x19, #-1]");
1339 COMPARE(str(w20, MemOperand(x21, 255), option), "stur w20, [x21, #255]");
1340 COMPARE(str(w22, MemOperand(x23, -256), option), "stur w22, [x23, #-256]");
1341 COMPARE(str(x24, MemOperand(x25, 1), option), "stur x24, [x25, #1]");
1342 COMPARE(str(x26, MemOperand(x27, -1), option), "stur x26, [x27, #-1]");
1343 COMPARE(str(x28, MemOperand(x29, 255), option), "stur x28, [x29, #255]");
1344 COMPARE(str(x30, MemOperand(x0, -256), option), "stur x30, [x0, #-256]");
1345 COMPARE(ldr(w0, MemOperand(sp, 1), option), "ldur w0, [sp, #1]");
1346 COMPARE(str(x1, MemOperand(sp, -1), option), "stur x1, [sp, #-1]");
1347 COMPARE(ldrb(w2, MemOperand(x3, -2), option), "ldurb w2, [x3, #-2]");
1348 COMPARE(ldrsb(w4, MemOperand(x5, -3), option), "ldursb w4, [x5, #-3]");
1349 COMPARE(ldrsb(x6, MemOperand(x7, -4), option), "ldursb x6, [x7, #-4]");
1350 COMPARE(ldrh(w8, MemOperand(x9, -5), option), "ldurh w8, [x9, #-5]");
1351 COMPARE(ldrsh(w10, MemOperand(x11, -6), option), "ldursh w10, [x11, #-6]");
1352 COMPARE(ldrsh(x12, MemOperand(x13, -7), option), "ldursh x12, [x13, #-7]");
1353 COMPARE(ldrsw(x14, MemOperand(x15, -8), option), "ldursw x14, [x15, #-8]");
1354 COMPARE(ldr(b0, MemOperand(x1, 1), option), "ldr b0, [x1, #1]");
1355 COMPARE(ldr(h2, MemOperand(x3, 1), option), "ldur h2, [x3, #1]");
1356 COMPARE(ldr(s4, MemOperand(x5, 3), option), "ldur s4, [x5, #3]");
1357 COMPARE(ldr(d6, MemOperand(x7, 7), option), "ldur d6, [x7, #7]");
1358 COMPARE(ldr(q8, MemOperand(x9, 15), option), "ldur q8, [x9, #15]");
1359 COMPARE(str(b10, MemOperand(x11, 1), option), "str b10, [x11, #1]");
1360 COMPARE(str(h12, MemOperand(x13, 1), option), "stur h12, [x13, #1]");
1361 COMPARE(str(s14, MemOperand(x15, 3), option), "stur s14, [x15, #3]");
1362 COMPARE(str(d16, MemOperand(x17, 7), option), "stur d16, [x17, #7]");
1363 COMPARE(str(q18, MemOperand(x19, 15), option), "stur q18, [x19, #15]");
1364
1365 CLEANUP();
1366 }
1367
1368
TEST(load_store_pair)1369 TEST(load_store_pair) {
1370 SETUP();
1371
1372 COMPARE(ldp(w0, w1, MemOperand(x2)), "ldp w0, w1, [x2]");
1373 COMPARE(ldp(x3, x4, MemOperand(x5)), "ldp x3, x4, [x5]");
1374 COMPARE(ldp(w6, w7, MemOperand(x8, 4)), "ldp w6, w7, [x8, #4]");
1375 COMPARE(ldp(x9, x10, MemOperand(x11, 8)), "ldp x9, x10, [x11, #8]");
1376 COMPARE(ldp(w12, w13, MemOperand(x14, 252)), "ldp w12, w13, [x14, #252]");
1377 COMPARE(ldp(x15, x16, MemOperand(x17, 504)), "ldp x15, x16, [x17, #504]");
1378 COMPARE(ldp(w18, w19, MemOperand(x20, -256)), "ldp w18, w19, [x20, #-256]");
1379 COMPARE(ldp(x21, x22, MemOperand(x23, -512)), "ldp x21, x22, [x23, #-512]");
1380 COMPARE(ldp(w24, w25, MemOperand(x26, 252, PreIndex)),
1381 "ldp w24, w25, [x26, #252]!");
1382 COMPARE(ldp(x27, x28, MemOperand(x29, 504, PreIndex)),
1383 "ldp x27, x28, [x29, #504]!");
1384 COMPARE(ldp(w30, w0, MemOperand(x1, -256, PreIndex)),
1385 "ldp w30, w0, [x1, #-256]!");
1386 COMPARE(ldp(x2, x3, MemOperand(x4, -512, PreIndex)),
1387 "ldp x2, x3, [x4, #-512]!");
1388 COMPARE(ldp(w5, w6, MemOperand(x7, 252, PostIndex)),
1389 "ldp w5, w6, [x7], #252");
1390 COMPARE(ldp(x8, x9, MemOperand(x10, 504, PostIndex)),
1391 "ldp x8, x9, [x10], #504");
1392 COMPARE(ldp(w11, w12, MemOperand(x13, -256, PostIndex)),
1393 "ldp w11, w12, [x13], #-256");
1394 COMPARE(ldp(x14, x15, MemOperand(x16, -512, PostIndex)),
1395 "ldp x14, x15, [x16], #-512");
1396 COMPARE(ldp(x0, x1, MemOperand(x2, 0, PostIndex)), "ldp x0, x1, [x2], #0");
1397 COMPARE(ldp(w3, w4, MemOperand(x5, 0, PreIndex)), "ldp w3, w4, [x5, #0]!");
1398
1399 COMPARE(ldp(s17, s18, MemOperand(x19)), "ldp s17, s18, [x19]");
1400 COMPARE(ldp(s20, s21, MemOperand(x22, 252)), "ldp s20, s21, [x22, #252]");
1401 COMPARE(ldp(s23, s24, MemOperand(x25, -256)), "ldp s23, s24, [x25, #-256]");
1402 COMPARE(ldp(s26, s27, MemOperand(x28, 252, PreIndex)),
1403 "ldp s26, s27, [x28, #252]!");
1404 COMPARE(ldp(s29, s30, MemOperand(x29, -256, PreIndex)),
1405 "ldp s29, s30, [x29, #-256]!");
1406 COMPARE(ldp(s31, s0, MemOperand(x1, 252, PostIndex)),
1407 "ldp s31, s0, [x1], #252");
1408 COMPARE(ldp(s2, s3, MemOperand(x4, -256, PostIndex)),
1409 "ldp s2, s3, [x4], #-256");
1410 COMPARE(ldp(d17, d18, MemOperand(x19)), "ldp d17, d18, [x19]");
1411 COMPARE(ldp(d20, d21, MemOperand(x22, 504)), "ldp d20, d21, [x22, #504]");
1412 COMPARE(ldp(d23, d24, MemOperand(x25, -512)), "ldp d23, d24, [x25, #-512]");
1413 COMPARE(ldp(d26, d27, MemOperand(x28, 504, PreIndex)),
1414 "ldp d26, d27, [x28, #504]!");
1415 COMPARE(ldp(d29, d30, MemOperand(x29, -512, PreIndex)),
1416 "ldp d29, d30, [x29, #-512]!");
1417 COMPARE(ldp(d31, d0, MemOperand(x1, 504, PostIndex)),
1418 "ldp d31, d0, [x1], #504");
1419 COMPARE(ldp(d2, d3, MemOperand(x4, -512, PostIndex)),
1420 "ldp d2, d3, [x4], #-512");
1421 COMPARE(ldp(s0, s1, MemOperand(x2, 0, PostIndex)), "ldp s0, s1, [x2], #0");
1422 COMPARE(ldp(d3, d4, MemOperand(x5, 0, PreIndex)), "ldp d3, d4, [x5, #0]!");
1423
1424 COMPARE(ldp(q5, q6, MemOperand(x7)), "ldp q5, q6, [x7]");
1425 COMPARE(ldp(q8, q9, MemOperand(x10, 1008)), "ldp q8, q9, [x10, #1008]");
1426 COMPARE(ldp(q11, q12, MemOperand(x13, -1024)), "ldp q11, q12, [x13, #-1024]");
1427 COMPARE(ldp(q14, q15, MemOperand(x16, 1008, PreIndex)),
1428 "ldp q14, q15, [x16, #1008]!");
1429 COMPARE(ldp(q17, q18, MemOperand(x19, -1024, PreIndex)),
1430 "ldp q17, q18, [x19, #-1024]!");
1431 COMPARE(ldp(q20, q21, MemOperand(x22, 1008, PostIndex)),
1432 "ldp q20, q21, [x22], #1008");
1433 COMPARE(ldp(q23, q24, MemOperand(x25, -1024, PostIndex)),
1434 "ldp q23, q24, [x25], #-1024");
1435 COMPARE(ldp(q6, q7, MemOperand(x8, 0, PreIndex)), "ldp q6, q7, [x8, #0]!");
1436
1437 COMPARE(stp(w0, w1, MemOperand(x2)), "stp w0, w1, [x2]");
1438 COMPARE(stp(x3, x4, MemOperand(x5)), "stp x3, x4, [x5]");
1439 COMPARE(stp(w6, w7, MemOperand(x8, 4)), "stp w6, w7, [x8, #4]");
1440 COMPARE(stp(x9, x10, MemOperand(x11, 8)), "stp x9, x10, [x11, #8]");
1441 COMPARE(stp(w12, w13, MemOperand(x14, 252)), "stp w12, w13, [x14, #252]");
1442 COMPARE(stp(x15, x16, MemOperand(x17, 504)), "stp x15, x16, [x17, #504]");
1443 COMPARE(stp(w18, w19, MemOperand(x20, -256)), "stp w18, w19, [x20, #-256]");
1444 COMPARE(stp(x21, x22, MemOperand(x23, -512)), "stp x21, x22, [x23, #-512]");
1445 COMPARE(stp(w24, w25, MemOperand(x26, 252, PreIndex)),
1446 "stp w24, w25, [x26, #252]!");
1447 COMPARE(stp(x27, x28, MemOperand(x29, 504, PreIndex)),
1448 "stp x27, x28, [x29, #504]!");
1449 COMPARE(stp(w30, w0, MemOperand(x1, -256, PreIndex)),
1450 "stp w30, w0, [x1, #-256]!");
1451 COMPARE(stp(x2, x3, MemOperand(x4, -512, PreIndex)),
1452 "stp x2, x3, [x4, #-512]!");
1453 COMPARE(stp(w5, w6, MemOperand(x7, 252, PostIndex)),
1454 "stp w5, w6, [x7], #252");
1455 COMPARE(stp(x8, x9, MemOperand(x10, 504, PostIndex)),
1456 "stp x8, x9, [x10], #504");
1457 COMPARE(stp(w11, w12, MemOperand(x13, -256, PostIndex)),
1458 "stp w11, w12, [x13], #-256");
1459 COMPARE(stp(x14, x15, MemOperand(x16, -512, PostIndex)),
1460 "stp x14, x15, [x16], #-512");
1461 COMPARE(stp(x0, x1, MemOperand(x2, 0, PostIndex)), "stp x0, x1, [x2], #0");
1462 COMPARE(stp(w3, w4, MemOperand(x5, 0, PreIndex)), "stp w3, w4, [x5, #0]!");
1463
1464 COMPARE(stp(s17, s18, MemOperand(x19)), "stp s17, s18, [x19]");
1465 COMPARE(stp(s20, s21, MemOperand(x22, 252)), "stp s20, s21, [x22, #252]");
1466 COMPARE(stp(s23, s24, MemOperand(x25, -256)), "stp s23, s24, [x25, #-256]");
1467 COMPARE(stp(s26, s27, MemOperand(x28, 252, PreIndex)),
1468 "stp s26, s27, [x28, #252]!");
1469 COMPARE(stp(s29, s30, MemOperand(x29, -256, PreIndex)),
1470 "stp s29, s30, [x29, #-256]!");
1471 COMPARE(stp(s31, s0, MemOperand(x1, 252, PostIndex)),
1472 "stp s31, s0, [x1], #252");
1473 COMPARE(stp(s2, s3, MemOperand(x4, -256, PostIndex)),
1474 "stp s2, s3, [x4], #-256");
1475 COMPARE(stp(d17, d18, MemOperand(x19)), "stp d17, d18, [x19]");
1476 COMPARE(stp(d20, d21, MemOperand(x22, 504)), "stp d20, d21, [x22, #504]");
1477 COMPARE(stp(d23, d24, MemOperand(x25, -512)), "stp d23, d24, [x25, #-512]");
1478 COMPARE(stp(d26, d27, MemOperand(x28, 504, PreIndex)),
1479 "stp d26, d27, [x28, #504]!");
1480 COMPARE(stp(d29, d30, MemOperand(x29, -512, PreIndex)),
1481 "stp d29, d30, [x29, #-512]!");
1482 COMPARE(stp(d31, d0, MemOperand(x1, 504, PostIndex)),
1483 "stp d31, d0, [x1], #504");
1484 COMPARE(stp(d2, d3, MemOperand(x4, -512, PostIndex)),
1485 "stp d2, d3, [x4], #-512");
1486 COMPARE(stp(s0, s1, MemOperand(x2, 0, PostIndex)), "stp s0, s1, [x2], #0");
1487 COMPARE(stp(d3, d4, MemOperand(x5, 0, PreIndex)), "stp d3, d4, [x5, #0]!");
1488
1489 COMPARE(stp(q5, q6, MemOperand(x7)), "stp q5, q6, [x7]");
1490 COMPARE(stp(q8, q9, MemOperand(x10, 1008)), "stp q8, q9, [x10, #1008]");
1491 COMPARE(stp(q11, q12, MemOperand(x13, -1024)), "stp q11, q12, [x13, #-1024]");
1492 COMPARE(stp(q14, q15, MemOperand(x16, 1008, PreIndex)),
1493 "stp q14, q15, [x16, #1008]!");
1494 COMPARE(stp(q17, q18, MemOperand(x19, -1024, PreIndex)),
1495 "stp q17, q18, [x19, #-1024]!");
1496 COMPARE(stp(q20, q21, MemOperand(x22, 1008, PostIndex)),
1497 "stp q20, q21, [x22], #1008");
1498 COMPARE(stp(q23, q24, MemOperand(x25, -1024, PostIndex)),
1499 "stp q23, q24, [x25], #-1024");
1500 COMPARE(stp(q6, q7, MemOperand(x8, 0, PreIndex)), "stp q6, q7, [x8, #0]!");
1501
1502 COMPARE(ldp(w16, w17, MemOperand(sp, 4, PostIndex)),
1503 "ldp w16, w17, [sp], #4");
1504 COMPARE(stp(x18, x19, MemOperand(sp, -8, PreIndex)),
1505 "stp x18, x19, [sp, #-8]!");
1506 COMPARE(ldp(s30, s31, MemOperand(sp, 12, PostIndex)),
1507 "ldp s30, s31, [sp], #12");
1508 COMPARE(stp(d30, d31, MemOperand(sp, -16)), "stp d30, d31, [sp, #-16]");
1509 COMPARE(ldp(q30, q31, MemOperand(sp, 32, PostIndex)),
1510 "ldp q30, q31, [sp], #32");
1511
1512 COMPARE(ldpsw(x0, x1, MemOperand(x2)), "ldpsw x0, x1, [x2]");
1513 COMPARE(ldpsw(x3, x4, MemOperand(x5, 16)), "ldpsw x3, x4, [x5, #16]");
1514 COMPARE(ldpsw(x6, x7, MemOperand(x8, -32, PreIndex)),
1515 "ldpsw x6, x7, [x8, #-32]!");
1516 COMPARE(ldpsw(x9, x10, MemOperand(x11, 128, PostIndex)),
1517 "ldpsw x9, x10, [x11], #128");
1518 COMPARE(ldpsw(x0, x1, MemOperand(x10, 0, PreIndex)),
1519 "ldpsw x0, x1, [x10, #0]!");
1520 COMPARE(ldpsw(x2, x3, MemOperand(x10, 0, PostIndex)),
1521 "ldpsw x2, x3, [x10], #0");
1522
1523 CLEANUP();
1524 }
1525
1526
TEST(load_pauth)1527 TEST(load_pauth) {
1528 SETUP();
1529
1530 COMPARE(ldraa(x0, MemOperand(x1)), "ldraa x0, [x1]");
1531 COMPARE(ldraa(x2, MemOperand(sp)), "ldraa x2, [sp]");
1532 COMPARE(ldraa(x3, MemOperand(x4, 64)), "ldraa x3, [x4, #64]");
1533 COMPARE(ldraa(x5, MemOperand(sp, 512)), "ldraa x5, [sp, #512]");
1534 COMPARE(ldraa(x6, MemOperand(x7, -256)), "ldraa x6, [x7, #-256]");
1535 COMPARE(ldraa(x8, MemOperand(sp, -1024)), "ldraa x8, [sp, #-1024]");
1536 COMPARE(ldraa(x9, MemOperand(x10, 2048, PreIndex)),
1537 "ldraa x9, [x10, #2048]!");
1538
1539 COMPARE(ldrab(x9, MemOperand(x10)), "ldrab x9, [x10]");
1540 COMPARE(ldrab(x11, MemOperand(sp)), "ldrab x11, [sp]");
1541 COMPARE(ldrab(x12, MemOperand(x13, 64)), "ldrab x12, [x13, #64]");
1542 COMPARE(ldrab(x14, MemOperand(sp, 512)), "ldrab x14, [sp, #512]");
1543 COMPARE(ldrab(x15, MemOperand(x16, -256)), "ldrab x15, [x16, #-256]");
1544 COMPARE(ldrab(x17, MemOperand(sp, -1024)), "ldrab x17, [sp, #-1024]");
1545 COMPARE(ldrab(x18, MemOperand(x19, 2048, PreIndex)),
1546 "ldrab x18, [x19, #2048]!");
1547
1548 CLEANUP();
1549 }
1550
1551
TEST(load_store_exclusive)1552 TEST(load_store_exclusive) {
1553 SETUP();
1554
1555 COMPARE(stxrb(w0, w1, MemOperand(x2)), "stxrb w0, w1, [x2]");
1556 COMPARE(stxrb(x3, w4, MemOperand(sp)), "stxrb w3, w4, [sp]");
1557 COMPARE(stxrb(w5, x6, MemOperand(x7)), "stxrb w5, w6, [x7]");
1558 COMPARE(stxrb(x8, x9, MemOperand(sp)), "stxrb w8, w9, [sp]");
1559 COMPARE(stxrh(w10, w11, MemOperand(x12)), "stxrh w10, w11, [x12]");
1560 COMPARE(stxrh(x13, w14, MemOperand(sp)), "stxrh w13, w14, [sp]");
1561 COMPARE(stxrh(w15, x16, MemOperand(x17)), "stxrh w15, w16, [x17]");
1562 COMPARE(stxrh(x18, x19, MemOperand(sp)), "stxrh w18, w19, [sp]");
1563 COMPARE(stxr(w20, w21, MemOperand(x22)), "stxr w20, w21, [x22]");
1564 COMPARE(stxr(x23, w24, MemOperand(sp)), "stxr w23, w24, [sp]");
1565 COMPARE(stxr(w25, x26, MemOperand(x27)), "stxr w25, x26, [x27]");
1566 COMPARE(stxr(x28, x29, MemOperand(sp)), "stxr w28, x29, [sp]");
1567 COMPARE(ldxrb(w30, MemOperand(x0)), "ldxrb w30, [x0]");
1568 COMPARE(ldxrb(w1, MemOperand(sp)), "ldxrb w1, [sp]");
1569 COMPARE(ldxrb(x2, MemOperand(x3)), "ldxrb w2, [x3]");
1570 COMPARE(ldxrb(x4, MemOperand(sp)), "ldxrb w4, [sp]");
1571 COMPARE(ldxrh(w5, MemOperand(x6)), "ldxrh w5, [x6]");
1572 COMPARE(ldxrh(w7, MemOperand(sp)), "ldxrh w7, [sp]");
1573 COMPARE(ldxrh(x8, MemOperand(x9)), "ldxrh w8, [x9]");
1574 COMPARE(ldxrh(x10, MemOperand(sp)), "ldxrh w10, [sp]");
1575 COMPARE(ldxr(w11, MemOperand(x12)), "ldxr w11, [x12]");
1576 COMPARE(ldxr(w13, MemOperand(sp)), "ldxr w13, [sp]");
1577 COMPARE(ldxr(x14, MemOperand(x15)), "ldxr x14, [x15]");
1578 COMPARE(ldxr(x16, MemOperand(sp)), "ldxr x16, [sp]");
1579 COMPARE(stxp(w17, w18, w19, MemOperand(x20)), "stxp w17, w18, w19, [x20]");
1580 COMPARE(stxp(x21, w22, w23, MemOperand(sp)), "stxp w21, w22, w23, [sp]");
1581 COMPARE(stxp(w24, x25, x26, MemOperand(x27)), "stxp w24, x25, x26, [x27]");
1582 COMPARE(stxp(x28, x29, x30, MemOperand(sp)), "stxp w28, x29, x30, [sp]");
1583 COMPARE(ldxp(w0, w1, MemOperand(x2)), "ldxp w0, w1, [x2]");
1584 COMPARE(ldxp(w3, w4, MemOperand(sp)), "ldxp w3, w4, [sp]");
1585 COMPARE(ldxp(x5, x6, MemOperand(x7)), "ldxp x5, x6, [x7]");
1586 COMPARE(ldxp(x8, x9, MemOperand(sp)), "ldxp x8, x9, [sp]");
1587 COMPARE(stlxrb(w10, w11, MemOperand(x12)), "stlxrb w10, w11, [x12]");
1588 COMPARE(stlxrb(x13, w14, MemOperand(sp)), "stlxrb w13, w14, [sp]");
1589 COMPARE(stlxrb(w15, x16, MemOperand(x17)), "stlxrb w15, w16, [x17]");
1590 COMPARE(stlxrb(x18, x19, MemOperand(sp)), "stlxrb w18, w19, [sp]");
1591 COMPARE(stlxrh(w20, w21, MemOperand(x22)), "stlxrh w20, w21, [x22]");
1592 COMPARE(stlxrh(x23, w24, MemOperand(sp)), "stlxrh w23, w24, [sp]");
1593 COMPARE(stlxrh(w25, x26, MemOperand(x27)), "stlxrh w25, w26, [x27]");
1594 COMPARE(stlxrh(x28, x29, MemOperand(sp)), "stlxrh w28, w29, [sp]");
1595 COMPARE(stlxr(w30, w0, MemOperand(x1)), "stlxr w30, w0, [x1]");
1596 COMPARE(stlxr(x2, w3, MemOperand(sp)), "stlxr w2, w3, [sp]");
1597 COMPARE(stlxr(w4, x5, MemOperand(x6)), "stlxr w4, x5, [x6]");
1598 COMPARE(stlxr(x7, x8, MemOperand(sp)), "stlxr w7, x8, [sp]");
1599 COMPARE(ldaxrb(w9, MemOperand(x10)), "ldaxrb w9, [x10]");
1600 COMPARE(ldaxrb(w11, MemOperand(sp)), "ldaxrb w11, [sp]");
1601 COMPARE(ldaxrb(x12, MemOperand(x13)), "ldaxrb w12, [x13]");
1602 COMPARE(ldaxrb(x14, MemOperand(sp)), "ldaxrb w14, [sp]");
1603 COMPARE(ldaxrh(w15, MemOperand(x16)), "ldaxrh w15, [x16]");
1604 COMPARE(ldaxrh(w17, MemOperand(sp)), "ldaxrh w17, [sp]");
1605 COMPARE(ldaxrh(x18, MemOperand(x19)), "ldaxrh w18, [x19]");
1606 COMPARE(ldaxrh(x20, MemOperand(sp)), "ldaxrh w20, [sp]");
1607 COMPARE(ldaxr(w21, MemOperand(x22)), "ldaxr w21, [x22]");
1608 COMPARE(ldaxr(w23, MemOperand(sp)), "ldaxr w23, [sp]");
1609 COMPARE(ldaxr(x24, MemOperand(x25)), "ldaxr x24, [x25]");
1610 COMPARE(ldaxr(x26, MemOperand(sp)), "ldaxr x26, [sp]");
1611 COMPARE(stlxp(w27, w28, w29, MemOperand(x30)), "stlxp w27, w28, w29, [x30]");
1612 COMPARE(stlxp(x0, w1, w2, MemOperand(sp)), "stlxp w0, w1, w2, [sp]");
1613 COMPARE(stlxp(w3, x4, x5, MemOperand(x6)), "stlxp w3, x4, x5, [x6]");
1614 COMPARE(stlxp(x7, x8, x9, MemOperand(sp)), "stlxp w7, x8, x9, [sp]");
1615 COMPARE(ldaxp(w10, w11, MemOperand(x12)), "ldaxp w10, w11, [x12]");
1616 COMPARE(ldaxp(w13, w14, MemOperand(sp)), "ldaxp w13, w14, [sp]");
1617 COMPARE(ldaxp(x15, x16, MemOperand(x17)), "ldaxp x15, x16, [x17]");
1618 COMPARE(ldaxp(x18, x19, MemOperand(sp)), "ldaxp x18, x19, [sp]");
1619 COMPARE(stlrb(w20, MemOperand(x21)), "stlrb w20, [x21]");
1620 COMPARE(stlrb(w22, MemOperand(sp)), "stlrb w22, [sp]");
1621 COMPARE(stlrb(x23, MemOperand(x24)), "stlrb w23, [x24]");
1622 COMPARE(stlrb(x25, MemOperand(sp)), "stlrb w25, [sp]");
1623 COMPARE(stlrh(w26, MemOperand(x27)), "stlrh w26, [x27]");
1624 COMPARE(stlrh(w28, MemOperand(sp)), "stlrh w28, [sp]");
1625 COMPARE(stlrh(x29, MemOperand(x30)), "stlrh w29, [x30]");
1626 COMPARE(stlrh(x0, MemOperand(sp)), "stlrh w0, [sp]");
1627 COMPARE(stlr(w1, MemOperand(x2)), "stlr w1, [x2]");
1628 COMPARE(stlr(w3, MemOperand(sp)), "stlr w3, [sp]");
1629 COMPARE(stlr(x4, MemOperand(x5)), "stlr x4, [x5]");
1630 COMPARE(stlr(x6, MemOperand(sp)), "stlr x6, [sp]");
1631 COMPARE(stllrb(w7, MemOperand(x8)), "stllrb w7, [x8]");
1632 COMPARE(stllrb(w9, MemOperand(sp)), "stllrb w9, [sp]");
1633 COMPARE(stllrb(x10, MemOperand(x11)), "stllrb w10, [x11]");
1634 COMPARE(stllrb(x12, MemOperand(sp)), "stllrb w12, [sp]");
1635 COMPARE(stllrh(w13, MemOperand(x14)), "stllrh w13, [x14]");
1636 COMPARE(stllrh(w15, MemOperand(sp)), "stllrh w15, [sp]");
1637 COMPARE(stllrh(x16, MemOperand(x17)), "stllrh w16, [x17]");
1638 COMPARE(stllrh(x18, MemOperand(sp)), "stllrh w18, [sp]");
1639 COMPARE(stllr(w19, MemOperand(x20)), "stllr w19, [x20]");
1640 COMPARE(stllr(w21, MemOperand(sp)), "stllr w21, [sp]");
1641 COMPARE(stllr(x22, MemOperand(x23)), "stllr x22, [x23]");
1642 COMPARE(stllr(x24, MemOperand(sp)), "stllr x24, [sp]");
1643 COMPARE(ldarb(w25, MemOperand(x26)), "ldarb w25, [x26]");
1644 COMPARE(ldarb(w27, MemOperand(sp)), "ldarb w27, [sp]");
1645 COMPARE(ldarb(x28, MemOperand(x29)), "ldarb w28, [x29]");
1646 COMPARE(ldarb(x30, MemOperand(sp)), "ldarb w30, [sp]");
1647 COMPARE(ldarh(w0, MemOperand(x1)), "ldarh w0, [x1]");
1648 COMPARE(ldarh(w2, MemOperand(sp)), "ldarh w2, [sp]");
1649 COMPARE(ldarh(x3, MemOperand(x4)), "ldarh w3, [x4]");
1650 COMPARE(ldarh(x5, MemOperand(sp)), "ldarh w5, [sp]");
1651 COMPARE(ldar(w6, MemOperand(x7)), "ldar w6, [x7]");
1652 COMPARE(ldar(w8, MemOperand(sp)), "ldar w8, [sp]");
1653 COMPARE(ldar(x9, MemOperand(x10)), "ldar x9, [x10]");
1654 COMPARE(ldar(x11, MemOperand(sp)), "ldar x11, [sp]");
1655 COMPARE(ldlarb(w12, MemOperand(x13)), "ldlarb w12, [x13]");
1656 COMPARE(ldlarb(w14, MemOperand(sp)), "ldlarb w14, [sp]");
1657 COMPARE(ldlarb(x15, MemOperand(x16)), "ldlarb w15, [x16]");
1658 COMPARE(ldlarb(x17, MemOperand(sp)), "ldlarb w17, [sp]");
1659 COMPARE(ldlarh(w18, MemOperand(x19)), "ldlarh w18, [x19]");
1660 COMPARE(ldlarh(w20, MemOperand(sp)), "ldlarh w20, [sp]");
1661 COMPARE(ldlarh(x21, MemOperand(x22)), "ldlarh w21, [x22]");
1662 COMPARE(ldlarh(x23, MemOperand(sp)), "ldlarh w23, [sp]");
1663 COMPARE(ldlar(w24, MemOperand(x25)), "ldlar w24, [x25]");
1664 COMPARE(ldlar(w26, MemOperand(sp)), "ldlar w26, [sp]");
1665 COMPARE(ldlar(x27, MemOperand(x28)), "ldlar x27, [x28]");
1666 COMPARE(ldlar(x29, MemOperand(sp)), "ldlar x29, [sp]");
1667
1668 COMPARE(cas(w30, w0, MemOperand(x1)), "cas w30, w0, [x1]");
1669 COMPARE(cas(w2, w3, MemOperand(sp)), "cas w2, w3, [sp]");
1670 COMPARE(cas(x4, x5, MemOperand(x6)), "cas x4, x5, [x6]");
1671 COMPARE(cas(x7, x8, MemOperand(sp)), "cas x7, x8, [sp]");
1672 COMPARE(casa(w9, w10, MemOperand(x11)), "casa w9, w10, [x11]");
1673 COMPARE(casa(w12, w13, MemOperand(sp)), "casa w12, w13, [sp]");
1674 COMPARE(casa(x14, x15, MemOperand(x16)), "casa x14, x15, [x16]");
1675 COMPARE(casa(x17, x18, MemOperand(sp)), "casa x17, x18, [sp]");
1676 COMPARE(casl(w19, w20, MemOperand(x21)), "casl w19, w20, [x21]");
1677 COMPARE(casl(w22, w23, MemOperand(sp)), "casl w22, w23, [sp]");
1678 COMPARE(casl(x24, x25, MemOperand(x26)), "casl x24, x25, [x26]");
1679 COMPARE(casl(x27, x28, MemOperand(sp)), "casl x27, x28, [sp]");
1680 COMPARE(casal(w29, w30, MemOperand(x0)), "casal w29, w30, [x0]");
1681 COMPARE(casal(w1, w2, MemOperand(sp)), "casal w1, w2, [sp]");
1682 COMPARE(casal(x3, x4, MemOperand(x5)), "casal x3, x4, [x5]");
1683 COMPARE(casal(x6, x7, MemOperand(sp)), "casal x6, x7, [sp]");
1684 COMPARE(casb(w8, w9, MemOperand(x10)), "casb w8, w9, [x10]");
1685 COMPARE(casb(w11, w12, MemOperand(sp)), "casb w11, w12, [sp]");
1686 COMPARE(casab(w13, w14, MemOperand(x15)), "casab w13, w14, [x15]");
1687 COMPARE(casab(w16, w17, MemOperand(sp)), "casab w16, w17, [sp]");
1688 COMPARE(caslb(w18, w19, MemOperand(x20)), "caslb w18, w19, [x20]");
1689 COMPARE(caslb(w21, w22, MemOperand(sp)), "caslb w21, w22, [sp]");
1690 COMPARE(casalb(w23, w24, MemOperand(x25)), "casalb w23, w24, [x25]");
1691 COMPARE(casalb(w26, w27, MemOperand(sp)), "casalb w26, w27, [sp]");
1692 COMPARE(cash(w28, w29, MemOperand(x30)), "cash w28, w29, [x30]");
1693 COMPARE(cash(w0, w1, MemOperand(sp)), "cash w0, w1, [sp]");
1694 COMPARE(casah(w2, w3, MemOperand(x4)), "casah w2, w3, [x4]");
1695 COMPARE(casah(w5, w6, MemOperand(sp)), "casah w5, w6, [sp]");
1696 COMPARE(caslh(w7, w8, MemOperand(x9)), "caslh w7, w8, [x9]");
1697 COMPARE(caslh(w10, w11, MemOperand(sp)), "caslh w10, w11, [sp]");
1698 COMPARE(casalh(w12, w13, MemOperand(x14)), "casalh w12, w13, [x14]");
1699 COMPARE(casalh(w15, w16, MemOperand(sp)), "casalh w15, w16, [sp]");
1700 COMPARE(casp(w18, w19, w20, w21, MemOperand(x22)),
1701 "casp w18, w19, w20, w21, [x22]");
1702 COMPARE(casp(w24, w25, w26, w27, MemOperand(sp)),
1703 "casp w24, w25, w26, w27, [sp]");
1704 COMPARE(casp(x28, x29, x0, x1, MemOperand(x2)),
1705 "casp x28, x29, x0, x1, [x2]");
1706 COMPARE(casp(x4, x5, x6, x7, MemOperand(sp)), "casp x4, x5, x6, x7, [sp]");
1707 COMPARE(caspa(w8, w9, w10, w11, MemOperand(x12)),
1708 "caspa w8, w9, w10, w11, [x12]");
1709 COMPARE(caspa(w14, w15, w16, w17, MemOperand(sp)),
1710 "caspa w14, w15, w16, w17, [sp]");
1711 COMPARE(caspa(x18, x19, x20, x21, MemOperand(x22)),
1712 "caspa x18, x19, x20, x21, [x22]");
1713 COMPARE(caspa(x24, x25, x26, x27, MemOperand(sp)),
1714 "caspa x24, x25, x26, x27, [sp]");
1715 COMPARE(caspl(w28, w29, w0, w1, MemOperand(x2)),
1716 "caspl w28, w29, w0, w1, [x2]");
1717 COMPARE(caspl(w4, w5, w6, w7, MemOperand(sp)), "caspl w4, w5, w6, w7, [sp]");
1718 COMPARE(caspl(x8, x9, x10, x11, MemOperand(x12)),
1719 "caspl x8, x9, x10, x11, [x12]");
1720 COMPARE(caspl(x14, x15, x16, x17, MemOperand(sp)),
1721 "caspl x14, x15, x16, x17, [sp]");
1722 COMPARE(caspal(w18, w19, w20, w21, MemOperand(x22)),
1723 "caspal w18, w19, w20, w21, [x22]");
1724 COMPARE(caspal(w24, w25, w26, w27, MemOperand(sp)),
1725 "caspal w24, w25, w26, w27, [sp]");
1726 COMPARE(caspal(x28, x29, x0, x1, MemOperand(x2)),
1727 "caspal x28, x29, x0, x1, [x2]");
1728 COMPARE(caspal(x4, x5, x6, x7, MemOperand(sp)),
1729 "caspal x4, x5, x6, x7, [sp]");
1730
1731
1732 CLEANUP();
1733 }
1734
1735 // clang-format off
1736 #define ATOMIC_MEMORY_DISASM_LIST(V, DEF) \
1737 V(DEF, add, "add") \
1738 V(DEF, clr, "clr") \
1739 V(DEF, eor, "eor") \
1740 V(DEF, set, "set") \
1741 V(DEF, smax, "smax") \
1742 V(DEF, smin, "smin") \
1743 V(DEF, umax, "umax") \
1744 V(DEF, umin, "umin")
1745
1746 #define ATOMIC_MEMORY_DISASM_STORE_X_MODES(V, NAME, STR) \
1747 V(NAME, STR) \
1748 V(NAME##l, STR "l")
1749
1750
1751 #define ATOMIC_MEMORY_DISASM_STORE_W_MODES(V, NAME, STR) \
1752 ATOMIC_MEMORY_DISASM_STORE_X_MODES(V, NAME, STR) \
1753 V(NAME##b, STR "b") \
1754 V(NAME##lb, STR "lb") \
1755 V(NAME##h, STR "h") \
1756 V(NAME##lh, STR "lh")
1757
1758 #define ATOMIC_MEMORY_DISASM_LOAD_X_MODES(V, NAME, STR) \
1759 ATOMIC_MEMORY_DISASM_STORE_X_MODES(V, NAME, STR) \
1760 V(NAME##a, STR "a") \
1761 V(NAME##al, STR "al")
1762
1763 #define ATOMIC_MEMORY_DISASM_LOAD_W_MODES(V, NAME, STR) \
1764 ATOMIC_MEMORY_DISASM_LOAD_X_MODES(V, NAME, STR) \
1765 V(NAME##ab, STR "ab") \
1766 V(NAME##alb, STR "alb") \
1767 V(NAME##ah, STR "ah") \
1768 V(NAME##alh, STR "alh")
1769 // clang-format on
1770
TEST(atomic_memory)1771 TEST(atomic_memory) {
1772 SETUP();
1773
1774 // These macros generate tests for all the variations of the atomic memory
1775 // operations, e.g. ldadd, ldadda, ldaddb, staddl, etc.
1776
1777 #define AM_LOAD_X_TESTS(N, MN) \
1778 COMPARE(ld##N(x0, x1, MemOperand(x2)), "ld" MN " x0, x1, [x2]"); \
1779 COMPARE(ld##N(x3, x4, MemOperand(sp)), "ld" MN " x3, x4, [sp]");
1780 #define AM_LOAD_W_TESTS(N, MN) \
1781 COMPARE(ld##N(w0, w1, MemOperand(x2)), "ld" MN " w0, w1, [x2]"); \
1782 COMPARE(ld##N(w3, w4, MemOperand(sp)), "ld" MN " w3, w4, [sp]");
1783 #define AM_STORE_X_TESTS(N, MN) \
1784 COMPARE(st##N(x0, MemOperand(x1)), "st" MN " x0, [x1]"); \
1785 COMPARE(st##N(x2, MemOperand(sp)), "st" MN " x2, [sp]");
1786 #define AM_STORE_W_TESTS(N, MN) \
1787 COMPARE(st##N(w0, MemOperand(x1)), "st" MN " w0, [x1]"); \
1788 COMPARE(st##N(w2, MemOperand(sp)), "st" MN " w2, [sp]");
1789
1790 ATOMIC_MEMORY_DISASM_LIST(ATOMIC_MEMORY_DISASM_LOAD_X_MODES, AM_LOAD_X_TESTS)
1791 ATOMIC_MEMORY_DISASM_LIST(ATOMIC_MEMORY_DISASM_LOAD_W_MODES, AM_LOAD_W_TESTS)
1792 ATOMIC_MEMORY_DISASM_LIST(ATOMIC_MEMORY_DISASM_STORE_X_MODES,
1793 AM_STORE_X_TESTS)
1794 ATOMIC_MEMORY_DISASM_LIST(ATOMIC_MEMORY_DISASM_STORE_W_MODES,
1795 AM_STORE_W_TESTS)
1796
1797 #define AM_SWP_X_TESTS(N, MN) \
1798 COMPARE(N(x0, x1, MemOperand(x2)), MN " x0, x1, [x2]"); \
1799 COMPARE(N(x3, x4, MemOperand(sp)), MN " x3, x4, [sp]");
1800 #define AM_SWP_W_TESTS(N, MN) \
1801 COMPARE(N(w0, w1, MemOperand(x2)), MN " w0, w1, [x2]"); \
1802 COMPARE(N(w3, w4, MemOperand(sp)), MN " w3, w4, [sp]");
1803
1804
1805 ATOMIC_MEMORY_DISASM_LOAD_X_MODES(AM_SWP_X_TESTS, swp, "swp")
1806 ATOMIC_MEMORY_DISASM_LOAD_W_MODES(AM_SWP_W_TESTS, swp, "swp")
1807
1808 #undef AM_LOAD_X_TESTS
1809 #undef AM_LOAD_W_TESTS
1810 #undef AM_STORE_X_TESTS
1811 #undef AM_STORE_W_TESTS
1812 #undef AM_SWP_X_TESTS
1813 #undef AM_SWP_W_TESTS
1814
1815 COMPARE(ldaprb(w0, MemOperand(x1)), "ldaprb w0, [x1]");
1816 COMPARE(ldaprb(w2, MemOperand(sp)), "ldaprb w2, [sp]");
1817 COMPARE(ldaprh(w3, MemOperand(x4)), "ldaprh w3, [x4]");
1818 COMPARE(ldaprh(w5, MemOperand(sp)), "ldaprh w5, [sp]");
1819 COMPARE(ldapr(w6, MemOperand(x7)), "ldapr w6, [x7]");
1820 COMPARE(ldapr(w8, MemOperand(sp)), "ldapr w8, [sp]");
1821 COMPARE(ldapr(x9, MemOperand(x10)), "ldapr x9, [x10]");
1822 COMPARE(ldapr(x11, MemOperand(sp)), "ldapr x11, [sp]");
1823
1824 CLEANUP();
1825 }
1826
TEST(load_store_rcpc_unscaled_offset)1827 TEST(load_store_rcpc_unscaled_offset) {
1828 SETUP();
1829
1830 COMPARE(ldapurb(w0, MemOperand(x1)), "ldapurb w0, [x1]");
1831 COMPARE(ldapurb(w2, MemOperand(x3, 13)), "ldapurb w2, [x3, #13]");
1832 COMPARE(ldapursb(w4, MemOperand(x5, 129)), "ldapursb w4, [x5, #129]");
1833 COMPARE(ldapursb(x6, MemOperand(sp, 64)), "ldapursb x6, [sp, #64]");
1834 COMPARE(ldapurh(w7, MemOperand(x8)), "ldapurh w7, [x8]");
1835 COMPARE(ldapurh(w9, MemOperand(x10, 13)), "ldapurh w9, [x10, #13]");
1836 COMPARE(ldapursh(w11, MemOperand(x12, 129)), "ldapursh w11, [x12, #129]");
1837 COMPARE(ldapursh(x13, MemOperand(sp, 64)), "ldapursh x13, [sp, #64]");
1838 COMPARE(ldapur(w14, MemOperand(x15)), "ldapur w14, [x15]");
1839 COMPARE(ldapur(w16, MemOperand(x17, 13)), "ldapur w16, [x17, #13]");
1840 COMPARE(ldapursw(x18, MemOperand(sp, 64)), "ldapursw x18, [sp, #64]");
1841 COMPARE(ldapur(x19, MemOperand(x20)), "ldapur x19, [x20]");
1842 COMPARE(ldapur(x21, MemOperand(sp, 64)), "ldapur x21, [sp, #64]");
1843
1844 COMPARE(stlurb(w22, MemOperand(x23)), "stlurb w22, [x23]");
1845 COMPARE(stlurb(w24, MemOperand(sp, 64)), "stlurb w24, [sp, #64]");
1846 COMPARE(stlurh(w25, MemOperand(x26)), "stlurh w25, [x26]");
1847 COMPARE(stlurh(w27, MemOperand(sp, 64)), "stlurh w27, [sp, #64]");
1848 COMPARE(stlur(w28, MemOperand(x29)), "stlur w28, [x29]");
1849 COMPARE(stlur(w0, MemOperand(sp, 64)), "stlur w0, [sp, #64]");
1850 COMPARE(stlur(x1, MemOperand(x2)), "stlur x1, [x2]");
1851 COMPARE(stlur(x3, MemOperand(sp, 64)), "stlur x3, [sp, #64]");
1852
1853
1854 COMPARE_MACRO(Ldaprb(w0, MemOperand(x1)), "ldaprb w0, [x1]");
1855 COMPARE_MACRO(Ldaprb(w2, MemOperand(x3, 13)), "ldapurb w2, [x3, #13]");
1856 COMPARE_MACRO(Ldaprh(w4, MemOperand(x5)), "ldaprh w4, [x5]");
1857 COMPARE_MACRO(Ldaprh(w6, MemOperand(x7, 13)), "ldapurh w6, [x7, #13]");
1858 COMPARE_MACRO(Ldapr(w8, MemOperand(x9)), "ldapr w8, [x9]");
1859 COMPARE_MACRO(Ldapr(w10, MemOperand(x11, 13)), "ldapur w10, [x11, #13]");
1860 COMPARE_MACRO(Ldapr(x12, MemOperand(x13)), "ldapr x12, [x13]");
1861 COMPARE_MACRO(Ldapr(x14, MemOperand(sp, 64)), "ldapur x14, [sp, #64]");
1862
1863 COMPARE_MACRO(Stlrb(w15, MemOperand(x16)), "stlrb w15, [x16]");
1864 COMPARE_MACRO(Stlrb(w17, MemOperand(sp, 64)), "stlurb w17, [sp, #64]");
1865 COMPARE_MACRO(Stlrh(w18, MemOperand(x19)), "stlrh w18, [x19]");
1866 COMPARE_MACRO(Stlrh(w20, MemOperand(sp, 64)), "stlurh w20, [sp, #64]");
1867 COMPARE_MACRO(Stlr(w21, MemOperand(x22)), "stlr w21, [x22]");
1868 COMPARE_MACRO(Stlr(w23, MemOperand(sp, 64)), "stlur w23, [sp, #64]");
1869 COMPARE_MACRO(Stlr(x24, MemOperand(x25)), "stlr x24, [x25]");
1870 COMPARE_MACRO(Stlr(x26, MemOperand(sp, 64)), "stlur x26, [sp, #64]");
1871
1872 CLEANUP();
1873 }
1874
1875
TEST(load_store_pair_nontemp)1876 TEST(load_store_pair_nontemp) {
1877 SETUP();
1878
1879 COMPARE(ldnp(w0, w1, MemOperand(x2)), "ldnp w0, w1, [x2]");
1880 COMPARE(stnp(w3, w4, MemOperand(x5, 252)), "stnp w3, w4, [x5, #252]");
1881 COMPARE(ldnp(w6, w7, MemOperand(x8, -256)), "ldnp w6, w7, [x8, #-256]");
1882 COMPARE(stnp(x9, x10, MemOperand(x11)), "stnp x9, x10, [x11]");
1883 COMPARE(ldnp(x12, x13, MemOperand(x14, 504)), "ldnp x12, x13, [x14, #504]");
1884 COMPARE(stnp(x15, x16, MemOperand(x17, -512)), "stnp x15, x16, [x17, #-512]");
1885 COMPARE(ldnp(s18, s19, MemOperand(x20)), "ldnp s18, s19, [x20]");
1886 COMPARE(stnp(s21, s22, MemOperand(x23, 252)), "stnp s21, s22, [x23, #252]");
1887 COMPARE(ldnp(s24, s25, MemOperand(x26, -256)), "ldnp s24, s25, [x26, #-256]");
1888 COMPARE(stnp(d27, d28, MemOperand(x29)), "stnp d27, d28, [x29]");
1889 COMPARE(ldnp(d30, d31, MemOperand(x0, 504)), "ldnp d30, d31, [x0, #504]");
1890 COMPARE(stnp(d1, d2, MemOperand(x3, -512)), "stnp d1, d2, [x3, #-512]");
1891 COMPARE(ldnp(q4, q5, MemOperand(x6)), "ldnp q4, q5, [x6]");
1892 COMPARE(stnp(q7, q8, MemOperand(x9, 1008)), "stnp q7, q8, [x9, #1008]");
1893 COMPARE(ldnp(q10, q11, MemOperand(x12, -1024)),
1894 "ldnp q10, q11, [x12, #-1024]");
1895
1896 CLEANUP();
1897 }
1898
1899
TEST(load_literal_macro)1900 TEST(load_literal_macro) {
1901 SETUP();
1902
1903 // In each case, the literal will be placed at PC+8:
1904 // ldr x10, pc+8 // Test instruction.
1905 // ldr xzr, pc+12 // Pool marker.
1906 // .word64 #0x1234567890abcdef // Test literal.
1907
1908 COMPARE_MACRO_PREFIX(Ldr(x10, 0x1234567890abcdef), "ldr x10, pc+8");
1909 COMPARE_MACRO_PREFIX(Ldr(w20, 0xfedcba09), "ldr w20, pc+8");
1910 COMPARE_MACRO_PREFIX(Ldr(d11, 1.234), "ldr d11, pc+8");
1911 COMPARE_MACRO_PREFIX(Ldr(s22, 2.5f), "ldr s22, pc+8");
1912 COMPARE_MACRO_PREFIX(Ldrsw(x21, 0x80000000), "ldrsw x21, pc+8");
1913
1914 CLEANUP();
1915 }
1916
1917
TEST(load_literal)1918 TEST(load_literal) {
1919 SETUP();
1920
1921 COMPARE_PREFIX(ldr(x20, INT64_C(0)), "ldr x20, pc+0");
1922 COMPARE_PREFIX(ldr(x20, 1), "ldr x20, pc+4");
1923 COMPARE_PREFIX(ldr(x20, -1), "ldr x20, pc-4");
1924 COMPARE_PREFIX(ldr(x20, 0x3ffff), "ldr x20, pc+1048572");
1925 COMPARE_PREFIX(ldr(x20, -0x40000), "ldr x20, pc-1048576");
1926 COMPARE_PREFIX(ldr(w21, INT64_C(0)), "ldr w21, pc+0");
1927 COMPARE_PREFIX(ldr(w21, 1), "ldr w21, pc+4");
1928 COMPARE_PREFIX(ldr(w21, -1), "ldr w21, pc-4");
1929 COMPARE_PREFIX(ldr(w21, 0x3ffff), "ldr w21, pc+1048572");
1930 COMPARE_PREFIX(ldr(w21, -0x40000), "ldr w21, pc-1048576");
1931 COMPARE_PREFIX(ldr(d22, INT64_C(0)), "ldr d22, pc+0");
1932 COMPARE_PREFIX(ldr(d22, 1), "ldr d22, pc+4");
1933 COMPARE_PREFIX(ldr(d22, -1), "ldr d22, pc-4");
1934 COMPARE_PREFIX(ldr(d22, 0x3ffff), "ldr d22, pc+1048572");
1935 COMPARE_PREFIX(ldr(d22, -0x40000), "ldr d22, pc-1048576");
1936 COMPARE_PREFIX(ldr(s23, INT64_C(0)), "ldr s23, pc+0");
1937 COMPARE_PREFIX(ldr(s23, 1), "ldr s23, pc+4");
1938 COMPARE_PREFIX(ldr(s23, -1), "ldr s23, pc-4");
1939 COMPARE_PREFIX(ldr(s23, 0x3ffff), "ldr s23, pc+1048572");
1940 COMPARE_PREFIX(ldr(s23, -0x40000), "ldr s23, pc-1048576");
1941 COMPARE_PREFIX(ldrsw(x24, INT64_C(0)), "ldrsw x24, pc+0");
1942 COMPARE_PREFIX(ldrsw(x24, 1), "ldrsw x24, pc+4");
1943 COMPARE_PREFIX(ldrsw(x24, -1), "ldrsw x24, pc-4");
1944 COMPARE_PREFIX(ldrsw(x24, 0x3ffff), "ldrsw x24, pc+1048572");
1945 COMPARE_PREFIX(ldrsw(x24, -0x40000), "ldrsw x24, pc-1048576");
1946
1947 CLEANUP();
1948 }
1949
1950
TEST(prfm_operations)1951 TEST(prfm_operations) {
1952 SETUP();
1953
1954 // Test every encodable prefetch operation.
1955 const char* expected[] = {
1956 "prfm pldl1keep, ", "prfm pldl1strm, ", "prfm pldl2keep, ",
1957 "prfm pldl2strm, ", "prfm pldl3keep, ", "prfm pldl3strm, ",
1958 "prfm #0b00110, ", "prfm #0b00111, ", "prfm plil1keep, ",
1959 "prfm plil1strm, ", "prfm plil2keep, ", "prfm plil2strm, ",
1960 "prfm plil3keep, ", "prfm plil3strm, ", "prfm #0b01110, ",
1961 "prfm #0b01111, ", "prfm pstl1keep, ", "prfm pstl1strm, ",
1962 "prfm pstl2keep, ", "prfm pstl2strm, ", "prfm pstl3keep, ",
1963 "prfm pstl3strm, ", "prfm #0b10110, ", "prfm #0b10111, ",
1964 "prfm #0b11000, ", "prfm #0b11001, ", "prfm #0b11010, ",
1965 "prfm #0b11011, ", "prfm #0b11100, ", "prfm #0b11101, ",
1966 "prfm #0b11110, ", "prfm #0b11111, ",
1967 };
1968 const int expected_count = sizeof(expected) / sizeof(expected[0]);
1969 VIXL_STATIC_ASSERT((1 << ImmPrefetchOperation_width) == expected_count);
1970
1971 for (int op = 0; op < (1 << ImmPrefetchOperation_width); op++) {
1972 COMPARE_PREFIX(prfm(op, INT64_C(0)), expected[op]);
1973 COMPARE_PREFIX(prfm(op, MemOperand(x0, 0)), expected[op]);
1974 COMPARE_PREFIX(prfm(op, MemOperand(x0, x1)), expected[op]);
1975 }
1976
1977 CLEANUP();
1978 }
1979
1980
TEST(prfum_operations)1981 TEST(prfum_operations) {
1982 SETUP();
1983
1984 // Test every encodable prefetch operation.
1985 const char* expected[] = {
1986 "prfum pldl1keep, ", "prfum pldl1strm, ", "prfum pldl2keep, ",
1987 "prfum pldl2strm, ", "prfum pldl3keep, ", "prfum pldl3strm, ",
1988 "prfum #0b00110, ", "prfum #0b00111, ", "prfum plil1keep, ",
1989 "prfum plil1strm, ", "prfum plil2keep, ", "prfum plil2strm, ",
1990 "prfum plil3keep, ", "prfum plil3strm, ", "prfum #0b01110, ",
1991 "prfum #0b01111, ", "prfum pstl1keep, ", "prfum pstl1strm, ",
1992 "prfum pstl2keep, ", "prfum pstl2strm, ", "prfum pstl3keep, ",
1993 "prfum pstl3strm, ", "prfum #0b10110, ", "prfum #0b10111, ",
1994 "prfum #0b11000, ", "prfum #0b11001, ", "prfum #0b11010, ",
1995 "prfum #0b11011, ", "prfum #0b11100, ", "prfum #0b11101, ",
1996 "prfum #0b11110, ", "prfum #0b11111, ",
1997 };
1998 const int expected_count = sizeof(expected) / sizeof(expected[0]);
1999 VIXL_STATIC_ASSERT((1 << ImmPrefetchOperation_width) == expected_count);
2000
2001 for (int op = 0; op < (1 << ImmPrefetchOperation_width); op++) {
2002 COMPARE_PREFIX(prfum(op, MemOperand(x0, 0)), expected[op]);
2003 }
2004
2005 CLEANUP();
2006 }
2007
2008
TEST(prfm_offset)2009 TEST(prfm_offset) {
2010 SETUP();
2011
2012 COMPARE(prfm(PLDL1KEEP, MemOperand(x1)), "prfm pldl1keep, [x1]");
2013 COMPARE(prfm(PLDL1STRM, MemOperand(x3, 8)), "prfm pldl1strm, [x3, #8]");
2014 COMPARE(prfm(PLDL2KEEP, MemOperand(x5, 32760)),
2015 "prfm pldl2keep, [x5, #32760]");
2016
2017 COMPARE(prfm(PLDL2STRM, MemOperand(sp)), "prfm pldl2strm, [sp]");
2018 COMPARE(prfm(PLDL3KEEP, MemOperand(sp, 8)), "prfm pldl3keep, [sp, #8]");
2019 COMPARE(prfm(PLDL3STRM, MemOperand(sp, 32760)),
2020 "prfm pldl3strm, [sp, #32760]");
2021
2022 CLEANUP();
2023 }
2024
2025
TEST(prfm_regoffset)2026 TEST(prfm_regoffset) {
2027 SETUP();
2028
2029 COMPARE(prfm(PLIL1KEEP, MemOperand(x1, x2)), "prfm plil1keep, [x1, x2]");
2030 COMPARE(prfm(PLIL1STRM, MemOperand(x3, w4, SXTW)),
2031 "prfm plil1strm, [x3, w4, sxtw]");
2032 COMPARE(prfm(PLIL2KEEP, MemOperand(x5, x6, LSL, 3)),
2033 "prfm plil2keep, [x5, x6, lsl #3]");
2034
2035 COMPARE(prfm(PLIL2STRM, MemOperand(sp, xzr)), "prfm plil2strm, [sp, xzr]");
2036 COMPARE(prfm(PLIL3KEEP, MemOperand(sp, wzr, SXTW)),
2037 "prfm plil3keep, [sp, wzr, sxtw]");
2038 COMPARE(prfm(PLIL3STRM, MemOperand(sp, xzr, LSL, 3)),
2039 "prfm plil3strm, [sp, xzr, lsl #3]");
2040
2041 CLEANUP();
2042 }
2043
2044
TEST(prfm_literal)2045 TEST(prfm_literal) {
2046 SETUP();
2047
2048 COMPARE_PREFIX(prfm(PSTL1KEEP, INT64_C(0)), "prfm pstl1keep, pc+0");
2049 COMPARE_PREFIX(prfm(PSTL1STRM, 1), "prfm pstl1strm, pc+4");
2050 COMPARE_PREFIX(prfm(PSTL2KEEP, -1), "prfm pstl2keep, pc-4");
2051 COMPARE_PREFIX(prfm(PSTL2STRM, 0x3ffff), "prfm pstl2strm, pc+1048572");
2052 COMPARE_PREFIX(prfm(PSTL3KEEP, -0x3ffff), "prfm pstl3keep, pc-1048572");
2053 COMPARE_PREFIX(prfm(PSTL3STRM, -0x40000), "prfm pstl3strm, pc-1048576");
2054
2055 CLEANUP();
2056 }
2057
2058
TEST(prfm_unscaled)2059 TEST(prfm_unscaled) {
2060 SETUP();
2061
2062 // If an unscaled-offset instruction is requested, it is used, even if the
2063 // offset could be encoded in a scaled-offset instruction.
2064 COMPARE(prfum(PLDL1KEEP, MemOperand(x1)), "prfum pldl1keep, [x1]");
2065 COMPARE(prfum(PLDL1STRM, MemOperand(x1, 8)), "prfum pldl1strm, [x1, #8]");
2066 COMPARE(prfum(PLDL2KEEP, MemOperand(x1, 248)), "prfum pldl2keep, [x1, #248]");
2067
2068 // Normal offsets are converted to unscaled offsets if necssary.
2069 COMPARE(prfm(PLDL2STRM, MemOperand(x1, 1)), "prfum pldl2strm, [x1, #1]");
2070 COMPARE(prfm(PLDL3KEEP, MemOperand(x1, -1)), "prfum pldl3keep, [x1, #-1]");
2071 COMPARE(prfm(PLDL3STRM, MemOperand(x1, 255)), "prfum pldl3strm, [x1, #255]");
2072 COMPARE(prfm(PLDL3STRM, MemOperand(x1, -256)),
2073 "prfum pldl3strm, [x1, #-256]");
2074
2075 CLEANUP();
2076 }
2077
2078
TEST(prfm_unscaled_option)2079 TEST(prfm_unscaled_option) {
2080 SETUP();
2081
2082 // Just like prfm_unscaled, but specify the scaling option explicitly.
2083
2084 // Require unscaled-offset forms.
2085 LoadStoreScalingOption option = RequireUnscaledOffset;
2086
2087 COMPARE(prfum(PLDL1KEEP, MemOperand(x1), option), "prfum pldl1keep, [x1]");
2088 COMPARE(prfum(PLDL1STRM, MemOperand(x1, 8), option),
2089 "prfum pldl1strm, [x1, #8]");
2090 COMPARE(prfum(PLDL2KEEP, MemOperand(x1, 248), option),
2091 "prfum pldl2keep, [x1, #248]");
2092 COMPARE(prfum(PLDL2STRM, MemOperand(x1, 1), option),
2093 "prfum pldl2strm, [x1, #1]");
2094 COMPARE(prfum(PLDL3KEEP, MemOperand(x1, -1), option),
2095 "prfum pldl3keep, [x1, #-1]");
2096 COMPARE(prfum(PLDL3STRM, MemOperand(x1, 255), option),
2097 "prfum pldl3strm, [x1, #255]");
2098 COMPARE(prfum(PLIL1KEEP, MemOperand(x1, -256), option),
2099 "prfum plil1keep, [x1, #-256]");
2100
2101 // Require scaled-offset forms..
2102 option = RequireScaledOffset;
2103
2104 COMPARE(prfm(PLDL1KEEP, MemOperand(x1), option), "prfm pldl1keep, [x1]");
2105 COMPARE(prfm(PLDL1STRM, MemOperand(x1, 8), option),
2106 "prfm pldl1strm, [x1, #8]");
2107 COMPARE(prfm(PLDL2KEEP, MemOperand(x1, 248), option),
2108 "prfm pldl2keep, [x1, #248]");
2109 COMPARE(prfm(PLIL2STRM, MemOperand(x1, 256), option),
2110 "prfm plil2strm, [x1, #256]");
2111 COMPARE(prfm(PLIL3KEEP, MemOperand(x1, 32760), option),
2112 "prfm plil3keep, [x1, #32760]");
2113
2114 // Prefer unscaled-offset forms, but allow scaled-offset forms if necessary.
2115 option = PreferUnscaledOffset;
2116
2117 COMPARE(prfum(PLDL1KEEP, MemOperand(x1), option), "prfum pldl1keep, [x1]");
2118 COMPARE(prfum(PLDL1STRM, MemOperand(x1, 8), option),
2119 "prfum pldl1strm, [x1, #8]");
2120 COMPARE(prfum(PLDL2KEEP, MemOperand(x1, 248), option),
2121 "prfum pldl2keep, [x1, #248]");
2122 COMPARE(prfum(PLDL2STRM, MemOperand(x1, 1), option),
2123 "prfum pldl2strm, [x1, #1]");
2124 COMPARE(prfum(PLDL3KEEP, MemOperand(x1, -1), option),
2125 "prfum pldl3keep, [x1, #-1]");
2126 COMPARE(prfum(PLDL3STRM, MemOperand(x1, 255), option),
2127 "prfum pldl3strm, [x1, #255]");
2128 COMPARE(prfum(PLIL1KEEP, MemOperand(x1, -256), option),
2129 "prfum plil1keep, [x1, #-256]");
2130 COMPARE(prfum(PLIL1STRM, MemOperand(x1, 256), option),
2131 "prfm plil1strm, [x1, #256]");
2132 COMPARE(prfum(PLIL2KEEP, MemOperand(x1, 32760), option),
2133 "prfm plil2keep, [x1, #32760]");
2134
2135 // Prefer scaled-offset forms, but allow unscaled-offset forms if necessary.
2136 option = PreferScaledOffset;
2137
2138 COMPARE(prfm(PLDL1KEEP, MemOperand(x1), option), "prfm pldl1keep, [x1]");
2139 COMPARE(prfm(PLDL1STRM, MemOperand(x1, 8), option),
2140 "prfm pldl1strm, [x1, #8]");
2141 COMPARE(prfm(PLDL2KEEP, MemOperand(x1, 248), option),
2142 "prfm pldl2keep, [x1, #248]");
2143 COMPARE(prfm(PLDL2STRM, MemOperand(x1, 1), option),
2144 "prfum pldl2strm, [x1, #1]");
2145 COMPARE(prfm(PLDL3KEEP, MemOperand(x1, -1), option),
2146 "prfum pldl3keep, [x1, #-1]");
2147 COMPARE(prfm(PLDL3STRM, MemOperand(x1, 255), option),
2148 "prfum pldl3strm, [x1, #255]");
2149 COMPARE(prfm(PLIL1KEEP, MemOperand(x1, -256), option),
2150 "prfum plil1keep, [x1, #-256]");
2151 COMPARE(prfm(PLIL1STRM, MemOperand(x1, 256), option),
2152 "prfm plil1strm, [x1, #256]");
2153 COMPARE(prfm(PLIL2KEEP, MemOperand(x1, 32760), option),
2154 "prfm plil2keep, [x1, #32760]");
2155
2156 CLEANUP();
2157 }
2158
2159
TEST(cond_select)2160 TEST(cond_select) {
2161 SETUP();
2162
2163 COMPARE(csel(w0, w1, w2, eq), "csel w0, w1, w2, eq");
2164 COMPARE(csel(x3, x4, x5, ne), "csel x3, x4, x5, ne");
2165 COMPARE(csinc(w6, w7, w8, hs), "csinc w6, w7, w8, hs");
2166 COMPARE(csinc(x9, x10, x11, lo), "csinc x9, x10, x11, lo");
2167 COMPARE(csinv(w12, w13, w14, mi), "csinv w12, w13, w14, mi");
2168 COMPARE(csinv(x15, x16, x17, pl), "csinv x15, x16, x17, pl");
2169 COMPARE(csneg(w18, w19, w20, vs), "csneg w18, w19, w20, vs");
2170 COMPARE(csneg(x21, x22, x23, vc), "csneg x21, x22, x23, vc");
2171 COMPARE(cset(w24, hi), "cset w24, hi");
2172 COMPARE(cset(x25, ls), "cset x25, ls");
2173 COMPARE(csetm(w26, ge), "csetm w26, ge");
2174 COMPARE(csetm(x27, lt), "csetm x27, lt");
2175 COMPARE(cinc(w28, w29, gt), "cinc w28, w29, gt");
2176 COMPARE(cinc(x30, x0, le), "cinc x30, x0, le");
2177 COMPARE(cinv(w1, w2, eq), "cinv w1, w2, eq");
2178 COMPARE(cinv(x3, x4, ne), "cinv x3, x4, ne");
2179 COMPARE(cneg(w5, w6, hs), "cneg w5, w6, hs");
2180 COMPARE(cneg(x7, x8, lo), "cneg x7, x8, lo");
2181
2182 COMPARE(csel(x0, x1, x2, al), "csel x0, x1, x2, al");
2183 COMPARE(csel(x1, x2, x3, nv), "csel x1, x2, x3, nv");
2184 COMPARE(csinc(x2, x3, x4, al), "csinc x2, x3, x4, al");
2185 COMPARE(csinc(x3, x4, x5, nv), "csinc x3, x4, x5, nv");
2186 COMPARE(csinv(x4, x5, x6, al), "csinv x4, x5, x6, al");
2187 COMPARE(csinv(x5, x6, x7, nv), "csinv x5, x6, x7, nv");
2188 COMPARE(csneg(x6, x7, x8, al), "csneg x6, x7, x8, al");
2189 COMPARE(csneg(x7, x8, x9, nv), "csneg x7, x8, x9, nv");
2190
2191 CLEANUP();
2192 }
2193
2194
TEST(cond_select_macro)2195 TEST(cond_select_macro) {
2196 SETUP();
2197
2198 // In the tests below we also test the `GetCselSynthesisInformation()` helper.
2199 // These tests are here (rather than in test-assembler-aarch64.cc) because the
2200 // disassembly makes it easy to see whether or not the inputs are synthesised.
2201 bool synthesises_left = false;
2202 bool synthesises_right = false;
2203
2204 COMPARE_MACRO(Csel(w0, w1, -1, eq), "csinv w0, w1, wzr, eq");
2205 MacroAssembler::GetCselSynthesisInformation(w0,
2206 w1,
2207 -1,
2208 &synthesises_left,
2209 &synthesises_right);
2210 VIXL_CHECK(!synthesises_left && !synthesises_right);
2211
2212 COMPARE_MACRO(Csel(w2, w3, 0, ne), "csel w2, w3, wzr, ne");
2213 MacroAssembler::GetCselSynthesisInformation(w2,
2214 w3,
2215 wzr,
2216 &synthesises_left,
2217 &synthesises_right);
2218 VIXL_CHECK(!synthesises_left && !synthesises_right);
2219
2220 COMPARE_MACRO(Csel(w4, w5, 1, hs), "csinc w4, w5, wzr, hs");
2221 MacroAssembler::GetCselSynthesisInformation(w4,
2222 w5,
2223 1,
2224 &synthesises_left,
2225 &synthesises_right);
2226 VIXL_CHECK(!synthesises_left && !synthesises_right);
2227
2228 COMPARE_MACRO(Csel(x6, x7, -1, lo), "csinv x6, x7, xzr, lo");
2229 MacroAssembler::GetCselSynthesisInformation(x6,
2230 x7,
2231 xzr,
2232 &synthesises_left,
2233 &synthesises_right);
2234 VIXL_CHECK(!synthesises_left && !synthesises_right);
2235
2236 COMPARE_MACRO(Csel(x8, x9, 0, mi), "csel x8, x9, xzr, mi");
2237 MacroAssembler::GetCselSynthesisInformation(x8,
2238 x9,
2239 xzr,
2240 &synthesises_left,
2241 &synthesises_right);
2242 VIXL_CHECK(!synthesises_left && !synthesises_right);
2243
2244 COMPARE_MACRO(Csel(x10, x11, 1, pl), "csinc x10, x11, xzr, pl");
2245 MacroAssembler::GetCselSynthesisInformation(x10,
2246 x11,
2247 xzr,
2248 &synthesises_left,
2249 &synthesises_right);
2250 VIXL_CHECK(!synthesises_left && !synthesises_right);
2251
2252 COMPARE_MACRO(Csel(x12, 0, 0, eq), "mov x12, #0x0");
2253 MacroAssembler::GetCselSynthesisInformation(x12,
2254 0,
2255 0,
2256 &synthesises_left,
2257 &synthesises_right);
2258 VIXL_CHECK(!synthesises_left && !synthesises_right);
2259
2260 COMPARE_MACRO(Csel(w13, 0, 1, eq), "cset w13, ne");
2261 MacroAssembler::GetCselSynthesisInformation(w13,
2262 0,
2263 1,
2264 &synthesises_left,
2265 &synthesises_right);
2266 VIXL_CHECK(!synthesises_left && !synthesises_right);
2267
2268 COMPARE_MACRO(Csel(x14, 1, 0, eq), "cset x14, eq");
2269 MacroAssembler::GetCselSynthesisInformation(x14,
2270 1,
2271 0,
2272 &synthesises_left,
2273 &synthesises_right);
2274 VIXL_CHECK(!synthesises_left && !synthesises_right);
2275
2276 COMPARE_MACRO(Csel(w15, 0, -1, eq), "csetm w15, ne");
2277 MacroAssembler::GetCselSynthesisInformation(w15,
2278 0,
2279 -1,
2280 &synthesises_left,
2281 &synthesises_right);
2282 VIXL_CHECK(!synthesises_left && !synthesises_right);
2283
2284 COMPARE_MACRO(Csel(x18, -1, 0, eq), "csetm x18, eq");
2285 MacroAssembler::GetCselSynthesisInformation(x18,
2286 -1,
2287 0,
2288 &synthesises_left,
2289 &synthesises_right);
2290 VIXL_CHECK(!synthesises_left && !synthesises_right);
2291
2292 COMPARE_MACRO(Csel(w19, -1, 1, eq),
2293 "mov w19, #0x1\n"
2294 "cneg w19, w19, eq");
2295 MacroAssembler::GetCselSynthesisInformation(w19,
2296 -1,
2297 1,
2298 &synthesises_left,
2299 &synthesises_right);
2300 VIXL_CHECK(!synthesises_left && synthesises_right);
2301
2302 COMPARE_MACRO(Csel(x20, 1, -1, eq),
2303 "mov x20, #0xffffffffffffffff\n"
2304 "cneg x20, x20, eq");
2305 MacroAssembler::GetCselSynthesisInformation(x20,
2306 1,
2307 -1,
2308 &synthesises_left,
2309 &synthesises_right);
2310 VIXL_CHECK(!synthesises_left && synthesises_right);
2311
2312 COMPARE_MACRO(Csel(w21, 0xaa, 0xbb, eq),
2313 "mov w16, #0xaa\n"
2314 "mov w17, #0xbb\n"
2315 "csel w21, w16, w17, eq");
2316 MacroAssembler::GetCselSynthesisInformation(w21,
2317 0xaa,
2318 0xbb,
2319 &synthesises_left,
2320 &synthesises_right);
2321 VIXL_CHECK(synthesises_left && synthesises_right);
2322
2323 COMPARE_MACRO(Csel(x22, 0xaa, -0xbb, eq),
2324 "mov x16, #0xaa\n"
2325 "mov x17, #0xffffffffffffff45\n"
2326 "csel x22, x16, x17, eq");
2327 MacroAssembler::GetCselSynthesisInformation(x22,
2328 0xaa,
2329 -0xbb,
2330 &synthesises_left,
2331 &synthesises_right);
2332 VIXL_CHECK(synthesises_left && synthesises_right);
2333
2334 COMPARE_MACRO(Csel(w23, 0, 0xaa, eq),
2335 "mov w16, #0xaa\n"
2336 "csel w23, w16, wzr, ne");
2337 MacroAssembler::GetCselSynthesisInformation(w23,
2338 0,
2339 0xaa,
2340 &synthesises_left,
2341 &synthesises_right);
2342 VIXL_CHECK(!synthesises_left && synthesises_right);
2343
2344 COMPARE_MACRO(Csel(x24, -0xaa, 0, eq),
2345 "mov x16, #0xffffffffffffff56\n"
2346 "csel x24, x16, xzr, eq");
2347 MacroAssembler::GetCselSynthesisInformation(x24,
2348 -0xaa,
2349 0,
2350 &synthesises_left,
2351 &synthesises_right);
2352 VIXL_CHECK(synthesises_left && !synthesises_right);
2353
2354 COMPARE_MACRO(Csel(w25, 0xcc, -0xcc, eq),
2355 "mov w25, #0xffffff34\n"
2356 "cneg w25, w25, eq");
2357 MacroAssembler::GetCselSynthesisInformation(w25,
2358 0xcc,
2359 -0xcc,
2360 &synthesises_left,
2361 &synthesises_right);
2362 VIXL_CHECK(!synthesises_left && synthesises_right);
2363
2364 COMPARE_MACRO(Csel(x26, -0xcc, 0xcc, eq),
2365 "mov x26, #0xcc\n"
2366 "cneg x26, x26, eq");
2367 MacroAssembler::GetCselSynthesisInformation(w25,
2368 -0xcc,
2369 0xcc,
2370 &synthesises_left,
2371 &synthesises_right);
2372 VIXL_CHECK(!synthesises_left && synthesises_right);
2373
2374 // Test with `Operand` inputs.
2375 COMPARE_MACRO(Csel(x0, x1, Operand(x2, LSL, 3), eq),
2376 "lsl x16, x2, #3\n"
2377 "csel x0, x1, x16, eq");
2378 MacroAssembler::GetCselSynthesisInformation(x0,
2379 x1,
2380 Operand(x2, LSL, 3),
2381 &synthesises_left,
2382 &synthesises_right);
2383 VIXL_CHECK(!synthesises_left && synthesises_right);
2384
2385 COMPARE_MACRO(Csel(x3, x4, Operand(x5, SXTH), eq),
2386 "sxth x16, w5\n"
2387 "csel x3, x4, x16, eq");
2388 MacroAssembler::GetCselSynthesisInformation(x3,
2389 x4,
2390 Operand(x5, SXTH),
2391 &synthesises_left,
2392 &synthesises_right);
2393 VIXL_CHECK(!synthesises_left && synthesises_right);
2394
2395 COMPARE_MACRO(Csel(x6, Operand(x7, LSL, 7), x8, eq),
2396 "lsl x16, x7, #7\n"
2397 "csel x6, x16, x8, eq");
2398 MacroAssembler::GetCselSynthesisInformation(x6,
2399 Operand(x7, LSL, 7),
2400 x8,
2401 &synthesises_left,
2402 &synthesises_right);
2403 VIXL_CHECK(synthesises_left && !synthesises_right);
2404
2405 COMPARE_MACRO(Csel(x9, Operand(x10, SXTH), x11, eq),
2406 "sxth x16, w10\n"
2407 "csel x9, x16, x11, eq");
2408 MacroAssembler::GetCselSynthesisInformation(x9,
2409 Operand(x10, SXTH),
2410 x11,
2411 &synthesises_left,
2412 &synthesises_right);
2413 VIXL_CHECK(synthesises_left && !synthesises_right);
2414
2415 COMPARE_MACRO(Csel(x12, Operand(x13, LSL, 13), Operand(x14, SXTB), eq),
2416 "lsl x16, x13, #13\n"
2417 "sxtb x17, w14\n"
2418 "csel x12, x16, x17, eq");
2419 MacroAssembler::GetCselSynthesisInformation(x12,
2420 Operand(x13, LSL, 13),
2421 Operand(x14, SXTB),
2422 &synthesises_left,
2423 &synthesises_right);
2424 VIXL_CHECK(synthesises_left && synthesises_right);
2425
2426 COMPARE_MACRO(Csel(x15, 0, Operand(x18, LSR, 18), eq),
2427 "lsr x16, x18, #18\n"
2428 "csel x15, x16, xzr, ne");
2429 MacroAssembler::GetCselSynthesisInformation(x15,
2430 0,
2431 Operand(x18, LSR, 18),
2432 &synthesises_left,
2433 &synthesises_right);
2434 VIXL_CHECK(!synthesises_left && synthesises_right);
2435
2436 // Test with the zero register.
2437 COMPARE_MACRO(Csel(w19, wzr, wzr, eq), "mov w19, #0x0");
2438 MacroAssembler::GetCselSynthesisInformation(w19,
2439 wzr,
2440 wzr,
2441 &synthesises_left,
2442 &synthesises_right);
2443 VIXL_CHECK(!synthesises_left && !synthesises_right);
2444
2445 COMPARE_MACRO(Csel(x20, x21, xzr, eq), "csel x20, x21, xzr, eq");
2446 MacroAssembler::GetCselSynthesisInformation(x20,
2447 x21,
2448 xzr,
2449 &synthesises_left,
2450 &synthesises_right);
2451 VIXL_CHECK(!synthesises_left && !synthesises_right);
2452
2453 COMPARE_MACRO(Csel(w22, wzr, w23, eq), "csel w22, w23, wzr, ne");
2454 MacroAssembler::GetCselSynthesisInformation(w22,
2455 wzr,
2456 w23,
2457 &synthesises_left,
2458 &synthesises_right);
2459 VIXL_CHECK(!synthesises_left && !synthesises_right);
2460
2461 COMPARE_MACRO(Csel(x24, xzr, 0, eq), "mov x24, #0x0");
2462 MacroAssembler::GetCselSynthesisInformation(x24,
2463 xzr,
2464 0,
2465 &synthesises_left,
2466 &synthesises_right);
2467 VIXL_CHECK(!synthesises_left && !synthesises_right);
2468
2469 COMPARE_MACRO(Csel(w25, wzr, 1, eq), "cset w25, ne");
2470 MacroAssembler::GetCselSynthesisInformation(w25,
2471 wzr,
2472 1,
2473 &synthesises_left,
2474 &synthesises_right);
2475 VIXL_CHECK(!synthesises_left && !synthesises_right);
2476
2477
2478 CLEANUP();
2479 }
2480
2481
TEST(cond_cmp)2482 TEST(cond_cmp) {
2483 SETUP();
2484
2485 COMPARE(ccmn(w0, w1, NZCVFlag, eq), "ccmn w0, w1, #NZCV, eq");
2486 COMPARE(ccmn(x2, x3, NZCFlag, ne), "ccmn x2, x3, #NZCv, ne");
2487 COMPARE(ccmp(w4, w5, NZVFlag, hs), "ccmp w4, w5, #NZcV, hs");
2488 COMPARE(ccmp(x6, x7, NZFlag, lo), "ccmp x6, x7, #NZcv, lo");
2489 COMPARE(ccmn(w8, 31, NFlag, mi), "ccmn w8, #31, #Nzcv, mi");
2490 COMPARE(ccmn(x9, 30, NCFlag, pl), "ccmn x9, #30, #NzCv, pl");
2491 COMPARE(ccmp(w10, 29, NVFlag, vs), "ccmp w10, #29, #NzcV, vs");
2492 COMPARE(ccmp(x11, 28, NFlag, vc), "ccmp x11, #28, #Nzcv, vc");
2493 COMPARE(ccmn(w12, w13, NoFlag, al), "ccmn w12, w13, #nzcv, al");
2494 COMPARE(ccmp(x14, 27, ZVFlag, nv), "ccmp x14, #27, #nZcV, nv");
2495
2496 CLEANUP();
2497 }
2498
2499
TEST(cond_cmp_macro)2500 TEST(cond_cmp_macro) {
2501 SETUP();
2502
2503 COMPARE_MACRO(Ccmp(w0, -1, VFlag, hi), "ccmn w0, #1, #nzcV, hi");
2504 COMPARE_MACRO(Ccmp(x1, -31, CFlag, ge), "ccmn x1, #31, #nzCv, ge");
2505 COMPARE_MACRO(Ccmn(w2, -1, CVFlag, gt), "ccmp w2, #1, #nzCV, gt");
2506 COMPARE_MACRO(Ccmn(x3, -31, ZCVFlag, ls), "ccmp x3, #31, #nZCV, ls");
2507
2508 CLEANUP();
2509 }
2510
2511
TEST(system_clrex)2512 TEST(system_clrex) {
2513 SETUP();
2514
2515 COMPARE(clrex(0), "clrex #0x0");
2516 COMPARE(clrex(14), "clrex #0xe");
2517 COMPARE(clrex(15), "clrex");
2518 COMPARE(clrex(), "clrex");
2519
2520 CLEANUP();
2521 }
2522
2523
TEST(system_mrs)2524 TEST(system_mrs) {
2525 SETUP();
2526
2527 COMPARE(mrs(x0, NZCV), "mrs x0, nzcv");
2528 COMPARE(mrs(x30, NZCV), "mrs x30, nzcv");
2529 COMPARE(mrs(x15, FPCR), "mrs x15, fpcr");
2530 COMPARE(mrs(x20, RNDR), "mrs x20, rndr");
2531 COMPARE(mrs(x5, RNDRRS), "mrs x5, rndrrs");
2532
2533 // Test mrs that use system registers we haven't named.
2534 COMPARE(dci(MRS | (0x5555 << 5)), "mrs x0, S3_2_c10_c10_5");
2535 COMPARE(dci(0xd53e1000), "mrs x0, S3_6_c1_c0_0");
2536
2537 CLEANUP();
2538 }
2539
2540
TEST(system_msr)2541 TEST(system_msr) {
2542 SETUP();
2543
2544 COMPARE(msr(NZCV, x0), "msr nzcv, x0");
2545 COMPARE(msr(NZCV, x30), "msr nzcv, x30");
2546 COMPARE(msr(FPCR, x15), "msr fpcr, x15");
2547
2548 // Test msr that use system registers we haven't named.
2549 COMPARE(dci(MSR | (0x1234 << 5)), "msr S2_2_c4_c6_4, x0");
2550 COMPARE(dci(0xd51e1000), "msr S3_6_c1_c0_0, x0");
2551
2552 CLEANUP();
2553 }
2554
2555
TEST(system_pstate)2556 TEST(system_pstate) {
2557 SETUP();
2558
2559 COMPARE(cfinv(), "cfinv");
2560 COMPARE(axflag(), "axflag");
2561 COMPARE(xaflag(), "xaflag");
2562
2563 CLEANUP();
2564 }
2565
2566
TEST(system_sys)2567 TEST(system_sys) {
2568 SETUP();
2569
2570 COMPARE(sys(0x3, 0x7, 0x5, 0x1, x1), "ic ivau, x1");
2571 COMPARE(sys(0x3, 0x7, 0xa, 0x1, x2), "dc cvac, x2");
2572 COMPARE(sys(0x3, 0x7, 0xb, 0x1, x3), "dc cvau, x3");
2573 COMPARE(sys(0x3, 0x7, 0xe, 0x1, x4), "dc civac, x4");
2574 COMPARE(sys(0x3, 0x7, 0xc, 0x1, x5), "dc cvap, x5");
2575 COMPARE(sys(0x3, 0x7, 0xd, 0x1, x6), "dc cvadp, x6");
2576 COMPARE(sys(0x3, 0x7, 0x4, 0x1, x0), "dc zva, x0");
2577 COMPARE(sys(0x0, 0x0, 0x0, 0x0, x0), "sys #0, C0, C0, #0, x0");
2578 COMPARE(sys(0x1, 0x2, 0x5, 0x2, x5), "sys #1, C2, C5, #2, x5");
2579 COMPARE(sys(0x2, 0x8, 0xa, 0x3, x6), "sys #2, C8, C10, #3, x6");
2580 COMPARE(sys(0x2, 0xf, 0xf, 0x1, xzr), "sys #2, C15, C15, #1");
2581 COMPARE(sys(0x2, 0xf, 0xf, 0x1), "sys #2, C15, C15, #1");
2582
2583 CLEANUP();
2584 }
2585
2586
TEST(system_ic)2587 TEST(system_ic) {
2588 SETUP();
2589
2590 COMPARE(ic(IVAU, x0), "ic ivau, x0");
2591 COMPARE(ic(IVAU, x1), "ic ivau, x1");
2592 COMPARE(ic(IVAU, xzr), "ic ivau, xzr");
2593
2594 CLEANUP();
2595 }
2596
2597
TEST(system_dc)2598 TEST(system_dc) {
2599 SETUP();
2600
2601 COMPARE(dc(CVAC, x2), "dc cvac, x2");
2602 COMPARE(dc(CVAU, x3), "dc cvau, x3");
2603 COMPARE(dc(CVAP, x4), "dc cvap, x4");
2604 COMPARE(dc(CIVAC, x5), "dc civac, x5");
2605 COMPARE(dc(CVADP, x6), "dc cvadp, x6");
2606 COMPARE(dc(ZVA, x0), "dc zva, x0");
2607 COMPARE(dc(ZVA, xzr), "dc zva, xzr");
2608
2609 CLEANUP();
2610 }
2611
2612
TEST(system_nop)2613 TEST(system_nop) {
2614 SETUP();
2615
2616 COMPARE(nop(), "nop");
2617 COMPARE_MACRO(Nop(), "nop");
2618
2619 CLEANUP();
2620 }
2621
2622
TEST(system_pauth)2623 TEST(system_pauth) {
2624 SETUP();
2625
2626 COMPARE(pacia1716(), "pacia1716");
2627 COMPARE(pacib1716(), "pacib1716");
2628 COMPARE(paciaz(), "paciaz");
2629 COMPARE(pacibz(), "pacibz");
2630 COMPARE(paciasp(), "paciasp");
2631 COMPARE(pacibsp(), "pacibsp");
2632 COMPARE(autia1716(), "autia1716");
2633 COMPARE(autib1716(), "autib1716");
2634 COMPARE(autiaz(), "autiaz");
2635 COMPARE(autibz(), "autibz");
2636 COMPARE(autiasp(), "autiasp");
2637 COMPARE(autibsp(), "autibsp");
2638 COMPARE(xpaclri(), "xpaclri");
2639
2640 CLEANUP();
2641 }
2642
2643
TEST(unreachable)2644 TEST(unreachable) {
2645 SETUP();
2646
2647 VIXL_ASSERT(kUnreachableOpcode == 0xdeb0);
2648 #ifdef VIXL_INCLUDE_SIMULATOR_AARCH64
2649 COMPARE_MACRO(Unreachable(), "hlt #0xdeb0");
2650 #else
2651 COMPARE_MACRO(Unreachable(), "udf #0xdeb0");
2652 #endif
2653
2654 CLEANUP();
2655 }
2656
2657
2658 #ifdef VIXL_INCLUDE_SIMULATOR_AARCH64
TEST(trace)2659 TEST(trace) {
2660 SETUP();
2661
2662 VIXL_ASSERT(kTraceOpcode == 0xdeb2);
2663
2664 // All Trace calls should produce the same instruction.
2665 COMPARE_MACRO_PREFIX(Trace(LOG_ALL, TRACE_ENABLE), "hlt #0xdeb2");
2666 COMPARE_MACRO_PREFIX(Trace(LOG_REGS, TRACE_DISABLE), "hlt #0xdeb2");
2667
2668 CLEANUP();
2669 }
2670 #endif
2671
2672
2673 #ifdef VIXL_INCLUDE_SIMULATOR_AARCH64
TEST(log)2674 TEST(log) {
2675 SETUP();
2676
2677 VIXL_ASSERT(kLogOpcode == 0xdeb3);
2678
2679 // All Log calls should produce the same instruction.
2680 COMPARE_MACRO_PREFIX(Log(LOG_ALL), "hlt #0xdeb3");
2681 COMPARE_MACRO_PREFIX(Log(LOG_SYSREGS), "hlt #0xdeb3");
2682
2683 CLEANUP();
2684 }
2685 #endif
2686
2687
TEST(hlt)2688 TEST(hlt) {
2689 SETUP();
2690
2691 COMPARE(hlt(0), "hlt #0x0");
2692 COMPARE(hlt(1), "hlt #0x1");
2693 COMPARE(hlt(65535), "hlt #0xffff");
2694
2695 CLEANUP();
2696 }
2697
2698
TEST(brk)2699 TEST(brk) {
2700 SETUP();
2701
2702 COMPARE(brk(0), "brk #0x0");
2703 COMPARE(brk(1), "brk #0x1");
2704 COMPARE(brk(65535), "brk #0xffff");
2705
2706 CLEANUP();
2707 }
2708
2709
TEST(svc)2710 TEST(svc) {
2711 SETUP();
2712
2713 COMPARE(svc(0), "svc #0x0");
2714 COMPARE(svc(1), "svc #0x1");
2715 COMPARE(svc(65535), "svc #0xffff");
2716
2717 CLEANUP();
2718 }
2719
2720
TEST(add_sub_negative)2721 TEST(add_sub_negative) {
2722 SETUP();
2723
2724 COMPARE_MACRO(Add(x10, x0, -42), "sub x10, x0, #0x2a (42)");
2725 COMPARE_MACRO(Add(x11, x1, -687), "sub x11, x1, #0x2af (687)");
2726 COMPARE_MACRO(Add(x12, x2, -0x88), "sub x12, x2, #0x88 (136)");
2727
2728 COMPARE_MACRO(Sub(x13, x0, -600), "add x13, x0, #0x258 (600)");
2729 COMPARE_MACRO(Sub(x14, x1, -313), "add x14, x1, #0x139 (313)");
2730 COMPARE_MACRO(Sub(x15, x2, -0x555), "add x15, x2, #0x555 (1365)");
2731
2732 COMPARE_MACRO(Add(w19, w3, -0x344), "sub w19, w3, #0x344 (836)");
2733 COMPARE_MACRO(Add(w20, w4, -2000), "sub w20, w4, #0x7d0 (2000)");
2734
2735 COMPARE_MACRO(Add(w0, w1, 5, LeaveFlags), "add w0, w1, #0x5 (5)");
2736 COMPARE_MACRO(Add(w1, w2, 15, SetFlags), "adds w1, w2, #0xf (15)");
2737
2738 COMPARE_MACRO(Sub(w0, w1, 5, LeaveFlags), "sub w0, w1, #0x5 (5)");
2739 COMPARE_MACRO(Sub(w1, w2, 15, SetFlags), "subs w1, w2, #0xf (15)");
2740
2741 COMPARE_MACRO(Sub(w21, w3, -0xbc), "add w21, w3, #0xbc (188)");
2742 COMPARE_MACRO(Sub(w22, w4, -2000), "add w22, w4, #0x7d0 (2000)");
2743
2744 COMPARE_MACRO(Cmp(w0, -1), "cmn w0, #0x1 (1)");
2745 COMPARE_MACRO(Cmp(x1, -1), "cmn x1, #0x1 (1)");
2746 COMPARE_MACRO(Cmp(w2, -4095), "cmn w2, #0xfff (4095)");
2747 COMPARE_MACRO(Cmp(x3, -4095), "cmn x3, #0xfff (4095)");
2748
2749 COMPARE_MACRO(Cmn(w0, -1), "cmp w0, #0x1 (1)");
2750 COMPARE_MACRO(Cmn(x1, -1), "cmp x1, #0x1 (1)");
2751 COMPARE_MACRO(Cmn(w2, -4095), "cmp w2, #0xfff (4095)");
2752 COMPARE_MACRO(Cmn(x3, -4095), "cmp x3, #0xfff (4095)");
2753
2754 CLEANUP();
2755 }
2756
TEST(add_sub_macro)2757 TEST(add_sub_macro) {
2758 SETUP();
2759
2760 // Add and Sub use their destination register as a scratch if they can.
2761 COMPARE_MACRO(Add(x0, x1, 0x4242),
2762 "mov x0, #0x4242\n"
2763 "add x0, x1, x0");
2764 COMPARE_MACRO(Add(x0, x0, 0x4242),
2765 "mov x16, #0x4242\n"
2766 "add x0, x0, x16");
2767 COMPARE_MACRO(Adds(x0, xzr, Operand(w1, SXTW)),
2768 "sxtw x0, w1\n"
2769 "adds x0, xzr, x0");
2770 COMPARE_MACRO(Sub(x0, x1, 0x4242),
2771 "mov x0, #0x4242\n"
2772 "sub x0, x1, x0");
2773 COMPARE_MACRO(Sub(x0, x0, 0x4242),
2774 "mov x16, #0x4242\n"
2775 "sub x0, x0, x16");
2776 COMPARE_MACRO(Subs(x0, xzr, Operand(w1, SXTW)),
2777 "sxtw x0, w1\n"
2778 "negs x0, x0");
2779 }
2780
TEST(adc_sbc_macro)2781 TEST(adc_sbc_macro) {
2782 SETUP();
2783
2784 // Adc and Sbc use their destination register as a scratch if they can.
2785 COMPARE_MACRO(Adc(x0, x1, 0x4242),
2786 "mov x0, #0x4242\n"
2787 "adc x0, x1, x0");
2788 COMPARE_MACRO(Adc(x0, x0, 0x4242),
2789 "mov x16, #0x4242\n"
2790 "adc x0, x0, x16");
2791 COMPARE_MACRO(Adcs(x0, xzr, Operand(w1, SXTW)),
2792 "sxtw x0, w1\n"
2793 "adcs x0, xzr, x0");
2794 COMPARE_MACRO(Sbc(x0, x1, 0x4242),
2795 "mov x0, #0x4242\n"
2796 "sbc x0, x1, x0");
2797 COMPARE_MACRO(Sbc(x0, x0, 0x4242),
2798 "mov x16, #0x4242\n"
2799 "sbc x0, x0, x16");
2800 COMPARE_MACRO(Sbcs(x0, xzr, Operand(w1, SXTW)),
2801 "sxtw x0, w1\n"
2802 "ngcs x0, x0");
2803 }
2804
TEST(logical_immediate_move)2805 TEST(logical_immediate_move) {
2806 SETUP();
2807
2808 COMPARE_MACRO(And(w0, w1, 0), "mov w0, #0x0");
2809 COMPARE_MACRO(And(x0, x1, 0), "mov x0, #0x0");
2810 COMPARE_MACRO(Orr(w2, w3, 0), "mov w2, w3");
2811 COMPARE_MACRO(Orr(x2, x3, 0), "mov x2, x3");
2812 COMPARE_MACRO(Eor(w4, w5, 0), "mov w4, w5");
2813 COMPARE_MACRO(Eor(x4, x5, 0), "mov x4, x5");
2814 COMPARE_MACRO(Bic(w6, w7, 0), "mov w6, w7");
2815 COMPARE_MACRO(Bic(x6, x7, 0), "mov x6, x7");
2816 COMPARE_MACRO(Orn(w8, w9, 0), "mov w8, #0xffffffff");
2817 COMPARE_MACRO(Orn(x8, x9, 0), "mov x8, #0xffffffffffffffff");
2818 COMPARE_MACRO(Eon(w10, w11, 0), "mvn w10, w11");
2819 COMPARE_MACRO(Eon(x10, x11, 0), "mvn x10, x11");
2820
2821 COMPARE_MACRO(And(w12, w13, 0xffffffff), "mov w12, w13");
2822 COMPARE_MACRO(And(x12, x13, 0xffffffff), "and x12, x13, #0xffffffff");
2823 COMPARE_MACRO(And(x12, x13, 0xffffffffffffffff), "mov x12, x13");
2824 COMPARE_MACRO(Orr(w14, w15, 0xffffffff), "mov w14, #0xffffffff");
2825 COMPARE_MACRO(Orr(x14, x15, 0xffffffff), "orr x14, x15, #0xffffffff");
2826 COMPARE_MACRO(Orr(x14, x15, 0xffffffffffffffff),
2827 "mov x14, #0xffffffffffffffff");
2828 COMPARE_MACRO(Eor(w16, w17, 0xffffffff), "mvn w16, w17");
2829 COMPARE_MACRO(Eor(x16, x17, 0xffffffff), "eor x16, x17, #0xffffffff");
2830 COMPARE_MACRO(Eor(x16, x17, 0xffffffffffffffff), "mvn x16, x17");
2831 COMPARE_MACRO(Bic(w18, w19, 0xffffffff), "mov w18, #0x0");
2832 COMPARE_MACRO(Bic(x18, x19, 0xffffffff), "and x18, x19, #0xffffffff00000000");
2833 COMPARE_MACRO(Bic(x18, x19, 0xffffffffffffffff), "mov x18, #0x0");
2834 COMPARE_MACRO(Orn(w20, w21, 0xffffffff), "mov w20, w21");
2835 COMPARE_MACRO(Orn(x20, x21, 0xffffffff), "orr x20, x21, #0xffffffff00000000");
2836 COMPARE_MACRO(Orn(x20, x21, 0xffffffffffffffff), "mov x20, x21");
2837 COMPARE_MACRO(Eon(w22, w23, 0xffffffff), "mov w22, w23");
2838 COMPARE_MACRO(Eon(x22, x23, 0xffffffff), "eor x22, x23, #0xffffffff00000000");
2839 COMPARE_MACRO(Eon(x22, x23, 0xffffffffffffffff), "mov x22, x23");
2840
2841 // Test stack pointer with non encodable immediate.
2842 COMPARE_MACRO(Orr(wsp, w5, 0x1234),
2843 "mov w16, #0x1234\n"
2844 "orr w16, w5, w16\n"
2845 "mov wsp, w16");
2846 COMPARE_MACRO(Orr(sp, x15, 0x123),
2847 "mov x16, #0x123\n"
2848 "orr x16, x15, x16\n"
2849 "mov sp, x16");
2850
2851 CLEANUP();
2852 }
2853
TEST(logical_macro)2854 TEST(logical_macro) {
2855 SETUP();
2856
2857 // LogicalMacro uses the destination register as a scratch if it can.
2858 COMPARE_MACRO(And(x0, x1, 0x4242),
2859 "mov x0, #0x4242\n"
2860 "and x0, x1, x0");
2861 COMPARE_MACRO(Bic(x0, x0, 0x4242),
2862 "mov x16, #0xffffffffffffbdbd\n"
2863 "and x0, x0, x16");
2864 COMPARE_MACRO(Orn(x0, xzr, Operand(w1, SXTW)),
2865 "sxtw x0, w1\n"
2866 "mvn x0, x0");
2867 COMPARE_MACRO(Orr(x0, x1, 0x4242),
2868 "mov x0, #0x4242\n"
2869 "orr x0, x1, x0");
2870 COMPARE_MACRO(Ands(x0, x0, 0x4242),
2871 "mov x16, #0x4242\n"
2872 "ands x0, x0, x16");
2873 COMPARE_MACRO(Tst(xzr, Operand(w1, SXTW)),
2874 "sxtw x16, w1\n"
2875 "tst xzr, x16");
2876 }
2877
TEST(barriers)2878 TEST(barriers) {
2879 SETUP();
2880
2881 // DMB
2882 COMPARE_MACRO(Dmb(FullSystem, BarrierAll), "dmb sy");
2883 COMPARE_MACRO(Dmb(FullSystem, BarrierReads), "dmb ld");
2884 COMPARE_MACRO(Dmb(FullSystem, BarrierWrites), "dmb st");
2885
2886 COMPARE_MACRO(Dmb(InnerShareable, BarrierAll), "dmb ish");
2887 COMPARE_MACRO(Dmb(InnerShareable, BarrierReads), "dmb ishld");
2888 COMPARE_MACRO(Dmb(InnerShareable, BarrierWrites), "dmb ishst");
2889
2890 COMPARE_MACRO(Dmb(NonShareable, BarrierAll), "dmb nsh");
2891 COMPARE_MACRO(Dmb(NonShareable, BarrierReads), "dmb nshld");
2892 COMPARE_MACRO(Dmb(NonShareable, BarrierWrites), "dmb nshst");
2893
2894 COMPARE_MACRO(Dmb(OuterShareable, BarrierAll), "dmb osh");
2895 COMPARE_MACRO(Dmb(OuterShareable, BarrierReads), "dmb oshld");
2896 COMPARE_MACRO(Dmb(OuterShareable, BarrierWrites), "dmb oshst");
2897
2898 COMPARE_MACRO(Dmb(FullSystem, BarrierOther), "dmb sy (0b1100)");
2899 COMPARE_MACRO(Dmb(InnerShareable, BarrierOther), "dmb sy (0b1000)");
2900 COMPARE_MACRO(Dmb(NonShareable, BarrierOther), "dmb sy (0b0100)");
2901 COMPARE_MACRO(Dmb(OuterShareable, BarrierOther), "dmb sy (0b0000)");
2902
2903 // DSB
2904 COMPARE_MACRO(Dsb(FullSystem, BarrierAll), "dsb sy");
2905 COMPARE_MACRO(Dsb(FullSystem, BarrierReads), "dsb ld");
2906 COMPARE_MACRO(Dsb(FullSystem, BarrierWrites), "dsb st");
2907
2908 COMPARE_MACRO(Dsb(InnerShareable, BarrierAll), "dsb ish");
2909 COMPARE_MACRO(Dsb(InnerShareable, BarrierReads), "dsb ishld");
2910 COMPARE_MACRO(Dsb(InnerShareable, BarrierWrites), "dsb ishst");
2911
2912 COMPARE_MACRO(Dsb(NonShareable, BarrierAll), "dsb nsh");
2913 COMPARE_MACRO(Dsb(NonShareable, BarrierReads), "dsb nshld");
2914 COMPARE_MACRO(Dsb(NonShareable, BarrierWrites), "dsb nshst");
2915
2916 COMPARE_MACRO(Dsb(OuterShareable, BarrierAll), "dsb osh");
2917 COMPARE_MACRO(Dsb(OuterShareable, BarrierReads), "dsb oshld");
2918 COMPARE_MACRO(Dsb(OuterShareable, BarrierWrites), "dsb oshst");
2919
2920 COMPARE_MACRO(Dsb(FullSystem, BarrierOther), "dsb sy (0b1100)");
2921 COMPARE_MACRO(Dsb(InnerShareable, BarrierOther), "dsb sy (0b1000)");
2922 COMPARE_MACRO(Dsb(NonShareable, BarrierOther), "dsb sy (0b0100)");
2923 COMPARE_MACRO(Dsb(OuterShareable, BarrierOther), "dsb sy (0b0000)");
2924
2925 // ISB
2926 COMPARE_MACRO(Isb(), "isb");
2927
2928 // ESB
2929 COMPARE_MACRO(Esb(), "esb");
2930
2931 // CSDB
2932 COMPARE_MACRO(Csdb(), "csdb");
2933
2934 CLEANUP();
2935 }
2936
TEST(address_map)2937 TEST(address_map) {
2938 // Check that we can disassemble from a fake base address.
2939 SETUP();
2940
2941 disasm.MapCodeAddress(0, masm.GetBuffer()->GetStartAddress<Instruction*>());
2942 COMPARE(ldr(x0, INT64_C(0)), "ldr x0, pc+0 (addr 0x0)");
2943 COMPARE(ldr(x0, -1), "ldr x0, pc-4 (addr -0x4)");
2944 COMPARE(ldr(x0, 1), "ldr x0, pc+4 (addr 0x4)");
2945 COMPARE(prfm(PLIL1KEEP, INT64_C(0)), "prfm plil1keep, pc+0 (addr 0x0)");
2946 COMPARE(prfm(PLIL1KEEP, -1), "prfm plil1keep, pc-4 (addr -0x4)");
2947 COMPARE(prfm(PLIL1KEEP, 1), "prfm plil1keep, pc+4 (addr 0x4)");
2948 COMPARE(adr(x0, INT64_C(0)), "adr x0, #+0x0 (addr 0x0)");
2949 COMPARE(adr(x0, -1), "adr x0, #-0x1 (addr -0x1)");
2950 COMPARE(adr(x0, 1), "adr x0, #+0x1 (addr 0x1)");
2951 COMPARE(adrp(x0, INT64_C(0)), "adrp x0, #+0x0 (addr 0x0)");
2952 COMPARE(adrp(x0, -1), "adrp x0, #-0x1000 (addr -0x1000)");
2953 COMPARE(adrp(x0, 1), "adrp x0, #+0x1000 (addr 0x1000)");
2954 COMPARE(b(INT64_C(0)), "b #+0x0 (addr 0x0)");
2955 COMPARE(b(-1), "b #-0x4 (addr -0x4)");
2956 COMPARE(b(1), "b #+0x4 (addr 0x4)");
2957
2958 disasm.MapCodeAddress(0x1234,
2959 masm.GetBuffer()->GetStartAddress<Instruction*>());
2960 COMPARE(ldr(x0, INT64_C(0)), "ldr x0, pc+0 (addr 0x1234)");
2961 COMPARE(ldr(x0, -1), "ldr x0, pc-4 (addr 0x1230)");
2962 COMPARE(ldr(x0, 1), "ldr x0, pc+4 (addr 0x1238)");
2963 COMPARE(prfm(PLIL1KEEP, INT64_C(0)), "prfm plil1keep, pc+0 (addr 0x1234)");
2964 COMPARE(prfm(PLIL1KEEP, -1), "prfm plil1keep, pc-4 (addr 0x1230)");
2965 COMPARE(prfm(PLIL1KEEP, 1), "prfm plil1keep, pc+4 (addr 0x1238)");
2966 COMPARE(adr(x0, INT64_C(0)), "adr x0, #+0x0 (addr 0x1234)");
2967 COMPARE(adr(x0, -1), "adr x0, #-0x1 (addr 0x1233)");
2968 COMPARE(adr(x0, 1), "adr x0, #+0x1 (addr 0x1235)");
2969 COMPARE(adrp(x0, INT64_C(0)), "adrp x0, #+0x0 (addr 0x1000)");
2970 COMPARE(adrp(x0, -1), "adrp x0, #-0x1000 (addr 0x0)");
2971 COMPARE(adrp(x0, 1), "adrp x0, #+0x1000 (addr 0x2000)");
2972 COMPARE(b(INT64_C(0)), "b #+0x0 (addr 0x1234)");
2973 COMPARE(b(-1), "b #-0x4 (addr 0x1230)");
2974 COMPARE(b(1), "b #+0x4 (addr 0x1238)");
2975
2976 // Check that 64-bit addresses work.
2977 disasm.MapCodeAddress(UINT64_C(0x100000000),
2978 masm.GetBuffer()->GetStartAddress<Instruction*>());
2979 COMPARE(ldr(x0, INT64_C(0)), "ldr x0, pc+0 (addr 0x100000000)");
2980 COMPARE(ldr(x0, -1), "ldr x0, pc-4 (addr 0xfffffffc)");
2981 COMPARE(ldr(x0, 1), "ldr x0, pc+4 (addr 0x100000004)");
2982 COMPARE(prfm(PLIL1KEEP, INT64_C(0)),
2983 "prfm plil1keep, pc+0 (addr 0x100000000)");
2984 COMPARE(prfm(PLIL1KEEP, -1), "prfm plil1keep, pc-4 (addr 0xfffffffc)");
2985 COMPARE(prfm(PLIL1KEEP, 1), "prfm plil1keep, pc+4 (addr 0x100000004)");
2986 COMPARE(adr(x0, INT64_C(0)), "adr x0, #+0x0 (addr 0x100000000)");
2987 COMPARE(adr(x0, -1), "adr x0, #-0x1 (addr 0xffffffff)");
2988 COMPARE(adr(x0, 1), "adr x0, #+0x1 (addr 0x100000001)");
2989 COMPARE(adrp(x0, INT64_C(0)), "adrp x0, #+0x0 (addr 0x100000000)");
2990 COMPARE(adrp(x0, -1), "adrp x0, #-0x1000 (addr 0xfffff000)");
2991 COMPARE(adrp(x0, 1), "adrp x0, #+0x1000 (addr 0x100001000)");
2992 COMPARE(b(INT64_C(0)), "b #+0x0 (addr 0x100000000)");
2993 COMPARE(b(-1), "b #-0x4 (addr 0xfffffffc)");
2994 COMPARE(b(1), "b #+0x4 (addr 0x100000004)");
2995
2996 disasm.MapCodeAddress(0xfffffffc,
2997 masm.GetBuffer()->GetStartAddress<Instruction*>());
2998 COMPARE(ldr(x0, 1), "ldr x0, pc+4 (addr 0x100000000)");
2999 COMPARE(prfm(PLIL1KEEP, 1), "prfm plil1keep, pc+4 (addr 0x100000000)");
3000 COMPARE(b(1), "b #+0x4 (addr 0x100000000)");
3001 COMPARE(adr(x0, 4), "adr x0, #+0x4 (addr 0x100000000)");
3002 COMPARE(adrp(x0, 1), "adrp x0, #+0x1000 (addr 0x100000000)");
3003
3004 // Check that very large offsets are handled properly. This detects misuse of
3005 // the host's ptrdiff_t type when run on a 32-bit host. Only adrp is capable
3006 // of encoding such offsets.
3007 disasm.MapCodeAddress(0, masm.GetBuffer()->GetStartAddress<Instruction*>());
3008 COMPARE(adrp(x0, 0x000fffff), "adrp x0, #+0xfffff000 (addr 0xfffff000)");
3009 COMPARE(adrp(x0, -0x00100000), "adrp x0, #-0x100000000 (addr -0x100000000)");
3010
3011 CLEANUP();
3012 }
3013
TEST(hint)3014 TEST(hint) {
3015 SETUP();
3016
3017 // Test that we properly disassemble named and unnamed hints.
3018 COMPARE(hint(NOP), "nop");
3019 COMPARE(hint(YIELD), "yield");
3020 COMPARE(hint(WFE), "wfe");
3021 COMPARE(hint(WFI), "wfi");
3022 COMPARE(hint(SEV), "sev");
3023 COMPARE(hint(SEVL), "sevl");
3024 COMPARE(hint(6), "hint #6");
3025 COMPARE(hint(ESB), "esb");
3026 COMPARE(hint(CSDB), "csdb");
3027 COMPARE(hint(42), "hint #42");
3028 COMPARE(hint(127), "hint #127");
3029
3030 // The MacroAssembler should simply pass through to the Assembler.
3031 COMPARE_MACRO(Hint(NOP), "nop");
3032 COMPARE_MACRO(Hint(CSDB), "csdb");
3033 COMPARE_MACRO(Hint(42), "hint #42");
3034 COMPARE_MACRO(Hint(127), "hint #127");
3035
3036 CLEANUP();
3037 }
3038
TEST(bti)3039 TEST(bti) {
3040 SETUP();
3041
3042 COMPARE(bti(EmitBTI), "bti");
3043 COMPARE(bti(EmitBTI_c), "bti c");
3044 COMPARE(bti(EmitBTI_j), "bti j");
3045 COMPARE(bti(EmitBTI_jc), "bti jc");
3046 COMPARE(hint(BTI), "bti");
3047 COMPARE(hint(BTI_c), "bti c");
3048 COMPARE(hint(BTI_j), "bti j");
3049 COMPARE(hint(BTI_jc), "bti jc");
3050
3051 Label placeholder1, placeholder2, placeholder3, placeholder4;
3052 COMPARE_MACRO(Bind(&placeholder1, EmitBTI), "bti");
3053 COMPARE_MACRO(Bind(&placeholder2, EmitBTI_c), "bti c");
3054 COMPARE_MACRO(Bind(&placeholder3, EmitBTI_j), "bti j");
3055 COMPARE_MACRO(Bind(&placeholder4, EmitBTI_jc), "bti jc");
3056
3057 CLEANUP();
3058 }
3059
TEST(udf)3060 TEST(udf) {
3061 SETUP();
3062
3063 COMPARE(udf(0), "udf #0x0");
3064 COMPARE(udf(0x1234), "udf #0x1234");
3065 COMPARE(udf(0xffff), "udf #0xffff");
3066
3067 // UDF gives the useful property that zero-initialised memory is guaranteed to
3068 // generate undefined instruction exceptions.
3069 COMPARE(dc(0), "udf #0x0");
3070
3071 // Check related unallocated bit patterns from the reserved block.
3072 COMPARE(dc(0x00010000), "unallocated (Unallocated)");
3073 COMPARE(dc(0x01000000), "unallocated (Unallocated)");
3074 COMPARE(dc(0x20000000), "unallocated (Unallocated)");
3075 COMPARE(dc(0x80000000), "unallocated (Unallocated)");
3076
3077 CLEANUP();
3078 }
3079
3080 } // namespace aarch64
3081 } // namespace vixl
3082