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