1 // Copyright 2013, ARM Limited
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 #include <stdio.h>
28 #include <cstring>
29 #include "cctest.h"
30 
31 #include "a64/macro-assembler-a64.h"
32 #include "a64/disasm-a64.h"
33 
34 #define TEST(name)  TEST_(DISASM_##name)
35 
36 #define EXP_SIZE   (256)
37 #define INSTR_SIZE (1024)
38 #define SETUP_CLASS(ASMCLASS)                                                  \
39   byte* buf = static_cast<byte*>(malloc(INSTR_SIZE));                          \
40   uint32_t encoding = 0;                                                       \
41   ASMCLASS* masm = new ASMCLASS(buf, INSTR_SIZE);                              \
42   Decoder* decoder = new Decoder();                                            \
43   Disassembler* disasm = new Disassembler();                                   \
44   decoder->AppendVisitor(disasm)
45 
46 #define SETUP() SETUP_CLASS(Assembler)
47 
48 #define COMPARE(ASM, EXP)                                                      \
49   masm->Reset();                                                               \
50   masm->ASM;                                                                   \
51   masm->FinalizeCode();                                                        \
52   decoder->Decode(reinterpret_cast<Instruction*>(buf));                        \
53   encoding = *reinterpret_cast<uint32_t*>(buf);                                \
54   if (strcmp(disasm->GetOutput(), EXP) != 0) {                                 \
55     printf("Encoding: %08" PRIx32 "\nExpected: %s\nFound:    %s\n",            \
56            encoding, EXP, disasm->GetOutput());                                \
57     abort();                                                                   \
58   }
59 
60 #define COMPARE_PREFIX(ASM, EXP)                                               \
61   masm->Reset();                                                               \
62   masm->ASM;                                                                   \
63   masm->FinalizeCode();                                                        \
64   decoder->Decode(reinterpret_cast<Instruction*>(buf));                        \
65   encoding = *reinterpret_cast<uint32_t*>(buf);                                \
66   if (strncmp(disasm->GetOutput(), EXP, strlen(EXP)) != 0) {                   \
67     printf("Encoding: %08" PRIx32 "\nExpected: %s\nFound:    %s\n",            \
68            encoding, EXP, disasm->GetOutput());                                \
69     abort();                                                                   \
70   }
71 
72 #define CLEANUP()                                                              \
73   delete disasm;                                                               \
74   delete decoder;                                                              \
75   delete masm
76 
77 namespace vixl {
78 
TEST(bootstrap)79 TEST(bootstrap) {
80   SETUP();
81 
82   // Instructions generated by C compiler, disassembled by objdump, and
83   // reformatted to suit our disassembly style.
84   COMPARE(dci(0xa9ba7bfd), "stp x29, x30, [sp, #-96]!");
85   COMPARE(dci(0x910003fd), "mov x29, sp");
86   COMPARE(dci(0x9100e3a0), "add x0, x29, #0x38 (56)");
87   COMPARE(dci(0xb900001f), "str wzr, [x0]");
88   COMPARE(dci(0x528000e1), "movz w1, #0x7");
89   COMPARE(dci(0xb9001c01), "str w1, [x0, #28]");
90   COMPARE(dci(0x390043a0), "strb w0, [x29, #16]");
91   COMPARE(dci(0x790027a0), "strh w0, [x29, #18]");
92   COMPARE(dci(0xb9400400), "ldr w0, [x0, #4]");
93   COMPARE(dci(0x0b000021), "add w1, w1, w0");
94   COMPARE(dci(0x531b6800), "lsl w0, w0, #5");
95   COMPARE(dci(0x521e0400), "eor w0, w0, #0xc");
96   COMPARE(dci(0x72af0f00), "movk w0, #0x7878, lsl #16");
97   COMPARE(dci(0xd360fc00), "lsr x0, x0, #32");
98   COMPARE(dci(0x13037c01), "asr w1, w0, #3");
99   COMPARE(dci(0x4b000021), "sub w1, w1, w0");
100   COMPARE(dci(0x2a0103e0), "mov w0, w1");
101   COMPARE(dci(0x93407c00), "sxtw x0, w0");
102   COMPARE(dci(0x2a000020), "orr w0, w1, w0");
103   COMPARE(dci(0xa8c67bfd), "ldp x29, x30, [sp], #96");
104 
105   CLEANUP();
106 }
107 
TEST(mov_mvn)108 TEST(mov_mvn) {
109   SETUP_CLASS(MacroAssembler);
110 
111   COMPARE(Mov(w0, Operand(0x1234)), "movz w0, #0x1234");
112   COMPARE(Mov(x1, Operand(0x1234)), "movz x1, #0x1234");
113   COMPARE(Mov(w2, Operand(w3)), "mov w2, w3");
114   COMPARE(Mov(x4, Operand(x5)), "mov x4, x5");
115   COMPARE(Mov(w6, Operand(w7, LSL, 5)), "lsl w6, w7, #5");
116   COMPARE(Mov(x8, Operand(x9, ASR, 42)), "asr x8, x9, #42");
117   COMPARE(Mov(w10, Operand(w11, UXTB)), "uxtb w10, w11");
118   COMPARE(Mov(x12, Operand(x13, UXTB, 1)), "ubfiz x12, x13, #1, #8");
119   COMPARE(Mov(w14, Operand(w15, SXTH, 2)), "sbfiz w14, w15, #2, #16");
120   COMPARE(Mov(x16, Operand(x17, SXTW, 3)), "sbfiz x16, x17, #3, #32");
121 
122   COMPARE(Mvn(w0, Operand(0x101)), "movn w0, #0x101");
123   COMPARE(Mvn(x1, Operand(0xfff1)), "movn x1, #0xfff1");
124   COMPARE(Mvn(w2, Operand(w3)), "mvn w2, w3");
125   COMPARE(Mvn(x4, Operand(x5)), "mvn x4, x5");
126   COMPARE(Mvn(w6, Operand(w7, LSL, 12)), "mvn w6, w7, lsl #12");
127   COMPARE(Mvn(x8, Operand(x9, ASR, 63)), "mvn x8, x9, asr #63");
128 
129   CLEANUP();
130 }
131 
TEST(move_immediate)132 TEST(move_immediate) {
133   SETUP();
134 
135   COMPARE(movz(w0, 0x1234), "movz w0, #0x1234");
136   COMPARE(movz(x1, 0xabcd0000), "movz x1, #0xabcd0000");
137   COMPARE(movz(x2, 0x555500000000), "movz x2, #0x555500000000");
138   COMPARE(movz(x3, 0xaaaa000000000000), "movz x3, #0xaaaa000000000000");
139   COMPARE(movz(x4, 0xabcd, 16), "movz x4, #0xabcd0000");
140   COMPARE(movz(x5, 0x5555, 32), "movz x5, #0x555500000000");
141   COMPARE(movz(x6, 0xaaaa, 48), "movz x6, #0xaaaa000000000000");
142 
143   COMPARE(movk(w7, 0x1234), "movk w7, #0x1234");
144   COMPARE(movk(x8, 0xabcd0000), "movk x8, #0xabcd, lsl #16");
145   COMPARE(movk(x9, 0x555500000000), "movk x9, #0x5555, lsl #32");
146   COMPARE(movk(x10, 0xaaaa000000000000), "movk x10, #0xaaaa, lsl #48");
147   COMPARE(movk(w11, 0xabcd, 16), "movk w11, #0xabcd, lsl #16");
148   COMPARE(movk(x12, 0x5555, 32), "movk x12, #0x5555, lsl #32");
149   COMPARE(movk(x13, 0xaaaa, 48), "movk x13, #0xaaaa, lsl #48");
150 
151   COMPARE(movn(w14, 0x1234), "movn w14, #0x1234");
152   COMPARE(movn(x15, 0xabcd0000), "movn x15, #0xabcd0000");
153   COMPARE(movn(x16, 0x555500000000), "movn x16, #0x555500000000");
154   COMPARE(movn(x17, 0xaaaa000000000000), "movn x17, #0xaaaa000000000000");
155   COMPARE(movn(w18, 0xabcd, 16), "movn w18, #0xabcd0000");
156   COMPARE(movn(x19, 0x5555, 32), "movn x19, #0x555500000000");
157   COMPARE(movn(x20, 0xaaaa, 48), "movn x20, #0xaaaa000000000000");
158 
159   COMPARE(movk(w21, 0), "movk w21, #0x0");
160   COMPARE(movk(x22, 0, 0), "movk x22, #0x0");
161   COMPARE(movk(w23, 0, 16), "movk w23, #0x0, lsl #16");
162   COMPARE(movk(x24, 0, 32), "movk x24, #0x0, lsl #32");
163   COMPARE(movk(x25, 0, 48), "movk x25, #0x0, lsl #48");
164 
165   CLEANUP();
166 }
167 
TEST(move_immediate_2)168 TEST(move_immediate_2) {
169   SETUP_CLASS(MacroAssembler);
170 
171   // Move instructions expected for certain immediates. This is really a macro
172   // assembler test, to ensure it generates immediates efficiently.
173   COMPARE(Mov(w0, 0), "movz w0, #0x0");
174   COMPARE(Mov(w0, 0x0000ffff), "movz w0, #0xffff");
175   COMPARE(Mov(w0, 0x00010000), "movz w0, #0x10000");
176   COMPARE(Mov(w0, 0xffff0000), "movz w0, #0xffff0000");
177   COMPARE(Mov(w0, 0x0001ffff), "movn w0, #0xfffe0000");
178   COMPARE(Mov(w0, 0xffff8000), "movn w0, #0x7fff");
179   COMPARE(Mov(w0, 0xfffffffe), "movn w0, #0x1");
180   COMPARE(Mov(w0, 0xffffffff), "movn w0, #0x0");
181   COMPARE(Mov(w0, 0x00ffff00), "mov w0, #0xffff00");
182   COMPARE(Mov(w0, 0xfffe7fff), "mov w0, #0xfffe7fff");
183   COMPARE(Mov(w0, 0xfffeffff), "movn w0, #0x10000");
184   COMPARE(Mov(w0, 0xffff7fff), "movn w0, #0x8000");
185 
186   COMPARE(Mov(x0, 0), "movz x0, #0x0");
187   COMPARE(Mov(x0, 0x0000ffff), "movz x0, #0xffff");
188   COMPARE(Mov(x0, 0x00010000), "movz x0, #0x10000");
189   COMPARE(Mov(x0, 0xffff0000), "movz x0, #0xffff0000");
190   COMPARE(Mov(x0, 0x0001ffff), "mov x0, #0x1ffff");
191   COMPARE(Mov(x0, 0xffff8000), "mov x0, #0xffff8000");
192   COMPARE(Mov(x0, 0xfffffffe), "mov x0, #0xfffffffe");
193   COMPARE(Mov(x0, 0xffffffff), "mov x0, #0xffffffff");
194   COMPARE(Mov(x0, 0x00ffff00), "mov x0, #0xffff00");
195   COMPARE(Mov(x0, 0xffff000000000000), "movz x0, #0xffff000000000000");
196   COMPARE(Mov(x0, 0x0000ffff00000000), "movz x0, #0xffff00000000");
197   COMPARE(Mov(x0, 0x00000000ffff0000), "movz x0, #0xffff0000");
198   COMPARE(Mov(x0, 0xffffffffffff0000), "movn x0, #0xffff");
199   COMPARE(Mov(x0, 0xffffffff0000ffff), "movn x0, #0xffff0000");
200   COMPARE(Mov(x0, 0xffff0000ffffffff), "movn x0, #0xffff00000000");
201   COMPARE(Mov(x0, 0x0000ffffffffffff), "movn x0, #0xffff000000000000");
202   COMPARE(Mov(x0, 0xfffe7fffffffffff), "mov x0, #0xfffe7fffffffffff");
203   COMPARE(Mov(x0, 0xfffeffffffffffff), "movn x0, #0x1000000000000");
204   COMPARE(Mov(x0, 0xffff7fffffffffff), "movn x0, #0x800000000000");
205   COMPARE(Mov(x0, 0xfffffffe7fffffff), "mov x0, #0xfffffffe7fffffff");
206   COMPARE(Mov(x0, 0xfffffffeffffffff), "movn x0, #0x100000000");
207   COMPARE(Mov(x0, 0xffffffff7fffffff), "movn x0, #0x80000000");
208   COMPARE(Mov(x0, 0xfffffffffffe7fff), "mov x0, #0xfffffffffffe7fff");
209   COMPARE(Mov(x0, 0xfffffffffffeffff), "movn x0, #0x10000");
210   COMPARE(Mov(x0, 0xffffffffffff7fff), "movn x0, #0x8000");
211   COMPARE(Mov(x0, 0xffffffffffffffff), "movn x0, #0x0");
212 
213   COMPARE(Movk(w0, 0x1234, 0), "movk w0, #0x1234");
214   COMPARE(Movk(x1, 0x2345, 0), "movk x1, #0x2345");
215   COMPARE(Movk(w2, 0x3456, 16), "movk w2, #0x3456, lsl #16");
216   COMPARE(Movk(x3, 0x4567, 16), "movk x3, #0x4567, lsl #16");
217   COMPARE(Movk(x4, 0x5678, 32), "movk x4, #0x5678, lsl #32");
218   COMPARE(Movk(x5, 0x6789, 48), "movk x5, #0x6789, lsl #48");
219 
220   CLEANUP();
221 }
222 
TEST(add_immediate)223 TEST(add_immediate) {
224   SETUP();
225 
226   COMPARE(add(w0, w1, Operand(0xff)), "add w0, w1, #0xff (255)");
227   COMPARE(add(x2, x3, Operand(0x3ff)), "add x2, x3, #0x3ff (1023)");
228   COMPARE(add(w4, w5, Operand(0xfff)), "add w4, w5, #0xfff (4095)");
229   COMPARE(add(x6, x7, Operand(0x1000)), "add x6, x7, #0x1000 (4096)");
230   COMPARE(add(w8, w9, Operand(0xff000)), "add w8, w9, #0xff000 (1044480)");
231   COMPARE(add(x10, x11, Operand(0x3ff000)),
232           "add x10, x11, #0x3ff000 (4190208)");
233   COMPARE(add(w12, w13, Operand(0xfff000)),
234           "add w12, w13, #0xfff000 (16773120)");
235   COMPARE(adds(w14, w15, Operand(0xff)), "adds w14, w15, #0xff (255)");
236   COMPARE(adds(x16, x17, Operand(0xaa000)), "adds x16, x17, #0xaa000 (696320)");
237 
238   COMPARE(cmn(w18, Operand(0xff)), "cmn w18, #0xff (255)");
239   COMPARE(cmn(x19, Operand(0xff000)), "cmn x19, #0xff000 (1044480)");
240   COMPARE(add(w0, wsp, Operand(0)), "mov w0, wsp");
241   COMPARE(add(sp, x0, Operand(0)), "mov sp, x0");
242 
243   COMPARE(add(w1, wsp, Operand(8)), "add w1, wsp, #0x8 (8)");
244   COMPARE(add(x2, sp, Operand(16)), "add x2, sp, #0x10 (16)");
245   COMPARE(add(wsp, wsp, Operand(42)), "add wsp, wsp, #0x2a (42)");
246   COMPARE(cmn(sp, Operand(24)), "cmn sp, #0x18 (24)");
247   COMPARE(adds(wzr, wsp, Operand(9)), "cmn wsp, #0x9 (9)");
248 
249   CLEANUP();
250 }
251 
TEST(sub_immediate)252 TEST(sub_immediate) {
253   SETUP();
254 
255   COMPARE(sub(w0, w1, Operand(0xff)), "sub w0, w1, #0xff (255)");
256   COMPARE(sub(x2, x3, Operand(0x3ff)), "sub x2, x3, #0x3ff (1023)");
257   COMPARE(sub(w4, w5, Operand(0xfff)), "sub w4, w5, #0xfff (4095)");
258   COMPARE(sub(x6, x7, Operand(0x1000)), "sub x6, x7, #0x1000 (4096)");
259   COMPARE(sub(w8, w9, Operand(0xff000)), "sub w8, w9, #0xff000 (1044480)");
260   COMPARE(sub(x10, x11, Operand(0x3ff000)),
261           "sub x10, x11, #0x3ff000 (4190208)");
262   COMPARE(sub(w12, w13, Operand(0xfff000)),
263           "sub w12, w13, #0xfff000 (16773120)");
264   COMPARE(subs(w14, w15, Operand(0xff)), "subs w14, w15, #0xff (255)");
265   COMPARE(subs(x16, x17, Operand(0xaa000)), "subs x16, x17, #0xaa000 (696320)");
266   COMPARE(cmp(w18, Operand(0xff)), "cmp w18, #0xff (255)");
267   COMPARE(cmp(x19, Operand(0xff000)), "cmp x19, #0xff000 (1044480)");
268 
269   COMPARE(sub(w1, wsp, Operand(8)), "sub w1, wsp, #0x8 (8)");
270   COMPARE(sub(x2, sp, Operand(16)), "sub x2, sp, #0x10 (16)");
271   COMPARE(sub(wsp, wsp, Operand(42)), "sub wsp, wsp, #0x2a (42)");
272   COMPARE(cmp(sp, Operand(24)), "cmp sp, #0x18 (24)");
273   COMPARE(subs(wzr, wsp, Operand(9)), "cmp wsp, #0x9 (9)");
274 
275   CLEANUP();
276 }
277 
278 
TEST(add_shifted)279 TEST(add_shifted) {
280   SETUP();
281 
282   COMPARE(add(w0, w1, Operand(w2)), "add w0, w1, w2");
283   COMPARE(add(x3, x4, Operand(x5)), "add x3, x4, x5");
284   COMPARE(add(w6, w7, Operand(w8, LSL, 1)), "add w6, w7, w8, lsl #1");
285   COMPARE(add(x9, x10, Operand(x11, LSL, 2)), "add x9, x10, x11, lsl #2");
286   COMPARE(add(w12, w13, Operand(w14, LSR, 3)), "add w12, w13, w14, lsr #3");
287   COMPARE(add(x15, x16, Operand(x17, LSR, 4)), "add x15, x16, x17, lsr #4");
288   COMPARE(add(w18, w19, Operand(w20, ASR, 5)), "add w18, w19, w20, asr #5");
289   COMPARE(add(x21, x22, Operand(x23, ASR, 6)), "add x21, x22, x23, asr #6");
290   COMPARE(cmn(w24, Operand(w25)), "cmn w24, w25");
291   COMPARE(cmn(x26, Operand(x27, LSL, 63)), "cmn x26, x27, lsl #63");
292 
293   COMPARE(add(x0, sp, Operand(x1)), "add x0, sp, x1");
294   COMPARE(add(w2, wsp, Operand(w3)), "add w2, wsp, w3");
295   COMPARE(add(x4, sp, Operand(x5, LSL, 1)), "add x4, sp, x5, lsl #1");
296   COMPARE(add(x4, xzr, Operand(x5, LSL, 1)), "add x4, xzr, x5, lsl #1");
297   COMPARE(add(w6, wsp, Operand(w7, LSL, 3)), "add w6, wsp, w7, lsl #3");
298   COMPARE(adds(xzr, sp, Operand(x8, LSL, 4)), "cmn sp, x8, lsl #4");
299   COMPARE(adds(xzr, xzr, Operand(x8, LSL, 5)), "cmn xzr, x8, lsl #5");
300 
301   CLEANUP();
302 }
303 
304 
TEST(sub_shifted)305 TEST(sub_shifted) {
306   SETUP();
307 
308   COMPARE(sub(w0, w1, Operand(w2)), "sub w0, w1, w2");
309   COMPARE(sub(x3, x4, Operand(x5)), "sub x3, x4, x5");
310   COMPARE(sub(w6, w7, Operand(w8, LSL, 1)), "sub w6, w7, w8, lsl #1");
311   COMPARE(sub(x9, x10, Operand(x11, LSL, 2)), "sub x9, x10, x11, lsl #2");
312   COMPARE(sub(w12, w13, Operand(w14, LSR, 3)), "sub w12, w13, w14, lsr #3");
313   COMPARE(sub(x15, x16, Operand(x17, LSR, 4)), "sub x15, x16, x17, lsr #4");
314   COMPARE(sub(w18, w19, Operand(w20, ASR, 5)), "sub w18, w19, w20, asr #5");
315   COMPARE(sub(x21, x22, Operand(x23, ASR, 6)), "sub x21, x22, x23, asr #6");
316   COMPARE(cmp(w24, Operand(w25)), "cmp w24, w25");
317   COMPARE(cmp(x26, Operand(x27, LSL, 63)), "cmp x26, x27, lsl #63");
318   COMPARE(neg(w28, Operand(w29)), "neg w28, w29");
319   COMPARE(neg(x30, Operand(x0, LSR, 62)), "neg x30, x0, lsr #62");
320   COMPARE(negs(w1, Operand(w2)), "negs w1, w2");
321   COMPARE(negs(x3, Operand(x4, ASR, 61)), "negs x3, x4, asr #61");
322 
323   COMPARE(sub(x0, sp, Operand(x1)), "sub x0, sp, x1");
324   COMPARE(sub(w2, wsp, Operand(w3)), "sub w2, wsp, w3");
325   COMPARE(sub(x4, sp, Operand(x5, LSL, 1)), "sub x4, sp, x5, lsl #1");
326   COMPARE(sub(x4, xzr, Operand(x5, LSL, 1)), "neg x4, x5, lsl #1");
327   COMPARE(sub(w6, wsp, Operand(w7, LSL, 3)), "sub w6, wsp, w7, lsl #3");
328   COMPARE(subs(xzr, sp, Operand(x8, LSL, 4)), "cmp sp, x8, lsl #4");
329   COMPARE(subs(xzr, xzr, Operand(x8, LSL, 5)), "cmp xzr, x8, lsl #5");
330 
331   CLEANUP();
332 }
333 
334 
TEST(add_extended)335 TEST(add_extended) {
336   SETUP();
337 
338   COMPARE(add(w0, w1, Operand(w2, UXTB)), "add w0, w1, w2, uxtb");
339   COMPARE(adds(x3, x4, Operand(w5, UXTB, 1)), "adds x3, x4, w5, uxtb #1");
340   COMPARE(add(w6, w7, Operand(w8, UXTH, 2)), "add w6, w7, w8, uxth #2");
341   COMPARE(adds(x9, x10, Operand(x11, UXTW, 3)), "adds x9, x10, w11, uxtw #3");
342   COMPARE(add(x12, x13, Operand(x14, UXTX, 4)), "add x12, x13, x14, uxtx #4");
343   COMPARE(adds(w15, w16, Operand(w17, SXTB, 4)), "adds w15, w16, w17, sxtb #4");
344   COMPARE(add(x18, x19, Operand(x20, SXTB, 3)), "add x18, x19, w20, sxtb #3");
345   COMPARE(adds(w21, w22, Operand(w23, SXTH, 2)), "adds w21, w22, w23, sxth #2");
346   COMPARE(add(x24, x25, Operand(x26, SXTW, 1)), "add x24, x25, w26, sxtw #1");
347   COMPARE(adds(x27, x28, Operand(x29, SXTX)), "adds x27, x28, x29, sxtx");
348   COMPARE(cmn(w0, Operand(w1, UXTB, 2)), "cmn w0, w1, uxtb #2");
349   COMPARE(cmn(x2, Operand(x3, SXTH, 4)), "cmn x2, w3, sxth #4");
350 
351   COMPARE(add(w0, wsp, Operand(w1, UXTB)), "add w0, wsp, w1, uxtb");
352   COMPARE(add(x2, sp, Operand(x3, UXTH, 1)), "add x2, sp, w3, uxth #1");
353   COMPARE(add(wsp, wsp, Operand(w4, UXTW, 2)), "add wsp, wsp, w4, lsl #2");
354   COMPARE(cmn(sp, Operand(xzr, UXTX, 3)), "cmn sp, xzr, lsl #3");
355   COMPARE(cmn(sp, Operand(xzr, LSL, 4)), "cmn sp, xzr, lsl #4");
356 
357   CLEANUP();
358 }
359 
360 
TEST(sub_extended)361 TEST(sub_extended) {
362   SETUP();
363 
364   COMPARE(sub(w0, w1, Operand(w2, UXTB)), "sub w0, w1, w2, uxtb");
365   COMPARE(subs(x3, x4, Operand(w5, UXTB, 1)), "subs x3, x4, w5, uxtb #1");
366   COMPARE(sub(w6, w7, Operand(w8, UXTH, 2)), "sub w6, w7, w8, uxth #2");
367   COMPARE(subs(x9, x10, Operand(x11, UXTW, 3)), "subs x9, x10, w11, uxtw #3");
368   COMPARE(sub(x12, x13, Operand(x14, UXTX, 4)), "sub x12, x13, x14, uxtx #4");
369   COMPARE(subs(w15, w16, Operand(w17, SXTB, 4)), "subs w15, w16, w17, sxtb #4");
370   COMPARE(sub(x18, x19, Operand(x20, SXTB, 3)), "sub x18, x19, w20, sxtb #3");
371   COMPARE(subs(w21, w22, Operand(w23, SXTH, 2)), "subs w21, w22, w23, sxth #2");
372   COMPARE(sub(x24, x25, Operand(x26, SXTW, 1)), "sub x24, x25, w26, sxtw #1");
373   COMPARE(subs(x27, x28, Operand(x29, SXTX)), "subs x27, x28, x29, sxtx");
374   COMPARE(cmp(w0, Operand(w1, SXTB, 1)), "cmp w0, w1, sxtb #1");
375   COMPARE(cmp(x2, Operand(x3, UXTH, 3)), "cmp x2, w3, uxth #3");
376 
377   COMPARE(sub(w0, wsp, Operand(w1, UXTB)), "sub w0, wsp, w1, uxtb");
378   COMPARE(sub(x2, sp, Operand(x3, UXTH, 1)), "sub x2, sp, w3, uxth #1");
379   COMPARE(sub(wsp, wsp, Operand(w4, UXTW, 2)), "sub wsp, wsp, w4, lsl #2");
380   COMPARE(cmp(sp, Operand(xzr, UXTX, 3)), "cmp sp, xzr, lsl #3");
381   COMPARE(cmp(sp, Operand(xzr, LSL, 4)), "cmp sp, xzr, lsl #4");
382 
383   CLEANUP();
384 }
385 
386 
TEST(adc_subc_ngc)387 TEST(adc_subc_ngc) {
388   SETUP();
389 
390   COMPARE(adc(w0, w1, Operand(w2)), "adc w0, w1, w2");
391   COMPARE(adc(x3, x4, Operand(x5)), "adc x3, x4, x5");
392   COMPARE(adcs(w6, w7, Operand(w8)), "adcs w6, w7, w8");
393   COMPARE(adcs(x9, x10, Operand(x11)), "adcs x9, x10, x11");
394   COMPARE(sbc(w12, w13, Operand(w14)), "sbc w12, w13, w14");
395   COMPARE(sbc(x15, x16, Operand(x17)), "sbc x15, x16, x17");
396   COMPARE(sbcs(w18, w19, Operand(w20)), "sbcs w18, w19, w20");
397   COMPARE(sbcs(x21, x22, Operand(x23)), "sbcs x21, x22, x23");
398   COMPARE(ngc(w24, Operand(w25)), "ngc w24, w25");
399   COMPARE(ngc(x26, Operand(x27)), "ngc x26, x27");
400   COMPARE(ngcs(w28, Operand(w29)), "ngcs w28, w29");
401   COMPARE(ngcs(x30, Operand(x0)), "ngcs x30, x0");
402 
403   CLEANUP();
404 }
405 
406 
TEST(mul_and_div)407 TEST(mul_and_div) {
408   SETUP();
409 
410   COMPARE(mul(w0, w1, w2), "mul w0, w1, w2");
411   COMPARE(mul(x3, x4, x5), "mul x3, x4, x5");
412   COMPARE(mul(w30, w0, w1), "mul w30, w0, w1");
413   COMPARE(mul(x30, x0, x1), "mul x30, x0, x1");
414   COMPARE(mneg(w0, w1, w2), "mneg w0, w1, w2");
415   COMPARE(mneg(x3, x4, x5), "mneg x3, x4, x5");
416   COMPARE(mneg(w30, w0, w1), "mneg w30, w0, w1");
417   COMPARE(mneg(x30, x0, x1), "mneg x30, x0, x1");
418   COMPARE(smull(x0, w0, w1), "smull x0, w0, w1");
419   COMPARE(smull(x30, w30, w0), "smull x30, w30, w0");
420   COMPARE(smulh(x0, x1, x2), "smulh x0, x1, x2");
421 
422   COMPARE(sdiv(w0, w1, w2), "sdiv w0, w1, w2");
423   COMPARE(sdiv(x3, x4, x5), "sdiv x3, x4, x5");
424   COMPARE(udiv(w6, w7, w8), "udiv w6, w7, w8");
425   COMPARE(udiv(x9, x10, x11), "udiv x9, x10, x11");
426 
427   CLEANUP();
428 }
429 
430 
TEST(madd)431 TEST(madd) {
432   SETUP();
433 
434   COMPARE(madd(w0, w1, w2, w3), "madd w0, w1, w2, w3");
435   COMPARE(madd(w30, w21, w22, w16), "madd w30, w21, w22, w16");
436   COMPARE(madd(x0, x1, x2, x3), "madd x0, x1, x2, x3");
437   COMPARE(madd(x30, x21, x22, x16), "madd x30, x21, x22, x16");
438 
439   COMPARE(smaddl(x0, w1, w2, x3), "smaddl x0, w1, w2, x3");
440   COMPARE(smaddl(x30, w21, w22, x16), "smaddl x30, w21, w22, x16");
441   COMPARE(umaddl(x0, w1, w2, x3), "umaddl x0, w1, w2, x3");
442   COMPARE(umaddl(x30, w21, w22, x16), "umaddl x30, w21, w22, x16");
443 
444   CLEANUP();
445 }
446 
447 
TEST(msub)448 TEST(msub) {
449   SETUP();
450 
451   COMPARE(msub(w0, w1, w2, w3), "msub w0, w1, w2, w3");
452   COMPARE(msub(w30, w21, w22, w16), "msub w30, w21, w22, w16");
453   COMPARE(msub(x0, x1, x2, x3), "msub x0, x1, x2, x3");
454   COMPARE(msub(x30, x21, x22, x16), "msub x30, x21, x22, x16");
455 
456   COMPARE(smsubl(x0, w1, w2, x3), "smsubl x0, w1, w2, x3");
457   COMPARE(smsubl(x30, w21, w22, x16), "smsubl x30, w21, w22, x16");
458   COMPARE(umsubl(x0, w1, w2, x3), "umsubl x0, w1, w2, x3");
459   COMPARE(umsubl(x30, w21, w22, x16), "umsubl x30, w21, w22, x16");
460 
461   CLEANUP();
462 }
463 
464 
TEST(dp_1_source)465 TEST(dp_1_source) {
466   SETUP();
467 
468   COMPARE(rbit(w0, w1), "rbit w0, w1");
469   COMPARE(rbit(x2, x3), "rbit x2, x3");
470   COMPARE(rev16(w4, w5), "rev16 w4, w5");
471   COMPARE(rev16(x6, x7), "rev16 x6, x7");
472   COMPARE(rev32(x8, x9), "rev32 x8, x9");
473   COMPARE(rev(w10, w11), "rev w10, w11");
474   COMPARE(rev(x12, x13), "rev x12, x13");
475   COMPARE(clz(w14, w15), "clz w14, w15");
476   COMPARE(clz(x16, x17), "clz x16, x17");
477   COMPARE(cls(w18, w19), "cls w18, w19");
478   COMPARE(cls(x20, x21), "cls x20, x21");
479 
480   CLEANUP();
481 }
482 
483 
TEST(bitfield)484 TEST(bitfield) {
485   SETUP();
486 
487   COMPARE(sxtb(w0, w1), "sxtb w0, w1");
488   COMPARE(sxtb(x2, x3), "sxtb x2, w3");
489   COMPARE(sxth(w4, w5), "sxth w4, w5");
490   COMPARE(sxth(x6, x7), "sxth x6, w7");
491   COMPARE(sxtw(x8, x9), "sxtw x8, w9");
492   COMPARE(sxtb(x0, w1), "sxtb x0, w1");
493   COMPARE(sxth(x2, w3), "sxth x2, w3");
494   COMPARE(sxtw(x4, w5), "sxtw x4, w5");
495 
496   COMPARE(uxtb(w10, w11), "uxtb w10, w11");
497   COMPARE(uxtb(x12, x13), "uxtb x12, w13");
498   COMPARE(uxth(w14, w15), "uxth w14, w15");
499   COMPARE(uxth(x16, x17), "uxth x16, w17");
500   COMPARE(uxtw(x18, x19), "ubfx x18, x19, #0, #32");
501 
502   COMPARE(asr(w20, w21, 10), "asr w20, w21, #10");
503   COMPARE(asr(x22, x23, 20), "asr x22, x23, #20");
504   COMPARE(lsr(w24, w25, 10), "lsr w24, w25, #10");
505   COMPARE(lsr(x26, x27, 20), "lsr x26, x27, #20");
506   COMPARE(lsl(w28, w29, 10), "lsl w28, w29, #10");
507   COMPARE(lsl(x30, x0, 20), "lsl x30, x0, #20");
508 
509   COMPARE(sbfiz(w1, w2, 1, 20), "sbfiz w1, w2, #1, #20");
510   COMPARE(sbfiz(x3, x4, 2, 19), "sbfiz x3, x4, #2, #19");
511   COMPARE(sbfx(w5, w6, 3, 18), "sbfx w5, w6, #3, #18");
512   COMPARE(sbfx(x7, x8, 4, 17), "sbfx x7, x8, #4, #17");
513   COMPARE(bfi(w9, w10, 5, 16), "bfi w9, w10, #5, #16");
514   COMPARE(bfi(x11, x12, 6, 15), "bfi x11, x12, #6, #15");
515   COMPARE(bfxil(w13, w14, 7, 14), "bfxil w13, w14, #7, #14");
516   COMPARE(bfxil(x15, x16, 8, 13), "bfxil x15, x16, #8, #13");
517   COMPARE(ubfiz(w17, w18, 9, 12), "ubfiz w17, w18, #9, #12");
518   COMPARE(ubfiz(x19, x20, 10, 11), "ubfiz x19, x20, #10, #11");
519   COMPARE(ubfx(w21, w22, 11, 10), "ubfx w21, w22, #11, #10");
520   COMPARE(ubfx(x23, x24, 12, 9), "ubfx x23, x24, #12, #9");
521 
522   CLEANUP();
523 }
524 
525 
TEST(extract)526 TEST(extract) {
527   SETUP();
528 
529   COMPARE(extr(w0, w1, w2, 0), "extr w0, w1, w2, #0");
530   COMPARE(extr(x3, x4, x5, 1), "extr x3, x4, x5, #1");
531   COMPARE(extr(w6, w7, w8, 31), "extr w6, w7, w8, #31");
532   COMPARE(extr(x9, x10, x11, 63), "extr x9, x10, x11, #63");
533   COMPARE(extr(w12, w13, w13, 10), "ror w12, w13, #10");
534   COMPARE(extr(x14, x15, x15, 42), "ror x14, x15, #42");
535 
536   CLEANUP();
537 }
538 
539 
TEST(logical_immediate)540 TEST(logical_immediate) {
541   SETUP();
542   #define RESULT_SIZE (256)
543 
544   char result[RESULT_SIZE];
545 
546   // Test immediate encoding - 64-bit destination.
547   // 64-bit patterns.
548   uint64_t value = 0x7fffffff;
549   for (int i = 0; i < 64; i++) {
550     snprintf(result, RESULT_SIZE, "and x0, x0, #0x%" PRIx64, value);
551     COMPARE(and_(x0, x0, Operand(value)), result);
552     value = ((value & 1) << 63) | (value >> 1);  // Rotate right 1 bit.
553   }
554 
555   // 32-bit patterns.
556   value = 0x00003fff00003fff;
557   for (int i = 0; i < 32; i++) {
558     snprintf(result, RESULT_SIZE, "and x0, x0, #0x%" PRIx64, value);
559     COMPARE(and_(x0, x0, Operand(value)), result);
560     value = ((value & 1) << 63) | (value >> 1);  // Rotate right 1 bit.
561   }
562 
563   // 16-bit patterns.
564   value = 0x001f001f001f001f;
565   for (int i = 0; i < 16; i++) {
566     snprintf(result, RESULT_SIZE, "and x0, x0, #0x%" PRIx64, value);
567     COMPARE(and_(x0, x0, Operand(value)), result);
568     value = ((value & 1) << 63) | (value >> 1);  // Rotate right 1 bit.
569   }
570 
571   // 8-bit patterns.
572   value = 0x0e0e0e0e0e0e0e0e;
573   for (int i = 0; i < 8; i++) {
574     snprintf(result, RESULT_SIZE, "and x0, x0, #0x%" PRIx64, value);
575     COMPARE(and_(x0, x0, Operand(value)), result);
576     value = ((value & 1) << 63) | (value >> 1);  // Rotate right 1 bit.
577   }
578 
579   // 4-bit patterns.
580   value = 0x6666666666666666;
581   for (int i = 0; i < 4; i++) {
582     snprintf(result, RESULT_SIZE, "and x0, x0, #0x%" PRIx64, value);
583     COMPARE(and_(x0, x0, Operand(value)), result);
584     value = ((value & 1) << 63) | (value >> 1);  // Rotate right 1 bit.
585   }
586 
587   // 2-bit patterns.
588   COMPARE(and_(x0, x0, Operand(0x5555555555555555)),
589           "and x0, x0, #0x5555555555555555");
590   COMPARE(and_(x0, x0, Operand(0xaaaaaaaaaaaaaaaa)),
591           "and x0, x0, #0xaaaaaaaaaaaaaaaa");
592 
593   // Test immediate encoding - 32-bit destination.
594   COMPARE(and_(w0, w0, Operand(0xff8007ff)),
595           "and w0, w0, #0xff8007ff");  // 32-bit pattern.
596   COMPARE(and_(w0, w0, Operand(0xf87ff87f)),
597           "and w0, w0, #0xf87ff87f");  // 16-bit pattern.
598   COMPARE(and_(w0, w0, Operand(0x87878787)),
599           "and w0, w0, #0x87878787");  // 8-bit pattern.
600   COMPARE(and_(w0, w0, Operand(0x66666666)),
601           "and w0, w0, #0x66666666");  // 4-bit pattern.
602   COMPARE(and_(w0, w0, Operand(0x55555555)),
603           "and w0, w0, #0x55555555");  // 2-bit pattern.
604 
605   // Test other instructions.
606   COMPARE(tst(w1, Operand(0x11111111)),
607           "tst w1, #0x11111111");
608   COMPARE(tst(x2, Operand(0x8888888888888888)),
609           "tst x2, #0x8888888888888888");
610   COMPARE(orr(w7, w8, Operand(0xaaaaaaaa)),
611           "orr w7, w8, #0xaaaaaaaa");
612   COMPARE(orr(x9, x10, Operand(0x5555555555555555)),
613           "orr x9, x10, #0x5555555555555555");
614   COMPARE(eor(w15, w16, Operand(0x00000001)),
615           "eor w15, w16, #0x1");
616   COMPARE(eor(x17, x18, Operand(0x0000000000000003)),
617           "eor x17, x18, #0x3");
618   COMPARE(ands(w23, w24, Operand(0x0000000f)), "ands w23, w24, #0xf");
619   COMPARE(ands(x25, x26, Operand(0x800000000000000f)),
620           "ands x25, x26, #0x800000000000000f");
621 
622   // Test inverse.
623   COMPARE(bic(w3, w4, Operand(0x20202020)),
624           "and w3, w4, #0xdfdfdfdf");
625   COMPARE(bic(x5, x6, Operand(0x4040404040404040)),
626           "and x5, x6, #0xbfbfbfbfbfbfbfbf");
627   COMPARE(orn(w11, w12, Operand(0x40004000)),
628           "orr w11, w12, #0xbfffbfff");
629   COMPARE(orn(x13, x14, Operand(0x8181818181818181)),
630           "orr x13, x14, #0x7e7e7e7e7e7e7e7e");
631   COMPARE(eon(w19, w20, Operand(0x80000001)),
632           "eor w19, w20, #0x7ffffffe");
633   COMPARE(eon(x21, x22, Operand(0xc000000000000003)),
634           "eor x21, x22, #0x3ffffffffffffffc");
635   COMPARE(bics(w27, w28, Operand(0xfffffff7)), "ands w27, w28, #0x8");
636   COMPARE(bics(x29, x0, Operand(0xfffffffeffffffff)),
637           "ands x29, x0, #0x100000000");
638 
639   // Test stack pointer.
640   COMPARE(and_(wsp, wzr, Operand(7)), "and wsp, wzr, #0x7");
641   COMPARE(ands(xzr, xzr, Operand(7)), "tst xzr, #0x7");
642   COMPARE(orr(sp, xzr, Operand(15)), "orr sp, xzr, #0xf");
643   COMPARE(eor(wsp, w0, Operand(31)), "eor wsp, w0, #0x1f");
644 
645   // Test move aliases.
646   COMPARE(orr(w0, wzr, Operand(0x00000780)), "orr w0, wzr, #0x780");
647   COMPARE(orr(w1, wzr, Operand(0x00007800)), "orr w1, wzr, #0x7800");
648   COMPARE(orr(w2, wzr, Operand(0x00078000)), "mov w2, #0x78000");
649   COMPARE(orr(w3, wzr, Operand(0x00780000)), "orr w3, wzr, #0x780000");
650   COMPARE(orr(w4, wzr, Operand(0x07800000)), "orr w4, wzr, #0x7800000");
651   COMPARE(orr(x5, xzr, Operand(0xffffffffffffc001)),
652           "orr x5, xzr, #0xffffffffffffc001");
653   COMPARE(orr(x6, xzr, Operand(0xfffffffffffc001f)),
654           "mov x6, #0xfffffffffffc001f");
655   COMPARE(orr(x7, xzr, Operand(0xffffffffffc001ff)),
656           "mov x7, #0xffffffffffc001ff");
657   COMPARE(orr(x8, xzr, Operand(0xfffffffffc001fff)),
658           "mov x8, #0xfffffffffc001fff");
659   COMPARE(orr(x9, xzr, Operand(0xffffffffc001ffff)),
660           "orr x9, xzr, #0xffffffffc001ffff");
661 
662   CLEANUP();
663 }
664 
665 
TEST(logical_shifted)666 TEST(logical_shifted) {
667   SETUP();
668 
669   COMPARE(and_(w0, w1, Operand(w2)), "and w0, w1, w2");
670   COMPARE(and_(x3, x4, Operand(x5, LSL, 1)), "and x3, x4, x5, lsl #1");
671   COMPARE(and_(w6, w7, Operand(w8, LSR, 2)), "and w6, w7, w8, lsr #2");
672   COMPARE(and_(x9, x10, Operand(x11, ASR, 3)), "and x9, x10, x11, asr #3");
673   COMPARE(and_(w12, w13, Operand(w14, ROR, 4)), "and w12, w13, w14, ror #4");
674 
675   COMPARE(bic(w15, w16, Operand(w17)), "bic w15, w16, w17");
676   COMPARE(bic(x18, x19, Operand(x20, LSL, 5)), "bic x18, x19, x20, lsl #5");
677   COMPARE(bic(w21, w22, Operand(w23, LSR, 6)), "bic w21, w22, w23, lsr #6");
678   COMPARE(bic(x24, x25, Operand(x26, ASR, 7)), "bic x24, x25, x26, asr #7");
679   COMPARE(bic(w27, w28, Operand(w29, ROR, 8)), "bic w27, w28, w29, ror #8");
680 
681   COMPARE(orr(w0, w1, Operand(w2)), "orr w0, w1, w2");
682   COMPARE(orr(x3, x4, Operand(x5, LSL, 9)), "orr x3, x4, x5, lsl #9");
683   COMPARE(orr(w6, w7, Operand(w8, LSR, 10)), "orr w6, w7, w8, lsr #10");
684   COMPARE(orr(x9, x10, Operand(x11, ASR, 11)), "orr x9, x10, x11, asr #11");
685   COMPARE(orr(w12, w13, Operand(w14, ROR, 12)), "orr w12, w13, w14, ror #12");
686 
687   COMPARE(orn(w15, w16, Operand(w17)), "orn w15, w16, w17");
688   COMPARE(orn(x18, x19, Operand(x20, LSL, 13)), "orn x18, x19, x20, lsl #13");
689   COMPARE(orn(w21, w22, Operand(w23, LSR, 14)), "orn w21, w22, w23, lsr #14");
690   COMPARE(orn(x24, x25, Operand(x26, ASR, 15)), "orn x24, x25, x26, asr #15");
691   COMPARE(orn(w27, w28, Operand(w29, ROR, 16)), "orn w27, w28, w29, ror #16");
692 
693   COMPARE(eor(w0, w1, Operand(w2)), "eor w0, w1, w2");
694   COMPARE(eor(x3, x4, Operand(x5, LSL, 17)), "eor x3, x4, x5, lsl #17");
695   COMPARE(eor(w6, w7, Operand(w8, LSR, 18)), "eor w6, w7, w8, lsr #18");
696   COMPARE(eor(x9, x10, Operand(x11, ASR, 19)), "eor x9, x10, x11, asr #19");
697   COMPARE(eor(w12, w13, Operand(w14, ROR, 20)), "eor w12, w13, w14, ror #20");
698 
699   COMPARE(eon(w15, w16, Operand(w17)), "eon w15, w16, w17");
700   COMPARE(eon(x18, x19, Operand(x20, LSL, 21)), "eon x18, x19, x20, lsl #21");
701   COMPARE(eon(w21, w22, Operand(w23, LSR, 22)), "eon w21, w22, w23, lsr #22");
702   COMPARE(eon(x24, x25, Operand(x26, ASR, 23)), "eon x24, x25, x26, asr #23");
703   COMPARE(eon(w27, w28, Operand(w29, ROR, 24)), "eon w27, w28, w29, ror #24");
704 
705   COMPARE(ands(w0, w1, Operand(w2)), "ands w0, w1, w2");
706   COMPARE(ands(x3, x4, Operand(x5, LSL, 1)), "ands x3, x4, x5, lsl #1");
707   COMPARE(ands(w6, w7, Operand(w8, LSR, 2)), "ands w6, w7, w8, lsr #2");
708   COMPARE(ands(x9, x10, Operand(x11, ASR, 3)), "ands x9, x10, x11, asr #3");
709   COMPARE(ands(w12, w13, Operand(w14, ROR, 4)), "ands w12, w13, w14, ror #4");
710 
711   COMPARE(bics(w15, w16, Operand(w17)), "bics w15, w16, w17");
712   COMPARE(bics(x18, x19, Operand(x20, LSL, 5)), "bics x18, x19, x20, lsl #5");
713   COMPARE(bics(w21, w22, Operand(w23, LSR, 6)), "bics w21, w22, w23, lsr #6");
714   COMPARE(bics(x24, x25, Operand(x26, ASR, 7)), "bics x24, x25, x26, asr #7");
715   COMPARE(bics(w27, w28, Operand(w29, ROR, 8)), "bics w27, w28, w29, ror #8");
716 
717   COMPARE(tst(w0, Operand(w1)), "tst w0, w1");
718   COMPARE(tst(w2, Operand(w3, ROR, 10)), "tst w2, w3, ror #10");
719   COMPARE(tst(x0, Operand(x1)), "tst x0, x1");
720   COMPARE(tst(x2, Operand(x3, ROR, 42)), "tst x2, x3, ror #42");
721 
722   COMPARE(orn(w0, wzr, Operand(w1)), "mvn w0, w1");
723   COMPARE(orn(w2, wzr, Operand(w3, ASR, 5)), "mvn w2, w3, asr #5");
724   COMPARE(orn(x0, xzr, Operand(x1)), "mvn x0, x1");
725   COMPARE(orn(x2, xzr, Operand(x3, ASR, 42)), "mvn x2, x3, asr #42");
726 
727   COMPARE(orr(w0, wzr, Operand(w1)), "mov w0, w1");
728   COMPARE(orr(x0, xzr, Operand(x1)), "mov x0, x1");
729   COMPARE(orr(w16, wzr, Operand(w17, LSL, 1)), "orr w16, wzr, w17, lsl #1");
730   COMPARE(orr(x16, xzr, Operand(x17, ASR, 2)), "orr x16, xzr, x17, asr #2");
731 
732   CLEANUP();
733 }
734 
735 
TEST(dp_2_source)736 TEST(dp_2_source) {
737   SETUP();
738 
739   COMPARE(lslv(w0, w1, w2), "lsl w0, w1, w2");
740   COMPARE(lslv(x3, x4, x5), "lsl x3, x4, x5");
741   COMPARE(lsrv(w6, w7, w8), "lsr w6, w7, w8");
742   COMPARE(lsrv(x9, x10, x11), "lsr x9, x10, x11");
743   COMPARE(asrv(w12, w13, w14), "asr w12, w13, w14");
744   COMPARE(asrv(x15, x16, x17), "asr x15, x16, x17");
745   COMPARE(rorv(w18, w19, w20), "ror w18, w19, w20");
746   COMPARE(rorv(x21, x22, x23), "ror x21, x22, x23");
747 
748   CLEANUP();
749 }
750 
TEST(adr)751 TEST(adr) {
752   SETUP();
753 
754   COMPARE_PREFIX(adr(x0, 0), "adr x0, #+0x0");
755   COMPARE_PREFIX(adr(x1, 1), "adr x1, #+0x1");
756   COMPARE_PREFIX(adr(x2, -1), "adr x2, #-0x1");
757   COMPARE_PREFIX(adr(x3, 4), "adr x3, #+0x4");
758   COMPARE_PREFIX(adr(x4, -4), "adr x4, #-0x4");
759   COMPARE_PREFIX(adr(x5, 0x000fffff), "adr x5, #+0xfffff");
760   COMPARE_PREFIX(adr(x6, -0x00100000), "adr x6, #-0x100000");
761   COMPARE_PREFIX(adr(xzr, 0), "adr xzr, #+0x0");
762 
763   CLEANUP();
764 }
765 
TEST(branch)766 TEST(branch) {
767   SETUP();
768 
769   #define INST_OFF(x) ((x) >> kInstructionSizeLog2)
770   COMPARE_PREFIX(b(INST_OFF(0x4)), "b #+0x4");
771   COMPARE_PREFIX(b(INST_OFF(-0x4)), "b #-0x4");
772   COMPARE_PREFIX(b(INST_OFF(0x7fffffc)), "b #+0x7fffffc");
773   COMPARE_PREFIX(b(INST_OFF(-0x8000000)), "b #-0x8000000");
774   COMPARE_PREFIX(b(INST_OFF(0xffffc), eq), "b.eq #+0xffffc");
775   COMPARE_PREFIX(b(INST_OFF(-0x100000), mi), "b.mi #-0x100000");
776   COMPARE_PREFIX(b(INST_OFF(0xffffc), al), "b.al #+0xffffc");
777   COMPARE_PREFIX(b(INST_OFF(-0x100000), nv), "b.nv #-0x100000");
778   COMPARE_PREFIX(bl(INST_OFF(0x4)), "bl #+0x4");
779   COMPARE_PREFIX(bl(INST_OFF(-0x4)), "bl #-0x4");
780   COMPARE_PREFIX(bl(INST_OFF(0xffffc)), "bl #+0xffffc");
781   COMPARE_PREFIX(bl(INST_OFF(-0x100000)), "bl #-0x100000");
782   COMPARE_PREFIX(cbz(w0, INST_OFF(0xffffc)), "cbz w0, #+0xffffc");
783   COMPARE_PREFIX(cbz(x1, INST_OFF(-0x100000)), "cbz x1, #-0x100000");
784   COMPARE_PREFIX(cbnz(w2, INST_OFF(0xffffc)), "cbnz w2, #+0xffffc");
785   COMPARE_PREFIX(cbnz(x3, INST_OFF(-0x100000)), "cbnz x3, #-0x100000");
786   COMPARE_PREFIX(tbz(w4, 0, INST_OFF(0x7ffc)), "tbz w4, #0, #+0x7ffc");
787   COMPARE_PREFIX(tbz(x5, 63, INST_OFF(-0x8000)), "tbz x5, #63, #-0x8000");
788   COMPARE_PREFIX(tbz(w6, 31, INST_OFF(0)), "tbz w6, #31, #+0x0");
789   COMPARE_PREFIX(tbz(x7, 31, INST_OFF(0x4)), "tbz w7, #31, #+0x4");
790   COMPARE_PREFIX(tbz(x8, 32, INST_OFF(0x8)), "tbz x8, #32, #+0x8");
791   COMPARE_PREFIX(tbnz(w8, 0, INST_OFF(0x7ffc)), "tbnz w8, #0, #+0x7ffc");
792   COMPARE_PREFIX(tbnz(x9, 63, INST_OFF(-0x8000)), "tbnz x9, #63, #-0x8000");
793   COMPARE_PREFIX(tbnz(w10, 31, INST_OFF(0)), "tbnz w10, #31, #+0x0");
794   COMPARE_PREFIX(tbnz(x11, 31, INST_OFF(0x4)), "tbnz w11, #31, #+0x4");
795   COMPARE_PREFIX(tbnz(x12, 32, INST_OFF(0x8)), "tbnz x12, #32, #+0x8");
796   COMPARE(br(x0), "br x0");
797   COMPARE(blr(x1), "blr x1");
798   COMPARE(ret(x2), "ret x2");
799   COMPARE(ret(lr), "ret")
800 
801   CLEANUP();
802 }
803 
TEST(load_store)804 TEST(load_store) {
805   SETUP();
806 
807   COMPARE(ldr(w0, MemOperand(x1)), "ldr w0, [x1]");
808   COMPARE(ldr(w2, MemOperand(x3, 4)), "ldr w2, [x3, #4]");
809   COMPARE(ldr(w4, MemOperand(x5, 16380)), "ldr w4, [x5, #16380]");
810   COMPARE(ldr(x6, MemOperand(x7)), "ldr x6, [x7]");
811   COMPARE(ldr(x8, MemOperand(x9, 8)), "ldr x8, [x9, #8]");
812   COMPARE(ldr(x10, MemOperand(x11, 32760)), "ldr x10, [x11, #32760]");
813   COMPARE(str(w12, MemOperand(x13)), "str w12, [x13]");
814   COMPARE(str(w14, MemOperand(x15, 4)), "str w14, [x15, #4]");
815   COMPARE(str(w16, MemOperand(x17, 16380)), "str w16, [x17, #16380]");
816   COMPARE(str(x18, MemOperand(x19)), "str x18, [x19]");
817   COMPARE(str(x20, MemOperand(x21, 8)), "str x20, [x21, #8]");
818   COMPARE(str(x22, MemOperand(x23, 32760)), "str x22, [x23, #32760]");
819 
820   COMPARE(ldr(w0, MemOperand(x1, 4, PreIndex)), "ldr w0, [x1, #4]!");
821   COMPARE(ldr(w2, MemOperand(x3, 255, PreIndex)), "ldr w2, [x3, #255]!");
822   COMPARE(ldr(w4, MemOperand(x5, -256, PreIndex)), "ldr w4, [x5, #-256]!");
823   COMPARE(ldr(x6, MemOperand(x7, 8, PreIndex)), "ldr x6, [x7, #8]!");
824   COMPARE(ldr(x8, MemOperand(x9, 255, PreIndex)), "ldr x8, [x9, #255]!");
825   COMPARE(ldr(x10, MemOperand(x11, -256, PreIndex)), "ldr x10, [x11, #-256]!");
826   COMPARE(str(w12, MemOperand(x13, 4, PreIndex)), "str w12, [x13, #4]!");
827   COMPARE(str(w14, MemOperand(x15, 255, PreIndex)), "str w14, [x15, #255]!");
828   COMPARE(str(w16, MemOperand(x17, -256, PreIndex)), "str w16, [x17, #-256]!");
829   COMPARE(str(x18, MemOperand(x19, 8, PreIndex)), "str x18, [x19, #8]!");
830   COMPARE(str(x20, MemOperand(x21, 255, PreIndex)), "str x20, [x21, #255]!");
831   COMPARE(str(x22, MemOperand(x23, -256, PreIndex)), "str x22, [x23, #-256]!");
832 
833   COMPARE(ldr(w0, MemOperand(x1, 4, PostIndex)), "ldr w0, [x1], #4");
834   COMPARE(ldr(w2, MemOperand(x3, 255, PostIndex)), "ldr w2, [x3], #255");
835   COMPARE(ldr(w4, MemOperand(x5, -256, PostIndex)), "ldr w4, [x5], #-256");
836   COMPARE(ldr(x6, MemOperand(x7, 8, PostIndex)), "ldr x6, [x7], #8");
837   COMPARE(ldr(x8, MemOperand(x9, 255, PostIndex)), "ldr x8, [x9], #255");
838   COMPARE(ldr(x10, MemOperand(x11, -256, PostIndex)), "ldr x10, [x11], #-256");
839   COMPARE(str(w12, MemOperand(x13, 4, PostIndex)), "str w12, [x13], #4");
840   COMPARE(str(w14, MemOperand(x15, 255, PostIndex)), "str w14, [x15], #255");
841   COMPARE(str(w16, MemOperand(x17, -256, PostIndex)), "str w16, [x17], #-256");
842   COMPARE(str(x18, MemOperand(x19, 8, PostIndex)), "str x18, [x19], #8");
843   COMPARE(str(x20, MemOperand(x21, 255, PostIndex)), "str x20, [x21], #255");
844   COMPARE(str(x22, MemOperand(x23, -256, PostIndex)), "str x22, [x23], #-256");
845 
846   COMPARE(ldr(w24, MemOperand(sp)), "ldr w24, [sp]");
847   COMPARE(ldr(x25, MemOperand(sp, 8)), "ldr x25, [sp, #8]");
848   COMPARE(str(w26, MemOperand(sp, 4, PreIndex)), "str w26, [sp, #4]!");
849   COMPARE(str(x27, MemOperand(sp, -8, PostIndex)), "str x27, [sp], #-8");
850 
851   COMPARE(ldrsw(x0, MemOperand(x1)), "ldrsw x0, [x1]");
852   COMPARE(ldrsw(x2, MemOperand(x3, 8)), "ldrsw x2, [x3, #8]");
853   COMPARE(ldrsw(x4, MemOperand(x5, 42, PreIndex)), "ldrsw x4, [x5, #42]!");
854   COMPARE(ldrsw(x6, MemOperand(x7, -11, PostIndex)), "ldrsw x6, [x7], #-11");
855 
856   CLEANUP();
857 }
858 
859 
TEST(load_store_regoffset)860 TEST(load_store_regoffset) {
861   SETUP();
862 
863   COMPARE(ldr(w0, MemOperand(x1, w2, UXTW)), "ldr w0, [x1, w2, uxtw]");
864   COMPARE(ldr(w3, MemOperand(x4, w5, UXTW, 2)), "ldr w3, [x4, w5, uxtw #2]");
865   COMPARE(ldr(w6, MemOperand(x7, x8)), "ldr w6, [x7, x8]");
866   COMPARE(ldr(w9, MemOperand(x10, x11, LSL, 2)), "ldr w9, [x10, x11, lsl #2]");
867   COMPARE(ldr(w12, MemOperand(x13, w14, SXTW)), "ldr w12, [x13, w14, sxtw]");
868   COMPARE(ldr(w15, MemOperand(x16, w17, SXTW, 2)),
869           "ldr w15, [x16, w17, sxtw #2]");
870   COMPARE(ldr(w18, MemOperand(x19, x20, SXTX)), "ldr w18, [x19, x20, sxtx]");
871   COMPARE(ldr(w21, MemOperand(x22, x23, SXTX, 2)),
872           "ldr w21, [x22, x23, sxtx #2]");
873   COMPARE(ldr(x0, MemOperand(x1, w2, UXTW)), "ldr x0, [x1, w2, uxtw]");
874   COMPARE(ldr(x3, MemOperand(x4, w5, UXTW, 3)), "ldr x3, [x4, w5, uxtw #3]");
875   COMPARE(ldr(x6, MemOperand(x7, x8)), "ldr x6, [x7, x8]");
876   COMPARE(ldr(x9, MemOperand(x10, x11, LSL, 3)), "ldr x9, [x10, x11, lsl #3]");
877   COMPARE(ldr(x12, MemOperand(x13, w14, SXTW)), "ldr x12, [x13, w14, sxtw]");
878   COMPARE(ldr(x15, MemOperand(x16, w17, SXTW, 3)),
879           "ldr x15, [x16, w17, sxtw #3]");
880   COMPARE(ldr(x18, MemOperand(x19, x20, SXTX)), "ldr x18, [x19, x20, sxtx]");
881   COMPARE(ldr(x21, MemOperand(x22, x23, SXTX, 3)),
882           "ldr x21, [x22, x23, sxtx #3]");
883 
884   COMPARE(str(w0, MemOperand(x1, w2, UXTW)), "str w0, [x1, w2, uxtw]");
885   COMPARE(str(w3, MemOperand(x4, w5, UXTW, 2)), "str w3, [x4, w5, uxtw #2]");
886   COMPARE(str(w6, MemOperand(x7, x8)), "str w6, [x7, x8]");
887   COMPARE(str(w9, MemOperand(x10, x11, LSL, 2)), "str w9, [x10, x11, lsl #2]");
888   COMPARE(str(w12, MemOperand(x13, w14, SXTW)), "str w12, [x13, w14, sxtw]");
889   COMPARE(str(w15, MemOperand(x16, w17, SXTW, 2)),
890           "str w15, [x16, w17, sxtw #2]");
891   COMPARE(str(w18, MemOperand(x19, x20, SXTX)), "str w18, [x19, x20, sxtx]");
892   COMPARE(str(w21, MemOperand(x22, x23, SXTX, 2)),
893           "str w21, [x22, x23, sxtx #2]");
894   COMPARE(str(x0, MemOperand(x1, w2, UXTW)), "str x0, [x1, w2, uxtw]");
895   COMPARE(str(x3, MemOperand(x4, w5, UXTW, 3)), "str x3, [x4, w5, uxtw #3]");
896   COMPARE(str(x6, MemOperand(x7, x8)), "str x6, [x7, x8]");
897   COMPARE(str(x9, MemOperand(x10, x11, LSL, 3)), "str x9, [x10, x11, lsl #3]");
898   COMPARE(str(x12, MemOperand(x13, w14, SXTW)), "str x12, [x13, w14, sxtw]");
899   COMPARE(str(x15, MemOperand(x16, w17, SXTW, 3)),
900           "str x15, [x16, w17, sxtw #3]");
901   COMPARE(str(x18, MemOperand(x19, x20, SXTX)), "str x18, [x19, x20, sxtx]");
902   COMPARE(str(x21, MemOperand(x22, x23, SXTX, 3)),
903           "str x21, [x22, x23, sxtx #3]");
904 
905   COMPARE(ldrb(w0, MemOperand(x1, w2, UXTW)), "ldrb w0, [x1, w2, uxtw]");
906   COMPARE(ldrb(w6, MemOperand(x7, x8)), "ldrb w6, [x7, x8]");
907   COMPARE(ldrb(w12, MemOperand(x13, w14, SXTW)), "ldrb w12, [x13, w14, sxtw]");
908   COMPARE(ldrb(w18, MemOperand(x19, x20, SXTX)), "ldrb w18, [x19, x20, sxtx]");
909   COMPARE(strb(w0, MemOperand(x1, w2, UXTW)), "strb w0, [x1, w2, uxtw]");
910   COMPARE(strb(w6, MemOperand(x7, x8)), "strb w6, [x7, x8]");
911   COMPARE(strb(w12, MemOperand(x13, w14, SXTW)), "strb w12, [x13, w14, sxtw]");
912   COMPARE(strb(w18, MemOperand(x19, x20, SXTX)), "strb w18, [x19, x20, sxtx]");
913 
914   COMPARE(ldrh(w0, MemOperand(x1, w2, UXTW)), "ldrh w0, [x1, w2, uxtw]");
915   COMPARE(ldrh(w3, MemOperand(x4, w5, UXTW, 1)), "ldrh w3, [x4, w5, uxtw #1]");
916   COMPARE(ldrh(w6, MemOperand(x7, x8)), "ldrh w6, [x7, x8]");
917   COMPARE(ldrh(w9, MemOperand(x10, x11, LSL, 1)),
918           "ldrh w9, [x10, x11, lsl #1]");
919   COMPARE(ldrh(w12, MemOperand(x13, w14, SXTW)), "ldrh w12, [x13, w14, sxtw]");
920   COMPARE(ldrh(w15, MemOperand(x16, w17, SXTW, 1)),
921           "ldrh w15, [x16, w17, sxtw #1]");
922   COMPARE(ldrh(w18, MemOperand(x19, x20, SXTX)), "ldrh w18, [x19, x20, sxtx]");
923   COMPARE(ldrh(w21, MemOperand(x22, x23, SXTX, 1)),
924           "ldrh w21, [x22, x23, sxtx #1]");
925   COMPARE(strh(w0, MemOperand(x1, w2, UXTW)), "strh w0, [x1, w2, uxtw]");
926   COMPARE(strh(w3, MemOperand(x4, w5, UXTW, 1)), "strh w3, [x4, w5, uxtw #1]");
927   COMPARE(strh(w6, MemOperand(x7, x8)), "strh w6, [x7, x8]");
928   COMPARE(strh(w9, MemOperand(x10, x11, LSL, 1)),
929           "strh w9, [x10, x11, lsl #1]");
930   COMPARE(strh(w12, MemOperand(x13, w14, SXTW)), "strh w12, [x13, w14, sxtw]");
931   COMPARE(strh(w15, MemOperand(x16, w17, SXTW, 1)),
932           "strh w15, [x16, w17, sxtw #1]");
933   COMPARE(strh(w18, MemOperand(x19, x20, SXTX)), "strh w18, [x19, x20, sxtx]");
934   COMPARE(strh(w21, MemOperand(x22, x23, SXTX, 1)),
935           "strh w21, [x22, x23, sxtx #1]");
936 
937   COMPARE(ldr(x0, MemOperand(sp, wzr, SXTW)), "ldr x0, [sp, wzr, sxtw]");
938   COMPARE(str(x1, MemOperand(sp, xzr)), "str x1, [sp, xzr]");
939 
940   CLEANUP();
941 }
942 
943 
TEST(load_store_byte)944 TEST(load_store_byte) {
945   SETUP();
946 
947   COMPARE(ldrb(w0, MemOperand(x1)), "ldrb w0, [x1]");
948   COMPARE(ldrb(x2, MemOperand(x3)), "ldrb w2, [x3]");
949   COMPARE(ldrb(w4, MemOperand(x5, 4095)), "ldrb w4, [x5, #4095]");
950   COMPARE(ldrb(w6, MemOperand(x7, 255, PreIndex)), "ldrb w6, [x7, #255]!");
951   COMPARE(ldrb(w8, MemOperand(x9, -256, PreIndex)), "ldrb w8, [x9, #-256]!");
952   COMPARE(ldrb(w10, MemOperand(x11, 255, PostIndex)), "ldrb w10, [x11], #255");
953   COMPARE(ldrb(w12, MemOperand(x13, -256, PostIndex)),
954           "ldrb w12, [x13], #-256");
955   COMPARE(strb(w14, MemOperand(x15)), "strb w14, [x15]");
956   COMPARE(strb(x16, MemOperand(x17)), "strb w16, [x17]");
957   COMPARE(strb(w18, MemOperand(x19, 4095)), "strb w18, [x19, #4095]");
958   COMPARE(strb(w20, MemOperand(x21, 255, PreIndex)), "strb w20, [x21, #255]!");
959   COMPARE(strb(w22, MemOperand(x23, -256, PreIndex)),
960           "strb w22, [x23, #-256]!");
961   COMPARE(strb(w24, MemOperand(x25, 255, PostIndex)), "strb w24, [x25], #255");
962   COMPARE(strb(w26, MemOperand(x27, -256, PostIndex)),
963           "strb w26, [x27], #-256");
964   COMPARE(ldrb(w28, MemOperand(sp, 3, PostIndex)), "ldrb w28, [sp], #3");
965   COMPARE(strb(x29, MemOperand(sp, -42, PreIndex)), "strb w29, [sp, #-42]!");
966   COMPARE(ldrsb(w0, MemOperand(x1)), "ldrsb w0, [x1]");
967   COMPARE(ldrsb(x2, MemOperand(x3, 8)), "ldrsb x2, [x3, #8]");
968   COMPARE(ldrsb(w4, MemOperand(x5, 42, PreIndex)), "ldrsb w4, [x5, #42]!");
969   COMPARE(ldrsb(x6, MemOperand(x7, -11, PostIndex)), "ldrsb x6, [x7], #-11");
970 
971   CLEANUP();
972 }
973 
974 
TEST(load_store_half)975 TEST(load_store_half) {
976   SETUP();
977 
978   COMPARE(ldrh(w0, MemOperand(x1)), "ldrh w0, [x1]");
979   COMPARE(ldrh(x2, MemOperand(x3)), "ldrh w2, [x3]");
980   COMPARE(ldrh(w4, MemOperand(x5, 8190)), "ldrh w4, [x5, #8190]");
981   COMPARE(ldrh(w6, MemOperand(x7, 255, PreIndex)), "ldrh w6, [x7, #255]!");
982   COMPARE(ldrh(w8, MemOperand(x9, -256, PreIndex)), "ldrh w8, [x9, #-256]!");
983   COMPARE(ldrh(w10, MemOperand(x11, 255, PostIndex)), "ldrh w10, [x11], #255");
984   COMPARE(ldrh(w12, MemOperand(x13, -256, PostIndex)),
985           "ldrh w12, [x13], #-256");
986   COMPARE(strh(w14, MemOperand(x15)), "strh w14, [x15]");
987   COMPARE(strh(x16, MemOperand(x17)), "strh w16, [x17]");
988   COMPARE(strh(w18, MemOperand(x19, 8190)), "strh w18, [x19, #8190]");
989   COMPARE(strh(w20, MemOperand(x21, 255, PreIndex)), "strh w20, [x21, #255]!");
990   COMPARE(strh(w22, MemOperand(x23, -256, PreIndex)),
991           "strh w22, [x23, #-256]!");
992   COMPARE(strh(w24, MemOperand(x25, 255, PostIndex)), "strh w24, [x25], #255");
993   COMPARE(strh(w26, MemOperand(x27, -256, PostIndex)),
994           "strh w26, [x27], #-256");
995   COMPARE(ldrh(w28, MemOperand(sp, 3, PostIndex)), "ldrh w28, [sp], #3");
996   COMPARE(strh(x29, MemOperand(sp, -42, PreIndex)), "strh w29, [sp, #-42]!");
997   COMPARE(ldrh(w30, MemOperand(x0, 255)), "ldurh w30, [x0, #255]");
998   COMPARE(ldrh(x1, MemOperand(x2, -256)), "ldurh w1, [x2, #-256]");
999   COMPARE(strh(w3, MemOperand(x4, 255)), "sturh w3, [x4, #255]");
1000   COMPARE(strh(x5, MemOperand(x6, -256)), "sturh w5, [x6, #-256]");
1001   COMPARE(ldrsh(w0, MemOperand(x1)), "ldrsh w0, [x1]");
1002   COMPARE(ldrsh(w2, MemOperand(x3, 8)), "ldrsh w2, [x3, #8]");
1003   COMPARE(ldrsh(w4, MemOperand(x5, 42, PreIndex)), "ldrsh w4, [x5, #42]!");
1004   COMPARE(ldrsh(x6, MemOperand(x7, -11, PostIndex)), "ldrsh x6, [x7], #-11");
1005 
1006   CLEANUP();
1007 }
1008 
1009 
TEST(load_store_fp)1010 TEST(load_store_fp) {
1011   SETUP();
1012 
1013   COMPARE(ldr(s0, MemOperand(x1)), "ldr s0, [x1]");
1014   COMPARE(ldr(s2, MemOperand(x3, 4)), "ldr s2, [x3, #4]");
1015   COMPARE(ldr(s4, MemOperand(x5, 16380)), "ldr s4, [x5, #16380]");
1016   COMPARE(ldr(d6, MemOperand(x7)), "ldr d6, [x7]");
1017   COMPARE(ldr(d8, MemOperand(x9, 8)), "ldr d8, [x9, #8]");
1018   COMPARE(ldr(d10, MemOperand(x11, 32760)), "ldr d10, [x11, #32760]");
1019   COMPARE(str(s12, MemOperand(x13)), "str s12, [x13]");
1020   COMPARE(str(s14, MemOperand(x15, 4)), "str s14, [x15, #4]");
1021   COMPARE(str(s16, MemOperand(x17, 16380)), "str s16, [x17, #16380]");
1022   COMPARE(str(d18, MemOperand(x19)), "str d18, [x19]");
1023   COMPARE(str(d20, MemOperand(x21, 8)), "str d20, [x21, #8]");
1024   COMPARE(str(d22, MemOperand(x23, 32760)), "str d22, [x23, #32760]");
1025 
1026   COMPARE(ldr(s0, MemOperand(x1, 4, PreIndex)), "ldr s0, [x1, #4]!");
1027   COMPARE(ldr(s2, MemOperand(x3, 255, PreIndex)), "ldr s2, [x3, #255]!");
1028   COMPARE(ldr(s4, MemOperand(x5, -256, PreIndex)), "ldr s4, [x5, #-256]!");
1029   COMPARE(ldr(d6, MemOperand(x7, 8, PreIndex)), "ldr d6, [x7, #8]!");
1030   COMPARE(ldr(d8, MemOperand(x9, 255, PreIndex)), "ldr d8, [x9, #255]!");
1031   COMPARE(ldr(d10, MemOperand(x11, -256, PreIndex)), "ldr d10, [x11, #-256]!");
1032   COMPARE(str(s12, MemOperand(x13, 4, PreIndex)), "str s12, [x13, #4]!");
1033   COMPARE(str(s14, MemOperand(x15, 255, PreIndex)), "str s14, [x15, #255]!");
1034   COMPARE(str(s16, MemOperand(x17, -256, PreIndex)), "str s16, [x17, #-256]!");
1035   COMPARE(str(d18, MemOperand(x19, 8, PreIndex)), "str d18, [x19, #8]!");
1036   COMPARE(str(d20, MemOperand(x21, 255, PreIndex)), "str d20, [x21, #255]!");
1037   COMPARE(str(d22, MemOperand(x23, -256, PreIndex)), "str d22, [x23, #-256]!");
1038 
1039   COMPARE(ldr(s0, MemOperand(x1, 4, PostIndex)), "ldr s0, [x1], #4");
1040   COMPARE(ldr(s2, MemOperand(x3, 255, PostIndex)), "ldr s2, [x3], #255");
1041   COMPARE(ldr(s4, MemOperand(x5, -256, PostIndex)), "ldr s4, [x5], #-256");
1042   COMPARE(ldr(d6, MemOperand(x7, 8, PostIndex)), "ldr d6, [x7], #8");
1043   COMPARE(ldr(d8, MemOperand(x9, 255, PostIndex)), "ldr d8, [x9], #255");
1044   COMPARE(ldr(d10, MemOperand(x11, -256, PostIndex)), "ldr d10, [x11], #-256");
1045   COMPARE(str(s12, MemOperand(x13, 4, PostIndex)), "str s12, [x13], #4");
1046   COMPARE(str(s14, MemOperand(x15, 255, PostIndex)), "str s14, [x15], #255");
1047   COMPARE(str(s16, MemOperand(x17, -256, PostIndex)), "str s16, [x17], #-256");
1048   COMPARE(str(d18, MemOperand(x19, 8, PostIndex)), "str d18, [x19], #8");
1049   COMPARE(str(d20, MemOperand(x21, 255, PostIndex)), "str d20, [x21], #255");
1050   COMPARE(str(d22, MemOperand(x23, -256, PostIndex)), "str d22, [x23], #-256");
1051 
1052   COMPARE(ldr(s24, MemOperand(sp)), "ldr s24, [sp]");
1053   COMPARE(ldr(d25, MemOperand(sp, 8)), "ldr d25, [sp, #8]");
1054   COMPARE(str(s26, MemOperand(sp, 4, PreIndex)), "str s26, [sp, #4]!");
1055   COMPARE(str(d27, MemOperand(sp, -8, PostIndex)), "str d27, [sp], #-8");
1056 
1057   CLEANUP();
1058 }
1059 
1060 
TEST(load_store_unscaled)1061 TEST(load_store_unscaled) {
1062   SETUP();
1063 
1064   COMPARE(ldr(w0, MemOperand(x1, 1)), "ldur w0, [x1, #1]");
1065   COMPARE(ldr(w2, MemOperand(x3, -1)), "ldur w2, [x3, #-1]");
1066   COMPARE(ldr(w4, MemOperand(x5, 255)), "ldur w4, [x5, #255]");
1067   COMPARE(ldr(w6, MemOperand(x7, -256)), "ldur w6, [x7, #-256]");
1068   COMPARE(ldr(x8, MemOperand(x9, 1)), "ldur x8, [x9, #1]");
1069   COMPARE(ldr(x10, MemOperand(x11, -1)), "ldur x10, [x11, #-1]");
1070   COMPARE(ldr(x12, MemOperand(x13, 255)), "ldur x12, [x13, #255]");
1071   COMPARE(ldr(x14, MemOperand(x15, -256)), "ldur x14, [x15, #-256]");
1072   COMPARE(str(w16, MemOperand(x17, 1)), "stur w16, [x17, #1]");
1073   COMPARE(str(w18, MemOperand(x19, -1)), "stur w18, [x19, #-1]");
1074   COMPARE(str(w20, MemOperand(x21, 255)), "stur w20, [x21, #255]");
1075   COMPARE(str(w22, MemOperand(x23, -256)), "stur w22, [x23, #-256]");
1076   COMPARE(str(x24, MemOperand(x25, 1)), "stur x24, [x25, #1]");
1077   COMPARE(str(x26, MemOperand(x27, -1)), "stur x26, [x27, #-1]");
1078   COMPARE(str(x28, MemOperand(x29, 255)), "stur x28, [x29, #255]");
1079   COMPARE(str(x30, MemOperand(x0, -256)), "stur x30, [x0, #-256]");
1080   COMPARE(ldr(w0, MemOperand(sp, 1)), "ldur w0, [sp, #1]");
1081   COMPARE(str(x1, MemOperand(sp, -1)), "stur x1, [sp, #-1]");
1082   COMPARE(ldrb(w2, MemOperand(x3, -2)), "ldurb w2, [x3, #-2]");
1083   COMPARE(ldrsb(w4, MemOperand(x5, -3)), "ldursb w4, [x5, #-3]");
1084   COMPARE(ldrsb(x6, MemOperand(x7, -4)), "ldursb x6, [x7, #-4]");
1085   COMPARE(ldrh(w8, MemOperand(x9, -5)), "ldurh w8, [x9, #-5]");
1086   COMPARE(ldrsh(w10, MemOperand(x11, -6)), "ldursh w10, [x11, #-6]");
1087   COMPARE(ldrsh(x12, MemOperand(x13, -7)), "ldursh x12, [x13, #-7]");
1088   COMPARE(ldrsw(x14, MemOperand(x15, -8)), "ldursw x14, [x15, #-8]");
1089 
1090   CLEANUP();
1091 }
1092 
TEST(load_store_pair)1093 TEST(load_store_pair) {
1094   SETUP();
1095 
1096   COMPARE(ldp(w0, w1, MemOperand(x2)), "ldp w0, w1, [x2]");
1097   COMPARE(ldp(x3, x4, MemOperand(x5)), "ldp x3, x4, [x5]");
1098   COMPARE(ldp(w6, w7, MemOperand(x8, 4)), "ldp w6, w7, [x8, #4]");
1099   COMPARE(ldp(x9, x10, MemOperand(x11, 8)), "ldp x9, x10, [x11, #8]");
1100   COMPARE(ldp(w12, w13, MemOperand(x14, 252)), "ldp w12, w13, [x14, #252]");
1101   COMPARE(ldp(x15, x16, MemOperand(x17, 504)), "ldp x15, x16, [x17, #504]");
1102   COMPARE(ldp(w18, w19, MemOperand(x20, -256)), "ldp w18, w19, [x20, #-256]");
1103   COMPARE(ldp(x21, x22, MemOperand(x23, -512)), "ldp x21, x22, [x23, #-512]");
1104   COMPARE(ldp(w24, w25, MemOperand(x26, 252, PreIndex)),
1105           "ldp w24, w25, [x26, #252]!");
1106   COMPARE(ldp(x27, x28, MemOperand(x29, 504, PreIndex)),
1107           "ldp x27, x28, [x29, #504]!");
1108   COMPARE(ldp(w30, w0, MemOperand(x1, -256, PreIndex)),
1109           "ldp w30, w0, [x1, #-256]!");
1110   COMPARE(ldp(x2, x3, MemOperand(x4, -512, PreIndex)),
1111           "ldp x2, x3, [x4, #-512]!");
1112   COMPARE(ldp(w5, w6, MemOperand(x7, 252, PostIndex)),
1113           "ldp w5, w6, [x7], #252");
1114   COMPARE(ldp(x8, x9, MemOperand(x10, 504, PostIndex)),
1115           "ldp x8, x9, [x10], #504");
1116   COMPARE(ldp(w11, w12, MemOperand(x13, -256, PostIndex)),
1117           "ldp w11, w12, [x13], #-256");
1118   COMPARE(ldp(x14, x15, MemOperand(x16, -512, PostIndex)),
1119           "ldp x14, x15, [x16], #-512");
1120 
1121   COMPARE(ldp(s17, s18, MemOperand(x19)), "ldp s17, s18, [x19]");
1122   COMPARE(ldp(s20, s21, MemOperand(x22, 252)), "ldp s20, s21, [x22, #252]");
1123   COMPARE(ldp(s23, s24, MemOperand(x25, -256)), "ldp s23, s24, [x25, #-256]");
1124   COMPARE(ldp(s26, s27, MemOperand(x28, 252, PreIndex)),
1125           "ldp s26, s27, [x28, #252]!");
1126   COMPARE(ldp(s29, s30, MemOperand(x29, -256, PreIndex)),
1127           "ldp s29, s30, [x29, #-256]!");
1128   COMPARE(ldp(s31, s0, MemOperand(x1, 252, PostIndex)),
1129           "ldp s31, s0, [x1], #252");
1130   COMPARE(ldp(s2, s3, MemOperand(x4, -256, PostIndex)),
1131           "ldp s2, s3, [x4], #-256");
1132   COMPARE(ldp(d17, d18, MemOperand(x19)), "ldp d17, d18, [x19]");
1133   COMPARE(ldp(d20, d21, MemOperand(x22, 504)), "ldp d20, d21, [x22, #504]");
1134   COMPARE(ldp(d23, d24, MemOperand(x25, -512)), "ldp d23, d24, [x25, #-512]");
1135   COMPARE(ldp(d26, d27, MemOperand(x28, 504, PreIndex)),
1136           "ldp d26, d27, [x28, #504]!");
1137   COMPARE(ldp(d29, d30, MemOperand(x29, -512, PreIndex)),
1138           "ldp d29, d30, [x29, #-512]!");
1139   COMPARE(ldp(d31, d0, MemOperand(x1, 504, PostIndex)),
1140           "ldp d31, d0, [x1], #504");
1141   COMPARE(ldp(d2, d3, MemOperand(x4, -512, PostIndex)),
1142           "ldp d2, d3, [x4], #-512");
1143 
1144   COMPARE(stp(w0, w1, MemOperand(x2)), "stp w0, w1, [x2]");
1145   COMPARE(stp(x3, x4, MemOperand(x5)), "stp x3, x4, [x5]");
1146   COMPARE(stp(w6, w7, MemOperand(x8, 4)), "stp w6, w7, [x8, #4]");
1147   COMPARE(stp(x9, x10, MemOperand(x11, 8)), "stp x9, x10, [x11, #8]");
1148   COMPARE(stp(w12, w13, MemOperand(x14, 252)), "stp w12, w13, [x14, #252]");
1149   COMPARE(stp(x15, x16, MemOperand(x17, 504)), "stp x15, x16, [x17, #504]");
1150   COMPARE(stp(w18, w19, MemOperand(x20, -256)), "stp w18, w19, [x20, #-256]");
1151   COMPARE(stp(x21, x22, MemOperand(x23, -512)), "stp x21, x22, [x23, #-512]");
1152   COMPARE(stp(w24, w25, MemOperand(x26, 252, PreIndex)),
1153           "stp w24, w25, [x26, #252]!");
1154   COMPARE(stp(x27, x28, MemOperand(x29, 504, PreIndex)),
1155           "stp x27, x28, [x29, #504]!");
1156   COMPARE(stp(w30, w0, MemOperand(x1, -256, PreIndex)),
1157           "stp w30, w0, [x1, #-256]!");
1158   COMPARE(stp(x2, x3, MemOperand(x4, -512, PreIndex)),
1159           "stp x2, x3, [x4, #-512]!");
1160   COMPARE(stp(w5, w6, MemOperand(x7, 252, PostIndex)),
1161           "stp w5, w6, [x7], #252");
1162   COMPARE(stp(x8, x9, MemOperand(x10, 504, PostIndex)),
1163           "stp x8, x9, [x10], #504");
1164   COMPARE(stp(w11, w12, MemOperand(x13, -256, PostIndex)),
1165           "stp w11, w12, [x13], #-256");
1166   COMPARE(stp(x14, x15, MemOperand(x16, -512, PostIndex)),
1167           "stp x14, x15, [x16], #-512");
1168 
1169   COMPARE(stp(s17, s18, MemOperand(x19)), "stp s17, s18, [x19]");
1170   COMPARE(stp(s20, s21, MemOperand(x22, 252)), "stp s20, s21, [x22, #252]");
1171   COMPARE(stp(s23, s24, MemOperand(x25, -256)), "stp s23, s24, [x25, #-256]");
1172   COMPARE(stp(s26, s27, MemOperand(x28, 252, PreIndex)),
1173           "stp s26, s27, [x28, #252]!");
1174   COMPARE(stp(s29, s30, MemOperand(x29, -256, PreIndex)),
1175           "stp s29, s30, [x29, #-256]!");
1176   COMPARE(stp(s31, s0, MemOperand(x1, 252, PostIndex)),
1177           "stp s31, s0, [x1], #252");
1178   COMPARE(stp(s2, s3, MemOperand(x4, -256, PostIndex)),
1179           "stp s2, s3, [x4], #-256");
1180   COMPARE(stp(d17, d18, MemOperand(x19)), "stp d17, d18, [x19]");
1181   COMPARE(stp(d20, d21, MemOperand(x22, 504)), "stp d20, d21, [x22, #504]");
1182   COMPARE(stp(d23, d24, MemOperand(x25, -512)), "stp d23, d24, [x25, #-512]");
1183   COMPARE(stp(d26, d27, MemOperand(x28, 504, PreIndex)),
1184           "stp d26, d27, [x28, #504]!");
1185   COMPARE(stp(d29, d30, MemOperand(x29, -512, PreIndex)),
1186           "stp d29, d30, [x29, #-512]!");
1187   COMPARE(stp(d31, d0, MemOperand(x1, 504, PostIndex)),
1188           "stp d31, d0, [x1], #504");
1189   COMPARE(stp(d2, d3, MemOperand(x4, -512, PostIndex)),
1190           "stp d2, d3, [x4], #-512");
1191 
1192   COMPARE(ldp(w16, w17, MemOperand(sp, 4, PostIndex)),
1193           "ldp w16, w17, [sp], #4");
1194   COMPARE(stp(x18, x19, MemOperand(sp, -8, PreIndex)),
1195           "stp x18, x19, [sp, #-8]!");
1196   COMPARE(ldp(s30, s31, MemOperand(sp, 12, PostIndex)),
1197           "ldp s30, s31, [sp], #12");
1198   COMPARE(stp(d30, d31, MemOperand(sp, -16)),
1199           "stp d30, d31, [sp, #-16]");
1200 
1201   COMPARE(ldpsw(x0, x1, MemOperand(x2)), "ldpsw x0, x1, [x2]");
1202   COMPARE(ldpsw(x3, x4, MemOperand(x5, 16)), "ldpsw x3, x4, [x5, #16]");
1203   COMPARE(ldpsw(x6, x7, MemOperand(x8, -32, PreIndex)),
1204           "ldpsw x6, x7, [x8, #-32]!");
1205   COMPARE(ldpsw(x9, x10, MemOperand(x11, 128, PostIndex)),
1206           "ldpsw x9, x10, [x11], #128");
1207 
1208   CLEANUP();
1209 }
1210 
TEST(load_store_pair_nontemp)1211 TEST(load_store_pair_nontemp) {
1212   SETUP();
1213 
1214   COMPARE(ldnp(w0, w1, MemOperand(x2)), "ldnp w0, w1, [x2]");
1215   COMPARE(stnp(w3, w4, MemOperand(x5, 252)), "stnp w3, w4, [x5, #252]");
1216   COMPARE(ldnp(w6, w7, MemOperand(x8, -256)), "ldnp w6, w7, [x8, #-256]");
1217   COMPARE(stnp(x9, x10, MemOperand(x11)), "stnp x9, x10, [x11]");
1218   COMPARE(ldnp(x12, x13, MemOperand(x14, 504)), "ldnp x12, x13, [x14, #504]");
1219   COMPARE(stnp(x15, x16, MemOperand(x17, -512)), "stnp x15, x16, [x17, #-512]");
1220   COMPARE(ldnp(s18, s19, MemOperand(x20)), "ldnp s18, s19, [x20]");
1221   COMPARE(stnp(s21, s22, MemOperand(x23, 252)), "stnp s21, s22, [x23, #252]");
1222   COMPARE(ldnp(s24, s25, MemOperand(x26, -256)), "ldnp s24, s25, [x26, #-256]");
1223   COMPARE(stnp(d27, d28, MemOperand(x29)), "stnp d27, d28, [x29]");
1224   COMPARE(ldnp(d30, d31, MemOperand(x0, 504)), "ldnp d30, d31, [x0, #504]");
1225   COMPARE(stnp(d1, d2, MemOperand(x3, -512)), "stnp d1, d2, [x3, #-512]");
1226 
1227   CLEANUP();
1228 }
1229 
TEST(load_literal)1230 TEST(load_literal) {
1231   SETUP();
1232 
1233   COMPARE_PREFIX(ldr(x10, 0x1234567890abcdef),  "ldr x10, pc+8");
1234   COMPARE_PREFIX(ldr(w20, 0xfedcba09),  "ldr w20, pc+8");
1235   COMPARE_PREFIX(ldr(d11, 1.234),  "ldr d11, pc+8");
1236   COMPARE_PREFIX(ldr(s22, 2.5f),  "ldr s22, pc+8");
1237 
1238   CLEANUP();
1239 }
1240 
TEST(cond_select)1241 TEST(cond_select) {
1242   SETUP();
1243 
1244   COMPARE(csel(w0, w1, w2, eq), "csel w0, w1, w2, eq");
1245   COMPARE(csel(x3, x4, x5, ne), "csel x3, x4, x5, ne");
1246   COMPARE(csinc(w6, w7, w8, hs), "csinc w6, w7, w8, hs");
1247   COMPARE(csinc(x9, x10, x11, lo), "csinc x9, x10, x11, lo");
1248   COMPARE(csinv(w12, w13, w14, mi), "csinv w12, w13, w14, mi");
1249   COMPARE(csinv(x15, x16, x17, pl), "csinv x15, x16, x17, pl");
1250   COMPARE(csneg(w18, w19, w20, vs), "csneg w18, w19, w20, vs");
1251   COMPARE(csneg(x21, x22, x23, vc), "csneg x21, x22, x23, vc");
1252   COMPARE(cset(w24, hi), "cset w24, hi");
1253   COMPARE(cset(x25, ls), "cset x25, ls");
1254   COMPARE(csetm(w26, ge), "csetm w26, ge");
1255   COMPARE(csetm(x27, lt), "csetm x27, lt");
1256   COMPARE(cinc(w28, w29, gt), "cinc w28, w29, gt");
1257   COMPARE(cinc(x30, x0, le), "cinc x30, x0, le");
1258   COMPARE(cinv(w1, w2, eq), "cinv w1, w2, eq");
1259   COMPARE(cinv(x3, x4, ne), "cinv x3, x4, ne");
1260   COMPARE(cneg(w5, w6, hs), "cneg w5, w6, hs");
1261   COMPARE(cneg(x7, x8, lo), "cneg x7, x8, lo");
1262 
1263   COMPARE(csel(x0, x1, x2, al), "csel x0, x1, x2, al");
1264   COMPARE(csel(x1, x2, x3, nv), "csel x1, x2, x3, nv");
1265   COMPARE(csinc(x2, x3, x4, al), "csinc x2, x3, x4, al");
1266   COMPARE(csinc(x3, x4, x5, nv), "csinc x3, x4, x5, nv");
1267   COMPARE(csinv(x4, x5, x6, al), "csinv x4, x5, x6, al");
1268   COMPARE(csinv(x5, x6, x7, nv), "csinv x5, x6, x7, nv");
1269   COMPARE(csneg(x6, x7, x8, al), "csneg x6, x7, x8, al");
1270   COMPARE(csneg(x7, x8, x9, nv), "csneg x7, x8, x9, nv");
1271 
1272   CLEANUP();
1273 }
1274 
TEST(cond_select_macro)1275 TEST(cond_select_macro) {
1276   SETUP_CLASS(MacroAssembler);
1277 
1278   COMPARE(Csel(w0, w1, -1, eq), "csinv w0, w1, wzr, eq");
1279   COMPARE(Csel(w2, w3, 0, ne), "csel w2, w3, wzr, ne");
1280   COMPARE(Csel(w4, w5, 1, hs), "csinc w4, w5, wzr, hs");
1281   COMPARE(Csel(x6, x7, -1, lo), "csinv x6, x7, xzr, lo");
1282   COMPARE(Csel(x8, x9, 0, mi), "csel x8, x9, xzr, mi");
1283   COMPARE(Csel(x10, x11, 1, pl), "csinc x10, x11, xzr, pl");
1284 
1285   CLEANUP();
1286 }
1287 
TEST(cond_cmp)1288 TEST(cond_cmp) {
1289   SETUP();
1290 
1291   COMPARE(ccmn(w0, w1, NZCVFlag, eq), "ccmn w0, w1, #NZCV, eq");
1292   COMPARE(ccmn(x2, x3, NZCFlag, ne), "ccmn x2, x3, #NZCv, ne");
1293   COMPARE(ccmp(w4, w5, NZVFlag, hs), "ccmp w4, w5, #NZcV, hs");
1294   COMPARE(ccmp(x6, x7, NZFlag, lo), "ccmp x6, x7, #NZcv, lo");
1295   COMPARE(ccmn(w8, 31, NFlag, mi), "ccmn w8, #31, #Nzcv, mi");
1296   COMPARE(ccmn(x9, 30, NCFlag, pl), "ccmn x9, #30, #NzCv, pl");
1297   COMPARE(ccmp(w10, 29, NVFlag, vs), "ccmp w10, #29, #NzcV, vs");
1298   COMPARE(ccmp(x11, 28, NFlag, vc), "ccmp x11, #28, #Nzcv, vc");
1299   COMPARE(ccmn(w12, w13, NoFlag, al), "ccmn w12, w13, #nzcv, al");
1300   COMPARE(ccmp(x14, 27, ZVFlag, nv), "ccmp x14, #27, #nZcV, nv");
1301 
1302   CLEANUP();
1303 }
1304 
TEST(cond_cmp_macro)1305 TEST(cond_cmp_macro) {
1306   SETUP_CLASS(MacroAssembler);
1307 
1308   COMPARE(Ccmp(w0, -1, VFlag, hi), "ccmn w0, #1, #nzcV, hi");
1309   COMPARE(Ccmp(x1, -31, CFlag, ge), "ccmn x1, #31, #nzCv, ge");
1310   COMPARE(Ccmn(w2, -1, CVFlag, gt), "ccmp w2, #1, #nzCV, gt");
1311   COMPARE(Ccmn(x3, -31, ZCVFlag, ls), "ccmp x3, #31, #nZCV, ls");
1312 
1313   CLEANUP();
1314 }
1315 
TEST(fmov_imm)1316 TEST(fmov_imm) {
1317   SETUP();
1318 
1319   COMPARE(fmov(s0, 1.0f), "fmov s0, #0x70 (1.0000)");
1320   COMPARE(fmov(s31, -13.0f), "fmov s31, #0xaa (-13.0000)");
1321   COMPARE(fmov(d1, 1.0), "fmov d1, #0x70 (1.0000)");
1322   COMPARE(fmov(d29, -13.0), "fmov d29, #0xaa (-13.0000)");
1323 
1324   CLEANUP();
1325 }
1326 
TEST(fmov_reg)1327 TEST(fmov_reg) {
1328   SETUP();
1329 
1330   COMPARE(fmov(w3, s13), "fmov w3, s13");
1331   COMPARE(fmov(x6, d26), "fmov x6, d26");
1332   COMPARE(fmov(s11, w30), "fmov s11, w30");
1333   COMPARE(fmov(d31, x2), "fmov d31, x2");
1334   COMPARE(fmov(s12, s13), "fmov s12, s13");
1335   COMPARE(fmov(d22, d23), "fmov d22, d23");
1336 
1337   CLEANUP();
1338 }
1339 
1340 
TEST(fp_dp1)1341 TEST(fp_dp1) {
1342   SETUP();
1343 
1344   COMPARE(fabs(s0, s1), "fabs s0, s1");
1345   COMPARE(fabs(s31, s30), "fabs s31, s30");
1346   COMPARE(fabs(d2, d3), "fabs d2, d3");
1347   COMPARE(fabs(d31, d30), "fabs d31, d30");
1348   COMPARE(fneg(s4, s5), "fneg s4, s5");
1349   COMPARE(fneg(s31, s30), "fneg s31, s30");
1350   COMPARE(fneg(d6, d7), "fneg d6, d7");
1351   COMPARE(fneg(d31, d30), "fneg d31, d30");
1352   COMPARE(fsqrt(s8, s9), "fsqrt s8, s9");
1353   COMPARE(fsqrt(s31, s30), "fsqrt s31, s30");
1354   COMPARE(fsqrt(d10, d11), "fsqrt d10, d11");
1355   COMPARE(fsqrt(d31, d30), "fsqrt d31, d30");
1356   COMPARE(frinta(s10, s11), "frinta s10, s11");
1357   COMPARE(frinta(s31, s30), "frinta s31, s30");
1358   COMPARE(frinta(d12, d13), "frinta d12, d13");
1359   COMPARE(frinta(d31, d30), "frinta d31, d30");
1360   COMPARE(frintn(s10, s11), "frintn s10, s11");
1361   COMPARE(frintn(s31, s30), "frintn s31, s30");
1362   COMPARE(frintn(d12, d13), "frintn d12, d13");
1363   COMPARE(frintn(d31, d30), "frintn d31, d30");
1364   COMPARE(frintz(s10, s11), "frintz s10, s11");
1365   COMPARE(frintz(s31, s30), "frintz s31, s30");
1366   COMPARE(frintz(d12, d13), "frintz d12, d13");
1367   COMPARE(frintz(d31, d30), "frintz d31, d30");
1368   COMPARE(fcvt(d14, s15), "fcvt d14, s15");
1369   COMPARE(fcvt(d31, s31), "fcvt d31, s31");
1370 
1371   CLEANUP();
1372 }
1373 
1374 
TEST(fp_dp2)1375 TEST(fp_dp2) {
1376   SETUP();
1377 
1378   COMPARE(fadd(s0, s1, s2), "fadd s0, s1, s2");
1379   COMPARE(fadd(d3, d4, d5), "fadd d3, d4, d5");
1380   COMPARE(fsub(s31, s30, s29), "fsub s31, s30, s29");
1381   COMPARE(fsub(d31, d30, d29), "fsub d31, d30, d29");
1382   COMPARE(fmul(s7, s8, s9), "fmul s7, s8, s9");
1383   COMPARE(fmul(d10, d11, d12), "fmul d10, d11, d12");
1384   COMPARE(fdiv(s13, s14, s15), "fdiv s13, s14, s15");
1385   COMPARE(fdiv(d16, d17, d18), "fdiv d16, d17, d18");
1386   COMPARE(fmax(s19, s20, s21), "fmax s19, s20, s21");
1387   COMPARE(fmax(d22, d23, d24), "fmax d22, d23, d24");
1388   COMPARE(fmin(s25, s26, s27), "fmin s25, s26, s27");
1389   COMPARE(fmin(d28, d29, d30), "fmin d28, d29, d30");
1390   COMPARE(fmaxnm(s31, s0, s1), "fmaxnm s31, s0, s1");
1391   COMPARE(fmaxnm(d2, d3, d4), "fmaxnm d2, d3, d4");
1392   COMPARE(fminnm(s5, s6, s7), "fminnm s5, s6, s7");
1393   COMPARE(fminnm(d8, d9, d10), "fminnm d8, d9, d10");
1394 
1395   CLEANUP();
1396 }
1397 
1398 
TEST(fp_dp3)1399 TEST(fp_dp3) {
1400   SETUP();
1401 
1402   COMPARE(fmadd(s7, s8, s9, s10), "fmadd s7, s8, s9, s10");
1403   COMPARE(fmadd(d10, d11, d12, d10), "fmadd d10, d11, d12, d10");
1404   COMPARE(fmsub(s7, s8, s9, s10), "fmsub s7, s8, s9, s10");
1405   COMPARE(fmsub(d10, d11, d12, d10), "fmsub d10, d11, d12, d10");
1406 
1407   COMPARE(fnmadd(s7, s8, s9, s10), "fnmadd s7, s8, s9, s10");
1408   COMPARE(fnmadd(d10, d11, d12, d10), "fnmadd d10, d11, d12, d10");
1409   COMPARE(fnmsub(s7, s8, s9, s10), "fnmsub s7, s8, s9, s10");
1410   COMPARE(fnmsub(d10, d11, d12, d10), "fnmsub d10, d11, d12, d10");
1411 
1412   CLEANUP();
1413 }
1414 
1415 
TEST(fp_compare)1416 TEST(fp_compare) {
1417   SETUP();
1418 
1419   COMPARE(fcmp(s0, s1), "fcmp s0, s1");
1420   COMPARE(fcmp(s31, s30), "fcmp s31, s30");
1421   COMPARE(fcmp(d0, d1), "fcmp d0, d1");
1422   COMPARE(fcmp(d31, d30), "fcmp d31, d30");
1423   COMPARE(fcmp(s12, 0), "fcmp s12, #0.0");
1424   COMPARE(fcmp(d12, 0), "fcmp d12, #0.0");
1425 
1426   CLEANUP();
1427 }
1428 
1429 
TEST(fp_cond_compare)1430 TEST(fp_cond_compare) {
1431   SETUP();
1432 
1433   COMPARE(fccmp(s0, s1, NoFlag, eq), "fccmp s0, s1, #nzcv, eq");
1434   COMPARE(fccmp(s2, s3, ZVFlag, ne), "fccmp s2, s3, #nZcV, ne");
1435   COMPARE(fccmp(s30, s16, NCFlag, pl), "fccmp s30, s16, #NzCv, pl");
1436   COMPARE(fccmp(s31, s31, NZCVFlag, le), "fccmp s31, s31, #NZCV, le");
1437   COMPARE(fccmp(d4, d5, VFlag, gt), "fccmp d4, d5, #nzcV, gt");
1438   COMPARE(fccmp(d6, d7, NFlag, vs), "fccmp d6, d7, #Nzcv, vs");
1439   COMPARE(fccmp(d30, d0, NZFlag, vc), "fccmp d30, d0, #NZcv, vc");
1440   COMPARE(fccmp(d31, d31, ZFlag, hs), "fccmp d31, d31, #nZcv, hs");
1441   COMPARE(fccmp(s14, s15, CVFlag, al), "fccmp s14, s15, #nzCV, al");
1442   COMPARE(fccmp(d16, d17, CFlag, nv), "fccmp d16, d17, #nzCv, nv");
1443 
1444   CLEANUP();
1445 }
1446 
1447 
TEST(fp_select)1448 TEST(fp_select) {
1449   SETUP();
1450 
1451   COMPARE(fcsel(s0, s1, s2, eq), "fcsel s0, s1, s2, eq")
1452   COMPARE(fcsel(s31, s31, s30, ne), "fcsel s31, s31, s30, ne");
1453   COMPARE(fcsel(d0, d1, d2, mi), "fcsel d0, d1, d2, mi");
1454   COMPARE(fcsel(d31, d30, d31, pl), "fcsel d31, d30, d31, pl");
1455   COMPARE(fcsel(s14, s15, s16, al), "fcsel s14, s15, s16, al");
1456   COMPARE(fcsel(d17, d18, d19, nv), "fcsel d17, d18, d19, nv");
1457 
1458   CLEANUP();
1459 }
1460 
1461 
TEST(fcvt_scvtf_ucvtf)1462 TEST(fcvt_scvtf_ucvtf) {
1463   SETUP();
1464 
1465   COMPARE(fcvtas(w0, s1), "fcvtas w0, s1");
1466   COMPARE(fcvtas(x2, s3), "fcvtas x2, s3");
1467   COMPARE(fcvtas(w4, d5), "fcvtas w4, d5");
1468   COMPARE(fcvtas(x6, d7), "fcvtas x6, d7");
1469   COMPARE(fcvtau(w8, s9), "fcvtau w8, s9");
1470   COMPARE(fcvtau(x10, s11), "fcvtau x10, s11");
1471   COMPARE(fcvtau(w12, d13), "fcvtau w12, d13");
1472   COMPARE(fcvtau(x14, d15), "fcvtau x14, d15");
1473   COMPARE(fcvtns(w0, s1), "fcvtns w0, s1");
1474   COMPARE(fcvtns(x2, s3), "fcvtns x2, s3");
1475   COMPARE(fcvtns(w4, d5), "fcvtns w4, d5");
1476   COMPARE(fcvtns(x6, d7), "fcvtns x6, d7");
1477   COMPARE(fcvtnu(w8, s9), "fcvtnu w8, s9");
1478   COMPARE(fcvtnu(x10, s11), "fcvtnu x10, s11");
1479   COMPARE(fcvtnu(w12, d13), "fcvtnu w12, d13");
1480   COMPARE(fcvtnu(x14, d15), "fcvtnu x14, d15");
1481   COMPARE(fcvtzu(x16, d17), "fcvtzu x16, d17");
1482   COMPARE(fcvtzu(w18, d19), "fcvtzu w18, d19");
1483   COMPARE(fcvtzs(x20, d21), "fcvtzs x20, d21");
1484   COMPARE(fcvtzs(w22, d23), "fcvtzs w22, d23");
1485   COMPARE(fcvtzu(x16, s17), "fcvtzu x16, s17");
1486   COMPARE(fcvtzu(w18, s19), "fcvtzu w18, s19");
1487   COMPARE(fcvtzs(x20, s21), "fcvtzs x20, s21");
1488   COMPARE(fcvtzs(w22, s23), "fcvtzs w22, s23");
1489   COMPARE(scvtf(d24, w25), "scvtf d24, w25");
1490   COMPARE(scvtf(s24, w25), "scvtf s24, w25");
1491   COMPARE(scvtf(d26, x0), "scvtf d26, x0");
1492   COMPARE(scvtf(s26, x0), "scvtf s26, x0");
1493   COMPARE(ucvtf(d28, w29), "ucvtf d28, w29");
1494   COMPARE(ucvtf(s28, w29), "ucvtf s28, w29");
1495   COMPARE(ucvtf(d0, x1), "ucvtf d0, x1");
1496   COMPARE(ucvtf(s0, x1), "ucvtf s0, x1");
1497   COMPARE(ucvtf(d0, x1, 0), "ucvtf d0, x1");
1498   COMPARE(ucvtf(s0, x1, 0), "ucvtf s0, x1");
1499   COMPARE(scvtf(d1, x2, 1), "scvtf d1, x2, #1");
1500   COMPARE(scvtf(s1, x2, 1), "scvtf s1, x2, #1");
1501   COMPARE(scvtf(d3, x4, 15), "scvtf d3, x4, #15");
1502   COMPARE(scvtf(s3, x4, 15), "scvtf s3, x4, #15");
1503   COMPARE(scvtf(d5, x6, 32), "scvtf d5, x6, #32");
1504   COMPARE(scvtf(s5, x6, 32), "scvtf s5, x6, #32");
1505   COMPARE(ucvtf(d7, x8, 2), "ucvtf d7, x8, #2");
1506   COMPARE(ucvtf(s7, x8, 2), "ucvtf s7, x8, #2");
1507   COMPARE(ucvtf(d9, x10, 16), "ucvtf d9, x10, #16");
1508   COMPARE(ucvtf(s9, x10, 16), "ucvtf s9, x10, #16");
1509   COMPARE(ucvtf(d11, x12, 33), "ucvtf d11, x12, #33");
1510   COMPARE(ucvtf(s11, x12, 33), "ucvtf s11, x12, #33");
1511   COMPARE(fcvtms(w0, s1), "fcvtms w0, s1");
1512   COMPARE(fcvtms(x2, s3), "fcvtms x2, s3");
1513   COMPARE(fcvtms(w4, d5), "fcvtms w4, d5");
1514   COMPARE(fcvtms(x6, d7), "fcvtms x6, d7");
1515   COMPARE(fcvtmu(w8, s9), "fcvtmu w8, s9");
1516   COMPARE(fcvtmu(x10, s11), "fcvtmu x10, s11");
1517   COMPARE(fcvtmu(w12, d13), "fcvtmu w12, d13");
1518   COMPARE(fcvtmu(x14, d15), "fcvtmu x14, d15");
1519 
1520   CLEANUP();
1521 }
1522 
1523 
TEST(system_mrs)1524 TEST(system_mrs) {
1525   SETUP();
1526 
1527   COMPARE(mrs(x0, NZCV), "mrs x0, nzcv");
1528   COMPARE(mrs(x30, NZCV), "mrs x30, nzcv");
1529   COMPARE(mrs(x15, FPCR), "mrs x15, fpcr");
1530 
1531   CLEANUP();
1532 }
1533 
1534 
TEST(system_msr)1535 TEST(system_msr) {
1536   SETUP();
1537 
1538   COMPARE(msr(NZCV, x0), "msr nzcv, x0");
1539   COMPARE(msr(NZCV, x30), "msr nzcv, x30");
1540   COMPARE(msr(FPCR, x15), "msr fpcr, x15");
1541 
1542   CLEANUP();
1543 }
1544 
1545 
TEST(system_nop)1546 TEST(system_nop) {
1547   SETUP();
1548 
1549   COMPARE(nop(), "nop");
1550 
1551   CLEANUP();
1552 }
1553 
1554 
TEST(unreachable)1555 TEST(unreachable) {
1556   SETUP_CLASS(MacroAssembler);
1557 
1558 #ifdef USE_SIMULATOR
1559   VIXL_ASSERT(kUnreachableOpcode == 0xdeb0);
1560   COMPARE(Unreachable(), "hlt #0xdeb0");
1561 #else
1562   COMPARE(Unreachable(), "blr xzr");
1563 #endif
1564 
1565   CLEANUP();
1566 }
1567 
1568 
1569 #ifdef USE_SIMULATOR
TEST(trace)1570 TEST(trace) {
1571   SETUP_CLASS(MacroAssembler);
1572 
1573   VIXL_ASSERT(kTraceOpcode == 0xdeb2);
1574 
1575   // All Trace calls should produce the same instruction.
1576   COMPARE(Trace(LOG_ALL, TRACE_ENABLE), "hlt #0xdeb2");
1577   COMPARE(Trace(LOG_REGS, TRACE_DISABLE), "hlt #0xdeb2");
1578 
1579   CLEANUP();
1580 }
1581 #endif
1582 
1583 
1584 #ifdef USE_SIMULATOR
TEST(log)1585 TEST(log) {
1586   SETUP_CLASS(MacroAssembler);
1587 
1588   VIXL_ASSERT(kLogOpcode == 0xdeb3);
1589 
1590   // All Log calls should produce the same instruction.
1591   COMPARE(Log(LOG_ALL), "hlt #0xdeb3");
1592   COMPARE(Log(LOG_SYS_REGS), "hlt #0xdeb3");
1593 
1594   CLEANUP();
1595 }
1596 #endif
1597 
1598 
TEST(hlt)1599 TEST(hlt) {
1600   SETUP();
1601 
1602   COMPARE(hlt(0), "hlt #0x0");
1603   COMPARE(hlt(1), "hlt #0x1");
1604   COMPARE(hlt(65535), "hlt #0xffff");
1605 
1606   CLEANUP();
1607 }
1608 
1609 
TEST(brk)1610 TEST(brk) {
1611   SETUP();
1612 
1613   COMPARE(brk(0), "brk #0x0");
1614   COMPARE(brk(1), "brk #0x1");
1615   COMPARE(brk(65535), "brk #0xffff");
1616 
1617   CLEANUP();
1618 }
1619 
1620 
TEST(add_sub_negative)1621 TEST(add_sub_negative) {
1622   SETUP_CLASS(MacroAssembler);
1623 
1624   COMPARE(Add(x10, x0, -42), "sub x10, x0, #0x2a (42)");
1625   COMPARE(Add(x11, x1, -687), "sub x11, x1, #0x2af (687)");
1626   COMPARE(Add(x12, x2, -0x88), "sub x12, x2, #0x88 (136)");
1627 
1628   COMPARE(Sub(x13, x0, -600), "add x13, x0, #0x258 (600)");
1629   COMPARE(Sub(x14, x1, -313), "add x14, x1, #0x139 (313)");
1630   COMPARE(Sub(x15, x2, -0x555), "add x15, x2, #0x555 (1365)");
1631 
1632   COMPARE(Add(w19, w3, -0x344), "sub w19, w3, #0x344 (836)");
1633   COMPARE(Add(w20, w4, -2000), "sub w20, w4, #0x7d0 (2000)");
1634 
1635   COMPARE(Sub(w21, w3, -0xbc), "add w21, w3, #0xbc (188)");
1636   COMPARE(Sub(w22, w4, -2000), "add w22, w4, #0x7d0 (2000)");
1637 
1638   COMPARE(Cmp(w0, -1), "cmn w0, #0x1 (1)");
1639   COMPARE(Cmp(x1, -1), "cmn x1, #0x1 (1)");
1640   COMPARE(Cmp(w2, -4095), "cmn w2, #0xfff (4095)");
1641   COMPARE(Cmp(x3, -4095), "cmn x3, #0xfff (4095)");
1642 
1643   COMPARE(Cmn(w0, -1), "cmp w0, #0x1 (1)");
1644   COMPARE(Cmn(x1, -1), "cmp x1, #0x1 (1)");
1645   COMPARE(Cmn(w2, -4095), "cmp w2, #0xfff (4095)");
1646   COMPARE(Cmn(x3, -4095), "cmp x3, #0xfff (4095)");
1647 
1648   CLEANUP();
1649 }
1650 
1651 
TEST(logical_immediate_move)1652 TEST(logical_immediate_move) {
1653   SETUP_CLASS(MacroAssembler);
1654 
1655   COMPARE(And(w0, w1, 0), "movz w0, #0x0");
1656   COMPARE(And(x0, x1, 0), "movz x0, #0x0");
1657   COMPARE(Orr(w2, w3, 0), "mov w2, w3");
1658   COMPARE(Orr(x2, x3, 0), "mov x2, x3");
1659   COMPARE(Eor(w4, w5, 0), "mov w4, w5");
1660   COMPARE(Eor(x4, x5, 0), "mov x4, x5");
1661   COMPARE(Bic(w6, w7, 0), "mov w6, w7");
1662   COMPARE(Bic(x6, x7, 0), "mov x6, x7");
1663   COMPARE(Orn(w8, w9, 0), "movn w8, #0x0");
1664   COMPARE(Orn(x8, x9, 0), "movn x8, #0x0");
1665   COMPARE(Eon(w10, w11, 0), "mvn w10, w11");
1666   COMPARE(Eon(x10, x11, 0), "mvn x10, x11");
1667 
1668   COMPARE(And(w12, w13, 0xffffffff), "mov w12, w13");
1669   COMPARE(And(x12, x13, 0xffffffff), "and x12, x13, #0xffffffff");
1670   COMPARE(And(x12, x13, 0xffffffffffffffff), "mov x12, x13");
1671   COMPARE(Orr(w14, w15, 0xffffffff), "movn w14, #0x0");
1672   COMPARE(Orr(x14, x15, 0xffffffff), "orr x14, x15, #0xffffffff");
1673   COMPARE(Orr(x14, x15, 0xffffffffffffffff), "movn x14, #0x0");
1674   COMPARE(Eor(w16, w17, 0xffffffff), "mvn w16, w17");
1675   COMPARE(Eor(x16, x17, 0xffffffff), "eor x16, x17, #0xffffffff");
1676   COMPARE(Eor(x16, x17, 0xffffffffffffffff), "mvn x16, x17");
1677   COMPARE(Bic(w18, w19, 0xffffffff), "movz w18, #0x0");
1678   COMPARE(Bic(x18, x19, 0xffffffff), "and x18, x19, #0xffffffff00000000");
1679   COMPARE(Bic(x18, x19, 0xffffffffffffffff), "movz x18, #0x0");
1680   COMPARE(Orn(w20, w21, 0xffffffff), "mov w20, w21");
1681   COMPARE(Orn(x20, x21, 0xffffffff), "orr x20, x21, #0xffffffff00000000");
1682   COMPARE(Orn(x20, x21, 0xffffffffffffffff), "mov x20, x21");
1683   COMPARE(Eon(w22, w23, 0xffffffff), "mov w22, w23");
1684   COMPARE(Eon(x22, x23, 0xffffffff), "eor x22, x23, #0xffffffff00000000");
1685   COMPARE(Eon(x22, x23, 0xffffffffffffffff), "mov x22, x23");
1686 
1687   CLEANUP();
1688 }
1689 
TEST(barriers)1690 TEST(barriers) {
1691   SETUP_CLASS(MacroAssembler);
1692 
1693   // DMB
1694   COMPARE(Dmb(FullSystem, BarrierAll), "dmb sy");
1695   COMPARE(Dmb(FullSystem, BarrierReads), "dmb ld");
1696   COMPARE(Dmb(FullSystem, BarrierWrites), "dmb st");
1697 
1698   COMPARE(Dmb(InnerShareable, BarrierAll), "dmb ish");
1699   COMPARE(Dmb(InnerShareable, BarrierReads), "dmb ishld");
1700   COMPARE(Dmb(InnerShareable, BarrierWrites), "dmb ishst");
1701 
1702   COMPARE(Dmb(NonShareable, BarrierAll), "dmb nsh");
1703   COMPARE(Dmb(NonShareable, BarrierReads), "dmb nshld");
1704   COMPARE(Dmb(NonShareable, BarrierWrites), "dmb nshst");
1705 
1706   COMPARE(Dmb(OuterShareable, BarrierAll), "dmb osh");
1707   COMPARE(Dmb(OuterShareable, BarrierReads), "dmb oshld");
1708   COMPARE(Dmb(OuterShareable, BarrierWrites), "dmb oshst");
1709 
1710   COMPARE(Dmb(FullSystem, BarrierOther), "dmb sy (0b1100)");
1711   COMPARE(Dmb(InnerShareable, BarrierOther), "dmb sy (0b1000)");
1712   COMPARE(Dmb(NonShareable, BarrierOther), "dmb sy (0b0100)");
1713   COMPARE(Dmb(OuterShareable, BarrierOther), "dmb sy (0b0000)");
1714 
1715   // DSB
1716   COMPARE(Dsb(FullSystem, BarrierAll), "dsb sy");
1717   COMPARE(Dsb(FullSystem, BarrierReads), "dsb ld");
1718   COMPARE(Dsb(FullSystem, BarrierWrites), "dsb st");
1719 
1720   COMPARE(Dsb(InnerShareable, BarrierAll), "dsb ish");
1721   COMPARE(Dsb(InnerShareable, BarrierReads), "dsb ishld");
1722   COMPARE(Dsb(InnerShareable, BarrierWrites), "dsb ishst");
1723 
1724   COMPARE(Dsb(NonShareable, BarrierAll), "dsb nsh");
1725   COMPARE(Dsb(NonShareable, BarrierReads), "dsb nshld");
1726   COMPARE(Dsb(NonShareable, BarrierWrites), "dsb nshst");
1727 
1728   COMPARE(Dsb(OuterShareable, BarrierAll), "dsb osh");
1729   COMPARE(Dsb(OuterShareable, BarrierReads), "dsb oshld");
1730   COMPARE(Dsb(OuterShareable, BarrierWrites), "dsb oshst");
1731 
1732   COMPARE(Dsb(FullSystem, BarrierOther), "dsb sy (0b1100)");
1733   COMPARE(Dsb(InnerShareable, BarrierOther), "dsb sy (0b1000)");
1734   COMPARE(Dsb(NonShareable, BarrierOther), "dsb sy (0b0100)");
1735   COMPARE(Dsb(OuterShareable, BarrierOther), "dsb sy (0b0000)");
1736 
1737   // ISB
1738   COMPARE(Isb(), "isb");
1739 
1740   CLEANUP();
1741 }
1742 }  // namespace vixl
1743