1 /*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "assembler_x86_64.h"
18
19 #include <inttypes.h>
20 #include <map>
21 #include <random>
22
23 #include "base/bit_utils.h"
24 #include "base/malloc_arena_pool.h"
25 #include "base/stl_util.h"
26 #include "jni_macro_assembler_x86_64.h"
27 #include "utils/assembler_test.h"
28 #include "utils/jni_macro_assembler_test.h"
29
30 namespace art {
31
TEST(AssemblerX86_64,CreateBuffer)32 TEST(AssemblerX86_64, CreateBuffer) {
33 MallocArenaPool pool;
34 ArenaAllocator allocator(&pool);
35 AssemblerBuffer buffer(&allocator);
36 AssemblerBuffer::EnsureCapacity ensured(&buffer);
37 buffer.Emit<uint8_t>(0x42);
38 ASSERT_EQ(static_cast<size_t>(1), buffer.Size());
39 buffer.Emit<int32_t>(42);
40 ASSERT_EQ(static_cast<size_t>(5), buffer.Size());
41 }
42
43 #ifdef ART_TARGET_ANDROID
44 static constexpr size_t kRandomIterations = 1000; // Devices might be puny, don't stress them...
45 #else
46 static constexpr size_t kRandomIterations = 100000; // Hosts are pretty powerful.
47 #endif
48
TEST(AssemblerX86_64,SignExtension)49 TEST(AssemblerX86_64, SignExtension) {
50 // 32bit.
51 for (int32_t i = 0; i < 128; i++) {
52 EXPECT_TRUE(IsInt<8>(i)) << i;
53 }
54 for (int32_t i = 128; i < 255; i++) {
55 EXPECT_FALSE(IsInt<8>(i)) << i;
56 }
57 // Do some higher ones randomly.
58 std::random_device rd;
59 std::default_random_engine e1(rd());
60 std::uniform_int_distribution<int32_t> uniform_dist(256, INT32_MAX);
61 for (size_t i = 0; i < kRandomIterations; i++) {
62 int32_t value = uniform_dist(e1);
63 EXPECT_FALSE(IsInt<8>(value)) << value;
64 }
65
66 // Negative ones.
67 for (int32_t i = -1; i >= -128; i--) {
68 EXPECT_TRUE(IsInt<8>(i)) << i;
69 }
70
71 for (int32_t i = -129; i > -256; i--) {
72 EXPECT_FALSE(IsInt<8>(i)) << i;
73 }
74
75 // Do some lower ones randomly.
76 std::uniform_int_distribution<int32_t> uniform_dist2(INT32_MIN, -256);
77 for (size_t i = 0; i < 100; i++) {
78 int32_t value = uniform_dist2(e1);
79 EXPECT_FALSE(IsInt<8>(value)) << value;
80 }
81
82 // 64bit.
83 for (int64_t i = 0; i < 128; i++) {
84 EXPECT_TRUE(IsInt<8>(i)) << i;
85 }
86 for (int32_t i = 128; i < 255; i++) {
87 EXPECT_FALSE(IsInt<8>(i)) << i;
88 }
89 // Do some higher ones randomly.
90 std::uniform_int_distribution<int64_t> uniform_dist3(256, INT64_MAX);
91 for (size_t i = 0; i < 100; i++) {
92 int64_t value = uniform_dist3(e1);
93 EXPECT_FALSE(IsInt<8>(value)) << value;
94 }
95
96 // Negative ones.
97 for (int64_t i = -1; i >= -128; i--) {
98 EXPECT_TRUE(IsInt<8>(i)) << i;
99 }
100
101 for (int64_t i = -129; i > -256; i--) {
102 EXPECT_FALSE(IsInt<8>(i)) << i;
103 }
104
105 // Do some lower ones randomly.
106 std::uniform_int_distribution<int64_t> uniform_dist4(INT64_MIN, -256);
107 for (size_t i = 0; i < kRandomIterations; i++) {
108 int64_t value = uniform_dist4(e1);
109 EXPECT_FALSE(IsInt<8>(value)) << value;
110 }
111
112 int64_t value = INT64_C(0x1200000010);
113 x86_64::Immediate imm(value);
114 EXPECT_FALSE(imm.is_int8());
115 EXPECT_FALSE(imm.is_int16());
116 EXPECT_FALSE(imm.is_int32());
117 value = INT64_C(0x8000000000000001);
118 x86_64::Immediate imm2(value);
119 EXPECT_FALSE(imm2.is_int8());
120 EXPECT_FALSE(imm2.is_int16());
121 EXPECT_FALSE(imm2.is_int32());
122 }
123
124 struct X86_64CpuRegisterCompare {
operator ()art::X86_64CpuRegisterCompare125 bool operator()(const x86_64::CpuRegister& a, const x86_64::CpuRegister& b) const {
126 return a.AsRegister() < b.AsRegister();
127 }
128 };
129
130 //
131 // Test fixture.
132 //
133
134 class AssemblerX86_64Test : public AssemblerTest<x86_64::X86_64Assembler,
135 x86_64::Address,
136 x86_64::CpuRegister,
137 x86_64::XmmRegister,
138 x86_64::Immediate> {
139 public:
140 using Base = AssemblerTest<x86_64::X86_64Assembler,
141 x86_64::Address,
142 x86_64::CpuRegister,
143 x86_64::XmmRegister,
144 x86_64::Immediate>;
145
146 protected:
147 // Get the typically used name for this architecture, e.g., aarch64, x86-64, ...
GetArchitectureString()148 std::string GetArchitectureString() override {
149 return "x86_64";
150 }
151
GetDisassembleParameters()152 std::string GetDisassembleParameters() override {
153 return " -D -bbinary -mi386:x86-64 -Mx86-64,addr64,data32 --no-show-raw-insn";
154 }
155
SetUpHelpers()156 void SetUpHelpers() override {
157 if (addresses_singleton_.size() == 0) {
158 // One addressing mode to test the repeat drivers.
159 addresses_singleton_.push_back(
160 x86_64::Address(x86_64::CpuRegister(x86_64::RAX),
161 x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_1, -1));
162 }
163
164 if (addresses_.size() == 0) {
165 // Several addressing modes.
166 addresses_.push_back(
167 x86_64::Address(x86_64::CpuRegister(x86_64::RDI),
168 x86_64::CpuRegister(x86_64::RAX), x86_64::TIMES_1, 15));
169 addresses_.push_back(
170 x86_64::Address(x86_64::CpuRegister(x86_64::RDI),
171 x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_2, 16));
172 addresses_.push_back(
173 x86_64::Address(x86_64::CpuRegister(x86_64::RDI),
174 x86_64::CpuRegister(x86_64::RCX), x86_64::TIMES_4, 17));
175 addresses_.push_back(
176 x86_64::Address(x86_64::CpuRegister(x86_64::RDI),
177 x86_64::CpuRegister(x86_64::RDX), x86_64::TIMES_8, 18));
178 addresses_.push_back(x86_64::Address(x86_64::CpuRegister(x86_64::RAX), -1));
179 addresses_.push_back(x86_64::Address(x86_64::CpuRegister(x86_64::RBX), 0));
180 addresses_.push_back(x86_64::Address(x86_64::CpuRegister(x86_64::RSI), 1));
181 addresses_.push_back(x86_64::Address(x86_64::CpuRegister(x86_64::RDI), 987654321));
182 // Several addressing modes with the special ESP.
183 addresses_.push_back(
184 x86_64::Address(x86_64::CpuRegister(x86_64::RSP),
185 x86_64::CpuRegister(x86_64::RAX), x86_64::TIMES_1, 15));
186 addresses_.push_back(
187 x86_64::Address(x86_64::CpuRegister(x86_64::RSP),
188 x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_2, 16));
189 addresses_.push_back(
190 x86_64::Address(x86_64::CpuRegister(x86_64::RSP),
191 x86_64::CpuRegister(x86_64::RCX), x86_64::TIMES_4, 17));
192 addresses_.push_back(
193 x86_64::Address(x86_64::CpuRegister(x86_64::RSP),
194 x86_64::CpuRegister(x86_64::RDX), x86_64::TIMES_8, 18));
195 addresses_.push_back(x86_64::Address(x86_64::CpuRegister(x86_64::RSP), -1));
196 addresses_.push_back(x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 0));
197 addresses_.push_back(x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 1));
198 addresses_.push_back(x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 987654321));
199 // Several addressing modes with the higher registers.
200 addresses_.push_back(
201 x86_64::Address(x86_64::CpuRegister(x86_64::R8),
202 x86_64::CpuRegister(x86_64::R15), x86_64::TIMES_2, -1));
203 addresses_.push_back(x86_64::Address(x86_64::CpuRegister(x86_64::R15), 123456789));
204 }
205
206 if (registers_.size() == 0) {
207 registers_.push_back(new x86_64::CpuRegister(x86_64::RAX));
208 registers_.push_back(new x86_64::CpuRegister(x86_64::RBX));
209 registers_.push_back(new x86_64::CpuRegister(x86_64::RCX));
210 registers_.push_back(new x86_64::CpuRegister(x86_64::RDX));
211 registers_.push_back(new x86_64::CpuRegister(x86_64::RBP));
212 registers_.push_back(new x86_64::CpuRegister(x86_64::RSP));
213 registers_.push_back(new x86_64::CpuRegister(x86_64::RSI));
214 registers_.push_back(new x86_64::CpuRegister(x86_64::RDI));
215 registers_.push_back(new x86_64::CpuRegister(x86_64::R8));
216 registers_.push_back(new x86_64::CpuRegister(x86_64::R9));
217 registers_.push_back(new x86_64::CpuRegister(x86_64::R10));
218 registers_.push_back(new x86_64::CpuRegister(x86_64::R11));
219 registers_.push_back(new x86_64::CpuRegister(x86_64::R12));
220 registers_.push_back(new x86_64::CpuRegister(x86_64::R13));
221 registers_.push_back(new x86_64::CpuRegister(x86_64::R14));
222 registers_.push_back(new x86_64::CpuRegister(x86_64::R15));
223
224 secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::RAX), "eax");
225 secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::RBX), "ebx");
226 secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::RCX), "ecx");
227 secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::RDX), "edx");
228 secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::RBP), "ebp");
229 secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::RSP), "esp");
230 secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::RSI), "esi");
231 secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::RDI), "edi");
232 secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::R8), "r8d");
233 secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::R9), "r9d");
234 secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::R10), "r10d");
235 secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::R11), "r11d");
236 secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::R12), "r12d");
237 secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::R13), "r13d");
238 secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::R14), "r14d");
239 secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::R15), "r15d");
240
241 tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::RAX), "ax");
242 tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::RBX), "bx");
243 tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::RCX), "cx");
244 tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::RDX), "dx");
245 tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::RBP), "bp");
246 tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::RSP), "sp");
247 tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::RSI), "si");
248 tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::RDI), "di");
249 tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::R8), "r8w");
250 tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::R9), "r9w");
251 tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::R10), "r10w");
252 tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::R11), "r11w");
253 tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::R12), "r12w");
254 tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::R13), "r13w");
255 tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::R14), "r14w");
256 tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::R15), "r15w");
257
258 quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::RAX), "al");
259 quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::RBX), "bl");
260 quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::RCX), "cl");
261 quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::RDX), "dl");
262 quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::RBP), "bpl");
263 quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::RSP), "spl");
264 quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::RSI), "sil");
265 quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::RDI), "dil");
266 quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::R8), "r8b");
267 quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::R9), "r9b");
268 quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::R10), "r10b");
269 quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::R11), "r11b");
270 quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::R12), "r12b");
271 quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::R13), "r13b");
272 quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::R14), "r14b");
273 quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::R15), "r15b");
274
275 fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM0));
276 fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM1));
277 fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM2));
278 fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM3));
279 fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM4));
280 fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM5));
281 fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM6));
282 fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM7));
283 fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM8));
284 fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM9));
285 fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM10));
286 fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM11));
287 fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM12));
288 fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM13));
289 fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM14));
290 fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM15));
291 }
292 }
293
TearDown()294 void TearDown() override {
295 AssemblerTest::TearDown();
296 STLDeleteElements(®isters_);
297 STLDeleteElements(&fp_registers_);
298 }
299
GetAddresses()300 std::vector<x86_64::Address> GetAddresses() override {
301 return addresses_;
302 }
303
GetRegisters()304 std::vector<x86_64::CpuRegister*> GetRegisters() override {
305 return registers_;
306 }
307
GetFPRegisters()308 std::vector<x86_64::XmmRegister*> GetFPRegisters() override {
309 return fp_registers_;
310 }
311
CreateImmediate(int64_t imm_value)312 x86_64::Immediate CreateImmediate(int64_t imm_value) override {
313 return x86_64::Immediate(imm_value);
314 }
315
GetSecondaryRegisterName(const x86_64::CpuRegister & reg)316 std::string GetSecondaryRegisterName(const x86_64::CpuRegister& reg) override {
317 CHECK(secondary_register_names_.find(reg) != secondary_register_names_.end());
318 return secondary_register_names_[reg];
319 }
320
GetTertiaryRegisterName(const x86_64::CpuRegister & reg)321 std::string GetTertiaryRegisterName(const x86_64::CpuRegister& reg) override {
322 CHECK(tertiary_register_names_.find(reg) != tertiary_register_names_.end());
323 return tertiary_register_names_[reg];
324 }
325
GetQuaternaryRegisterName(const x86_64::CpuRegister & reg)326 std::string GetQuaternaryRegisterName(const x86_64::CpuRegister& reg) override {
327 CHECK(quaternary_register_names_.find(reg) != quaternary_register_names_.end());
328 return quaternary_register_names_[reg];
329 }
330
331 std::vector<x86_64::Address> addresses_singleton_;
332
333 private:
334 std::vector<x86_64::Address> addresses_;
335 std::vector<x86_64::CpuRegister*> registers_;
336 std::map<x86_64::CpuRegister, std::string, X86_64CpuRegisterCompare> secondary_register_names_;
337 std::map<x86_64::CpuRegister, std::string, X86_64CpuRegisterCompare> tertiary_register_names_;
338 std::map<x86_64::CpuRegister, std::string, X86_64CpuRegisterCompare> quaternary_register_names_;
339 std::vector<x86_64::XmmRegister*> fp_registers_;
340 };
341
342 class AssemblerX86_64AVXTest : public AssemblerX86_64Test {
343 public:
AssemblerX86_64AVXTest()344 AssemblerX86_64AVXTest()
345 : instruction_set_features_(X86_64InstructionSetFeatures::FromVariant("kabylake", nullptr)) {}
346 protected:
CreateAssembler(ArenaAllocator * allocator)347 x86_64::X86_64Assembler* CreateAssembler(ArenaAllocator* allocator) override {
348 return new (allocator) x86_64::X86_64Assembler(allocator, instruction_set_features_.get());
349 }
350 private:
351 std::unique_ptr<const X86_64InstructionSetFeatures> instruction_set_features_;
352 };
353
354 //
355 // Test some repeat drivers used in the tests.
356 //
357
TEST_F(AssemblerX86_64Test,RepeatI4)358 TEST_F(AssemblerX86_64Test, RepeatI4) {
359 EXPECT_EQ("$0\n$-1\n$18\n$4660\n$-4660\n$305419896\n$-305419896\n",
360 RepeatI(/*f*/ nullptr, /*imm_bytes*/ 4U, "${imm}"));
361 }
362
TEST_F(AssemblerX86_64Test,RepeatI8)363 TEST_F(AssemblerX86_64Test, RepeatI8) {
364 EXPECT_EQ("$0\n$-1\n$18\n$4660\n$-4660\n$305419896\n$-305419896\n"
365 "$20015998343868\n$-20015998343868\n$1311768467463790320\n"
366 "$-1311768467463790320\n",
367 RepeatI(/*f*/ nullptr, /*imm_bytes*/ 8U, "${imm}"));
368 }
369
TEST_F(AssemblerX86_64Test,Repeatr)370 TEST_F(AssemblerX86_64Test, Repeatr) {
371 EXPECT_EQ("%eax\n%ebx\n%ecx\n%edx\n%ebp\n%esp\n%esi\n%edi\n"
372 "%r8d\n%r9d\n%r10d\n%r11d\n%r12d\n%r13d\n%r14d\n%r15d\n",
373 Repeatr(/*f*/ nullptr, "%{reg}"));
374 }
375
TEST_F(AssemblerX86_64Test,RepeatrI)376 TEST_F(AssemblerX86_64Test, RepeatrI) {
377 EXPECT_NE(RepeatrI(/*f*/ nullptr, /*imm_bytes*/ 1U, "%{reg} ${imm}").
378 find("%eax $0\n%eax $-1\n%eax $18\n%ebx $0\n%ebx $-1\n%ebx $18\n"
379 "%ecx $0\n%ecx $-1\n%ecx $18\n%edx $0\n%edx $-1\n%edx $18\n"),
380 std::string::npos);
381 }
382
TEST_F(AssemblerX86_64Test,Repeatrr)383 TEST_F(AssemblerX86_64Test, Repeatrr) {
384 EXPECT_NE(Repeatrr(/*f*/ nullptr, "%{reg1} %{reg2}")
385 .find("%eax %eax\n%eax %ebx\n%eax %ecx\n%eax %edx\n"
386 "%eax %ebp\n%eax %esp\n%eax %esi\n%eax %edi\n"),
387 std::string::npos);
388 }
389
TEST_F(AssemblerX86_64Test,Repeatrb)390 TEST_F(AssemblerX86_64Test, Repeatrb) {
391 EXPECT_NE(Repeatrb(/*f*/ nullptr, "%{reg1} %{reg2}").
392 find("%eax %al\n%eax %bl\n%eax %cl\n%eax %dl\n%eax %bpl\n"
393 "%eax %spl\n%eax %sil\n%eax %dil\n%eax %r8b\n%eax %r9b\n"),
394 std::string::npos);
395 }
396
TEST_F(AssemblerX86_64Test,RepeatrF)397 TEST_F(AssemblerX86_64Test, RepeatrF) {
398 EXPECT_NE(RepeatrF(/*f*/ nullptr, "%{reg1} %{reg2}")
399 .find("%eax %xmm0\n%eax %xmm1\n%eax %xmm2\n%eax %xmm3\n"
400 "%eax %xmm4\n%eax %xmm5\n%eax %xmm6\n%eax %xmm7\n"),
401 std::string::npos);
402 }
403
TEST_F(AssemblerX86_64Test,RepeatR)404 TEST_F(AssemblerX86_64Test, RepeatR) {
405 EXPECT_EQ("%rax\n%rbx\n%rcx\n%rdx\n%rbp\n%rsp\n%rsi\n%rdi\n"
406 "%r8\n%r9\n%r10\n%r11\n%r12\n%r13\n%r14\n%r15\n",
407 RepeatR(/*f*/ nullptr, "%{reg}"));
408 }
409
TEST_F(AssemblerX86_64Test,RepeatRI)410 TEST_F(AssemblerX86_64Test, RepeatRI) {
411 EXPECT_NE(RepeatRI(/*f*/ nullptr, /*imm_bytes*/ 1U, "%{reg} ${imm}")
412 .find("%rax $0\n%rax $-1\n%rax $18\n%rbx $0\n%rbx $-1\n%rbx $18\n"
413 "%rcx $0\n%rcx $-1\n%rcx $18\n%rdx $0\n%rdx $-1\n%rdx $18\n"),
414 std::string::npos);
415 }
416
TEST_F(AssemblerX86_64Test,RepeatRr)417 TEST_F(AssemblerX86_64Test, RepeatRr) {
418 EXPECT_NE(RepeatRr(/*f*/ nullptr, "%{reg1} %{reg2}")
419 .find("%rax %eax\n%rax %ebx\n%rax %ecx\n%rax %edx\n%rax %ebp\n"
420 "%rax %esp\n%rax %esi\n%rax %edi\n%rax %r8d\n%rax %r9d\n"),
421 std::string::npos);
422 }
423
TEST_F(AssemblerX86_64Test,RepeatRR)424 TEST_F(AssemblerX86_64Test, RepeatRR) {
425 EXPECT_NE(RepeatRR(/*f*/ nullptr, "%{reg1} %{reg2}")
426 .find("%rax %rax\n%rax %rbx\n%rax %rcx\n%rax %rdx\n%rax %rbp\n"
427 "%rax %rsp\n%rax %rsi\n%rax %rdi\n%rax %r8\n%rax %r9\n"),
428 std::string::npos);
429 }
430
TEST_F(AssemblerX86_64Test,RepeatRF)431 TEST_F(AssemblerX86_64Test, RepeatRF) {
432 EXPECT_NE(RepeatRF(/*f*/ nullptr, "%{reg1} %{reg2}")
433 .find("%rax %xmm0\n%rax %xmm1\n%rax %xmm2\n%rax %xmm3\n%rax %xmm4\n"
434 "%rax %xmm5\n%rax %xmm6\n%rax %xmm7\n%rax %xmm8\n%rax %xmm9\n"),
435 std::string::npos);
436 }
437
TEST_F(AssemblerX86_64Test,RepeatFF)438 TEST_F(AssemblerX86_64Test, RepeatFF) {
439 EXPECT_NE(RepeatFF(/*f*/ nullptr, "%{reg1} %{reg2}")
440 .find("%xmm0 %xmm0\n%xmm0 %xmm1\n%xmm0 %xmm2\n%xmm0 %xmm3\n%xmm0 %xmm4\n"
441 "%xmm0 %xmm5\n%xmm0 %xmm6\n%xmm0 %xmm7\n%xmm0 %xmm8\n%xmm0 %xmm9\n"),
442 std::string::npos);
443 }
444
TEST_F(AssemblerX86_64Test,RepeatFFI)445 TEST_F(AssemblerX86_64Test, RepeatFFI) {
446 EXPECT_NE(RepeatFFI(/*f*/ nullptr, /*imm_bytes*/ 1U, "%{reg1} %{reg2} ${imm}")
447 .find("%xmm0 %xmm0 $0\n%xmm0 %xmm0 $-1\n%xmm0 %xmm0 $18\n"
448 "%xmm0 %xmm1 $0\n%xmm0 %xmm1 $-1\n%xmm0 %xmm1 $18\n"),
449 std::string::npos);
450 }
451
TEST_F(AssemblerX86_64Test,RepeatA)452 TEST_F(AssemblerX86_64Test, RepeatA) {
453 EXPECT_EQ("-1(%rax,%rbx,1)\n", RepeatA(/*f*/ nullptr, addresses_singleton_, "{mem}"));
454 }
455
TEST_F(AssemblerX86_64Test,RepeatAFull)456 TEST_F(AssemblerX86_64Test, RepeatAFull) {
457 EXPECT_EQ("15(%rdi,%rax,1)\n16(%rdi,%rbx,2)\n17(%rdi,%rcx,4)\n18(%rdi,%rdx,8)\n"
458 "-1(%rax)\n(%rbx)\n1(%rsi)\n987654321(%rdi)\n15(%rsp,%rax,1)\n"
459 "16(%rsp,%rbx,2)\n17(%rsp,%rcx,4)\n18(%rsp,%rdx,8)\n-1(%rsp)\n"
460 "(%rsp)\n1(%rsp)\n987654321(%rsp)\n-1(%r8,%r15,2)\n123456789(%r15)\n",
461 RepeatA(/*f*/ nullptr, "{mem}"));
462 }
463
TEST_F(AssemblerX86_64Test,RepeatAI)464 TEST_F(AssemblerX86_64Test, RepeatAI) {
465 EXPECT_EQ("-1(%rax,%rbx,1) $0\n-1(%rax,%rbx,1) $-1\n-1(%rax,%rbx,1) $18\n",
466 RepeatAI(/*f*/ nullptr, /*imm_bytes*/ 1U, addresses_singleton_, "{mem} ${imm}"));
467 }
468
TEST_F(AssemblerX86_64Test,RepeatRA)469 TEST_F(AssemblerX86_64Test, RepeatRA) {
470 EXPECT_NE(RepeatRA(/*f*/ nullptr, addresses_singleton_, "%{reg} {mem}")
471 .find("%rax -1(%rax,%rbx,1)\n%rbx -1(%rax,%rbx,1)\n%rcx -1(%rax,%rbx,1)\n"
472 "%rdx -1(%rax,%rbx,1)\n%rbp -1(%rax,%rbx,1)\n%rsp -1(%rax,%rbx,1)\n"),
473 std::string::npos);
474 }
475
TEST_F(AssemblerX86_64Test,RepeatrA)476 TEST_F(AssemblerX86_64Test, RepeatrA) {
477 EXPECT_NE(RepeatrA(/*f*/ nullptr, addresses_singleton_, "%{reg} {mem}")
478 .find("%eax -1(%rax,%rbx,1)\n%ebx -1(%rax,%rbx,1)\n%ecx -1(%rax,%rbx,1)\n"
479 "%edx -1(%rax,%rbx,1)\n%ebp -1(%rax,%rbx,1)\n%esp -1(%rax,%rbx,1)\n"),
480 std::string::npos);
481 }
482
TEST_F(AssemblerX86_64Test,RepeatAR)483 TEST_F(AssemblerX86_64Test, RepeatAR) {
484 EXPECT_NE(RepeatAR(/*f*/ nullptr, addresses_singleton_, "{mem} %{reg}")
485 .find("-1(%rax,%rbx,1) %rax\n-1(%rax,%rbx,1) %rbx\n-1(%rax,%rbx,1) %rcx\n"
486 "-1(%rax,%rbx,1) %rdx\n-1(%rax,%rbx,1) %rbp\n-1(%rax,%rbx,1) %rsp\n"),
487 std::string::npos);
488 }
489
TEST_F(AssemblerX86_64Test,RepeatAr)490 TEST_F(AssemblerX86_64Test, RepeatAr) {
491 EXPECT_NE(RepeatAr(/*f*/ nullptr, addresses_singleton_, "{mem} %{reg}")
492 .find("-1(%rax,%rbx,1) %eax\n-1(%rax,%rbx,1) %ebx\n-1(%rax,%rbx,1) %ecx\n"
493 "-1(%rax,%rbx,1) %edx\n-1(%rax,%rbx,1) %ebp\n-1(%rax,%rbx,1) %esp\n"),
494 std::string::npos);
495 }
496
TEST_F(AssemblerX86_64Test,RepeatFA)497 TEST_F(AssemblerX86_64Test, RepeatFA) {
498 EXPECT_NE(RepeatFA(/*f*/ nullptr, addresses_singleton_, "%{reg} {mem}").
499 find("%xmm0 -1(%rax,%rbx,1)\n%xmm1 -1(%rax,%rbx,1)\n%xmm2 -1(%rax,%rbx,1)\n"
500 "%xmm3 -1(%rax,%rbx,1)\n%xmm4 -1(%rax,%rbx,1)\n%xmm5 -1(%rax,%rbx,1)\n"),
501 std::string::npos);
502 }
503
TEST_F(AssemblerX86_64Test,RepeatAF)504 TEST_F(AssemblerX86_64Test, RepeatAF) {
505 EXPECT_NE(RepeatAF(/*f*/ nullptr, addresses_singleton_, "{mem} %{reg}")
506 .find("-1(%rax,%rbx,1) %xmm0\n-1(%rax,%rbx,1) %xmm1\n-1(%rax,%rbx,1) %xmm2\n"
507 "-1(%rax,%rbx,1) %xmm3\n-1(%rax,%rbx,1) %xmm4\n-1(%rax,%rbx,1) %xmm5\n"),
508 std::string::npos);
509 }
510
511 //
512 // Actual x86-64 instruction assembler tests.
513 //
514
TEST_F(AssemblerX86_64Test,Toolchain)515 TEST_F(AssemblerX86_64Test, Toolchain) {
516 EXPECT_TRUE(CheckTools());
517 }
518
TEST_F(AssemblerX86_64Test,PopqAllAddresses)519 TEST_F(AssemblerX86_64Test, PopqAllAddresses) {
520 // Make sure all addressing modes combinations are tested at least once.
521 std::vector<x86_64::Address> all_addresses;
522 for (x86_64::CpuRegister* base : GetRegisters()) {
523 // Base only.
524 all_addresses.push_back(x86_64::Address(*base, -1));
525 all_addresses.push_back(x86_64::Address(*base, 0));
526 all_addresses.push_back(x86_64::Address(*base, 1));
527 all_addresses.push_back(x86_64::Address(*base, 123456789));
528 for (x86_64::CpuRegister* index : GetRegisters()) {
529 if (index->AsRegister() == x86_64::RSP) {
530 // Index cannot be RSP.
531 continue;
532 } else if (base->AsRegister() == index->AsRegister()) {
533 // Index only.
534 all_addresses.push_back(x86_64::Address(*index, x86_64::TIMES_1, -1));
535 all_addresses.push_back(x86_64::Address(*index, x86_64::TIMES_2, 0));
536 all_addresses.push_back(x86_64::Address(*index, x86_64::TIMES_4, 1));
537 all_addresses.push_back(x86_64::Address(*index, x86_64::TIMES_8, 123456789));
538 }
539 // Base and index.
540 all_addresses.push_back(x86_64::Address(*base, *index, x86_64::TIMES_1, -1));
541 all_addresses.push_back(x86_64::Address(*base, *index, x86_64::TIMES_2, 0));
542 all_addresses.push_back(x86_64::Address(*base, *index, x86_64::TIMES_4, 1));
543 all_addresses.push_back(x86_64::Address(*base, *index, x86_64::TIMES_8, 123456789));
544 }
545 }
546 DriverStr(RepeatA(&x86_64::X86_64Assembler::popq, all_addresses, "popq {mem}"), "popq");
547 }
548
TEST_F(AssemblerX86_64Test,PushqRegs)549 TEST_F(AssemblerX86_64Test, PushqRegs) {
550 DriverStr(RepeatR(&x86_64::X86_64Assembler::pushq, "pushq %{reg}"), "pushq");
551 }
552
TEST_F(AssemblerX86_64Test,PushqImm)553 TEST_F(AssemblerX86_64Test, PushqImm) {
554 DriverStr(RepeatI(&x86_64::X86_64Assembler::pushq, /*imm_bytes*/ 4U,
555 "pushq ${imm}"), "pushqi");
556 }
557
TEST_F(AssemblerX86_64Test,MovqRegs)558 TEST_F(AssemblerX86_64Test, MovqRegs) {
559 DriverStr(RepeatRR(&x86_64::X86_64Assembler::movq, "movq %{reg2}, %{reg1}"), "movq");
560 }
561
TEST_F(AssemblerX86_64Test,MovqImm)562 TEST_F(AssemblerX86_64Test, MovqImm) {
563 DriverStr(RepeatRI(&x86_64::X86_64Assembler::movq, /*imm_bytes*/ 8U,
564 "movq ${imm}, %{reg}"), "movqi");
565 }
566
TEST_F(AssemblerX86_64Test,MovlRegs)567 TEST_F(AssemblerX86_64Test, MovlRegs) {
568 DriverStr(Repeatrr(&x86_64::X86_64Assembler::movl, "mov %{reg2}, %{reg1}"), "movl");
569 }
570
TEST_F(AssemblerX86_64Test,MovlImm)571 TEST_F(AssemblerX86_64Test, MovlImm) {
572 DriverStr(RepeatrI(&x86_64::X86_64Assembler::movl, /*imm_bytes*/ 4U,
573 "mov ${imm}, %{reg}"), "movli");
574 }
575
TEST_F(AssemblerX86_64Test,AddqRegs)576 TEST_F(AssemblerX86_64Test, AddqRegs) {
577 DriverStr(RepeatRR(&x86_64::X86_64Assembler::addq, "addq %{reg2}, %{reg1}"), "addq");
578 }
579
TEST_F(AssemblerX86_64Test,AddqImm)580 TEST_F(AssemblerX86_64Test, AddqImm) {
581 DriverStr(RepeatRI(&x86_64::X86_64Assembler::addq, /*imm_bytes*/ 4U,
582 "addq ${imm}, %{reg}"), "addqi");
583 }
584
TEST_F(AssemblerX86_64Test,AddlRegs)585 TEST_F(AssemblerX86_64Test, AddlRegs) {
586 DriverStr(Repeatrr(&x86_64::X86_64Assembler::addl, "add %{reg2}, %{reg1}"), "addl");
587 }
588
TEST_F(AssemblerX86_64Test,AddlImm)589 TEST_F(AssemblerX86_64Test, AddlImm) {
590 DriverStr(RepeatrI(&x86_64::X86_64Assembler::addl, /*imm_bytes*/ 4U,
591 "add ${imm}, %{reg}"), "addli");
592 }
593
TEST_F(AssemblerX86_64Test,Addw)594 TEST_F(AssemblerX86_64Test, Addw) {
595 DriverStr(
596 RepeatAI(&x86_64::X86_64Assembler::addw, /*imm_bytes*/2U, "addw ${imm}, {mem}"), "addw");
597 }
598
TEST_F(AssemblerX86_64Test,ImulqReg1)599 TEST_F(AssemblerX86_64Test, ImulqReg1) {
600 DriverStr(RepeatR(&x86_64::X86_64Assembler::imulq, "imulq %{reg}"), "imulq");
601 }
602
TEST_F(AssemblerX86_64Test,ImulqRegs)603 TEST_F(AssemblerX86_64Test, ImulqRegs) {
604 DriverStr(RepeatRR(&x86_64::X86_64Assembler::imulq, "imulq %{reg2}, %{reg1}"), "imulq");
605 }
606
TEST_F(AssemblerX86_64Test,ImulqImm)607 TEST_F(AssemblerX86_64Test, ImulqImm) {
608 DriverStr(RepeatRI(&x86_64::X86_64Assembler::imulq, /*imm_bytes*/ 4U,
609 "imulq ${imm}, %{reg}, %{reg}"),
610 "imulqi");
611 }
612
TEST_F(AssemblerX86_64Test,ImullRegs)613 TEST_F(AssemblerX86_64Test, ImullRegs) {
614 DriverStr(Repeatrr(&x86_64::X86_64Assembler::imull, "imul %{reg2}, %{reg1}"), "imull");
615 }
616
TEST_F(AssemblerX86_64Test,ImullImm)617 TEST_F(AssemblerX86_64Test, ImullImm) {
618 DriverStr(RepeatrI(&x86_64::X86_64Assembler::imull, /*imm_bytes*/ 4U,
619 "imull ${imm}, %{reg}, %{reg}"),
620 "imulli");
621 }
622
TEST_F(AssemblerX86_64Test,Mull)623 TEST_F(AssemblerX86_64Test, Mull) {
624 DriverStr(Repeatr(&x86_64::X86_64Assembler::mull, "mull %{reg}"), "mull");
625 }
626
TEST_F(AssemblerX86_64Test,SubqRegs)627 TEST_F(AssemblerX86_64Test, SubqRegs) {
628 DriverStr(RepeatRR(&x86_64::X86_64Assembler::subq, "subq %{reg2}, %{reg1}"), "subq");
629 }
630
TEST_F(AssemblerX86_64Test,SubqImm)631 TEST_F(AssemblerX86_64Test, SubqImm) {
632 DriverStr(RepeatRI(&x86_64::X86_64Assembler::subq, /*imm_bytes*/ 4U,
633 "subq ${imm}, %{reg}"), "subqi");
634 }
635
TEST_F(AssemblerX86_64Test,SublRegs)636 TEST_F(AssemblerX86_64Test, SublRegs) {
637 DriverStr(Repeatrr(&x86_64::X86_64Assembler::subl, "sub %{reg2}, %{reg1}"), "subl");
638 }
639
TEST_F(AssemblerX86_64Test,SublImm)640 TEST_F(AssemblerX86_64Test, SublImm) {
641 DriverStr(RepeatrI(&x86_64::X86_64Assembler::subl, /*imm_bytes*/ 4U,
642 "sub ${imm}, %{reg}"), "subli");
643 }
644
645 // Shll only allows CL as the shift count.
shll_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)646 std::string shll_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
647 std::ostringstream str;
648 std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
649 x86_64::CpuRegister shifter(x86_64::RCX);
650 for (auto reg : registers) {
651 assembler->shll(*reg, shifter);
652 str << "shll %cl, %" << assembler_test->GetSecondaryRegisterName(*reg) << "\n";
653 }
654 return str.str();
655 }
656
TEST_F(AssemblerX86_64Test,ShllReg)657 TEST_F(AssemblerX86_64Test, ShllReg) {
658 DriverFn(&shll_fn, "shll");
659 }
660
TEST_F(AssemblerX86_64Test,ShllImm)661 TEST_F(AssemblerX86_64Test, ShllImm) {
662 DriverStr(RepeatrI(&x86_64::X86_64Assembler::shll, /*imm_bytes*/ 1U,
663 "shll ${imm}, %{reg}"), "shlli");
664 }
665
666 // Shlq only allows CL as the shift count.
shlq_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)667 std::string shlq_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
668 std::ostringstream str;
669 std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
670 x86_64::CpuRegister shifter(x86_64::RCX);
671 for (auto reg : registers) {
672 assembler->shlq(*reg, shifter);
673 str << "shlq %cl, %" << assembler_test->GetRegisterName(*reg) << "\n";
674 }
675 return str.str();
676 }
677
TEST_F(AssemblerX86_64Test,ShlqReg)678 TEST_F(AssemblerX86_64Test, ShlqReg) {
679 DriverFn(&shlq_fn, "shlq");
680 }
681
TEST_F(AssemblerX86_64Test,ShlqImm)682 TEST_F(AssemblerX86_64Test, ShlqImm) {
683 DriverStr(RepeatRI(&x86_64::X86_64Assembler::shlq, /*imm_bytes*/ 1U,
684 "shlq ${imm}, %{reg}"), "shlqi");
685 }
686
687 // Shrl only allows CL as the shift count.
shrl_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)688 std::string shrl_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
689 std::ostringstream str;
690 std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
691 x86_64::CpuRegister shifter(x86_64::RCX);
692 for (auto reg : registers) {
693 assembler->shrl(*reg, shifter);
694 str << "shrl %cl, %" << assembler_test->GetSecondaryRegisterName(*reg) << "\n";
695 }
696 return str.str();
697 }
698
TEST_F(AssemblerX86_64Test,ShrlReg)699 TEST_F(AssemblerX86_64Test, ShrlReg) {
700 DriverFn(&shrl_fn, "shrl");
701 }
702
TEST_F(AssemblerX86_64Test,ShrlImm)703 TEST_F(AssemblerX86_64Test, ShrlImm) {
704 DriverStr(RepeatrI(&x86_64::X86_64Assembler::shrl, /*imm_bytes*/ 1U, "shrl ${imm}, %{reg}"), "shrli");
705 }
706
707 // Shrq only allows CL as the shift count.
shrq_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)708 std::string shrq_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
709 std::ostringstream str;
710 std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
711 x86_64::CpuRegister shifter(x86_64::RCX);
712 for (auto reg : registers) {
713 assembler->shrq(*reg, shifter);
714 str << "shrq %cl, %" << assembler_test->GetRegisterName(*reg) << "\n";
715 }
716 return str.str();
717 }
718
TEST_F(AssemblerX86_64Test,ShrqReg)719 TEST_F(AssemblerX86_64Test, ShrqReg) {
720 DriverFn(&shrq_fn, "shrq");
721 }
722
TEST_F(AssemblerX86_64Test,ShrqImm)723 TEST_F(AssemblerX86_64Test, ShrqImm) {
724 DriverStr(RepeatRI(&x86_64::X86_64Assembler::shrq, /*imm_bytes*/ 1U, "shrq ${imm}, %{reg}"), "shrqi");
725 }
726
727 // Sarl only allows CL as the shift count.
sarl_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)728 std::string sarl_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
729 std::ostringstream str;
730 std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
731 x86_64::CpuRegister shifter(x86_64::RCX);
732 for (auto reg : registers) {
733 assembler->sarl(*reg, shifter);
734 str << "sarl %cl, %" << assembler_test->GetSecondaryRegisterName(*reg) << "\n";
735 }
736 return str.str();
737 }
738
TEST_F(AssemblerX86_64Test,SarlReg)739 TEST_F(AssemblerX86_64Test, SarlReg) {
740 DriverFn(&sarl_fn, "sarl");
741 }
742
TEST_F(AssemblerX86_64Test,SarlImm)743 TEST_F(AssemblerX86_64Test, SarlImm) {
744 DriverStr(RepeatrI(&x86_64::X86_64Assembler::sarl, /*imm_bytes*/ 1U, "sarl ${imm}, %{reg}"), "sarli");
745 }
746
747 // Sarq only allows CL as the shift count.
sarq_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)748 std::string sarq_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
749 std::ostringstream str;
750 std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
751 x86_64::CpuRegister shifter(x86_64::RCX);
752 for (auto reg : registers) {
753 assembler->sarq(*reg, shifter);
754 str << "sarq %cl, %" << assembler_test->GetRegisterName(*reg) << "\n";
755 }
756 return str.str();
757 }
758
TEST_F(AssemblerX86_64Test,SarqReg)759 TEST_F(AssemblerX86_64Test, SarqReg) {
760 DriverFn(&sarq_fn, "sarq");
761 }
762
TEST_F(AssemblerX86_64Test,SarqImm)763 TEST_F(AssemblerX86_64Test, SarqImm) {
764 DriverStr(RepeatRI(&x86_64::X86_64Assembler::sarq, /*imm_bytes*/ 1U, "sarq ${imm}, %{reg}"), "sarqi");
765 }
766
767 // Rorl only allows CL as the shift count.
rorl_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)768 std::string rorl_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
769 std::ostringstream str;
770 std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
771 x86_64::CpuRegister shifter(x86_64::RCX);
772 for (auto reg : registers) {
773 assembler->rorl(*reg, shifter);
774 str << "rorl %cl, %" << assembler_test->GetSecondaryRegisterName(*reg) << "\n";
775 }
776 return str.str();
777 }
778
TEST_F(AssemblerX86_64Test,RorlReg)779 TEST_F(AssemblerX86_64Test, RorlReg) {
780 DriverFn(&rorl_fn, "rorl");
781 }
782
TEST_F(AssemblerX86_64Test,RorlImm)783 TEST_F(AssemblerX86_64Test, RorlImm) {
784 DriverStr(RepeatrI(&x86_64::X86_64Assembler::rorl, /*imm_bytes*/ 1U, "rorl ${imm}, %{reg}"), "rorli");
785 }
786
787 // Roll only allows CL as the shift count.
roll_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)788 std::string roll_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
789 std::ostringstream str;
790 std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
791 x86_64::CpuRegister shifter(x86_64::RCX);
792 for (auto reg : registers) {
793 assembler->roll(*reg, shifter);
794 str << "roll %cl, %" << assembler_test->GetSecondaryRegisterName(*reg) << "\n";
795 }
796 return str.str();
797 }
798
TEST_F(AssemblerX86_64Test,RollReg)799 TEST_F(AssemblerX86_64Test, RollReg) {
800 DriverFn(&roll_fn, "roll");
801 }
802
TEST_F(AssemblerX86_64Test,RollImm)803 TEST_F(AssemblerX86_64Test, RollImm) {
804 DriverStr(RepeatrI(&x86_64::X86_64Assembler::roll, /*imm_bytes*/ 1U, "roll ${imm}, %{reg}"), "rolli");
805 }
806
807 // Rorq only allows CL as the shift count.
rorq_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)808 std::string rorq_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
809 std::ostringstream str;
810 std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
811 x86_64::CpuRegister shifter(x86_64::RCX);
812 for (auto reg : registers) {
813 assembler->rorq(*reg, shifter);
814 str << "rorq %cl, %" << assembler_test->GetRegisterName(*reg) << "\n";
815 }
816 return str.str();
817 }
818
TEST_F(AssemblerX86_64Test,RorqReg)819 TEST_F(AssemblerX86_64Test, RorqReg) {
820 DriverFn(&rorq_fn, "rorq");
821 }
822
TEST_F(AssemblerX86_64Test,RorqImm)823 TEST_F(AssemblerX86_64Test, RorqImm) {
824 DriverStr(RepeatRI(&x86_64::X86_64Assembler::rorq, /*imm_bytes*/ 1U, "rorq ${imm}, %{reg}"), "rorqi");
825 }
826
827 // Rolq only allows CL as the shift count.
rolq_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)828 std::string rolq_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
829 std::ostringstream str;
830 std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
831 x86_64::CpuRegister shifter(x86_64::RCX);
832 for (auto reg : registers) {
833 assembler->rolq(*reg, shifter);
834 str << "rolq %cl, %" << assembler_test->GetRegisterName(*reg) << "\n";
835 }
836 return str.str();
837 }
838
TEST_F(AssemblerX86_64Test,RolqReg)839 TEST_F(AssemblerX86_64Test, RolqReg) {
840 DriverFn(&rolq_fn, "rolq");
841 }
842
TEST_F(AssemblerX86_64Test,RolqImm)843 TEST_F(AssemblerX86_64Test, RolqImm) {
844 DriverStr(RepeatRI(&x86_64::X86_64Assembler::rolq, /*imm_bytes*/ 1U, "rolq ${imm}, %{reg}"), "rolqi");
845 }
846
TEST_F(AssemblerX86_64Test,CmpqRegs)847 TEST_F(AssemblerX86_64Test, CmpqRegs) {
848 DriverStr(RepeatRR(&x86_64::X86_64Assembler::cmpq, "cmpq %{reg2}, %{reg1}"), "cmpq");
849 }
850
TEST_F(AssemblerX86_64Test,CmpqImm)851 TEST_F(AssemblerX86_64Test, CmpqImm) {
852 DriverStr(RepeatRI(&x86_64::X86_64Assembler::cmpq,
853 /*imm_bytes*/ 4U,
854 "cmpq ${imm}, %{reg}"), "cmpqi"); // only imm32
855 }
856
TEST_F(AssemblerX86_64Test,CmplRegs)857 TEST_F(AssemblerX86_64Test, CmplRegs) {
858 DriverStr(Repeatrr(&x86_64::X86_64Assembler::cmpl, "cmp %{reg2}, %{reg1}"), "cmpl");
859 }
860
TEST_F(AssemblerX86_64Test,CmplImm)861 TEST_F(AssemblerX86_64Test, CmplImm) {
862 DriverStr(RepeatrI(&x86_64::X86_64Assembler::cmpl, /*imm_bytes*/ 4U, "cmpl ${imm}, %{reg}"), "cmpli");
863 }
864
TEST_F(AssemblerX86_64Test,Testl)865 TEST_F(AssemblerX86_64Test, Testl) {
866 // Note: uses different order for GCC than usual. This makes GCC happy, and doesn't have an
867 // impact on functional correctness.
868 DriverStr(Repeatrr(&x86_64::X86_64Assembler::testl, "testl %{reg1}, %{reg2}"), "testl");
869 }
870
TEST_F(AssemblerX86_64Test,Negq)871 TEST_F(AssemblerX86_64Test, Negq) {
872 DriverStr(RepeatR(&x86_64::X86_64Assembler::negq, "negq %{reg}"), "negq");
873 }
874
TEST_F(AssemblerX86_64Test,Negl)875 TEST_F(AssemblerX86_64Test, Negl) {
876 DriverStr(Repeatr(&x86_64::X86_64Assembler::negl, "negl %{reg}"), "negl");
877 }
878
TEST_F(AssemblerX86_64Test,Notq)879 TEST_F(AssemblerX86_64Test, Notq) {
880 DriverStr(RepeatR(&x86_64::X86_64Assembler::notq, "notq %{reg}"), "notq");
881 }
882
TEST_F(AssemblerX86_64Test,Notl)883 TEST_F(AssemblerX86_64Test, Notl) {
884 DriverStr(Repeatr(&x86_64::X86_64Assembler::notl, "notl %{reg}"), "notl");
885 }
886
TEST_F(AssemblerX86_64Test,AndqRegs)887 TEST_F(AssemblerX86_64Test, AndqRegs) {
888 DriverStr(RepeatRR(&x86_64::X86_64Assembler::andq, "andq %{reg2}, %{reg1}"), "andq");
889 }
890
TEST_F(AssemblerX86_64Test,AndqImm)891 TEST_F(AssemblerX86_64Test, AndqImm) {
892 DriverStr(RepeatRI(&x86_64::X86_64Assembler::andq,
893 /*imm_bytes*/ 4U,
894 "andq ${imm}, %{reg}"), "andqi"); // only imm32
895 }
896
TEST_F(AssemblerX86_64Test,AndlRegs)897 TEST_F(AssemblerX86_64Test, AndlRegs) {
898 DriverStr(Repeatrr(&x86_64::X86_64Assembler::andl, "andl %{reg2}, %{reg1}"), "andl");
899 }
900
TEST_F(AssemblerX86_64Test,AndlImm)901 TEST_F(AssemblerX86_64Test, AndlImm) {
902 DriverStr(RepeatrI(&x86_64::X86_64Assembler::andl,
903 /*imm_bytes*/ 4U,
904 "andl ${imm}, %{reg}"), "andli");
905 }
906
TEST_F(AssemblerX86_64Test,OrqRegs)907 TEST_F(AssemblerX86_64Test, OrqRegs) {
908 DriverStr(RepeatRR(&x86_64::X86_64Assembler::orq, "orq %{reg2}, %{reg1}"), "orq");
909 }
910
TEST_F(AssemblerX86_64Test,OrlRegs)911 TEST_F(AssemblerX86_64Test, OrlRegs) {
912 DriverStr(Repeatrr(&x86_64::X86_64Assembler::orl, "orl %{reg2}, %{reg1}"), "orl");
913 }
914
TEST_F(AssemblerX86_64Test,OrlImm)915 TEST_F(AssemblerX86_64Test, OrlImm) {
916 DriverStr(RepeatrI(&x86_64::X86_64Assembler::orl,
917 /*imm_bytes*/ 4U, "orl ${imm}, %{reg}"), "orli");
918 }
919
TEST_F(AssemblerX86_64Test,XorqRegs)920 TEST_F(AssemblerX86_64Test, XorqRegs) {
921 DriverStr(RepeatRR(&x86_64::X86_64Assembler::xorq, "xorq %{reg2}, %{reg1}"), "xorq");
922 }
923
TEST_F(AssemblerX86_64Test,XorqImm)924 TEST_F(AssemblerX86_64Test, XorqImm) {
925 DriverStr(RepeatRI(&x86_64::X86_64Assembler::xorq,
926 /*imm_bytes*/ 4U, "xorq ${imm}, %{reg}"), "xorqi");
927 }
928
TEST_F(AssemblerX86_64Test,XorlRegs)929 TEST_F(AssemblerX86_64Test, XorlRegs) {
930 DriverStr(Repeatrr(&x86_64::X86_64Assembler::xorl, "xor %{reg2}, %{reg1}"), "xorl");
931 }
932
TEST_F(AssemblerX86_64Test,XorlImm)933 TEST_F(AssemblerX86_64Test, XorlImm) {
934 DriverStr(RepeatrI(&x86_64::X86_64Assembler::xorl,
935 /*imm_bytes*/ 4U, "xor ${imm}, %{reg}"), "xorli");
936 }
937
TEST_F(AssemblerX86_64Test,Xchgq)938 TEST_F(AssemblerX86_64Test, Xchgq) {
939 DriverStr(RepeatRR(&x86_64::X86_64Assembler::xchgq, "xchgq %{reg2}, %{reg1}"), "xchgq");
940 }
941
TEST_F(AssemblerX86_64Test,Xchgl)942 TEST_F(AssemblerX86_64Test, Xchgl) {
943 // TODO: Test is disabled because GCC generates 0x87 0xC0 for xchgl eax, eax. All other cases
944 // are the same. Anyone know why it doesn't emit a simple 0x90? It does so for xchgq rax, rax...
945 // DriverStr(Repeatrr(&x86_64::X86_64Assembler::xchgl, "xchgl %{reg2}, %{reg1}"), "xchgl");
946 }
947
TEST_F(AssemblerX86_64Test,LockCmpxchgl)948 TEST_F(AssemblerX86_64Test, LockCmpxchgl) {
949 DriverStr(RepeatAr(&x86_64::X86_64Assembler::LockCmpxchgl,
950 "lock cmpxchgl %{reg}, {mem}"), "lock_cmpxchgl");
951 }
952
TEST_F(AssemblerX86_64Test,LockCmpxchgq)953 TEST_F(AssemblerX86_64Test, LockCmpxchgq) {
954 DriverStr(RepeatAR(&x86_64::X86_64Assembler::LockCmpxchgq,
955 "lock cmpxchg %{reg}, {mem}"), "lock_cmpxchg");
956 }
957
TEST_F(AssemblerX86_64Test,MovqStore)958 TEST_F(AssemblerX86_64Test, MovqStore) {
959 DriverStr(RepeatAR(&x86_64::X86_64Assembler::movq, "movq %{reg}, {mem}"), "movq_s");
960 }
961
TEST_F(AssemblerX86_64Test,MovqLoad)962 TEST_F(AssemblerX86_64Test, MovqLoad) {
963 DriverStr(RepeatRA(&x86_64::X86_64Assembler::movq, "movq {mem}, %{reg}"), "movq_l");
964 }
965
TEST_F(AssemblerX86_64Test,MovlStore)966 TEST_F(AssemblerX86_64Test, MovlStore) {
967 DriverStr(RepeatAr(&x86_64::X86_64Assembler::movl, "movl %{reg}, {mem}"), "movl_s");
968 }
969
TEST_F(AssemblerX86_64Test,MovlLoad)970 TEST_F(AssemblerX86_64Test, MovlLoad) {
971 DriverStr(RepeatrA(&x86_64::X86_64Assembler::movl, "movl {mem}, %{reg}"), "movl_l");
972 }
973
TEST_F(AssemblerX86_64Test,MovwStore)974 TEST_F(AssemblerX86_64Test, MovwStore) {
975 DriverStr(RepeatAw(&x86_64::X86_64Assembler::movw, "movw %{reg}, {mem}"), "movw_s");
976 }
977
TEST_F(AssemblerX86_64Test,MovbStore)978 TEST_F(AssemblerX86_64Test, MovbStore) {
979 DriverStr(RepeatAb(&x86_64::X86_64Assembler::movb, "movb %{reg}, {mem}"), "movb_s");
980 }
981
TEST_F(AssemblerX86_64Test,Cmpw)982 TEST_F(AssemblerX86_64Test, Cmpw) {
983 DriverStr(
984 RepeatAI(&x86_64::X86_64Assembler::cmpw, /*imm_bytes*/ 2U, "cmpw ${imm}, {mem}"), "cmpw");
985 }
986
TEST_F(AssemblerX86_64Test,MovqAddrImm)987 TEST_F(AssemblerX86_64Test, MovqAddrImm) {
988 DriverStr(RepeatAI(&x86_64::X86_64Assembler::movq,
989 /*imm_bytes*/ 4U,
990 "movq ${imm}, {mem}"), "movq"); // only imm32
991 }
992
TEST_F(AssemblerX86_64Test,MovlAddrImm)993 TEST_F(AssemblerX86_64Test, MovlAddrImm) {
994 DriverStr(RepeatAI(&x86_64::X86_64Assembler::movl,
995 /*imm_bytes*/ 4U, "movl ${imm}, {mem}"), "movl");
996 }
997
TEST_F(AssemblerX86_64Test,MovwAddrImm)998 TEST_F(AssemblerX86_64Test, MovwAddrImm) {
999 DriverStr(RepeatAI(&x86_64::X86_64Assembler::movw,
1000 /*imm_bytes*/ 2U, "movw ${imm}, {mem}"), "movw");
1001 }
1002
TEST_F(AssemblerX86_64Test,MovbAddrImm)1003 TEST_F(AssemblerX86_64Test, MovbAddrImm) {
1004 DriverStr(RepeatAI(&x86_64::X86_64Assembler::movb,
1005 /*imm_bytes*/ 1U, "movb ${imm}, {mem}"), "movb");
1006 }
1007
TEST_F(AssemblerX86_64Test,Movntl)1008 TEST_F(AssemblerX86_64Test, Movntl) {
1009 DriverStr(RepeatAr(&x86_64::X86_64Assembler::movntl, "movntil %{reg}, {mem}"), "movntl");
1010 }
1011
TEST_F(AssemblerX86_64Test,Movntq)1012 TEST_F(AssemblerX86_64Test, Movntq) {
1013 DriverStr(RepeatAR(&x86_64::X86_64Assembler::movntq, "movntiq %{reg}, {mem}"), "movntq");
1014 }
1015
TEST_F(AssemblerX86_64Test,Cvtsi2ssAddr)1016 TEST_F(AssemblerX86_64Test, Cvtsi2ssAddr) {
1017 GetAssembler()->cvtsi2ss(x86_64::XmmRegister(x86_64::XMM0),
1018 x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0),
1019 /*is64bit*/ false);
1020 GetAssembler()->cvtsi2ss(x86_64::XmmRegister(x86_64::XMM0),
1021 x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0),
1022 /*is64bit*/ true);
1023 const char* expected = "cvtsi2ss 0(%RAX), %xmm0\n"
1024 "cvtsi2ssq 0(%RAX), %xmm0\n";
1025 DriverStr(expected, "cvtsi2ss");
1026 }
1027
TEST_F(AssemblerX86_64Test,Cvtsi2sdAddr)1028 TEST_F(AssemblerX86_64Test, Cvtsi2sdAddr) {
1029 GetAssembler()->cvtsi2sd(x86_64::XmmRegister(x86_64::XMM0),
1030 x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0),
1031 /*is64bit*/ false);
1032 GetAssembler()->cvtsi2sd(x86_64::XmmRegister(x86_64::XMM0),
1033 x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0),
1034 /*is64bit*/ true);
1035 const char* expected = "cvtsi2sd 0(%RAX), %xmm0\n"
1036 "cvtsi2sdq 0(%RAX), %xmm0\n";
1037 DriverStr(expected, "cvtsi2sd");
1038 }
1039
TEST_F(AssemblerX86_64Test,CmpqAddr)1040 TEST_F(AssemblerX86_64Test, CmpqAddr) {
1041 DriverStr(RepeatRA(&x86_64::X86_64Assembler::cmpq, "cmpq {mem}, %{reg}"), "cmpq");
1042 }
1043
TEST_F(AssemblerX86_64Test,MovsxdAddr)1044 TEST_F(AssemblerX86_64Test, MovsxdAddr) {
1045 DriverStr(RepeatRA(&x86_64::X86_64Assembler::movsxd, "movslq {mem}, %{reg}"), "movsxd");
1046 }
1047
TEST_F(AssemblerX86_64Test,TestqAddr)1048 TEST_F(AssemblerX86_64Test, TestqAddr) {
1049 DriverStr(RepeatRA(&x86_64::X86_64Assembler::testq, "testq {mem}, %{reg}"), "testq");
1050 }
1051
TEST_F(AssemblerX86_64Test,AddqAddr)1052 TEST_F(AssemblerX86_64Test, AddqAddr) {
1053 DriverStr(RepeatRA(&x86_64::X86_64Assembler::addq, "addq {mem}, %{reg}"), "addq");
1054 }
1055
TEST_F(AssemblerX86_64Test,SubqAddr)1056 TEST_F(AssemblerX86_64Test, SubqAddr) {
1057 DriverStr(RepeatRA(&x86_64::X86_64Assembler::subq, "subq {mem}, %{reg}"), "subq");
1058 }
1059
TEST_F(AssemblerX86_64Test,Cvtss2sdAddr)1060 TEST_F(AssemblerX86_64Test, Cvtss2sdAddr) {
1061 DriverStr(RepeatFA(&x86_64::X86_64Assembler::cvtss2sd, "cvtss2sd {mem}, %{reg}"), "cvtss2sd");
1062 }
1063
TEST_F(AssemblerX86_64Test,Cvtsd2ssAddr)1064 TEST_F(AssemblerX86_64Test, Cvtsd2ssAddr) {
1065 DriverStr(RepeatFA(&x86_64::X86_64Assembler::cvtsd2ss, "cvtsd2ss {mem}, %{reg}"), "cvtsd2ss");
1066 }
1067
TEST_F(AssemblerX86_64Test,ComissAddr)1068 TEST_F(AssemblerX86_64Test, ComissAddr) {
1069 DriverStr(RepeatFA(&x86_64::X86_64Assembler::comiss, "comiss {mem}, %{reg}"), "comiss");
1070 }
1071
TEST_F(AssemblerX86_64Test,ComisdAddr)1072 TEST_F(AssemblerX86_64Test, ComisdAddr) {
1073 DriverStr(RepeatFA(&x86_64::X86_64Assembler::comisd, "comisd {mem}, %{reg}"), "comisd");
1074 }
1075
TEST_F(AssemblerX86_64Test,UComissAddr)1076 TEST_F(AssemblerX86_64Test, UComissAddr) {
1077 DriverStr(RepeatFA(&x86_64::X86_64Assembler::ucomiss, "ucomiss {mem}, %{reg}"), "ucomiss");
1078 }
1079
TEST_F(AssemblerX86_64Test,UComisdAddr)1080 TEST_F(AssemblerX86_64Test, UComisdAddr) {
1081 DriverStr(RepeatFA(&x86_64::X86_64Assembler::ucomisd, "ucomisd {mem}, %{reg}"), "ucomisd");
1082 }
1083
TEST_F(AssemblerX86_64Test,Andq)1084 TEST_F(AssemblerX86_64Test, Andq) {
1085 DriverStr(RepeatRA(&x86_64::X86_64Assembler::andq, "andq {mem}, %{reg}"), "andq");
1086 }
1087
TEST_F(AssemblerX86_64Test,Orq)1088 TEST_F(AssemblerX86_64Test, Orq) {
1089 DriverStr(RepeatRA(&x86_64::X86_64Assembler::orq, "orq {mem}, %{reg}"), "orq");
1090 }
1091
TEST_F(AssemblerX86_64Test,Xorq)1092 TEST_F(AssemblerX86_64Test, Xorq) {
1093 DriverStr(RepeatRA(&x86_64::X86_64Assembler::xorq, "xorq {mem}, %{reg}"), "xorq");
1094 }
1095
TEST_F(AssemblerX86_64Test,RepneScasb)1096 TEST_F(AssemblerX86_64Test, RepneScasb) {
1097 GetAssembler()->repne_scasb();
1098 const char* expected = "repne scasb\n";
1099 DriverStr(expected, "repne_scasb");
1100 }
1101
TEST_F(AssemblerX86_64Test,RepneScasw)1102 TEST_F(AssemblerX86_64Test, RepneScasw) {
1103 GetAssembler()->repne_scasw();
1104 const char* expected = "repne scasw\n";
1105 DriverStr(expected, "repne_scasw");
1106 }
1107
TEST_F(AssemblerX86_64Test,RepMovsw)1108 TEST_F(AssemblerX86_64Test, RepMovsw) {
1109 GetAssembler()->rep_movsw();
1110 const char* expected = "rep movsw\n";
1111 DriverStr(expected, "rep_movsw");
1112 }
1113
TEST_F(AssemblerX86_64Test,Movsxd)1114 TEST_F(AssemblerX86_64Test, Movsxd) {
1115 DriverStr(RepeatRr(&x86_64::X86_64Assembler::movsxd, "movsxd %{reg2}, %{reg1}"), "movsxd");
1116 }
1117
TEST_F(AssemblerX86_64Test,Movaps)1118 TEST_F(AssemblerX86_64Test, Movaps) {
1119 DriverStr(RepeatFF(&x86_64::X86_64Assembler::movaps, "movaps %{reg2}, %{reg1}"), "movaps");
1120 }
1121
TEST_F(AssemblerX86_64AVXTest,VMovaps)1122 TEST_F(AssemblerX86_64AVXTest, VMovaps) {
1123 DriverStr(RepeatFF(&x86_64::X86_64Assembler::vmovaps, "vmovaps %{reg2}, %{reg1}"), "vmovaps");
1124 }
1125
TEST_F(AssemblerX86_64AVXTest,Movaps)1126 TEST_F(AssemblerX86_64AVXTest, Movaps) {
1127 DriverStr(RepeatFF(&x86_64::X86_64Assembler::movaps, "vmovaps %{reg2}, %{reg1}"), "avx_movaps");
1128 }
1129
TEST_F(AssemblerX86_64Test,MovapsStore)1130 TEST_F(AssemblerX86_64Test, MovapsStore) {
1131 DriverStr(RepeatAF(&x86_64::X86_64Assembler::movaps, "movaps %{reg}, {mem}"), "movaps_s");
1132 }
1133
TEST_F(AssemblerX86_64AVXTest,VMovapsStore)1134 TEST_F(AssemblerX86_64AVXTest, VMovapsStore) {
1135 DriverStr(RepeatAF(&x86_64::X86_64Assembler::vmovaps, "vmovaps %{reg}, {mem}"), "vmovaps_s");
1136 }
1137
TEST_F(AssemblerX86_64AVXTest,MovapsStore)1138 TEST_F(AssemblerX86_64AVXTest, MovapsStore) {
1139 DriverStr(RepeatAF(&x86_64::X86_64Assembler::movaps, "vmovaps %{reg}, {mem}"), "avx_movaps_s");
1140 }
1141
TEST_F(AssemblerX86_64Test,MovapsLoad)1142 TEST_F(AssemblerX86_64Test, MovapsLoad) {
1143 DriverStr(RepeatFA(&x86_64::X86_64Assembler::movaps, "movaps {mem}, %{reg}"), "movaps_l");
1144 }
1145
TEST_F(AssemblerX86_64AVXTest,VMovapsLoad)1146 TEST_F(AssemblerX86_64AVXTest, VMovapsLoad) {
1147 DriverStr(RepeatFA(&x86_64::X86_64Assembler::vmovaps, "vmovaps {mem}, %{reg}"), "vmovaps_l");
1148 }
1149
TEST_F(AssemblerX86_64AVXTest,MovapsLoad)1150 TEST_F(AssemblerX86_64AVXTest, MovapsLoad) {
1151 DriverStr(RepeatFA(&x86_64::X86_64Assembler::movaps, "vmovaps {mem}, %{reg}"), "avx_movaps_l");
1152 }
1153
TEST_F(AssemblerX86_64Test,MovupsStore)1154 TEST_F(AssemblerX86_64Test, MovupsStore) {
1155 DriverStr(RepeatAF(&x86_64::X86_64Assembler::movups, "movups %{reg}, {mem}"), "movups_s");
1156 }
1157
TEST_F(AssemblerX86_64AVXTest,VMovupsStore)1158 TEST_F(AssemblerX86_64AVXTest, VMovupsStore) {
1159 DriverStr(RepeatAF(&x86_64::X86_64Assembler::vmovups, "vmovups %{reg}, {mem}"), "vmovups_s");
1160 }
1161
TEST_F(AssemblerX86_64AVXTest,MovupsStore)1162 TEST_F(AssemblerX86_64AVXTest, MovupsStore) {
1163 DriverStr(RepeatAF(&x86_64::X86_64Assembler::movups, "vmovups %{reg}, {mem}"), "avx_movups_s");
1164 }
1165
TEST_F(AssemblerX86_64Test,MovupsLoad)1166 TEST_F(AssemblerX86_64Test, MovupsLoad) {
1167 DriverStr(RepeatFA(&x86_64::X86_64Assembler::movups, "movups {mem}, %{reg}"), "movups_l");
1168 }
1169
TEST_F(AssemblerX86_64AVXTest,VMovupsLoad)1170 TEST_F(AssemblerX86_64AVXTest, VMovupsLoad) {
1171 DriverStr(RepeatFA(&x86_64::X86_64Assembler::vmovups, "vmovups {mem}, %{reg}"), "vmovups_l");
1172 }
1173
TEST_F(AssemblerX86_64AVXTest,MovupsLoad)1174 TEST_F(AssemblerX86_64AVXTest, MovupsLoad) {
1175 DriverStr(RepeatFA(&x86_64::X86_64Assembler::movups, "vmovups {mem}, %{reg}"), "avx_movups_l");
1176 }
1177
TEST_F(AssemblerX86_64Test,Movss)1178 TEST_F(AssemblerX86_64Test, Movss) {
1179 DriverStr(RepeatFF(&x86_64::X86_64Assembler::movss, "movss %{reg2}, %{reg1}"), "movss");
1180 }
1181
TEST_F(AssemblerX86_64Test,Movapd)1182 TEST_F(AssemblerX86_64Test, Movapd) {
1183 DriverStr(RepeatFF(&x86_64::X86_64Assembler::movapd, "movapd %{reg2}, %{reg1}"), "movapd");
1184 }
1185
TEST_F(AssemblerX86_64AVXTest,VMovapd)1186 TEST_F(AssemblerX86_64AVXTest, VMovapd) {
1187 DriverStr(RepeatFF(&x86_64::X86_64Assembler::vmovapd, "vmovapd %{reg2}, %{reg1}"), "vmovapd");
1188 }
1189
TEST_F(AssemblerX86_64AVXTest,Movapd)1190 TEST_F(AssemblerX86_64AVXTest, Movapd) {
1191 DriverStr(RepeatFF(&x86_64::X86_64Assembler::movapd, "vmovapd %{reg2}, %{reg1}"), "avx_movapd");
1192 }
1193
TEST_F(AssemblerX86_64Test,MovapdStore)1194 TEST_F(AssemblerX86_64Test, MovapdStore) {
1195 DriverStr(RepeatAF(&x86_64::X86_64Assembler::movapd, "movapd %{reg}, {mem}"), "movapd_s");
1196 }
1197
TEST_F(AssemblerX86_64AVXTest,VMovapdStore)1198 TEST_F(AssemblerX86_64AVXTest, VMovapdStore) {
1199 DriverStr(RepeatAF(&x86_64::X86_64Assembler::vmovapd, "vmovapd %{reg}, {mem}"), "vmovapd_s");
1200 }
1201
TEST_F(AssemblerX86_64AVXTest,MovapdStore)1202 TEST_F(AssemblerX86_64AVXTest, MovapdStore) {
1203 DriverStr(RepeatAF(&x86_64::X86_64Assembler::movapd, "vmovapd %{reg}, {mem}"), "avx_movapd_s");
1204 }
1205
TEST_F(AssemblerX86_64Test,MovapdLoad)1206 TEST_F(AssemblerX86_64Test, MovapdLoad) {
1207 DriverStr(RepeatFA(&x86_64::X86_64Assembler::movapd, "movapd {mem}, %{reg}"), "movapd_l");
1208 }
1209
TEST_F(AssemblerX86_64AVXTest,VMovapdLoad)1210 TEST_F(AssemblerX86_64AVXTest, VMovapdLoad) {
1211 DriverStr(RepeatFA(&x86_64::X86_64Assembler::vmovapd, "vmovapd {mem}, %{reg}"), "vmovapd_l");
1212 }
1213
TEST_F(AssemblerX86_64AVXTest,MovapdLoad)1214 TEST_F(AssemblerX86_64AVXTest, MovapdLoad) {
1215 DriverStr(RepeatFA(&x86_64::X86_64Assembler::movapd, "vmovapd {mem}, %{reg}"), "avx_movapd_l");
1216 }
1217
TEST_F(AssemblerX86_64Test,MovupdStore)1218 TEST_F(AssemblerX86_64Test, MovupdStore) {
1219 DriverStr(RepeatAF(&x86_64::X86_64Assembler::movupd, "movupd %{reg}, {mem}"), "movupd_s");
1220 }
1221
TEST_F(AssemblerX86_64AVXTest,VMovupdStore)1222 TEST_F(AssemblerX86_64AVXTest, VMovupdStore) {
1223 DriverStr(RepeatAF(&x86_64::X86_64Assembler::vmovupd, "vmovupd %{reg}, {mem}"), "vmovupd_s");
1224 }
1225
TEST_F(AssemblerX86_64AVXTest,MovupdStore)1226 TEST_F(AssemblerX86_64AVXTest, MovupdStore) {
1227 DriverStr(RepeatAF(&x86_64::X86_64Assembler::movupd, "vmovupd %{reg}, {mem}"), "avx_movupd_s");
1228 }
1229
TEST_F(AssemblerX86_64Test,MovupdLoad)1230 TEST_F(AssemblerX86_64Test, MovupdLoad) {
1231 DriverStr(RepeatFA(&x86_64::X86_64Assembler::movupd, "movupd {mem}, %{reg}"), "movupd_l");
1232 }
1233
TEST_F(AssemblerX86_64AVXTest,VMovupdLoad)1234 TEST_F(AssemblerX86_64AVXTest, VMovupdLoad) {
1235 DriverStr(RepeatFA(&x86_64::X86_64Assembler::vmovupd, "vmovupd {mem}, %{reg}"), "vmovupd_l");
1236 }
1237
TEST_F(AssemblerX86_64AVXTest,MovupdLoad)1238 TEST_F(AssemblerX86_64AVXTest, MovupdLoad) {
1239 DriverStr(RepeatFA(&x86_64::X86_64Assembler::movupd, "vmovupd {mem}, %{reg}"), "avx_movupd_l");
1240 }
1241
TEST_F(AssemblerX86_64Test,Movsd)1242 TEST_F(AssemblerX86_64Test, Movsd) {
1243 DriverStr(RepeatFF(&x86_64::X86_64Assembler::movsd, "movsd %{reg2}, %{reg1}"), "movsd");
1244 }
1245
TEST_F(AssemblerX86_64Test,Movdqa)1246 TEST_F(AssemblerX86_64Test, Movdqa) {
1247 DriverStr(RepeatFF(&x86_64::X86_64Assembler::movdqa, "movdqa %{reg2}, %{reg1}"), "movdqa");
1248 }
1249
TEST_F(AssemblerX86_64AVXTest,VMovdqa)1250 TEST_F(AssemblerX86_64AVXTest, VMovdqa) {
1251 DriverStr(RepeatFF(&x86_64::X86_64Assembler::vmovdqa, "vmovdqa %{reg2}, %{reg1}"), "vmovdqa");
1252 }
1253
TEST_F(AssemblerX86_64AVXTest,Movdqa)1254 TEST_F(AssemblerX86_64AVXTest, Movdqa) {
1255 DriverStr(RepeatFF(&x86_64::X86_64Assembler::movdqa, "vmovdqa %{reg2}, %{reg1}"), "avx_movdqa");
1256 }
1257
TEST_F(AssemblerX86_64Test,MovdqaStore)1258 TEST_F(AssemblerX86_64Test, MovdqaStore) {
1259 DriverStr(RepeatAF(&x86_64::X86_64Assembler::movdqa, "movdqa %{reg}, {mem}"), "movdqa_s");
1260 }
1261
TEST_F(AssemblerX86_64AVXTest,VMovdqaStore)1262 TEST_F(AssemblerX86_64AVXTest, VMovdqaStore) {
1263 DriverStr(RepeatAF(&x86_64::X86_64Assembler::vmovdqa, "vmovdqa %{reg}, {mem}"), "vmovdqa_s");
1264 }
1265
TEST_F(AssemblerX86_64AVXTest,MovdqaStore)1266 TEST_F(AssemblerX86_64AVXTest, MovdqaStore) {
1267 DriverStr(RepeatAF(&x86_64::X86_64Assembler::movdqa, "vmovdqa %{reg}, {mem}"), "avx_movdqa_s");
1268 }
1269
TEST_F(AssemblerX86_64Test,MovdqaLoad)1270 TEST_F(AssemblerX86_64Test, MovdqaLoad) {
1271 DriverStr(RepeatFA(&x86_64::X86_64Assembler::movdqa, "movdqa {mem}, %{reg}"), "movdqa_l");
1272 }
1273
TEST_F(AssemblerX86_64AVXTest,VMovdqaLoad)1274 TEST_F(AssemblerX86_64AVXTest, VMovdqaLoad) {
1275 DriverStr(RepeatFA(&x86_64::X86_64Assembler::vmovdqa, "vmovdqa {mem}, %{reg}"), "vmovdqa_l");
1276 }
1277
TEST_F(AssemblerX86_64AVXTest,MovdqaLoad)1278 TEST_F(AssemblerX86_64AVXTest, MovdqaLoad) {
1279 DriverStr(RepeatFA(&x86_64::X86_64Assembler::movdqa, "vmovdqa {mem}, %{reg}"), "avx_movdqa_l");
1280 }
1281
TEST_F(AssemblerX86_64Test,MovdquStore)1282 TEST_F(AssemblerX86_64Test, MovdquStore) {
1283 DriverStr(RepeatAF(&x86_64::X86_64Assembler::movdqu, "movdqu %{reg}, {mem}"), "movdqu_s");
1284 }
1285
TEST_F(AssemblerX86_64AVXTest,VMovdquStore)1286 TEST_F(AssemblerX86_64AVXTest, VMovdquStore) {
1287 DriverStr(RepeatAF(&x86_64::X86_64Assembler::vmovdqu, "vmovdqu %{reg}, {mem}"), "vmovdqu_s");
1288 }
1289
TEST_F(AssemblerX86_64AVXTest,MovdquStore)1290 TEST_F(AssemblerX86_64AVXTest, MovdquStore) {
1291 DriverStr(RepeatAF(&x86_64::X86_64Assembler::movdqu, "vmovdqu %{reg}, {mem}"), "avx_movdqu_s");
1292 }
1293
TEST_F(AssemblerX86_64Test,MovdquLoad)1294 TEST_F(AssemblerX86_64Test, MovdquLoad) {
1295 DriverStr(RepeatFA(&x86_64::X86_64Assembler::movdqu, "movdqu {mem}, %{reg}"), "movdqu_l");
1296 }
1297
TEST_F(AssemblerX86_64AVXTest,VMovdquLoad)1298 TEST_F(AssemblerX86_64AVXTest, VMovdquLoad) {
1299 DriverStr(RepeatFA(&x86_64::X86_64Assembler::vmovdqu, "vmovdqu {mem}, %{reg}"), "vmovdqu_l");
1300 }
1301
TEST_F(AssemblerX86_64AVXTest,MovdquLoad)1302 TEST_F(AssemblerX86_64AVXTest, MovdquLoad) {
1303 DriverStr(RepeatFA(&x86_64::X86_64Assembler::movdqu, "vmovdqu {mem}, %{reg}"), "avx_movdqu_l");
1304 }
1305
TEST_F(AssemblerX86_64Test,Movd1)1306 TEST_F(AssemblerX86_64Test, Movd1) {
1307 DriverStr(RepeatFR(&x86_64::X86_64Assembler::movd, "movd %{reg2}, %{reg1}"), "movd.1");
1308 }
1309
TEST_F(AssemblerX86_64Test,Movd2)1310 TEST_F(AssemblerX86_64Test, Movd2) {
1311 DriverStr(RepeatRF(&x86_64::X86_64Assembler::movd, "movd %{reg2}, %{reg1}"), "movd.2");
1312 }
1313
TEST_F(AssemblerX86_64Test,Addss)1314 TEST_F(AssemblerX86_64Test, Addss) {
1315 DriverStr(RepeatFF(&x86_64::X86_64Assembler::addss, "addss %{reg2}, %{reg1}"), "addss");
1316 }
1317
TEST_F(AssemblerX86_64Test,Addsd)1318 TEST_F(AssemblerX86_64Test, Addsd) {
1319 DriverStr(RepeatFF(&x86_64::X86_64Assembler::addsd, "addsd %{reg2}, %{reg1}"), "addsd");
1320 }
1321
TEST_F(AssemblerX86_64Test,Addps)1322 TEST_F(AssemblerX86_64Test, Addps) {
1323 DriverStr(RepeatFF(&x86_64::X86_64Assembler::addps, "addps %{reg2}, %{reg1}"), "addps");
1324 }
1325
TEST_F(AssemblerX86_64AVXTest,VAddps)1326 TEST_F(AssemblerX86_64AVXTest, VAddps) {
1327 DriverStr(
1328 RepeatFFF(&x86_64::X86_64Assembler::vaddps, "vaddps %{reg3}, %{reg2}, %{reg1}"), "vaddps");
1329 }
1330
TEST_F(AssemblerX86_64Test,Addpd)1331 TEST_F(AssemblerX86_64Test, Addpd) {
1332 DriverStr(RepeatFF(&x86_64::X86_64Assembler::addpd, "addpd %{reg2}, %{reg1}"), "addpd");
1333 }
1334
TEST_F(AssemblerX86_64AVXTest,VAddpd)1335 TEST_F(AssemblerX86_64AVXTest, VAddpd) {
1336 DriverStr(
1337 RepeatFFF(&x86_64::X86_64Assembler::vaddpd, "vaddpd %{reg3}, %{reg2}, %{reg1}"), "vaddpd");
1338 }
1339
TEST_F(AssemblerX86_64Test,Subss)1340 TEST_F(AssemblerX86_64Test, Subss) {
1341 DriverStr(RepeatFF(&x86_64::X86_64Assembler::subss, "subss %{reg2}, %{reg1}"), "subss");
1342 }
1343
TEST_F(AssemblerX86_64Test,Subsd)1344 TEST_F(AssemblerX86_64Test, Subsd) {
1345 DriverStr(RepeatFF(&x86_64::X86_64Assembler::subsd, "subsd %{reg2}, %{reg1}"), "subsd");
1346 }
1347
TEST_F(AssemblerX86_64Test,Subps)1348 TEST_F(AssemblerX86_64Test, Subps) {
1349 DriverStr(RepeatFF(&x86_64::X86_64Assembler::subps, "subps %{reg2}, %{reg1}"), "subps");
1350 }
1351
TEST_F(AssemblerX86_64AVXTest,VSubps)1352 TEST_F(AssemblerX86_64AVXTest, VSubps) {
1353 DriverStr(
1354 RepeatFFF(&x86_64::X86_64Assembler::vsubps, "vsubps %{reg3},%{reg2}, %{reg1}"), "vsubps");
1355 }
1356
TEST_F(AssemblerX86_64Test,Subpd)1357 TEST_F(AssemblerX86_64Test, Subpd) {
1358 DriverStr(RepeatFF(&x86_64::X86_64Assembler::subpd, "subpd %{reg2}, %{reg1}"), "subpd");
1359 }
1360
TEST_F(AssemblerX86_64AVXTest,VSubpd)1361 TEST_F(AssemblerX86_64AVXTest, VSubpd) {
1362 DriverStr(
1363 RepeatFFF(&x86_64::X86_64Assembler::vsubpd, "vsubpd %{reg3}, %{reg2}, %{reg1}"), "vsubpd");
1364 }
1365
TEST_F(AssemblerX86_64Test,Mulss)1366 TEST_F(AssemblerX86_64Test, Mulss) {
1367 DriverStr(RepeatFF(&x86_64::X86_64Assembler::mulss, "mulss %{reg2}, %{reg1}"), "mulss");
1368 }
1369
TEST_F(AssemblerX86_64Test,Mulsd)1370 TEST_F(AssemblerX86_64Test, Mulsd) {
1371 DriverStr(RepeatFF(&x86_64::X86_64Assembler::mulsd, "mulsd %{reg2}, %{reg1}"), "mulsd");
1372 }
1373
TEST_F(AssemblerX86_64Test,Mulps)1374 TEST_F(AssemblerX86_64Test, Mulps) {
1375 DriverStr(RepeatFF(&x86_64::X86_64Assembler::mulps, "mulps %{reg2}, %{reg1}"), "mulps");
1376 }
1377
TEST_F(AssemblerX86_64AVXTest,VMulps)1378 TEST_F(AssemblerX86_64AVXTest, VMulps) {
1379 DriverStr(
1380 RepeatFFF(&x86_64::X86_64Assembler::vmulps, "vmulps %{reg3}, %{reg2}, %{reg1}"), "vmulps");
1381 }
1382
TEST_F(AssemblerX86_64Test,Mulpd)1383 TEST_F(AssemblerX86_64Test, Mulpd) {
1384 DriverStr(RepeatFF(&x86_64::X86_64Assembler::mulpd, "mulpd %{reg2}, %{reg1}"), "mulpd");
1385 }
1386
TEST_F(AssemblerX86_64AVXTest,VMulpd)1387 TEST_F(AssemblerX86_64AVXTest, VMulpd) {
1388 DriverStr(
1389 RepeatFFF(&x86_64::X86_64Assembler::vmulpd, "vmulpd %{reg3}, %{reg2}, %{reg1}"), "vmulpd");
1390 }
1391
TEST_F(AssemblerX86_64Test,Divss)1392 TEST_F(AssemblerX86_64Test, Divss) {
1393 DriverStr(RepeatFF(&x86_64::X86_64Assembler::divss, "divss %{reg2}, %{reg1}"), "divss");
1394 }
1395
TEST_F(AssemblerX86_64Test,Divsd)1396 TEST_F(AssemblerX86_64Test, Divsd) {
1397 DriverStr(RepeatFF(&x86_64::X86_64Assembler::divsd, "divsd %{reg2}, %{reg1}"), "divsd");
1398 }
1399
TEST_F(AssemblerX86_64Test,Divps)1400 TEST_F(AssemblerX86_64Test, Divps) {
1401 DriverStr(RepeatFF(&x86_64::X86_64Assembler::divps, "divps %{reg2}, %{reg1}"), "divps");
1402 }
1403
TEST_F(AssemblerX86_64AVXTest,VDivps)1404 TEST_F(AssemblerX86_64AVXTest, VDivps) {
1405 DriverStr(
1406 RepeatFFF(&x86_64::X86_64Assembler::vdivps, "vdivps %{reg3}, %{reg2}, %{reg1}"), "vdivps");
1407 }
1408
TEST_F(AssemblerX86_64Test,Divpd)1409 TEST_F(AssemblerX86_64Test, Divpd) {
1410 DriverStr(RepeatFF(&x86_64::X86_64Assembler::divpd, "divpd %{reg2}, %{reg1}"), "divpd");
1411 }
1412
TEST_F(AssemblerX86_64AVXTest,VDivpd)1413 TEST_F(AssemblerX86_64AVXTest, VDivpd) {
1414 DriverStr(
1415 RepeatFFF(&x86_64::X86_64Assembler::vdivpd, "vdivpd %{reg3}, %{reg2}, %{reg1}"), "vdivpd");
1416 }
1417
TEST_F(AssemblerX86_64Test,Paddb)1418 TEST_F(AssemblerX86_64Test, Paddb) {
1419 DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddb, "paddb %{reg2}, %{reg1}"), "paddb");
1420 }
1421
TEST_F(AssemblerX86_64AVXTest,VPaddb)1422 TEST_F(AssemblerX86_64AVXTest, VPaddb) {
1423 DriverStr(
1424 RepeatFFF(&x86_64::X86_64Assembler::vpaddb, "vpaddb %{reg3}, %{reg2}, %{reg1}"), "vpaddb");
1425 }
1426
TEST_F(AssemblerX86_64Test,Psubb)1427 TEST_F(AssemblerX86_64Test, Psubb) {
1428 DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubb, "psubb %{reg2}, %{reg1}"), "psubb");
1429 }
1430
TEST_F(AssemblerX86_64AVXTest,VPsubb)1431 TEST_F(AssemblerX86_64AVXTest, VPsubb) {
1432 DriverStr(
1433 RepeatFFF(&x86_64::X86_64Assembler::vpsubb, "vpsubb %{reg3},%{reg2}, %{reg1}"), "vpsubb");
1434 }
1435
TEST_F(AssemblerX86_64Test,Paddw)1436 TEST_F(AssemblerX86_64Test, Paddw) {
1437 DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddw, "paddw %{reg2}, %{reg1}"), "paddw");
1438 }
1439
TEST_F(AssemblerX86_64AVXTest,VPsubw)1440 TEST_F(AssemblerX86_64AVXTest, VPsubw) {
1441 DriverStr(
1442 RepeatFFF(&x86_64::X86_64Assembler::vpsubw, "vpsubw %{reg3}, %{reg2}, %{reg1}"), "vpsubw");
1443 }
1444
TEST_F(AssemblerX86_64AVXTest,VPaddw)1445 TEST_F(AssemblerX86_64AVXTest, VPaddw) {
1446 DriverStr(
1447 RepeatFFF(&x86_64::X86_64Assembler::vpaddw, "vpaddw %{reg3}, %{reg2}, %{reg1}"), "vpaddw");
1448 }
1449
TEST_F(AssemblerX86_64Test,Psubw)1450 TEST_F(AssemblerX86_64Test, Psubw) {
1451 DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubw, "psubw %{reg2}, %{reg1}"), "psubw");
1452 }
1453
TEST_F(AssemblerX86_64Test,Pmullw)1454 TEST_F(AssemblerX86_64Test, Pmullw) {
1455 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmullw, "pmullw %{reg2}, %{reg1}"), "pmullw");
1456 }
1457
TEST_F(AssemblerX86_64AVXTest,VPmullw)1458 TEST_F(AssemblerX86_64AVXTest, VPmullw) {
1459 DriverStr(
1460 RepeatFFF(&x86_64::X86_64Assembler::vpmullw, "vpmullw %{reg3}, %{reg2}, %{reg1}"), "vpmullw");
1461 }
1462
TEST_F(AssemblerX86_64Test,Paddd)1463 TEST_F(AssemblerX86_64Test, Paddd) {
1464 DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddd, "paddd %{reg2}, %{reg1}"), "paddd");
1465 }
1466
TEST_F(AssemblerX86_64AVXTest,VPaddd)1467 TEST_F(AssemblerX86_64AVXTest, VPaddd) {
1468 DriverStr(
1469 RepeatFFF(&x86_64::X86_64Assembler::vpaddd, "vpaddd %{reg3}, %{reg2}, %{reg1}"), "vpaddd");
1470 }
1471
TEST_F(AssemblerX86_64Test,Psubd)1472 TEST_F(AssemblerX86_64Test, Psubd) {
1473 DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubd, "psubd %{reg2}, %{reg1}"), "psubd");
1474 }
1475
TEST_F(AssemblerX86_64AVXTest,VPsubd)1476 TEST_F(AssemblerX86_64AVXTest, VPsubd) {
1477 DriverStr(
1478 RepeatFFF(&x86_64::X86_64Assembler::vpsubd, "vpsubd %{reg3}, %{reg2}, %{reg1}"), "vpsubd");
1479 }
1480
TEST_F(AssemblerX86_64Test,Pmulld)1481 TEST_F(AssemblerX86_64Test, Pmulld) {
1482 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmulld, "pmulld %{reg2}, %{reg1}"), "pmulld");
1483 }
1484
TEST_F(AssemblerX86_64AVXTest,VPmulld)1485 TEST_F(AssemblerX86_64AVXTest, VPmulld) {
1486 DriverStr(
1487 RepeatFFF(&x86_64::X86_64Assembler::vpmulld, "vpmulld %{reg3}, %{reg2}, %{reg1}"), "vpmulld");
1488 }
1489
TEST_F(AssemblerX86_64Test,Paddq)1490 TEST_F(AssemblerX86_64Test, Paddq) {
1491 DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddq, "paddq %{reg2}, %{reg1}"), "paddq");
1492 }
1493
TEST_F(AssemblerX86_64AVXTest,VPaddq)1494 TEST_F(AssemblerX86_64AVXTest, VPaddq) {
1495 DriverStr(
1496 RepeatFFF(&x86_64::X86_64Assembler::vpaddq, "vpaddq %{reg3}, %{reg2}, %{reg1}"), "vpaddq");
1497 }
1498
TEST_F(AssemblerX86_64Test,Psubq)1499 TEST_F(AssemblerX86_64Test, Psubq) {
1500 DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubq, "psubq %{reg2}, %{reg1}"), "psubq");
1501 }
1502
TEST_F(AssemblerX86_64AVXTest,VPsubq)1503 TEST_F(AssemblerX86_64AVXTest, VPsubq) {
1504 DriverStr(
1505 RepeatFFF(&x86_64::X86_64Assembler::vpsubq, "vpsubq %{reg3}, %{reg2}, %{reg1}"), "vpsubq");
1506 }
1507
TEST_F(AssemblerX86_64Test,Paddusb)1508 TEST_F(AssemblerX86_64Test, Paddusb) {
1509 DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddusb, "paddusb %{reg2}, %{reg1}"), "paddusb");
1510 }
1511
TEST_F(AssemblerX86_64Test,Paddsb)1512 TEST_F(AssemblerX86_64Test, Paddsb) {
1513 DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddsb, "paddsb %{reg2}, %{reg1}"), "paddsb");
1514 }
1515
TEST_F(AssemblerX86_64Test,Paddusw)1516 TEST_F(AssemblerX86_64Test, Paddusw) {
1517 DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddusw, "paddusw %{reg2}, %{reg1}"), "paddusw");
1518 }
1519
TEST_F(AssemblerX86_64Test,Paddsw)1520 TEST_F(AssemblerX86_64Test, Paddsw) {
1521 DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddsw, "paddsw %{reg2}, %{reg1}"), "paddsw");
1522 }
1523
TEST_F(AssemblerX86_64Test,Psubusb)1524 TEST_F(AssemblerX86_64Test, Psubusb) {
1525 DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubusb, "psubusb %{reg2}, %{reg1}"), "psubusb");
1526 }
1527
TEST_F(AssemblerX86_64Test,Psubsb)1528 TEST_F(AssemblerX86_64Test, Psubsb) {
1529 DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubsb, "psubsb %{reg2}, %{reg1}"), "psubsb");
1530 }
1531
TEST_F(AssemblerX86_64Test,Psubusw)1532 TEST_F(AssemblerX86_64Test, Psubusw) {
1533 DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubusw, "psubusw %{reg2}, %{reg1}"), "psubusw");
1534 }
1535
TEST_F(AssemblerX86_64Test,Psubsw)1536 TEST_F(AssemblerX86_64Test, Psubsw) {
1537 DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubsw, "psubsw %{reg2}, %{reg1}"), "psubsw");
1538 }
1539
TEST_F(AssemblerX86_64Test,Cvtsi2ss)1540 TEST_F(AssemblerX86_64Test, Cvtsi2ss) {
1541 DriverStr(RepeatFr(&x86_64::X86_64Assembler::cvtsi2ss, "cvtsi2ss %{reg2}, %{reg1}"), "cvtsi2ss");
1542 }
1543
TEST_F(AssemblerX86_64Test,Cvtsi2sd)1544 TEST_F(AssemblerX86_64Test, Cvtsi2sd) {
1545 DriverStr(RepeatFr(&x86_64::X86_64Assembler::cvtsi2sd, "cvtsi2sd %{reg2}, %{reg1}"), "cvtsi2sd");
1546 }
1547
TEST_F(AssemblerX86_64Test,Cvtss2si)1548 TEST_F(AssemblerX86_64Test, Cvtss2si) {
1549 DriverStr(RepeatrF(&x86_64::X86_64Assembler::cvtss2si, "cvtss2si %{reg2}, %{reg1}"), "cvtss2si");
1550 }
1551
TEST_F(AssemblerX86_64Test,Cvtss2sd)1552 TEST_F(AssemblerX86_64Test, Cvtss2sd) {
1553 DriverStr(RepeatFF(&x86_64::X86_64Assembler::cvtss2sd, "cvtss2sd %{reg2}, %{reg1}"), "cvtss2sd");
1554 }
1555
TEST_F(AssemblerX86_64Test,Cvtsd2si)1556 TEST_F(AssemblerX86_64Test, Cvtsd2si) {
1557 DriverStr(RepeatrF(&x86_64::X86_64Assembler::cvtsd2si, "cvtsd2si %{reg2}, %{reg1}"), "cvtsd2si");
1558 }
1559
TEST_F(AssemblerX86_64Test,Cvttss2si)1560 TEST_F(AssemblerX86_64Test, Cvttss2si) {
1561 DriverStr(RepeatrF(&x86_64::X86_64Assembler::cvttss2si, "cvttss2si %{reg2}, %{reg1}"),
1562 "cvttss2si");
1563 }
1564
TEST_F(AssemblerX86_64Test,Cvttsd2si)1565 TEST_F(AssemblerX86_64Test, Cvttsd2si) {
1566 DriverStr(RepeatrF(&x86_64::X86_64Assembler::cvttsd2si, "cvttsd2si %{reg2}, %{reg1}"),
1567 "cvttsd2si");
1568 }
1569
TEST_F(AssemblerX86_64Test,Cvtsd2ss)1570 TEST_F(AssemblerX86_64Test, Cvtsd2ss) {
1571 DriverStr(RepeatFF(&x86_64::X86_64Assembler::cvtsd2ss, "cvtsd2ss %{reg2}, %{reg1}"), "cvtsd2ss");
1572 }
1573
TEST_F(AssemblerX86_64Test,Cvtdq2ps)1574 TEST_F(AssemblerX86_64Test, Cvtdq2ps) {
1575 DriverStr(RepeatFF(&x86_64::X86_64Assembler::cvtdq2ps, "cvtdq2ps %{reg2}, %{reg1}"), "cvtdq2ps");
1576 }
1577
TEST_F(AssemblerX86_64Test,Cvtdq2pd)1578 TEST_F(AssemblerX86_64Test, Cvtdq2pd) {
1579 DriverStr(RepeatFF(&x86_64::X86_64Assembler::cvtdq2pd, "cvtdq2pd %{reg2}, %{reg1}"), "cvtdq2pd");
1580 }
1581
TEST_F(AssemblerX86_64Test,Comiss)1582 TEST_F(AssemblerX86_64Test, Comiss) {
1583 DriverStr(RepeatFF(&x86_64::X86_64Assembler::comiss, "comiss %{reg2}, %{reg1}"), "comiss");
1584 }
1585
TEST_F(AssemblerX86_64Test,Comisd)1586 TEST_F(AssemblerX86_64Test, Comisd) {
1587 DriverStr(RepeatFF(&x86_64::X86_64Assembler::comisd, "comisd %{reg2}, %{reg1}"), "comisd");
1588 }
1589
TEST_F(AssemblerX86_64Test,Ucomiss)1590 TEST_F(AssemblerX86_64Test, Ucomiss) {
1591 DriverStr(RepeatFF(&x86_64::X86_64Assembler::ucomiss, "ucomiss %{reg2}, %{reg1}"), "ucomiss");
1592 }
1593
TEST_F(AssemblerX86_64Test,Ucomisd)1594 TEST_F(AssemblerX86_64Test, Ucomisd) {
1595 DriverStr(RepeatFF(&x86_64::X86_64Assembler::ucomisd, "ucomisd %{reg2}, %{reg1}"), "ucomisd");
1596 }
1597
TEST_F(AssemblerX86_64Test,Sqrtss)1598 TEST_F(AssemblerX86_64Test, Sqrtss) {
1599 DriverStr(RepeatFF(&x86_64::X86_64Assembler::sqrtss, "sqrtss %{reg2}, %{reg1}"), "sqrtss");
1600 }
1601
TEST_F(AssemblerX86_64Test,Sqrtsd)1602 TEST_F(AssemblerX86_64Test, Sqrtsd) {
1603 DriverStr(RepeatFF(&x86_64::X86_64Assembler::sqrtsd, "sqrtsd %{reg2}, %{reg1}"), "sqrtsd");
1604 }
1605
TEST_F(AssemblerX86_64Test,Roundss)1606 TEST_F(AssemblerX86_64Test, Roundss) {
1607 DriverStr(RepeatFFI(&x86_64::X86_64Assembler::roundss, /*imm_bytes*/ 1U,
1608 "roundss ${imm}, %{reg2}, %{reg1}"), "roundss");
1609 }
1610
TEST_F(AssemblerX86_64Test,Roundsd)1611 TEST_F(AssemblerX86_64Test, Roundsd) {
1612 DriverStr(RepeatFFI(&x86_64::X86_64Assembler::roundsd, /*imm_bytes*/ 1U,
1613 "roundsd ${imm}, %{reg2}, %{reg1}"), "roundsd");
1614 }
1615
TEST_F(AssemblerX86_64Test,Xorps)1616 TEST_F(AssemblerX86_64Test, Xorps) {
1617 DriverStr(RepeatFF(&x86_64::X86_64Assembler::xorps, "xorps %{reg2}, %{reg1}"), "xorps");
1618 }
1619
TEST_F(AssemblerX86_64Test,Xorpd)1620 TEST_F(AssemblerX86_64Test, Xorpd) {
1621 DriverStr(RepeatFF(&x86_64::X86_64Assembler::xorpd, "xorpd %{reg2}, %{reg1}"), "xorpd");
1622 }
1623
TEST_F(AssemblerX86_64Test,Pxor)1624 TEST_F(AssemblerX86_64Test, Pxor) {
1625 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pxor, "pxor %{reg2}, %{reg1}"), "pxor");
1626 }
1627
TEST_F(AssemblerX86_64AVXTest,VPXor)1628 TEST_F(AssemblerX86_64AVXTest, VPXor) {
1629 DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vpxor,
1630 "vpxor %{reg3}, %{reg2}, %{reg1}"), "vpxor");
1631 }
1632
TEST_F(AssemblerX86_64AVXTest,VXorps)1633 TEST_F(AssemblerX86_64AVXTest, VXorps) {
1634 DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vxorps,
1635 "vxorps %{reg3}, %{reg2}, %{reg1}"), "vxorps");
1636 }
1637
TEST_F(AssemblerX86_64AVXTest,VXorpd)1638 TEST_F(AssemblerX86_64AVXTest, VXorpd) {
1639 DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vxorpd,
1640 "vxorpd %{reg3}, %{reg2}, %{reg1}"), "vxorpd");
1641 }
1642
TEST_F(AssemblerX86_64Test,Andps)1643 TEST_F(AssemblerX86_64Test, Andps) {
1644 DriverStr(RepeatFF(&x86_64::X86_64Assembler::andps, "andps %{reg2}, %{reg1}"), "andps");
1645 }
1646
TEST_F(AssemblerX86_64Test,Andpd)1647 TEST_F(AssemblerX86_64Test, Andpd) {
1648 DriverStr(RepeatFF(&x86_64::X86_64Assembler::andpd, "andpd %{reg2}, %{reg1}"), "andpd");
1649 }
1650
TEST_F(AssemblerX86_64Test,Pand)1651 TEST_F(AssemblerX86_64Test, Pand) {
1652 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pand, "pand %{reg2}, %{reg1}"), "pand");
1653 }
1654
TEST_F(AssemblerX86_64AVXTest,VPAnd)1655 TEST_F(AssemblerX86_64AVXTest, VPAnd) {
1656 DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vpand,
1657 "vpand %{reg3}, %{reg2}, %{reg1}"), "vpand");
1658 }
1659
TEST_F(AssemblerX86_64AVXTest,VAndps)1660 TEST_F(AssemblerX86_64AVXTest, VAndps) {
1661 DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vandps,
1662 "vandps %{reg3}, %{reg2}, %{reg1}"), "vandps");
1663 }
1664
TEST_F(AssemblerX86_64AVXTest,VAndpd)1665 TEST_F(AssemblerX86_64AVXTest, VAndpd) {
1666 DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vandpd,
1667 "vandpd %{reg3}, %{reg2}, %{reg1}"), "vandpd");
1668 }
1669
TEST_F(AssemblerX86_64Test,Andn)1670 TEST_F(AssemblerX86_64Test, Andn) {
1671 DriverStr(RepeatRRR(&x86_64::X86_64Assembler::andn, "andn %{reg3}, %{reg2}, %{reg1}"), "andn");
1672 }
TEST_F(AssemblerX86_64Test,andnpd)1673 TEST_F(AssemblerX86_64Test, andnpd) {
1674 DriverStr(RepeatFF(&x86_64::X86_64Assembler::andnpd, "andnpd %{reg2}, %{reg1}"), "andnpd");
1675 }
1676
TEST_F(AssemblerX86_64Test,andnps)1677 TEST_F(AssemblerX86_64Test, andnps) {
1678 DriverStr(RepeatFF(&x86_64::X86_64Assembler::andnps, "andnps %{reg2}, %{reg1}"), "andnps");
1679 }
1680
TEST_F(AssemblerX86_64Test,Pandn)1681 TEST_F(AssemblerX86_64Test, Pandn) {
1682 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pandn, "pandn %{reg2}, %{reg1}"), "pandn");
1683 }
1684
TEST_F(AssemblerX86_64AVXTest,VPAndn)1685 TEST_F(AssemblerX86_64AVXTest, VPAndn) {
1686 DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vpandn,
1687 "vpandn %{reg3}, %{reg2}, %{reg1}"), "vpandn");
1688 }
1689
TEST_F(AssemblerX86_64AVXTest,VAndnps)1690 TEST_F(AssemblerX86_64AVXTest, VAndnps) {
1691 DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vandnps,
1692 "vandnps %{reg3}, %{reg2}, %{reg1}"), "vandnps");
1693 }
1694
TEST_F(AssemblerX86_64AVXTest,VAndnpd)1695 TEST_F(AssemblerX86_64AVXTest, VAndnpd) {
1696 DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vandnpd,
1697 "vandnpd %{reg3}, %{reg2}, %{reg1}"), "vandnpd");
1698 }
1699
TEST_F(AssemblerX86_64Test,Orps)1700 TEST_F(AssemblerX86_64Test, Orps) {
1701 DriverStr(RepeatFF(&x86_64::X86_64Assembler::orps, "orps %{reg2}, %{reg1}"), "orps");
1702 }
1703
TEST_F(AssemblerX86_64Test,Orpd)1704 TEST_F(AssemblerX86_64Test, Orpd) {
1705 DriverStr(RepeatFF(&x86_64::X86_64Assembler::orpd, "orpd %{reg2}, %{reg1}"), "orpd");
1706 }
1707
TEST_F(AssemblerX86_64Test,Por)1708 TEST_F(AssemblerX86_64Test, Por) {
1709 DriverStr(RepeatFF(&x86_64::X86_64Assembler::por, "por %{reg2}, %{reg1}"), "por");
1710 }
1711
TEST_F(AssemblerX86_64AVXTest,VPor)1712 TEST_F(AssemblerX86_64AVXTest, VPor) {
1713 DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vpor,
1714 "vpor %{reg3}, %{reg2}, %{reg1}"), "vpor");
1715 }
1716
TEST_F(AssemblerX86_64AVXTest,Vorps)1717 TEST_F(AssemblerX86_64AVXTest, Vorps) {
1718 DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vorps,
1719 "vorps %{reg3}, %{reg2}, %{reg1}"), "vorps");
1720 }
1721
TEST_F(AssemblerX86_64AVXTest,Vorpd)1722 TEST_F(AssemblerX86_64AVXTest, Vorpd) {
1723 DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vorpd,
1724 "vorpd %{reg3}, %{reg2}, %{reg1}"), "vorpd");
1725 }
1726
TEST_F(AssemblerX86_64Test,Pavgb)1727 TEST_F(AssemblerX86_64Test, Pavgb) {
1728 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pavgb, "pavgb %{reg2}, %{reg1}"), "pavgb");
1729 }
1730
TEST_F(AssemblerX86_64Test,Pavgw)1731 TEST_F(AssemblerX86_64Test, Pavgw) {
1732 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pavgw, "pavgw %{reg2}, %{reg1}"), "pavgw");
1733 }
1734
TEST_F(AssemblerX86_64Test,Psadbw)1735 TEST_F(AssemblerX86_64Test, Psadbw) {
1736 DriverStr(RepeatFF(&x86_64::X86_64Assembler::psadbw, "psadbw %{reg2}, %{reg1}"), "psadbw");
1737 }
1738
TEST_F(AssemblerX86_64Test,Pmaddwd)1739 TEST_F(AssemblerX86_64Test, Pmaddwd) {
1740 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaddwd, "pmaddwd %{reg2}, %{reg1}"), "pmadwd");
1741 }
1742
TEST_F(AssemblerX86_64AVXTest,VPmaddwd)1743 TEST_F(AssemblerX86_64AVXTest, VPmaddwd) {
1744 DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vpmaddwd,
1745 "vpmaddwd %{reg3}, %{reg2}, %{reg1}"), "vpmaddwd");
1746 }
1747
TEST_F(AssemblerX86_64Test,Phaddw)1748 TEST_F(AssemblerX86_64Test, Phaddw) {
1749 DriverStr(RepeatFF(&x86_64::X86_64Assembler::phaddw, "phaddw %{reg2}, %{reg1}"), "phaddw");
1750 }
1751
TEST_F(AssemblerX86_64Test,Phaddd)1752 TEST_F(AssemblerX86_64Test, Phaddd) {
1753 DriverStr(RepeatFF(&x86_64::X86_64Assembler::phaddd, "phaddd %{reg2}, %{reg1}"), "phaddd");
1754 }
1755
TEST_F(AssemblerX86_64Test,Haddps)1756 TEST_F(AssemblerX86_64Test, Haddps) {
1757 DriverStr(RepeatFF(&x86_64::X86_64Assembler::haddps, "haddps %{reg2}, %{reg1}"), "haddps");
1758 }
1759
TEST_F(AssemblerX86_64Test,Haddpd)1760 TEST_F(AssemblerX86_64Test, Haddpd) {
1761 DriverStr(RepeatFF(&x86_64::X86_64Assembler::haddpd, "haddpd %{reg2}, %{reg1}"), "haddpd");
1762 }
1763
TEST_F(AssemblerX86_64Test,Phsubw)1764 TEST_F(AssemblerX86_64Test, Phsubw) {
1765 DriverStr(RepeatFF(&x86_64::X86_64Assembler::phsubw, "phsubw %{reg2}, %{reg1}"), "phsubw");
1766 }
1767
TEST_F(AssemblerX86_64Test,Phsubd)1768 TEST_F(AssemblerX86_64Test, Phsubd) {
1769 DriverStr(RepeatFF(&x86_64::X86_64Assembler::phsubd, "phsubd %{reg2}, %{reg1}"), "phsubd");
1770 }
1771
TEST_F(AssemblerX86_64Test,Hsubps)1772 TEST_F(AssemblerX86_64Test, Hsubps) {
1773 DriverStr(RepeatFF(&x86_64::X86_64Assembler::hsubps, "hsubps %{reg2}, %{reg1}"), "hsubps");
1774 }
1775
TEST_F(AssemblerX86_64Test,Hsubpd)1776 TEST_F(AssemblerX86_64Test, Hsubpd) {
1777 DriverStr(RepeatFF(&x86_64::X86_64Assembler::hsubpd, "hsubpd %{reg2}, %{reg1}"), "hsubpd");
1778 }
1779
TEST_F(AssemblerX86_64Test,Pminsb)1780 TEST_F(AssemblerX86_64Test, Pminsb) {
1781 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pminsb, "pminsb %{reg2}, %{reg1}"), "pminsb");
1782 }
1783
TEST_F(AssemblerX86_64Test,Pmaxsb)1784 TEST_F(AssemblerX86_64Test, Pmaxsb) {
1785 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaxsb, "pmaxsb %{reg2}, %{reg1}"), "pmaxsb");
1786 }
1787
TEST_F(AssemblerX86_64Test,Pminsw)1788 TEST_F(AssemblerX86_64Test, Pminsw) {
1789 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pminsw, "pminsw %{reg2}, %{reg1}"), "pminsw");
1790 }
1791
TEST_F(AssemblerX86_64Test,Pmaxsw)1792 TEST_F(AssemblerX86_64Test, Pmaxsw) {
1793 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaxsw, "pmaxsw %{reg2}, %{reg1}"), "pmaxsw");
1794 }
1795
TEST_F(AssemblerX86_64Test,Pminsd)1796 TEST_F(AssemblerX86_64Test, Pminsd) {
1797 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pminsd, "pminsd %{reg2}, %{reg1}"), "pminsd");
1798 }
1799
TEST_F(AssemblerX86_64Test,Pmaxsd)1800 TEST_F(AssemblerX86_64Test, Pmaxsd) {
1801 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaxsd, "pmaxsd %{reg2}, %{reg1}"), "pmaxsd");
1802 }
1803
TEST_F(AssemblerX86_64Test,Pminub)1804 TEST_F(AssemblerX86_64Test, Pminub) {
1805 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pminub, "pminub %{reg2}, %{reg1}"), "pminub");
1806 }
1807
TEST_F(AssemblerX86_64Test,Pmaxub)1808 TEST_F(AssemblerX86_64Test, Pmaxub) {
1809 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaxub, "pmaxub %{reg2}, %{reg1}"), "pmaxub");
1810 }
1811
TEST_F(AssemblerX86_64Test,Pminuw)1812 TEST_F(AssemblerX86_64Test, Pminuw) {
1813 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pminuw, "pminuw %{reg2}, %{reg1}"), "pminuw");
1814 }
1815
TEST_F(AssemblerX86_64Test,Pmaxuw)1816 TEST_F(AssemblerX86_64Test, Pmaxuw) {
1817 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaxuw, "pmaxuw %{reg2}, %{reg1}"), "pmaxuw");
1818 }
1819
TEST_F(AssemblerX86_64Test,Pminud)1820 TEST_F(AssemblerX86_64Test, Pminud) {
1821 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pminud, "pminud %{reg2}, %{reg1}"), "pminud");
1822 }
1823
TEST_F(AssemblerX86_64Test,Pmaxud)1824 TEST_F(AssemblerX86_64Test, Pmaxud) {
1825 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaxud, "pmaxud %{reg2}, %{reg1}"), "pmaxud");
1826 }
1827
TEST_F(AssemblerX86_64Test,Minps)1828 TEST_F(AssemblerX86_64Test, Minps) {
1829 DriverStr(RepeatFF(&x86_64::X86_64Assembler::minps, "minps %{reg2}, %{reg1}"), "minps");
1830 }
1831
TEST_F(AssemblerX86_64Test,Maxps)1832 TEST_F(AssemblerX86_64Test, Maxps) {
1833 DriverStr(RepeatFF(&x86_64::X86_64Assembler::maxps, "maxps %{reg2}, %{reg1}"), "maxps");
1834 }
1835
TEST_F(AssemblerX86_64Test,Minpd)1836 TEST_F(AssemblerX86_64Test, Minpd) {
1837 DriverStr(RepeatFF(&x86_64::X86_64Assembler::minpd, "minpd %{reg2}, %{reg1}"), "minpd");
1838 }
1839
TEST_F(AssemblerX86_64Test,Maxpd)1840 TEST_F(AssemblerX86_64Test, Maxpd) {
1841 DriverStr(RepeatFF(&x86_64::X86_64Assembler::maxpd, "maxpd %{reg2}, %{reg1}"), "maxpd");
1842 }
1843
TEST_F(AssemblerX86_64Test,PCmpeqb)1844 TEST_F(AssemblerX86_64Test, PCmpeqb) {
1845 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpeqb, "pcmpeqb %{reg2}, %{reg1}"), "pcmpeqb");
1846 }
1847
TEST_F(AssemblerX86_64Test,PCmpeqw)1848 TEST_F(AssemblerX86_64Test, PCmpeqw) {
1849 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpeqw, "pcmpeqw %{reg2}, %{reg1}"), "pcmpeqw");
1850 }
1851
TEST_F(AssemblerX86_64Test,PCmpeqd)1852 TEST_F(AssemblerX86_64Test, PCmpeqd) {
1853 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpeqd, "pcmpeqd %{reg2}, %{reg1}"), "pcmpeqd");
1854 }
1855
TEST_F(AssemblerX86_64Test,PCmpeqq)1856 TEST_F(AssemblerX86_64Test, PCmpeqq) {
1857 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpeqq, "pcmpeqq %{reg2}, %{reg1}"), "pcmpeqq");
1858 }
1859
TEST_F(AssemblerX86_64Test,PCmpgtb)1860 TEST_F(AssemblerX86_64Test, PCmpgtb) {
1861 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpgtb, "pcmpgtb %{reg2}, %{reg1}"), "pcmpgtb");
1862 }
1863
TEST_F(AssemblerX86_64Test,PCmpgtw)1864 TEST_F(AssemblerX86_64Test, PCmpgtw) {
1865 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpgtw, "pcmpgtw %{reg2}, %{reg1}"), "pcmpgtw");
1866 }
1867
TEST_F(AssemblerX86_64Test,PCmpgtd)1868 TEST_F(AssemblerX86_64Test, PCmpgtd) {
1869 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpgtd, "pcmpgtd %{reg2}, %{reg1}"), "pcmpgtd");
1870 }
1871
TEST_F(AssemblerX86_64Test,PCmpgtq)1872 TEST_F(AssemblerX86_64Test, PCmpgtq) {
1873 DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpgtq, "pcmpgtq %{reg2}, %{reg1}"), "pcmpgtq");
1874 }
1875
TEST_F(AssemblerX86_64Test,Shufps)1876 TEST_F(AssemblerX86_64Test, Shufps) {
1877 DriverStr(RepeatFFI(&x86_64::X86_64Assembler::shufps, /*imm_bytes*/ 1U,
1878 "shufps ${imm}, %{reg2}, %{reg1}"), "shufps");
1879 }
1880
TEST_F(AssemblerX86_64Test,Shufpd)1881 TEST_F(AssemblerX86_64Test, Shufpd) {
1882 DriverStr(RepeatFFI(&x86_64::X86_64Assembler::shufpd, /*imm_bytes*/ 1U,
1883 "shufpd ${imm}, %{reg2}, %{reg1}"), "shufpd");
1884 }
1885
TEST_F(AssemblerX86_64Test,PShufd)1886 TEST_F(AssemblerX86_64Test, PShufd) {
1887 DriverStr(RepeatFFI(&x86_64::X86_64Assembler::pshufd, /*imm_bytes*/ 1U,
1888 "pshufd ${imm}, %{reg2}, %{reg1}"), "pshufd");
1889 }
1890
TEST_F(AssemblerX86_64Test,Punpcklbw)1891 TEST_F(AssemblerX86_64Test, Punpcklbw) {
1892 DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpcklbw,
1893 "punpcklbw %{reg2}, %{reg1}"), "punpcklbw");
1894 }
1895
TEST_F(AssemblerX86_64Test,Punpcklwd)1896 TEST_F(AssemblerX86_64Test, Punpcklwd) {
1897 DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpcklwd,
1898 "punpcklwd %{reg2}, %{reg1}"), "punpcklwd");
1899 }
1900
TEST_F(AssemblerX86_64Test,Punpckldq)1901 TEST_F(AssemblerX86_64Test, Punpckldq) {
1902 DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpckldq,
1903 "punpckldq %{reg2}, %{reg1}"), "punpckldq");
1904 }
1905
TEST_F(AssemblerX86_64Test,Punpcklqdq)1906 TEST_F(AssemblerX86_64Test, Punpcklqdq) {
1907 DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpcklqdq,
1908 "punpcklqdq %{reg2}, %{reg1}"), "punpcklqdq");
1909 }
1910
TEST_F(AssemblerX86_64Test,Punpckhbw)1911 TEST_F(AssemblerX86_64Test, Punpckhbw) {
1912 DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpckhbw,
1913 "punpckhbw %{reg2}, %{reg1}"), "punpckhbw");
1914 }
1915
TEST_F(AssemblerX86_64Test,Punpckhwd)1916 TEST_F(AssemblerX86_64Test, Punpckhwd) {
1917 DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpckhwd,
1918 "punpckhwd %{reg2}, %{reg1}"), "punpckhwd");
1919 }
1920
TEST_F(AssemblerX86_64Test,Punpckhdq)1921 TEST_F(AssemblerX86_64Test, Punpckhdq) {
1922 DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpckhdq,
1923 "punpckhdq %{reg2}, %{reg1}"), "punpckhdq");
1924 }
1925
TEST_F(AssemblerX86_64Test,Punpckhqdq)1926 TEST_F(AssemblerX86_64Test, Punpckhqdq) {
1927 DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpckhqdq,
1928 "punpckhqdq %{reg2}, %{reg1}"), "punpckhqdq");
1929 }
1930
TEST_F(AssemblerX86_64Test,Psllw)1931 TEST_F(AssemblerX86_64Test, Psllw) {
1932 GetAssembler()->psllw(x86_64::XmmRegister(x86_64::XMM0), x86_64::Immediate(1));
1933 GetAssembler()->psllw(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1934 DriverStr("psllw $1, %xmm0\n"
1935 "psllw $2, %xmm15\n", "psllwi");
1936 }
1937
TEST_F(AssemblerX86_64Test,Pslld)1938 TEST_F(AssemblerX86_64Test, Pslld) {
1939 GetAssembler()->pslld(x86_64::XmmRegister(x86_64::XMM0), x86_64::Immediate(1));
1940 GetAssembler()->pslld(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1941 DriverStr("pslld $1, %xmm0\n"
1942 "pslld $2, %xmm15\n", "pslldi");
1943 }
1944
TEST_F(AssemblerX86_64Test,Psllq)1945 TEST_F(AssemblerX86_64Test, Psllq) {
1946 GetAssembler()->psllq(x86_64::XmmRegister(x86_64::XMM0), x86_64::Immediate(1));
1947 GetAssembler()->psllq(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1948 DriverStr("psllq $1, %xmm0\n"
1949 "psllq $2, %xmm15\n", "psllqi");
1950 }
1951
TEST_F(AssemblerX86_64Test,Psraw)1952 TEST_F(AssemblerX86_64Test, Psraw) {
1953 GetAssembler()->psraw(x86_64::XmmRegister(x86_64::XMM0), x86_64::Immediate(1));
1954 GetAssembler()->psraw(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1955 DriverStr("psraw $1, %xmm0\n"
1956 "psraw $2, %xmm15\n", "psrawi");
1957 }
1958
TEST_F(AssemblerX86_64Test,Psrad)1959 TEST_F(AssemblerX86_64Test, Psrad) {
1960 GetAssembler()->psrad(x86_64::XmmRegister(x86_64::XMM0), x86_64::Immediate(1));
1961 GetAssembler()->psrad(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1962 DriverStr("psrad $1, %xmm0\n"
1963 "psrad $2, %xmm15\n", "psradi");
1964 }
1965
TEST_F(AssemblerX86_64Test,Psrlw)1966 TEST_F(AssemblerX86_64Test, Psrlw) {
1967 GetAssembler()->psrlw(x86_64::XmmRegister(x86_64::XMM0), x86_64::Immediate(1));
1968 GetAssembler()->psrlw(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1969 DriverStr("psrlw $1, %xmm0\n"
1970 "psrlw $2, %xmm15\n", "psrlwi");
1971 }
1972
TEST_F(AssemblerX86_64Test,Psrld)1973 TEST_F(AssemblerX86_64Test, Psrld) {
1974 GetAssembler()->psrld(x86_64::XmmRegister(x86_64::XMM0), x86_64::Immediate(1));
1975 GetAssembler()->psrld(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1976 DriverStr("psrld $1, %xmm0\n"
1977 "psrld $2, %xmm15\n", "psrldi");
1978 }
1979
TEST_F(AssemblerX86_64Test,Psrlq)1980 TEST_F(AssemblerX86_64Test, Psrlq) {
1981 GetAssembler()->psrlq(x86_64::XmmRegister(x86_64::XMM0), x86_64::Immediate(1));
1982 GetAssembler()->psrlq(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1983 DriverStr("psrlq $1, %xmm0\n"
1984 "psrlq $2, %xmm15\n", "psrlqi");
1985 }
1986
TEST_F(AssemblerX86_64Test,Psrldq)1987 TEST_F(AssemblerX86_64Test, Psrldq) {
1988 GetAssembler()->psrldq(x86_64::XmmRegister(x86_64::XMM0), x86_64::Immediate(1));
1989 GetAssembler()->psrldq(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1990 DriverStr("psrldq $1, %xmm0\n"
1991 "psrldq $2, %xmm15\n", "psrldqi");
1992 }
1993
x87_fn(AssemblerX86_64Test::Base * assembler_test ATTRIBUTE_UNUSED,x86_64::X86_64Assembler * assembler)1994 std::string x87_fn(AssemblerX86_64Test::Base* assembler_test ATTRIBUTE_UNUSED,
1995 x86_64::X86_64Assembler* assembler) {
1996 std::ostringstream str;
1997
1998 assembler->fincstp();
1999 str << "fincstp\n";
2000
2001 assembler->fsin();
2002 str << "fsin\n";
2003
2004 assembler->fcos();
2005 str << "fcos\n";
2006
2007 assembler->fptan();
2008 str << "fptan\n";
2009
2010 return str.str();
2011 }
2012
TEST_F(AssemblerX86_64Test,X87)2013 TEST_F(AssemblerX86_64Test, X87) {
2014 DriverFn(&x87_fn, "x87");
2015 }
2016
TEST_F(AssemblerX86_64Test,FPUIntegerLoads)2017 TEST_F(AssemblerX86_64Test, FPUIntegerLoads) {
2018 DriverStr(RepeatA(&x86_64::X86_64Assembler::filds,
2019 addresses_singleton_, // no ext addressing
2020 "fildl {mem}"), "filds");
2021 }
2022
TEST_F(AssemblerX86_64Test,FPUIntegerLoadl)2023 TEST_F(AssemblerX86_64Test, FPUIntegerLoadl) {
2024 DriverStr(RepeatA(&x86_64::X86_64Assembler::fildl,
2025 addresses_singleton_, // no ext addressing
2026 "fildll {mem}"), "fildl");
2027 }
2028
TEST_F(AssemblerX86_64Test,FPUIntegerStores)2029 TEST_F(AssemblerX86_64Test, FPUIntegerStores) {
2030 DriverStr(RepeatA(&x86_64::X86_64Assembler::fistps,
2031 addresses_singleton_, // no ext addressing
2032 "fistpl {mem}"), "fistps");
2033 }
2034
TEST_F(AssemblerX86_64Test,FPUIntegerStorel)2035 TEST_F(AssemblerX86_64Test, FPUIntegerStorel) {
2036 DriverStr(RepeatA(&x86_64::X86_64Assembler::fistpl,
2037 addresses_singleton_, // no ext addressing
2038 "fistpll {mem}"), "fistpl");
2039 }
2040
TEST_F(AssemblerX86_64Test,Call)2041 TEST_F(AssemblerX86_64Test, Call) {
2042 DriverStr(RepeatR(&x86_64::X86_64Assembler::call, "call *%{reg}"), "call");
2043 }
2044
TEST_F(AssemblerX86_64Test,Jmp)2045 TEST_F(AssemblerX86_64Test, Jmp) {
2046 DriverStr(RepeatR(&x86_64::X86_64Assembler::jmp, "jmp *%{reg}"), "jmp");
2047 }
2048
TEST_F(AssemblerX86_64Test,Enter)2049 TEST_F(AssemblerX86_64Test, Enter) {
2050 DriverStr(RepeatI(&x86_64::X86_64Assembler::enter,
2051 /*imm_bytes*/ 2U,
2052 "enter ${imm}, $0", /*non-negative*/ true), "enter");
2053 }
2054
TEST_F(AssemblerX86_64Test,RetImm)2055 TEST_F(AssemblerX86_64Test, RetImm) {
2056 DriverStr(RepeatI(&x86_64::X86_64Assembler::ret,
2057 /*imm_bytes*/ 2U,
2058 "ret ${imm}", /*non-negative*/ true), "ret");
2059 }
2060
ret_and_leave_fn(AssemblerX86_64Test::Base * assembler_test ATTRIBUTE_UNUSED,x86_64::X86_64Assembler * assembler)2061 std::string ret_and_leave_fn(AssemblerX86_64Test::Base* assembler_test ATTRIBUTE_UNUSED,
2062 x86_64::X86_64Assembler* assembler) {
2063 std::ostringstream str;
2064
2065 assembler->ret();
2066 str << "ret\n";
2067
2068 assembler->leave();
2069 str << "leave\n";
2070
2071 return str.str();
2072 }
2073
TEST_F(AssemblerX86_64Test,RetAndLeave)2074 TEST_F(AssemblerX86_64Test, RetAndLeave) {
2075 DriverFn(&ret_and_leave_fn, "retleave");
2076 }
2077
TEST_F(AssemblerX86_64Test,Blsmask)2078 TEST_F(AssemblerX86_64Test, Blsmask) {
2079 DriverStr(RepeatRR(&x86_64::X86_64Assembler::blsmsk, "blsmsk %{reg2}, %{reg1}"), "blsmsk");
2080 }
2081
TEST_F(AssemblerX86_64Test,Blsi)2082 TEST_F(AssemblerX86_64Test, Blsi) {
2083 DriverStr(RepeatRR(&x86_64::X86_64Assembler::blsi, "blsi %{reg2}, %{reg1}"), "blsi");
2084 }
2085
TEST_F(AssemblerX86_64Test,Blsr)2086 TEST_F(AssemblerX86_64Test, Blsr) {
2087 DriverStr(RepeatRR(&x86_64::X86_64Assembler::blsr, "blsr %{reg2}, %{reg1}"), "blsr");
2088 }
2089
TEST_F(AssemblerX86_64Test,Bswapl)2090 TEST_F(AssemblerX86_64Test, Bswapl) {
2091 DriverStr(Repeatr(&x86_64::X86_64Assembler::bswapl, "bswap %{reg}"), "bswapl");
2092 }
2093
TEST_F(AssemblerX86_64Test,Bswapq)2094 TEST_F(AssemblerX86_64Test, Bswapq) {
2095 DriverStr(RepeatR(&x86_64::X86_64Assembler::bswapq, "bswap %{reg}"), "bswapq");
2096 }
2097
TEST_F(AssemblerX86_64Test,Bsfl)2098 TEST_F(AssemblerX86_64Test, Bsfl) {
2099 DriverStr(Repeatrr(&x86_64::X86_64Assembler::bsfl, "bsfl %{reg2}, %{reg1}"), "bsfl");
2100 }
2101
TEST_F(AssemblerX86_64Test,BsflAddress)2102 TEST_F(AssemblerX86_64Test, BsflAddress) {
2103 DriverStr(RepeatrA(&x86_64::X86_64Assembler::bsfl, "bsfl {mem}, %{reg}"), "bsfl_address");
2104 }
2105
TEST_F(AssemblerX86_64Test,Bsfq)2106 TEST_F(AssemblerX86_64Test, Bsfq) {
2107 DriverStr(RepeatRR(&x86_64::X86_64Assembler::bsfq, "bsfq %{reg2}, %{reg1}"), "bsfq");
2108 }
2109
TEST_F(AssemblerX86_64Test,BsfqAddress)2110 TEST_F(AssemblerX86_64Test, BsfqAddress) {
2111 DriverStr(RepeatRA(&x86_64::X86_64Assembler::bsfq, "bsfq {mem}, %{reg}"), "bsfq_address");
2112 }
2113
TEST_F(AssemblerX86_64Test,Bsrl)2114 TEST_F(AssemblerX86_64Test, Bsrl) {
2115 DriverStr(Repeatrr(&x86_64::X86_64Assembler::bsrl, "bsrl %{reg2}, %{reg1}"), "bsrl");
2116 }
2117
TEST_F(AssemblerX86_64Test,BsrlAddress)2118 TEST_F(AssemblerX86_64Test, BsrlAddress) {
2119 DriverStr(RepeatrA(&x86_64::X86_64Assembler::bsrl, "bsrl {mem}, %{reg}"), "bsrl_address");
2120 }
2121
TEST_F(AssemblerX86_64Test,Bsrq)2122 TEST_F(AssemblerX86_64Test, Bsrq) {
2123 DriverStr(RepeatRR(&x86_64::X86_64Assembler::bsrq, "bsrq %{reg2}, %{reg1}"), "bsrq");
2124 }
2125
TEST_F(AssemblerX86_64Test,BsrqAddress)2126 TEST_F(AssemblerX86_64Test, BsrqAddress) {
2127 DriverStr(RepeatRA(&x86_64::X86_64Assembler::bsrq, "bsrq {mem}, %{reg}"), "bsrq_address");
2128 }
2129
TEST_F(AssemblerX86_64Test,Popcntl)2130 TEST_F(AssemblerX86_64Test, Popcntl) {
2131 DriverStr(Repeatrr(&x86_64::X86_64Assembler::popcntl, "popcntl %{reg2}, %{reg1}"), "popcntl");
2132 }
2133
TEST_F(AssemblerX86_64Test,PopcntlAddress)2134 TEST_F(AssemblerX86_64Test, PopcntlAddress) {
2135 DriverStr(RepeatrA(&x86_64::X86_64Assembler::popcntl, "popcntl {mem}, %{reg}"), "popcntl_address");
2136 }
2137
TEST_F(AssemblerX86_64Test,Popcntq)2138 TEST_F(AssemblerX86_64Test, Popcntq) {
2139 DriverStr(RepeatRR(&x86_64::X86_64Assembler::popcntq, "popcntq %{reg2}, %{reg1}"), "popcntq");
2140 }
2141
TEST_F(AssemblerX86_64Test,PopcntqAddress)2142 TEST_F(AssemblerX86_64Test, PopcntqAddress) {
2143 DriverStr(RepeatRA(&x86_64::X86_64Assembler::popcntq, "popcntq {mem}, %{reg}"), "popcntq_address");
2144 }
2145
TEST_F(AssemblerX86_64Test,CmovlAddress)2146 TEST_F(AssemblerX86_64Test, CmovlAddress) {
2147 GetAssembler()->cmov(x86_64::kEqual, x86_64::CpuRegister(x86_64::R10), x86_64::Address(
2148 x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12), false);
2149 GetAssembler()->cmov(x86_64::kNotEqual, x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
2150 x86_64::CpuRegister(x86_64::R10), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12), false);
2151 GetAssembler()->cmov(x86_64::kEqual, x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
2152 x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12), false);
2153 const char* expected =
2154 "cmovzl 0xc(%RDI,%RBX,4), %R10d\n"
2155 "cmovnzl 0xc(%R10,%RBX,4), %edi\n"
2156 "cmovzl 0xc(%RDI,%R9,4), %edi\n";
2157 DriverStr(expected, "cmovl_address");
2158 }
2159
TEST_F(AssemblerX86_64Test,CmovqAddress)2160 TEST_F(AssemblerX86_64Test, CmovqAddress) {
2161 GetAssembler()->cmov(x86_64::kEqual, x86_64::CpuRegister(x86_64::R10), x86_64::Address(
2162 x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12), true);
2163 GetAssembler()->cmov(x86_64::kNotEqual, x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
2164 x86_64::CpuRegister(x86_64::R10), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12), true);
2165 GetAssembler()->cmov(x86_64::kEqual, x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
2166 x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12), true);
2167 const char* expected =
2168 "cmovzq 0xc(%RDI,%RBX,4), %R10\n"
2169 "cmovnzq 0xc(%R10,%RBX,4), %rdi\n"
2170 "cmovzq 0xc(%RDI,%R9,4), %rdi\n";
2171 DriverStr(expected, "cmovq_address");
2172 }
2173
TEST_F(AssemblerX86_64Test,Jrcxz)2174 TEST_F(AssemblerX86_64Test, Jrcxz) {
2175 x86_64::NearLabel target;
2176 GetAssembler()->jrcxz(&target);
2177 GetAssembler()->addl(x86_64::CpuRegister(x86_64::RDI),
2178 x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 4));
2179 GetAssembler()->Bind(&target);
2180 const char* expected =
2181 "jrcxz 1f\n"
2182 "addl 4(%RSP),%EDI\n"
2183 "1:\n";
2184
2185 DriverStr(expected, "jrcxz");
2186 }
2187
TEST_F(AssemblerX86_64Test,NearLabel)2188 TEST_F(AssemblerX86_64Test, NearLabel) {
2189 // Test both forward and backward branches.
2190 x86_64::NearLabel start, target;
2191 GetAssembler()->Bind(&start);
2192 GetAssembler()->j(x86_64::kEqual, &target);
2193 GetAssembler()->jmp(&target);
2194 GetAssembler()->jrcxz(&target);
2195 GetAssembler()->addl(x86_64::CpuRegister(x86_64::RDI),
2196 x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 4));
2197 GetAssembler()->Bind(&target);
2198 GetAssembler()->j(x86_64::kNotEqual, &start);
2199 GetAssembler()->jmp(&start);
2200 const char* expected =
2201 "1: je 2f\n"
2202 "jmp 2f\n"
2203 "jrcxz 2f\n"
2204 "addl 4(%RSP),%EDI\n"
2205 "2: jne 1b\n"
2206 "jmp 1b\n";
2207
2208 DriverStr(expected, "near_label");
2209 }
2210
setcc_test_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)2211 std::string setcc_test_fn(AssemblerX86_64Test::Base* assembler_test,
2212 x86_64::X86_64Assembler* assembler) {
2213 // From Condition
2214 /*
2215 kOverflow = 0,
2216 kNoOverflow = 1,
2217 kBelow = 2,
2218 kAboveEqual = 3,
2219 kEqual = 4,
2220 kNotEqual = 5,
2221 kBelowEqual = 6,
2222 kAbove = 7,
2223 kSign = 8,
2224 kNotSign = 9,
2225 kParityEven = 10,
2226 kParityOdd = 11,
2227 kLess = 12,
2228 kGreaterEqual = 13,
2229 kLessEqual = 14,
2230 */
2231 std::string suffixes[15] = { "o", "no", "b", "ae", "e", "ne", "be", "a", "s", "ns", "pe", "po",
2232 "l", "ge", "le" };
2233
2234 std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
2235 std::ostringstream str;
2236
2237 for (auto reg : registers) {
2238 for (size_t i = 0; i < 15; ++i) {
2239 assembler->setcc(static_cast<x86_64::Condition>(i), *reg);
2240 str << "set" << suffixes[i] << " %" << assembler_test->GetQuaternaryRegisterName(*reg) << "\n";
2241 }
2242 }
2243
2244 return str.str();
2245 }
2246
TEST_F(AssemblerX86_64Test,SetCC)2247 TEST_F(AssemblerX86_64Test, SetCC) {
2248 DriverFn(&setcc_test_fn, "setcc");
2249 }
2250
TEST_F(AssemblerX86_64Test,MovzxbRegs)2251 TEST_F(AssemblerX86_64Test, MovzxbRegs) {
2252 DriverStr(Repeatrb(&x86_64::X86_64Assembler::movzxb, "movzbl %{reg2}, %{reg1}"), "movzxb");
2253 }
2254
TEST_F(AssemblerX86_64Test,MovsxbRegs)2255 TEST_F(AssemblerX86_64Test, MovsxbRegs) {
2256 DriverStr(Repeatrb(&x86_64::X86_64Assembler::movsxb, "movsbl %{reg2}, %{reg1}"), "movsxb");
2257 }
2258
TEST_F(AssemblerX86_64Test,Repnescasw)2259 TEST_F(AssemblerX86_64Test, Repnescasw) {
2260 GetAssembler()->repne_scasw();
2261 const char* expected = "repne scasw\n";
2262 DriverStr(expected, "Repnescasw");
2263 }
2264
TEST_F(AssemblerX86_64Test,Repecmpsw)2265 TEST_F(AssemblerX86_64Test, Repecmpsw) {
2266 GetAssembler()->repe_cmpsw();
2267 const char* expected = "repe cmpsw\n";
2268 DriverStr(expected, "Repecmpsw");
2269 }
2270
TEST_F(AssemblerX86_64Test,Repecmpsl)2271 TEST_F(AssemblerX86_64Test, Repecmpsl) {
2272 GetAssembler()->repe_cmpsl();
2273 const char* expected = "repe cmpsl\n";
2274 DriverStr(expected, "Repecmpsl");
2275 }
2276
TEST_F(AssemblerX86_64Test,Repecmpsq)2277 TEST_F(AssemblerX86_64Test, Repecmpsq) {
2278 GetAssembler()->repe_cmpsq();
2279 const char* expected = "repe cmpsq\n";
2280 DriverStr(expected, "Repecmpsq");
2281 }
2282
TEST_F(AssemblerX86_64Test,Cmpb)2283 TEST_F(AssemblerX86_64Test, Cmpb) {
2284 DriverStr(RepeatAI(&x86_64::X86_64Assembler::cmpb,
2285 /*imm_bytes*/ 1U,
2286 "cmpb ${imm}, {mem}"), "cmpb");
2287 }
2288
TEST_F(AssemblerX86_64Test,TestbAddressImmediate)2289 TEST_F(AssemblerX86_64Test, TestbAddressImmediate) {
2290 DriverStr(RepeatAI(&x86_64::X86_64Assembler::testb,
2291 /*imm_bytes*/ 1U,
2292 "testb ${imm}, {mem}"), "testbi");
2293 }
2294
TEST_F(AssemblerX86_64Test,TestlAddressImmediate)2295 TEST_F(AssemblerX86_64Test, TestlAddressImmediate) {
2296 DriverStr(RepeatAI(&x86_64::X86_64Assembler::testl,
2297 /*imm_bytes*/ 4U,
2298 "testl ${imm}, {mem}"), "testli");
2299 }
2300
2301 class JNIMacroAssemblerX86_64Test : public JNIMacroAssemblerTest<x86_64::X86_64JNIMacroAssembler> {
2302 public:
2303 using Base = JNIMacroAssemblerTest<x86_64::X86_64JNIMacroAssembler>;
2304
2305 protected:
2306 // Get the typically used name for this architecture, e.g., aarch64, x86-64, ...
GetArchitectureString()2307 std::string GetArchitectureString() override {
2308 return "x86_64";
2309 }
2310
GetDisassembleParameters()2311 std::string GetDisassembleParameters() override {
2312 return " -D -bbinary -mi386:x86-64 -Mx86-64,addr64,data32 --no-show-raw-insn";
2313 }
2314
2315 private:
2316 };
2317
ManagedFromCpu(x86_64::Register r)2318 static x86_64::X86_64ManagedRegister ManagedFromCpu(x86_64::Register r) {
2319 return x86_64::X86_64ManagedRegister::FromCpuRegister(r);
2320 }
2321
ManagedFromFpu(x86_64::FloatRegister r)2322 static x86_64::X86_64ManagedRegister ManagedFromFpu(x86_64::FloatRegister r) {
2323 return x86_64::X86_64ManagedRegister::FromXmmRegister(r);
2324 }
2325
buildframe_test_fn(JNIMacroAssemblerX86_64Test::Base * assembler_test ATTRIBUTE_UNUSED,x86_64::X86_64JNIMacroAssembler * assembler)2326 std::string buildframe_test_fn(JNIMacroAssemblerX86_64Test::Base* assembler_test ATTRIBUTE_UNUSED,
2327 x86_64::X86_64JNIMacroAssembler* assembler) {
2328 // TODO: more interesting spill registers / entry spills.
2329
2330 // Two random spill regs.
2331 const ManagedRegister raw_spill_regs[] = {
2332 ManagedFromCpu(x86_64::R10),
2333 ManagedFromCpu(x86_64::RSI)
2334 };
2335 ArrayRef<const ManagedRegister> spill_regs(raw_spill_regs);
2336
2337 // Three random entry spills.
2338 ManagedRegisterEntrySpills entry_spills;
2339 ManagedRegisterSpill spill(ManagedFromCpu(x86_64::RAX), 8, 0);
2340 entry_spills.push_back(spill);
2341 ManagedRegisterSpill spill2(ManagedFromCpu(x86_64::RBX), 8, 8);
2342 entry_spills.push_back(spill2);
2343 ManagedRegisterSpill spill3(ManagedFromFpu(x86_64::XMM1), 8, 16);
2344 entry_spills.push_back(spill3);
2345
2346 x86_64::X86_64ManagedRegister method_reg = ManagedFromCpu(x86_64::RDI);
2347
2348 size_t frame_size = 10 * kStackAlignment;
2349 assembler->BuildFrame(frame_size, method_reg, spill_regs, entry_spills);
2350
2351 // Construct assembly text counterpart.
2352 std::ostringstream str;
2353 // (1) Push the spill_regs.
2354 str << "pushq %rsi\n";
2355 str << "pushq %r10\n";
2356 // (2) Move down the stack pointer.
2357 ssize_t displacement = static_cast<ssize_t>(frame_size) - (spill_regs.size() * 8 + 8);
2358 str << "subq $" << displacement << ", %rsp\n";
2359 // (3) Store method reference.
2360 str << "movq %rdi, (%rsp)\n";
2361 // (4) Entry spills.
2362 str << "movq %rax, " << frame_size + 0 << "(%rsp)\n";
2363 str << "movq %rbx, " << frame_size + 8 << "(%rsp)\n";
2364 str << "movsd %xmm1, " << frame_size + 16 << "(%rsp)\n";
2365
2366 return str.str();
2367 }
2368
TEST_F(JNIMacroAssemblerX86_64Test,BuildFrame)2369 TEST_F(JNIMacroAssemblerX86_64Test, BuildFrame) {
2370 DriverFn(&buildframe_test_fn, "BuildFrame");
2371 }
2372
removeframe_test_fn(JNIMacroAssemblerX86_64Test::Base * assembler_test ATTRIBUTE_UNUSED,x86_64::X86_64JNIMacroAssembler * assembler)2373 std::string removeframe_test_fn(JNIMacroAssemblerX86_64Test::Base* assembler_test ATTRIBUTE_UNUSED,
2374 x86_64::X86_64JNIMacroAssembler* assembler) {
2375 // TODO: more interesting spill registers / entry spills.
2376
2377 // Two random spill regs.
2378 const ManagedRegister raw_spill_regs[] = {
2379 ManagedFromCpu(x86_64::R10),
2380 ManagedFromCpu(x86_64::RSI)
2381 };
2382 ArrayRef<const ManagedRegister> spill_regs(raw_spill_regs);
2383
2384 size_t frame_size = 10 * kStackAlignment;
2385 assembler->RemoveFrame(frame_size, spill_regs, /* may_suspend= */ true);
2386
2387 // Construct assembly text counterpart.
2388 std::ostringstream str;
2389 // (1) Move up the stack pointer.
2390 ssize_t displacement = static_cast<ssize_t>(frame_size) - spill_regs.size() * 8 - 8;
2391 str << "addq $" << displacement << ", %rsp\n";
2392 // (2) Pop spill regs.
2393 str << "popq %r10\n";
2394 str << "popq %rsi\n";
2395 str << "ret\n";
2396
2397 return str.str();
2398 }
2399
TEST_F(JNIMacroAssemblerX86_64Test,RemoveFrame)2400 TEST_F(JNIMacroAssemblerX86_64Test, RemoveFrame) {
2401 DriverFn(&removeframe_test_fn, "RemoveFrame");
2402 }
2403
increaseframe_test_fn(JNIMacroAssemblerX86_64Test::Base * assembler_test ATTRIBUTE_UNUSED,x86_64::X86_64JNIMacroAssembler * assembler)2404 std::string increaseframe_test_fn(
2405 JNIMacroAssemblerX86_64Test::Base* assembler_test ATTRIBUTE_UNUSED,
2406 x86_64::X86_64JNIMacroAssembler* assembler) {
2407 assembler->IncreaseFrameSize(0U);
2408 assembler->IncreaseFrameSize(kStackAlignment);
2409 assembler->IncreaseFrameSize(10 * kStackAlignment);
2410
2411 // Construct assembly text counterpart.
2412 std::ostringstream str;
2413 // Increase by 0 is a NO-OP and ignored by the assembler.
2414 str << "addq $-" << kStackAlignment << ", %rsp\n";
2415 str << "addq $-" << 10 * kStackAlignment << ", %rsp\n";
2416
2417 return str.str();
2418 }
2419
TEST_F(JNIMacroAssemblerX86_64Test,IncreaseFrame)2420 TEST_F(JNIMacroAssemblerX86_64Test, IncreaseFrame) {
2421 DriverFn(&increaseframe_test_fn, "IncreaseFrame");
2422 }
2423
decreaseframe_test_fn(JNIMacroAssemblerX86_64Test::Base * assembler_test ATTRIBUTE_UNUSED,x86_64::X86_64JNIMacroAssembler * assembler)2424 std::string decreaseframe_test_fn(
2425 JNIMacroAssemblerX86_64Test::Base* assembler_test ATTRIBUTE_UNUSED,
2426 x86_64::X86_64JNIMacroAssembler* assembler) {
2427 assembler->DecreaseFrameSize(0U);
2428 assembler->DecreaseFrameSize(kStackAlignment);
2429 assembler->DecreaseFrameSize(10 * kStackAlignment);
2430
2431 // Construct assembly text counterpart.
2432 std::ostringstream str;
2433 // Decrease by 0 is a NO-OP and ignored by the assembler.
2434 str << "addq $" << kStackAlignment << ", %rsp\n";
2435 str << "addq $" << 10 * kStackAlignment << ", %rsp\n";
2436
2437 return str.str();
2438 }
2439
TEST_F(JNIMacroAssemblerX86_64Test,DecreaseFrame)2440 TEST_F(JNIMacroAssemblerX86_64Test, DecreaseFrame) {
2441 DriverFn(&decreaseframe_test_fn, "DecreaseFrame");
2442 }
2443
2444 } // namespace art
2445