blob: 1528fbb56b9112e71361de065bd990a5f62f7fa4 [file] [log] [blame]
armvixlad96eda2013-06-14 11:42:37 +01001// 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>
armvixl330dc712014-11-25 10:38:32 +000029#include "test-runner.h"
armvixlad96eda2013-06-14 11:42:37 +010030
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) \
armvixlc68cb642014-09-25 18:49:30 +010039 byte* buf = new byte[INSTR_SIZE]; \
armvixlad96eda2013-06-14 11:42:37 +010040 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
armvixlc68cb642014-09-25 18:49:30 +010048#define SETUP_MACRO() SETUP_CLASS(MacroAssembler)
49
armvixlad96eda2013-06-14 11:42:37 +010050#define COMPARE(ASM, EXP) \
51 masm->Reset(); \
armvixlc68cb642014-09-25 18:49:30 +010052 { \
53 CodeBufferCheckScope blind(masm); \
54 masm->ASM; \
55 } \
armvixlad96eda2013-06-14 11:42:37 +010056 masm->FinalizeCode(); \
57 decoder->Decode(reinterpret_cast<Instruction*>(buf)); \
58 encoding = *reinterpret_cast<uint32_t*>(buf); \
59 if (strcmp(disasm->GetOutput(), EXP) != 0) { \
armvixl330dc712014-11-25 10:38:32 +000060 printf("\nEncoding: %08" PRIx32 "\nExpected: %s\nFound: %s\n", \
armvixlad96eda2013-06-14 11:42:37 +010061 encoding, EXP, disasm->GetOutput()); \
62 abort(); \
armvixl330dc712014-11-25 10:38:32 +000063 } \
64 if (Test::trace_sim()) { \
65 printf("%08" PRIx32 "\t%s\n", encoding, disasm->GetOutput()); \
armvixlad96eda2013-06-14 11:42:37 +010066 }
67
armvixl578645f2013-08-15 17:21:42 +010068#define COMPARE_PREFIX(ASM, EXP) \
69 masm->Reset(); \
armvixlc68cb642014-09-25 18:49:30 +010070 { \
71 CodeBufferCheckScope blind(masm); \
72 masm->ASM; \
73 } \
74 masm->FinalizeCode(); \
75 decoder->Decode(reinterpret_cast<Instruction*>(buf)); \
76 encoding = *reinterpret_cast<uint32_t*>(buf); \
77 if (strncmp(disasm->GetOutput(), EXP, strlen(EXP)) != 0) { \
armvixl330dc712014-11-25 10:38:32 +000078 printf("\nEncoding: %08" PRIx32 "\nExpected: %s\nFound: %s\n", \
armvixlc68cb642014-09-25 18:49:30 +010079 encoding, EXP, disasm->GetOutput()); \
80 abort(); \
armvixl330dc712014-11-25 10:38:32 +000081 } \
82 if (Test::trace_sim()) { \
83 printf("%08" PRIx32 "\t%s\n", encoding, disasm->GetOutput()); \
armvixlc68cb642014-09-25 18:49:30 +010084 }
85
86#define COMPARE_MACRO(ASM, EXP) \
87 masm->Reset(); \
armvixl578645f2013-08-15 17:21:42 +010088 masm->ASM; \
89 masm->FinalizeCode(); \
90 decoder->Decode(reinterpret_cast<Instruction*>(buf)); \
91 encoding = *reinterpret_cast<uint32_t*>(buf); \
92 if (strncmp(disasm->GetOutput(), EXP, strlen(EXP)) != 0) { \
armvixl330dc712014-11-25 10:38:32 +000093 printf("\nEncoding: %08" PRIx32 "\nExpected: %s\nFound: %s\n", \
armvixl578645f2013-08-15 17:21:42 +010094 encoding, EXP, disasm->GetOutput()); \
95 abort(); \
armvixl330dc712014-11-25 10:38:32 +000096 } \
97 if (Test::trace_sim()) { \
98 printf("%08" PRIx32 "\t%s\n", encoding, disasm->GetOutput()); \
armvixl578645f2013-08-15 17:21:42 +010099 }
100
armvixlad96eda2013-06-14 11:42:37 +0100101#define CLEANUP() \
102 delete disasm; \
103 delete decoder; \
armvixlc68cb642014-09-25 18:49:30 +0100104 delete masm; \
105 delete buf
armvixlad96eda2013-06-14 11:42:37 +0100106
107namespace vixl {
108
109TEST(bootstrap) {
110 SETUP();
111
112 // Instructions generated by C compiler, disassembled by objdump, and
113 // reformatted to suit our disassembly style.
114 COMPARE(dci(0xa9ba7bfd), "stp x29, x30, [sp, #-96]!");
115 COMPARE(dci(0x910003fd), "mov x29, sp");
116 COMPARE(dci(0x9100e3a0), "add x0, x29, #0x38 (56)");
117 COMPARE(dci(0xb900001f), "str wzr, [x0]");
armvixl330dc712014-11-25 10:38:32 +0000118 COMPARE(dci(0x528000e1), "mov w1, #0x7");
armvixlad96eda2013-06-14 11:42:37 +0100119 COMPARE(dci(0xb9001c01), "str w1, [x0, #28]");
120 COMPARE(dci(0x390043a0), "strb w0, [x29, #16]");
121 COMPARE(dci(0x790027a0), "strh w0, [x29, #18]");
122 COMPARE(dci(0xb9400400), "ldr w0, [x0, #4]");
123 COMPARE(dci(0x0b000021), "add w1, w1, w0");
124 COMPARE(dci(0x531b6800), "lsl w0, w0, #5");
125 COMPARE(dci(0x521e0400), "eor w0, w0, #0xc");
126 COMPARE(dci(0x72af0f00), "movk w0, #0x7878, lsl #16");
127 COMPARE(dci(0xd360fc00), "lsr x0, x0, #32");
128 COMPARE(dci(0x13037c01), "asr w1, w0, #3");
129 COMPARE(dci(0x4b000021), "sub w1, w1, w0");
130 COMPARE(dci(0x2a0103e0), "mov w0, w1");
131 COMPARE(dci(0x93407c00), "sxtw x0, w0");
132 COMPARE(dci(0x2a000020), "orr w0, w1, w0");
133 COMPARE(dci(0xa8c67bfd), "ldp x29, x30, [sp], #96");
134
135 CLEANUP();
136}
137
armvixl4a102ba2014-07-14 09:02:40 +0100138
armvixlad96eda2013-06-14 11:42:37 +0100139TEST(mov_mvn) {
140 SETUP_CLASS(MacroAssembler);
141
armvixl330dc712014-11-25 10:38:32 +0000142 COMPARE(Mov(w0, Operand(0x1234)), "mov w0, #0x1234");
143 COMPARE(Mov(x1, Operand(0x1234)), "mov x1, #0x1234");
armvixlad96eda2013-06-14 11:42:37 +0100144 COMPARE(Mov(w2, Operand(w3)), "mov w2, w3");
145 COMPARE(Mov(x4, Operand(x5)), "mov x4, x5");
146 COMPARE(Mov(w6, Operand(w7, LSL, 5)), "lsl w6, w7, #5");
147 COMPARE(Mov(x8, Operand(x9, ASR, 42)), "asr x8, x9, #42");
148 COMPARE(Mov(w10, Operand(w11, UXTB)), "uxtb w10, w11");
149 COMPARE(Mov(x12, Operand(x13, UXTB, 1)), "ubfiz x12, x13, #1, #8");
150 COMPARE(Mov(w14, Operand(w15, SXTH, 2)), "sbfiz w14, w15, #2, #16");
151 COMPARE(Mov(x16, Operand(x17, SXTW, 3)), "sbfiz x16, x17, #3, #32");
152
armvixl330dc712014-11-25 10:38:32 +0000153 COMPARE(Mvn(w0, Operand(0x101)), "mov w0, #0xfffffefe");
154 COMPARE(Mvn(x1, Operand(0xfff1)), "mov x1, #0xffffffffffff000e");
armvixlad96eda2013-06-14 11:42:37 +0100155 COMPARE(Mvn(w2, Operand(w3)), "mvn w2, w3");
156 COMPARE(Mvn(x4, Operand(x5)), "mvn x4, x5");
157 COMPARE(Mvn(w6, Operand(w7, LSL, 12)), "mvn w6, w7, lsl #12");
158 COMPARE(Mvn(x8, Operand(x9, ASR, 63)), "mvn x8, x9, asr #63");
159
160 CLEANUP();
161}
162
armvixl4a102ba2014-07-14 09:02:40 +0100163
armvixlad96eda2013-06-14 11:42:37 +0100164TEST(move_immediate) {
165 SETUP();
166
armvixl330dc712014-11-25 10:38:32 +0000167 COMPARE(movz(w0, 0x1234), "mov w0, #0x1234");
168 COMPARE(movz(x1, 0xabcd0000), "mov x1, #0xabcd0000");
169 COMPARE(movz(x2, 0x555500000000), "mov x2, #0x555500000000");
170 COMPARE(movz(x3, 0xaaaa000000000000), "mov x3, #0xaaaa000000000000");
171 COMPARE(movz(x4, 0xabcd, 16), "mov x4, #0xabcd0000");
172 COMPARE(movz(x5, 0x5555, 32), "mov x5, #0x555500000000");
173 COMPARE(movz(x6, 0xaaaa, 48), "mov x6, #0xaaaa000000000000");
armvixlad96eda2013-06-14 11:42:37 +0100174
175 COMPARE(movk(w7, 0x1234), "movk w7, #0x1234");
176 COMPARE(movk(x8, 0xabcd0000), "movk x8, #0xabcd, lsl #16");
177 COMPARE(movk(x9, 0x555500000000), "movk x9, #0x5555, lsl #32");
178 COMPARE(movk(x10, 0xaaaa000000000000), "movk x10, #0xaaaa, lsl #48");
179 COMPARE(movk(w11, 0xabcd, 16), "movk w11, #0xabcd, lsl #16");
180 COMPARE(movk(x12, 0x5555, 32), "movk x12, #0x5555, lsl #32");
181 COMPARE(movk(x13, 0xaaaa, 48), "movk x13, #0xaaaa, lsl #48");
182
armvixl330dc712014-11-25 10:38:32 +0000183 COMPARE(movn(w14, 0x1234), "mov w14, #0xffffedcb");
184 COMPARE(movn(x15, 0xabcd0000), "mov x15, #0xffffffff5432ffff");
185 COMPARE(movn(x16, 0x555500000000), "mov x16, #0xffffaaaaffffffff");
186 COMPARE(movn(x17, 0xaaaa000000000000), "mov x17, #0x5555ffffffffffff");
187 COMPARE(movn(w18, 0xabcd, 16), "mov w18, #0x5432ffff");
188 COMPARE(movn(x19, 0x5555, 32), "mov x19, #0xffffaaaaffffffff");
189 COMPARE(movn(x20, 0xaaaa, 48), "mov x20, #0x5555ffffffffffff");
armvixlad96eda2013-06-14 11:42:37 +0100190
191 COMPARE(movk(w21, 0), "movk w21, #0x0");
192 COMPARE(movk(x22, 0, 0), "movk x22, #0x0");
193 COMPARE(movk(w23, 0, 16), "movk w23, #0x0, lsl #16");
194 COMPARE(movk(x24, 0, 32), "movk x24, #0x0, lsl #32");
195 COMPARE(movk(x25, 0, 48), "movk x25, #0x0, lsl #48");
196
armvixl330dc712014-11-25 10:38:32 +0000197 COMPARE(movz(x26, 0, 48), "movz x26, #0x0");
198 COMPARE(movn(x27, 0, 48), "movn x27, #0x0");
199 COMPARE(movn(w28, 0xffff), "movn w28, #0xffff");
200
armvixlad96eda2013-06-14 11:42:37 +0100201 CLEANUP();
202}
203
armvixl4a102ba2014-07-14 09:02:40 +0100204
armvixlf37fdc02014-02-05 13:22:16 +0000205TEST(move_immediate_2) {
206 SETUP_CLASS(MacroAssembler);
207
208 // Move instructions expected for certain immediates. This is really a macro
209 // assembler test, to ensure it generates immediates efficiently.
armvixl330dc712014-11-25 10:38:32 +0000210 COMPARE(Mov(w0, 0), "mov w0, #0x0");
211 COMPARE(Mov(w0, 0x0000ffff), "mov w0, #0xffff");
212 COMPARE(Mov(w0, 0x00010000), "mov w0, #0x10000");
213 COMPARE(Mov(w0, 0xffff0000), "mov w0, #0xffff0000");
214 COMPARE(Mov(w0, 0x0001ffff), "mov w0, #0x1ffff");
215 COMPARE(Mov(w0, 0xffff8000), "mov w0, #0xffff8000");
216 COMPARE(Mov(w0, 0xfffffffe), "mov w0, #0xfffffffe");
217 COMPARE(Mov(w0, 0xffffffff), "mov w0, #0xffffffff");
armvixlf37fdc02014-02-05 13:22:16 +0000218 COMPARE(Mov(w0, 0x00ffff00), "mov w0, #0xffff00");
219 COMPARE(Mov(w0, 0xfffe7fff), "mov w0, #0xfffe7fff");
armvixl330dc712014-11-25 10:38:32 +0000220 COMPARE(Mov(w0, 0xfffeffff), "mov w0, #0xfffeffff");
221 COMPARE(Mov(w0, 0xffff7fff), "mov w0, #0xffff7fff");
armvixlf37fdc02014-02-05 13:22:16 +0000222
armvixl330dc712014-11-25 10:38:32 +0000223 COMPARE(Mov(x0, 0), "mov x0, #0x0");
224 COMPARE(Mov(x0, 0x0000ffff), "mov x0, #0xffff");
225 COMPARE(Mov(x0, 0x00010000), "mov x0, #0x10000");
226 COMPARE(Mov(x0, 0xffff0000), "mov x0, #0xffff0000");
armvixlf37fdc02014-02-05 13:22:16 +0000227 COMPARE(Mov(x0, 0x0001ffff), "mov x0, #0x1ffff");
228 COMPARE(Mov(x0, 0xffff8000), "mov x0, #0xffff8000");
229 COMPARE(Mov(x0, 0xfffffffe), "mov x0, #0xfffffffe");
230 COMPARE(Mov(x0, 0xffffffff), "mov x0, #0xffffffff");
231 COMPARE(Mov(x0, 0x00ffff00), "mov x0, #0xffff00");
armvixl330dc712014-11-25 10:38:32 +0000232 COMPARE(Mov(x0, 0xffff000000000000), "mov x0, #0xffff000000000000");
233 COMPARE(Mov(x0, 0x0000ffff00000000), "mov x0, #0xffff00000000");
234 COMPARE(Mov(x0, 0x00000000ffff0000), "mov x0, #0xffff0000");
235 COMPARE(Mov(x0, 0xffffffffffff0000), "mov x0, #0xffffffffffff0000");
236 COMPARE(Mov(x0, 0xffffffff0000ffff), "mov x0, #0xffffffff0000ffff");
237 COMPARE(Mov(x0, 0xffff0000ffffffff), "mov x0, #0xffff0000ffffffff");
238 COMPARE(Mov(x0, 0x0000ffffffffffff), "mov x0, #0xffffffffffff");
armvixlf37fdc02014-02-05 13:22:16 +0000239 COMPARE(Mov(x0, 0xfffe7fffffffffff), "mov x0, #0xfffe7fffffffffff");
armvixl330dc712014-11-25 10:38:32 +0000240 COMPARE(Mov(x0, 0xfffeffffffffffff), "mov x0, #0xfffeffffffffffff");
241 COMPARE(Mov(x0, 0xffff7fffffffffff), "mov x0, #0xffff7fffffffffff");
armvixlf37fdc02014-02-05 13:22:16 +0000242 COMPARE(Mov(x0, 0xfffffffe7fffffff), "mov x0, #0xfffffffe7fffffff");
armvixl330dc712014-11-25 10:38:32 +0000243 COMPARE(Mov(x0, 0xfffffffeffffffff), "mov x0, #0xfffffffeffffffff");
244 COMPARE(Mov(x0, 0xffffffff7fffffff), "mov x0, #0xffffffff7fffffff");
armvixlf37fdc02014-02-05 13:22:16 +0000245 COMPARE(Mov(x0, 0xfffffffffffe7fff), "mov x0, #0xfffffffffffe7fff");
armvixl330dc712014-11-25 10:38:32 +0000246 COMPARE(Mov(x0, 0xfffffffffffeffff), "mov x0, #0xfffffffffffeffff");
247 COMPARE(Mov(x0, 0xffffffffffff7fff), "mov x0, #0xffffffffffff7fff");
248 COMPARE(Mov(x0, 0xffffffffffffffff), "mov x0, #0xffffffffffffffff");
armvixlf37fdc02014-02-05 13:22:16 +0000249
250 COMPARE(Movk(w0, 0x1234, 0), "movk w0, #0x1234");
251 COMPARE(Movk(x1, 0x2345, 0), "movk x1, #0x2345");
252 COMPARE(Movk(w2, 0x3456, 16), "movk w2, #0x3456, lsl #16");
253 COMPARE(Movk(x3, 0x4567, 16), "movk x3, #0x4567, lsl #16");
254 COMPARE(Movk(x4, 0x5678, 32), "movk x4, #0x5678, lsl #32");
255 COMPARE(Movk(x5, 0x6789, 48), "movk x5, #0x6789, lsl #48");
256
257 CLEANUP();
258}
259
armvixl4a102ba2014-07-14 09:02:40 +0100260
armvixlad96eda2013-06-14 11:42:37 +0100261TEST(add_immediate) {
262 SETUP();
263
264 COMPARE(add(w0, w1, Operand(0xff)), "add w0, w1, #0xff (255)");
265 COMPARE(add(x2, x3, Operand(0x3ff)), "add x2, x3, #0x3ff (1023)");
266 COMPARE(add(w4, w5, Operand(0xfff)), "add w4, w5, #0xfff (4095)");
267 COMPARE(add(x6, x7, Operand(0x1000)), "add x6, x7, #0x1000 (4096)");
268 COMPARE(add(w8, w9, Operand(0xff000)), "add w8, w9, #0xff000 (1044480)");
269 COMPARE(add(x10, x11, Operand(0x3ff000)),
270 "add x10, x11, #0x3ff000 (4190208)");
271 COMPARE(add(w12, w13, Operand(0xfff000)),
272 "add w12, w13, #0xfff000 (16773120)");
armvixlf37fdc02014-02-05 13:22:16 +0000273 COMPARE(adds(w14, w15, Operand(0xff)), "adds w14, w15, #0xff (255)");
274 COMPARE(adds(x16, x17, Operand(0xaa000)), "adds x16, x17, #0xaa000 (696320)");
275
armvixlad96eda2013-06-14 11:42:37 +0100276 COMPARE(cmn(w18, Operand(0xff)), "cmn w18, #0xff (255)");
277 COMPARE(cmn(x19, Operand(0xff000)), "cmn x19, #0xff000 (1044480)");
278 COMPARE(add(w0, wsp, Operand(0)), "mov w0, wsp");
279 COMPARE(add(sp, x0, Operand(0)), "mov sp, x0");
280
281 COMPARE(add(w1, wsp, Operand(8)), "add w1, wsp, #0x8 (8)");
282 COMPARE(add(x2, sp, Operand(16)), "add x2, sp, #0x10 (16)");
283 COMPARE(add(wsp, wsp, Operand(42)), "add wsp, wsp, #0x2a (42)");
284 COMPARE(cmn(sp, Operand(24)), "cmn sp, #0x18 (24)");
armvixlf37fdc02014-02-05 13:22:16 +0000285 COMPARE(adds(wzr, wsp, Operand(9)), "cmn wsp, #0x9 (9)");
armvixlad96eda2013-06-14 11:42:37 +0100286
287 CLEANUP();
288}
289
armvixl4a102ba2014-07-14 09:02:40 +0100290
armvixlad96eda2013-06-14 11:42:37 +0100291TEST(sub_immediate) {
292 SETUP();
293
294 COMPARE(sub(w0, w1, Operand(0xff)), "sub w0, w1, #0xff (255)");
295 COMPARE(sub(x2, x3, Operand(0x3ff)), "sub x2, x3, #0x3ff (1023)");
296 COMPARE(sub(w4, w5, Operand(0xfff)), "sub w4, w5, #0xfff (4095)");
297 COMPARE(sub(x6, x7, Operand(0x1000)), "sub x6, x7, #0x1000 (4096)");
298 COMPARE(sub(w8, w9, Operand(0xff000)), "sub w8, w9, #0xff000 (1044480)");
299 COMPARE(sub(x10, x11, Operand(0x3ff000)),
300 "sub x10, x11, #0x3ff000 (4190208)");
301 COMPARE(sub(w12, w13, Operand(0xfff000)),
302 "sub w12, w13, #0xfff000 (16773120)");
armvixlf37fdc02014-02-05 13:22:16 +0000303 COMPARE(subs(w14, w15, Operand(0xff)), "subs w14, w15, #0xff (255)");
304 COMPARE(subs(x16, x17, Operand(0xaa000)), "subs x16, x17, #0xaa000 (696320)");
armvixlad96eda2013-06-14 11:42:37 +0100305 COMPARE(cmp(w18, Operand(0xff)), "cmp w18, #0xff (255)");
306 COMPARE(cmp(x19, Operand(0xff000)), "cmp x19, #0xff000 (1044480)");
307
308 COMPARE(sub(w1, wsp, Operand(8)), "sub w1, wsp, #0x8 (8)");
309 COMPARE(sub(x2, sp, Operand(16)), "sub x2, sp, #0x10 (16)");
310 COMPARE(sub(wsp, wsp, Operand(42)), "sub wsp, wsp, #0x2a (42)");
311 COMPARE(cmp(sp, Operand(24)), "cmp sp, #0x18 (24)");
armvixlf37fdc02014-02-05 13:22:16 +0000312 COMPARE(subs(wzr, wsp, Operand(9)), "cmp wsp, #0x9 (9)");
armvixlad96eda2013-06-14 11:42:37 +0100313
314 CLEANUP();
315}
316
317
318TEST(add_shifted) {
319 SETUP();
320
321 COMPARE(add(w0, w1, Operand(w2)), "add w0, w1, w2");
322 COMPARE(add(x3, x4, Operand(x5)), "add x3, x4, x5");
323 COMPARE(add(w6, w7, Operand(w8, LSL, 1)), "add w6, w7, w8, lsl #1");
324 COMPARE(add(x9, x10, Operand(x11, LSL, 2)), "add x9, x10, x11, lsl #2");
325 COMPARE(add(w12, w13, Operand(w14, LSR, 3)), "add w12, w13, w14, lsr #3");
326 COMPARE(add(x15, x16, Operand(x17, LSR, 4)), "add x15, x16, x17, lsr #4");
327 COMPARE(add(w18, w19, Operand(w20, ASR, 5)), "add w18, w19, w20, asr #5");
328 COMPARE(add(x21, x22, Operand(x23, ASR, 6)), "add x21, x22, x23, asr #6");
329 COMPARE(cmn(w24, Operand(w25)), "cmn w24, w25");
330 COMPARE(cmn(x26, Operand(x27, LSL, 63)), "cmn x26, x27, lsl #63");
331
332 COMPARE(add(x0, sp, Operand(x1)), "add x0, sp, x1");
333 COMPARE(add(w2, wsp, Operand(w3)), "add w2, wsp, w3");
334 COMPARE(add(x4, sp, Operand(x5, LSL, 1)), "add x4, sp, x5, lsl #1");
335 COMPARE(add(x4, xzr, Operand(x5, LSL, 1)), "add x4, xzr, x5, lsl #1");
336 COMPARE(add(w6, wsp, Operand(w7, LSL, 3)), "add w6, wsp, w7, lsl #3");
armvixlf37fdc02014-02-05 13:22:16 +0000337 COMPARE(adds(xzr, sp, Operand(x8, LSL, 4)), "cmn sp, x8, lsl #4");
338 COMPARE(adds(xzr, xzr, Operand(x8, LSL, 5)), "cmn xzr, x8, lsl #5");
armvixlad96eda2013-06-14 11:42:37 +0100339
340 CLEANUP();
341}
342
343
344TEST(sub_shifted) {
345 SETUP();
346
347 COMPARE(sub(w0, w1, Operand(w2)), "sub w0, w1, w2");
348 COMPARE(sub(x3, x4, Operand(x5)), "sub x3, x4, x5");
349 COMPARE(sub(w6, w7, Operand(w8, LSL, 1)), "sub w6, w7, w8, lsl #1");
350 COMPARE(sub(x9, x10, Operand(x11, LSL, 2)), "sub x9, x10, x11, lsl #2");
351 COMPARE(sub(w12, w13, Operand(w14, LSR, 3)), "sub w12, w13, w14, lsr #3");
352 COMPARE(sub(x15, x16, Operand(x17, LSR, 4)), "sub x15, x16, x17, lsr #4");
353 COMPARE(sub(w18, w19, Operand(w20, ASR, 5)), "sub w18, w19, w20, asr #5");
354 COMPARE(sub(x21, x22, Operand(x23, ASR, 6)), "sub x21, x22, x23, asr #6");
355 COMPARE(cmp(w24, Operand(w25)), "cmp w24, w25");
356 COMPARE(cmp(x26, Operand(x27, LSL, 63)), "cmp x26, x27, lsl #63");
357 COMPARE(neg(w28, Operand(w29)), "neg w28, w29");
358 COMPARE(neg(x30, Operand(x0, LSR, 62)), "neg x30, x0, lsr #62");
armvixlf37fdc02014-02-05 13:22:16 +0000359 COMPARE(negs(w1, Operand(w2)), "negs w1, w2");
360 COMPARE(negs(x3, Operand(x4, ASR, 61)), "negs x3, x4, asr #61");
armvixlad96eda2013-06-14 11:42:37 +0100361
362 COMPARE(sub(x0, sp, Operand(x1)), "sub x0, sp, x1");
363 COMPARE(sub(w2, wsp, Operand(w3)), "sub w2, wsp, w3");
364 COMPARE(sub(x4, sp, Operand(x5, LSL, 1)), "sub x4, sp, x5, lsl #1");
365 COMPARE(sub(x4, xzr, Operand(x5, LSL, 1)), "neg x4, x5, lsl #1");
366 COMPARE(sub(w6, wsp, Operand(w7, LSL, 3)), "sub w6, wsp, w7, lsl #3");
armvixlf37fdc02014-02-05 13:22:16 +0000367 COMPARE(subs(xzr, sp, Operand(x8, LSL, 4)), "cmp sp, x8, lsl #4");
368 COMPARE(subs(xzr, xzr, Operand(x8, LSL, 5)), "cmp xzr, x8, lsl #5");
armvixlad96eda2013-06-14 11:42:37 +0100369
370 CLEANUP();
371}
372
373
374TEST(add_extended) {
375 SETUP();
376
377 COMPARE(add(w0, w1, Operand(w2, UXTB)), "add w0, w1, w2, uxtb");
armvixlf37fdc02014-02-05 13:22:16 +0000378 COMPARE(adds(x3, x4, Operand(w5, UXTB, 1)), "adds x3, x4, w5, uxtb #1");
armvixlad96eda2013-06-14 11:42:37 +0100379 COMPARE(add(w6, w7, Operand(w8, UXTH, 2)), "add w6, w7, w8, uxth #2");
armvixlf37fdc02014-02-05 13:22:16 +0000380 COMPARE(adds(x9, x10, Operand(x11, UXTW, 3)), "adds x9, x10, w11, uxtw #3");
armvixlad96eda2013-06-14 11:42:37 +0100381 COMPARE(add(x12, x13, Operand(x14, UXTX, 4)), "add x12, x13, x14, uxtx #4");
armvixlf37fdc02014-02-05 13:22:16 +0000382 COMPARE(adds(w15, w16, Operand(w17, SXTB, 4)), "adds w15, w16, w17, sxtb #4");
armvixlad96eda2013-06-14 11:42:37 +0100383 COMPARE(add(x18, x19, Operand(x20, SXTB, 3)), "add x18, x19, w20, sxtb #3");
armvixlf37fdc02014-02-05 13:22:16 +0000384 COMPARE(adds(w21, w22, Operand(w23, SXTH, 2)), "adds w21, w22, w23, sxth #2");
armvixlad96eda2013-06-14 11:42:37 +0100385 COMPARE(add(x24, x25, Operand(x26, SXTW, 1)), "add x24, x25, w26, sxtw #1");
armvixlf37fdc02014-02-05 13:22:16 +0000386 COMPARE(adds(x27, x28, Operand(x29, SXTX)), "adds x27, x28, x29, sxtx");
armvixlad96eda2013-06-14 11:42:37 +0100387 COMPARE(cmn(w0, Operand(w1, UXTB, 2)), "cmn w0, w1, uxtb #2");
388 COMPARE(cmn(x2, Operand(x3, SXTH, 4)), "cmn x2, w3, sxth #4");
389
390 COMPARE(add(w0, wsp, Operand(w1, UXTB)), "add w0, wsp, w1, uxtb");
391 COMPARE(add(x2, sp, Operand(x3, UXTH, 1)), "add x2, sp, w3, uxth #1");
392 COMPARE(add(wsp, wsp, Operand(w4, UXTW, 2)), "add wsp, wsp, w4, lsl #2");
393 COMPARE(cmn(sp, Operand(xzr, UXTX, 3)), "cmn sp, xzr, lsl #3");
394 COMPARE(cmn(sp, Operand(xzr, LSL, 4)), "cmn sp, xzr, lsl #4");
395
396 CLEANUP();
397}
398
399
400TEST(sub_extended) {
401 SETUP();
402
403 COMPARE(sub(w0, w1, Operand(w2, UXTB)), "sub w0, w1, w2, uxtb");
armvixlf37fdc02014-02-05 13:22:16 +0000404 COMPARE(subs(x3, x4, Operand(w5, UXTB, 1)), "subs x3, x4, w5, uxtb #1");
armvixlad96eda2013-06-14 11:42:37 +0100405 COMPARE(sub(w6, w7, Operand(w8, UXTH, 2)), "sub w6, w7, w8, uxth #2");
armvixlf37fdc02014-02-05 13:22:16 +0000406 COMPARE(subs(x9, x10, Operand(x11, UXTW, 3)), "subs x9, x10, w11, uxtw #3");
armvixlad96eda2013-06-14 11:42:37 +0100407 COMPARE(sub(x12, x13, Operand(x14, UXTX, 4)), "sub x12, x13, x14, uxtx #4");
armvixlf37fdc02014-02-05 13:22:16 +0000408 COMPARE(subs(w15, w16, Operand(w17, SXTB, 4)), "subs w15, w16, w17, sxtb #4");
armvixlad96eda2013-06-14 11:42:37 +0100409 COMPARE(sub(x18, x19, Operand(x20, SXTB, 3)), "sub x18, x19, w20, sxtb #3");
armvixlf37fdc02014-02-05 13:22:16 +0000410 COMPARE(subs(w21, w22, Operand(w23, SXTH, 2)), "subs w21, w22, w23, sxth #2");
armvixlad96eda2013-06-14 11:42:37 +0100411 COMPARE(sub(x24, x25, Operand(x26, SXTW, 1)), "sub x24, x25, w26, sxtw #1");
armvixlf37fdc02014-02-05 13:22:16 +0000412 COMPARE(subs(x27, x28, Operand(x29, SXTX)), "subs x27, x28, x29, sxtx");
armvixlad96eda2013-06-14 11:42:37 +0100413 COMPARE(cmp(w0, Operand(w1, SXTB, 1)), "cmp w0, w1, sxtb #1");
414 COMPARE(cmp(x2, Operand(x3, UXTH, 3)), "cmp x2, w3, uxth #3");
415
416 COMPARE(sub(w0, wsp, Operand(w1, UXTB)), "sub w0, wsp, w1, uxtb");
417 COMPARE(sub(x2, sp, Operand(x3, UXTH, 1)), "sub x2, sp, w3, uxth #1");
418 COMPARE(sub(wsp, wsp, Operand(w4, UXTW, 2)), "sub wsp, wsp, w4, lsl #2");
419 COMPARE(cmp(sp, Operand(xzr, UXTX, 3)), "cmp sp, xzr, lsl #3");
420 COMPARE(cmp(sp, Operand(xzr, LSL, 4)), "cmp sp, xzr, lsl #4");
421
422 CLEANUP();
423}
424
425
426TEST(adc_subc_ngc) {
427 SETUP();
428
429 COMPARE(adc(w0, w1, Operand(w2)), "adc w0, w1, w2");
430 COMPARE(adc(x3, x4, Operand(x5)), "adc x3, x4, x5");
armvixlf37fdc02014-02-05 13:22:16 +0000431 COMPARE(adcs(w6, w7, Operand(w8)), "adcs w6, w7, w8");
432 COMPARE(adcs(x9, x10, Operand(x11)), "adcs x9, x10, x11");
armvixlad96eda2013-06-14 11:42:37 +0100433 COMPARE(sbc(w12, w13, Operand(w14)), "sbc w12, w13, w14");
434 COMPARE(sbc(x15, x16, Operand(x17)), "sbc x15, x16, x17");
armvixlf37fdc02014-02-05 13:22:16 +0000435 COMPARE(sbcs(w18, w19, Operand(w20)), "sbcs w18, w19, w20");
436 COMPARE(sbcs(x21, x22, Operand(x23)), "sbcs x21, x22, x23");
armvixlad96eda2013-06-14 11:42:37 +0100437 COMPARE(ngc(w24, Operand(w25)), "ngc w24, w25");
438 COMPARE(ngc(x26, Operand(x27)), "ngc x26, x27");
armvixlf37fdc02014-02-05 13:22:16 +0000439 COMPARE(ngcs(w28, Operand(w29)), "ngcs w28, w29");
440 COMPARE(ngcs(x30, Operand(x0)), "ngcs x30, x0");
armvixlad96eda2013-06-14 11:42:37 +0100441
442 CLEANUP();
443}
444
445
446TEST(mul_and_div) {
447 SETUP();
448
449 COMPARE(mul(w0, w1, w2), "mul w0, w1, w2");
450 COMPARE(mul(x3, x4, x5), "mul x3, x4, x5");
451 COMPARE(mul(w30, w0, w1), "mul w30, w0, w1");
452 COMPARE(mul(x30, x0, x1), "mul x30, x0, x1");
453 COMPARE(mneg(w0, w1, w2), "mneg w0, w1, w2");
454 COMPARE(mneg(x3, x4, x5), "mneg x3, x4, x5");
455 COMPARE(mneg(w30, w0, w1), "mneg w30, w0, w1");
456 COMPARE(mneg(x30, x0, x1), "mneg x30, x0, x1");
457 COMPARE(smull(x0, w0, w1), "smull x0, w0, w1");
458 COMPARE(smull(x30, w30, w0), "smull x30, w30, w0");
459 COMPARE(smulh(x0, x1, x2), "smulh x0, x1, x2");
460
461 COMPARE(sdiv(w0, w1, w2), "sdiv w0, w1, w2");
462 COMPARE(sdiv(x3, x4, x5), "sdiv x3, x4, x5");
463 COMPARE(udiv(w6, w7, w8), "udiv w6, w7, w8");
464 COMPARE(udiv(x9, x10, x11), "udiv x9, x10, x11");
465
466 CLEANUP();
467}
468
469
470TEST(madd) {
471 SETUP();
472
473 COMPARE(madd(w0, w1, w2, w3), "madd w0, w1, w2, w3");
474 COMPARE(madd(w30, w21, w22, w16), "madd w30, w21, w22, w16");
475 COMPARE(madd(x0, x1, x2, x3), "madd x0, x1, x2, x3");
476 COMPARE(madd(x30, x21, x22, x16), "madd x30, x21, x22, x16");
477
478 COMPARE(smaddl(x0, w1, w2, x3), "smaddl x0, w1, w2, x3");
479 COMPARE(smaddl(x30, w21, w22, x16), "smaddl x30, w21, w22, x16");
480 COMPARE(umaddl(x0, w1, w2, x3), "umaddl x0, w1, w2, x3");
481 COMPARE(umaddl(x30, w21, w22, x16), "umaddl x30, w21, w22, x16");
482
483 CLEANUP();
484}
485
486
487TEST(msub) {
488 SETUP();
489
490 COMPARE(msub(w0, w1, w2, w3), "msub w0, w1, w2, w3");
491 COMPARE(msub(w30, w21, w22, w16), "msub w30, w21, w22, w16");
492 COMPARE(msub(x0, x1, x2, x3), "msub x0, x1, x2, x3");
493 COMPARE(msub(x30, x21, x22, x16), "msub x30, x21, x22, x16");
494
495 COMPARE(smsubl(x0, w1, w2, x3), "smsubl x0, w1, w2, x3");
496 COMPARE(smsubl(x30, w21, w22, x16), "smsubl x30, w21, w22, x16");
497 COMPARE(umsubl(x0, w1, w2, x3), "umsubl x0, w1, w2, x3");
498 COMPARE(umsubl(x30, w21, w22, x16), "umsubl x30, w21, w22, x16");
499
500 CLEANUP();
501}
502
503
504TEST(dp_1_source) {
505 SETUP();
506
507 COMPARE(rbit(w0, w1), "rbit w0, w1");
508 COMPARE(rbit(x2, x3), "rbit x2, x3");
509 COMPARE(rev16(w4, w5), "rev16 w4, w5");
510 COMPARE(rev16(x6, x7), "rev16 x6, x7");
511 COMPARE(rev32(x8, x9), "rev32 x8, x9");
512 COMPARE(rev(w10, w11), "rev w10, w11");
513 COMPARE(rev(x12, x13), "rev x12, x13");
514 COMPARE(clz(w14, w15), "clz w14, w15");
515 COMPARE(clz(x16, x17), "clz x16, x17");
516 COMPARE(cls(w18, w19), "cls w18, w19");
517 COMPARE(cls(x20, x21), "cls x20, x21");
518
519 CLEANUP();
520}
521
522
523TEST(bitfield) {
524 SETUP();
525
526 COMPARE(sxtb(w0, w1), "sxtb w0, w1");
527 COMPARE(sxtb(x2, x3), "sxtb x2, w3");
528 COMPARE(sxth(w4, w5), "sxth w4, w5");
529 COMPARE(sxth(x6, x7), "sxth x6, w7");
530 COMPARE(sxtw(x8, x9), "sxtw x8, w9");
armvixlf37fdc02014-02-05 13:22:16 +0000531 COMPARE(sxtb(x0, w1), "sxtb x0, w1");
532 COMPARE(sxth(x2, w3), "sxth x2, w3");
533 COMPARE(sxtw(x4, w5), "sxtw x4, w5");
534
armvixlad96eda2013-06-14 11:42:37 +0100535 COMPARE(uxtb(w10, w11), "uxtb w10, w11");
536 COMPARE(uxtb(x12, x13), "uxtb x12, w13");
537 COMPARE(uxth(w14, w15), "uxth w14, w15");
538 COMPARE(uxth(x16, x17), "uxth x16, w17");
539 COMPARE(uxtw(x18, x19), "ubfx x18, x19, #0, #32");
540
541 COMPARE(asr(w20, w21, 10), "asr w20, w21, #10");
542 COMPARE(asr(x22, x23, 20), "asr x22, x23, #20");
543 COMPARE(lsr(w24, w25, 10), "lsr w24, w25, #10");
544 COMPARE(lsr(x26, x27, 20), "lsr x26, x27, #20");
545 COMPARE(lsl(w28, w29, 10), "lsl w28, w29, #10");
546 COMPARE(lsl(x30, x0, 20), "lsl x30, x0, #20");
547
548 COMPARE(sbfiz(w1, w2, 1, 20), "sbfiz w1, w2, #1, #20");
549 COMPARE(sbfiz(x3, x4, 2, 19), "sbfiz x3, x4, #2, #19");
550 COMPARE(sbfx(w5, w6, 3, 18), "sbfx w5, w6, #3, #18");
551 COMPARE(sbfx(x7, x8, 4, 17), "sbfx x7, x8, #4, #17");
552 COMPARE(bfi(w9, w10, 5, 16), "bfi w9, w10, #5, #16");
553 COMPARE(bfi(x11, x12, 6, 15), "bfi x11, x12, #6, #15");
554 COMPARE(bfxil(w13, w14, 7, 14), "bfxil w13, w14, #7, #14");
555 COMPARE(bfxil(x15, x16, 8, 13), "bfxil x15, x16, #8, #13");
556 COMPARE(ubfiz(w17, w18, 9, 12), "ubfiz w17, w18, #9, #12");
557 COMPARE(ubfiz(x19, x20, 10, 11), "ubfiz x19, x20, #10, #11");
558 COMPARE(ubfx(w21, w22, 11, 10), "ubfx w21, w22, #11, #10");
559 COMPARE(ubfx(x23, x24, 12, 9), "ubfx x23, x24, #12, #9");
560
561 CLEANUP();
562}
563
564
565TEST(extract) {
566 SETUP();
567
568 COMPARE(extr(w0, w1, w2, 0), "extr w0, w1, w2, #0");
569 COMPARE(extr(x3, x4, x5, 1), "extr x3, x4, x5, #1");
570 COMPARE(extr(w6, w7, w8, 31), "extr w6, w7, w8, #31");
571 COMPARE(extr(x9, x10, x11, 63), "extr x9, x10, x11, #63");
572 COMPARE(extr(w12, w13, w13, 10), "ror w12, w13, #10");
573 COMPARE(extr(x14, x15, x15, 42), "ror x14, x15, #42");
574
575 CLEANUP();
576}
577
578
579TEST(logical_immediate) {
580 SETUP();
581 #define RESULT_SIZE (256)
582
583 char result[RESULT_SIZE];
584
585 // Test immediate encoding - 64-bit destination.
586 // 64-bit patterns.
587 uint64_t value = 0x7fffffff;
588 for (int i = 0; i < 64; i++) {
589 snprintf(result, RESULT_SIZE, "and x0, x0, #0x%" PRIx64, value);
590 COMPARE(and_(x0, x0, Operand(value)), result);
591 value = ((value & 1) << 63) | (value >> 1); // Rotate right 1 bit.
592 }
593
594 // 32-bit patterns.
armvixlb0c8ae22014-03-21 14:03:59 +0000595 value = 0x00003fff00003fff;
armvixlad96eda2013-06-14 11:42:37 +0100596 for (int i = 0; i < 32; i++) {
597 snprintf(result, RESULT_SIZE, "and x0, x0, #0x%" PRIx64, value);
598 COMPARE(and_(x0, x0, Operand(value)), result);
599 value = ((value & 1) << 63) | (value >> 1); // Rotate right 1 bit.
600 }
601
602 // 16-bit patterns.
armvixlb0c8ae22014-03-21 14:03:59 +0000603 value = 0x001f001f001f001f;
armvixlad96eda2013-06-14 11:42:37 +0100604 for (int i = 0; i < 16; i++) {
605 snprintf(result, RESULT_SIZE, "and x0, x0, #0x%" PRIx64, value);
606 COMPARE(and_(x0, x0, Operand(value)), result);
607 value = ((value & 1) << 63) | (value >> 1); // Rotate right 1 bit.
608 }
609
610 // 8-bit patterns.
armvixlb0c8ae22014-03-21 14:03:59 +0000611 value = 0x0e0e0e0e0e0e0e0e;
armvixlad96eda2013-06-14 11:42:37 +0100612 for (int i = 0; i < 8; i++) {
613 snprintf(result, RESULT_SIZE, "and x0, x0, #0x%" PRIx64, value);
614 COMPARE(and_(x0, x0, Operand(value)), result);
615 value = ((value & 1) << 63) | (value >> 1); // Rotate right 1 bit.
616 }
617
618 // 4-bit patterns.
armvixlb0c8ae22014-03-21 14:03:59 +0000619 value = 0x6666666666666666;
armvixlad96eda2013-06-14 11:42:37 +0100620 for (int i = 0; i < 4; i++) {
621 snprintf(result, RESULT_SIZE, "and x0, x0, #0x%" PRIx64, value);
622 COMPARE(and_(x0, x0, Operand(value)), result);
623 value = ((value & 1) << 63) | (value >> 1); // Rotate right 1 bit.
624 }
625
626 // 2-bit patterns.
armvixlb0c8ae22014-03-21 14:03:59 +0000627 COMPARE(and_(x0, x0, Operand(0x5555555555555555)),
armvixlad96eda2013-06-14 11:42:37 +0100628 "and x0, x0, #0x5555555555555555");
armvixlb0c8ae22014-03-21 14:03:59 +0000629 COMPARE(and_(x0, x0, Operand(0xaaaaaaaaaaaaaaaa)),
armvixlad96eda2013-06-14 11:42:37 +0100630 "and x0, x0, #0xaaaaaaaaaaaaaaaa");
631
632 // Test immediate encoding - 32-bit destination.
633 COMPARE(and_(w0, w0, Operand(0xff8007ff)),
634 "and w0, w0, #0xff8007ff"); // 32-bit pattern.
635 COMPARE(and_(w0, w0, Operand(0xf87ff87f)),
636 "and w0, w0, #0xf87ff87f"); // 16-bit pattern.
637 COMPARE(and_(w0, w0, Operand(0x87878787)),
638 "and w0, w0, #0x87878787"); // 8-bit pattern.
639 COMPARE(and_(w0, w0, Operand(0x66666666)),
640 "and w0, w0, #0x66666666"); // 4-bit pattern.
641 COMPARE(and_(w0, w0, Operand(0x55555555)),
642 "and w0, w0, #0x55555555"); // 2-bit pattern.
643
644 // Test other instructions.
645 COMPARE(tst(w1, Operand(0x11111111)),
646 "tst w1, #0x11111111");
armvixlb0c8ae22014-03-21 14:03:59 +0000647 COMPARE(tst(x2, Operand(0x8888888888888888)),
armvixlad96eda2013-06-14 11:42:37 +0100648 "tst x2, #0x8888888888888888");
649 COMPARE(orr(w7, w8, Operand(0xaaaaaaaa)),
650 "orr w7, w8, #0xaaaaaaaa");
armvixlb0c8ae22014-03-21 14:03:59 +0000651 COMPARE(orr(x9, x10, Operand(0x5555555555555555)),
armvixlad96eda2013-06-14 11:42:37 +0100652 "orr x9, x10, #0x5555555555555555");
653 COMPARE(eor(w15, w16, Operand(0x00000001)),
654 "eor w15, w16, #0x1");
armvixlb0c8ae22014-03-21 14:03:59 +0000655 COMPARE(eor(x17, x18, Operand(0x0000000000000003)),
armvixlad96eda2013-06-14 11:42:37 +0100656 "eor x17, x18, #0x3");
armvixlf37fdc02014-02-05 13:22:16 +0000657 COMPARE(ands(w23, w24, Operand(0x0000000f)), "ands w23, w24, #0xf");
armvixlb0c8ae22014-03-21 14:03:59 +0000658 COMPARE(ands(x25, x26, Operand(0x800000000000000f)),
armvixlad96eda2013-06-14 11:42:37 +0100659 "ands x25, x26, #0x800000000000000f");
660
661 // Test inverse.
662 COMPARE(bic(w3, w4, Operand(0x20202020)),
663 "and w3, w4, #0xdfdfdfdf");
armvixlb0c8ae22014-03-21 14:03:59 +0000664 COMPARE(bic(x5, x6, Operand(0x4040404040404040)),
armvixlad96eda2013-06-14 11:42:37 +0100665 "and x5, x6, #0xbfbfbfbfbfbfbfbf");
666 COMPARE(orn(w11, w12, Operand(0x40004000)),
667 "orr w11, w12, #0xbfffbfff");
armvixlb0c8ae22014-03-21 14:03:59 +0000668 COMPARE(orn(x13, x14, Operand(0x8181818181818181)),
armvixlad96eda2013-06-14 11:42:37 +0100669 "orr x13, x14, #0x7e7e7e7e7e7e7e7e");
670 COMPARE(eon(w19, w20, Operand(0x80000001)),
671 "eor w19, w20, #0x7ffffffe");
armvixlb0c8ae22014-03-21 14:03:59 +0000672 COMPARE(eon(x21, x22, Operand(0xc000000000000003)),
armvixlad96eda2013-06-14 11:42:37 +0100673 "eor x21, x22, #0x3ffffffffffffffc");
armvixlf37fdc02014-02-05 13:22:16 +0000674 COMPARE(bics(w27, w28, Operand(0xfffffff7)), "ands w27, w28, #0x8");
armvixlb0c8ae22014-03-21 14:03:59 +0000675 COMPARE(bics(x29, x0, Operand(0xfffffffeffffffff)),
armvixlad96eda2013-06-14 11:42:37 +0100676 "ands x29, x0, #0x100000000");
677
678 // Test stack pointer.
679 COMPARE(and_(wsp, wzr, Operand(7)), "and wsp, wzr, #0x7");
armvixlf37fdc02014-02-05 13:22:16 +0000680 COMPARE(ands(xzr, xzr, Operand(7)), "tst xzr, #0x7");
armvixlad96eda2013-06-14 11:42:37 +0100681 COMPARE(orr(sp, xzr, Operand(15)), "orr sp, xzr, #0xf");
682 COMPARE(eor(wsp, w0, Operand(31)), "eor wsp, w0, #0x1f");
683
684 // Test move aliases.
685 COMPARE(orr(w0, wzr, Operand(0x00000780)), "orr w0, wzr, #0x780");
686 COMPARE(orr(w1, wzr, Operand(0x00007800)), "orr w1, wzr, #0x7800");
687 COMPARE(orr(w2, wzr, Operand(0x00078000)), "mov w2, #0x78000");
688 COMPARE(orr(w3, wzr, Operand(0x00780000)), "orr w3, wzr, #0x780000");
689 COMPARE(orr(w4, wzr, Operand(0x07800000)), "orr w4, wzr, #0x7800000");
armvixlb0c8ae22014-03-21 14:03:59 +0000690 COMPARE(orr(x5, xzr, Operand(0xffffffffffffc001)),
armvixlad96eda2013-06-14 11:42:37 +0100691 "orr x5, xzr, #0xffffffffffffc001");
armvixlb0c8ae22014-03-21 14:03:59 +0000692 COMPARE(orr(x6, xzr, Operand(0xfffffffffffc001f)),
armvixlad96eda2013-06-14 11:42:37 +0100693 "mov x6, #0xfffffffffffc001f");
armvixlb0c8ae22014-03-21 14:03:59 +0000694 COMPARE(orr(x7, xzr, Operand(0xffffffffffc001ff)),
armvixlad96eda2013-06-14 11:42:37 +0100695 "mov x7, #0xffffffffffc001ff");
armvixlb0c8ae22014-03-21 14:03:59 +0000696 COMPARE(orr(x8, xzr, Operand(0xfffffffffc001fff)),
armvixlad96eda2013-06-14 11:42:37 +0100697 "mov x8, #0xfffffffffc001fff");
armvixlb0c8ae22014-03-21 14:03:59 +0000698 COMPARE(orr(x9, xzr, Operand(0xffffffffc001ffff)),
armvixlad96eda2013-06-14 11:42:37 +0100699 "orr x9, xzr, #0xffffffffc001ffff");
700
701 CLEANUP();
702}
703
704
705TEST(logical_shifted) {
706 SETUP();
707
708 COMPARE(and_(w0, w1, Operand(w2)), "and w0, w1, w2");
709 COMPARE(and_(x3, x4, Operand(x5, LSL, 1)), "and x3, x4, x5, lsl #1");
710 COMPARE(and_(w6, w7, Operand(w8, LSR, 2)), "and w6, w7, w8, lsr #2");
711 COMPARE(and_(x9, x10, Operand(x11, ASR, 3)), "and x9, x10, x11, asr #3");
712 COMPARE(and_(w12, w13, Operand(w14, ROR, 4)), "and w12, w13, w14, ror #4");
713
714 COMPARE(bic(w15, w16, Operand(w17)), "bic w15, w16, w17");
715 COMPARE(bic(x18, x19, Operand(x20, LSL, 5)), "bic x18, x19, x20, lsl #5");
716 COMPARE(bic(w21, w22, Operand(w23, LSR, 6)), "bic w21, w22, w23, lsr #6");
717 COMPARE(bic(x24, x25, Operand(x26, ASR, 7)), "bic x24, x25, x26, asr #7");
718 COMPARE(bic(w27, w28, Operand(w29, ROR, 8)), "bic w27, w28, w29, ror #8");
719
720 COMPARE(orr(w0, w1, Operand(w2)), "orr w0, w1, w2");
721 COMPARE(orr(x3, x4, Operand(x5, LSL, 9)), "orr x3, x4, x5, lsl #9");
722 COMPARE(orr(w6, w7, Operand(w8, LSR, 10)), "orr w6, w7, w8, lsr #10");
723 COMPARE(orr(x9, x10, Operand(x11, ASR, 11)), "orr x9, x10, x11, asr #11");
724 COMPARE(orr(w12, w13, Operand(w14, ROR, 12)), "orr w12, w13, w14, ror #12");
725
726 COMPARE(orn(w15, w16, Operand(w17)), "orn w15, w16, w17");
727 COMPARE(orn(x18, x19, Operand(x20, LSL, 13)), "orn x18, x19, x20, lsl #13");
728 COMPARE(orn(w21, w22, Operand(w23, LSR, 14)), "orn w21, w22, w23, lsr #14");
729 COMPARE(orn(x24, x25, Operand(x26, ASR, 15)), "orn x24, x25, x26, asr #15");
730 COMPARE(orn(w27, w28, Operand(w29, ROR, 16)), "orn w27, w28, w29, ror #16");
731
732 COMPARE(eor(w0, w1, Operand(w2)), "eor w0, w1, w2");
733 COMPARE(eor(x3, x4, Operand(x5, LSL, 17)), "eor x3, x4, x5, lsl #17");
734 COMPARE(eor(w6, w7, Operand(w8, LSR, 18)), "eor w6, w7, w8, lsr #18");
735 COMPARE(eor(x9, x10, Operand(x11, ASR, 19)), "eor x9, x10, x11, asr #19");
736 COMPARE(eor(w12, w13, Operand(w14, ROR, 20)), "eor w12, w13, w14, ror #20");
737
738 COMPARE(eon(w15, w16, Operand(w17)), "eon w15, w16, w17");
739 COMPARE(eon(x18, x19, Operand(x20, LSL, 21)), "eon x18, x19, x20, lsl #21");
740 COMPARE(eon(w21, w22, Operand(w23, LSR, 22)), "eon w21, w22, w23, lsr #22");
741 COMPARE(eon(x24, x25, Operand(x26, ASR, 23)), "eon x24, x25, x26, asr #23");
742 COMPARE(eon(w27, w28, Operand(w29, ROR, 24)), "eon w27, w28, w29, ror #24");
743
armvixlf37fdc02014-02-05 13:22:16 +0000744 COMPARE(ands(w0, w1, Operand(w2)), "ands w0, w1, w2");
745 COMPARE(ands(x3, x4, Operand(x5, LSL, 1)), "ands x3, x4, x5, lsl #1");
746 COMPARE(ands(w6, w7, Operand(w8, LSR, 2)), "ands w6, w7, w8, lsr #2");
747 COMPARE(ands(x9, x10, Operand(x11, ASR, 3)), "ands x9, x10, x11, asr #3");
748 COMPARE(ands(w12, w13, Operand(w14, ROR, 4)), "ands w12, w13, w14, ror #4");
armvixlad96eda2013-06-14 11:42:37 +0100749
armvixlf37fdc02014-02-05 13:22:16 +0000750 COMPARE(bics(w15, w16, Operand(w17)), "bics w15, w16, w17");
751 COMPARE(bics(x18, x19, Operand(x20, LSL, 5)), "bics x18, x19, x20, lsl #5");
752 COMPARE(bics(w21, w22, Operand(w23, LSR, 6)), "bics w21, w22, w23, lsr #6");
753 COMPARE(bics(x24, x25, Operand(x26, ASR, 7)), "bics x24, x25, x26, asr #7");
754 COMPARE(bics(w27, w28, Operand(w29, ROR, 8)), "bics w27, w28, w29, ror #8");
armvixlad96eda2013-06-14 11:42:37 +0100755
756 COMPARE(tst(w0, Operand(w1)), "tst w0, w1");
757 COMPARE(tst(w2, Operand(w3, ROR, 10)), "tst w2, w3, ror #10");
758 COMPARE(tst(x0, Operand(x1)), "tst x0, x1");
759 COMPARE(tst(x2, Operand(x3, ROR, 42)), "tst x2, x3, ror #42");
760
761 COMPARE(orn(w0, wzr, Operand(w1)), "mvn w0, w1");
762 COMPARE(orn(w2, wzr, Operand(w3, ASR, 5)), "mvn w2, w3, asr #5");
763 COMPARE(orn(x0, xzr, Operand(x1)), "mvn x0, x1");
764 COMPARE(orn(x2, xzr, Operand(x3, ASR, 42)), "mvn x2, x3, asr #42");
765
766 COMPARE(orr(w0, wzr, Operand(w1)), "mov w0, w1");
767 COMPARE(orr(x0, xzr, Operand(x1)), "mov x0, x1");
768 COMPARE(orr(w16, wzr, Operand(w17, LSL, 1)), "orr w16, wzr, w17, lsl #1");
769 COMPARE(orr(x16, xzr, Operand(x17, ASR, 2)), "orr x16, xzr, x17, asr #2");
770
771 CLEANUP();
772}
773
774
775TEST(dp_2_source) {
776 SETUP();
777
778 COMPARE(lslv(w0, w1, w2), "lsl w0, w1, w2");
779 COMPARE(lslv(x3, x4, x5), "lsl x3, x4, x5");
780 COMPARE(lsrv(w6, w7, w8), "lsr w6, w7, w8");
781 COMPARE(lsrv(x9, x10, x11), "lsr x9, x10, x11");
782 COMPARE(asrv(w12, w13, w14), "asr w12, w13, w14");
783 COMPARE(asrv(x15, x16, x17), "asr x15, x16, x17");
784 COMPARE(rorv(w18, w19, w20), "ror w18, w19, w20");
785 COMPARE(rorv(x21, x22, x23), "ror x21, x22, x23");
786
787 CLEANUP();
788}
789
armvixl4a102ba2014-07-14 09:02:40 +0100790
armvixlad96eda2013-06-14 11:42:37 +0100791TEST(adr) {
792 SETUP();
793
armvixlb0c8ae22014-03-21 14:03:59 +0000794 COMPARE_PREFIX(adr(x0, 0), "adr x0, #+0x0");
795 COMPARE_PREFIX(adr(x1, 1), "adr x1, #+0x1");
796 COMPARE_PREFIX(adr(x2, -1), "adr x2, #-0x1");
797 COMPARE_PREFIX(adr(x3, 4), "adr x3, #+0x4");
798 COMPARE_PREFIX(adr(x4, -4), "adr x4, #-0x4");
799 COMPARE_PREFIX(adr(x5, 0x000fffff), "adr x5, #+0xfffff");
800 COMPARE_PREFIX(adr(x6, -0x00100000), "adr x6, #-0x100000");
801 COMPARE_PREFIX(adr(xzr, 0), "adr xzr, #+0x0");
armvixlad96eda2013-06-14 11:42:37 +0100802
803 CLEANUP();
804}
805
armvixl4a102ba2014-07-14 09:02:40 +0100806
807TEST(adrp) {
808 SETUP();
809
810 COMPARE_PREFIX(adrp(x0, 0), "adrp x0, #+0x0");
armvixl330dc712014-11-25 10:38:32 +0000811 COMPARE_PREFIX(adrp(x1, 1), "adrp x1, #+0x1000");
812 COMPARE_PREFIX(adrp(x2, -1), "adrp x2, #-0x1000");
813 COMPARE_PREFIX(adrp(x3, 4), "adrp x3, #+0x4000");
814 COMPARE_PREFIX(adrp(x4, -4), "adrp x4, #-0x4000");
815 COMPARE_PREFIX(adrp(x5, 0x000fffff), "adrp x5, #+0xfffff000");
816 COMPARE_PREFIX(adrp(x6, -0x00100000), "adrp x6, #-0x100000000");
armvixl4a102ba2014-07-14 09:02:40 +0100817 COMPARE_PREFIX(adrp(xzr, 0), "adrp xzr, #+0x0");
818
819 CLEANUP();
820}
821
822
armvixlad96eda2013-06-14 11:42:37 +0100823TEST(branch) {
824 SETUP();
825
826 #define INST_OFF(x) ((x) >> kInstructionSizeLog2)
armvixlb0c8ae22014-03-21 14:03:59 +0000827 COMPARE_PREFIX(b(INST_OFF(0x4)), "b #+0x4");
828 COMPARE_PREFIX(b(INST_OFF(-0x4)), "b #-0x4");
829 COMPARE_PREFIX(b(INST_OFF(0x7fffffc)), "b #+0x7fffffc");
830 COMPARE_PREFIX(b(INST_OFF(-0x8000000)), "b #-0x8000000");
831 COMPARE_PREFIX(b(INST_OFF(0xffffc), eq), "b.eq #+0xffffc");
832 COMPARE_PREFIX(b(INST_OFF(-0x100000), mi), "b.mi #-0x100000");
833 COMPARE_PREFIX(b(INST_OFF(0xffffc), al), "b.al #+0xffffc");
834 COMPARE_PREFIX(b(INST_OFF(-0x100000), nv), "b.nv #-0x100000");
835 COMPARE_PREFIX(bl(INST_OFF(0x4)), "bl #+0x4");
836 COMPARE_PREFIX(bl(INST_OFF(-0x4)), "bl #-0x4");
837 COMPARE_PREFIX(bl(INST_OFF(0xffffc)), "bl #+0xffffc");
838 COMPARE_PREFIX(bl(INST_OFF(-0x100000)), "bl #-0x100000");
839 COMPARE_PREFIX(cbz(w0, INST_OFF(0xffffc)), "cbz w0, #+0xffffc");
840 COMPARE_PREFIX(cbz(x1, INST_OFF(-0x100000)), "cbz x1, #-0x100000");
841 COMPARE_PREFIX(cbnz(w2, INST_OFF(0xffffc)), "cbnz w2, #+0xffffc");
842 COMPARE_PREFIX(cbnz(x3, INST_OFF(-0x100000)), "cbnz x3, #-0x100000");
843 COMPARE_PREFIX(tbz(w4, 0, INST_OFF(0x7ffc)), "tbz w4, #0, #+0x7ffc");
844 COMPARE_PREFIX(tbz(x5, 63, INST_OFF(-0x8000)), "tbz x5, #63, #-0x8000");
845 COMPARE_PREFIX(tbz(w6, 31, INST_OFF(0)), "tbz w6, #31, #+0x0");
846 COMPARE_PREFIX(tbz(x7, 31, INST_OFF(0x4)), "tbz w7, #31, #+0x4");
847 COMPARE_PREFIX(tbz(x8, 32, INST_OFF(0x8)), "tbz x8, #32, #+0x8");
848 COMPARE_PREFIX(tbnz(w8, 0, INST_OFF(0x7ffc)), "tbnz w8, #0, #+0x7ffc");
849 COMPARE_PREFIX(tbnz(x9, 63, INST_OFF(-0x8000)), "tbnz x9, #63, #-0x8000");
850 COMPARE_PREFIX(tbnz(w10, 31, INST_OFF(0)), "tbnz w10, #31, #+0x0");
851 COMPARE_PREFIX(tbnz(x11, 31, INST_OFF(0x4)), "tbnz w11, #31, #+0x4");
852 COMPARE_PREFIX(tbnz(x12, 32, INST_OFF(0x8)), "tbnz x12, #32, #+0x8");
armvixlad96eda2013-06-14 11:42:37 +0100853 COMPARE(br(x0), "br x0");
854 COMPARE(blr(x1), "blr x1");
855 COMPARE(ret(x2), "ret x2");
856 COMPARE(ret(lr), "ret")
857
858 CLEANUP();
859}
860
armvixl4a102ba2014-07-14 09:02:40 +0100861
armvixlad96eda2013-06-14 11:42:37 +0100862TEST(load_store) {
863 SETUP();
864
865 COMPARE(ldr(w0, MemOperand(x1)), "ldr w0, [x1]");
866 COMPARE(ldr(w2, MemOperand(x3, 4)), "ldr w2, [x3, #4]");
867 COMPARE(ldr(w4, MemOperand(x5, 16380)), "ldr w4, [x5, #16380]");
868 COMPARE(ldr(x6, MemOperand(x7)), "ldr x6, [x7]");
869 COMPARE(ldr(x8, MemOperand(x9, 8)), "ldr x8, [x9, #8]");
870 COMPARE(ldr(x10, MemOperand(x11, 32760)), "ldr x10, [x11, #32760]");
871 COMPARE(str(w12, MemOperand(x13)), "str w12, [x13]");
872 COMPARE(str(w14, MemOperand(x15, 4)), "str w14, [x15, #4]");
873 COMPARE(str(w16, MemOperand(x17, 16380)), "str w16, [x17, #16380]");
874 COMPARE(str(x18, MemOperand(x19)), "str x18, [x19]");
875 COMPARE(str(x20, MemOperand(x21, 8)), "str x20, [x21, #8]");
876 COMPARE(str(x22, MemOperand(x23, 32760)), "str x22, [x23, #32760]");
877
878 COMPARE(ldr(w0, MemOperand(x1, 4, PreIndex)), "ldr w0, [x1, #4]!");
879 COMPARE(ldr(w2, MemOperand(x3, 255, PreIndex)), "ldr w2, [x3, #255]!");
880 COMPARE(ldr(w4, MemOperand(x5, -256, PreIndex)), "ldr w4, [x5, #-256]!");
881 COMPARE(ldr(x6, MemOperand(x7, 8, PreIndex)), "ldr x6, [x7, #8]!");
882 COMPARE(ldr(x8, MemOperand(x9, 255, PreIndex)), "ldr x8, [x9, #255]!");
883 COMPARE(ldr(x10, MemOperand(x11, -256, PreIndex)), "ldr x10, [x11, #-256]!");
884 COMPARE(str(w12, MemOperand(x13, 4, PreIndex)), "str w12, [x13, #4]!");
885 COMPARE(str(w14, MemOperand(x15, 255, PreIndex)), "str w14, [x15, #255]!");
886 COMPARE(str(w16, MemOperand(x17, -256, PreIndex)), "str w16, [x17, #-256]!");
887 COMPARE(str(x18, MemOperand(x19, 8, PreIndex)), "str x18, [x19, #8]!");
888 COMPARE(str(x20, MemOperand(x21, 255, PreIndex)), "str x20, [x21, #255]!");
889 COMPARE(str(x22, MemOperand(x23, -256, PreIndex)), "str x22, [x23, #-256]!");
890
891 COMPARE(ldr(w0, MemOperand(x1, 4, PostIndex)), "ldr w0, [x1], #4");
892 COMPARE(ldr(w2, MemOperand(x3, 255, PostIndex)), "ldr w2, [x3], #255");
893 COMPARE(ldr(w4, MemOperand(x5, -256, PostIndex)), "ldr w4, [x5], #-256");
894 COMPARE(ldr(x6, MemOperand(x7, 8, PostIndex)), "ldr x6, [x7], #8");
895 COMPARE(ldr(x8, MemOperand(x9, 255, PostIndex)), "ldr x8, [x9], #255");
896 COMPARE(ldr(x10, MemOperand(x11, -256, PostIndex)), "ldr x10, [x11], #-256");
897 COMPARE(str(w12, MemOperand(x13, 4, PostIndex)), "str w12, [x13], #4");
898 COMPARE(str(w14, MemOperand(x15, 255, PostIndex)), "str w14, [x15], #255");
899 COMPARE(str(w16, MemOperand(x17, -256, PostIndex)), "str w16, [x17], #-256");
900 COMPARE(str(x18, MemOperand(x19, 8, PostIndex)), "str x18, [x19], #8");
901 COMPARE(str(x20, MemOperand(x21, 255, PostIndex)), "str x20, [x21], #255");
902 COMPARE(str(x22, MemOperand(x23, -256, PostIndex)), "str x22, [x23], #-256");
903
904 COMPARE(ldr(w24, MemOperand(sp)), "ldr w24, [sp]");
905 COMPARE(ldr(x25, MemOperand(sp, 8)), "ldr x25, [sp, #8]");
906 COMPARE(str(w26, MemOperand(sp, 4, PreIndex)), "str w26, [sp, #4]!");
907 COMPARE(str(x27, MemOperand(sp, -8, PostIndex)), "str x27, [sp], #-8");
908
909 COMPARE(ldrsw(x0, MemOperand(x1)), "ldrsw x0, [x1]");
910 COMPARE(ldrsw(x2, MemOperand(x3, 8)), "ldrsw x2, [x3, #8]");
911 COMPARE(ldrsw(x4, MemOperand(x5, 42, PreIndex)), "ldrsw x4, [x5, #42]!");
912 COMPARE(ldrsw(x6, MemOperand(x7, -11, PostIndex)), "ldrsw x6, [x7], #-11");
913
914 CLEANUP();
915}
916
917
918TEST(load_store_regoffset) {
919 SETUP();
920
921 COMPARE(ldr(w0, MemOperand(x1, w2, UXTW)), "ldr w0, [x1, w2, uxtw]");
922 COMPARE(ldr(w3, MemOperand(x4, w5, UXTW, 2)), "ldr w3, [x4, w5, uxtw #2]");
923 COMPARE(ldr(w6, MemOperand(x7, x8)), "ldr w6, [x7, x8]");
924 COMPARE(ldr(w9, MemOperand(x10, x11, LSL, 2)), "ldr w9, [x10, x11, lsl #2]");
925 COMPARE(ldr(w12, MemOperand(x13, w14, SXTW)), "ldr w12, [x13, w14, sxtw]");
926 COMPARE(ldr(w15, MemOperand(x16, w17, SXTW, 2)),
927 "ldr w15, [x16, w17, sxtw #2]");
928 COMPARE(ldr(w18, MemOperand(x19, x20, SXTX)), "ldr w18, [x19, x20, sxtx]");
929 COMPARE(ldr(w21, MemOperand(x22, x23, SXTX, 2)),
930 "ldr w21, [x22, x23, sxtx #2]");
931 COMPARE(ldr(x0, MemOperand(x1, w2, UXTW)), "ldr x0, [x1, w2, uxtw]");
932 COMPARE(ldr(x3, MemOperand(x4, w5, UXTW, 3)), "ldr x3, [x4, w5, uxtw #3]");
933 COMPARE(ldr(x6, MemOperand(x7, x8)), "ldr x6, [x7, x8]");
934 COMPARE(ldr(x9, MemOperand(x10, x11, LSL, 3)), "ldr x9, [x10, x11, lsl #3]");
935 COMPARE(ldr(x12, MemOperand(x13, w14, SXTW)), "ldr x12, [x13, w14, sxtw]");
936 COMPARE(ldr(x15, MemOperand(x16, w17, SXTW, 3)),
937 "ldr x15, [x16, w17, sxtw #3]");
938 COMPARE(ldr(x18, MemOperand(x19, x20, SXTX)), "ldr x18, [x19, x20, sxtx]");
939 COMPARE(ldr(x21, MemOperand(x22, x23, SXTX, 3)),
940 "ldr x21, [x22, x23, sxtx #3]");
941
942 COMPARE(str(w0, MemOperand(x1, w2, UXTW)), "str w0, [x1, w2, uxtw]");
943 COMPARE(str(w3, MemOperand(x4, w5, UXTW, 2)), "str w3, [x4, w5, uxtw #2]");
944 COMPARE(str(w6, MemOperand(x7, x8)), "str w6, [x7, x8]");
945 COMPARE(str(w9, MemOperand(x10, x11, LSL, 2)), "str w9, [x10, x11, lsl #2]");
946 COMPARE(str(w12, MemOperand(x13, w14, SXTW)), "str w12, [x13, w14, sxtw]");
947 COMPARE(str(w15, MemOperand(x16, w17, SXTW, 2)),
948 "str w15, [x16, w17, sxtw #2]");
949 COMPARE(str(w18, MemOperand(x19, x20, SXTX)), "str w18, [x19, x20, sxtx]");
950 COMPARE(str(w21, MemOperand(x22, x23, SXTX, 2)),
951 "str w21, [x22, x23, sxtx #2]");
952 COMPARE(str(x0, MemOperand(x1, w2, UXTW)), "str x0, [x1, w2, uxtw]");
953 COMPARE(str(x3, MemOperand(x4, w5, UXTW, 3)), "str x3, [x4, w5, uxtw #3]");
954 COMPARE(str(x6, MemOperand(x7, x8)), "str x6, [x7, x8]");
955 COMPARE(str(x9, MemOperand(x10, x11, LSL, 3)), "str x9, [x10, x11, lsl #3]");
956 COMPARE(str(x12, MemOperand(x13, w14, SXTW)), "str x12, [x13, w14, sxtw]");
957 COMPARE(str(x15, MemOperand(x16, w17, SXTW, 3)),
958 "str x15, [x16, w17, sxtw #3]");
959 COMPARE(str(x18, MemOperand(x19, x20, SXTX)), "str x18, [x19, x20, sxtx]");
960 COMPARE(str(x21, MemOperand(x22, x23, SXTX, 3)),
961 "str x21, [x22, x23, sxtx #3]");
962
963 COMPARE(ldrb(w0, MemOperand(x1, w2, UXTW)), "ldrb w0, [x1, w2, uxtw]");
964 COMPARE(ldrb(w6, MemOperand(x7, x8)), "ldrb w6, [x7, x8]");
965 COMPARE(ldrb(w12, MemOperand(x13, w14, SXTW)), "ldrb w12, [x13, w14, sxtw]");
966 COMPARE(ldrb(w18, MemOperand(x19, x20, SXTX)), "ldrb w18, [x19, x20, sxtx]");
967 COMPARE(strb(w0, MemOperand(x1, w2, UXTW)), "strb w0, [x1, w2, uxtw]");
968 COMPARE(strb(w6, MemOperand(x7, x8)), "strb w6, [x7, x8]");
969 COMPARE(strb(w12, MemOperand(x13, w14, SXTW)), "strb w12, [x13, w14, sxtw]");
970 COMPARE(strb(w18, MemOperand(x19, x20, SXTX)), "strb w18, [x19, x20, sxtx]");
971
972 COMPARE(ldrh(w0, MemOperand(x1, w2, UXTW)), "ldrh w0, [x1, w2, uxtw]");
973 COMPARE(ldrh(w3, MemOperand(x4, w5, UXTW, 1)), "ldrh w3, [x4, w5, uxtw #1]");
974 COMPARE(ldrh(w6, MemOperand(x7, x8)), "ldrh w6, [x7, x8]");
975 COMPARE(ldrh(w9, MemOperand(x10, x11, LSL, 1)),
976 "ldrh w9, [x10, x11, lsl #1]");
977 COMPARE(ldrh(w12, MemOperand(x13, w14, SXTW)), "ldrh w12, [x13, w14, sxtw]");
978 COMPARE(ldrh(w15, MemOperand(x16, w17, SXTW, 1)),
979 "ldrh w15, [x16, w17, sxtw #1]");
980 COMPARE(ldrh(w18, MemOperand(x19, x20, SXTX)), "ldrh w18, [x19, x20, sxtx]");
981 COMPARE(ldrh(w21, MemOperand(x22, x23, SXTX, 1)),
982 "ldrh w21, [x22, x23, sxtx #1]");
983 COMPARE(strh(w0, MemOperand(x1, w2, UXTW)), "strh w0, [x1, w2, uxtw]");
984 COMPARE(strh(w3, MemOperand(x4, w5, UXTW, 1)), "strh w3, [x4, w5, uxtw #1]");
985 COMPARE(strh(w6, MemOperand(x7, x8)), "strh w6, [x7, x8]");
986 COMPARE(strh(w9, MemOperand(x10, x11, LSL, 1)),
987 "strh w9, [x10, x11, lsl #1]");
988 COMPARE(strh(w12, MemOperand(x13, w14, SXTW)), "strh w12, [x13, w14, sxtw]");
989 COMPARE(strh(w15, MemOperand(x16, w17, SXTW, 1)),
990 "strh w15, [x16, w17, sxtw #1]");
991 COMPARE(strh(w18, MemOperand(x19, x20, SXTX)), "strh w18, [x19, x20, sxtx]");
992 COMPARE(strh(w21, MemOperand(x22, x23, SXTX, 1)),
993 "strh w21, [x22, x23, sxtx #1]");
994
995 COMPARE(ldr(x0, MemOperand(sp, wzr, SXTW)), "ldr x0, [sp, wzr, sxtw]");
996 COMPARE(str(x1, MemOperand(sp, xzr)), "str x1, [sp, xzr]");
997
998 CLEANUP();
999}
1000
1001
1002TEST(load_store_byte) {
1003 SETUP();
1004
1005 COMPARE(ldrb(w0, MemOperand(x1)), "ldrb w0, [x1]");
1006 COMPARE(ldrb(x2, MemOperand(x3)), "ldrb w2, [x3]");
1007 COMPARE(ldrb(w4, MemOperand(x5, 4095)), "ldrb w4, [x5, #4095]");
1008 COMPARE(ldrb(w6, MemOperand(x7, 255, PreIndex)), "ldrb w6, [x7, #255]!");
1009 COMPARE(ldrb(w8, MemOperand(x9, -256, PreIndex)), "ldrb w8, [x9, #-256]!");
1010 COMPARE(ldrb(w10, MemOperand(x11, 255, PostIndex)), "ldrb w10, [x11], #255");
1011 COMPARE(ldrb(w12, MemOperand(x13, -256, PostIndex)),
1012 "ldrb w12, [x13], #-256");
1013 COMPARE(strb(w14, MemOperand(x15)), "strb w14, [x15]");
1014 COMPARE(strb(x16, MemOperand(x17)), "strb w16, [x17]");
1015 COMPARE(strb(w18, MemOperand(x19, 4095)), "strb w18, [x19, #4095]");
1016 COMPARE(strb(w20, MemOperand(x21, 255, PreIndex)), "strb w20, [x21, #255]!");
1017 COMPARE(strb(w22, MemOperand(x23, -256, PreIndex)),
1018 "strb w22, [x23, #-256]!");
1019 COMPARE(strb(w24, MemOperand(x25, 255, PostIndex)), "strb w24, [x25], #255");
1020 COMPARE(strb(w26, MemOperand(x27, -256, PostIndex)),
1021 "strb w26, [x27], #-256");
1022 COMPARE(ldrb(w28, MemOperand(sp, 3, PostIndex)), "ldrb w28, [sp], #3");
1023 COMPARE(strb(x29, MemOperand(sp, -42, PreIndex)), "strb w29, [sp, #-42]!");
1024 COMPARE(ldrsb(w0, MemOperand(x1)), "ldrsb w0, [x1]");
1025 COMPARE(ldrsb(x2, MemOperand(x3, 8)), "ldrsb x2, [x3, #8]");
1026 COMPARE(ldrsb(w4, MemOperand(x5, 42, PreIndex)), "ldrsb w4, [x5, #42]!");
1027 COMPARE(ldrsb(x6, MemOperand(x7, -11, PostIndex)), "ldrsb x6, [x7], #-11");
1028
1029 CLEANUP();
1030}
1031
1032
1033TEST(load_store_half) {
1034 SETUP();
1035
1036 COMPARE(ldrh(w0, MemOperand(x1)), "ldrh w0, [x1]");
1037 COMPARE(ldrh(x2, MemOperand(x3)), "ldrh w2, [x3]");
1038 COMPARE(ldrh(w4, MemOperand(x5, 8190)), "ldrh w4, [x5, #8190]");
1039 COMPARE(ldrh(w6, MemOperand(x7, 255, PreIndex)), "ldrh w6, [x7, #255]!");
1040 COMPARE(ldrh(w8, MemOperand(x9, -256, PreIndex)), "ldrh w8, [x9, #-256]!");
1041 COMPARE(ldrh(w10, MemOperand(x11, 255, PostIndex)), "ldrh w10, [x11], #255");
1042 COMPARE(ldrh(w12, MemOperand(x13, -256, PostIndex)),
1043 "ldrh w12, [x13], #-256");
1044 COMPARE(strh(w14, MemOperand(x15)), "strh w14, [x15]");
1045 COMPARE(strh(x16, MemOperand(x17)), "strh w16, [x17]");
1046 COMPARE(strh(w18, MemOperand(x19, 8190)), "strh w18, [x19, #8190]");
1047 COMPARE(strh(w20, MemOperand(x21, 255, PreIndex)), "strh w20, [x21, #255]!");
1048 COMPARE(strh(w22, MemOperand(x23, -256, PreIndex)),
1049 "strh w22, [x23, #-256]!");
1050 COMPARE(strh(w24, MemOperand(x25, 255, PostIndex)), "strh w24, [x25], #255");
1051 COMPARE(strh(w26, MemOperand(x27, -256, PostIndex)),
1052 "strh w26, [x27], #-256");
1053 COMPARE(ldrh(w28, MemOperand(sp, 3, PostIndex)), "ldrh w28, [sp], #3");
1054 COMPARE(strh(x29, MemOperand(sp, -42, PreIndex)), "strh w29, [sp, #-42]!");
1055 COMPARE(ldrh(w30, MemOperand(x0, 255)), "ldurh w30, [x0, #255]");
1056 COMPARE(ldrh(x1, MemOperand(x2, -256)), "ldurh w1, [x2, #-256]");
1057 COMPARE(strh(w3, MemOperand(x4, 255)), "sturh w3, [x4, #255]");
1058 COMPARE(strh(x5, MemOperand(x6, -256)), "sturh w5, [x6, #-256]");
1059 COMPARE(ldrsh(w0, MemOperand(x1)), "ldrsh w0, [x1]");
1060 COMPARE(ldrsh(w2, MemOperand(x3, 8)), "ldrsh w2, [x3, #8]");
1061 COMPARE(ldrsh(w4, MemOperand(x5, 42, PreIndex)), "ldrsh w4, [x5, #42]!");
1062 COMPARE(ldrsh(x6, MemOperand(x7, -11, PostIndex)), "ldrsh x6, [x7], #-11");
1063
1064 CLEANUP();
1065}
1066
1067
1068TEST(load_store_fp) {
1069 SETUP();
1070
1071 COMPARE(ldr(s0, MemOperand(x1)), "ldr s0, [x1]");
1072 COMPARE(ldr(s2, MemOperand(x3, 4)), "ldr s2, [x3, #4]");
1073 COMPARE(ldr(s4, MemOperand(x5, 16380)), "ldr s4, [x5, #16380]");
1074 COMPARE(ldr(d6, MemOperand(x7)), "ldr d6, [x7]");
1075 COMPARE(ldr(d8, MemOperand(x9, 8)), "ldr d8, [x9, #8]");
1076 COMPARE(ldr(d10, MemOperand(x11, 32760)), "ldr d10, [x11, #32760]");
1077 COMPARE(str(s12, MemOperand(x13)), "str s12, [x13]");
1078 COMPARE(str(s14, MemOperand(x15, 4)), "str s14, [x15, #4]");
1079 COMPARE(str(s16, MemOperand(x17, 16380)), "str s16, [x17, #16380]");
1080 COMPARE(str(d18, MemOperand(x19)), "str d18, [x19]");
1081 COMPARE(str(d20, MemOperand(x21, 8)), "str d20, [x21, #8]");
1082 COMPARE(str(d22, MemOperand(x23, 32760)), "str d22, [x23, #32760]");
1083
1084 COMPARE(ldr(s0, MemOperand(x1, 4, PreIndex)), "ldr s0, [x1, #4]!");
1085 COMPARE(ldr(s2, MemOperand(x3, 255, PreIndex)), "ldr s2, [x3, #255]!");
1086 COMPARE(ldr(s4, MemOperand(x5, -256, PreIndex)), "ldr s4, [x5, #-256]!");
1087 COMPARE(ldr(d6, MemOperand(x7, 8, PreIndex)), "ldr d6, [x7, #8]!");
1088 COMPARE(ldr(d8, MemOperand(x9, 255, PreIndex)), "ldr d8, [x9, #255]!");
1089 COMPARE(ldr(d10, MemOperand(x11, -256, PreIndex)), "ldr d10, [x11, #-256]!");
1090 COMPARE(str(s12, MemOperand(x13, 4, PreIndex)), "str s12, [x13, #4]!");
1091 COMPARE(str(s14, MemOperand(x15, 255, PreIndex)), "str s14, [x15, #255]!");
1092 COMPARE(str(s16, MemOperand(x17, -256, PreIndex)), "str s16, [x17, #-256]!");
1093 COMPARE(str(d18, MemOperand(x19, 8, PreIndex)), "str d18, [x19, #8]!");
1094 COMPARE(str(d20, MemOperand(x21, 255, PreIndex)), "str d20, [x21, #255]!");
1095 COMPARE(str(d22, MemOperand(x23, -256, PreIndex)), "str d22, [x23, #-256]!");
1096
1097 COMPARE(ldr(s0, MemOperand(x1, 4, PostIndex)), "ldr s0, [x1], #4");
1098 COMPARE(ldr(s2, MemOperand(x3, 255, PostIndex)), "ldr s2, [x3], #255");
1099 COMPARE(ldr(s4, MemOperand(x5, -256, PostIndex)), "ldr s4, [x5], #-256");
1100 COMPARE(ldr(d6, MemOperand(x7, 8, PostIndex)), "ldr d6, [x7], #8");
1101 COMPARE(ldr(d8, MemOperand(x9, 255, PostIndex)), "ldr d8, [x9], #255");
1102 COMPARE(ldr(d10, MemOperand(x11, -256, PostIndex)), "ldr d10, [x11], #-256");
1103 COMPARE(str(s12, MemOperand(x13, 4, PostIndex)), "str s12, [x13], #4");
1104 COMPARE(str(s14, MemOperand(x15, 255, PostIndex)), "str s14, [x15], #255");
1105 COMPARE(str(s16, MemOperand(x17, -256, PostIndex)), "str s16, [x17], #-256");
1106 COMPARE(str(d18, MemOperand(x19, 8, PostIndex)), "str d18, [x19], #8");
1107 COMPARE(str(d20, MemOperand(x21, 255, PostIndex)), "str d20, [x21], #255");
1108 COMPARE(str(d22, MemOperand(x23, -256, PostIndex)), "str d22, [x23], #-256");
1109
1110 COMPARE(ldr(s24, MemOperand(sp)), "ldr s24, [sp]");
1111 COMPARE(ldr(d25, MemOperand(sp, 8)), "ldr d25, [sp, #8]");
1112 COMPARE(str(s26, MemOperand(sp, 4, PreIndex)), "str s26, [sp, #4]!");
1113 COMPARE(str(d27, MemOperand(sp, -8, PostIndex)), "str d27, [sp], #-8");
1114
1115 CLEANUP();
1116}
1117
1118
1119TEST(load_store_unscaled) {
1120 SETUP();
1121
armvixl4a102ba2014-07-14 09:02:40 +01001122 // If an unscaled-offset instruction is requested, it is used, even if the
1123 // offset could be encoded in a scaled-offset instruction.
1124 COMPARE(ldurb(w0, MemOperand(x1)), "ldurb w0, [x1]");
1125 COMPARE(ldurb(x2, MemOperand(x3, 1)), "ldurb w2, [x3, #1]");
1126 COMPARE(ldurb(w4, MemOperand(x5, 255)), "ldurb w4, [x5, #255]");
1127 COMPARE(sturb(w14, MemOperand(x15)), "sturb w14, [x15]");
1128 COMPARE(sturb(x16, MemOperand(x17, 1)), "sturb w16, [x17, #1]");
1129 COMPARE(sturb(w18, MemOperand(x19, 255)), "sturb w18, [x19, #255]");
1130 COMPARE(ldursb(w0, MemOperand(x1)), "ldursb w0, [x1]");
1131 COMPARE(ldursb(w2, MemOperand(x3, 1)), "ldursb w2, [x3, #1]");
1132 COMPARE(ldursb(x2, MemOperand(x3, 255)), "ldursb x2, [x3, #255]");
1133
1134 COMPARE(ldurh(w0, MemOperand(x1)), "ldurh w0, [x1]");
1135 COMPARE(ldurh(x2, MemOperand(x3, 2)), "ldurh w2, [x3, #2]");
1136 COMPARE(ldurh(w4, MemOperand(x5, 254)), "ldurh w4, [x5, #254]");
1137 COMPARE(sturh(w14, MemOperand(x15)), "sturh w14, [x15]");
1138 COMPARE(sturh(x16, MemOperand(x17, 2)), "sturh w16, [x17, #2]");
1139 COMPARE(sturh(w18, MemOperand(x19, 254)), "sturh w18, [x19, #254]");
1140 COMPARE(ldursh(w0, MemOperand(x1)), "ldursh w0, [x1]");
1141 COMPARE(ldursh(w2, MemOperand(x3, 2)), "ldursh w2, [x3, #2]");
1142 COMPARE(ldursh(x4, MemOperand(x5, 254)), "ldursh x4, [x5, #254]");
1143
1144 COMPARE(ldur(w0, MemOperand(x1)), "ldur w0, [x1]");
1145 COMPARE(ldur(w2, MemOperand(x3, 4)), "ldur w2, [x3, #4]");
1146 COMPARE(ldur(w4, MemOperand(x5, 248)), "ldur w4, [x5, #248]");
1147 COMPARE(stur(w12, MemOperand(x13)), "stur w12, [x13]");
1148 COMPARE(stur(w14, MemOperand(x15, 4)), "stur w14, [x15, #4]");
1149 COMPARE(stur(w16, MemOperand(x17, 248)), "stur w16, [x17, #248]");
1150 COMPARE(ldursw(x0, MemOperand(x1)), "ldursw x0, [x1]");
1151 COMPARE(ldursw(x2, MemOperand(x3, 4)), "ldursw x2, [x3, #4]");
1152 COMPARE(ldursw(x4, MemOperand(x5, 248)), "ldursw x4, [x5, #248]");
1153
1154 COMPARE(ldur(x6, MemOperand(x7)), "ldur x6, [x7]");
1155 COMPARE(ldur(x8, MemOperand(x9, 8)), "ldur x8, [x9, #8]");
1156 COMPARE(ldur(x10, MemOperand(x11, 248)), "ldur x10, [x11, #248]");
1157 COMPARE(stur(x18, MemOperand(x19)), "stur x18, [x19]");
1158 COMPARE(stur(x20, MemOperand(x21, 8)), "stur x20, [x21, #8]");
1159 COMPARE(stur(x22, MemOperand(x23, 248)), "stur x22, [x23, #248]");
1160
1161 // Normal loads and stores are converted to unscaled loads and stores if the
1162 // offset requires it.
armvixlad96eda2013-06-14 11:42:37 +01001163 COMPARE(ldr(w0, MemOperand(x1, 1)), "ldur w0, [x1, #1]");
1164 COMPARE(ldr(w2, MemOperand(x3, -1)), "ldur w2, [x3, #-1]");
1165 COMPARE(ldr(w4, MemOperand(x5, 255)), "ldur w4, [x5, #255]");
1166 COMPARE(ldr(w6, MemOperand(x7, -256)), "ldur w6, [x7, #-256]");
1167 COMPARE(ldr(x8, MemOperand(x9, 1)), "ldur x8, [x9, #1]");
1168 COMPARE(ldr(x10, MemOperand(x11, -1)), "ldur x10, [x11, #-1]");
1169 COMPARE(ldr(x12, MemOperand(x13, 255)), "ldur x12, [x13, #255]");
1170 COMPARE(ldr(x14, MemOperand(x15, -256)), "ldur x14, [x15, #-256]");
1171 COMPARE(str(w16, MemOperand(x17, 1)), "stur w16, [x17, #1]");
1172 COMPARE(str(w18, MemOperand(x19, -1)), "stur w18, [x19, #-1]");
1173 COMPARE(str(w20, MemOperand(x21, 255)), "stur w20, [x21, #255]");
1174 COMPARE(str(w22, MemOperand(x23, -256)), "stur w22, [x23, #-256]");
1175 COMPARE(str(x24, MemOperand(x25, 1)), "stur x24, [x25, #1]");
1176 COMPARE(str(x26, MemOperand(x27, -1)), "stur x26, [x27, #-1]");
1177 COMPARE(str(x28, MemOperand(x29, 255)), "stur x28, [x29, #255]");
1178 COMPARE(str(x30, MemOperand(x0, -256)), "stur x30, [x0, #-256]");
1179 COMPARE(ldr(w0, MemOperand(sp, 1)), "ldur w0, [sp, #1]");
1180 COMPARE(str(x1, MemOperand(sp, -1)), "stur x1, [sp, #-1]");
1181 COMPARE(ldrb(w2, MemOperand(x3, -2)), "ldurb w2, [x3, #-2]");
1182 COMPARE(ldrsb(w4, MemOperand(x5, -3)), "ldursb w4, [x5, #-3]");
1183 COMPARE(ldrsb(x6, MemOperand(x7, -4)), "ldursb x6, [x7, #-4]");
1184 COMPARE(ldrh(w8, MemOperand(x9, -5)), "ldurh w8, [x9, #-5]");
1185 COMPARE(ldrsh(w10, MemOperand(x11, -6)), "ldursh w10, [x11, #-6]");
1186 COMPARE(ldrsh(x12, MemOperand(x13, -7)), "ldursh x12, [x13, #-7]");
1187 COMPARE(ldrsw(x14, MemOperand(x15, -8)), "ldursw x14, [x15, #-8]");
1188
1189 CLEANUP();
1190}
1191
armvixl4a102ba2014-07-14 09:02:40 +01001192
1193TEST(load_store_unscaled_option) {
1194 SETUP();
1195
1196 // Just like load_store_unscaled, but specify the scaling option explicitly.
1197 LoadStoreScalingOption options[] = {
1198 PreferUnscaledOffset,
1199 RequireUnscaledOffset
1200 };
1201
1202 for (size_t i = 0; i < sizeof(options)/sizeof(options[0]); i++) {
1203 LoadStoreScalingOption option = options[i];
1204
1205 // If an unscaled-offset instruction is requested, it is used, even if the
1206 // offset could be encoded in a scaled-offset instruction.
1207 COMPARE(ldurb(w0, MemOperand(x1), option), "ldurb w0, [x1]");
1208 COMPARE(ldurb(x2, MemOperand(x3, 1), option), "ldurb w2, [x3, #1]");
1209 COMPARE(ldurb(w4, MemOperand(x5, 255), option), "ldurb w4, [x5, #255]");
1210 COMPARE(sturb(w14, MemOperand(x15), option), "sturb w14, [x15]");
1211 COMPARE(sturb(x16, MemOperand(x17, 1), option), "sturb w16, [x17, #1]");
1212 COMPARE(sturb(w18, MemOperand(x19, 255), option), "sturb w18, [x19, #255]");
1213 COMPARE(ldursb(w0, MemOperand(x1), option), "ldursb w0, [x1]");
1214 COMPARE(ldursb(w2, MemOperand(x3, 1), option), "ldursb w2, [x3, #1]");
1215 COMPARE(ldursb(x2, MemOperand(x3, 255), option), "ldursb x2, [x3, #255]");
1216
1217 COMPARE(ldurh(w0, MemOperand(x1), option), "ldurh w0, [x1]");
1218 COMPARE(ldurh(x2, MemOperand(x3, 2), option), "ldurh w2, [x3, #2]");
1219 COMPARE(ldurh(w4, MemOperand(x5, 254), option), "ldurh w4, [x5, #254]");
1220 COMPARE(sturh(w14, MemOperand(x15), option), "sturh w14, [x15]");
1221 COMPARE(sturh(x16, MemOperand(x17, 2), option), "sturh w16, [x17, #2]");
1222 COMPARE(sturh(w18, MemOperand(x19, 254), option), "sturh w18, [x19, #254]");
1223 COMPARE(ldursh(w0, MemOperand(x1), option), "ldursh w0, [x1]");
1224 COMPARE(ldursh(w2, MemOperand(x3, 2), option), "ldursh w2, [x3, #2]");
1225 COMPARE(ldursh(x4, MemOperand(x5, 254), option), "ldursh x4, [x5, #254]");
1226
1227 COMPARE(ldur(w0, MemOperand(x1), option), "ldur w0, [x1]");
1228 COMPARE(ldur(w2, MemOperand(x3, 4), option), "ldur w2, [x3, #4]");
1229 COMPARE(ldur(w4, MemOperand(x5, 248), option), "ldur w4, [x5, #248]");
1230 COMPARE(stur(w12, MemOperand(x13), option), "stur w12, [x13]");
1231 COMPARE(stur(w14, MemOperand(x15, 4), option), "stur w14, [x15, #4]");
1232 COMPARE(stur(w16, MemOperand(x17, 248), option), "stur w16, [x17, #248]");
1233 COMPARE(ldursw(x0, MemOperand(x1), option), "ldursw x0, [x1]");
1234 COMPARE(ldursw(x2, MemOperand(x3, 4), option), "ldursw x2, [x3, #4]");
1235 COMPARE(ldursw(x4, MemOperand(x5, 248), option), "ldursw x4, [x5, #248]");
1236
1237 COMPARE(ldur(x6, MemOperand(x7), option), "ldur x6, [x7]");
1238 COMPARE(ldur(x8, MemOperand(x9, 8), option), "ldur x8, [x9, #8]");
1239 COMPARE(ldur(x10, MemOperand(x11, 248), option), "ldur x10, [x11, #248]");
1240 COMPARE(stur(x18, MemOperand(x19), option), "stur x18, [x19]");
1241 COMPARE(stur(x20, MemOperand(x21, 8), option), "stur x20, [x21, #8]");
1242 COMPARE(stur(x22, MemOperand(x23, 248), option), "stur x22, [x23, #248]");
1243 }
1244
1245 // Normal loads and stores are converted to unscaled loads and stores if the
1246 // offset requires it. PreferScaledOffset is the default for these cases, so
1247 // the behaviour here is the same when no option is specified.
1248 LoadStoreScalingOption option = PreferScaledOffset;
1249 COMPARE(ldr(w0, MemOperand(x1, 1), option), "ldur w0, [x1, #1]");
1250 COMPARE(ldr(w2, MemOperand(x3, -1), option), "ldur w2, [x3, #-1]");
1251 COMPARE(ldr(w4, MemOperand(x5, 255), option), "ldur w4, [x5, #255]");
1252 COMPARE(ldr(w6, MemOperand(x7, -256), option), "ldur w6, [x7, #-256]");
1253 COMPARE(ldr(x8, MemOperand(x9, 1), option), "ldur x8, [x9, #1]");
1254 COMPARE(ldr(x10, MemOperand(x11, -1), option), "ldur x10, [x11, #-1]");
1255 COMPARE(ldr(x12, MemOperand(x13, 255), option), "ldur x12, [x13, #255]");
1256 COMPARE(ldr(x14, MemOperand(x15, -256), option), "ldur x14, [x15, #-256]");
1257 COMPARE(str(w16, MemOperand(x17, 1), option), "stur w16, [x17, #1]");
1258 COMPARE(str(w18, MemOperand(x19, -1), option), "stur w18, [x19, #-1]");
1259 COMPARE(str(w20, MemOperand(x21, 255), option), "stur w20, [x21, #255]");
1260 COMPARE(str(w22, MemOperand(x23, -256), option), "stur w22, [x23, #-256]");
1261 COMPARE(str(x24, MemOperand(x25, 1), option), "stur x24, [x25, #1]");
1262 COMPARE(str(x26, MemOperand(x27, -1), option), "stur x26, [x27, #-1]");
1263 COMPARE(str(x28, MemOperand(x29, 255), option), "stur x28, [x29, #255]");
1264 COMPARE(str(x30, MemOperand(x0, -256), option), "stur x30, [x0, #-256]");
1265 COMPARE(ldr(w0, MemOperand(sp, 1), option), "ldur w0, [sp, #1]");
1266 COMPARE(str(x1, MemOperand(sp, -1), option), "stur x1, [sp, #-1]");
1267 COMPARE(ldrb(w2, MemOperand(x3, -2), option), "ldurb w2, [x3, #-2]");
1268 COMPARE(ldrsb(w4, MemOperand(x5, -3), option), "ldursb w4, [x5, #-3]");
1269 COMPARE(ldrsb(x6, MemOperand(x7, -4), option), "ldursb x6, [x7, #-4]");
1270 COMPARE(ldrh(w8, MemOperand(x9, -5), option), "ldurh w8, [x9, #-5]");
1271 COMPARE(ldrsh(w10, MemOperand(x11, -6), option), "ldursh w10, [x11, #-6]");
1272 COMPARE(ldrsh(x12, MemOperand(x13, -7), option), "ldursh x12, [x13, #-7]");
1273 COMPARE(ldrsw(x14, MemOperand(x15, -8), option), "ldursw x14, [x15, #-8]");
1274
1275 CLEANUP();
1276}
1277
1278
armvixlad96eda2013-06-14 11:42:37 +01001279TEST(load_store_pair) {
1280 SETUP();
1281
1282 COMPARE(ldp(w0, w1, MemOperand(x2)), "ldp w0, w1, [x2]");
1283 COMPARE(ldp(x3, x4, MemOperand(x5)), "ldp x3, x4, [x5]");
1284 COMPARE(ldp(w6, w7, MemOperand(x8, 4)), "ldp w6, w7, [x8, #4]");
1285 COMPARE(ldp(x9, x10, MemOperand(x11, 8)), "ldp x9, x10, [x11, #8]");
1286 COMPARE(ldp(w12, w13, MemOperand(x14, 252)), "ldp w12, w13, [x14, #252]");
1287 COMPARE(ldp(x15, x16, MemOperand(x17, 504)), "ldp x15, x16, [x17, #504]");
1288 COMPARE(ldp(w18, w19, MemOperand(x20, -256)), "ldp w18, w19, [x20, #-256]");
1289 COMPARE(ldp(x21, x22, MemOperand(x23, -512)), "ldp x21, x22, [x23, #-512]");
1290 COMPARE(ldp(w24, w25, MemOperand(x26, 252, PreIndex)),
1291 "ldp w24, w25, [x26, #252]!");
1292 COMPARE(ldp(x27, x28, MemOperand(x29, 504, PreIndex)),
1293 "ldp x27, x28, [x29, #504]!");
1294 COMPARE(ldp(w30, w0, MemOperand(x1, -256, PreIndex)),
1295 "ldp w30, w0, [x1, #-256]!");
1296 COMPARE(ldp(x2, x3, MemOperand(x4, -512, PreIndex)),
1297 "ldp x2, x3, [x4, #-512]!");
1298 COMPARE(ldp(w5, w6, MemOperand(x7, 252, PostIndex)),
1299 "ldp w5, w6, [x7], #252");
1300 COMPARE(ldp(x8, x9, MemOperand(x10, 504, PostIndex)),
1301 "ldp x8, x9, [x10], #504");
1302 COMPARE(ldp(w11, w12, MemOperand(x13, -256, PostIndex)),
1303 "ldp w11, w12, [x13], #-256");
1304 COMPARE(ldp(x14, x15, MemOperand(x16, -512, PostIndex)),
1305 "ldp x14, x15, [x16], #-512");
1306
1307 COMPARE(ldp(s17, s18, MemOperand(x19)), "ldp s17, s18, [x19]");
1308 COMPARE(ldp(s20, s21, MemOperand(x22, 252)), "ldp s20, s21, [x22, #252]");
1309 COMPARE(ldp(s23, s24, MemOperand(x25, -256)), "ldp s23, s24, [x25, #-256]");
1310 COMPARE(ldp(s26, s27, MemOperand(x28, 252, PreIndex)),
1311 "ldp s26, s27, [x28, #252]!");
1312 COMPARE(ldp(s29, s30, MemOperand(x29, -256, PreIndex)),
1313 "ldp s29, s30, [x29, #-256]!");
1314 COMPARE(ldp(s31, s0, MemOperand(x1, 252, PostIndex)),
1315 "ldp s31, s0, [x1], #252");
1316 COMPARE(ldp(s2, s3, MemOperand(x4, -256, PostIndex)),
1317 "ldp s2, s3, [x4], #-256");
1318 COMPARE(ldp(d17, d18, MemOperand(x19)), "ldp d17, d18, [x19]");
1319 COMPARE(ldp(d20, d21, MemOperand(x22, 504)), "ldp d20, d21, [x22, #504]");
1320 COMPARE(ldp(d23, d24, MemOperand(x25, -512)), "ldp d23, d24, [x25, #-512]");
1321 COMPARE(ldp(d26, d27, MemOperand(x28, 504, PreIndex)),
1322 "ldp d26, d27, [x28, #504]!");
1323 COMPARE(ldp(d29, d30, MemOperand(x29, -512, PreIndex)),
1324 "ldp d29, d30, [x29, #-512]!");
1325 COMPARE(ldp(d31, d0, MemOperand(x1, 504, PostIndex)),
1326 "ldp d31, d0, [x1], #504");
1327 COMPARE(ldp(d2, d3, MemOperand(x4, -512, PostIndex)),
1328 "ldp d2, d3, [x4], #-512");
1329
1330 COMPARE(stp(w0, w1, MemOperand(x2)), "stp w0, w1, [x2]");
1331 COMPARE(stp(x3, x4, MemOperand(x5)), "stp x3, x4, [x5]");
1332 COMPARE(stp(w6, w7, MemOperand(x8, 4)), "stp w6, w7, [x8, #4]");
1333 COMPARE(stp(x9, x10, MemOperand(x11, 8)), "stp x9, x10, [x11, #8]");
1334 COMPARE(stp(w12, w13, MemOperand(x14, 252)), "stp w12, w13, [x14, #252]");
1335 COMPARE(stp(x15, x16, MemOperand(x17, 504)), "stp x15, x16, [x17, #504]");
1336 COMPARE(stp(w18, w19, MemOperand(x20, -256)), "stp w18, w19, [x20, #-256]");
1337 COMPARE(stp(x21, x22, MemOperand(x23, -512)), "stp x21, x22, [x23, #-512]");
1338 COMPARE(stp(w24, w25, MemOperand(x26, 252, PreIndex)),
1339 "stp w24, w25, [x26, #252]!");
1340 COMPARE(stp(x27, x28, MemOperand(x29, 504, PreIndex)),
1341 "stp x27, x28, [x29, #504]!");
1342 COMPARE(stp(w30, w0, MemOperand(x1, -256, PreIndex)),
1343 "stp w30, w0, [x1, #-256]!");
1344 COMPARE(stp(x2, x3, MemOperand(x4, -512, PreIndex)),
1345 "stp x2, x3, [x4, #-512]!");
1346 COMPARE(stp(w5, w6, MemOperand(x7, 252, PostIndex)),
1347 "stp w5, w6, [x7], #252");
1348 COMPARE(stp(x8, x9, MemOperand(x10, 504, PostIndex)),
1349 "stp x8, x9, [x10], #504");
1350 COMPARE(stp(w11, w12, MemOperand(x13, -256, PostIndex)),
1351 "stp w11, w12, [x13], #-256");
1352 COMPARE(stp(x14, x15, MemOperand(x16, -512, PostIndex)),
1353 "stp x14, x15, [x16], #-512");
1354
1355 COMPARE(stp(s17, s18, MemOperand(x19)), "stp s17, s18, [x19]");
1356 COMPARE(stp(s20, s21, MemOperand(x22, 252)), "stp s20, s21, [x22, #252]");
1357 COMPARE(stp(s23, s24, MemOperand(x25, -256)), "stp s23, s24, [x25, #-256]");
1358 COMPARE(stp(s26, s27, MemOperand(x28, 252, PreIndex)),
1359 "stp s26, s27, [x28, #252]!");
1360 COMPARE(stp(s29, s30, MemOperand(x29, -256, PreIndex)),
1361 "stp s29, s30, [x29, #-256]!");
1362 COMPARE(stp(s31, s0, MemOperand(x1, 252, PostIndex)),
1363 "stp s31, s0, [x1], #252");
1364 COMPARE(stp(s2, s3, MemOperand(x4, -256, PostIndex)),
1365 "stp s2, s3, [x4], #-256");
1366 COMPARE(stp(d17, d18, MemOperand(x19)), "stp d17, d18, [x19]");
1367 COMPARE(stp(d20, d21, MemOperand(x22, 504)), "stp d20, d21, [x22, #504]");
1368 COMPARE(stp(d23, d24, MemOperand(x25, -512)), "stp d23, d24, [x25, #-512]");
1369 COMPARE(stp(d26, d27, MemOperand(x28, 504, PreIndex)),
1370 "stp d26, d27, [x28, #504]!");
1371 COMPARE(stp(d29, d30, MemOperand(x29, -512, PreIndex)),
1372 "stp d29, d30, [x29, #-512]!");
1373 COMPARE(stp(d31, d0, MemOperand(x1, 504, PostIndex)),
1374 "stp d31, d0, [x1], #504");
1375 COMPARE(stp(d2, d3, MemOperand(x4, -512, PostIndex)),
1376 "stp d2, d3, [x4], #-512");
1377
1378 COMPARE(ldp(w16, w17, MemOperand(sp, 4, PostIndex)),
1379 "ldp w16, w17, [sp], #4");
1380 COMPARE(stp(x18, x19, MemOperand(sp, -8, PreIndex)),
1381 "stp x18, x19, [sp, #-8]!");
1382 COMPARE(ldp(s30, s31, MemOperand(sp, 12, PostIndex)),
1383 "ldp s30, s31, [sp], #12");
1384 COMPARE(stp(d30, d31, MemOperand(sp, -16)),
1385 "stp d30, d31, [sp, #-16]");
1386
1387 COMPARE(ldpsw(x0, x1, MemOperand(x2)), "ldpsw x0, x1, [x2]");
1388 COMPARE(ldpsw(x3, x4, MemOperand(x5, 16)), "ldpsw x3, x4, [x5, #16]");
1389 COMPARE(ldpsw(x6, x7, MemOperand(x8, -32, PreIndex)),
1390 "ldpsw x6, x7, [x8, #-32]!");
1391 COMPARE(ldpsw(x9, x10, MemOperand(x11, 128, PostIndex)),
1392 "ldpsw x9, x10, [x11], #128");
1393
1394 CLEANUP();
1395}
1396
armvixl4a102ba2014-07-14 09:02:40 +01001397
1398TEST(load_store_exclusive) {
1399 SETUP();
1400
1401 COMPARE(stxrb(w0, w1, MemOperand(x2)), "stxrb w0, w1, [x2]");
1402 COMPARE(stxrb(x3, w4, MemOperand(sp)), "stxrb w3, w4, [sp]");
1403 COMPARE(stxrb(w5, x6, MemOperand(x7)), "stxrb w5, w6, [x7]");
1404 COMPARE(stxrb(x8, x9, MemOperand(sp)), "stxrb w8, w9, [sp]");
1405 COMPARE(stxrh(w10, w11, MemOperand(x12)), "stxrh w10, w11, [x12]");
1406 COMPARE(stxrh(x13, w14, MemOperand(sp)), "stxrh w13, w14, [sp]");
1407 COMPARE(stxrh(w15, x16, MemOperand(x17)), "stxrh w15, w16, [x17]");
1408 COMPARE(stxrh(x18, x19, MemOperand(sp)), "stxrh w18, w19, [sp]");
1409 COMPARE(stxr(w20, w21, MemOperand(x22)), "stxr w20, w21, [x22]");
1410 COMPARE(stxr(x23, w24, MemOperand(sp)), "stxr w23, w24, [sp]");
1411 COMPARE(stxr(w25, x26, MemOperand(x27)), "stxr w25, x26, [x27]");
1412 COMPARE(stxr(x28, x29, MemOperand(sp)), "stxr w28, x29, [sp]");
1413 COMPARE(ldxrb(w30, MemOperand(x0)), "ldxrb w30, [x0]");
1414 COMPARE(ldxrb(w1, MemOperand(sp)), "ldxrb w1, [sp]");
1415 COMPARE(ldxrb(x2, MemOperand(x3)), "ldxrb w2, [x3]");
1416 COMPARE(ldxrb(x4, MemOperand(sp)), "ldxrb w4, [sp]");
1417 COMPARE(ldxrh(w5, MemOperand(x6)), "ldxrh w5, [x6]");
1418 COMPARE(ldxrh(w7, MemOperand(sp)), "ldxrh w7, [sp]");
1419 COMPARE(ldxrh(x8, MemOperand(x9)), "ldxrh w8, [x9]");
1420 COMPARE(ldxrh(x10, MemOperand(sp)), "ldxrh w10, [sp]");
1421 COMPARE(ldxr(w11, MemOperand(x12)), "ldxr w11, [x12]");
1422 COMPARE(ldxr(w13, MemOperand(sp)), "ldxr w13, [sp]");
1423 COMPARE(ldxr(x14, MemOperand(x15)), "ldxr x14, [x15]");
1424 COMPARE(ldxr(x16, MemOperand(sp)), "ldxr x16, [sp]");
1425 COMPARE(stxp(w17, w18, w19, MemOperand(x20)), "stxp w17, w18, w19, [x20]");
1426 COMPARE(stxp(x21, w22, w23, MemOperand(sp)), "stxp w21, w22, w23, [sp]");
1427 COMPARE(stxp(w24, x25, x26, MemOperand(x27)), "stxp w24, x25, x26, [x27]");
1428 COMPARE(stxp(x28, x29, x30, MemOperand(sp)), "stxp w28, x29, x30, [sp]");
1429 COMPARE(ldxp(w0, w1, MemOperand(x2)), "ldxp w0, w1, [x2]");
1430 COMPARE(ldxp(w3, w4, MemOperand(sp)), "ldxp w3, w4, [sp]");
1431 COMPARE(ldxp(x5, x6, MemOperand(x7)), "ldxp x5, x6, [x7]");
1432 COMPARE(ldxp(x8, x9, MemOperand(sp)), "ldxp x8, x9, [sp]");
1433 COMPARE(stlxrb(w10, w11, MemOperand(x12)), "stlxrb w10, w11, [x12]");
1434 COMPARE(stlxrb(x13, w14, MemOperand(sp)), "stlxrb w13, w14, [sp]");
1435 COMPARE(stlxrb(w15, x16, MemOperand(x17)), "stlxrb w15, w16, [x17]");
1436 COMPARE(stlxrb(x18, x19, MemOperand(sp)), "stlxrb w18, w19, [sp]");
1437 COMPARE(stlxrh(w20, w21, MemOperand(x22)), "stlxrh w20, w21, [x22]");
1438 COMPARE(stlxrh(x23, w24, MemOperand(sp)), "stlxrh w23, w24, [sp]");
1439 COMPARE(stlxrh(w25, x26, MemOperand(x27)), "stlxrh w25, w26, [x27]");
1440 COMPARE(stlxrh(x28, x29, MemOperand(sp)), "stlxrh w28, w29, [sp]");
1441 COMPARE(stlxr(w30, w0, MemOperand(x1)), "stlxr w30, w0, [x1]");
1442 COMPARE(stlxr(x2, w3, MemOperand(sp)), "stlxr w2, w3, [sp]");
1443 COMPARE(stlxr(w4, x5, MemOperand(x6)), "stlxr w4, x5, [x6]");
1444 COMPARE(stlxr(x7, x8, MemOperand(sp)), "stlxr w7, x8, [sp]");
1445 COMPARE(ldaxrb(w9, MemOperand(x10)), "ldaxrb w9, [x10]");
1446 COMPARE(ldaxrb(w11, MemOperand(sp)), "ldaxrb w11, [sp]");
1447 COMPARE(ldaxrb(x12, MemOperand(x13)), "ldaxrb w12, [x13]");
1448 COMPARE(ldaxrb(x14, MemOperand(sp)), "ldaxrb w14, [sp]");
1449 COMPARE(ldaxrh(w15, MemOperand(x16)), "ldaxrh w15, [x16]");
1450 COMPARE(ldaxrh(w17, MemOperand(sp)), "ldaxrh w17, [sp]");
1451 COMPARE(ldaxrh(x18, MemOperand(x19)), "ldaxrh w18, [x19]");
1452 COMPARE(ldaxrh(x20, MemOperand(sp)), "ldaxrh w20, [sp]");
1453 COMPARE(ldaxr(w21, MemOperand(x22)), "ldaxr w21, [x22]");
1454 COMPARE(ldaxr(w23, MemOperand(sp)), "ldaxr w23, [sp]");
1455 COMPARE(ldaxr(x24, MemOperand(x25)), "ldaxr x24, [x25]");
1456 COMPARE(ldaxr(x26, MemOperand(sp)), "ldaxr x26, [sp]");
1457 COMPARE(stlxp(w27, w28, w29, MemOperand(x30)), "stlxp w27, w28, w29, [x30]");
1458 COMPARE(stlxp(x0, w1, w2, MemOperand(sp)), "stlxp w0, w1, w2, [sp]");
1459 COMPARE(stlxp(w3, x4, x5, MemOperand(x6)), "stlxp w3, x4, x5, [x6]");
1460 COMPARE(stlxp(x7, x8, x9, MemOperand(sp)), "stlxp w7, x8, x9, [sp]");
1461 COMPARE(ldaxp(w10, w11, MemOperand(x12)), "ldaxp w10, w11, [x12]");
1462 COMPARE(ldaxp(w13, w14, MemOperand(sp)), "ldaxp w13, w14, [sp]");
1463 COMPARE(ldaxp(x15, x16, MemOperand(x17)), "ldaxp x15, x16, [x17]");
1464 COMPARE(ldaxp(x18, x19, MemOperand(sp)), "ldaxp x18, x19, [sp]");
1465 COMPARE(stlrb(w20, MemOperand(x21)), "stlrb w20, [x21]");
1466 COMPARE(stlrb(w22, MemOperand(sp)), "stlrb w22, [sp]");
1467 COMPARE(stlrb(x23, MemOperand(x24)), "stlrb w23, [x24]");
1468 COMPARE(stlrb(x25, MemOperand(sp)), "stlrb w25, [sp]");
1469 COMPARE(stlrh(w26, MemOperand(x27)), "stlrh w26, [x27]");
1470 COMPARE(stlrh(w28, MemOperand(sp)), "stlrh w28, [sp]");
1471 COMPARE(stlrh(x29, MemOperand(x30)), "stlrh w29, [x30]");
1472 COMPARE(stlrh(x0, MemOperand(sp)), "stlrh w0, [sp]");
1473 COMPARE(stlr(w1, MemOperand(x2)), "stlr w1, [x2]");
1474 COMPARE(stlr(w3, MemOperand(sp)), "stlr w3, [sp]");
1475 COMPARE(stlr(x4, MemOperand(x5)), "stlr x4, [x5]");
1476 COMPARE(stlr(x6, MemOperand(sp)), "stlr x6, [sp]");
1477 COMPARE(ldarb(w7, MemOperand(x8)), "ldarb w7, [x8]");
1478 COMPARE(ldarb(w9, MemOperand(sp)), "ldarb w9, [sp]");
1479 COMPARE(ldarb(x10, MemOperand(x11)), "ldarb w10, [x11]");
1480 COMPARE(ldarb(x12, MemOperand(sp)), "ldarb w12, [sp]");
1481 COMPARE(ldarh(w13, MemOperand(x14)), "ldarh w13, [x14]");
1482 COMPARE(ldarh(w15, MemOperand(sp)), "ldarh w15, [sp]");
1483 COMPARE(ldarh(x16, MemOperand(x17)), "ldarh w16, [x17]");
1484 COMPARE(ldarh(x18, MemOperand(sp)), "ldarh w18, [sp]");
1485 COMPARE(ldar(w19, MemOperand(x20)), "ldar w19, [x20]");
1486 COMPARE(ldar(w21, MemOperand(sp)), "ldar w21, [sp]");
1487 COMPARE(ldar(x22, MemOperand(x23)), "ldar x22, [x23]");
1488 COMPARE(ldar(x24, MemOperand(sp)), "ldar x24, [sp]");
1489
1490 CLEANUP();
1491}
1492
1493
armvixlad96eda2013-06-14 11:42:37 +01001494TEST(load_store_pair_nontemp) {
1495 SETUP();
1496
1497 COMPARE(ldnp(w0, w1, MemOperand(x2)), "ldnp w0, w1, [x2]");
1498 COMPARE(stnp(w3, w4, MemOperand(x5, 252)), "stnp w3, w4, [x5, #252]");
1499 COMPARE(ldnp(w6, w7, MemOperand(x8, -256)), "ldnp w6, w7, [x8, #-256]");
1500 COMPARE(stnp(x9, x10, MemOperand(x11)), "stnp x9, x10, [x11]");
1501 COMPARE(ldnp(x12, x13, MemOperand(x14, 504)), "ldnp x12, x13, [x14, #504]");
1502 COMPARE(stnp(x15, x16, MemOperand(x17, -512)), "stnp x15, x16, [x17, #-512]");
1503 COMPARE(ldnp(s18, s19, MemOperand(x20)), "ldnp s18, s19, [x20]");
1504 COMPARE(stnp(s21, s22, MemOperand(x23, 252)), "stnp s21, s22, [x23, #252]");
1505 COMPARE(ldnp(s24, s25, MemOperand(x26, -256)), "ldnp s24, s25, [x26, #-256]");
1506 COMPARE(stnp(d27, d28, MemOperand(x29)), "stnp d27, d28, [x29]");
1507 COMPARE(ldnp(d30, d31, MemOperand(x0, 504)), "ldnp d30, d31, [x0, #504]");
1508 COMPARE(stnp(d1, d2, MemOperand(x3, -512)), "stnp d1, d2, [x3, #-512]");
1509
1510 CLEANUP();
1511}
1512
armvixl4a102ba2014-07-14 09:02:40 +01001513
armvixl330dc712014-11-25 10:38:32 +00001514TEST(load_literal_macro) {
armvixlc68cb642014-09-25 18:49:30 +01001515 SETUP_CLASS(MacroAssembler);
armvixlad96eda2013-06-14 11:42:37 +01001516
armvixl330dc712014-11-25 10:38:32 +00001517 // In each case, the literal will be placed at PC+8:
1518 // ldr x10, pc+8 // Test instruction.
1519 // ldr xzr, pc+12 // Pool marker.
1520 // .word64 #0x1234567890abcdef // Test literal.
1521
1522 COMPARE_PREFIX(Ldr(x10, 0x1234567890abcdef), "ldr x10, pc+8");
1523 COMPARE_PREFIX(Ldr(w20, 0xfedcba09), "ldr w20, pc+8");
1524 COMPARE_PREFIX(Ldr(d11, 1.234), "ldr d11, pc+8");
1525 COMPARE_PREFIX(Ldr(s22, 2.5f), "ldr s22, pc+8");
1526 COMPARE_PREFIX(Ldrsw(x21, 0x80000000), "ldrsw x21, pc+8");
1527
1528 CLEANUP();
1529}
1530
1531
1532TEST(load_literal) {
1533 SETUP();
1534
1535 COMPARE_PREFIX(ldr(x20, 0), "ldr x20, pc+0");
1536 COMPARE_PREFIX(ldr(x20, 1), "ldr x20, pc+4");
1537 COMPARE_PREFIX(ldr(x20, -1), "ldr x20, pc-4");
1538 COMPARE_PREFIX(ldr(x20, 0x3ffff), "ldr x20, pc+1048572");
1539 COMPARE_PREFIX(ldr(x20, -0x40000), "ldr x20, pc-1048576");
1540 COMPARE_PREFIX(ldr(w21, 0), "ldr w21, pc+0");
1541 COMPARE_PREFIX(ldr(w21, 1), "ldr w21, pc+4");
1542 COMPARE_PREFIX(ldr(w21, -1), "ldr w21, pc-4");
1543 COMPARE_PREFIX(ldr(w21, 0x3ffff), "ldr w21, pc+1048572");
1544 COMPARE_PREFIX(ldr(w21, -0x40000), "ldr w21, pc-1048576");
1545 COMPARE_PREFIX(ldr(d22, 0), "ldr d22, pc+0");
1546 COMPARE_PREFIX(ldr(d22, 1), "ldr d22, pc+4");
1547 COMPARE_PREFIX(ldr(d22, -1), "ldr d22, pc-4");
1548 COMPARE_PREFIX(ldr(d22, 0x3ffff), "ldr d22, pc+1048572");
1549 COMPARE_PREFIX(ldr(d22, -0x40000), "ldr d22, pc-1048576");
1550 COMPARE_PREFIX(ldr(s23, 0), "ldr s23, pc+0");
1551 COMPARE_PREFIX(ldr(s23, 1), "ldr s23, pc+4");
1552 COMPARE_PREFIX(ldr(s23, -1), "ldr s23, pc-4");
1553 COMPARE_PREFIX(ldr(s23, 0x3ffff), "ldr s23, pc+1048572");
1554 COMPARE_PREFIX(ldr(s23, -0x40000), "ldr s23, pc-1048576");
1555 COMPARE_PREFIX(ldrsw(x24, 0), "ldrsw x24, pc+0");
1556 COMPARE_PREFIX(ldrsw(x24, 1), "ldrsw x24, pc+4");
1557 COMPARE_PREFIX(ldrsw(x24, -1), "ldrsw x24, pc-4");
1558 COMPARE_PREFIX(ldrsw(x24, 0x3ffff), "ldrsw x24, pc+1048572");
1559 COMPARE_PREFIX(ldrsw(x24, -0x40000), "ldrsw x24, pc-1048576");
1560
1561 CLEANUP();
1562}
1563
1564
1565TEST(prfm_operations) {
1566 SETUP();
1567
1568 // Test every encodable prefetch operation.
1569 const char* expected[] = {
1570 "prfm pldl1keep, ",
1571 "prfm pldl1strm, ",
1572 "prfm pldl2keep, ",
1573 "prfm pldl2strm, ",
1574 "prfm pldl3keep, ",
1575 "prfm pldl3strm, ",
1576 "prfm #0b00110, ",
1577 "prfm #0b00111, ",
1578 "prfm plil1keep, ",
1579 "prfm plil1strm, ",
1580 "prfm plil2keep, ",
1581 "prfm plil2strm, ",
1582 "prfm plil3keep, ",
1583 "prfm plil3strm, ",
1584 "prfm #0b01110, ",
1585 "prfm #0b01111, ",
1586 "prfm pstl1keep, ",
1587 "prfm pstl1strm, ",
1588 "prfm pstl2keep, ",
1589 "prfm pstl2strm, ",
1590 "prfm pstl3keep, ",
1591 "prfm pstl3strm, ",
1592 "prfm #0b10110, ",
1593 "prfm #0b10111, ",
1594 "prfm #0b11000, ",
1595 "prfm #0b11001, ",
1596 "prfm #0b11010, ",
1597 "prfm #0b11011, ",
1598 "prfm #0b11100, ",
1599 "prfm #0b11101, ",
1600 "prfm #0b11110, ",
1601 "prfm #0b11111, ",
1602 };
1603 const int expected_count = sizeof(expected) / sizeof(expected[0]);
1604 VIXL_STATIC_ASSERT((1 << ImmPrefetchOperation_width) == expected_count);
1605
1606 for (int i = 0; i < (1 << ImmPrefetchOperation_width); i++) {
1607 PrefetchOperation op = static_cast<PrefetchOperation>(i);
1608 COMPARE_PREFIX(prfm(op, 0), expected[i]);
1609 COMPARE_PREFIX(prfm(op, MemOperand(x0, 0)), expected[i]);
1610 COMPARE_PREFIX(prfm(op, MemOperand(x0, x1)), expected[i]);
1611 }
1612
1613 CLEANUP();
1614}
1615
1616
1617TEST(prfum_operations) {
1618 SETUP();
1619
1620 // Test every encodable prefetch operation.
1621 const char* expected[] = {
1622 "prfum pldl1keep, ",
1623 "prfum pldl1strm, ",
1624 "prfum pldl2keep, ",
1625 "prfum pldl2strm, ",
1626 "prfum pldl3keep, ",
1627 "prfum pldl3strm, ",
1628 "prfum #0b00110, ",
1629 "prfum #0b00111, ",
1630 "prfum plil1keep, ",
1631 "prfum plil1strm, ",
1632 "prfum plil2keep, ",
1633 "prfum plil2strm, ",
1634 "prfum plil3keep, ",
1635 "prfum plil3strm, ",
1636 "prfum #0b01110, ",
1637 "prfum #0b01111, ",
1638 "prfum pstl1keep, ",
1639 "prfum pstl1strm, ",
1640 "prfum pstl2keep, ",
1641 "prfum pstl2strm, ",
1642 "prfum pstl3keep, ",
1643 "prfum pstl3strm, ",
1644 "prfum #0b10110, ",
1645 "prfum #0b10111, ",
1646 "prfum #0b11000, ",
1647 "prfum #0b11001, ",
1648 "prfum #0b11010, ",
1649 "prfum #0b11011, ",
1650 "prfum #0b11100, ",
1651 "prfum #0b11101, ",
1652 "prfum #0b11110, ",
1653 "prfum #0b11111, ",
1654 };
1655 const int expected_count = sizeof(expected) / sizeof(expected[0]);
1656 VIXL_STATIC_ASSERT((1 << ImmPrefetchOperation_width) == expected_count);
1657
1658 for (int i = 0; i < (1 << ImmPrefetchOperation_width); i++) {
1659 PrefetchOperation op = static_cast<PrefetchOperation>(i);
1660 COMPARE_PREFIX(prfum(op, MemOperand(x0, 0)), expected[i]);
1661 }
1662
1663 CLEANUP();
1664}
1665
1666
1667TEST(prfm_offset) {
1668 SETUP();
1669
1670 COMPARE(prfm(PLDL1KEEP, MemOperand(x1)), "prfm pldl1keep, [x1]");
1671 COMPARE(prfm(PLDL1STRM, MemOperand(x3, 8)), "prfm pldl1strm, [x3, #8]");
1672 COMPARE(prfm(PLDL2KEEP, MemOperand(x5, 32760)),
1673 "prfm pldl2keep, [x5, #32760]");
1674
1675 COMPARE(prfm(PLDL2STRM, MemOperand(sp)), "prfm pldl2strm, [sp]");
1676 COMPARE(prfm(PLDL3KEEP, MemOperand(sp, 8)), "prfm pldl3keep, [sp, #8]");
1677 COMPARE(prfm(PLDL3STRM, MemOperand(sp, 32760)),
1678 "prfm pldl3strm, [sp, #32760]");
1679
1680 CLEANUP();
1681}
1682
1683
1684TEST(prfm_regoffset) {
1685 SETUP();
1686
1687 COMPARE(prfm(PLIL1KEEP, MemOperand(x1, x2)), "prfm plil1keep, [x1, x2]");
1688 COMPARE(prfm(PLIL1STRM, MemOperand(x3, w4, SXTW)),
1689 "prfm plil1strm, [x3, w4, sxtw]");
1690 COMPARE(prfm(PLIL2KEEP, MemOperand(x5, x6, LSL, 3)),
1691 "prfm plil2keep, [x5, x6, lsl #3]");
1692
1693 COMPARE(prfm(PLIL2STRM, MemOperand(sp, xzr)), "prfm plil2strm, [sp, xzr]");
1694 COMPARE(prfm(PLIL3KEEP, MemOperand(sp, wzr, SXTW)),
1695 "prfm plil3keep, [sp, wzr, sxtw]");
1696 COMPARE(prfm(PLIL3STRM, MemOperand(sp, xzr, LSL, 3)),
1697 "prfm plil3strm, [sp, xzr, lsl #3]");
1698
1699 CLEANUP();
1700}
1701
1702
1703TEST(prfm_literal) {
1704 SETUP();
1705
1706 COMPARE_PREFIX(prfm(PSTL1KEEP, 0), "prfm pstl1keep, pc+0");
1707 COMPARE_PREFIX(prfm(PSTL1STRM, 1), "prfm pstl1strm, pc+4");
1708 COMPARE_PREFIX(prfm(PSTL2KEEP, -1), "prfm pstl2keep, pc-4");
1709 COMPARE_PREFIX(prfm(PSTL2STRM, 0x3ffff), "prfm pstl2strm, pc+1048572");
1710 COMPARE_PREFIX(prfm(PSTL3KEEP, -0x3ffff), "prfm pstl3keep, pc-1048572");
1711 COMPARE_PREFIX(prfm(PSTL3STRM, -0x40000), "prfm pstl3strm, pc-1048576");
1712
1713 CLEANUP();
1714}
1715
1716
1717TEST(prfm_unscaled) {
1718 SETUP();
1719
1720 // If an unscaled-offset instruction is requested, it is used, even if the
1721 // offset could be encoded in a scaled-offset instruction.
1722 COMPARE(prfum(PLDL1KEEP, MemOperand(x1)), "prfum pldl1keep, [x1]");
1723 COMPARE(prfum(PLDL1STRM, MemOperand(x1, 8)), "prfum pldl1strm, [x1, #8]");
1724 COMPARE(prfum(PLDL2KEEP, MemOperand(x1, 248)), "prfum pldl2keep, [x1, #248]");
1725
1726 // Normal offsets are converted to unscaled offsets if necssary.
1727 COMPARE(prfm(PLDL2STRM, MemOperand(x1, 1)), "prfum pldl2strm, [x1, #1]");
1728 COMPARE(prfm(PLDL3KEEP, MemOperand(x1, -1)), "prfum pldl3keep, [x1, #-1]");
1729 COMPARE(prfm(PLDL3STRM, MemOperand(x1, 255)), "prfum pldl3strm, [x1, #255]");
1730 COMPARE(prfm(PLDL3STRM, MemOperand(x1, -256)),
1731 "prfum pldl3strm, [x1, #-256]");
1732
1733 CLEANUP();
1734}
1735
1736
1737TEST(prfm_unscaled_option) {
1738 SETUP();
1739
1740 // Just like prfm_unscaled, but specify the scaling option explicitly.
1741
1742 // Require unscaled-offset forms.
1743 LoadStoreScalingOption option = RequireUnscaledOffset;
1744
1745 COMPARE(prfum(PLDL1KEEP, MemOperand(x1), option), "prfum pldl1keep, [x1]");
1746 COMPARE(prfum(PLDL1STRM, MemOperand(x1, 8), option),
1747 "prfum pldl1strm, [x1, #8]");
1748 COMPARE(prfum(PLDL2KEEP, MemOperand(x1, 248), option),
1749 "prfum pldl2keep, [x1, #248]");
1750 COMPARE(prfum(PLDL2STRM, MemOperand(x1, 1), option),
1751 "prfum pldl2strm, [x1, #1]");
1752 COMPARE(prfum(PLDL3KEEP, MemOperand(x1, -1), option),
1753 "prfum pldl3keep, [x1, #-1]");
1754 COMPARE(prfum(PLDL3STRM, MemOperand(x1, 255), option),
1755 "prfum pldl3strm, [x1, #255]");
1756 COMPARE(prfum(PLIL1KEEP, MemOperand(x1, -256), option),
1757 "prfum plil1keep, [x1, #-256]");
1758
1759 // Require scaled-offset forms..
1760 option = RequireScaledOffset;
1761
1762 COMPARE(prfm(PLDL1KEEP, MemOperand(x1), option), "prfm pldl1keep, [x1]");
1763 COMPARE(prfm(PLDL1STRM, MemOperand(x1, 8), option),
1764 "prfm pldl1strm, [x1, #8]");
1765 COMPARE(prfm(PLDL2KEEP, MemOperand(x1, 248), option),
1766 "prfm pldl2keep, [x1, #248]");
1767 COMPARE(prfm(PLIL2STRM, MemOperand(x1, 256), option),
1768 "prfm plil2strm, [x1, #256]");
1769 COMPARE(prfm(PLIL3KEEP, MemOperand(x1, 32760), option),
1770 "prfm plil3keep, [x1, #32760]");
1771
1772 // Prefer unscaled-offset forms, but allow scaled-offset forms if necessary.
1773 option = PreferUnscaledOffset;
1774
1775 COMPARE(prfum(PLDL1KEEP, MemOperand(x1), option), "prfum pldl1keep, [x1]");
1776 COMPARE(prfum(PLDL1STRM, MemOperand(x1, 8), option),
1777 "prfum pldl1strm, [x1, #8]");
1778 COMPARE(prfum(PLDL2KEEP, MemOperand(x1, 248), option),
1779 "prfum pldl2keep, [x1, #248]");
1780 COMPARE(prfum(PLDL2STRM, MemOperand(x1, 1), option),
1781 "prfum pldl2strm, [x1, #1]");
1782 COMPARE(prfum(PLDL3KEEP, MemOperand(x1, -1), option),
1783 "prfum pldl3keep, [x1, #-1]");
1784 COMPARE(prfum(PLDL3STRM, MemOperand(x1, 255), option),
1785 "prfum pldl3strm, [x1, #255]");
1786 COMPARE(prfum(PLIL1KEEP, MemOperand(x1, -256), option),
1787 "prfum plil1keep, [x1, #-256]");
1788 COMPARE(prfum(PLIL1STRM, MemOperand(x1, 256), option),
1789 "prfm plil1strm, [x1, #256]");
1790 COMPARE(prfum(PLIL2KEEP, MemOperand(x1, 32760), option),
1791 "prfm plil2keep, [x1, #32760]");
1792
1793 // Prefer scaled-offset forms, but allow unscaled-offset forms if necessary.
1794 option = PreferScaledOffset;
1795
1796 COMPARE(prfm(PLDL1KEEP, MemOperand(x1), option), "prfm pldl1keep, [x1]");
1797 COMPARE(prfm(PLDL1STRM, MemOperand(x1, 8), option),
1798 "prfm pldl1strm, [x1, #8]");
1799 COMPARE(prfm(PLDL2KEEP, MemOperand(x1, 248), option),
1800 "prfm pldl2keep, [x1, #248]");
1801 COMPARE(prfm(PLDL2STRM, MemOperand(x1, 1), option),
1802 "prfum pldl2strm, [x1, #1]");
1803 COMPARE(prfm(PLDL3KEEP, MemOperand(x1, -1), option),
1804 "prfum pldl3keep, [x1, #-1]");
1805 COMPARE(prfm(PLDL3STRM, MemOperand(x1, 255), option),
1806 "prfum pldl3strm, [x1, #255]");
1807 COMPARE(prfm(PLIL1KEEP, MemOperand(x1, -256), option),
1808 "prfum plil1keep, [x1, #-256]");
1809 COMPARE(prfm(PLIL1STRM, MemOperand(x1, 256), option),
1810 "prfm plil1strm, [x1, #256]");
1811 COMPARE(prfm(PLIL2KEEP, MemOperand(x1, 32760), option),
1812 "prfm plil2keep, [x1, #32760]");
armvixlad96eda2013-06-14 11:42:37 +01001813
1814 CLEANUP();
1815}
1816
armvixl4a102ba2014-07-14 09:02:40 +01001817
armvixlad96eda2013-06-14 11:42:37 +01001818TEST(cond_select) {
1819 SETUP();
1820
1821 COMPARE(csel(w0, w1, w2, eq), "csel w0, w1, w2, eq");
1822 COMPARE(csel(x3, x4, x5, ne), "csel x3, x4, x5, ne");
1823 COMPARE(csinc(w6, w7, w8, hs), "csinc w6, w7, w8, hs");
1824 COMPARE(csinc(x9, x10, x11, lo), "csinc x9, x10, x11, lo");
1825 COMPARE(csinv(w12, w13, w14, mi), "csinv w12, w13, w14, mi");
1826 COMPARE(csinv(x15, x16, x17, pl), "csinv x15, x16, x17, pl");
1827 COMPARE(csneg(w18, w19, w20, vs), "csneg w18, w19, w20, vs");
1828 COMPARE(csneg(x21, x22, x23, vc), "csneg x21, x22, x23, vc");
1829 COMPARE(cset(w24, hi), "cset w24, hi");
1830 COMPARE(cset(x25, ls), "cset x25, ls");
1831 COMPARE(csetm(w26, ge), "csetm w26, ge");
1832 COMPARE(csetm(x27, lt), "csetm x27, lt");
1833 COMPARE(cinc(w28, w29, gt), "cinc w28, w29, gt");
1834 COMPARE(cinc(x30, x0, le), "cinc x30, x0, le");
1835 COMPARE(cinv(w1, w2, eq), "cinv w1, w2, eq");
1836 COMPARE(cinv(x3, x4, ne), "cinv x3, x4, ne");
1837 COMPARE(cneg(w5, w6, hs), "cneg w5, w6, hs");
1838 COMPARE(cneg(x7, x8, lo), "cneg x7, x8, lo");
1839
armvixl578645f2013-08-15 17:21:42 +01001840 COMPARE(csel(x0, x1, x2, al), "csel x0, x1, x2, al");
1841 COMPARE(csel(x1, x2, x3, nv), "csel x1, x2, x3, nv");
1842 COMPARE(csinc(x2, x3, x4, al), "csinc x2, x3, x4, al");
1843 COMPARE(csinc(x3, x4, x5, nv), "csinc x3, x4, x5, nv");
1844 COMPARE(csinv(x4, x5, x6, al), "csinv x4, x5, x6, al");
1845 COMPARE(csinv(x5, x6, x7, nv), "csinv x5, x6, x7, nv");
1846 COMPARE(csneg(x6, x7, x8, al), "csneg x6, x7, x8, al");
1847 COMPARE(csneg(x7, x8, x9, nv), "csneg x7, x8, x9, nv");
1848
armvixlad96eda2013-06-14 11:42:37 +01001849 CLEANUP();
1850}
1851
armvixl4a102ba2014-07-14 09:02:40 +01001852
armvixlf37fdc02014-02-05 13:22:16 +00001853TEST(cond_select_macro) {
1854 SETUP_CLASS(MacroAssembler);
1855
1856 COMPARE(Csel(w0, w1, -1, eq), "csinv w0, w1, wzr, eq");
1857 COMPARE(Csel(w2, w3, 0, ne), "csel w2, w3, wzr, ne");
1858 COMPARE(Csel(w4, w5, 1, hs), "csinc w4, w5, wzr, hs");
1859 COMPARE(Csel(x6, x7, -1, lo), "csinv x6, x7, xzr, lo");
1860 COMPARE(Csel(x8, x9, 0, mi), "csel x8, x9, xzr, mi");
1861 COMPARE(Csel(x10, x11, 1, pl), "csinc x10, x11, xzr, pl");
1862
1863 CLEANUP();
1864}
1865
armvixl4a102ba2014-07-14 09:02:40 +01001866
armvixlad96eda2013-06-14 11:42:37 +01001867TEST(cond_cmp) {
1868 SETUP();
1869
armvixl578645f2013-08-15 17:21:42 +01001870 COMPARE(ccmn(w0, w1, NZCVFlag, eq), "ccmn w0, w1, #NZCV, eq");
1871 COMPARE(ccmn(x2, x3, NZCFlag, ne), "ccmn x2, x3, #NZCv, ne");
1872 COMPARE(ccmp(w4, w5, NZVFlag, hs), "ccmp w4, w5, #NZcV, hs");
1873 COMPARE(ccmp(x6, x7, NZFlag, lo), "ccmp x6, x7, #NZcv, lo");
1874 COMPARE(ccmn(w8, 31, NFlag, mi), "ccmn w8, #31, #Nzcv, mi");
1875 COMPARE(ccmn(x9, 30, NCFlag, pl), "ccmn x9, #30, #NzCv, pl");
1876 COMPARE(ccmp(w10, 29, NVFlag, vs), "ccmp w10, #29, #NzcV, vs");
1877 COMPARE(ccmp(x11, 28, NFlag, vc), "ccmp x11, #28, #Nzcv, vc");
1878 COMPARE(ccmn(w12, w13, NoFlag, al), "ccmn w12, w13, #nzcv, al");
1879 COMPARE(ccmp(x14, 27, ZVFlag, nv), "ccmp x14, #27, #nZcV, nv");
armvixlad96eda2013-06-14 11:42:37 +01001880
1881 CLEANUP();
1882}
1883
armvixl4a102ba2014-07-14 09:02:40 +01001884
armvixlf37fdc02014-02-05 13:22:16 +00001885TEST(cond_cmp_macro) {
1886 SETUP_CLASS(MacroAssembler);
1887
1888 COMPARE(Ccmp(w0, -1, VFlag, hi), "ccmn w0, #1, #nzcV, hi");
1889 COMPARE(Ccmp(x1, -31, CFlag, ge), "ccmn x1, #31, #nzCv, ge");
1890 COMPARE(Ccmn(w2, -1, CVFlag, gt), "ccmp w2, #1, #nzCV, gt");
1891 COMPARE(Ccmn(x3, -31, ZCVFlag, ls), "ccmp x3, #31, #nZCV, ls");
1892
1893 CLEANUP();
1894}
1895
armvixl4a102ba2014-07-14 09:02:40 +01001896
armvixlad96eda2013-06-14 11:42:37 +01001897TEST(fmov_imm) {
1898 SETUP();
1899
armvixlb0c8ae22014-03-21 14:03:59 +00001900 COMPARE(fmov(s0, 1.0f), "fmov s0, #0x70 (1.0000)");
1901 COMPARE(fmov(s31, -13.0f), "fmov s31, #0xaa (-13.0000)");
armvixlad96eda2013-06-14 11:42:37 +01001902 COMPARE(fmov(d1, 1.0), "fmov d1, #0x70 (1.0000)");
1903 COMPARE(fmov(d29, -13.0), "fmov d29, #0xaa (-13.0000)");
1904
1905 CLEANUP();
1906}
1907
armvixl4a102ba2014-07-14 09:02:40 +01001908
armvixlad96eda2013-06-14 11:42:37 +01001909TEST(fmov_reg) {
1910 SETUP();
1911
1912 COMPARE(fmov(w3, s13), "fmov w3, s13");
1913 COMPARE(fmov(x6, d26), "fmov x6, d26");
1914 COMPARE(fmov(s11, w30), "fmov s11, w30");
1915 COMPARE(fmov(d31, x2), "fmov d31, x2");
1916 COMPARE(fmov(s12, s13), "fmov s12, s13");
1917 COMPARE(fmov(d22, d23), "fmov d22, d23");
1918
1919 CLEANUP();
1920}
1921
1922
1923TEST(fp_dp1) {
1924 SETUP();
1925
1926 COMPARE(fabs(s0, s1), "fabs s0, s1");
1927 COMPARE(fabs(s31, s30), "fabs s31, s30");
1928 COMPARE(fabs(d2, d3), "fabs d2, d3");
1929 COMPARE(fabs(d31, d30), "fabs d31, d30");
1930 COMPARE(fneg(s4, s5), "fneg s4, s5");
1931 COMPARE(fneg(s31, s30), "fneg s31, s30");
1932 COMPARE(fneg(d6, d7), "fneg d6, d7");
1933 COMPARE(fneg(d31, d30), "fneg d31, d30");
1934 COMPARE(fsqrt(s8, s9), "fsqrt s8, s9");
1935 COMPARE(fsqrt(s31, s30), "fsqrt s31, s30");
1936 COMPARE(fsqrt(d10, d11), "fsqrt d10, d11");
1937 COMPARE(fsqrt(d31, d30), "fsqrt d31, d30");
armvixlf37fdc02014-02-05 13:22:16 +00001938 COMPARE(frinta(s10, s11), "frinta s10, s11");
1939 COMPARE(frinta(s31, s30), "frinta s31, s30");
1940 COMPARE(frinta(d12, d13), "frinta d12, d13");
1941 COMPARE(frinta(d31, d30), "frinta d31, d30");
armvixl330dc712014-11-25 10:38:32 +00001942 COMPARE(frinti(s10, s11), "frinti s10, s11");
1943 COMPARE(frinti(s31, s30), "frinti s31, s30");
1944 COMPARE(frinti(d12, d13), "frinti d12, d13");
1945 COMPARE(frinti(d31, d30), "frinti d31, d30");
1946 COMPARE(frintm(s10, s11), "frintm s10, s11");
1947 COMPARE(frintm(s31, s30), "frintm s31, s30");
1948 COMPARE(frintm(d12, d13), "frintm d12, d13");
1949 COMPARE(frintm(d31, d30), "frintm d31, d30");
armvixlad96eda2013-06-14 11:42:37 +01001950 COMPARE(frintn(s10, s11), "frintn s10, s11");
1951 COMPARE(frintn(s31, s30), "frintn s31, s30");
1952 COMPARE(frintn(d12, d13), "frintn d12, d13");
1953 COMPARE(frintn(d31, d30), "frintn d31, d30");
armvixl330dc712014-11-25 10:38:32 +00001954 COMPARE(frintx(s10, s11), "frintx s10, s11");
1955 COMPARE(frintx(s31, s30), "frintx s31, s30");
1956 COMPARE(frintx(d12, d13), "frintx d12, d13");
1957 COMPARE(frintx(d31, d30), "frintx d31, d30");
armvixlad96eda2013-06-14 11:42:37 +01001958 COMPARE(frintz(s10, s11), "frintz s10, s11");
1959 COMPARE(frintz(s31, s30), "frintz s31, s30");
1960 COMPARE(frintz(d12, d13), "frintz d12, d13");
1961 COMPARE(frintz(d31, d30), "frintz d31, d30");
1962 COMPARE(fcvt(d14, s15), "fcvt d14, s15");
1963 COMPARE(fcvt(d31, s31), "fcvt d31, s31");
1964
1965 CLEANUP();
1966}
1967
1968
1969TEST(fp_dp2) {
1970 SETUP();
1971
1972 COMPARE(fadd(s0, s1, s2), "fadd s0, s1, s2");
1973 COMPARE(fadd(d3, d4, d5), "fadd d3, d4, d5");
1974 COMPARE(fsub(s31, s30, s29), "fsub s31, s30, s29");
1975 COMPARE(fsub(d31, d30, d29), "fsub d31, d30, d29");
1976 COMPARE(fmul(s7, s8, s9), "fmul s7, s8, s9");
1977 COMPARE(fmul(d10, d11, d12), "fmul d10, d11, d12");
1978 COMPARE(fdiv(s13, s14, s15), "fdiv s13, s14, s15");
1979 COMPARE(fdiv(d16, d17, d18), "fdiv d16, d17, d18");
1980 COMPARE(fmax(s19, s20, s21), "fmax s19, s20, s21");
1981 COMPARE(fmax(d22, d23, d24), "fmax d22, d23, d24");
1982 COMPARE(fmin(s25, s26, s27), "fmin s25, s26, s27");
1983 COMPARE(fmin(d28, d29, d30), "fmin d28, d29, d30");
armvixlf37fdc02014-02-05 13:22:16 +00001984 COMPARE(fmaxnm(s31, s0, s1), "fmaxnm s31, s0, s1");
1985 COMPARE(fmaxnm(d2, d3, d4), "fmaxnm d2, d3, d4");
1986 COMPARE(fminnm(s5, s6, s7), "fminnm s5, s6, s7");
1987 COMPARE(fminnm(d8, d9, d10), "fminnm d8, d9, d10");
armvixlad96eda2013-06-14 11:42:37 +01001988
1989 CLEANUP();
1990}
1991
1992
1993TEST(fp_dp3) {
1994 SETUP();
1995
armvixlf37fdc02014-02-05 13:22:16 +00001996 COMPARE(fmadd(s7, s8, s9, s10), "fmadd s7, s8, s9, s10");
1997 COMPARE(fmadd(d10, d11, d12, d10), "fmadd d10, d11, d12, d10");
armvixlad96eda2013-06-14 11:42:37 +01001998 COMPARE(fmsub(s7, s8, s9, s10), "fmsub s7, s8, s9, s10");
1999 COMPARE(fmsub(d10, d11, d12, d10), "fmsub d10, d11, d12, d10");
2000
armvixlf37fdc02014-02-05 13:22:16 +00002001 COMPARE(fnmadd(s7, s8, s9, s10), "fnmadd s7, s8, s9, s10");
2002 COMPARE(fnmadd(d10, d11, d12, d10), "fnmadd d10, d11, d12, d10");
2003 COMPARE(fnmsub(s7, s8, s9, s10), "fnmsub s7, s8, s9, s10");
2004 COMPARE(fnmsub(d10, d11, d12, d10), "fnmsub d10, d11, d12, d10");
2005
armvixlad96eda2013-06-14 11:42:37 +01002006 CLEANUP();
2007}
2008
2009
2010TEST(fp_compare) {
2011 SETUP();
2012
2013 COMPARE(fcmp(s0, s1), "fcmp s0, s1");
2014 COMPARE(fcmp(s31, s30), "fcmp s31, s30");
2015 COMPARE(fcmp(d0, d1), "fcmp d0, d1");
2016 COMPARE(fcmp(d31, d30), "fcmp d31, d30");
2017 COMPARE(fcmp(s12, 0), "fcmp s12, #0.0");
2018 COMPARE(fcmp(d12, 0), "fcmp d12, #0.0");
2019
2020 CLEANUP();
2021}
2022
2023
2024TEST(fp_cond_compare) {
2025 SETUP();
2026
2027 COMPARE(fccmp(s0, s1, NoFlag, eq), "fccmp s0, s1, #nzcv, eq");
2028 COMPARE(fccmp(s2, s3, ZVFlag, ne), "fccmp s2, s3, #nZcV, ne");
2029 COMPARE(fccmp(s30, s16, NCFlag, pl), "fccmp s30, s16, #NzCv, pl");
2030 COMPARE(fccmp(s31, s31, NZCVFlag, le), "fccmp s31, s31, #NZCV, le");
2031 COMPARE(fccmp(d4, d5, VFlag, gt), "fccmp d4, d5, #nzcV, gt");
2032 COMPARE(fccmp(d6, d7, NFlag, vs), "fccmp d6, d7, #Nzcv, vs");
2033 COMPARE(fccmp(d30, d0, NZFlag, vc), "fccmp d30, d0, #NZcv, vc");
2034 COMPARE(fccmp(d31, d31, ZFlag, hs), "fccmp d31, d31, #nZcv, hs");
armvixl578645f2013-08-15 17:21:42 +01002035 COMPARE(fccmp(s14, s15, CVFlag, al), "fccmp s14, s15, #nzCV, al");
2036 COMPARE(fccmp(d16, d17, CFlag, nv), "fccmp d16, d17, #nzCv, nv");
armvixlad96eda2013-06-14 11:42:37 +01002037
2038 CLEANUP();
2039}
2040
2041
2042TEST(fp_select) {
2043 SETUP();
2044
2045 COMPARE(fcsel(s0, s1, s2, eq), "fcsel s0, s1, s2, eq")
2046 COMPARE(fcsel(s31, s31, s30, ne), "fcsel s31, s31, s30, ne");
2047 COMPARE(fcsel(d0, d1, d2, mi), "fcsel d0, d1, d2, mi");
2048 COMPARE(fcsel(d31, d30, d31, pl), "fcsel d31, d30, d31, pl");
armvixl578645f2013-08-15 17:21:42 +01002049 COMPARE(fcsel(s14, s15, s16, al), "fcsel s14, s15, s16, al");
2050 COMPARE(fcsel(d17, d18, d19, nv), "fcsel d17, d18, d19, nv");
armvixlad96eda2013-06-14 11:42:37 +01002051
2052 CLEANUP();
2053}
2054
2055
2056TEST(fcvt_scvtf_ucvtf) {
2057 SETUP();
2058
armvixlf37fdc02014-02-05 13:22:16 +00002059 COMPARE(fcvtas(w0, s1), "fcvtas w0, s1");
2060 COMPARE(fcvtas(x2, s3), "fcvtas x2, s3");
2061 COMPARE(fcvtas(w4, d5), "fcvtas w4, d5");
2062 COMPARE(fcvtas(x6, d7), "fcvtas x6, d7");
2063 COMPARE(fcvtau(w8, s9), "fcvtau w8, s9");
2064 COMPARE(fcvtau(x10, s11), "fcvtau x10, s11");
2065 COMPARE(fcvtau(w12, d13), "fcvtau w12, d13");
2066 COMPARE(fcvtau(x14, d15), "fcvtau x14, d15");
armvixlad96eda2013-06-14 11:42:37 +01002067 COMPARE(fcvtns(w0, s1), "fcvtns w0, s1");
2068 COMPARE(fcvtns(x2, s3), "fcvtns x2, s3");
2069 COMPARE(fcvtns(w4, d5), "fcvtns w4, d5");
2070 COMPARE(fcvtns(x6, d7), "fcvtns x6, d7");
2071 COMPARE(fcvtnu(w8, s9), "fcvtnu w8, s9");
2072 COMPARE(fcvtnu(x10, s11), "fcvtnu x10, s11");
2073 COMPARE(fcvtnu(w12, d13), "fcvtnu w12, d13");
2074 COMPARE(fcvtnu(x14, d15), "fcvtnu x14, d15");
2075 COMPARE(fcvtzu(x16, d17), "fcvtzu x16, d17");
2076 COMPARE(fcvtzu(w18, d19), "fcvtzu w18, d19");
2077 COMPARE(fcvtzs(x20, d21), "fcvtzs x20, d21");
2078 COMPARE(fcvtzs(w22, d23), "fcvtzs w22, d23");
2079 COMPARE(fcvtzu(x16, s17), "fcvtzu x16, s17");
2080 COMPARE(fcvtzu(w18, s19), "fcvtzu w18, s19");
2081 COMPARE(fcvtzs(x20, s21), "fcvtzs x20, s21");
2082 COMPARE(fcvtzs(w22, s23), "fcvtzs w22, s23");
2083 COMPARE(scvtf(d24, w25), "scvtf d24, w25");
armvixl578645f2013-08-15 17:21:42 +01002084 COMPARE(scvtf(s24, w25), "scvtf s24, w25");
2085 COMPARE(scvtf(d26, x0), "scvtf d26, x0");
2086 COMPARE(scvtf(s26, x0), "scvtf s26, x0");
armvixlad96eda2013-06-14 11:42:37 +01002087 COMPARE(ucvtf(d28, w29), "ucvtf d28, w29");
armvixl578645f2013-08-15 17:21:42 +01002088 COMPARE(ucvtf(s28, w29), "ucvtf s28, w29");
armvixlad96eda2013-06-14 11:42:37 +01002089 COMPARE(ucvtf(d0, x1), "ucvtf d0, x1");
armvixl578645f2013-08-15 17:21:42 +01002090 COMPARE(ucvtf(s0, x1), "ucvtf s0, x1");
2091 COMPARE(ucvtf(d0, x1, 0), "ucvtf d0, x1");
2092 COMPARE(ucvtf(s0, x1, 0), "ucvtf s0, x1");
armvixlad96eda2013-06-14 11:42:37 +01002093 COMPARE(scvtf(d1, x2, 1), "scvtf d1, x2, #1");
armvixl578645f2013-08-15 17:21:42 +01002094 COMPARE(scvtf(s1, x2, 1), "scvtf s1, x2, #1");
armvixlad96eda2013-06-14 11:42:37 +01002095 COMPARE(scvtf(d3, x4, 15), "scvtf d3, x4, #15");
armvixl578645f2013-08-15 17:21:42 +01002096 COMPARE(scvtf(s3, x4, 15), "scvtf s3, x4, #15");
armvixlad96eda2013-06-14 11:42:37 +01002097 COMPARE(scvtf(d5, x6, 32), "scvtf d5, x6, #32");
armvixl578645f2013-08-15 17:21:42 +01002098 COMPARE(scvtf(s5, x6, 32), "scvtf s5, x6, #32");
armvixlad96eda2013-06-14 11:42:37 +01002099 COMPARE(ucvtf(d7, x8, 2), "ucvtf d7, x8, #2");
armvixl578645f2013-08-15 17:21:42 +01002100 COMPARE(ucvtf(s7, x8, 2), "ucvtf s7, x8, #2");
armvixlad96eda2013-06-14 11:42:37 +01002101 COMPARE(ucvtf(d9, x10, 16), "ucvtf d9, x10, #16");
armvixl578645f2013-08-15 17:21:42 +01002102 COMPARE(ucvtf(s9, x10, 16), "ucvtf s9, x10, #16");
armvixlad96eda2013-06-14 11:42:37 +01002103 COMPARE(ucvtf(d11, x12, 33), "ucvtf d11, x12, #33");
armvixl578645f2013-08-15 17:21:42 +01002104 COMPARE(ucvtf(s11, x12, 33), "ucvtf s11, x12, #33");
armvixlad96eda2013-06-14 11:42:37 +01002105 COMPARE(fcvtms(w0, s1), "fcvtms w0, s1");
2106 COMPARE(fcvtms(x2, s3), "fcvtms x2, s3");
2107 COMPARE(fcvtms(w4, d5), "fcvtms w4, d5");
2108 COMPARE(fcvtms(x6, d7), "fcvtms x6, d7");
2109 COMPARE(fcvtmu(w8, s9), "fcvtmu w8, s9");
2110 COMPARE(fcvtmu(x10, s11), "fcvtmu x10, s11");
2111 COMPARE(fcvtmu(w12, d13), "fcvtmu w12, d13");
2112 COMPARE(fcvtmu(x14, d15), "fcvtmu x14, d15");
2113
2114 CLEANUP();
2115}
2116
2117
armvixl4a102ba2014-07-14 09:02:40 +01002118TEST(system_clrex) {
2119 SETUP();
2120
2121 COMPARE(clrex(0), "clrex #0x0");
2122 COMPARE(clrex(14), "clrex #0xe");
2123 COMPARE(clrex(15), "clrex");
2124 COMPARE(clrex(), "clrex");
2125
2126 CLEANUP();
2127}
2128
2129
armvixlad96eda2013-06-14 11:42:37 +01002130TEST(system_mrs) {
2131 SETUP();
2132
2133 COMPARE(mrs(x0, NZCV), "mrs x0, nzcv");
2134 COMPARE(mrs(x30, NZCV), "mrs x30, nzcv");
armvixl578645f2013-08-15 17:21:42 +01002135 COMPARE(mrs(x15, FPCR), "mrs x15, fpcr");
armvixlad96eda2013-06-14 11:42:37 +01002136
2137 CLEANUP();
2138}
2139
2140
2141TEST(system_msr) {
2142 SETUP();
2143
2144 COMPARE(msr(NZCV, x0), "msr nzcv, x0");
2145 COMPARE(msr(NZCV, x30), "msr nzcv, x30");
armvixl578645f2013-08-15 17:21:42 +01002146 COMPARE(msr(FPCR, x15), "msr fpcr, x15");
armvixlad96eda2013-06-14 11:42:37 +01002147
2148 CLEANUP();
2149}
2150
2151
2152TEST(system_nop) {
2153 SETUP();
2154
2155 COMPARE(nop(), "nop");
2156
2157 CLEANUP();
2158}
2159
2160
2161TEST(unreachable) {
2162 SETUP_CLASS(MacroAssembler);
2163
2164#ifdef USE_SIMULATOR
armvixlb0c8ae22014-03-21 14:03:59 +00002165 VIXL_ASSERT(kUnreachableOpcode == 0xdeb0);
armvixlad96eda2013-06-14 11:42:37 +01002166 COMPARE(Unreachable(), "hlt #0xdeb0");
2167#else
2168 COMPARE(Unreachable(), "blr xzr");
2169#endif
2170
2171 CLEANUP();
2172}
2173
2174
2175#ifdef USE_SIMULATOR
2176TEST(trace) {
2177 SETUP_CLASS(MacroAssembler);
2178
armvixlb0c8ae22014-03-21 14:03:59 +00002179 VIXL_ASSERT(kTraceOpcode == 0xdeb2);
armvixlad96eda2013-06-14 11:42:37 +01002180
2181 // All Trace calls should produce the same instruction.
armvixlc68cb642014-09-25 18:49:30 +01002182 COMPARE_MACRO(Trace(LOG_ALL, TRACE_ENABLE), "hlt #0xdeb2");
2183 COMPARE_MACRO(Trace(LOG_REGS, TRACE_DISABLE), "hlt #0xdeb2");
armvixlad96eda2013-06-14 11:42:37 +01002184
2185 CLEANUP();
2186}
2187#endif
2188
2189
2190#ifdef USE_SIMULATOR
2191TEST(log) {
2192 SETUP_CLASS(MacroAssembler);
2193
armvixlb0c8ae22014-03-21 14:03:59 +00002194 VIXL_ASSERT(kLogOpcode == 0xdeb3);
armvixlad96eda2013-06-14 11:42:37 +01002195
2196 // All Log calls should produce the same instruction.
armvixlc68cb642014-09-25 18:49:30 +01002197 COMPARE_MACRO(Log(LOG_ALL), "hlt #0xdeb3");
2198 COMPARE_MACRO(Log(LOG_SYS_REGS), "hlt #0xdeb3");
armvixlad96eda2013-06-14 11:42:37 +01002199
2200 CLEANUP();
2201}
2202#endif
2203
2204
2205TEST(hlt) {
2206 SETUP();
2207
2208 COMPARE(hlt(0), "hlt #0x0");
2209 COMPARE(hlt(1), "hlt #0x1");
2210 COMPARE(hlt(65535), "hlt #0xffff");
2211
2212 CLEANUP();
2213}
2214
2215
2216TEST(brk) {
2217 SETUP();
2218
2219 COMPARE(brk(0), "brk #0x0");
2220 COMPARE(brk(1), "brk #0x1");
2221 COMPARE(brk(65535), "brk #0xffff");
2222
2223 CLEANUP();
2224}
2225
2226
2227TEST(add_sub_negative) {
2228 SETUP_CLASS(MacroAssembler);
2229
2230 COMPARE(Add(x10, x0, -42), "sub x10, x0, #0x2a (42)");
2231 COMPARE(Add(x11, x1, -687), "sub x11, x1, #0x2af (687)");
2232 COMPARE(Add(x12, x2, -0x88), "sub x12, x2, #0x88 (136)");
2233
2234 COMPARE(Sub(x13, x0, -600), "add x13, x0, #0x258 (600)");
2235 COMPARE(Sub(x14, x1, -313), "add x14, x1, #0x139 (313)");
2236 COMPARE(Sub(x15, x2, -0x555), "add x15, x2, #0x555 (1365)");
2237
2238 COMPARE(Add(w19, w3, -0x344), "sub w19, w3, #0x344 (836)");
2239 COMPARE(Add(w20, w4, -2000), "sub w20, w4, #0x7d0 (2000)");
2240
2241 COMPARE(Sub(w21, w3, -0xbc), "add w21, w3, #0xbc (188)");
2242 COMPARE(Sub(w22, w4, -2000), "add w22, w4, #0x7d0 (2000)");
2243
armvixlf37fdc02014-02-05 13:22:16 +00002244 COMPARE(Cmp(w0, -1), "cmn w0, #0x1 (1)");
2245 COMPARE(Cmp(x1, -1), "cmn x1, #0x1 (1)");
2246 COMPARE(Cmp(w2, -4095), "cmn w2, #0xfff (4095)");
2247 COMPARE(Cmp(x3, -4095), "cmn x3, #0xfff (4095)");
2248
2249 COMPARE(Cmn(w0, -1), "cmp w0, #0x1 (1)");
2250 COMPARE(Cmn(x1, -1), "cmp x1, #0x1 (1)");
2251 COMPARE(Cmn(w2, -4095), "cmp w2, #0xfff (4095)");
2252 COMPARE(Cmn(x3, -4095), "cmp x3, #0xfff (4095)");
2253
armvixlad96eda2013-06-14 11:42:37 +01002254 CLEANUP();
2255}
2256
2257
2258TEST(logical_immediate_move) {
2259 SETUP_CLASS(MacroAssembler);
2260
armvixl330dc712014-11-25 10:38:32 +00002261 COMPARE(And(w0, w1, 0), "mov w0, #0x0");
2262 COMPARE(And(x0, x1, 0), "mov x0, #0x0");
armvixlad96eda2013-06-14 11:42:37 +01002263 COMPARE(Orr(w2, w3, 0), "mov w2, w3");
2264 COMPARE(Orr(x2, x3, 0), "mov x2, x3");
2265 COMPARE(Eor(w4, w5, 0), "mov w4, w5");
2266 COMPARE(Eor(x4, x5, 0), "mov x4, x5");
2267 COMPARE(Bic(w6, w7, 0), "mov w6, w7");
2268 COMPARE(Bic(x6, x7, 0), "mov x6, x7");
armvixl330dc712014-11-25 10:38:32 +00002269 COMPARE(Orn(w8, w9, 0), "mov w8, #0xffffffff");
2270 COMPARE(Orn(x8, x9, 0), "mov x8, #0xffffffffffffffff");
armvixlad96eda2013-06-14 11:42:37 +01002271 COMPARE(Eon(w10, w11, 0), "mvn w10, w11");
2272 COMPARE(Eon(x10, x11, 0), "mvn x10, x11");
2273
2274 COMPARE(And(w12, w13, 0xffffffff), "mov w12, w13");
2275 COMPARE(And(x12, x13, 0xffffffff), "and x12, x13, #0xffffffff");
2276 COMPARE(And(x12, x13, 0xffffffffffffffff), "mov x12, x13");
armvixl330dc712014-11-25 10:38:32 +00002277 COMPARE(Orr(w14, w15, 0xffffffff), "mov w14, #0xffffffff");
armvixlad96eda2013-06-14 11:42:37 +01002278 COMPARE(Orr(x14, x15, 0xffffffff), "orr x14, x15, #0xffffffff");
armvixl330dc712014-11-25 10:38:32 +00002279 COMPARE(Orr(x14, x15, 0xffffffffffffffff), "mov x14, #0xffffffffffffffff");
armvixlad96eda2013-06-14 11:42:37 +01002280 COMPARE(Eor(w16, w17, 0xffffffff), "mvn w16, w17");
2281 COMPARE(Eor(x16, x17, 0xffffffff), "eor x16, x17, #0xffffffff");
2282 COMPARE(Eor(x16, x17, 0xffffffffffffffff), "mvn x16, x17");
armvixl330dc712014-11-25 10:38:32 +00002283 COMPARE(Bic(w18, w19, 0xffffffff), "mov w18, #0x0");
armvixlad96eda2013-06-14 11:42:37 +01002284 COMPARE(Bic(x18, x19, 0xffffffff), "and x18, x19, #0xffffffff00000000");
armvixl330dc712014-11-25 10:38:32 +00002285 COMPARE(Bic(x18, x19, 0xffffffffffffffff), "mov x18, #0x0");
armvixlad96eda2013-06-14 11:42:37 +01002286 COMPARE(Orn(w20, w21, 0xffffffff), "mov w20, w21");
2287 COMPARE(Orn(x20, x21, 0xffffffff), "orr x20, x21, #0xffffffff00000000");
2288 COMPARE(Orn(x20, x21, 0xffffffffffffffff), "mov x20, x21");
2289 COMPARE(Eon(w22, w23, 0xffffffff), "mov w22, w23");
2290 COMPARE(Eon(x22, x23, 0xffffffff), "eor x22, x23, #0xffffffff00000000");
2291 COMPARE(Eon(x22, x23, 0xffffffffffffffff), "mov x22, x23");
2292
2293 CLEANUP();
2294}
armvixlf37fdc02014-02-05 13:22:16 +00002295
armvixl4a102ba2014-07-14 09:02:40 +01002296
armvixlf37fdc02014-02-05 13:22:16 +00002297TEST(barriers) {
2298 SETUP_CLASS(MacroAssembler);
2299
2300 // DMB
2301 COMPARE(Dmb(FullSystem, BarrierAll), "dmb sy");
2302 COMPARE(Dmb(FullSystem, BarrierReads), "dmb ld");
2303 COMPARE(Dmb(FullSystem, BarrierWrites), "dmb st");
2304
2305 COMPARE(Dmb(InnerShareable, BarrierAll), "dmb ish");
2306 COMPARE(Dmb(InnerShareable, BarrierReads), "dmb ishld");
2307 COMPARE(Dmb(InnerShareable, BarrierWrites), "dmb ishst");
2308
2309 COMPARE(Dmb(NonShareable, BarrierAll), "dmb nsh");
2310 COMPARE(Dmb(NonShareable, BarrierReads), "dmb nshld");
2311 COMPARE(Dmb(NonShareable, BarrierWrites), "dmb nshst");
2312
2313 COMPARE(Dmb(OuterShareable, BarrierAll), "dmb osh");
2314 COMPARE(Dmb(OuterShareable, BarrierReads), "dmb oshld");
2315 COMPARE(Dmb(OuterShareable, BarrierWrites), "dmb oshst");
2316
2317 COMPARE(Dmb(FullSystem, BarrierOther), "dmb sy (0b1100)");
2318 COMPARE(Dmb(InnerShareable, BarrierOther), "dmb sy (0b1000)");
2319 COMPARE(Dmb(NonShareable, BarrierOther), "dmb sy (0b0100)");
2320 COMPARE(Dmb(OuterShareable, BarrierOther), "dmb sy (0b0000)");
2321
2322 // DSB
2323 COMPARE(Dsb(FullSystem, BarrierAll), "dsb sy");
2324 COMPARE(Dsb(FullSystem, BarrierReads), "dsb ld");
2325 COMPARE(Dsb(FullSystem, BarrierWrites), "dsb st");
2326
2327 COMPARE(Dsb(InnerShareable, BarrierAll), "dsb ish");
2328 COMPARE(Dsb(InnerShareable, BarrierReads), "dsb ishld");
2329 COMPARE(Dsb(InnerShareable, BarrierWrites), "dsb ishst");
2330
2331 COMPARE(Dsb(NonShareable, BarrierAll), "dsb nsh");
2332 COMPARE(Dsb(NonShareable, BarrierReads), "dsb nshld");
2333 COMPARE(Dsb(NonShareable, BarrierWrites), "dsb nshst");
2334
2335 COMPARE(Dsb(OuterShareable, BarrierAll), "dsb osh");
2336 COMPARE(Dsb(OuterShareable, BarrierReads), "dsb oshld");
2337 COMPARE(Dsb(OuterShareable, BarrierWrites), "dsb oshst");
2338
2339 COMPARE(Dsb(FullSystem, BarrierOther), "dsb sy (0b1100)");
2340 COMPARE(Dsb(InnerShareable, BarrierOther), "dsb sy (0b1000)");
2341 COMPARE(Dsb(NonShareable, BarrierOther), "dsb sy (0b0100)");
2342 COMPARE(Dsb(OuterShareable, BarrierOther), "dsb sy (0b0000)");
2343
2344 // ISB
2345 COMPARE(Isb(), "isb");
2346
2347 CLEANUP();
2348}
armvixl330dc712014-11-25 10:38:32 +00002349
2350
2351TEST(address_map) {
2352 // Check that we can disassemble from a fake base address.
2353 SETUP();
2354
2355 disasm->MapCodeAddress(0, reinterpret_cast<Instruction*>(buf));
2356 COMPARE(ldr(x0, 0), "ldr x0, pc+0 (addr 0x0)");
2357 COMPARE(ldr(x0, -1), "ldr x0, pc-4 (addr -0x4)");
2358 COMPARE(ldr(x0, 1), "ldr x0, pc+4 (addr 0x4)");
2359 COMPARE(prfm(PLIL1KEEP, 0), "prfm plil1keep, pc+0 (addr 0x0)");
2360 COMPARE(prfm(PLIL1KEEP, -1), "prfm plil1keep, pc-4 (addr -0x4)");
2361 COMPARE(prfm(PLIL1KEEP, 1), "prfm plil1keep, pc+4 (addr 0x4)");
2362 COMPARE(adr(x0, 0), "adr x0, #+0x0 (addr 0x0)");
2363 COMPARE(adr(x0, -1), "adr x0, #-0x1 (addr -0x1)");
2364 COMPARE(adr(x0, 1), "adr x0, #+0x1 (addr 0x1)");
2365 COMPARE(adrp(x0, 0), "adrp x0, #+0x0 (addr 0x0)");
2366 COMPARE(adrp(x0, -1), "adrp x0, #-0x1000 (addr -0x1000)");
2367 COMPARE(adrp(x0, 1), "adrp x0, #+0x1000 (addr 0x1000)");
2368 COMPARE(b(0), "b #+0x0 (addr 0x0)");
2369 COMPARE(b(-1), "b #-0x4 (addr -0x4)");
2370 COMPARE(b(1), "b #+0x4 (addr 0x4)");
2371
2372 disasm->MapCodeAddress(0x1234, reinterpret_cast<Instruction*>(buf));
2373 COMPARE(ldr(x0, 0), "ldr x0, pc+0 (addr 0x1234)");
2374 COMPARE(ldr(x0, -1), "ldr x0, pc-4 (addr 0x1230)");
2375 COMPARE(ldr(x0, 1), "ldr x0, pc+4 (addr 0x1238)");
2376 COMPARE(prfm(PLIL1KEEP, 0), "prfm plil1keep, pc+0 (addr 0x1234)");
2377 COMPARE(prfm(PLIL1KEEP, -1), "prfm plil1keep, pc-4 (addr 0x1230)");
2378 COMPARE(prfm(PLIL1KEEP, 1), "prfm plil1keep, pc+4 (addr 0x1238)");
2379 COMPARE(adr(x0, 0), "adr x0, #+0x0 (addr 0x1234)");
2380 COMPARE(adr(x0, -1), "adr x0, #-0x1 (addr 0x1233)");
2381 COMPARE(adr(x0, 1), "adr x0, #+0x1 (addr 0x1235)");
2382 COMPARE(adrp(x0, 0), "adrp x0, #+0x0 (addr 0x1000)");
2383 COMPARE(adrp(x0, -1), "adrp x0, #-0x1000 (addr 0x0)");
2384 COMPARE(adrp(x0, 1), "adrp x0, #+0x1000 (addr 0x2000)");
2385 COMPARE(b(0), "b #+0x0 (addr 0x1234)");
2386 COMPARE(b(-1), "b #-0x4 (addr 0x1230)");
2387 COMPARE(b(1), "b #+0x4 (addr 0x1238)");
2388
2389 // Check that 64-bit addresses work.
2390 disasm->MapCodeAddress(UINT64_C(0x100000000),
2391 reinterpret_cast<Instruction*>(buf));
2392 COMPARE(ldr(x0, 0), "ldr x0, pc+0 (addr 0x100000000)");
2393 COMPARE(ldr(x0, -1), "ldr x0, pc-4 (addr 0xfffffffc)");
2394 COMPARE(ldr(x0, 1), "ldr x0, pc+4 (addr 0x100000004)");
2395 COMPARE(prfm(PLIL1KEEP, 0), "prfm plil1keep, pc+0 (addr 0x100000000)");
2396 COMPARE(prfm(PLIL1KEEP, -1), "prfm plil1keep, pc-4 (addr 0xfffffffc)");
2397 COMPARE(prfm(PLIL1KEEP, 1), "prfm plil1keep, pc+4 (addr 0x100000004)");
2398 COMPARE(adr(x0, 0), "adr x0, #+0x0 (addr 0x100000000)");
2399 COMPARE(adr(x0, -1), "adr x0, #-0x1 (addr 0xffffffff)");
2400 COMPARE(adr(x0, 1), "adr x0, #+0x1 (addr 0x100000001)");
2401 COMPARE(adrp(x0, 0), "adrp x0, #+0x0 (addr 0x100000000)");
2402 COMPARE(adrp(x0, -1), "adrp x0, #-0x1000 (addr 0xfffff000)");
2403 COMPARE(adrp(x0, 1), "adrp x0, #+0x1000 (addr 0x100001000)");
2404 COMPARE(b(0), "b #+0x0 (addr 0x100000000)");
2405 COMPARE(b(-1), "b #-0x4 (addr 0xfffffffc)");
2406 COMPARE(b(1), "b #+0x4 (addr 0x100000004)");
2407
2408 disasm->MapCodeAddress(0xfffffffc, reinterpret_cast<Instruction*>(buf));
2409 COMPARE(ldr(x0, 1), "ldr x0, pc+4 (addr 0x100000000)");
2410 COMPARE(prfm(PLIL1KEEP, 1), "prfm plil1keep, pc+4 (addr 0x100000000)");
2411 COMPARE(b(1), "b #+0x4 (addr 0x100000000)");
2412 COMPARE(adr(x0, 4), "adr x0, #+0x4 (addr 0x100000000)");
2413 COMPARE(adrp(x0, 1), "adrp x0, #+0x1000 (addr 0x100000000)");
2414
2415 // Check that very large offsets are handled properly. This detects misuse of
2416 // the host's ptrdiff_t type when run on a 32-bit host. Only adrp is capable
2417 // of encoding such offsets.
2418 disasm->MapCodeAddress(0, reinterpret_cast<Instruction*>(buf));
2419 COMPARE(adrp(x0, 0x000fffff), "adrp x0, #+0xfffff000 (addr 0xfffff000)");
2420 COMPARE(adrp(x0, -0x00100000), "adrp x0, #-0x100000000 (addr -0x100000000)");
2421
2422 CLEANUP();
2423}
armvixlad96eda2013-06-14 11:42:37 +01002424} // namespace vixl