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,OrqRegs)918 TEST_F(AssemblerX86_64Test, OrqRegs) {
919   DriverStr(RepeatRR(&x86_64::X86_64Assembler::orq, "orq %{reg2}, %{reg1}"), "orq");
920 }
921 
TEST_F(AssemblerX86_64Test,OrlRegs)922 TEST_F(AssemblerX86_64Test, OrlRegs) {
923   DriverStr(Repeatrr(&x86_64::X86_64Assembler::orl, "orl %{reg2}, %{reg1}"), "orl");
924 }
925 
TEST_F(AssemblerX86_64Test,OrlImm)926 TEST_F(AssemblerX86_64Test, OrlImm) {
927   DriverStr(RepeatrI(&x86_64::X86_64Assembler::orl,
928                      /*imm_bytes*/ 4U, "orl ${imm}, %{reg}"), "orli");
929 }
930 
TEST_F(AssemblerX86_64Test,XorqRegs)931 TEST_F(AssemblerX86_64Test, XorqRegs) {
932   DriverStr(RepeatRR(&x86_64::X86_64Assembler::xorq, "xorq %{reg2}, %{reg1}"), "xorq");
933 }
934 
TEST_F(AssemblerX86_64Test,XorqImm)935 TEST_F(AssemblerX86_64Test, XorqImm) {
936   DriverStr(RepeatRI(&x86_64::X86_64Assembler::xorq,
937                      /*imm_bytes*/ 4U, "xorq ${imm}, %{reg}"), "xorqi");
938 }
939 
TEST_F(AssemblerX86_64Test,XorlRegs)940 TEST_F(AssemblerX86_64Test, XorlRegs) {
941   DriverStr(Repeatrr(&x86_64::X86_64Assembler::xorl, "xor %{reg2}, %{reg1}"), "xorl");
942 }
943 
TEST_F(AssemblerX86_64Test,XorlImm)944 TEST_F(AssemblerX86_64Test, XorlImm) {
945   DriverStr(RepeatrI(&x86_64::X86_64Assembler::xorl,
946                      /*imm_bytes*/ 4U, "xor ${imm}, %{reg}"), "xorli");
947 }
948 
TEST_F(AssemblerX86_64Test,Xchgq)949 TEST_F(AssemblerX86_64Test, Xchgq) {
950   DriverStr(RepeatRR(&x86_64::X86_64Assembler::xchgq, "xchgq %{reg1}, %{reg2}"), "xchgq");
951 }
952 
TEST_F(AssemblerX86_64Test,Xchgl)953 TEST_F(AssemblerX86_64Test, Xchgl) {
954   // TODO: Test is disabled because GCC generates 0x87 0xC0 for xchgl eax, eax. All other cases
955   // are the same. Anyone know why it doesn't emit a simple 0x90? It does so for xchgq rax, rax...
956   // DriverStr(Repeatrr(&x86_64::X86_64Assembler::xchgl, "xchgl %{reg2}, %{reg1}"), "xchgl");
957 }
958 
TEST_F(AssemblerX86_64Test,LockCmpxchgl)959 TEST_F(AssemblerX86_64Test, LockCmpxchgl) {
960   DriverStr(RepeatAr(&x86_64::X86_64Assembler::LockCmpxchgl,
961                      "lock cmpxchgl %{reg}, {mem}"), "lock_cmpxchgl");
962 }
963 
TEST_F(AssemblerX86_64Test,LockCmpxchgq)964 TEST_F(AssemblerX86_64Test, LockCmpxchgq) {
965   DriverStr(RepeatAR(&x86_64::X86_64Assembler::LockCmpxchgq,
966                      "lock cmpxchg %{reg}, {mem}"), "lock_cmpxchg");
967 }
968 
TEST_F(AssemblerX86_64Test,MovqStore)969 TEST_F(AssemblerX86_64Test, MovqStore) {
970   DriverStr(RepeatAR(&x86_64::X86_64Assembler::movq, "movq %{reg}, {mem}"), "movq_s");
971 }
972 
TEST_F(AssemblerX86_64Test,MovqLoad)973 TEST_F(AssemblerX86_64Test, MovqLoad) {
974   DriverStr(RepeatRA(&x86_64::X86_64Assembler::movq, "movq {mem}, %{reg}"), "movq_l");
975 }
976 
TEST_F(AssemblerX86_64Test,MovlStore)977 TEST_F(AssemblerX86_64Test, MovlStore) {
978   DriverStr(RepeatAr(&x86_64::X86_64Assembler::movl, "movl %{reg}, {mem}"), "movl_s");
979 }
980 
TEST_F(AssemblerX86_64Test,MovlLoad)981 TEST_F(AssemblerX86_64Test, MovlLoad) {
982   DriverStr(RepeatrA(&x86_64::X86_64Assembler::movl, "movl {mem}, %{reg}"), "movl_l");
983 }
984 
TEST_F(AssemblerX86_64Test,MovwStore)985 TEST_F(AssemblerX86_64Test, MovwStore) {
986   DriverStr(RepeatAw(&x86_64::X86_64Assembler::movw, "movw %{reg}, {mem}"), "movw_s");
987 }
988 
TEST_F(AssemblerX86_64Test,MovbStore)989 TEST_F(AssemblerX86_64Test, MovbStore) {
990   DriverStr(RepeatAb(&x86_64::X86_64Assembler::movb, "movb %{reg}, {mem}"), "movb_s");
991 }
992 
TEST_F(AssemblerX86_64Test,Cmpw)993 TEST_F(AssemblerX86_64Test, Cmpw) {
994   DriverStr(
995       RepeatAI(&x86_64::X86_64Assembler::cmpw, /*imm_bytes*/ 2U, "cmpw ${imm}, {mem}"), "cmpw");
996 }
997 
TEST_F(AssemblerX86_64Test,MovqAddrImm)998 TEST_F(AssemblerX86_64Test, MovqAddrImm) {
999   DriverStr(RepeatAI(&x86_64::X86_64Assembler::movq,
1000                      /*imm_bytes*/ 4U,
1001                      "movq ${imm}, {mem}"), "movq");  // only imm32
1002 }
1003 
TEST_F(AssemblerX86_64Test,MovlAddrImm)1004 TEST_F(AssemblerX86_64Test, MovlAddrImm) {
1005   DriverStr(RepeatAI(&x86_64::X86_64Assembler::movl,
1006                      /*imm_bytes*/ 4U, "movl ${imm}, {mem}"), "movl");
1007 }
1008 
TEST_F(AssemblerX86_64Test,MovwAddrImm)1009 TEST_F(AssemblerX86_64Test, MovwAddrImm) {
1010   DriverStr(RepeatAI(&x86_64::X86_64Assembler::movw,
1011                      /*imm_bytes*/ 2U, "movw ${imm}, {mem}"), "movw");
1012 }
1013 
TEST_F(AssemblerX86_64Test,MovbAddrImm)1014 TEST_F(AssemblerX86_64Test, MovbAddrImm) {
1015   DriverStr(RepeatAI(&x86_64::X86_64Assembler::movb,
1016                      /*imm_bytes*/ 1U, "movb ${imm}, {mem}"), "movb");
1017 }
1018 
TEST_F(AssemblerX86_64Test,Movntl)1019 TEST_F(AssemblerX86_64Test, Movntl) {
1020   DriverStr(RepeatAr(&x86_64::X86_64Assembler::movntl, "movntil %{reg}, {mem}"), "movntl");
1021 }
1022 
TEST_F(AssemblerX86_64Test,Movntq)1023 TEST_F(AssemblerX86_64Test, Movntq) {
1024   DriverStr(RepeatAR(&x86_64::X86_64Assembler::movntq, "movntiq %{reg}, {mem}"), "movntq");
1025 }
1026 
TEST_F(AssemblerX86_64Test,Cvtsi2ssAddr)1027 TEST_F(AssemblerX86_64Test, Cvtsi2ssAddr) {
1028   GetAssembler()->cvtsi2ss(x86_64::XmmRegister(x86_64::XMM0),
1029                            x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0),
1030                            /*is64bit*/ false);
1031   GetAssembler()->cvtsi2ss(x86_64::XmmRegister(x86_64::XMM0),
1032                            x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0),
1033                            /*is64bit*/ true);
1034   const char* expected = "cvtsi2ss 0(%RAX), %xmm0\n"
1035                          "cvtsi2ssq 0(%RAX), %xmm0\n";
1036   DriverStr(expected, "cvtsi2ss");
1037 }
1038 
TEST_F(AssemblerX86_64Test,Cvtsi2sdAddr)1039 TEST_F(AssemblerX86_64Test, Cvtsi2sdAddr) {
1040   GetAssembler()->cvtsi2sd(x86_64::XmmRegister(x86_64::XMM0),
1041                            x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0),
1042                            /*is64bit*/ false);
1043   GetAssembler()->cvtsi2sd(x86_64::XmmRegister(x86_64::XMM0),
1044                            x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0),
1045                            /*is64bit*/ true);
1046   const char* expected = "cvtsi2sd 0(%RAX), %xmm0\n"
1047                          "cvtsi2sdq 0(%RAX), %xmm0\n";
1048   DriverStr(expected, "cvtsi2sd");
1049 }
1050 
TEST_F(AssemblerX86_64Test,CmpqAddr)1051 TEST_F(AssemblerX86_64Test, CmpqAddr) {
1052   DriverStr(RepeatRA(&x86_64::X86_64Assembler::cmpq, "cmpq {mem}, %{reg}"), "cmpq");
1053 }
1054 
TEST_F(AssemblerX86_64Test,MovsxdAddr)1055 TEST_F(AssemblerX86_64Test, MovsxdAddr) {
1056   DriverStr(RepeatRA(&x86_64::X86_64Assembler::movsxd, "movslq {mem}, %{reg}"), "movsxd");
1057 }
1058 
TEST_F(AssemblerX86_64Test,TestqAddr)1059 TEST_F(AssemblerX86_64Test, TestqAddr) {
1060   DriverStr(RepeatRA(&x86_64::X86_64Assembler::testq, "testq {mem}, %{reg}"), "testq");
1061 }
1062 
TEST_F(AssemblerX86_64Test,AddqAddr)1063 TEST_F(AssemblerX86_64Test, AddqAddr) {
1064   DriverStr(RepeatRA(&x86_64::X86_64Assembler::addq, "addq {mem}, %{reg}"), "addq");
1065 }
1066 
TEST_F(AssemblerX86_64Test,SubqAddr)1067 TEST_F(AssemblerX86_64Test, SubqAddr) {
1068   DriverStr(RepeatRA(&x86_64::X86_64Assembler::subq, "subq {mem}, %{reg}"), "subq");
1069 }
1070 
TEST_F(AssemblerX86_64Test,Cvtss2sdAddr)1071 TEST_F(AssemblerX86_64Test, Cvtss2sdAddr) {
1072   DriverStr(RepeatFA(&x86_64::X86_64Assembler::cvtss2sd, "cvtss2sd {mem}, %{reg}"), "cvtss2sd");
1073 }
1074 
TEST_F(AssemblerX86_64Test,Cvtsd2ssAddr)1075 TEST_F(AssemblerX86_64Test, Cvtsd2ssAddr) {
1076   DriverStr(RepeatFA(&x86_64::X86_64Assembler::cvtsd2ss, "cvtsd2ss {mem}, %{reg}"), "cvtsd2ss");
1077 }
1078 
TEST_F(AssemblerX86_64Test,ComissAddr)1079 TEST_F(AssemblerX86_64Test, ComissAddr) {
1080   DriverStr(RepeatFA(&x86_64::X86_64Assembler::comiss, "comiss {mem}, %{reg}"), "comiss");
1081 }
1082 
TEST_F(AssemblerX86_64Test,ComisdAddr)1083 TEST_F(AssemblerX86_64Test, ComisdAddr) {
1084   DriverStr(RepeatFA(&x86_64::X86_64Assembler::comisd, "comisd {mem}, %{reg}"), "comisd");
1085 }
1086 
TEST_F(AssemblerX86_64Test,UComissAddr)1087 TEST_F(AssemblerX86_64Test, UComissAddr) {
1088   DriverStr(RepeatFA(&x86_64::X86_64Assembler::ucomiss, "ucomiss {mem}, %{reg}"), "ucomiss");
1089 }
1090 
TEST_F(AssemblerX86_64Test,UComisdAddr)1091 TEST_F(AssemblerX86_64Test, UComisdAddr) {
1092   DriverStr(RepeatFA(&x86_64::X86_64Assembler::ucomisd, "ucomisd {mem}, %{reg}"), "ucomisd");
1093 }
1094 
TEST_F(AssemblerX86_64Test,Andq)1095 TEST_F(AssemblerX86_64Test, Andq) {
1096   DriverStr(RepeatRA(&x86_64::X86_64Assembler::andq, "andq {mem}, %{reg}"), "andq");
1097 }
1098 
TEST_F(AssemblerX86_64Test,Orq)1099 TEST_F(AssemblerX86_64Test, Orq) {
1100   DriverStr(RepeatRA(&x86_64::X86_64Assembler::orq, "orq {mem}, %{reg}"), "orq");
1101 }
1102 
TEST_F(AssemblerX86_64Test,Xorq)1103 TEST_F(AssemblerX86_64Test, Xorq) {
1104   DriverStr(RepeatRA(&x86_64::X86_64Assembler::xorq, "xorq {mem}, %{reg}"), "xorq");
1105 }
1106 
TEST_F(AssemblerX86_64Test,RepneScasb)1107 TEST_F(AssemblerX86_64Test, RepneScasb) {
1108   GetAssembler()->repne_scasb();
1109   const char* expected = "repne scasb\n";
1110   DriverStr(expected, "repne_scasb");
1111 }
1112 
TEST_F(AssemblerX86_64Test,RepneScasw)1113 TEST_F(AssemblerX86_64Test, RepneScasw) {
1114   GetAssembler()->repne_scasw();
1115   const char* expected = "repne scasw\n";
1116   DriverStr(expected, "repne_scasw");
1117 }
1118 
TEST_F(AssemblerX86_64Test,RepMovsw)1119 TEST_F(AssemblerX86_64Test, RepMovsw) {
1120   GetAssembler()->rep_movsw();
1121   const char* expected = "rep movsw\n";
1122   DriverStr(expected, "rep_movsw");
1123 }
1124 
TEST_F(AssemblerX86_64Test,Movsxd)1125 TEST_F(AssemblerX86_64Test, Movsxd) {
1126   DriverStr(RepeatRr(&x86_64::X86_64Assembler::movsxd, "movslq %{reg2}, %{reg1}"), "movsxd");
1127 }
1128 
TEST_F(AssemblerX86_64Test,Movaps)1129 TEST_F(AssemblerX86_64Test, Movaps) {
1130   DriverStr(RepeatFF(&x86_64::X86_64Assembler::movaps, "movaps %{reg2}, %{reg1}"), "movaps");
1131 }
1132 
TEST_F(AssemblerX86_64AVXTest,VMovaps)1133 TEST_F(AssemblerX86_64AVXTest, VMovaps) {
1134   DriverStr(RepeatFF(&x86_64::X86_64Assembler::vmovaps, "vmovaps %{reg2}, %{reg1}"), "vmovaps");
1135 }
1136 
TEST_F(AssemblerX86_64AVXTest,Movaps)1137 TEST_F(AssemblerX86_64AVXTest, Movaps) {
1138   DriverStr(RepeatFF(&x86_64::X86_64Assembler::movaps, "vmovaps %{reg2}, %{reg1}"), "avx_movaps");
1139 }
1140 
TEST_F(AssemblerX86_64Test,MovapsStore)1141 TEST_F(AssemblerX86_64Test, MovapsStore) {
1142   DriverStr(RepeatAF(&x86_64::X86_64Assembler::movaps, "movaps %{reg}, {mem}"), "movaps_s");
1143 }
1144 
TEST_F(AssemblerX86_64AVXTest,VMovapsStore)1145 TEST_F(AssemblerX86_64AVXTest, VMovapsStore) {
1146   DriverStr(RepeatAF(&x86_64::X86_64Assembler::vmovaps, "vmovaps %{reg}, {mem}"), "vmovaps_s");
1147 }
1148 
TEST_F(AssemblerX86_64AVXTest,MovapsStore)1149 TEST_F(AssemblerX86_64AVXTest, MovapsStore) {
1150   DriverStr(RepeatAF(&x86_64::X86_64Assembler::movaps, "vmovaps %{reg}, {mem}"), "avx_movaps_s");
1151 }
1152 
TEST_F(AssemblerX86_64Test,MovapsLoad)1153 TEST_F(AssemblerX86_64Test, MovapsLoad) {
1154   DriverStr(RepeatFA(&x86_64::X86_64Assembler::movaps, "movaps {mem}, %{reg}"), "movaps_l");
1155 }
1156 
TEST_F(AssemblerX86_64AVXTest,VMovapsLoad)1157 TEST_F(AssemblerX86_64AVXTest, VMovapsLoad) {
1158   DriverStr(RepeatFA(&x86_64::X86_64Assembler::vmovaps, "vmovaps {mem}, %{reg}"), "vmovaps_l");
1159 }
1160 
TEST_F(AssemblerX86_64AVXTest,MovapsLoad)1161 TEST_F(AssemblerX86_64AVXTest, MovapsLoad) {
1162   DriverStr(RepeatFA(&x86_64::X86_64Assembler::movaps, "vmovaps {mem}, %{reg}"), "avx_movaps_l");
1163 }
1164 
TEST_F(AssemblerX86_64Test,MovupsStore)1165 TEST_F(AssemblerX86_64Test, MovupsStore) {
1166   DriverStr(RepeatAF(&x86_64::X86_64Assembler::movups, "movups %{reg}, {mem}"), "movups_s");
1167 }
1168 
TEST_F(AssemblerX86_64AVXTest,VMovupsStore)1169 TEST_F(AssemblerX86_64AVXTest, VMovupsStore) {
1170   DriverStr(RepeatAF(&x86_64::X86_64Assembler::vmovups, "vmovups %{reg}, {mem}"), "vmovups_s");
1171 }
1172 
TEST_F(AssemblerX86_64AVXTest,MovupsStore)1173 TEST_F(AssemblerX86_64AVXTest, MovupsStore) {
1174   DriverStr(RepeatAF(&x86_64::X86_64Assembler::movups, "vmovups %{reg}, {mem}"), "avx_movups_s");
1175 }
1176 
TEST_F(AssemblerX86_64Test,MovupsLoad)1177 TEST_F(AssemblerX86_64Test, MovupsLoad) {
1178   DriverStr(RepeatFA(&x86_64::X86_64Assembler::movups, "movups {mem}, %{reg}"), "movups_l");
1179 }
1180 
TEST_F(AssemblerX86_64AVXTest,VMovupsLoad)1181 TEST_F(AssemblerX86_64AVXTest, VMovupsLoad) {
1182   DriverStr(RepeatFA(&x86_64::X86_64Assembler::vmovups, "vmovups {mem}, %{reg}"), "vmovups_l");
1183 }
1184 
TEST_F(AssemblerX86_64AVXTest,MovupsLoad)1185 TEST_F(AssemblerX86_64AVXTest, MovupsLoad) {
1186   DriverStr(RepeatFA(&x86_64::X86_64Assembler::movups, "vmovups {mem}, %{reg}"), "avx_movups_l");
1187 }
1188 
TEST_F(AssemblerX86_64Test,Movss)1189 TEST_F(AssemblerX86_64Test, Movss) {
1190   DriverStr(RepeatFF(&x86_64::X86_64Assembler::movss, "movss %{reg2}, %{reg1}"), "movss");
1191 }
1192 
TEST_F(AssemblerX86_64Test,Movapd)1193 TEST_F(AssemblerX86_64Test, Movapd) {
1194   DriverStr(RepeatFF(&x86_64::X86_64Assembler::movapd, "movapd %{reg2}, %{reg1}"), "movapd");
1195 }
1196 
TEST_F(AssemblerX86_64AVXTest,VMovapd)1197 TEST_F(AssemblerX86_64AVXTest, VMovapd) {
1198   DriverStr(RepeatFF(&x86_64::X86_64Assembler::vmovapd, "vmovapd %{reg2}, %{reg1}"), "vmovapd");
1199 }
1200 
TEST_F(AssemblerX86_64AVXTest,Movapd)1201 TEST_F(AssemblerX86_64AVXTest, Movapd) {
1202   DriverStr(RepeatFF(&x86_64::X86_64Assembler::movapd, "vmovapd %{reg2}, %{reg1}"), "avx_movapd");
1203 }
1204 
TEST_F(AssemblerX86_64Test,MovapdStore)1205 TEST_F(AssemblerX86_64Test, MovapdStore) {
1206   DriverStr(RepeatAF(&x86_64::X86_64Assembler::movapd, "movapd %{reg}, {mem}"), "movapd_s");
1207 }
1208 
TEST_F(AssemblerX86_64AVXTest,VMovapdStore)1209 TEST_F(AssemblerX86_64AVXTest, VMovapdStore) {
1210   DriverStr(RepeatAF(&x86_64::X86_64Assembler::vmovapd, "vmovapd %{reg}, {mem}"), "vmovapd_s");
1211 }
1212 
TEST_F(AssemblerX86_64AVXTest,MovapdStore)1213 TEST_F(AssemblerX86_64AVXTest, MovapdStore) {
1214   DriverStr(RepeatAF(&x86_64::X86_64Assembler::movapd, "vmovapd %{reg}, {mem}"), "avx_movapd_s");
1215 }
1216 
TEST_F(AssemblerX86_64Test,MovapdLoad)1217 TEST_F(AssemblerX86_64Test, MovapdLoad) {
1218   DriverStr(RepeatFA(&x86_64::X86_64Assembler::movapd, "movapd {mem}, %{reg}"), "movapd_l");
1219 }
1220 
TEST_F(AssemblerX86_64AVXTest,VMovapdLoad)1221 TEST_F(AssemblerX86_64AVXTest, VMovapdLoad) {
1222   DriverStr(RepeatFA(&x86_64::X86_64Assembler::vmovapd, "vmovapd {mem}, %{reg}"), "vmovapd_l");
1223 }
1224 
TEST_F(AssemblerX86_64AVXTest,MovapdLoad)1225 TEST_F(AssemblerX86_64AVXTest, MovapdLoad) {
1226   DriverStr(RepeatFA(&x86_64::X86_64Assembler::movapd, "vmovapd {mem}, %{reg}"), "avx_movapd_l");
1227 }
1228 
TEST_F(AssemblerX86_64Test,MovupdStore)1229 TEST_F(AssemblerX86_64Test, MovupdStore) {
1230   DriverStr(RepeatAF(&x86_64::X86_64Assembler::movupd, "movupd %{reg}, {mem}"), "movupd_s");
1231 }
1232 
TEST_F(AssemblerX86_64AVXTest,VMovupdStore)1233 TEST_F(AssemblerX86_64AVXTest, VMovupdStore) {
1234   DriverStr(RepeatAF(&x86_64::X86_64Assembler::vmovupd, "vmovupd %{reg}, {mem}"), "vmovupd_s");
1235 }
1236 
TEST_F(AssemblerX86_64AVXTest,MovupdStore)1237 TEST_F(AssemblerX86_64AVXTest, MovupdStore) {
1238   DriverStr(RepeatAF(&x86_64::X86_64Assembler::movupd, "vmovupd %{reg}, {mem}"), "avx_movupd_s");
1239 }
1240 
TEST_F(AssemblerX86_64Test,MovupdLoad)1241 TEST_F(AssemblerX86_64Test, MovupdLoad) {
1242   DriverStr(RepeatFA(&x86_64::X86_64Assembler::movupd, "movupd {mem}, %{reg}"), "movupd_l");
1243 }
1244 
TEST_F(AssemblerX86_64AVXTest,VMovupdLoad)1245 TEST_F(AssemblerX86_64AVXTest, VMovupdLoad) {
1246   DriverStr(RepeatFA(&x86_64::X86_64Assembler::vmovupd, "vmovupd {mem}, %{reg}"), "vmovupd_l");
1247 }
1248 
TEST_F(AssemblerX86_64AVXTest,MovupdLoad)1249 TEST_F(AssemblerX86_64AVXTest, MovupdLoad) {
1250   DriverStr(RepeatFA(&x86_64::X86_64Assembler::movupd, "vmovupd {mem}, %{reg}"), "avx_movupd_l");
1251 }
1252 
TEST_F(AssemblerX86_64Test,Movsd)1253 TEST_F(AssemblerX86_64Test, Movsd) {
1254   DriverStr(RepeatFF(&x86_64::X86_64Assembler::movsd, "movsd %{reg2}, %{reg1}"), "movsd");
1255 }
1256 
TEST_F(AssemblerX86_64Test,Movdqa)1257 TEST_F(AssemblerX86_64Test, Movdqa) {
1258   DriverStr(RepeatFF(&x86_64::X86_64Assembler::movdqa, "movdqa %{reg2}, %{reg1}"), "movdqa");
1259 }
1260 
TEST_F(AssemblerX86_64AVXTest,VMovdqa)1261 TEST_F(AssemblerX86_64AVXTest, VMovdqa) {
1262   DriverStr(RepeatFF(&x86_64::X86_64Assembler::vmovdqa, "vmovdqa %{reg2}, %{reg1}"), "vmovdqa");
1263 }
1264 
TEST_F(AssemblerX86_64AVXTest,Movdqa)1265 TEST_F(AssemblerX86_64AVXTest, Movdqa) {
1266   DriverStr(RepeatFF(&x86_64::X86_64Assembler::movdqa, "vmovdqa %{reg2}, %{reg1}"), "avx_movdqa");
1267 }
1268 
TEST_F(AssemblerX86_64Test,MovdqaStore)1269 TEST_F(AssemblerX86_64Test, MovdqaStore) {
1270   DriverStr(RepeatAF(&x86_64::X86_64Assembler::movdqa, "movdqa %{reg}, {mem}"), "movdqa_s");
1271 }
1272 
TEST_F(AssemblerX86_64AVXTest,VMovdqaStore)1273 TEST_F(AssemblerX86_64AVXTest, VMovdqaStore) {
1274   DriverStr(RepeatAF(&x86_64::X86_64Assembler::vmovdqa, "vmovdqa %{reg}, {mem}"), "vmovdqa_s");
1275 }
1276 
TEST_F(AssemblerX86_64AVXTest,MovdqaStore)1277 TEST_F(AssemblerX86_64AVXTest, MovdqaStore) {
1278   DriverStr(RepeatAF(&x86_64::X86_64Assembler::movdqa, "vmovdqa %{reg}, {mem}"), "avx_movdqa_s");
1279 }
1280 
TEST_F(AssemblerX86_64Test,MovdqaLoad)1281 TEST_F(AssemblerX86_64Test, MovdqaLoad) {
1282   DriverStr(RepeatFA(&x86_64::X86_64Assembler::movdqa, "movdqa {mem}, %{reg}"), "movdqa_l");
1283 }
1284 
TEST_F(AssemblerX86_64AVXTest,VMovdqaLoad)1285 TEST_F(AssemblerX86_64AVXTest, VMovdqaLoad) {
1286   DriverStr(RepeatFA(&x86_64::X86_64Assembler::vmovdqa, "vmovdqa {mem}, %{reg}"), "vmovdqa_l");
1287 }
1288 
TEST_F(AssemblerX86_64AVXTest,MovdqaLoad)1289 TEST_F(AssemblerX86_64AVXTest, MovdqaLoad) {
1290   DriverStr(RepeatFA(&x86_64::X86_64Assembler::movdqa, "vmovdqa {mem}, %{reg}"), "avx_movdqa_l");
1291 }
1292 
TEST_F(AssemblerX86_64Test,MovdquStore)1293 TEST_F(AssemblerX86_64Test, MovdquStore) {
1294   DriverStr(RepeatAF(&x86_64::X86_64Assembler::movdqu, "movdqu %{reg}, {mem}"), "movdqu_s");
1295 }
1296 
TEST_F(AssemblerX86_64AVXTest,VMovdquStore)1297 TEST_F(AssemblerX86_64AVXTest, VMovdquStore) {
1298   DriverStr(RepeatAF(&x86_64::X86_64Assembler::vmovdqu, "vmovdqu %{reg}, {mem}"), "vmovdqu_s");
1299 }
1300 
TEST_F(AssemblerX86_64AVXTest,MovdquStore)1301 TEST_F(AssemblerX86_64AVXTest, MovdquStore) {
1302   DriverStr(RepeatAF(&x86_64::X86_64Assembler::movdqu, "vmovdqu %{reg}, {mem}"), "avx_movdqu_s");
1303 }
1304 
TEST_F(AssemblerX86_64Test,MovdquLoad)1305 TEST_F(AssemblerX86_64Test, MovdquLoad) {
1306   DriverStr(RepeatFA(&x86_64::X86_64Assembler::movdqu, "movdqu {mem}, %{reg}"), "movdqu_l");
1307 }
1308 
TEST_F(AssemblerX86_64AVXTest,VMovdquLoad)1309 TEST_F(AssemblerX86_64AVXTest, VMovdquLoad) {
1310   DriverStr(RepeatFA(&x86_64::X86_64Assembler::vmovdqu, "vmovdqu {mem}, %{reg}"), "vmovdqu_l");
1311 }
1312 
TEST_F(AssemblerX86_64AVXTest,MovdquLoad)1313 TEST_F(AssemblerX86_64AVXTest, MovdquLoad) {
1314   DriverStr(RepeatFA(&x86_64::X86_64Assembler::movdqu, "vmovdqu {mem}, %{reg}"), "avx_movdqu_l");
1315 }
1316 
TEST_F(AssemblerX86_64Test,Movd1)1317 TEST_F(AssemblerX86_64Test, Movd1) {
1318   DriverStr(RepeatFR(&x86_64::X86_64Assembler::movd, "movd %{reg2}, %{reg1}"), "movd.1");
1319 }
1320 
TEST_F(AssemblerX86_64Test,Movd2)1321 TEST_F(AssemblerX86_64Test, Movd2) {
1322   DriverStr(RepeatRF(&x86_64::X86_64Assembler::movd, "movd %{reg2}, %{reg1}"), "movd.2");
1323 }
1324 
TEST_F(AssemblerX86_64Test,Addss)1325 TEST_F(AssemblerX86_64Test, Addss) {
1326   DriverStr(RepeatFF(&x86_64::X86_64Assembler::addss, "addss %{reg2}, %{reg1}"), "addss");
1327 }
1328 
TEST_F(AssemblerX86_64Test,Addsd)1329 TEST_F(AssemblerX86_64Test, Addsd) {
1330   DriverStr(RepeatFF(&x86_64::X86_64Assembler::addsd, "addsd %{reg2}, %{reg1}"), "addsd");
1331 }
1332 
TEST_F(AssemblerX86_64Test,Addps)1333 TEST_F(AssemblerX86_64Test, Addps) {
1334   DriverStr(RepeatFF(&x86_64::X86_64Assembler::addps, "addps %{reg2}, %{reg1}"), "addps");
1335 }
1336 
TEST_F(AssemblerX86_64AVXTest,VAddps)1337 TEST_F(AssemblerX86_64AVXTest, VAddps) {
1338   DriverStr(
1339       RepeatFFF(&x86_64::X86_64Assembler::vaddps, "vaddps %{reg3}, %{reg2}, %{reg1}"), "vaddps");
1340 }
1341 
TEST_F(AssemblerX86_64Test,Addpd)1342 TEST_F(AssemblerX86_64Test, Addpd) {
1343   DriverStr(RepeatFF(&x86_64::X86_64Assembler::addpd, "addpd %{reg2}, %{reg1}"), "addpd");
1344 }
1345 
TEST_F(AssemblerX86_64AVXTest,VAddpd)1346 TEST_F(AssemblerX86_64AVXTest, VAddpd) {
1347   DriverStr(
1348       RepeatFFF(&x86_64::X86_64Assembler::vaddpd, "vaddpd %{reg3}, %{reg2}, %{reg1}"), "vaddpd");
1349 }
1350 
TEST_F(AssemblerX86_64Test,Subss)1351 TEST_F(AssemblerX86_64Test, Subss) {
1352   DriverStr(RepeatFF(&x86_64::X86_64Assembler::subss, "subss %{reg2}, %{reg1}"), "subss");
1353 }
1354 
TEST_F(AssemblerX86_64Test,Subsd)1355 TEST_F(AssemblerX86_64Test, Subsd) {
1356   DriverStr(RepeatFF(&x86_64::X86_64Assembler::subsd, "subsd %{reg2}, %{reg1}"), "subsd");
1357 }
1358 
TEST_F(AssemblerX86_64Test,Subps)1359 TEST_F(AssemblerX86_64Test, Subps) {
1360   DriverStr(RepeatFF(&x86_64::X86_64Assembler::subps, "subps %{reg2}, %{reg1}"), "subps");
1361 }
1362 
TEST_F(AssemblerX86_64AVXTest,VSubps)1363 TEST_F(AssemblerX86_64AVXTest, VSubps) {
1364   DriverStr(
1365       RepeatFFF(&x86_64::X86_64Assembler::vsubps, "vsubps %{reg3},%{reg2}, %{reg1}"), "vsubps");
1366 }
1367 
TEST_F(AssemblerX86_64Test,Subpd)1368 TEST_F(AssemblerX86_64Test, Subpd) {
1369   DriverStr(RepeatFF(&x86_64::X86_64Assembler::subpd, "subpd %{reg2}, %{reg1}"), "subpd");
1370 }
1371 
TEST_F(AssemblerX86_64AVXTest,VSubpd)1372 TEST_F(AssemblerX86_64AVXTest, VSubpd) {
1373   DriverStr(
1374       RepeatFFF(&x86_64::X86_64Assembler::vsubpd, "vsubpd %{reg3}, %{reg2}, %{reg1}"), "vsubpd");
1375 }
1376 
TEST_F(AssemblerX86_64Test,Mulss)1377 TEST_F(AssemblerX86_64Test, Mulss) {
1378   DriverStr(RepeatFF(&x86_64::X86_64Assembler::mulss, "mulss %{reg2}, %{reg1}"), "mulss");
1379 }
1380 
TEST_F(AssemblerX86_64Test,Mulsd)1381 TEST_F(AssemblerX86_64Test, Mulsd) {
1382   DriverStr(RepeatFF(&x86_64::X86_64Assembler::mulsd, "mulsd %{reg2}, %{reg1}"), "mulsd");
1383 }
1384 
TEST_F(AssemblerX86_64Test,Mulps)1385 TEST_F(AssemblerX86_64Test, Mulps) {
1386   DriverStr(RepeatFF(&x86_64::X86_64Assembler::mulps, "mulps %{reg2}, %{reg1}"), "mulps");
1387 }
1388 
TEST_F(AssemblerX86_64AVXTest,VMulps)1389 TEST_F(AssemblerX86_64AVXTest, VMulps) {
1390   DriverStr(
1391       RepeatFFF(&x86_64::X86_64Assembler::vmulps, "vmulps %{reg3}, %{reg2}, %{reg1}"), "vmulps");
1392 }
1393 
TEST_F(AssemblerX86_64Test,Mulpd)1394 TEST_F(AssemblerX86_64Test, Mulpd) {
1395   DriverStr(RepeatFF(&x86_64::X86_64Assembler::mulpd, "mulpd %{reg2}, %{reg1}"), "mulpd");
1396 }
1397 
TEST_F(AssemblerX86_64AVXTest,VMulpd)1398 TEST_F(AssemblerX86_64AVXTest, VMulpd) {
1399   DriverStr(
1400       RepeatFFF(&x86_64::X86_64Assembler::vmulpd, "vmulpd %{reg3}, %{reg2}, %{reg1}"), "vmulpd");
1401 }
1402 
TEST_F(AssemblerX86_64Test,Divss)1403 TEST_F(AssemblerX86_64Test, Divss) {
1404   DriverStr(RepeatFF(&x86_64::X86_64Assembler::divss, "divss %{reg2}, %{reg1}"), "divss");
1405 }
1406 
TEST_F(AssemblerX86_64Test,Divsd)1407 TEST_F(AssemblerX86_64Test, Divsd) {
1408   DriverStr(RepeatFF(&x86_64::X86_64Assembler::divsd, "divsd %{reg2}, %{reg1}"), "divsd");
1409 }
1410 
TEST_F(AssemblerX86_64Test,Divps)1411 TEST_F(AssemblerX86_64Test, Divps) {
1412   DriverStr(RepeatFF(&x86_64::X86_64Assembler::divps, "divps %{reg2}, %{reg1}"), "divps");
1413 }
1414 
TEST_F(AssemblerX86_64AVXTest,VDivps)1415 TEST_F(AssemblerX86_64AVXTest, VDivps) {
1416   DriverStr(
1417       RepeatFFF(&x86_64::X86_64Assembler::vdivps, "vdivps %{reg3}, %{reg2}, %{reg1}"), "vdivps");
1418 }
1419 
TEST_F(AssemblerX86_64Test,Divpd)1420 TEST_F(AssemblerX86_64Test, Divpd) {
1421   DriverStr(RepeatFF(&x86_64::X86_64Assembler::divpd, "divpd %{reg2}, %{reg1}"), "divpd");
1422 }
1423 
TEST_F(AssemblerX86_64AVXTest,VDivpd)1424 TEST_F(AssemblerX86_64AVXTest, VDivpd) {
1425   DriverStr(
1426       RepeatFFF(&x86_64::X86_64Assembler::vdivpd, "vdivpd %{reg3}, %{reg2}, %{reg1}"), "vdivpd");
1427 }
1428 
TEST_F(AssemblerX86_64Test,Paddb)1429 TEST_F(AssemblerX86_64Test, Paddb) {
1430   DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddb, "paddb %{reg2}, %{reg1}"), "paddb");
1431 }
1432 
TEST_F(AssemblerX86_64AVXTest,VPaddb)1433 TEST_F(AssemblerX86_64AVXTest, VPaddb) {
1434   DriverStr(
1435       RepeatFFF(&x86_64::X86_64Assembler::vpaddb, "vpaddb %{reg3}, %{reg2}, %{reg1}"), "vpaddb");
1436 }
1437 
TEST_F(AssemblerX86_64Test,Psubb)1438 TEST_F(AssemblerX86_64Test, Psubb) {
1439   DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubb, "psubb %{reg2}, %{reg1}"), "psubb");
1440 }
1441 
TEST_F(AssemblerX86_64AVXTest,VPsubb)1442 TEST_F(AssemblerX86_64AVXTest, VPsubb) {
1443   DriverStr(
1444       RepeatFFF(&x86_64::X86_64Assembler::vpsubb, "vpsubb %{reg3},%{reg2}, %{reg1}"), "vpsubb");
1445 }
1446 
TEST_F(AssemblerX86_64Test,Paddw)1447 TEST_F(AssemblerX86_64Test, Paddw) {
1448   DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddw, "paddw %{reg2}, %{reg1}"), "paddw");
1449 }
1450 
TEST_F(AssemblerX86_64AVXTest,VPsubw)1451 TEST_F(AssemblerX86_64AVXTest, VPsubw) {
1452   DriverStr(
1453       RepeatFFF(&x86_64::X86_64Assembler::vpsubw, "vpsubw %{reg3}, %{reg2}, %{reg1}"), "vpsubw");
1454 }
1455 
TEST_F(AssemblerX86_64AVXTest,VPaddw)1456 TEST_F(AssemblerX86_64AVXTest, VPaddw) {
1457   DriverStr(
1458       RepeatFFF(&x86_64::X86_64Assembler::vpaddw, "vpaddw %{reg3}, %{reg2}, %{reg1}"), "vpaddw");
1459 }
1460 
TEST_F(AssemblerX86_64Test,Psubw)1461 TEST_F(AssemblerX86_64Test, Psubw) {
1462   DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubw, "psubw %{reg2}, %{reg1}"), "psubw");
1463 }
1464 
TEST_F(AssemblerX86_64Test,Pmullw)1465 TEST_F(AssemblerX86_64Test, Pmullw) {
1466   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmullw, "pmullw %{reg2}, %{reg1}"), "pmullw");
1467 }
1468 
TEST_F(AssemblerX86_64AVXTest,VPmullw)1469 TEST_F(AssemblerX86_64AVXTest, VPmullw) {
1470   DriverStr(
1471       RepeatFFF(&x86_64::X86_64Assembler::vpmullw, "vpmullw %{reg3}, %{reg2}, %{reg1}"), "vpmullw");
1472 }
1473 
TEST_F(AssemblerX86_64Test,Paddd)1474 TEST_F(AssemblerX86_64Test, Paddd) {
1475   DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddd, "paddd %{reg2}, %{reg1}"), "paddd");
1476 }
1477 
TEST_F(AssemblerX86_64AVXTest,VPaddd)1478 TEST_F(AssemblerX86_64AVXTest, VPaddd) {
1479   DriverStr(
1480       RepeatFFF(&x86_64::X86_64Assembler::vpaddd, "vpaddd %{reg3}, %{reg2}, %{reg1}"), "vpaddd");
1481 }
1482 
TEST_F(AssemblerX86_64Test,Psubd)1483 TEST_F(AssemblerX86_64Test, Psubd) {
1484   DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubd, "psubd %{reg2}, %{reg1}"), "psubd");
1485 }
1486 
TEST_F(AssemblerX86_64AVXTest,VPsubd)1487 TEST_F(AssemblerX86_64AVXTest, VPsubd) {
1488   DriverStr(
1489       RepeatFFF(&x86_64::X86_64Assembler::vpsubd, "vpsubd %{reg3}, %{reg2}, %{reg1}"), "vpsubd");
1490 }
1491 
TEST_F(AssemblerX86_64Test,Pmulld)1492 TEST_F(AssemblerX86_64Test, Pmulld) {
1493   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmulld, "pmulld %{reg2}, %{reg1}"), "pmulld");
1494 }
1495 
TEST_F(AssemblerX86_64AVXTest,VPmulld)1496 TEST_F(AssemblerX86_64AVXTest, VPmulld) {
1497   DriverStr(
1498       RepeatFFF(&x86_64::X86_64Assembler::vpmulld, "vpmulld %{reg3}, %{reg2}, %{reg1}"), "vpmulld");
1499 }
1500 
TEST_F(AssemblerX86_64Test,Paddq)1501 TEST_F(AssemblerX86_64Test, Paddq) {
1502   DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddq, "paddq %{reg2}, %{reg1}"), "paddq");
1503 }
1504 
TEST_F(AssemblerX86_64AVXTest,VPaddq)1505 TEST_F(AssemblerX86_64AVXTest, VPaddq) {
1506   DriverStr(
1507       RepeatFFF(&x86_64::X86_64Assembler::vpaddq, "vpaddq %{reg3}, %{reg2}, %{reg1}"), "vpaddq");
1508 }
1509 
TEST_F(AssemblerX86_64Test,Psubq)1510 TEST_F(AssemblerX86_64Test, Psubq) {
1511   DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubq, "psubq %{reg2}, %{reg1}"), "psubq");
1512 }
1513 
TEST_F(AssemblerX86_64AVXTest,VPsubq)1514 TEST_F(AssemblerX86_64AVXTest, VPsubq) {
1515   DriverStr(
1516       RepeatFFF(&x86_64::X86_64Assembler::vpsubq, "vpsubq %{reg3}, %{reg2}, %{reg1}"), "vpsubq");
1517 }
1518 
TEST_F(AssemblerX86_64Test,Paddusb)1519 TEST_F(AssemblerX86_64Test, Paddusb) {
1520   DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddusb, "paddusb %{reg2}, %{reg1}"), "paddusb");
1521 }
1522 
TEST_F(AssemblerX86_64Test,Paddsb)1523 TEST_F(AssemblerX86_64Test, Paddsb) {
1524   DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddsb, "paddsb %{reg2}, %{reg1}"), "paddsb");
1525 }
1526 
TEST_F(AssemblerX86_64Test,Paddusw)1527 TEST_F(AssemblerX86_64Test, Paddusw) {
1528   DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddusw, "paddusw %{reg2}, %{reg1}"), "paddusw");
1529 }
1530 
TEST_F(AssemblerX86_64Test,Paddsw)1531 TEST_F(AssemblerX86_64Test, Paddsw) {
1532   DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddsw, "paddsw %{reg2}, %{reg1}"), "paddsw");
1533 }
1534 
TEST_F(AssemblerX86_64Test,Psubusb)1535 TEST_F(AssemblerX86_64Test, Psubusb) {
1536   DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubusb, "psubusb %{reg2}, %{reg1}"), "psubusb");
1537 }
1538 
TEST_F(AssemblerX86_64Test,Psubsb)1539 TEST_F(AssemblerX86_64Test, Psubsb) {
1540   DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubsb, "psubsb %{reg2}, %{reg1}"), "psubsb");
1541 }
1542 
TEST_F(AssemblerX86_64Test,Psubusw)1543 TEST_F(AssemblerX86_64Test, Psubusw) {
1544   DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubusw, "psubusw %{reg2}, %{reg1}"), "psubusw");
1545 }
1546 
TEST_F(AssemblerX86_64Test,Psubsw)1547 TEST_F(AssemblerX86_64Test, Psubsw) {
1548   DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubsw, "psubsw %{reg2}, %{reg1}"), "psubsw");
1549 }
1550 
TEST_F(AssemblerX86_64Test,Cvtsi2ss)1551 TEST_F(AssemblerX86_64Test, Cvtsi2ss) {
1552   DriverStr(RepeatFr(&x86_64::X86_64Assembler::cvtsi2ss, "cvtsi2ss %{reg2}, %{reg1}"), "cvtsi2ss");
1553 }
1554 
TEST_F(AssemblerX86_64Test,Cvtsi2sd)1555 TEST_F(AssemblerX86_64Test, Cvtsi2sd) {
1556   DriverStr(RepeatFr(&x86_64::X86_64Assembler::cvtsi2sd, "cvtsi2sd %{reg2}, %{reg1}"), "cvtsi2sd");
1557 }
1558 
TEST_F(AssemblerX86_64Test,Cvtss2si)1559 TEST_F(AssemblerX86_64Test, Cvtss2si) {
1560   DriverStr(RepeatrF(&x86_64::X86_64Assembler::cvtss2si, "cvtss2si %{reg2}, %{reg1}"), "cvtss2si");
1561 }
1562 
TEST_F(AssemblerX86_64Test,Cvtss2sd)1563 TEST_F(AssemblerX86_64Test, Cvtss2sd) {
1564   DriverStr(RepeatFF(&x86_64::X86_64Assembler::cvtss2sd, "cvtss2sd %{reg2}, %{reg1}"), "cvtss2sd");
1565 }
1566 
TEST_F(AssemblerX86_64Test,Cvtsd2si)1567 TEST_F(AssemblerX86_64Test, Cvtsd2si) {
1568   DriverStr(RepeatrF(&x86_64::X86_64Assembler::cvtsd2si, "cvtsd2si %{reg2}, %{reg1}"), "cvtsd2si");
1569 }
1570 
TEST_F(AssemblerX86_64Test,Cvttss2si)1571 TEST_F(AssemblerX86_64Test, Cvttss2si) {
1572   DriverStr(RepeatrF(&x86_64::X86_64Assembler::cvttss2si, "cvttss2si %{reg2}, %{reg1}"),
1573             "cvttss2si");
1574 }
1575 
TEST_F(AssemblerX86_64Test,Cvttsd2si)1576 TEST_F(AssemblerX86_64Test, Cvttsd2si) {
1577   DriverStr(RepeatrF(&x86_64::X86_64Assembler::cvttsd2si, "cvttsd2si %{reg2}, %{reg1}"),
1578             "cvttsd2si");
1579 }
1580 
TEST_F(AssemblerX86_64Test,Cvtsd2ss)1581 TEST_F(AssemblerX86_64Test, Cvtsd2ss) {
1582   DriverStr(RepeatFF(&x86_64::X86_64Assembler::cvtsd2ss, "cvtsd2ss %{reg2}, %{reg1}"), "cvtsd2ss");
1583 }
1584 
TEST_F(AssemblerX86_64Test,Cvtdq2ps)1585 TEST_F(AssemblerX86_64Test, Cvtdq2ps) {
1586   DriverStr(RepeatFF(&x86_64::X86_64Assembler::cvtdq2ps, "cvtdq2ps %{reg2}, %{reg1}"), "cvtdq2ps");
1587 }
1588 
TEST_F(AssemblerX86_64Test,Cvtdq2pd)1589 TEST_F(AssemblerX86_64Test, Cvtdq2pd) {
1590   DriverStr(RepeatFF(&x86_64::X86_64Assembler::cvtdq2pd, "cvtdq2pd %{reg2}, %{reg1}"), "cvtdq2pd");
1591 }
1592 
TEST_F(AssemblerX86_64Test,Comiss)1593 TEST_F(AssemblerX86_64Test, Comiss) {
1594   DriverStr(RepeatFF(&x86_64::X86_64Assembler::comiss, "comiss %{reg2}, %{reg1}"), "comiss");
1595 }
1596 
TEST_F(AssemblerX86_64Test,Comisd)1597 TEST_F(AssemblerX86_64Test, Comisd) {
1598   DriverStr(RepeatFF(&x86_64::X86_64Assembler::comisd, "comisd %{reg2}, %{reg1}"), "comisd");
1599 }
1600 
TEST_F(AssemblerX86_64Test,Ucomiss)1601 TEST_F(AssemblerX86_64Test, Ucomiss) {
1602   DriverStr(RepeatFF(&x86_64::X86_64Assembler::ucomiss, "ucomiss %{reg2}, %{reg1}"), "ucomiss");
1603 }
1604 
TEST_F(AssemblerX86_64Test,Ucomisd)1605 TEST_F(AssemblerX86_64Test, Ucomisd) {
1606   DriverStr(RepeatFF(&x86_64::X86_64Assembler::ucomisd, "ucomisd %{reg2}, %{reg1}"), "ucomisd");
1607 }
1608 
TEST_F(AssemblerX86_64Test,Sqrtss)1609 TEST_F(AssemblerX86_64Test, Sqrtss) {
1610   DriverStr(RepeatFF(&x86_64::X86_64Assembler::sqrtss, "sqrtss %{reg2}, %{reg1}"), "sqrtss");
1611 }
1612 
TEST_F(AssemblerX86_64Test,Sqrtsd)1613 TEST_F(AssemblerX86_64Test, Sqrtsd) {
1614   DriverStr(RepeatFF(&x86_64::X86_64Assembler::sqrtsd, "sqrtsd %{reg2}, %{reg1}"), "sqrtsd");
1615 }
1616 
TEST_F(AssemblerX86_64Test,Roundss)1617 TEST_F(AssemblerX86_64Test, Roundss) {
1618   DriverStr(RepeatFFI(&x86_64::X86_64Assembler::roundss, /*imm_bytes*/ 1U,
1619                       "roundss ${imm}, %{reg2}, %{reg1}"), "roundss");
1620 }
1621 
TEST_F(AssemblerX86_64Test,Roundsd)1622 TEST_F(AssemblerX86_64Test, Roundsd) {
1623   DriverStr(RepeatFFI(&x86_64::X86_64Assembler::roundsd, /*imm_bytes*/ 1U,
1624                       "roundsd ${imm}, %{reg2}, %{reg1}"), "roundsd");
1625 }
1626 
TEST_F(AssemblerX86_64Test,Xorps)1627 TEST_F(AssemblerX86_64Test, Xorps) {
1628   DriverStr(RepeatFF(&x86_64::X86_64Assembler::xorps, "xorps %{reg2}, %{reg1}"), "xorps");
1629 }
1630 
TEST_F(AssemblerX86_64Test,Xorpd)1631 TEST_F(AssemblerX86_64Test, Xorpd) {
1632   DriverStr(RepeatFF(&x86_64::X86_64Assembler::xorpd, "xorpd %{reg2}, %{reg1}"), "xorpd");
1633 }
1634 
TEST_F(AssemblerX86_64Test,Pxor)1635 TEST_F(AssemblerX86_64Test, Pxor) {
1636   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pxor, "pxor %{reg2}, %{reg1}"), "pxor");
1637 }
1638 
TEST_F(AssemblerX86_64AVXTest,VPXor)1639 TEST_F(AssemblerX86_64AVXTest, VPXor) {
1640   DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vpxor,
1641                       "vpxor %{reg3}, %{reg2}, %{reg1}"), "vpxor");
1642 }
1643 
TEST_F(AssemblerX86_64AVXTest,VXorps)1644 TEST_F(AssemblerX86_64AVXTest, VXorps) {
1645   DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vxorps,
1646                       "vxorps %{reg3}, %{reg2}, %{reg1}"), "vxorps");
1647 }
1648 
TEST_F(AssemblerX86_64AVXTest,VXorpd)1649 TEST_F(AssemblerX86_64AVXTest, VXorpd) {
1650   DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vxorpd,
1651                       "vxorpd %{reg3}, %{reg2}, %{reg1}"), "vxorpd");
1652 }
1653 
TEST_F(AssemblerX86_64Test,Andps)1654 TEST_F(AssemblerX86_64Test, Andps) {
1655   DriverStr(RepeatFF(&x86_64::X86_64Assembler::andps, "andps %{reg2}, %{reg1}"), "andps");
1656 }
1657 
TEST_F(AssemblerX86_64Test,Andpd)1658 TEST_F(AssemblerX86_64Test, Andpd) {
1659   DriverStr(RepeatFF(&x86_64::X86_64Assembler::andpd, "andpd %{reg2}, %{reg1}"), "andpd");
1660 }
1661 
TEST_F(AssemblerX86_64Test,Pand)1662 TEST_F(AssemblerX86_64Test, Pand) {
1663   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pand, "pand %{reg2}, %{reg1}"), "pand");
1664 }
1665 
TEST_F(AssemblerX86_64AVXTest,VPAnd)1666 TEST_F(AssemblerX86_64AVXTest, VPAnd) {
1667   DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vpand,
1668                       "vpand %{reg3}, %{reg2}, %{reg1}"), "vpand");
1669 }
1670 
TEST_F(AssemblerX86_64AVXTest,VAndps)1671 TEST_F(AssemblerX86_64AVXTest, VAndps) {
1672   DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vandps,
1673                       "vandps %{reg3}, %{reg2}, %{reg1}"), "vandps");
1674 }
1675 
TEST_F(AssemblerX86_64AVXTest,VAndpd)1676 TEST_F(AssemblerX86_64AVXTest, VAndpd) {
1677   DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vandpd,
1678                       "vandpd %{reg3}, %{reg2}, %{reg1}"), "vandpd");
1679 }
1680 
TEST_F(AssemblerX86_64Test,Andn)1681 TEST_F(AssemblerX86_64Test, Andn) {
1682   DriverStr(RepeatRRR(&x86_64::X86_64Assembler::andn, "andn %{reg3}, %{reg2}, %{reg1}"), "andn");
1683 }
TEST_F(AssemblerX86_64Test,andnpd)1684 TEST_F(AssemblerX86_64Test, andnpd) {
1685   DriverStr(RepeatFF(&x86_64::X86_64Assembler::andnpd, "andnpd %{reg2}, %{reg1}"), "andnpd");
1686 }
1687 
TEST_F(AssemblerX86_64Test,andnps)1688 TEST_F(AssemblerX86_64Test, andnps) {
1689   DriverStr(RepeatFF(&x86_64::X86_64Assembler::andnps, "andnps %{reg2}, %{reg1}"), "andnps");
1690 }
1691 
TEST_F(AssemblerX86_64Test,Pandn)1692 TEST_F(AssemblerX86_64Test, Pandn) {
1693   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pandn, "pandn %{reg2}, %{reg1}"), "pandn");
1694 }
1695 
TEST_F(AssemblerX86_64AVXTest,VPAndn)1696 TEST_F(AssemblerX86_64AVXTest, VPAndn) {
1697   DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vpandn,
1698                       "vpandn %{reg3}, %{reg2}, %{reg1}"), "vpandn");
1699 }
1700 
TEST_F(AssemblerX86_64AVXTest,VAndnps)1701 TEST_F(AssemblerX86_64AVXTest, VAndnps) {
1702   DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vandnps,
1703                       "vandnps %{reg3}, %{reg2}, %{reg1}"), "vandnps");
1704 }
1705 
TEST_F(AssemblerX86_64AVXTest,VAndnpd)1706 TEST_F(AssemblerX86_64AVXTest, VAndnpd) {
1707   DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vandnpd,
1708                       "vandnpd %{reg3}, %{reg2}, %{reg1}"), "vandnpd");
1709 }
1710 
TEST_F(AssemblerX86_64Test,Orps)1711 TEST_F(AssemblerX86_64Test, Orps) {
1712   DriverStr(RepeatFF(&x86_64::X86_64Assembler::orps, "orps %{reg2}, %{reg1}"), "orps");
1713 }
1714 
TEST_F(AssemblerX86_64Test,Orpd)1715 TEST_F(AssemblerX86_64Test, Orpd) {
1716   DriverStr(RepeatFF(&x86_64::X86_64Assembler::orpd, "orpd %{reg2}, %{reg1}"), "orpd");
1717 }
1718 
TEST_F(AssemblerX86_64Test,Por)1719 TEST_F(AssemblerX86_64Test, Por) {
1720   DriverStr(RepeatFF(&x86_64::X86_64Assembler::por, "por %{reg2}, %{reg1}"), "por");
1721 }
1722 
TEST_F(AssemblerX86_64AVXTest,VPor)1723 TEST_F(AssemblerX86_64AVXTest, VPor) {
1724   DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vpor,
1725                       "vpor %{reg3}, %{reg2}, %{reg1}"), "vpor");
1726 }
1727 
TEST_F(AssemblerX86_64AVXTest,Vorps)1728 TEST_F(AssemblerX86_64AVXTest, Vorps) {
1729   DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vorps,
1730                       "vorps %{reg3}, %{reg2}, %{reg1}"), "vorps");
1731 }
1732 
TEST_F(AssemblerX86_64AVXTest,Vorpd)1733 TEST_F(AssemblerX86_64AVXTest, Vorpd) {
1734   DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vorpd,
1735                       "vorpd %{reg3}, %{reg2}, %{reg1}"), "vorpd");
1736 }
1737 
TEST_F(AssemblerX86_64Test,Pavgb)1738 TEST_F(AssemblerX86_64Test, Pavgb) {
1739   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pavgb, "pavgb %{reg2}, %{reg1}"), "pavgb");
1740 }
1741 
TEST_F(AssemblerX86_64Test,Pavgw)1742 TEST_F(AssemblerX86_64Test, Pavgw) {
1743   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pavgw, "pavgw %{reg2}, %{reg1}"), "pavgw");
1744 }
1745 
TEST_F(AssemblerX86_64Test,Psadbw)1746 TEST_F(AssemblerX86_64Test, Psadbw) {
1747   DriverStr(RepeatFF(&x86_64::X86_64Assembler::psadbw, "psadbw %{reg2}, %{reg1}"), "psadbw");
1748 }
1749 
TEST_F(AssemblerX86_64Test,Pmaddwd)1750 TEST_F(AssemblerX86_64Test, Pmaddwd) {
1751   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaddwd, "pmaddwd %{reg2}, %{reg1}"), "pmadwd");
1752 }
1753 
TEST_F(AssemblerX86_64AVXTest,VPmaddwd)1754 TEST_F(AssemblerX86_64AVXTest, VPmaddwd) {
1755   DriverStr(RepeatFFF(&x86_64::X86_64Assembler::vpmaddwd,
1756                       "vpmaddwd %{reg3}, %{reg2}, %{reg1}"), "vpmaddwd");
1757 }
1758 
TEST_F(AssemblerX86_64Test,Phaddw)1759 TEST_F(AssemblerX86_64Test, Phaddw) {
1760   DriverStr(RepeatFF(&x86_64::X86_64Assembler::phaddw, "phaddw %{reg2}, %{reg1}"), "phaddw");
1761 }
1762 
TEST_F(AssemblerX86_64Test,Phaddd)1763 TEST_F(AssemblerX86_64Test, Phaddd) {
1764   DriverStr(RepeatFF(&x86_64::X86_64Assembler::phaddd, "phaddd %{reg2}, %{reg1}"), "phaddd");
1765 }
1766 
TEST_F(AssemblerX86_64Test,Haddps)1767 TEST_F(AssemblerX86_64Test, Haddps) {
1768   DriverStr(RepeatFF(&x86_64::X86_64Assembler::haddps, "haddps %{reg2}, %{reg1}"), "haddps");
1769 }
1770 
TEST_F(AssemblerX86_64Test,Haddpd)1771 TEST_F(AssemblerX86_64Test, Haddpd) {
1772   DriverStr(RepeatFF(&x86_64::X86_64Assembler::haddpd, "haddpd %{reg2}, %{reg1}"), "haddpd");
1773 }
1774 
TEST_F(AssemblerX86_64Test,Phsubw)1775 TEST_F(AssemblerX86_64Test, Phsubw) {
1776   DriverStr(RepeatFF(&x86_64::X86_64Assembler::phsubw, "phsubw %{reg2}, %{reg1}"), "phsubw");
1777 }
1778 
TEST_F(AssemblerX86_64Test,Phsubd)1779 TEST_F(AssemblerX86_64Test, Phsubd) {
1780   DriverStr(RepeatFF(&x86_64::X86_64Assembler::phsubd, "phsubd %{reg2}, %{reg1}"), "phsubd");
1781 }
1782 
TEST_F(AssemblerX86_64Test,Hsubps)1783 TEST_F(AssemblerX86_64Test, Hsubps) {
1784   DriverStr(RepeatFF(&x86_64::X86_64Assembler::hsubps, "hsubps %{reg2}, %{reg1}"), "hsubps");
1785 }
1786 
TEST_F(AssemblerX86_64Test,Hsubpd)1787 TEST_F(AssemblerX86_64Test, Hsubpd) {
1788   DriverStr(RepeatFF(&x86_64::X86_64Assembler::hsubpd, "hsubpd %{reg2}, %{reg1}"), "hsubpd");
1789 }
1790 
TEST_F(AssemblerX86_64Test,Pminsb)1791 TEST_F(AssemblerX86_64Test, Pminsb) {
1792   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pminsb, "pminsb %{reg2}, %{reg1}"), "pminsb");
1793 }
1794 
TEST_F(AssemblerX86_64Test,Pmaxsb)1795 TEST_F(AssemblerX86_64Test, Pmaxsb) {
1796   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaxsb, "pmaxsb %{reg2}, %{reg1}"), "pmaxsb");
1797 }
1798 
TEST_F(AssemblerX86_64Test,Pminsw)1799 TEST_F(AssemblerX86_64Test, Pminsw) {
1800   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pminsw, "pminsw %{reg2}, %{reg1}"), "pminsw");
1801 }
1802 
TEST_F(AssemblerX86_64Test,Pmaxsw)1803 TEST_F(AssemblerX86_64Test, Pmaxsw) {
1804   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaxsw, "pmaxsw %{reg2}, %{reg1}"), "pmaxsw");
1805 }
1806 
TEST_F(AssemblerX86_64Test,Pminsd)1807 TEST_F(AssemblerX86_64Test, Pminsd) {
1808   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pminsd, "pminsd %{reg2}, %{reg1}"), "pminsd");
1809 }
1810 
TEST_F(AssemblerX86_64Test,Pmaxsd)1811 TEST_F(AssemblerX86_64Test, Pmaxsd) {
1812   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaxsd, "pmaxsd %{reg2}, %{reg1}"), "pmaxsd");
1813 }
1814 
TEST_F(AssemblerX86_64Test,Pminub)1815 TEST_F(AssemblerX86_64Test, Pminub) {
1816   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pminub, "pminub %{reg2}, %{reg1}"), "pminub");
1817 }
1818 
TEST_F(AssemblerX86_64Test,Pmaxub)1819 TEST_F(AssemblerX86_64Test, Pmaxub) {
1820   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaxub, "pmaxub %{reg2}, %{reg1}"), "pmaxub");
1821 }
1822 
TEST_F(AssemblerX86_64Test,Pminuw)1823 TEST_F(AssemblerX86_64Test, Pminuw) {
1824   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pminuw, "pminuw %{reg2}, %{reg1}"), "pminuw");
1825 }
1826 
TEST_F(AssemblerX86_64Test,Pmaxuw)1827 TEST_F(AssemblerX86_64Test, Pmaxuw) {
1828   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaxuw, "pmaxuw %{reg2}, %{reg1}"), "pmaxuw");
1829 }
1830 
TEST_F(AssemblerX86_64Test,Pminud)1831 TEST_F(AssemblerX86_64Test, Pminud) {
1832   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pminud, "pminud %{reg2}, %{reg1}"), "pminud");
1833 }
1834 
TEST_F(AssemblerX86_64Test,Pmaxud)1835 TEST_F(AssemblerX86_64Test, Pmaxud) {
1836   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaxud, "pmaxud %{reg2}, %{reg1}"), "pmaxud");
1837 }
1838 
TEST_F(AssemblerX86_64Test,Minps)1839 TEST_F(AssemblerX86_64Test, Minps) {
1840   DriverStr(RepeatFF(&x86_64::X86_64Assembler::minps, "minps %{reg2}, %{reg1}"), "minps");
1841 }
1842 
TEST_F(AssemblerX86_64Test,Maxps)1843 TEST_F(AssemblerX86_64Test, Maxps) {
1844   DriverStr(RepeatFF(&x86_64::X86_64Assembler::maxps, "maxps %{reg2}, %{reg1}"), "maxps");
1845 }
1846 
TEST_F(AssemblerX86_64Test,Minpd)1847 TEST_F(AssemblerX86_64Test, Minpd) {
1848   DriverStr(RepeatFF(&x86_64::X86_64Assembler::minpd, "minpd %{reg2}, %{reg1}"), "minpd");
1849 }
1850 
TEST_F(AssemblerX86_64Test,Maxpd)1851 TEST_F(AssemblerX86_64Test, Maxpd) {
1852   DriverStr(RepeatFF(&x86_64::X86_64Assembler::maxpd, "maxpd %{reg2}, %{reg1}"), "maxpd");
1853 }
1854 
TEST_F(AssemblerX86_64Test,PCmpeqb)1855 TEST_F(AssemblerX86_64Test, PCmpeqb) {
1856   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpeqb, "pcmpeqb %{reg2}, %{reg1}"), "pcmpeqb");
1857 }
1858 
TEST_F(AssemblerX86_64Test,PCmpeqw)1859 TEST_F(AssemblerX86_64Test, PCmpeqw) {
1860   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpeqw, "pcmpeqw %{reg2}, %{reg1}"), "pcmpeqw");
1861 }
1862 
TEST_F(AssemblerX86_64Test,PCmpeqd)1863 TEST_F(AssemblerX86_64Test, PCmpeqd) {
1864   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpeqd, "pcmpeqd %{reg2}, %{reg1}"), "pcmpeqd");
1865 }
1866 
TEST_F(AssemblerX86_64Test,PCmpeqq)1867 TEST_F(AssemblerX86_64Test, PCmpeqq) {
1868   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpeqq, "pcmpeqq %{reg2}, %{reg1}"), "pcmpeqq");
1869 }
1870 
TEST_F(AssemblerX86_64Test,PCmpgtb)1871 TEST_F(AssemblerX86_64Test, PCmpgtb) {
1872   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpgtb, "pcmpgtb %{reg2}, %{reg1}"), "pcmpgtb");
1873 }
1874 
TEST_F(AssemblerX86_64Test,PCmpgtw)1875 TEST_F(AssemblerX86_64Test, PCmpgtw) {
1876   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpgtw, "pcmpgtw %{reg2}, %{reg1}"), "pcmpgtw");
1877 }
1878 
TEST_F(AssemblerX86_64Test,PCmpgtd)1879 TEST_F(AssemblerX86_64Test, PCmpgtd) {
1880   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpgtd, "pcmpgtd %{reg2}, %{reg1}"), "pcmpgtd");
1881 }
1882 
TEST_F(AssemblerX86_64Test,PCmpgtq)1883 TEST_F(AssemblerX86_64Test, PCmpgtq) {
1884   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpgtq, "pcmpgtq %{reg2}, %{reg1}"), "pcmpgtq");
1885 }
1886 
TEST_F(AssemblerX86_64Test,Shufps)1887 TEST_F(AssemblerX86_64Test, Shufps) {
1888   DriverStr(RepeatFFI(&x86_64::X86_64Assembler::shufps, /*imm_bytes*/ 1U,
1889                       "shufps ${imm}, %{reg2}, %{reg1}"), "shufps");
1890 }
1891 
TEST_F(AssemblerX86_64Test,Shufpd)1892 TEST_F(AssemblerX86_64Test, Shufpd) {
1893   DriverStr(RepeatFFI(&x86_64::X86_64Assembler::shufpd, /*imm_bytes*/ 1U,
1894                       "shufpd ${imm}, %{reg2}, %{reg1}"), "shufpd");
1895 }
1896 
TEST_F(AssemblerX86_64Test,PShufd)1897 TEST_F(AssemblerX86_64Test, PShufd) {
1898   DriverStr(RepeatFFI(&x86_64::X86_64Assembler::pshufd, /*imm_bytes*/ 1U,
1899                       "pshufd ${imm}, %{reg2}, %{reg1}"), "pshufd");
1900 }
1901 
TEST_F(AssemblerX86_64Test,Punpcklbw)1902 TEST_F(AssemblerX86_64Test, Punpcklbw) {
1903   DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpcklbw,
1904                      "punpcklbw %{reg2}, %{reg1}"), "punpcklbw");
1905 }
1906 
TEST_F(AssemblerX86_64Test,Punpcklwd)1907 TEST_F(AssemblerX86_64Test, Punpcklwd) {
1908   DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpcklwd,
1909                      "punpcklwd %{reg2}, %{reg1}"), "punpcklwd");
1910 }
1911 
TEST_F(AssemblerX86_64Test,Punpckldq)1912 TEST_F(AssemblerX86_64Test, Punpckldq) {
1913   DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpckldq,
1914                      "punpckldq %{reg2}, %{reg1}"), "punpckldq");
1915 }
1916 
TEST_F(AssemblerX86_64Test,Punpcklqdq)1917 TEST_F(AssemblerX86_64Test, Punpcklqdq) {
1918   DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpcklqdq,
1919                      "punpcklqdq %{reg2}, %{reg1}"), "punpcklqdq");
1920 }
1921 
TEST_F(AssemblerX86_64Test,Punpckhbw)1922 TEST_F(AssemblerX86_64Test, Punpckhbw) {
1923   DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpckhbw,
1924                      "punpckhbw %{reg2}, %{reg1}"), "punpckhbw");
1925 }
1926 
TEST_F(AssemblerX86_64Test,Punpckhwd)1927 TEST_F(AssemblerX86_64Test, Punpckhwd) {
1928   DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpckhwd,
1929                      "punpckhwd %{reg2}, %{reg1}"), "punpckhwd");
1930 }
1931 
TEST_F(AssemblerX86_64Test,Punpckhdq)1932 TEST_F(AssemblerX86_64Test, Punpckhdq) {
1933   DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpckhdq,
1934                      "punpckhdq %{reg2}, %{reg1}"), "punpckhdq");
1935 }
1936 
TEST_F(AssemblerX86_64Test,Punpckhqdq)1937 TEST_F(AssemblerX86_64Test, Punpckhqdq) {
1938   DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpckhqdq,
1939                      "punpckhqdq %{reg2}, %{reg1}"), "punpckhqdq");
1940 }
1941 
TEST_F(AssemblerX86_64Test,Psllw)1942 TEST_F(AssemblerX86_64Test, Psllw) {
1943   GetAssembler()->psllw(x86_64::XmmRegister(x86_64::XMM0),  x86_64::Immediate(1));
1944   GetAssembler()->psllw(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1945   DriverStr("psllw $1, %xmm0\n"
1946             "psllw $2, %xmm15\n", "psllwi");
1947 }
1948 
TEST_F(AssemblerX86_64Test,Pslld)1949 TEST_F(AssemblerX86_64Test, Pslld) {
1950   GetAssembler()->pslld(x86_64::XmmRegister(x86_64::XMM0),  x86_64::Immediate(1));
1951   GetAssembler()->pslld(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1952   DriverStr("pslld $1, %xmm0\n"
1953             "pslld $2, %xmm15\n", "pslldi");
1954 }
1955 
TEST_F(AssemblerX86_64Test,Psllq)1956 TEST_F(AssemblerX86_64Test, Psllq) {
1957   GetAssembler()->psllq(x86_64::XmmRegister(x86_64::XMM0),  x86_64::Immediate(1));
1958   GetAssembler()->psllq(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1959   DriverStr("psllq $1, %xmm0\n"
1960             "psllq $2, %xmm15\n", "psllqi");
1961 }
1962 
TEST_F(AssemblerX86_64Test,Psraw)1963 TEST_F(AssemblerX86_64Test, Psraw) {
1964   GetAssembler()->psraw(x86_64::XmmRegister(x86_64::XMM0),  x86_64::Immediate(1));
1965   GetAssembler()->psraw(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1966   DriverStr("psraw $1, %xmm0\n"
1967             "psraw $2, %xmm15\n", "psrawi");
1968 }
1969 
TEST_F(AssemblerX86_64Test,Psrad)1970 TEST_F(AssemblerX86_64Test, Psrad) {
1971   GetAssembler()->psrad(x86_64::XmmRegister(x86_64::XMM0),  x86_64::Immediate(1));
1972   GetAssembler()->psrad(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1973   DriverStr("psrad $1, %xmm0\n"
1974             "psrad $2, %xmm15\n", "psradi");
1975 }
1976 
TEST_F(AssemblerX86_64Test,Psrlw)1977 TEST_F(AssemblerX86_64Test, Psrlw) {
1978   GetAssembler()->psrlw(x86_64::XmmRegister(x86_64::XMM0),  x86_64::Immediate(1));
1979   GetAssembler()->psrlw(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1980   DriverStr("psrlw $1, %xmm0\n"
1981             "psrlw $2, %xmm15\n", "psrlwi");
1982 }
1983 
TEST_F(AssemblerX86_64Test,Psrld)1984 TEST_F(AssemblerX86_64Test, Psrld) {
1985   GetAssembler()->psrld(x86_64::XmmRegister(x86_64::XMM0),  x86_64::Immediate(1));
1986   GetAssembler()->psrld(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1987   DriverStr("psrld $1, %xmm0\n"
1988             "psrld $2, %xmm15\n", "psrldi");
1989 }
1990 
TEST_F(AssemblerX86_64Test,Psrlq)1991 TEST_F(AssemblerX86_64Test, Psrlq) {
1992   GetAssembler()->psrlq(x86_64::XmmRegister(x86_64::XMM0),  x86_64::Immediate(1));
1993   GetAssembler()->psrlq(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1994   DriverStr("psrlq $1, %xmm0\n"
1995             "psrlq $2, %xmm15\n", "psrlqi");
1996 }
1997 
TEST_F(AssemblerX86_64Test,Psrldq)1998 TEST_F(AssemblerX86_64Test, Psrldq) {
1999   GetAssembler()->psrldq(x86_64::XmmRegister(x86_64::XMM0),  x86_64::Immediate(1));
2000   GetAssembler()->psrldq(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
2001   DriverStr("psrldq $1, %xmm0\n"
2002             "psrldq $2, %xmm15\n", "psrldqi");
2003 }
2004 
x87_fn(AssemblerX86_64Test::Base * assembler_test ATTRIBUTE_UNUSED,x86_64::X86_64Assembler * assembler)2005 std::string x87_fn(AssemblerX86_64Test::Base* assembler_test ATTRIBUTE_UNUSED,
2006                    x86_64::X86_64Assembler* assembler) {
2007   std::ostringstream str;
2008 
2009   assembler->fincstp();
2010   str << "fincstp\n";
2011 
2012   assembler->fsin();
2013   str << "fsin\n";
2014 
2015   assembler->fcos();
2016   str << "fcos\n";
2017 
2018   assembler->fptan();
2019   str << "fptan\n";
2020 
2021   return str.str();
2022 }
2023 
TEST_F(AssemblerX86_64Test,X87)2024 TEST_F(AssemblerX86_64Test, X87) {
2025   DriverFn(&x87_fn, "x87");
2026 }
2027 
TEST_F(AssemblerX86_64Test,FPUIntegerLoads)2028 TEST_F(AssemblerX86_64Test, FPUIntegerLoads) {
2029   DriverStr(RepeatA(&x86_64::X86_64Assembler::filds,
2030                     addresses_singleton_,  // no ext addressing
2031                     "fildl {mem}"), "filds");
2032 }
2033 
TEST_F(AssemblerX86_64Test,FPUIntegerLoadl)2034 TEST_F(AssemblerX86_64Test, FPUIntegerLoadl) {
2035   DriverStr(RepeatA(&x86_64::X86_64Assembler::fildl,
2036                     addresses_singleton_,  // no ext addressing
2037                     "fildll {mem}"), "fildl");
2038 }
2039 
TEST_F(AssemblerX86_64Test,FPUIntegerStores)2040 TEST_F(AssemblerX86_64Test, FPUIntegerStores) {
2041   DriverStr(RepeatA(&x86_64::X86_64Assembler::fistps,
2042                     addresses_singleton_,  // no ext addressing
2043                     "fistpl {mem}"), "fistps");
2044 }
2045 
TEST_F(AssemblerX86_64Test,FPUIntegerStorel)2046 TEST_F(AssemblerX86_64Test, FPUIntegerStorel) {
2047   DriverStr(RepeatA(&x86_64::X86_64Assembler::fistpl,
2048                     addresses_singleton_,  // no ext addressing
2049                     "fistpll {mem}"), "fistpl");
2050 }
2051 
TEST_F(AssemblerX86_64Test,Call)2052 TEST_F(AssemblerX86_64Test, Call) {
2053   DriverStr(RepeatR(&x86_64::X86_64Assembler::call, "call *%{reg}"), "call");
2054 }
2055 
TEST_F(AssemblerX86_64Test,Jmp)2056 TEST_F(AssemblerX86_64Test, Jmp) {
2057   DriverStr(RepeatR(&x86_64::X86_64Assembler::jmp, "jmp *%{reg}"), "jmp");
2058 }
2059 
TEST_F(AssemblerX86_64Test,Enter)2060 TEST_F(AssemblerX86_64Test, Enter) {
2061   DriverStr(RepeatI(&x86_64::X86_64Assembler::enter,
2062                     /*imm_bytes*/ 2U,
2063                     "enter ${imm}, $0", /*non-negative*/ true), "enter");
2064 }
2065 
TEST_F(AssemblerX86_64Test,RetImm)2066 TEST_F(AssemblerX86_64Test, RetImm) {
2067   DriverStr(RepeatI(&x86_64::X86_64Assembler::ret,
2068                     /*imm_bytes*/ 2U,
2069                     "ret ${imm}", /*non-negative*/ true), "ret");
2070 }
2071 
ret_and_leave_fn(AssemblerX86_64Test::Base * assembler_test ATTRIBUTE_UNUSED,x86_64::X86_64Assembler * assembler)2072 std::string ret_and_leave_fn(AssemblerX86_64Test::Base* assembler_test ATTRIBUTE_UNUSED,
2073                              x86_64::X86_64Assembler* assembler) {
2074   std::ostringstream str;
2075 
2076   assembler->ret();
2077   str << "ret\n";
2078 
2079   assembler->leave();
2080   str << "leave\n";
2081 
2082   return str.str();
2083 }
2084 
TEST_F(AssemblerX86_64Test,RetAndLeave)2085 TEST_F(AssemblerX86_64Test, RetAndLeave) {
2086   DriverFn(&ret_and_leave_fn, "retleave");
2087 }
2088 
TEST_F(AssemblerX86_64Test,Blsmask)2089 TEST_F(AssemblerX86_64Test, Blsmask) {
2090   DriverStr(RepeatRR(&x86_64::X86_64Assembler::blsmsk, "blsmsk %{reg2}, %{reg1}"), "blsmsk");
2091 }
2092 
TEST_F(AssemblerX86_64Test,Blsi)2093 TEST_F(AssemblerX86_64Test, Blsi) {
2094   DriverStr(RepeatRR(&x86_64::X86_64Assembler::blsi, "blsi %{reg2}, %{reg1}"), "blsi");
2095 }
2096 
TEST_F(AssemblerX86_64Test,Blsr)2097 TEST_F(AssemblerX86_64Test, Blsr) {
2098   DriverStr(RepeatRR(&x86_64::X86_64Assembler::blsr, "blsr %{reg2}, %{reg1}"), "blsr");
2099 }
2100 
TEST_F(AssemblerX86_64Test,Bswapl)2101 TEST_F(AssemblerX86_64Test, Bswapl) {
2102   DriverStr(Repeatr(&x86_64::X86_64Assembler::bswapl, "bswap %{reg}"), "bswapl");
2103 }
2104 
TEST_F(AssemblerX86_64Test,Bswapq)2105 TEST_F(AssemblerX86_64Test, Bswapq) {
2106   DriverStr(RepeatR(&x86_64::X86_64Assembler::bswapq, "bswap %{reg}"), "bswapq");
2107 }
2108 
TEST_F(AssemblerX86_64Test,Bsfl)2109 TEST_F(AssemblerX86_64Test, Bsfl) {
2110   DriverStr(Repeatrr(&x86_64::X86_64Assembler::bsfl, "bsfl %{reg2}, %{reg1}"), "bsfl");
2111 }
2112 
TEST_F(AssemblerX86_64Test,BsflAddress)2113 TEST_F(AssemblerX86_64Test, BsflAddress) {
2114   DriverStr(RepeatrA(&x86_64::X86_64Assembler::bsfl, "bsfl {mem}, %{reg}"), "bsfl_address");
2115 }
2116 
TEST_F(AssemblerX86_64Test,Bsfq)2117 TEST_F(AssemblerX86_64Test, Bsfq) {
2118   DriverStr(RepeatRR(&x86_64::X86_64Assembler::bsfq, "bsfq %{reg2}, %{reg1}"), "bsfq");
2119 }
2120 
TEST_F(AssemblerX86_64Test,BsfqAddress)2121 TEST_F(AssemblerX86_64Test, BsfqAddress) {
2122   DriverStr(RepeatRA(&x86_64::X86_64Assembler::bsfq, "bsfq {mem}, %{reg}"), "bsfq_address");
2123 }
2124 
TEST_F(AssemblerX86_64Test,Bsrl)2125 TEST_F(AssemblerX86_64Test, Bsrl) {
2126   DriverStr(Repeatrr(&x86_64::X86_64Assembler::bsrl, "bsrl %{reg2}, %{reg1}"), "bsrl");
2127 }
2128 
TEST_F(AssemblerX86_64Test,BsrlAddress)2129 TEST_F(AssemblerX86_64Test, BsrlAddress) {
2130   DriverStr(RepeatrA(&x86_64::X86_64Assembler::bsrl, "bsrl {mem}, %{reg}"), "bsrl_address");
2131 }
2132 
TEST_F(AssemblerX86_64Test,Bsrq)2133 TEST_F(AssemblerX86_64Test, Bsrq) {
2134   DriverStr(RepeatRR(&x86_64::X86_64Assembler::bsrq, "bsrq %{reg2}, %{reg1}"), "bsrq");
2135 }
2136 
TEST_F(AssemblerX86_64Test,BsrqAddress)2137 TEST_F(AssemblerX86_64Test, BsrqAddress) {
2138   DriverStr(RepeatRA(&x86_64::X86_64Assembler::bsrq, "bsrq {mem}, %{reg}"), "bsrq_address");
2139 }
2140 
TEST_F(AssemblerX86_64Test,Popcntl)2141 TEST_F(AssemblerX86_64Test, Popcntl) {
2142   DriverStr(Repeatrr(&x86_64::X86_64Assembler::popcntl, "popcntl %{reg2}, %{reg1}"), "popcntl");
2143 }
2144 
TEST_F(AssemblerX86_64Test,PopcntlAddress)2145 TEST_F(AssemblerX86_64Test, PopcntlAddress) {
2146   DriverStr(RepeatrA(&x86_64::X86_64Assembler::popcntl, "popcntl {mem}, %{reg}"), "popcntl_address");
2147 }
2148 
TEST_F(AssemblerX86_64Test,Popcntq)2149 TEST_F(AssemblerX86_64Test, Popcntq) {
2150   DriverStr(RepeatRR(&x86_64::X86_64Assembler::popcntq, "popcntq %{reg2}, %{reg1}"), "popcntq");
2151 }
2152 
TEST_F(AssemblerX86_64Test,PopcntqAddress)2153 TEST_F(AssemblerX86_64Test, PopcntqAddress) {
2154   DriverStr(RepeatRA(&x86_64::X86_64Assembler::popcntq, "popcntq {mem}, %{reg}"), "popcntq_address");
2155 }
2156 
TEST_F(AssemblerX86_64Test,CmovlAddress)2157 TEST_F(AssemblerX86_64Test, CmovlAddress) {
2158   GetAssembler()->cmov(x86_64::kEqual, x86_64::CpuRegister(x86_64::R10), x86_64::Address(
2159       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12), false);
2160   GetAssembler()->cmov(x86_64::kNotEqual, x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
2161       x86_64::CpuRegister(x86_64::R10), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12), false);
2162   GetAssembler()->cmov(x86_64::kEqual, x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
2163       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12), false);
2164   const char* expected =
2165     "cmovzl 0xc(%RDI,%RBX,4), %R10d\n"
2166     "cmovnzl 0xc(%R10,%RBX,4), %edi\n"
2167     "cmovzl 0xc(%RDI,%R9,4), %edi\n";
2168   DriverStr(expected, "cmovl_address");
2169 }
2170 
TEST_F(AssemblerX86_64Test,CmovqAddress)2171 TEST_F(AssemblerX86_64Test, CmovqAddress) {
2172   GetAssembler()->cmov(x86_64::kEqual, x86_64::CpuRegister(x86_64::R10), x86_64::Address(
2173       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12), true);
2174   GetAssembler()->cmov(x86_64::kNotEqual, x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
2175       x86_64::CpuRegister(x86_64::R10), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12), true);
2176   GetAssembler()->cmov(x86_64::kEqual, x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
2177       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12), true);
2178   const char* expected =
2179     "cmovzq 0xc(%RDI,%RBX,4), %R10\n"
2180     "cmovnzq 0xc(%R10,%RBX,4), %rdi\n"
2181     "cmovzq 0xc(%RDI,%R9,4), %rdi\n";
2182   DriverStr(expected, "cmovq_address");
2183 }
2184 
TEST_F(AssemblerX86_64Test,Jrcxz)2185 TEST_F(AssemblerX86_64Test, Jrcxz) {
2186   x86_64::NearLabel target;
2187   GetAssembler()->jrcxz(&target);
2188   GetAssembler()->addl(x86_64::CpuRegister(x86_64::RDI),
2189                        x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 4));
2190   GetAssembler()->Bind(&target);
2191   const char* expected =
2192     "jrcxz 1f\n"
2193     "addl 4(%RSP),%EDI\n"
2194     "1:\n";
2195 
2196   DriverStr(expected, "jrcxz");
2197 }
2198 
TEST_F(AssemblerX86_64Test,NearLabel)2199 TEST_F(AssemblerX86_64Test, NearLabel) {
2200   // Test both forward and backward branches.
2201   x86_64::NearLabel start, target;
2202   GetAssembler()->Bind(&start);
2203   GetAssembler()->j(x86_64::kEqual, &target);
2204   GetAssembler()->jmp(&target);
2205   GetAssembler()->jrcxz(&target);
2206   GetAssembler()->addl(x86_64::CpuRegister(x86_64::RDI),
2207                        x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 4));
2208   GetAssembler()->Bind(&target);
2209   GetAssembler()->j(x86_64::kNotEqual, &start);
2210   GetAssembler()->jmp(&start);
2211   const char* expected =
2212     "1: je 2f\n"
2213     "jmp 2f\n"
2214     "jrcxz 2f\n"
2215     "addl 4(%RSP),%EDI\n"
2216     "2: jne 1b\n"
2217     "jmp 1b\n";
2218 
2219   DriverStr(expected, "near_label");
2220 }
2221 
setcc_test_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)2222 std::string setcc_test_fn(AssemblerX86_64Test::Base* assembler_test,
2223                           x86_64::X86_64Assembler* assembler) {
2224   // From Condition
2225   /*
2226   kOverflow     =  0,
2227   kNoOverflow   =  1,
2228   kBelow        =  2,
2229   kAboveEqual   =  3,
2230   kEqual        =  4,
2231   kNotEqual     =  5,
2232   kBelowEqual   =  6,
2233   kAbove        =  7,
2234   kSign         =  8,
2235   kNotSign      =  9,
2236   kParityEven   = 10,
2237   kParityOdd    = 11,
2238   kLess         = 12,
2239   kGreaterEqual = 13,
2240   kLessEqual    = 14,
2241   */
2242   std::string suffixes[15] = { "o", "no", "b", "ae", "e", "ne", "be", "a", "s", "ns", "pe", "po",
2243                                "l", "ge", "le" };
2244 
2245   std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
2246   std::ostringstream str;
2247 
2248   for (auto reg : registers) {
2249     for (size_t i = 0; i < 15; ++i) {
2250       assembler->setcc(static_cast<x86_64::Condition>(i), *reg);
2251       str << "set" << suffixes[i] << " %" << assembler_test->GetQuaternaryRegisterName(*reg) << "\n";
2252     }
2253   }
2254 
2255   return str.str();
2256 }
2257 
TEST_F(AssemblerX86_64Test,SetCC)2258 TEST_F(AssemblerX86_64Test, SetCC) {
2259   DriverFn(&setcc_test_fn, "setcc");
2260 }
2261 
TEST_F(AssemblerX86_64Test,MovzxbRegs)2262 TEST_F(AssemblerX86_64Test, MovzxbRegs) {
2263   DriverStr(Repeatrb(&x86_64::X86_64Assembler::movzxb, "movzbl %{reg2}, %{reg1}"), "movzxb");
2264 }
2265 
TEST_F(AssemblerX86_64Test,MovsxbRegs)2266 TEST_F(AssemblerX86_64Test, MovsxbRegs) {
2267   DriverStr(Repeatrb(&x86_64::X86_64Assembler::movsxb, "movsbl %{reg2}, %{reg1}"), "movsxb");
2268 }
2269 
TEST_F(AssemblerX86_64Test,Repnescasw)2270 TEST_F(AssemblerX86_64Test, Repnescasw) {
2271   GetAssembler()->repne_scasw();
2272   const char* expected = "repne scasw\n";
2273   DriverStr(expected, "Repnescasw");
2274 }
2275 
TEST_F(AssemblerX86_64Test,Repecmpsw)2276 TEST_F(AssemblerX86_64Test, Repecmpsw) {
2277   GetAssembler()->repe_cmpsw();
2278   const char* expected = "repe cmpsw\n";
2279   DriverStr(expected, "Repecmpsw");
2280 }
2281 
TEST_F(AssemblerX86_64Test,Repecmpsl)2282 TEST_F(AssemblerX86_64Test, Repecmpsl) {
2283   GetAssembler()->repe_cmpsl();
2284   const char* expected = "repe cmpsl\n";
2285   DriverStr(expected, "Repecmpsl");
2286 }
2287 
TEST_F(AssemblerX86_64Test,Repecmpsq)2288 TEST_F(AssemblerX86_64Test, Repecmpsq) {
2289   GetAssembler()->repe_cmpsq();
2290   const char* expected = "repe cmpsq\n";
2291   DriverStr(expected, "Repecmpsq");
2292 }
2293 
TEST_F(AssemblerX86_64Test,Cmpb)2294 TEST_F(AssemblerX86_64Test, Cmpb) {
2295   DriverStr(RepeatAI(&x86_64::X86_64Assembler::cmpb,
2296                      /*imm_bytes*/ 1U,
2297                      "cmpb ${imm}, {mem}"), "cmpb");
2298 }
2299 
TEST_F(AssemblerX86_64Test,TestbAddressImmediate)2300 TEST_F(AssemblerX86_64Test, TestbAddressImmediate) {
2301   DriverStr(RepeatAI(&x86_64::X86_64Assembler::testb,
2302                      /*imm_bytes*/ 1U,
2303                      "testb ${imm}, {mem}"), "testbi");
2304 }
2305 
TEST_F(AssemblerX86_64Test,TestlAddressImmediate)2306 TEST_F(AssemblerX86_64Test, TestlAddressImmediate) {
2307   DriverStr(RepeatAI(&x86_64::X86_64Assembler::testl,
2308                      /*imm_bytes*/ 4U,
2309                      "testl ${imm}, {mem}"), "testli");
2310 }
2311 
2312 class JNIMacroAssemblerX86_64Test : public JNIMacroAssemblerTest<x86_64::X86_64JNIMacroAssembler> {
2313  public:
2314   using Base = JNIMacroAssemblerTest<x86_64::X86_64JNIMacroAssembler>;
2315 
2316  protected:
GetIsa()2317   InstructionSet GetIsa() override {
2318     return InstructionSet::kX86_64;
2319   }
2320 
2321  private:
2322 };
2323 
ManagedFromCpu(x86_64::Register r)2324 static x86_64::X86_64ManagedRegister ManagedFromCpu(x86_64::Register r) {
2325   return x86_64::X86_64ManagedRegister::FromCpuRegister(r);
2326 }
2327 
ManagedFromFpu(x86_64::FloatRegister r)2328 static x86_64::X86_64ManagedRegister ManagedFromFpu(x86_64::FloatRegister r) {
2329   return x86_64::X86_64ManagedRegister::FromXmmRegister(r);
2330 }
2331 
buildframe_test_fn(JNIMacroAssemblerX86_64Test::Base * assembler_test ATTRIBUTE_UNUSED,x86_64::X86_64JNIMacroAssembler * assembler)2332 std::string buildframe_test_fn(JNIMacroAssemblerX86_64Test::Base* assembler_test ATTRIBUTE_UNUSED,
2333                                x86_64::X86_64JNIMacroAssembler* assembler) {
2334   // TODO: more interesting spill registers / entry spills.
2335 
2336   // Two random spill regs.
2337   const ManagedRegister raw_spill_regs[] = {
2338       ManagedFromCpu(x86_64::R10),
2339       ManagedFromCpu(x86_64::RSI)
2340   };
2341   ArrayRef<const ManagedRegister> spill_regs(raw_spill_regs);
2342 
2343   x86_64::X86_64ManagedRegister method_reg = ManagedFromCpu(x86_64::RDI);
2344 
2345   size_t frame_size = 10 * kStackAlignment;
2346   assembler->BuildFrame(frame_size, method_reg, spill_regs);
2347 
2348   // Three random entry spills.
2349   assembler->Store(FrameOffset(frame_size + 0u), ManagedFromCpu(x86_64::RAX), /* size= */ 8u);
2350   assembler->Store(FrameOffset(frame_size + 8u), ManagedFromCpu(x86_64::RBX), /* size= */ 8u);
2351   assembler->Store(FrameOffset(frame_size + 16u), ManagedFromFpu(x86_64::XMM1), /* size= */ 8u);
2352 
2353   // Construct assembly text counterpart.
2354   std::ostringstream str;
2355   // (1) Push the spill_regs.
2356   str << "pushq %rsi\n";
2357   str << "pushq %r10\n";
2358   // (2) Move down the stack pointer.
2359   ssize_t displacement = static_cast<ssize_t>(frame_size) - (spill_regs.size() * 8 + 8);
2360   str << "subq $" << displacement << ", %rsp\n";
2361   // (3) Store method reference.
2362   str << "movq %rdi, (%rsp)\n";
2363   // (4) Entry spills.
2364   str << "movq %rax, " << frame_size + 0 << "(%rsp)\n";
2365   str << "movq %rbx, " << frame_size + 8 << "(%rsp)\n";
2366   str << "movsd %xmm1, " << frame_size + 16 << "(%rsp)\n";
2367 
2368   return str.str();
2369 }
2370 
TEST_F(JNIMacroAssemblerX86_64Test,BuildFrame)2371 TEST_F(JNIMacroAssemblerX86_64Test, BuildFrame) {
2372   DriverFn(&buildframe_test_fn, "BuildFrame");
2373 }
2374 
removeframe_test_fn(JNIMacroAssemblerX86_64Test::Base * assembler_test ATTRIBUTE_UNUSED,x86_64::X86_64JNIMacroAssembler * assembler)2375 std::string removeframe_test_fn(JNIMacroAssemblerX86_64Test::Base* assembler_test ATTRIBUTE_UNUSED,
2376                                 x86_64::X86_64JNIMacroAssembler* assembler) {
2377   // TODO: more interesting spill registers / entry spills.
2378 
2379   // Two random spill regs.
2380   const ManagedRegister raw_spill_regs[] = {
2381       ManagedFromCpu(x86_64::R10),
2382       ManagedFromCpu(x86_64::RSI)
2383   };
2384   ArrayRef<const ManagedRegister> spill_regs(raw_spill_regs);
2385 
2386   size_t frame_size = 10 * kStackAlignment;
2387   assembler->RemoveFrame(frame_size, spill_regs, /* may_suspend= */ true);
2388 
2389   // Construct assembly text counterpart.
2390   std::ostringstream str;
2391   // (1) Move up the stack pointer.
2392   ssize_t displacement = static_cast<ssize_t>(frame_size) - spill_regs.size() * 8 - 8;
2393   str << "addq $" << displacement << ", %rsp\n";
2394   // (2) Pop spill regs.
2395   str << "popq %r10\n";
2396   str << "popq %rsi\n";
2397   str << "ret\n";
2398 
2399   return str.str();
2400 }
2401 
TEST_F(JNIMacroAssemblerX86_64Test,RemoveFrame)2402 TEST_F(JNIMacroAssemblerX86_64Test, RemoveFrame) {
2403   DriverFn(&removeframe_test_fn, "RemoveFrame");
2404 }
2405 
increaseframe_test_fn(JNIMacroAssemblerX86_64Test::Base * assembler_test ATTRIBUTE_UNUSED,x86_64::X86_64JNIMacroAssembler * assembler)2406 std::string increaseframe_test_fn(
2407     JNIMacroAssemblerX86_64Test::Base* assembler_test ATTRIBUTE_UNUSED,
2408     x86_64::X86_64JNIMacroAssembler* assembler) {
2409   assembler->IncreaseFrameSize(0U);
2410   assembler->IncreaseFrameSize(kStackAlignment);
2411   assembler->IncreaseFrameSize(10 * kStackAlignment);
2412 
2413   // Construct assembly text counterpart.
2414   std::ostringstream str;
2415   // Increase by 0 is a NO-OP and ignored by the assembler.
2416   str << "addq $-" << kStackAlignment << ", %rsp\n";
2417   str << "addq $-" << 10 * kStackAlignment << ", %rsp\n";
2418 
2419   return str.str();
2420 }
2421 
TEST_F(JNIMacroAssemblerX86_64Test,IncreaseFrame)2422 TEST_F(JNIMacroAssemblerX86_64Test, IncreaseFrame) {
2423   DriverFn(&increaseframe_test_fn, "IncreaseFrame");
2424 }
2425 
decreaseframe_test_fn(JNIMacroAssemblerX86_64Test::Base * assembler_test ATTRIBUTE_UNUSED,x86_64::X86_64JNIMacroAssembler * assembler)2426 std::string decreaseframe_test_fn(
2427     JNIMacroAssemblerX86_64Test::Base* assembler_test ATTRIBUTE_UNUSED,
2428     x86_64::X86_64JNIMacroAssembler* assembler) {
2429   assembler->DecreaseFrameSize(0U);
2430   assembler->DecreaseFrameSize(kStackAlignment);
2431   assembler->DecreaseFrameSize(10 * kStackAlignment);
2432 
2433   // Construct assembly text counterpart.
2434   std::ostringstream str;
2435   // Decrease by 0 is a NO-OP and ignored by the assembler.
2436   str << "addq $" << kStackAlignment << ", %rsp\n";
2437   str << "addq $" << 10 * kStackAlignment << ", %rsp\n";
2438 
2439   return str.str();
2440 }
2441 
TEST_F(JNIMacroAssemblerX86_64Test,DecreaseFrame)2442 TEST_F(JNIMacroAssemblerX86_64Test, DecreaseFrame) {
2443   DriverFn(&decreaseframe_test_fn, "DecreaseFrame");
2444 }
2445 
2446 }  // namespace art
2447