• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/stl_util.h"
25 #include "jni_macro_assembler_x86_64.h"
26 #include "utils/assembler_test.h"
27 #include "utils/jni_macro_assembler_test.h"
28 
29 namespace art {
30 
TEST(AssemblerX86_64,CreateBuffer)31 TEST(AssemblerX86_64, CreateBuffer) {
32   ArenaPool pool;
33   ArenaAllocator arena(&pool);
34   AssemblerBuffer buffer(&arena);
35   AssemblerBuffer::EnsureCapacity ensured(&buffer);
36   buffer.Emit<uint8_t>(0x42);
37   ASSERT_EQ(static_cast<size_t>(1), buffer.Size());
38   buffer.Emit<int32_t>(42);
39   ASSERT_EQ(static_cast<size_t>(5), buffer.Size());
40 }
41 
42 #ifdef ART_TARGET_ANDROID
43 static constexpr size_t kRandomIterations = 1000;  // Devices might be puny, don't stress them...
44 #else
45 static constexpr size_t kRandomIterations = 100000;  // Hosts are pretty powerful.
46 #endif
47 
TEST(AssemblerX86_64,SignExtension)48 TEST(AssemblerX86_64, SignExtension) {
49   // 32bit.
50   for (int32_t i = 0; i < 128; i++) {
51     EXPECT_TRUE(IsInt<8>(i)) << i;
52   }
53   for (int32_t i = 128; i < 255; i++) {
54     EXPECT_FALSE(IsInt<8>(i)) << i;
55   }
56   // Do some higher ones randomly.
57   std::random_device rd;
58   std::default_random_engine e1(rd());
59   std::uniform_int_distribution<int32_t> uniform_dist(256, INT32_MAX);
60   for (size_t i = 0; i < kRandomIterations; i++) {
61     int32_t value = uniform_dist(e1);
62     EXPECT_FALSE(IsInt<8>(value)) << value;
63   }
64 
65   // Negative ones.
66   for (int32_t i = -1; i >= -128; i--) {
67     EXPECT_TRUE(IsInt<8>(i)) << i;
68   }
69 
70   for (int32_t i = -129; i > -256; i--) {
71     EXPECT_FALSE(IsInt<8>(i)) << i;
72   }
73 
74   // Do some lower ones randomly.
75   std::uniform_int_distribution<int32_t> uniform_dist2(INT32_MIN, -256);
76   for (size_t i = 0; i < 100; i++) {
77     int32_t value = uniform_dist2(e1);
78     EXPECT_FALSE(IsInt<8>(value)) << value;
79   }
80 
81   // 64bit.
82   for (int64_t i = 0; i < 128; i++) {
83     EXPECT_TRUE(IsInt<8>(i)) << i;
84   }
85   for (int32_t i = 128; i < 255; i++) {
86     EXPECT_FALSE(IsInt<8>(i)) << i;
87   }
88   // Do some higher ones randomly.
89   std::uniform_int_distribution<int64_t> uniform_dist3(256, INT64_MAX);
90   for (size_t i = 0; i < 100; i++) {
91     int64_t value = uniform_dist3(e1);
92     EXPECT_FALSE(IsInt<8>(value)) << value;
93   }
94 
95   // Negative ones.
96   for (int64_t i = -1; i >= -128; i--) {
97     EXPECT_TRUE(IsInt<8>(i)) << i;
98   }
99 
100   for (int64_t i = -129; i > -256; i--) {
101     EXPECT_FALSE(IsInt<8>(i)) << i;
102   }
103 
104   // Do some lower ones randomly.
105   std::uniform_int_distribution<int64_t> uniform_dist4(INT64_MIN, -256);
106   for (size_t i = 0; i < kRandomIterations; i++) {
107     int64_t value = uniform_dist4(e1);
108     EXPECT_FALSE(IsInt<8>(value)) << value;
109   }
110 
111   int64_t value = INT64_C(0x1200000010);
112   x86_64::Immediate imm(value);
113   EXPECT_FALSE(imm.is_int8());
114   EXPECT_FALSE(imm.is_int16());
115   EXPECT_FALSE(imm.is_int32());
116   value = INT64_C(0x8000000000000001);
117   x86_64::Immediate imm2(value);
118   EXPECT_FALSE(imm2.is_int8());
119   EXPECT_FALSE(imm2.is_int16());
120   EXPECT_FALSE(imm2.is_int32());
121 }
122 
123 struct X86_64CpuRegisterCompare {
operator ()art::X86_64CpuRegisterCompare124     bool operator()(const x86_64::CpuRegister& a, const x86_64::CpuRegister& b) const {
125         return a.AsRegister() < b.AsRegister();
126     }
127 };
128 
129 class AssemblerX86_64Test : public AssemblerTest<x86_64::X86_64Assembler, x86_64::CpuRegister,
130                                                  x86_64::XmmRegister, x86_64::Immediate> {
131  public:
132   typedef AssemblerTest<x86_64::X86_64Assembler, x86_64::CpuRegister,
133                         x86_64::XmmRegister, x86_64::Immediate> Base;
134 
135  protected:
136   // Get the typically used name for this architecture, e.g., aarch64, x86-64, ...
GetArchitectureString()137   std::string GetArchitectureString() OVERRIDE {
138     return "x86_64";
139   }
140 
GetDisassembleParameters()141   std::string GetDisassembleParameters() OVERRIDE {
142     return " -D -bbinary -mi386:x86-64 -Mx86-64,addr64,data32 --no-show-raw-insn";
143   }
144 
SetUpHelpers()145   void SetUpHelpers() OVERRIDE {
146     if (registers_.size() == 0) {
147       registers_.push_back(new x86_64::CpuRegister(x86_64::RAX));
148       registers_.push_back(new x86_64::CpuRegister(x86_64::RBX));
149       registers_.push_back(new x86_64::CpuRegister(x86_64::RCX));
150       registers_.push_back(new x86_64::CpuRegister(x86_64::RDX));
151       registers_.push_back(new x86_64::CpuRegister(x86_64::RBP));
152       registers_.push_back(new x86_64::CpuRegister(x86_64::RSP));
153       registers_.push_back(new x86_64::CpuRegister(x86_64::RSI));
154       registers_.push_back(new x86_64::CpuRegister(x86_64::RDI));
155       registers_.push_back(new x86_64::CpuRegister(x86_64::R8));
156       registers_.push_back(new x86_64::CpuRegister(x86_64::R9));
157       registers_.push_back(new x86_64::CpuRegister(x86_64::R10));
158       registers_.push_back(new x86_64::CpuRegister(x86_64::R11));
159       registers_.push_back(new x86_64::CpuRegister(x86_64::R12));
160       registers_.push_back(new x86_64::CpuRegister(x86_64::R13));
161       registers_.push_back(new x86_64::CpuRegister(x86_64::R14));
162       registers_.push_back(new x86_64::CpuRegister(x86_64::R15));
163 
164       secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::RAX), "eax");
165       secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::RBX), "ebx");
166       secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::RCX), "ecx");
167       secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::RDX), "edx");
168       secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::RBP), "ebp");
169       secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::RSP), "esp");
170       secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::RSI), "esi");
171       secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::RDI), "edi");
172       secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::R8), "r8d");
173       secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::R9), "r9d");
174       secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::R10), "r10d");
175       secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::R11), "r11d");
176       secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::R12), "r12d");
177       secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::R13), "r13d");
178       secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::R14), "r14d");
179       secondary_register_names_.emplace(x86_64::CpuRegister(x86_64::R15), "r15d");
180 
181       tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::RAX), "ax");
182       tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::RBX), "bx");
183       tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::RCX), "cx");
184       tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::RDX), "dx");
185       tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::RBP), "bp");
186       tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::RSP), "sp");
187       tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::RSI), "si");
188       tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::RDI), "di");
189       tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::R8), "r8w");
190       tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::R9), "r9w");
191       tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::R10), "r10w");
192       tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::R11), "r11w");
193       tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::R12), "r12w");
194       tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::R13), "r13w");
195       tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::R14), "r14w");
196       tertiary_register_names_.emplace(x86_64::CpuRegister(x86_64::R15), "r15w");
197 
198       quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::RAX), "al");
199       quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::RBX), "bl");
200       quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::RCX), "cl");
201       quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::RDX), "dl");
202       quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::RBP), "bpl");
203       quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::RSP), "spl");
204       quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::RSI), "sil");
205       quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::RDI), "dil");
206       quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::R8), "r8b");
207       quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::R9), "r9b");
208       quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::R10), "r10b");
209       quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::R11), "r11b");
210       quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::R12), "r12b");
211       quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::R13), "r13b");
212       quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::R14), "r14b");
213       quaternary_register_names_.emplace(x86_64::CpuRegister(x86_64::R15), "r15b");
214 
215       fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM0));
216       fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM1));
217       fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM2));
218       fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM3));
219       fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM4));
220       fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM5));
221       fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM6));
222       fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM7));
223       fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM8));
224       fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM9));
225       fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM10));
226       fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM11));
227       fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM12));
228       fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM13));
229       fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM14));
230       fp_registers_.push_back(new x86_64::XmmRegister(x86_64::XMM15));
231     }
232   }
233 
TearDown()234   void TearDown() OVERRIDE {
235     AssemblerTest::TearDown();
236     STLDeleteElements(&registers_);
237     STLDeleteElements(&fp_registers_);
238   }
239 
GetRegisters()240   std::vector<x86_64::CpuRegister*> GetRegisters() OVERRIDE {
241     return registers_;
242   }
243 
GetFPRegisters()244   std::vector<x86_64::XmmRegister*> GetFPRegisters() OVERRIDE {
245     return fp_registers_;
246   }
247 
CreateImmediate(int64_t imm_value)248   x86_64::Immediate CreateImmediate(int64_t imm_value) OVERRIDE {
249     return x86_64::Immediate(imm_value);
250   }
251 
GetSecondaryRegisterName(const x86_64::CpuRegister & reg)252   std::string GetSecondaryRegisterName(const x86_64::CpuRegister& reg) OVERRIDE {
253     CHECK(secondary_register_names_.find(reg) != secondary_register_names_.end());
254     return secondary_register_names_[reg];
255   }
256 
GetTertiaryRegisterName(const x86_64::CpuRegister & reg)257   std::string GetTertiaryRegisterName(const x86_64::CpuRegister& reg) OVERRIDE {
258     CHECK(tertiary_register_names_.find(reg) != tertiary_register_names_.end());
259     return tertiary_register_names_[reg];
260   }
261 
GetQuaternaryRegisterName(const x86_64::CpuRegister & reg)262   std::string GetQuaternaryRegisterName(const x86_64::CpuRegister& reg) OVERRIDE {
263     CHECK(quaternary_register_names_.find(reg) != quaternary_register_names_.end());
264     return quaternary_register_names_[reg];
265   }
266 
267  private:
268   std::vector<x86_64::CpuRegister*> registers_;
269   std::map<x86_64::CpuRegister, std::string, X86_64CpuRegisterCompare> secondary_register_names_;
270   std::map<x86_64::CpuRegister, std::string, X86_64CpuRegisterCompare> tertiary_register_names_;
271   std::map<x86_64::CpuRegister, std::string, X86_64CpuRegisterCompare> quaternary_register_names_;
272 
273   std::vector<x86_64::XmmRegister*> fp_registers_;
274 };
275 
276 
TEST_F(AssemblerX86_64Test,Toolchain)277 TEST_F(AssemblerX86_64Test, Toolchain) {
278   EXPECT_TRUE(CheckTools());
279 }
280 
281 
TEST_F(AssemblerX86_64Test,PushqRegs)282 TEST_F(AssemblerX86_64Test, PushqRegs) {
283   DriverStr(RepeatR(&x86_64::X86_64Assembler::pushq, "pushq %{reg}"), "pushq");
284 }
285 
TEST_F(AssemblerX86_64Test,PushqImm)286 TEST_F(AssemblerX86_64Test, PushqImm) {
287   DriverStr(RepeatI(&x86_64::X86_64Assembler::pushq, 4U, "pushq ${imm}"), "pushqi");
288 }
289 
TEST_F(AssemblerX86_64Test,MovqRegs)290 TEST_F(AssemblerX86_64Test, MovqRegs) {
291   DriverStr(RepeatRR(&x86_64::X86_64Assembler::movq, "movq %{reg2}, %{reg1}"), "movq");
292 }
293 
TEST_F(AssemblerX86_64Test,MovqImm)294 TEST_F(AssemblerX86_64Test, MovqImm) {
295   DriverStr(RepeatRI(&x86_64::X86_64Assembler::movq, 8U, "movq ${imm}, %{reg}"), "movqi");
296 }
297 
TEST_F(AssemblerX86_64Test,MovlRegs)298 TEST_F(AssemblerX86_64Test, MovlRegs) {
299   DriverStr(Repeatrr(&x86_64::X86_64Assembler::movl, "mov %{reg2}, %{reg1}"), "movl");
300 }
301 
TEST_F(AssemblerX86_64Test,MovlImm)302 TEST_F(AssemblerX86_64Test, MovlImm) {
303   DriverStr(Repeatri(&x86_64::X86_64Assembler::movl, 4U, "mov ${imm}, %{reg}"), "movli");
304 }
305 
TEST_F(AssemblerX86_64Test,AddqRegs)306 TEST_F(AssemblerX86_64Test, AddqRegs) {
307   DriverStr(RepeatRR(&x86_64::X86_64Assembler::addq, "addq %{reg2}, %{reg1}"), "addq");
308 }
309 
TEST_F(AssemblerX86_64Test,AddqImm)310 TEST_F(AssemblerX86_64Test, AddqImm) {
311   DriverStr(RepeatRI(&x86_64::X86_64Assembler::addq, 4U, "addq ${imm}, %{reg}"), "addqi");
312 }
313 
TEST_F(AssemblerX86_64Test,AddlRegs)314 TEST_F(AssemblerX86_64Test, AddlRegs) {
315   DriverStr(Repeatrr(&x86_64::X86_64Assembler::addl, "add %{reg2}, %{reg1}"), "addl");
316 }
317 
TEST_F(AssemblerX86_64Test,AddlImm)318 TEST_F(AssemblerX86_64Test, AddlImm) {
319   DriverStr(Repeatri(&x86_64::X86_64Assembler::addl, 4U, "add ${imm}, %{reg}"), "addli");
320 }
321 
TEST_F(AssemblerX86_64Test,ImulqReg1)322 TEST_F(AssemblerX86_64Test, ImulqReg1) {
323   DriverStr(RepeatR(&x86_64::X86_64Assembler::imulq, "imulq %{reg}"), "imulq");
324 }
325 
TEST_F(AssemblerX86_64Test,ImulqRegs)326 TEST_F(AssemblerX86_64Test, ImulqRegs) {
327   DriverStr(RepeatRR(&x86_64::X86_64Assembler::imulq, "imulq %{reg2}, %{reg1}"), "imulq");
328 }
329 
TEST_F(AssemblerX86_64Test,ImulqImm)330 TEST_F(AssemblerX86_64Test, ImulqImm) {
331   DriverStr(RepeatRI(&x86_64::X86_64Assembler::imulq, 4U, "imulq ${imm}, %{reg}, %{reg}"),
332             "imulqi");
333 }
334 
TEST_F(AssemblerX86_64Test,ImullRegs)335 TEST_F(AssemblerX86_64Test, ImullRegs) {
336   DriverStr(Repeatrr(&x86_64::X86_64Assembler::imull, "imul %{reg2}, %{reg1}"), "imull");
337 }
338 
TEST_F(AssemblerX86_64Test,ImullImm)339 TEST_F(AssemblerX86_64Test, ImullImm) {
340   DriverStr(Repeatri(&x86_64::X86_64Assembler::imull, 4U, "imull ${imm}, %{reg}, %{reg}"),
341             "imulli");
342 }
343 
TEST_F(AssemblerX86_64Test,Mull)344 TEST_F(AssemblerX86_64Test, Mull) {
345   DriverStr(Repeatr(&x86_64::X86_64Assembler::mull, "mull %{reg}"), "mull");
346 }
347 
TEST_F(AssemblerX86_64Test,SubqRegs)348 TEST_F(AssemblerX86_64Test, SubqRegs) {
349   DriverStr(RepeatRR(&x86_64::X86_64Assembler::subq, "subq %{reg2}, %{reg1}"), "subq");
350 }
351 
TEST_F(AssemblerX86_64Test,SubqImm)352 TEST_F(AssemblerX86_64Test, SubqImm) {
353   DriverStr(RepeatRI(&x86_64::X86_64Assembler::subq, 4U, "subq ${imm}, %{reg}"), "subqi");
354 }
355 
TEST_F(AssemblerX86_64Test,SublRegs)356 TEST_F(AssemblerX86_64Test, SublRegs) {
357   DriverStr(Repeatrr(&x86_64::X86_64Assembler::subl, "sub %{reg2}, %{reg1}"), "subl");
358 }
359 
TEST_F(AssemblerX86_64Test,SublImm)360 TEST_F(AssemblerX86_64Test, SublImm) {
361   DriverStr(Repeatri(&x86_64::X86_64Assembler::subl, 4U, "sub ${imm}, %{reg}"), "subli");
362 }
363 
364 // Shll only allows CL as the shift count.
shll_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)365 std::string shll_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
366   std::ostringstream str;
367 
368   std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
369 
370   x86_64::CpuRegister shifter(x86_64::RCX);
371   for (auto reg : registers) {
372     assembler->shll(*reg, shifter);
373     str << "shll %cl, %" << assembler_test->GetSecondaryRegisterName(*reg) << "\n";
374   }
375 
376   return str.str();
377 }
378 
TEST_F(AssemblerX86_64Test,ShllReg)379 TEST_F(AssemblerX86_64Test, ShllReg) {
380   DriverFn(&shll_fn, "shll");
381 }
382 
TEST_F(AssemblerX86_64Test,ShllImm)383 TEST_F(AssemblerX86_64Test, ShllImm) {
384   DriverStr(Repeatri(&x86_64::X86_64Assembler::shll, 1U, "shll ${imm}, %{reg}"), "shlli");
385 }
386 
387 // Shlq only allows CL as the shift count.
shlq_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)388 std::string shlq_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
389   std::ostringstream str;
390 
391   std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
392 
393   x86_64::CpuRegister shifter(x86_64::RCX);
394   for (auto reg : registers) {
395     assembler->shlq(*reg, shifter);
396     str << "shlq %cl, %" << assembler_test->GetRegisterName(*reg) << "\n";
397   }
398 
399   return str.str();
400 }
401 
TEST_F(AssemblerX86_64Test,ShlqReg)402 TEST_F(AssemblerX86_64Test, ShlqReg) {
403   DriverFn(&shlq_fn, "shlq");
404 }
405 
TEST_F(AssemblerX86_64Test,ShlqImm)406 TEST_F(AssemblerX86_64Test, ShlqImm) {
407   DriverStr(RepeatRI(&x86_64::X86_64Assembler::shlq, 1U, "shlq ${imm}, %{reg}"), "shlqi");
408 }
409 
410 // Shrl only allows CL as the shift count.
shrl_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)411 std::string shrl_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
412   std::ostringstream str;
413 
414   std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
415 
416   x86_64::CpuRegister shifter(x86_64::RCX);
417   for (auto reg : registers) {
418     assembler->shrl(*reg, shifter);
419     str << "shrl %cl, %" << assembler_test->GetSecondaryRegisterName(*reg) << "\n";
420   }
421 
422   return str.str();
423 }
424 
TEST_F(AssemblerX86_64Test,ShrlReg)425 TEST_F(AssemblerX86_64Test, ShrlReg) {
426   DriverFn(&shrl_fn, "shrl");
427 }
428 
TEST_F(AssemblerX86_64Test,ShrlImm)429 TEST_F(AssemblerX86_64Test, ShrlImm) {
430   DriverStr(Repeatri(&x86_64::X86_64Assembler::shrl, 1U, "shrl ${imm}, %{reg}"), "shrli");
431 }
432 
433 // Shrq only allows CL as the shift count.
shrq_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)434 std::string shrq_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
435   std::ostringstream str;
436 
437   std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
438 
439   x86_64::CpuRegister shifter(x86_64::RCX);
440   for (auto reg : registers) {
441     assembler->shrq(*reg, shifter);
442     str << "shrq %cl, %" << assembler_test->GetRegisterName(*reg) << "\n";
443   }
444 
445   return str.str();
446 }
447 
TEST_F(AssemblerX86_64Test,ShrqReg)448 TEST_F(AssemblerX86_64Test, ShrqReg) {
449   DriverFn(&shrq_fn, "shrq");
450 }
451 
TEST_F(AssemblerX86_64Test,ShrqImm)452 TEST_F(AssemblerX86_64Test, ShrqImm) {
453   DriverStr(RepeatRI(&x86_64::X86_64Assembler::shrq, 1U, "shrq ${imm}, %{reg}"), "shrqi");
454 }
455 
456 // Sarl only allows CL as the shift count.
sarl_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)457 std::string sarl_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
458   std::ostringstream str;
459 
460   std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
461 
462   x86_64::CpuRegister shifter(x86_64::RCX);
463   for (auto reg : registers) {
464     assembler->sarl(*reg, shifter);
465     str << "sarl %cl, %" << assembler_test->GetSecondaryRegisterName(*reg) << "\n";
466   }
467 
468   return str.str();
469 }
470 
TEST_F(AssemblerX86_64Test,SarlReg)471 TEST_F(AssemblerX86_64Test, SarlReg) {
472   DriverFn(&sarl_fn, "sarl");
473 }
474 
TEST_F(AssemblerX86_64Test,SarlImm)475 TEST_F(AssemblerX86_64Test, SarlImm) {
476   DriverStr(Repeatri(&x86_64::X86_64Assembler::sarl, 1U, "sarl ${imm}, %{reg}"), "sarli");
477 }
478 
479 // Sarq only allows CL as the shift count.
sarq_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)480 std::string sarq_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
481   std::ostringstream str;
482 
483   std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
484 
485   x86_64::CpuRegister shifter(x86_64::RCX);
486   for (auto reg : registers) {
487     assembler->sarq(*reg, shifter);
488     str << "sarq %cl, %" << assembler_test->GetRegisterName(*reg) << "\n";
489   }
490 
491   return str.str();
492 }
493 
TEST_F(AssemblerX86_64Test,SarqReg)494 TEST_F(AssemblerX86_64Test, SarqReg) {
495   DriverFn(&sarq_fn, "sarq");
496 }
497 
TEST_F(AssemblerX86_64Test,SarqImm)498 TEST_F(AssemblerX86_64Test, SarqImm) {
499   DriverStr(RepeatRI(&x86_64::X86_64Assembler::sarq, 1U, "sarq ${imm}, %{reg}"), "sarqi");
500 }
501 
502 // Rorl only allows CL as the shift count.
rorl_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)503 std::string rorl_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
504   std::ostringstream str;
505 
506   std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
507 
508   x86_64::CpuRegister shifter(x86_64::RCX);
509   for (auto reg : registers) {
510     assembler->rorl(*reg, shifter);
511     str << "rorl %cl, %" << assembler_test->GetSecondaryRegisterName(*reg) << "\n";
512   }
513 
514   return str.str();
515 }
516 
TEST_F(AssemblerX86_64Test,RorlReg)517 TEST_F(AssemblerX86_64Test, RorlReg) {
518   DriverFn(&rorl_fn, "rorl");
519 }
520 
TEST_F(AssemblerX86_64Test,RorlImm)521 TEST_F(AssemblerX86_64Test, RorlImm) {
522   DriverStr(Repeatri(&x86_64::X86_64Assembler::rorl, 1U, "rorl ${imm}, %{reg}"), "rorli");
523 }
524 
525 // Roll only allows CL as the shift count.
roll_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)526 std::string roll_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
527   std::ostringstream str;
528 
529   std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
530 
531   x86_64::CpuRegister shifter(x86_64::RCX);
532   for (auto reg : registers) {
533     assembler->roll(*reg, shifter);
534     str << "roll %cl, %" << assembler_test->GetSecondaryRegisterName(*reg) << "\n";
535   }
536 
537   return str.str();
538 }
539 
TEST_F(AssemblerX86_64Test,RollReg)540 TEST_F(AssemblerX86_64Test, RollReg) {
541   DriverFn(&roll_fn, "roll");
542 }
543 
TEST_F(AssemblerX86_64Test,RollImm)544 TEST_F(AssemblerX86_64Test, RollImm) {
545   DriverStr(Repeatri(&x86_64::X86_64Assembler::roll, 1U, "roll ${imm}, %{reg}"), "rolli");
546 }
547 
548 // Rorq only allows CL as the shift count.
rorq_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)549 std::string rorq_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
550   std::ostringstream str;
551 
552   std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
553 
554   x86_64::CpuRegister shifter(x86_64::RCX);
555   for (auto reg : registers) {
556     assembler->rorq(*reg, shifter);
557     str << "rorq %cl, %" << assembler_test->GetRegisterName(*reg) << "\n";
558   }
559 
560   return str.str();
561 }
562 
TEST_F(AssemblerX86_64Test,RorqReg)563 TEST_F(AssemblerX86_64Test, RorqReg) {
564   DriverFn(&rorq_fn, "rorq");
565 }
566 
TEST_F(AssemblerX86_64Test,RorqImm)567 TEST_F(AssemblerX86_64Test, RorqImm) {
568   DriverStr(RepeatRI(&x86_64::X86_64Assembler::rorq, 1U, "rorq ${imm}, %{reg}"), "rorqi");
569 }
570 
571 // Rolq only allows CL as the shift count.
rolq_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)572 std::string rolq_fn(AssemblerX86_64Test::Base* assembler_test, x86_64::X86_64Assembler* assembler) {
573   std::ostringstream str;
574 
575   std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
576 
577   x86_64::CpuRegister shifter(x86_64::RCX);
578   for (auto reg : registers) {
579     assembler->rolq(*reg, shifter);
580     str << "rolq %cl, %" << assembler_test->GetRegisterName(*reg) << "\n";
581   }
582 
583   return str.str();
584 }
585 
TEST_F(AssemblerX86_64Test,RolqReg)586 TEST_F(AssemblerX86_64Test, RolqReg) {
587   DriverFn(&rolq_fn, "rolq");
588 }
589 
TEST_F(AssemblerX86_64Test,RolqImm)590 TEST_F(AssemblerX86_64Test, RolqImm) {
591   DriverStr(RepeatRI(&x86_64::X86_64Assembler::rolq, 1U, "rolq ${imm}, %{reg}"), "rolqi");
592 }
593 
TEST_F(AssemblerX86_64Test,CmpqRegs)594 TEST_F(AssemblerX86_64Test, CmpqRegs) {
595   DriverStr(RepeatRR(&x86_64::X86_64Assembler::cmpq, "cmpq %{reg2}, %{reg1}"), "cmpq");
596 }
597 
TEST_F(AssemblerX86_64Test,CmpqImm)598 TEST_F(AssemblerX86_64Test, CmpqImm) {
599   DriverStr(RepeatRI(&x86_64::X86_64Assembler::cmpq, 4U  /* cmpq only supports 32b imm */,
600                      "cmpq ${imm}, %{reg}"), "cmpqi");
601 }
602 
TEST_F(AssemblerX86_64Test,CmplRegs)603 TEST_F(AssemblerX86_64Test, CmplRegs) {
604   DriverStr(Repeatrr(&x86_64::X86_64Assembler::cmpl, "cmp %{reg2}, %{reg1}"), "cmpl");
605 }
606 
TEST_F(AssemblerX86_64Test,CmplImm)607 TEST_F(AssemblerX86_64Test, CmplImm) {
608   DriverStr(Repeatri(&x86_64::X86_64Assembler::cmpl, 4U, "cmpl ${imm}, %{reg}"), "cmpli");
609 }
610 
TEST_F(AssemblerX86_64Test,Testl)611 TEST_F(AssemblerX86_64Test, Testl) {
612   // Note: uses different order for GCC than usual. This makes GCC happy, and doesn't have an
613   // impact on functional correctness.
614   DriverStr(Repeatrr(&x86_64::X86_64Assembler::testl, "testl %{reg1}, %{reg2}"), "testl");
615 }
616 
TEST_F(AssemblerX86_64Test,Negq)617 TEST_F(AssemblerX86_64Test, Negq) {
618   DriverStr(RepeatR(&x86_64::X86_64Assembler::negq, "negq %{reg}"), "negq");
619 }
620 
TEST_F(AssemblerX86_64Test,Negl)621 TEST_F(AssemblerX86_64Test, Negl) {
622   DriverStr(Repeatr(&x86_64::X86_64Assembler::negl, "negl %{reg}"), "negl");
623 }
624 
TEST_F(AssemblerX86_64Test,Notq)625 TEST_F(AssemblerX86_64Test, Notq) {
626   DriverStr(RepeatR(&x86_64::X86_64Assembler::notq, "notq %{reg}"), "notq");
627 }
628 
TEST_F(AssemblerX86_64Test,Notl)629 TEST_F(AssemblerX86_64Test, Notl) {
630   DriverStr(Repeatr(&x86_64::X86_64Assembler::notl, "notl %{reg}"), "notl");
631 }
632 
TEST_F(AssemblerX86_64Test,AndqRegs)633 TEST_F(AssemblerX86_64Test, AndqRegs) {
634   DriverStr(RepeatRR(&x86_64::X86_64Assembler::andq, "andq %{reg2}, %{reg1}"), "andq");
635 }
636 
TEST_F(AssemblerX86_64Test,AndqImm)637 TEST_F(AssemblerX86_64Test, AndqImm) {
638   DriverStr(RepeatRI(&x86_64::X86_64Assembler::andq, 4U  /* andq only supports 32b imm */,
639                      "andq ${imm}, %{reg}"), "andqi");
640 }
641 
TEST_F(AssemblerX86_64Test,AndlRegs)642 TEST_F(AssemblerX86_64Test, AndlRegs) {
643   DriverStr(Repeatrr(&x86_64::X86_64Assembler::andl, "andl %{reg2}, %{reg1}"), "andl");
644 }
645 
TEST_F(AssemblerX86_64Test,AndlImm)646 TEST_F(AssemblerX86_64Test, AndlImm) {
647   DriverStr(Repeatri(&x86_64::X86_64Assembler::andl, 4U, "andl ${imm}, %{reg}"), "andli");
648 }
649 
TEST_F(AssemblerX86_64Test,OrqRegs)650 TEST_F(AssemblerX86_64Test, OrqRegs) {
651   DriverStr(RepeatRR(&x86_64::X86_64Assembler::orq, "orq %{reg2}, %{reg1}"), "orq");
652 }
653 
TEST_F(AssemblerX86_64Test,OrlRegs)654 TEST_F(AssemblerX86_64Test, OrlRegs) {
655   DriverStr(Repeatrr(&x86_64::X86_64Assembler::orl, "orl %{reg2}, %{reg1}"), "orl");
656 }
657 
TEST_F(AssemblerX86_64Test,OrlImm)658 TEST_F(AssemblerX86_64Test, OrlImm) {
659   DriverStr(Repeatri(&x86_64::X86_64Assembler::orl, 4U, "orl ${imm}, %{reg}"), "orli");
660 }
661 
TEST_F(AssemblerX86_64Test,XorqRegs)662 TEST_F(AssemblerX86_64Test, XorqRegs) {
663   DriverStr(RepeatRR(&x86_64::X86_64Assembler::xorq, "xorq %{reg2}, %{reg1}"), "xorq");
664 }
665 
TEST_F(AssemblerX86_64Test,XorqImm)666 TEST_F(AssemblerX86_64Test, XorqImm) {
667   DriverStr(RepeatRI(&x86_64::X86_64Assembler::xorq, 4U, "xorq ${imm}, %{reg}"), "xorqi");
668 }
669 
TEST_F(AssemblerX86_64Test,XorlRegs)670 TEST_F(AssemblerX86_64Test, XorlRegs) {
671   DriverStr(Repeatrr(&x86_64::X86_64Assembler::xorl, "xor %{reg2}, %{reg1}"), "xorl");
672 }
673 
TEST_F(AssemblerX86_64Test,XorlImm)674 TEST_F(AssemblerX86_64Test, XorlImm) {
675   DriverStr(Repeatri(&x86_64::X86_64Assembler::xorl, 4U, "xor ${imm}, %{reg}"), "xorli");
676 }
677 
TEST_F(AssemblerX86_64Test,Xchgq)678 TEST_F(AssemblerX86_64Test, Xchgq) {
679   DriverStr(RepeatRR(&x86_64::X86_64Assembler::xchgq, "xchgq %{reg2}, %{reg1}"), "xchgq");
680 }
681 
TEST_F(AssemblerX86_64Test,Xchgl)682 TEST_F(AssemblerX86_64Test, Xchgl) {
683   // Test is disabled because GCC generates 0x87 0xC0 for xchgl eax, eax. All other cases are the
684   // same. Anyone know why it doesn't emit a simple 0x90? It does so for xchgq rax, rax...
685   // DriverStr(Repeatrr(&x86_64::X86_64Assembler::xchgl, "xchgl %{reg2}, %{reg1}"), "xchgl");
686 }
687 
TEST_F(AssemblerX86_64Test,LockCmpxchgl)688 TEST_F(AssemblerX86_64Test, LockCmpxchgl) {
689   GetAssembler()->LockCmpxchgl(x86_64::Address(
690       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12),
691       x86_64::CpuRegister(x86_64::RSI));
692   GetAssembler()->LockCmpxchgl(x86_64::Address(
693       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12),
694       x86_64::CpuRegister(x86_64::RSI));
695   GetAssembler()->LockCmpxchgl(x86_64::Address(
696       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12),
697       x86_64::CpuRegister(x86_64::R8));
698   GetAssembler()->LockCmpxchgl(x86_64::Address(
699       x86_64::CpuRegister(x86_64::R13), 0), x86_64::CpuRegister(x86_64::RSI));
700   GetAssembler()->LockCmpxchgl(x86_64::Address(
701       x86_64::CpuRegister(x86_64::R13), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_1, 0),
702       x86_64::CpuRegister(x86_64::RSI));
703   const char* expected =
704     "lock cmpxchgl %ESI, 0xc(%RDI,%RBX,4)\n"
705     "lock cmpxchgl %ESI, 0xc(%RDI,%R9,4)\n"
706     "lock cmpxchgl %R8d, 0xc(%RDI,%R9,4)\n"
707     "lock cmpxchgl %ESI, (%R13)\n"
708     "lock cmpxchgl %ESI, (%R13,%R9,1)\n";
709 
710   DriverStr(expected, "lock_cmpxchgl");
711 }
712 
TEST_F(AssemblerX86_64Test,LockCmpxchgq)713 TEST_F(AssemblerX86_64Test, LockCmpxchgq) {
714   GetAssembler()->LockCmpxchgq(x86_64::Address(
715       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12),
716       x86_64::CpuRegister(x86_64::RSI));
717   GetAssembler()->LockCmpxchgq(x86_64::Address(
718       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12),
719       x86_64::CpuRegister(x86_64::RSI));
720   GetAssembler()->LockCmpxchgq(x86_64::Address(
721       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12),
722       x86_64::CpuRegister(x86_64::R8));
723   GetAssembler()->LockCmpxchgq(x86_64::Address(
724       x86_64::CpuRegister(x86_64::R13), 0), x86_64::CpuRegister(x86_64::RSI));
725   GetAssembler()->LockCmpxchgq(x86_64::Address(
726       x86_64::CpuRegister(x86_64::R13), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_1, 0),
727       x86_64::CpuRegister(x86_64::RSI));
728   const char* expected =
729     "lock cmpxchg %RSI, 0xc(%RDI,%RBX,4)\n"
730     "lock cmpxchg %RSI, 0xc(%RDI,%R9,4)\n"
731     "lock cmpxchg %R8, 0xc(%RDI,%R9,4)\n"
732     "lock cmpxchg %RSI, (%R13)\n"
733     "lock cmpxchg %RSI, (%R13,%R9,1)\n";
734 
735   DriverStr(expected, "lock_cmpxchg");
736 }
737 
TEST_F(AssemblerX86_64Test,Movl)738 TEST_F(AssemblerX86_64Test, Movl) {
739   GetAssembler()->movl(x86_64::CpuRegister(x86_64::RAX), x86_64::Address(
740       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12));
741   GetAssembler()->movl(x86_64::CpuRegister(x86_64::RAX), x86_64::Address(
742       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12));
743   GetAssembler()->movl(x86_64::CpuRegister(x86_64::R8), x86_64::Address(
744       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12));
745   GetAssembler()->movl(x86_64::CpuRegister(x86_64::RAX), x86_64::Address(
746       x86_64::CpuRegister(x86_64::R13), 0));
747   GetAssembler()->movl(x86_64::CpuRegister(x86_64::RAX), x86_64::Address(
748       x86_64::CpuRegister(x86_64::R13), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_1, 0));
749   const char* expected =
750     "movl 0xc(%RDI,%RBX,4), %EAX\n"
751     "movl 0xc(%RDI,%R9,4), %EAX\n"
752     "movl 0xc(%RDI,%R9,4), %R8d\n"
753     "movl (%R13), %EAX\n"
754     "movl (%R13,%R9,1), %EAX\n";
755 
756   DriverStr(expected, "movl");
757 }
758 
TEST_F(AssemblerX86_64Test,Movw)759 TEST_F(AssemblerX86_64Test, Movw) {
760   GetAssembler()->movw(x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0),
761                        x86_64::CpuRegister(x86_64::R9));
762   GetAssembler()->movw(x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0),
763                        x86_64::Immediate(0));
764   GetAssembler()->movw(x86_64::Address(x86_64::CpuRegister(x86_64::R9), 0),
765                        x86_64::Immediate(0));
766   GetAssembler()->movw(x86_64::Address(x86_64::CpuRegister(x86_64::R14), 0),
767                        x86_64::Immediate(0));
768   const char* expected =
769       "movw %R9w, 0(%RAX)\n"
770       "movw $0, 0(%RAX)\n"
771       "movw $0, 0(%R9)\n"
772       "movw $0, 0(%R14)\n";
773   DriverStr(expected, "movw");
774 }
775 
TEST_F(AssemblerX86_64Test,Cmpw)776 TEST_F(AssemblerX86_64Test, Cmpw) {
777   GetAssembler()->cmpw(x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0),
778                        x86_64::Immediate(0));
779   GetAssembler()->cmpw(x86_64::Address(x86_64::CpuRegister(x86_64::R9), 0),
780                        x86_64::Immediate(0));
781   GetAssembler()->cmpw(x86_64::Address(x86_64::CpuRegister(x86_64::R14), 0),
782                        x86_64::Immediate(0));
783   const char* expected =
784       "cmpw $0, 0(%RAX)\n"
785       "cmpw $0, 0(%R9)\n"
786       "cmpw $0, 0(%R14)\n";
787   DriverStr(expected, "cmpw");
788 }
789 
TEST_F(AssemblerX86_64Test,MovqAddrImm)790 TEST_F(AssemblerX86_64Test, MovqAddrImm) {
791   GetAssembler()->movq(x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0),
792                        x86_64::Immediate(-5));
793   const char* expected = "movq $-5, 0(%RAX)\n";
794   DriverStr(expected, "movq");
795 }
796 
TEST_F(AssemblerX86_64Test,Movntl)797 TEST_F(AssemblerX86_64Test, Movntl) {
798   GetAssembler()->movntl(x86_64::Address(
799       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12), x86_64::CpuRegister(x86_64::RAX));
800   GetAssembler()->movntl(x86_64::Address(
801       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12), x86_64::CpuRegister(x86_64::RAX));
802   GetAssembler()->movntl(x86_64::Address(
803       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12), x86_64::CpuRegister(x86_64::RAX));
804   GetAssembler()->movntl(x86_64::Address(x86_64::CpuRegister(x86_64::R13), 0), x86_64::CpuRegister(x86_64::RAX));
805   GetAssembler()->movntl(x86_64::Address(
806       x86_64::CpuRegister(x86_64::R13), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_1, 0), x86_64::CpuRegister(x86_64::R9));
807   const char* expected =
808     "movntil %EAX, 0xc(%RDI,%RBX,4)\n"
809     "movntil %EAX, 0xc(%RDI,%R9,4)\n"
810     "movntil %EAX, 0xc(%RDI,%R9,4)\n"
811     "movntil %EAX, (%R13)\n"
812     "movntil %R9d, (%R13,%R9,1)\n";
813 
814   DriverStr(expected, "movntl");
815 }
816 
TEST_F(AssemblerX86_64Test,Movntq)817 TEST_F(AssemblerX86_64Test, Movntq) {
818   GetAssembler()->movntq(x86_64::Address(
819       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12), x86_64::CpuRegister(x86_64::RAX));
820   GetAssembler()->movntq(x86_64::Address(
821       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12), x86_64::CpuRegister(x86_64::RAX));
822   GetAssembler()->movntq(x86_64::Address(
823       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12), x86_64::CpuRegister(x86_64::RAX));
824   GetAssembler()->movntq(x86_64::Address(x86_64::CpuRegister(x86_64::R13), 0), x86_64::CpuRegister(x86_64::RAX));
825   GetAssembler()->movntq(x86_64::Address(
826       x86_64::CpuRegister(x86_64::R13), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_1, 0), x86_64::CpuRegister(x86_64::R9));
827   const char* expected =
828     "movntiq %RAX, 0xc(%RDI,%RBX,4)\n"
829     "movntiq %RAX, 0xc(%RDI,%R9,4)\n"
830     "movntiq %RAX, 0xc(%RDI,%R9,4)\n"
831     "movntiq %RAX, (%R13)\n"
832     "movntiq %R9, (%R13,%R9,1)\n";
833 
834   DriverStr(expected, "movntq");
835 }
836 
TEST_F(AssemblerX86_64Test,Cvtsi2ssAddr)837 TEST_F(AssemblerX86_64Test, Cvtsi2ssAddr) {
838   GetAssembler()->cvtsi2ss(x86_64::XmmRegister(x86_64::XMM0),
839                            x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0),
840                            false);
841   GetAssembler()->cvtsi2ss(x86_64::XmmRegister(x86_64::XMM0),
842                            x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0),
843                            true);
844   const char* expected = "cvtsi2ss 0(%RAX), %xmm0\n"
845                          "cvtsi2ssq 0(%RAX), %xmm0\n";
846   DriverStr(expected, "cvtsi2ss");
847 }
848 
TEST_F(AssemblerX86_64Test,Cvtsi2sdAddr)849 TEST_F(AssemblerX86_64Test, Cvtsi2sdAddr) {
850   GetAssembler()->cvtsi2sd(x86_64::XmmRegister(x86_64::XMM0),
851                            x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0),
852                            false);
853   GetAssembler()->cvtsi2sd(x86_64::XmmRegister(x86_64::XMM0),
854                            x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0),
855                            true);
856   const char* expected = "cvtsi2sd 0(%RAX), %xmm0\n"
857                          "cvtsi2sdq 0(%RAX), %xmm0\n";
858   DriverStr(expected, "cvtsi2sd");
859 }
860 
TEST_F(AssemblerX86_64Test,CmpqAddr)861 TEST_F(AssemblerX86_64Test, CmpqAddr) {
862   GetAssembler()->cmpq(x86_64::CpuRegister(x86_64::R12),
863                        x86_64::Address(x86_64::CpuRegister(x86_64::R9), 0));
864   const char* expected = "cmpq 0(%R9), %R12\n";
865   DriverStr(expected, "cmpq");
866 }
867 
TEST_F(AssemblerX86_64Test,MovsxdAddr)868 TEST_F(AssemblerX86_64Test, MovsxdAddr) {
869   GetAssembler()->movsxd(x86_64::CpuRegister(x86_64::R12),
870                        x86_64::Address(x86_64::CpuRegister(x86_64::R9), 0));
871   const char* expected = "movslq 0(%R9), %R12\n";
872   DriverStr(expected, "movsxd");
873 }
874 
TEST_F(AssemblerX86_64Test,TestqAddr)875 TEST_F(AssemblerX86_64Test, TestqAddr) {
876   GetAssembler()->testq(x86_64::CpuRegister(x86_64::R12),
877                         x86_64::Address(x86_64::CpuRegister(x86_64::R9), 0));
878   const char* expected = "testq 0(%R9), %R12\n";
879   DriverStr(expected, "testq");
880 }
881 
TEST_F(AssemblerX86_64Test,AddqAddr)882 TEST_F(AssemblerX86_64Test, AddqAddr) {
883   GetAssembler()->addq(x86_64::CpuRegister(x86_64::R12),
884                         x86_64::Address(x86_64::CpuRegister(x86_64::R9), 0));
885   const char* expected = "addq 0(%R9), %R12\n";
886   DriverStr(expected, "addq");
887 }
888 
TEST_F(AssemblerX86_64Test,SubqAddr)889 TEST_F(AssemblerX86_64Test, SubqAddr) {
890   GetAssembler()->subq(x86_64::CpuRegister(x86_64::R12),
891                         x86_64::Address(x86_64::CpuRegister(x86_64::R9), 0));
892   const char* expected = "subq 0(%R9), %R12\n";
893   DriverStr(expected, "subq");
894 }
895 
TEST_F(AssemblerX86_64Test,Cvtss2sdAddr)896 TEST_F(AssemblerX86_64Test, Cvtss2sdAddr) {
897   GetAssembler()->cvtss2sd(x86_64::XmmRegister(x86_64::XMM0),
898                            x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0));
899   const char* expected = "cvtss2sd 0(%RAX), %xmm0\n";
900   DriverStr(expected, "cvtss2sd");
901 }
902 
TEST_F(AssemblerX86_64Test,Cvtsd2ssAddr)903 TEST_F(AssemblerX86_64Test, Cvtsd2ssAddr) {
904   GetAssembler()->cvtsd2ss(x86_64::XmmRegister(x86_64::XMM0),
905                            x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0));
906   const char* expected = "cvtsd2ss 0(%RAX), %xmm0\n";
907   DriverStr(expected, "cvtsd2ss");
908 }
909 
TEST_F(AssemblerX86_64Test,ComissAddr)910 TEST_F(AssemblerX86_64Test, ComissAddr) {
911   GetAssembler()->comiss(x86_64::XmmRegister(x86_64::XMM14),
912                            x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0));
913   const char* expected = "comiss 0(%RAX), %xmm14\n";
914   DriverStr(expected, "comiss");
915 }
916 
TEST_F(AssemblerX86_64Test,ComisdAddr)917 TEST_F(AssemblerX86_64Test, ComisdAddr) {
918   GetAssembler()->comisd(x86_64::XmmRegister(x86_64::XMM0),
919                            x86_64::Address(x86_64::CpuRegister(x86_64::R9), 0));
920   const char* expected = "comisd 0(%R9), %xmm0\n";
921   DriverStr(expected, "comisd");
922 }
923 
TEST_F(AssemblerX86_64Test,UComissAddr)924 TEST_F(AssemblerX86_64Test, UComissAddr) {
925   GetAssembler()->ucomiss(x86_64::XmmRegister(x86_64::XMM0),
926                            x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0));
927   const char* expected = "ucomiss 0(%RAX), %xmm0\n";
928   DriverStr(expected, "ucomiss");
929 }
930 
TEST_F(AssemblerX86_64Test,UComisdAddr)931 TEST_F(AssemblerX86_64Test, UComisdAddr) {
932   GetAssembler()->ucomisd(x86_64::XmmRegister(x86_64::XMM0),
933                            x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0));
934   const char* expected = "ucomisd 0(%RAX), %xmm0\n";
935   DriverStr(expected, "ucomisd");
936 }
937 
TEST_F(AssemblerX86_64Test,Andq)938 TEST_F(AssemblerX86_64Test, Andq) {
939   GetAssembler()->andq(x86_64::CpuRegister(x86_64::R9),
940                            x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0));
941   const char* expected = "andq 0(%RAX), %r9\n";
942   DriverStr(expected, "andq");
943 }
944 
TEST_F(AssemblerX86_64Test,Orq)945 TEST_F(AssemblerX86_64Test, Orq) {
946   GetAssembler()->orq(x86_64::CpuRegister(x86_64::R9),
947                            x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0));
948   const char* expected = "orq 0(%RAX), %r9\n";
949   DriverStr(expected, "orq");
950 }
951 
TEST_F(AssemblerX86_64Test,Xorq)952 TEST_F(AssemblerX86_64Test, Xorq) {
953   GetAssembler()->xorq(x86_64::CpuRegister(x86_64::R9),
954                            x86_64::Address(x86_64::CpuRegister(x86_64::RAX), 0));
955   const char* expected = "xorq 0(%RAX), %r9\n";
956   DriverStr(expected, "xorq");
957 }
958 
TEST_F(AssemblerX86_64Test,RepneScasb)959 TEST_F(AssemblerX86_64Test, RepneScasb) {
960   GetAssembler()->repne_scasb();
961   const char* expected = "repne scasb\n";
962   DriverStr(expected, "repne_scasb");
963 }
964 
TEST_F(AssemblerX86_64Test,RepneScasw)965 TEST_F(AssemblerX86_64Test, RepneScasw) {
966   GetAssembler()->repne_scasw();
967   const char* expected = "repne scasw\n";
968   DriverStr(expected, "repne_scasw");
969 }
970 
TEST_F(AssemblerX86_64Test,RepMovsw)971 TEST_F(AssemblerX86_64Test, RepMovsw) {
972   GetAssembler()->rep_movsw();
973   const char* expected = "rep movsw\n";
974   DriverStr(expected, "rep_movsw");
975 }
976 
TEST_F(AssemblerX86_64Test,Movsxd)977 TEST_F(AssemblerX86_64Test, Movsxd) {
978   DriverStr(RepeatRr(&x86_64::X86_64Assembler::movsxd, "movsxd %{reg2}, %{reg1}"), "movsxd");
979 }
980 
981 ///////////////////
982 // FP Operations //
983 ///////////////////
984 
TEST_F(AssemblerX86_64Test,Movaps)985 TEST_F(AssemblerX86_64Test, Movaps) {
986   DriverStr(RepeatFF(&x86_64::X86_64Assembler::movaps, "movaps %{reg2}, %{reg1}"), "movaps");
987 }
988 
TEST_F(AssemblerX86_64Test,MovapsAddr)989 TEST_F(AssemblerX86_64Test, MovapsAddr) {
990   GetAssembler()->movaps(x86_64::XmmRegister(x86_64::XMM0), x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 4));
991   GetAssembler()->movaps(x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 2), x86_64::XmmRegister(x86_64::XMM1));
992   const char* expected =
993     "movaps 0x4(%RSP), %xmm0\n"
994     "movaps %xmm1, 0x2(%RSP)\n";
995   DriverStr(expected, "movaps_address");
996 }
997 
TEST_F(AssemblerX86_64Test,MovupsAddr)998 TEST_F(AssemblerX86_64Test, MovupsAddr) {
999   GetAssembler()->movups(x86_64::XmmRegister(x86_64::XMM0), x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 4));
1000   GetAssembler()->movups(x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 2), x86_64::XmmRegister(x86_64::XMM1));
1001   const char* expected =
1002     "movups 0x4(%RSP), %xmm0\n"
1003     "movups %xmm1, 0x2(%RSP)\n";
1004   DriverStr(expected, "movups_address");
1005 }
1006 
TEST_F(AssemblerX86_64Test,Movss)1007 TEST_F(AssemblerX86_64Test, Movss) {
1008   DriverStr(RepeatFF(&x86_64::X86_64Assembler::movss, "movss %{reg2}, %{reg1}"), "movss");
1009 }
1010 
TEST_F(AssemblerX86_64Test,Movapd)1011 TEST_F(AssemblerX86_64Test, Movapd) {
1012   DriverStr(RepeatFF(&x86_64::X86_64Assembler::movapd, "movapd %{reg2}, %{reg1}"), "movapd");
1013 }
1014 
TEST_F(AssemblerX86_64Test,MovapdAddr)1015 TEST_F(AssemblerX86_64Test, MovapdAddr) {
1016   GetAssembler()->movapd(x86_64::XmmRegister(x86_64::XMM0), x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 4));
1017   GetAssembler()->movapd(x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 2), x86_64::XmmRegister(x86_64::XMM1));
1018   const char* expected =
1019     "movapd 0x4(%RSP), %xmm0\n"
1020     "movapd %xmm1, 0x2(%RSP)\n";
1021   DriverStr(expected, "movapd_address");
1022 }
1023 
TEST_F(AssemblerX86_64Test,MovupdAddr)1024 TEST_F(AssemblerX86_64Test, MovupdAddr) {
1025   GetAssembler()->movupd(x86_64::XmmRegister(x86_64::XMM0), x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 4));
1026   GetAssembler()->movupd(x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 2), x86_64::XmmRegister(x86_64::XMM1));
1027   const char* expected =
1028     "movupd 0x4(%RSP), %xmm0\n"
1029     "movupd %xmm1, 0x2(%RSP)\n";
1030   DriverStr(expected, "movupd_address");
1031 }
1032 
TEST_F(AssemblerX86_64Test,Movsd)1033 TEST_F(AssemblerX86_64Test, Movsd) {
1034   DriverStr(RepeatFF(&x86_64::X86_64Assembler::movsd, "movsd %{reg2}, %{reg1}"), "movsd");
1035 }
1036 
TEST_F(AssemblerX86_64Test,Movdqa)1037 TEST_F(AssemblerX86_64Test, Movdqa) {
1038   DriverStr(RepeatFF(&x86_64::X86_64Assembler::movdqa, "movdqa %{reg2}, %{reg1}"), "movapd");
1039 }
1040 
TEST_F(AssemblerX86_64Test,MovdqaAddr)1041 TEST_F(AssemblerX86_64Test, MovdqaAddr) {
1042   GetAssembler()->movdqa(x86_64::XmmRegister(x86_64::XMM0), x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 4));
1043   GetAssembler()->movdqa(x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 2), x86_64::XmmRegister(x86_64::XMM1));
1044   const char* expected =
1045     "movdqa 0x4(%RSP), %xmm0\n"
1046     "movdqa %xmm1, 0x2(%RSP)\n";
1047   DriverStr(expected, "movdqa_address");
1048 }
1049 
TEST_F(AssemblerX86_64Test,MovdquAddr)1050 TEST_F(AssemblerX86_64Test, MovdquAddr) {
1051   GetAssembler()->movdqu(x86_64::XmmRegister(x86_64::XMM0), x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 4));
1052   GetAssembler()->movdqu(x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 2), x86_64::XmmRegister(x86_64::XMM1));
1053   const char* expected =
1054     "movdqu 0x4(%RSP), %xmm0\n"
1055     "movdqu %xmm1, 0x2(%RSP)\n";
1056   DriverStr(expected, "movdqu_address");
1057 }
1058 
TEST_F(AssemblerX86_64Test,Movd1)1059 TEST_F(AssemblerX86_64Test, Movd1) {
1060   DriverStr(RepeatFR(&x86_64::X86_64Assembler::movd, "movd %{reg2}, %{reg1}"), "movd.1");
1061 }
1062 
TEST_F(AssemblerX86_64Test,Movd2)1063 TEST_F(AssemblerX86_64Test, Movd2) {
1064   DriverStr(RepeatRF(&x86_64::X86_64Assembler::movd, "movd %{reg2}, %{reg1}"), "movd.2");
1065 }
1066 
TEST_F(AssemblerX86_64Test,Addss)1067 TEST_F(AssemblerX86_64Test, Addss) {
1068   DriverStr(RepeatFF(&x86_64::X86_64Assembler::addss, "addss %{reg2}, %{reg1}"), "addss");
1069 }
1070 
TEST_F(AssemblerX86_64Test,Addsd)1071 TEST_F(AssemblerX86_64Test, Addsd) {
1072   DriverStr(RepeatFF(&x86_64::X86_64Assembler::addsd, "addsd %{reg2}, %{reg1}"), "addsd");
1073 }
1074 
TEST_F(AssemblerX86_64Test,Addps)1075 TEST_F(AssemblerX86_64Test, Addps) {
1076   DriverStr(RepeatFF(&x86_64::X86_64Assembler::addps, "addps %{reg2}, %{reg1}"), "addps");
1077 }
1078 
TEST_F(AssemblerX86_64Test,Addpd)1079 TEST_F(AssemblerX86_64Test, Addpd) {
1080   DriverStr(RepeatFF(&x86_64::X86_64Assembler::addpd, "addpd %{reg2}, %{reg1}"), "addpd");
1081 }
1082 
TEST_F(AssemblerX86_64Test,Subss)1083 TEST_F(AssemblerX86_64Test, Subss) {
1084   DriverStr(RepeatFF(&x86_64::X86_64Assembler::subss, "subss %{reg2}, %{reg1}"), "subss");
1085 }
1086 
TEST_F(AssemblerX86_64Test,Subsd)1087 TEST_F(AssemblerX86_64Test, Subsd) {
1088   DriverStr(RepeatFF(&x86_64::X86_64Assembler::subsd, "subsd %{reg2}, %{reg1}"), "subsd");
1089 }
1090 
TEST_F(AssemblerX86_64Test,Subps)1091 TEST_F(AssemblerX86_64Test, Subps) {
1092   DriverStr(RepeatFF(&x86_64::X86_64Assembler::subps, "subps %{reg2}, %{reg1}"), "subps");
1093 }
1094 
TEST_F(AssemblerX86_64Test,Subpd)1095 TEST_F(AssemblerX86_64Test, Subpd) {
1096   DriverStr(RepeatFF(&x86_64::X86_64Assembler::subpd, "subpd %{reg2}, %{reg1}"), "subpd");
1097 }
1098 
TEST_F(AssemblerX86_64Test,Mulss)1099 TEST_F(AssemblerX86_64Test, Mulss) {
1100   DriverStr(RepeatFF(&x86_64::X86_64Assembler::mulss, "mulss %{reg2}, %{reg1}"), "mulss");
1101 }
1102 
TEST_F(AssemblerX86_64Test,Mulsd)1103 TEST_F(AssemblerX86_64Test, Mulsd) {
1104   DriverStr(RepeatFF(&x86_64::X86_64Assembler::mulsd, "mulsd %{reg2}, %{reg1}"), "mulsd");
1105 }
1106 
TEST_F(AssemblerX86_64Test,Mulps)1107 TEST_F(AssemblerX86_64Test, Mulps) {
1108   DriverStr(RepeatFF(&x86_64::X86_64Assembler::mulps, "mulps %{reg2}, %{reg1}"), "mulps");
1109 }
1110 
TEST_F(AssemblerX86_64Test,Mulpd)1111 TEST_F(AssemblerX86_64Test, Mulpd) {
1112   DriverStr(RepeatFF(&x86_64::X86_64Assembler::mulpd, "mulpd %{reg2}, %{reg1}"), "mulpd");
1113 }
1114 
TEST_F(AssemblerX86_64Test,Divss)1115 TEST_F(AssemblerX86_64Test, Divss) {
1116   DriverStr(RepeatFF(&x86_64::X86_64Assembler::divss, "divss %{reg2}, %{reg1}"), "divss");
1117 }
1118 
TEST_F(AssemblerX86_64Test,Divsd)1119 TEST_F(AssemblerX86_64Test, Divsd) {
1120   DriverStr(RepeatFF(&x86_64::X86_64Assembler::divsd, "divsd %{reg2}, %{reg1}"), "divsd");
1121 }
1122 
TEST_F(AssemblerX86_64Test,Divps)1123 TEST_F(AssemblerX86_64Test, Divps) {
1124   DriverStr(RepeatFF(&x86_64::X86_64Assembler::divps, "divps %{reg2}, %{reg1}"), "divps");
1125 }
1126 
TEST_F(AssemblerX86_64Test,Divpd)1127 TEST_F(AssemblerX86_64Test, Divpd) {
1128   DriverStr(RepeatFF(&x86_64::X86_64Assembler::divpd, "divpd %{reg2}, %{reg1}"), "divpd");
1129 }
1130 
TEST_F(AssemblerX86_64Test,Paddb)1131 TEST_F(AssemblerX86_64Test, Paddb) {
1132   DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddb, "paddb %{reg2}, %{reg1}"), "paddb");
1133 }
1134 
TEST_F(AssemblerX86_64Test,Psubb)1135 TEST_F(AssemblerX86_64Test, Psubb) {
1136   DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubb, "psubb %{reg2}, %{reg1}"), "psubb");
1137 }
1138 
TEST_F(AssemblerX86_64Test,Paddw)1139 TEST_F(AssemblerX86_64Test, Paddw) {
1140   DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddw, "paddw %{reg2}, %{reg1}"), "paddw");
1141 }
1142 
TEST_F(AssemblerX86_64Test,Psubw)1143 TEST_F(AssemblerX86_64Test, Psubw) {
1144   DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubw, "psubw %{reg2}, %{reg1}"), "psubw");
1145 }
1146 
TEST_F(AssemblerX86_64Test,Pmullw)1147 TEST_F(AssemblerX86_64Test, Pmullw) {
1148   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmullw, "pmullw %{reg2}, %{reg1}"), "pmullw");
1149 }
1150 
TEST_F(AssemblerX86_64Test,Paddd)1151 TEST_F(AssemblerX86_64Test, Paddd) {
1152   DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddd, "paddd %{reg2}, %{reg1}"), "paddd");
1153 }
1154 
TEST_F(AssemblerX86_64Test,Psubd)1155 TEST_F(AssemblerX86_64Test, Psubd) {
1156   DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubd, "psubd %{reg2}, %{reg1}"), "psubd");
1157 }
1158 
TEST_F(AssemblerX86_64Test,Pmulld)1159 TEST_F(AssemblerX86_64Test, Pmulld) {
1160   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmulld, "pmulld %{reg2}, %{reg1}"), "pmulld");
1161 }
1162 
TEST_F(AssemblerX86_64Test,Paddq)1163 TEST_F(AssemblerX86_64Test, Paddq) {
1164   DriverStr(RepeatFF(&x86_64::X86_64Assembler::paddq, "paddq %{reg2}, %{reg1}"), "paddq");
1165 }
1166 
TEST_F(AssemblerX86_64Test,Psubq)1167 TEST_F(AssemblerX86_64Test, Psubq) {
1168   DriverStr(RepeatFF(&x86_64::X86_64Assembler::psubq, "psubq %{reg2}, %{reg1}"), "psubq");
1169 }
1170 
TEST_F(AssemblerX86_64Test,Cvtsi2ss)1171 TEST_F(AssemblerX86_64Test, Cvtsi2ss) {
1172   DriverStr(RepeatFr(&x86_64::X86_64Assembler::cvtsi2ss, "cvtsi2ss %{reg2}, %{reg1}"), "cvtsi2ss");
1173 }
1174 
TEST_F(AssemblerX86_64Test,Cvtsi2sd)1175 TEST_F(AssemblerX86_64Test, Cvtsi2sd) {
1176   DriverStr(RepeatFr(&x86_64::X86_64Assembler::cvtsi2sd, "cvtsi2sd %{reg2}, %{reg1}"), "cvtsi2sd");
1177 }
1178 
1179 
TEST_F(AssemblerX86_64Test,Cvtss2si)1180 TEST_F(AssemblerX86_64Test, Cvtss2si) {
1181   DriverStr(RepeatrF(&x86_64::X86_64Assembler::cvtss2si, "cvtss2si %{reg2}, %{reg1}"), "cvtss2si");
1182 }
1183 
1184 
TEST_F(AssemblerX86_64Test,Cvtss2sd)1185 TEST_F(AssemblerX86_64Test, Cvtss2sd) {
1186   DriverStr(RepeatFF(&x86_64::X86_64Assembler::cvtss2sd, "cvtss2sd %{reg2}, %{reg1}"), "cvtss2sd");
1187 }
1188 
1189 
TEST_F(AssemblerX86_64Test,Cvtsd2si)1190 TEST_F(AssemblerX86_64Test, Cvtsd2si) {
1191   DriverStr(RepeatrF(&x86_64::X86_64Assembler::cvtsd2si, "cvtsd2si %{reg2}, %{reg1}"), "cvtsd2si");
1192 }
1193 
TEST_F(AssemblerX86_64Test,Cvttss2si)1194 TEST_F(AssemblerX86_64Test, Cvttss2si) {
1195   DriverStr(RepeatrF(&x86_64::X86_64Assembler::cvttss2si, "cvttss2si %{reg2}, %{reg1}"),
1196             "cvttss2si");
1197 }
1198 
TEST_F(AssemblerX86_64Test,Cvttsd2si)1199 TEST_F(AssemblerX86_64Test, Cvttsd2si) {
1200   DriverStr(RepeatrF(&x86_64::X86_64Assembler::cvttsd2si, "cvttsd2si %{reg2}, %{reg1}"),
1201             "cvttsd2si");
1202 }
1203 
TEST_F(AssemblerX86_64Test,Cvtsd2ss)1204 TEST_F(AssemblerX86_64Test, Cvtsd2ss) {
1205   DriverStr(RepeatFF(&x86_64::X86_64Assembler::cvtsd2ss, "cvtsd2ss %{reg2}, %{reg1}"), "cvtsd2ss");
1206 }
1207 
TEST_F(AssemblerX86_64Test,Cvtdq2ps)1208 TEST_F(AssemblerX86_64Test, Cvtdq2ps) {
1209   DriverStr(RepeatFF(&x86_64::X86_64Assembler::cvtdq2ps, "cvtdq2ps %{reg2}, %{reg1}"), "cvtdq2ps");
1210 }
1211 
TEST_F(AssemblerX86_64Test,Cvtdq2pd)1212 TEST_F(AssemblerX86_64Test, Cvtdq2pd) {
1213   DriverStr(RepeatFF(&x86_64::X86_64Assembler::cvtdq2pd, "cvtdq2pd %{reg2}, %{reg1}"), "cvtdq2pd");
1214 }
1215 
TEST_F(AssemblerX86_64Test,Comiss)1216 TEST_F(AssemblerX86_64Test, Comiss) {
1217   DriverStr(RepeatFF(&x86_64::X86_64Assembler::comiss, "comiss %{reg2}, %{reg1}"), "comiss");
1218 }
1219 
TEST_F(AssemblerX86_64Test,Comisd)1220 TEST_F(AssemblerX86_64Test, Comisd) {
1221   DriverStr(RepeatFF(&x86_64::X86_64Assembler::comisd, "comisd %{reg2}, %{reg1}"), "comisd");
1222 }
1223 
TEST_F(AssemblerX86_64Test,Ucomiss)1224 TEST_F(AssemblerX86_64Test, Ucomiss) {
1225   DriverStr(RepeatFF(&x86_64::X86_64Assembler::ucomiss, "ucomiss %{reg2}, %{reg1}"), "ucomiss");
1226 }
1227 
TEST_F(AssemblerX86_64Test,Ucomisd)1228 TEST_F(AssemblerX86_64Test, Ucomisd) {
1229   DriverStr(RepeatFF(&x86_64::X86_64Assembler::ucomisd, "ucomisd %{reg2}, %{reg1}"), "ucomisd");
1230 }
1231 
TEST_F(AssemblerX86_64Test,Sqrtss)1232 TEST_F(AssemblerX86_64Test, Sqrtss) {
1233   DriverStr(RepeatFF(&x86_64::X86_64Assembler::sqrtss, "sqrtss %{reg2}, %{reg1}"), "sqrtss");
1234 }
1235 
TEST_F(AssemblerX86_64Test,Sqrtsd)1236 TEST_F(AssemblerX86_64Test, Sqrtsd) {
1237   DriverStr(RepeatFF(&x86_64::X86_64Assembler::sqrtsd, "sqrtsd %{reg2}, %{reg1}"), "sqrtsd");
1238 }
1239 
TEST_F(AssemblerX86_64Test,Roundss)1240 TEST_F(AssemblerX86_64Test, Roundss) {
1241   DriverStr(RepeatFFI(&x86_64::X86_64Assembler::roundss, 1, "roundss ${imm}, %{reg2}, %{reg1}"), "roundss");
1242 }
1243 
TEST_F(AssemblerX86_64Test,Roundsd)1244 TEST_F(AssemblerX86_64Test, Roundsd) {
1245   DriverStr(RepeatFFI(&x86_64::X86_64Assembler::roundsd, 1, "roundsd ${imm}, %{reg2}, %{reg1}"), "roundsd");
1246 }
1247 
TEST_F(AssemblerX86_64Test,Xorps)1248 TEST_F(AssemblerX86_64Test, Xorps) {
1249   DriverStr(RepeatFF(&x86_64::X86_64Assembler::xorps, "xorps %{reg2}, %{reg1}"), "xorps");
1250 }
1251 
TEST_F(AssemblerX86_64Test,Xorpd)1252 TEST_F(AssemblerX86_64Test, Xorpd) {
1253   DriverStr(RepeatFF(&x86_64::X86_64Assembler::xorpd, "xorpd %{reg2}, %{reg1}"), "xorpd");
1254 }
1255 
TEST_F(AssemblerX86_64Test,Pxor)1256 TEST_F(AssemblerX86_64Test, Pxor) {
1257   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pxor, "pxor %{reg2}, %{reg1}"), "pxor");
1258 }
1259 
TEST_F(AssemblerX86_64Test,Andps)1260 TEST_F(AssemblerX86_64Test, Andps) {
1261   DriverStr(RepeatFF(&x86_64::X86_64Assembler::andps, "andps %{reg2}, %{reg1}"), "andps");
1262 }
1263 
TEST_F(AssemblerX86_64Test,Andpd)1264 TEST_F(AssemblerX86_64Test, Andpd) {
1265   DriverStr(RepeatFF(&x86_64::X86_64Assembler::andpd, "andpd %{reg2}, %{reg1}"), "andpd");
1266 }
1267 
TEST_F(AssemblerX86_64Test,Pand)1268 TEST_F(AssemblerX86_64Test, Pand) {
1269   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pand, "pand %{reg2}, %{reg1}"), "pand");
1270 }
1271 
TEST_F(AssemblerX86_64Test,andnpd)1272 TEST_F(AssemblerX86_64Test, andnpd) {
1273   DriverStr(RepeatFF(&x86_64::X86_64Assembler::andnpd, "andnpd %{reg2}, %{reg1}"), "andnpd");
1274 }
1275 
TEST_F(AssemblerX86_64Test,andnps)1276 TEST_F(AssemblerX86_64Test, andnps) {
1277   DriverStr(RepeatFF(&x86_64::X86_64Assembler::andnps, "andnps %{reg2}, %{reg1}"), "andnps");
1278 }
1279 
TEST_F(AssemblerX86_64Test,Pandn)1280 TEST_F(AssemblerX86_64Test, Pandn) {
1281   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pandn, "pandn %{reg2}, %{reg1}"), "pandn");
1282 }
1283 
TEST_F(AssemblerX86_64Test,Orps)1284 TEST_F(AssemblerX86_64Test, Orps) {
1285   DriverStr(RepeatFF(&x86_64::X86_64Assembler::orps, "orps %{reg2}, %{reg1}"), "orps");
1286 }
1287 
TEST_F(AssemblerX86_64Test,Orpd)1288 TEST_F(AssemblerX86_64Test, Orpd) {
1289   DriverStr(RepeatFF(&x86_64::X86_64Assembler::orpd, "orpd %{reg2}, %{reg1}"), "orpd");
1290 }
1291 
TEST_F(AssemblerX86_64Test,Por)1292 TEST_F(AssemblerX86_64Test, Por) {
1293   DriverStr(RepeatFF(&x86_64::X86_64Assembler::por, "por %{reg2}, %{reg1}"), "por");
1294 }
1295 
TEST_F(AssemblerX86_64Test,Pavgb)1296 TEST_F(AssemblerX86_64Test, Pavgb) {
1297   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pavgb, "pavgb %{reg2}, %{reg1}"), "pavgb");
1298 }
1299 
TEST_F(AssemblerX86_64Test,Pavgw)1300 TEST_F(AssemblerX86_64Test, Pavgw) {
1301   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pavgw, "pavgw %{reg2}, %{reg1}"), "pavgw");
1302 }
1303 
TEST_F(AssemblerX86_64Test,Pminsb)1304 TEST_F(AssemblerX86_64Test, Pminsb) {
1305   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pminsb, "pminsb %{reg2}, %{reg1}"), "pminsb");
1306 }
1307 
TEST_F(AssemblerX86_64Test,Pmaxsb)1308 TEST_F(AssemblerX86_64Test, Pmaxsb) {
1309   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaxsb, "pmaxsb %{reg2}, %{reg1}"), "pmaxsb");
1310 }
1311 
TEST_F(AssemblerX86_64Test,Pminsw)1312 TEST_F(AssemblerX86_64Test, Pminsw) {
1313   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pminsw, "pminsw %{reg2}, %{reg1}"), "pminsw");
1314 }
1315 
TEST_F(AssemblerX86_64Test,Pmaxsw)1316 TEST_F(AssemblerX86_64Test, Pmaxsw) {
1317   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaxsw, "pmaxsw %{reg2}, %{reg1}"), "pmaxsw");
1318 }
1319 
TEST_F(AssemblerX86_64Test,Pminsd)1320 TEST_F(AssemblerX86_64Test, Pminsd) {
1321   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pminsd, "pminsd %{reg2}, %{reg1}"), "pminsd");
1322 }
1323 
TEST_F(AssemblerX86_64Test,Pmaxsd)1324 TEST_F(AssemblerX86_64Test, Pmaxsd) {
1325   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaxsd, "pmaxsd %{reg2}, %{reg1}"), "pmaxsd");
1326 }
1327 
TEST_F(AssemblerX86_64Test,Pminub)1328 TEST_F(AssemblerX86_64Test, Pminub) {
1329   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pminub, "pminub %{reg2}, %{reg1}"), "pminub");
1330 }
1331 
TEST_F(AssemblerX86_64Test,Pmaxub)1332 TEST_F(AssemblerX86_64Test, Pmaxub) {
1333   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaxub, "pmaxub %{reg2}, %{reg1}"), "pmaxub");
1334 }
1335 
TEST_F(AssemblerX86_64Test,Pminuw)1336 TEST_F(AssemblerX86_64Test, Pminuw) {
1337   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pminuw, "pminuw %{reg2}, %{reg1}"), "pminuw");
1338 }
1339 
TEST_F(AssemblerX86_64Test,Pmaxuw)1340 TEST_F(AssemblerX86_64Test, Pmaxuw) {
1341   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaxuw, "pmaxuw %{reg2}, %{reg1}"), "pmaxuw");
1342 }
1343 
TEST_F(AssemblerX86_64Test,Pminud)1344 TEST_F(AssemblerX86_64Test, Pminud) {
1345   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pminud, "pminud %{reg2}, %{reg1}"), "pminud");
1346 }
1347 
TEST_F(AssemblerX86_64Test,Pmaxud)1348 TEST_F(AssemblerX86_64Test, Pmaxud) {
1349   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pmaxud, "pmaxud %{reg2}, %{reg1}"), "pmaxud");
1350 }
1351 
TEST_F(AssemblerX86_64Test,Minps)1352 TEST_F(AssemblerX86_64Test, Minps) {
1353   DriverStr(RepeatFF(&x86_64::X86_64Assembler::minps, "minps %{reg2}, %{reg1}"), "minps");
1354 }
1355 
TEST_F(AssemblerX86_64Test,Maxps)1356 TEST_F(AssemblerX86_64Test, Maxps) {
1357   DriverStr(RepeatFF(&x86_64::X86_64Assembler::maxps, "maxps %{reg2}, %{reg1}"), "maxps");
1358 }
1359 
TEST_F(AssemblerX86_64Test,Minpd)1360 TEST_F(AssemblerX86_64Test, Minpd) {
1361   DriverStr(RepeatFF(&x86_64::X86_64Assembler::minpd, "minpd %{reg2}, %{reg1}"), "minpd");
1362 }
1363 
TEST_F(AssemblerX86_64Test,Maxpd)1364 TEST_F(AssemblerX86_64Test, Maxpd) {
1365   DriverStr(RepeatFF(&x86_64::X86_64Assembler::maxpd, "maxpd %{reg2}, %{reg1}"), "maxpd");
1366 }
1367 
TEST_F(AssemblerX86_64Test,PCmpeqb)1368 TEST_F(AssemblerX86_64Test, PCmpeqb) {
1369   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpeqb, "pcmpeqb %{reg2}, %{reg1}"), "pcmpeqb");
1370 }
1371 
TEST_F(AssemblerX86_64Test,PCmpeqw)1372 TEST_F(AssemblerX86_64Test, PCmpeqw) {
1373   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpeqw, "pcmpeqw %{reg2}, %{reg1}"), "pcmpeqw");
1374 }
1375 
TEST_F(AssemblerX86_64Test,PCmpeqd)1376 TEST_F(AssemblerX86_64Test, PCmpeqd) {
1377   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpeqd, "pcmpeqd %{reg2}, %{reg1}"), "pcmpeqd");
1378 }
1379 
TEST_F(AssemblerX86_64Test,PCmpeqq)1380 TEST_F(AssemblerX86_64Test, PCmpeqq) {
1381   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpeqq, "pcmpeqq %{reg2}, %{reg1}"), "pcmpeqq");
1382 }
1383 
TEST_F(AssemblerX86_64Test,PCmpgtb)1384 TEST_F(AssemblerX86_64Test, PCmpgtb) {
1385   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpgtb, "pcmpgtb %{reg2}, %{reg1}"), "pcmpgtb");
1386 }
1387 
TEST_F(AssemblerX86_64Test,PCmpgtw)1388 TEST_F(AssemblerX86_64Test, PCmpgtw) {
1389   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpgtw, "pcmpgtw %{reg2}, %{reg1}"), "pcmpgtw");
1390 }
1391 
TEST_F(AssemblerX86_64Test,PCmpgtd)1392 TEST_F(AssemblerX86_64Test, PCmpgtd) {
1393   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpgtd, "pcmpgtd %{reg2}, %{reg1}"), "pcmpgtd");
1394 }
1395 
TEST_F(AssemblerX86_64Test,PCmpgtq)1396 TEST_F(AssemblerX86_64Test, PCmpgtq) {
1397   DriverStr(RepeatFF(&x86_64::X86_64Assembler::pcmpgtq, "pcmpgtq %{reg2}, %{reg1}"), "pcmpgtq");
1398 }
1399 
TEST_F(AssemblerX86_64Test,Shufps)1400 TEST_F(AssemblerX86_64Test, Shufps) {
1401   DriverStr(RepeatFFI(&x86_64::X86_64Assembler::shufps, 1, "shufps ${imm}, %{reg2}, %{reg1}"), "shufps");
1402 }
1403 
TEST_F(AssemblerX86_64Test,Shufpd)1404 TEST_F(AssemblerX86_64Test, Shufpd) {
1405   DriverStr(RepeatFFI(&x86_64::X86_64Assembler::shufpd, 1, "shufpd ${imm}, %{reg2}, %{reg1}"), "shufpd");
1406 }
1407 
TEST_F(AssemblerX86_64Test,PShufd)1408 TEST_F(AssemblerX86_64Test, PShufd) {
1409   DriverStr(RepeatFFI(&x86_64::X86_64Assembler::pshufd, 1, "pshufd ${imm}, %{reg2}, %{reg1}"), "pshufd");
1410 }
1411 
TEST_F(AssemblerX86_64Test,Punpcklbw)1412 TEST_F(AssemblerX86_64Test, Punpcklbw) {
1413   DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpcklbw, "punpcklbw %{reg2}, %{reg1}"), "punpcklbw");
1414 }
1415 
TEST_F(AssemblerX86_64Test,Punpcklwd)1416 TEST_F(AssemblerX86_64Test, Punpcklwd) {
1417   DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpcklwd, "punpcklwd %{reg2}, %{reg1}"), "punpcklwd");
1418 }
1419 
TEST_F(AssemblerX86_64Test,Punpckldq)1420 TEST_F(AssemblerX86_64Test, Punpckldq) {
1421   DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpckldq, "punpckldq %{reg2}, %{reg1}"), "punpckldq");
1422 }
1423 
TEST_F(AssemblerX86_64Test,Punpcklqdq)1424 TEST_F(AssemblerX86_64Test, Punpcklqdq) {
1425   DriverStr(RepeatFF(&x86_64::X86_64Assembler::punpcklqdq, "punpcklqdq %{reg2}, %{reg1}"), "punpcklqdq");
1426 }
1427 
TEST_F(AssemblerX86_64Test,Psllw)1428 TEST_F(AssemblerX86_64Test, Psllw) {
1429   GetAssembler()->psllw(x86_64::XmmRegister(x86_64::XMM0),  x86_64::Immediate(1));
1430   GetAssembler()->psllw(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1431   DriverStr("psllw $1, %xmm0\n"
1432             "psllw $2, %xmm15\n", "psllwi");
1433 }
1434 
TEST_F(AssemblerX86_64Test,Pslld)1435 TEST_F(AssemblerX86_64Test, Pslld) {
1436   GetAssembler()->pslld(x86_64::XmmRegister(x86_64::XMM0),  x86_64::Immediate(1));
1437   GetAssembler()->pslld(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1438   DriverStr("pslld $1, %xmm0\n"
1439             "pslld $2, %xmm15\n", "pslldi");
1440 }
1441 
TEST_F(AssemblerX86_64Test,Psllq)1442 TEST_F(AssemblerX86_64Test, Psllq) {
1443   GetAssembler()->psllq(x86_64::XmmRegister(x86_64::XMM0),  x86_64::Immediate(1));
1444   GetAssembler()->psllq(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1445   DriverStr("psllq $1, %xmm0\n"
1446             "psllq $2, %xmm15\n", "psllqi");
1447 }
1448 
TEST_F(AssemblerX86_64Test,Psraw)1449 TEST_F(AssemblerX86_64Test, Psraw) {
1450   GetAssembler()->psraw(x86_64::XmmRegister(x86_64::XMM0),  x86_64::Immediate(1));
1451   GetAssembler()->psraw(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1452   DriverStr("psraw $1, %xmm0\n"
1453             "psraw $2, %xmm15\n", "psrawi");
1454 }
1455 
TEST_F(AssemblerX86_64Test,Psrad)1456 TEST_F(AssemblerX86_64Test, Psrad) {
1457   GetAssembler()->psrad(x86_64::XmmRegister(x86_64::XMM0),  x86_64::Immediate(1));
1458   GetAssembler()->psrad(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1459   DriverStr("psrad $1, %xmm0\n"
1460             "psrad $2, %xmm15\n", "psradi");
1461 }
1462 
TEST_F(AssemblerX86_64Test,Psrlw)1463 TEST_F(AssemblerX86_64Test, Psrlw) {
1464   GetAssembler()->psrlw(x86_64::XmmRegister(x86_64::XMM0),  x86_64::Immediate(1));
1465   GetAssembler()->psrlw(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1466   DriverStr("psrlw $1, %xmm0\n"
1467             "psrlw $2, %xmm15\n", "psrlwi");
1468 }
1469 
TEST_F(AssemblerX86_64Test,Psrld)1470 TEST_F(AssemblerX86_64Test, Psrld) {
1471   GetAssembler()->psrld(x86_64::XmmRegister(x86_64::XMM0),  x86_64::Immediate(1));
1472   GetAssembler()->psrld(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1473   DriverStr("psrld $1, %xmm0\n"
1474             "psrld $2, %xmm15\n", "pslldi");
1475 }
1476 
TEST_F(AssemblerX86_64Test,Psrlq)1477 TEST_F(AssemblerX86_64Test, Psrlq) {
1478   GetAssembler()->psrlq(x86_64::XmmRegister(x86_64::XMM0),  x86_64::Immediate(1));
1479   GetAssembler()->psrlq(x86_64::XmmRegister(x86_64::XMM15), x86_64::Immediate(2));
1480   DriverStr("psrlq $1, %xmm0\n"
1481             "psrlq $2, %xmm15\n", "pslrqi");
1482 }
1483 
TEST_F(AssemblerX86_64Test,UcomissAddress)1484 TEST_F(AssemblerX86_64Test, UcomissAddress) {
1485   GetAssembler()->ucomiss(x86_64::XmmRegister(x86_64::XMM0), x86_64::Address(
1486       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12));
1487   GetAssembler()->ucomiss(x86_64::XmmRegister(x86_64::XMM1), x86_64::Address(
1488       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12));
1489   GetAssembler()->ucomiss(x86_64::XmmRegister(x86_64::XMM2), x86_64::Address(
1490       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12));
1491   GetAssembler()->ucomiss(x86_64::XmmRegister(x86_64::XMM3), x86_64::Address(
1492       x86_64::CpuRegister(x86_64::R13), 0));
1493   GetAssembler()->ucomiss(x86_64::XmmRegister(x86_64::XMM4), x86_64::Address(
1494       x86_64::CpuRegister(x86_64::R13), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_1, 0));
1495   const char* expected =
1496     "ucomiss 0xc(%RDI,%RBX,4), %xmm0\n"
1497     "ucomiss 0xc(%RDI,%R9,4), %xmm1\n"
1498     "ucomiss 0xc(%RDI,%R9,4), %xmm2\n"
1499     "ucomiss (%R13), %xmm3\n"
1500     "ucomiss (%R13,%R9,1), %xmm4\n";
1501 
1502   DriverStr(expected, "ucomiss_address");
1503 }
1504 
TEST_F(AssemblerX86_64Test,UcomisdAddress)1505 TEST_F(AssemblerX86_64Test, UcomisdAddress) {
1506   GetAssembler()->ucomisd(x86_64::XmmRegister(x86_64::XMM0), x86_64::Address(
1507       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12));
1508   GetAssembler()->ucomisd(x86_64::XmmRegister(x86_64::XMM1), x86_64::Address(
1509       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12));
1510   GetAssembler()->ucomisd(x86_64::XmmRegister(x86_64::XMM2), x86_64::Address(
1511       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12));
1512   GetAssembler()->ucomisd(x86_64::XmmRegister(x86_64::XMM3), x86_64::Address(
1513       x86_64::CpuRegister(x86_64::R13), 0));
1514   GetAssembler()->ucomisd(x86_64::XmmRegister(x86_64::XMM4), x86_64::Address(
1515       x86_64::CpuRegister(x86_64::R13), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_1, 0));
1516   const char* expected =
1517     "ucomisd 0xc(%RDI,%RBX,4), %xmm0\n"
1518     "ucomisd 0xc(%RDI,%R9,4), %xmm1\n"
1519     "ucomisd 0xc(%RDI,%R9,4), %xmm2\n"
1520     "ucomisd (%R13), %xmm3\n"
1521     "ucomisd (%R13,%R9,1), %xmm4\n";
1522 
1523   DriverStr(expected, "ucomisd_address");
1524 }
1525 
1526 // X87
1527 
x87_fn(AssemblerX86_64Test::Base * assembler_test ATTRIBUTE_UNUSED,x86_64::X86_64Assembler * assembler)1528 std::string x87_fn(AssemblerX86_64Test::Base* assembler_test ATTRIBUTE_UNUSED,
1529                    x86_64::X86_64Assembler* assembler) {
1530   std::ostringstream str;
1531 
1532   assembler->fincstp();
1533   str << "fincstp\n";
1534 
1535   assembler->fsin();
1536   str << "fsin\n";
1537 
1538   assembler->fcos();
1539   str << "fcos\n";
1540 
1541   assembler->fptan();
1542   str << "fptan\n";
1543 
1544   return str.str();
1545 }
1546 
TEST_F(AssemblerX86_64Test,X87)1547 TEST_F(AssemblerX86_64Test, X87) {
1548   DriverFn(&x87_fn, "x87");
1549 }
1550 
TEST_F(AssemblerX86_64Test,FPUIntegerLoad)1551 TEST_F(AssemblerX86_64Test, FPUIntegerLoad) {
1552   GetAssembler()->filds(x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 4));
1553   GetAssembler()->fildl(x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 12));
1554   const char* expected =
1555       "fildl 0x4(%RSP)\n"
1556       "fildll 0xc(%RSP)\n";
1557   DriverStr(expected, "FPUIntegerLoad");
1558 }
1559 
TEST_F(AssemblerX86_64Test,FPUIntegerStore)1560 TEST_F(AssemblerX86_64Test, FPUIntegerStore) {
1561   GetAssembler()->fistps(x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 16));
1562   GetAssembler()->fistpl(x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 24));
1563   const char* expected =
1564       "fistpl 0x10(%RSP)\n"
1565       "fistpll 0x18(%RSP)\n";
1566   DriverStr(expected, "FPUIntegerStore");
1567 }
1568 
1569 ////////////////
1570 // CALL / JMP //
1571 ////////////////
1572 
TEST_F(AssemblerX86_64Test,Call)1573 TEST_F(AssemblerX86_64Test, Call) {
1574   DriverStr(RepeatR(&x86_64::X86_64Assembler::call, "call *%{reg}"), "call");
1575 }
1576 
TEST_F(AssemblerX86_64Test,Jmp)1577 TEST_F(AssemblerX86_64Test, Jmp) {
1578   DriverStr(RepeatR(&x86_64::X86_64Assembler::jmp, "jmp *%{reg}"), "jmp");
1579 }
1580 
TEST_F(AssemblerX86_64Test,Enter)1581 TEST_F(AssemblerX86_64Test, Enter) {
1582   DriverStr(RepeatI(&x86_64::X86_64Assembler::enter, 2U  /* 16b immediate */, "enter ${imm}, $0",
1583                     true  /* Only non-negative number */), "enter");
1584 }
1585 
TEST_F(AssemblerX86_64Test,RetImm)1586 TEST_F(AssemblerX86_64Test, RetImm) {
1587   DriverStr(RepeatI(&x86_64::X86_64Assembler::ret, 2U  /* 16b immediate */, "ret ${imm}",
1588                     true  /* Only non-negative number */), "reti");
1589 }
1590 
ret_and_leave_fn(AssemblerX86_64Test::Base * assembler_test ATTRIBUTE_UNUSED,x86_64::X86_64Assembler * assembler)1591 std::string ret_and_leave_fn(AssemblerX86_64Test::Base* assembler_test ATTRIBUTE_UNUSED,
1592                              x86_64::X86_64Assembler* assembler) {
1593   std::ostringstream str;
1594 
1595   assembler->ret();
1596   str << "ret\n";
1597 
1598   assembler->leave();
1599   str << "leave\n";
1600 
1601   return str.str();
1602 }
1603 
TEST_F(AssemblerX86_64Test,RetAndLeave)1604 TEST_F(AssemblerX86_64Test, RetAndLeave) {
1605   DriverFn(&ret_and_leave_fn, "retleave");
1606 }
1607 
1608 //////////
1609 // MISC //
1610 //////////
1611 
TEST_F(AssemblerX86_64Test,Bswapl)1612 TEST_F(AssemblerX86_64Test, Bswapl) {
1613   DriverStr(Repeatr(&x86_64::X86_64Assembler::bswapl, "bswap %{reg}"), "bswapl");
1614 }
1615 
TEST_F(AssemblerX86_64Test,Bswapq)1616 TEST_F(AssemblerX86_64Test, Bswapq) {
1617   DriverStr(RepeatR(&x86_64::X86_64Assembler::bswapq, "bswap %{reg}"), "bswapq");
1618 }
1619 
TEST_F(AssemblerX86_64Test,Bsfl)1620 TEST_F(AssemblerX86_64Test, Bsfl) {
1621   DriverStr(Repeatrr(&x86_64::X86_64Assembler::bsfl, "bsfl %{reg2}, %{reg1}"), "bsfl");
1622 }
1623 
TEST_F(AssemblerX86_64Test,BsflAddress)1624 TEST_F(AssemblerX86_64Test, BsflAddress) {
1625   GetAssembler()->bsfl(x86_64::CpuRegister(x86_64::R10), x86_64::Address(
1626       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12));
1627   GetAssembler()->bsfl(x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
1628       x86_64::CpuRegister(x86_64::R10), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12));
1629   GetAssembler()->bsfl(x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
1630       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12));
1631   const char* expected =
1632     "bsfl 0xc(%RDI,%RBX,4), %R10d\n"
1633     "bsfl 0xc(%R10,%RBX,4), %edi\n"
1634     "bsfl 0xc(%RDI,%R9,4), %edi\n";
1635 
1636   DriverStr(expected, "bsfl_address");
1637 }
1638 
TEST_F(AssemblerX86_64Test,Bsfq)1639 TEST_F(AssemblerX86_64Test, Bsfq) {
1640   DriverStr(RepeatRR(&x86_64::X86_64Assembler::bsfq, "bsfq %{reg2}, %{reg1}"), "bsfq");
1641 }
1642 
TEST_F(AssemblerX86_64Test,BsfqAddress)1643 TEST_F(AssemblerX86_64Test, BsfqAddress) {
1644   GetAssembler()->bsfq(x86_64::CpuRegister(x86_64::R10), x86_64::Address(
1645       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12));
1646   GetAssembler()->bsfq(x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
1647       x86_64::CpuRegister(x86_64::R10), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12));
1648   GetAssembler()->bsfq(x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
1649       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12));
1650   const char* expected =
1651     "bsfq 0xc(%RDI,%RBX,4), %R10\n"
1652     "bsfq 0xc(%R10,%RBX,4), %RDI\n"
1653     "bsfq 0xc(%RDI,%R9,4), %RDI\n";
1654 
1655   DriverStr(expected, "bsfq_address");
1656 }
1657 
TEST_F(AssemblerX86_64Test,Bsrl)1658 TEST_F(AssemblerX86_64Test, Bsrl) {
1659   DriverStr(Repeatrr(&x86_64::X86_64Assembler::bsrl, "bsrl %{reg2}, %{reg1}"), "bsrl");
1660 }
1661 
TEST_F(AssemblerX86_64Test,BsrlAddress)1662 TEST_F(AssemblerX86_64Test, BsrlAddress) {
1663   GetAssembler()->bsrl(x86_64::CpuRegister(x86_64::R10), x86_64::Address(
1664       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12));
1665   GetAssembler()->bsrl(x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
1666       x86_64::CpuRegister(x86_64::R10), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12));
1667   GetAssembler()->bsrl(x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
1668       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12));
1669   const char* expected =
1670     "bsrl 0xc(%RDI,%RBX,4), %R10d\n"
1671     "bsrl 0xc(%R10,%RBX,4), %edi\n"
1672     "bsrl 0xc(%RDI,%R9,4), %edi\n";
1673 
1674   DriverStr(expected, "bsrl_address");
1675 }
1676 
TEST_F(AssemblerX86_64Test,Bsrq)1677 TEST_F(AssemblerX86_64Test, Bsrq) {
1678   DriverStr(RepeatRR(&x86_64::X86_64Assembler::bsrq, "bsrq %{reg2}, %{reg1}"), "bsrq");
1679 }
1680 
TEST_F(AssemblerX86_64Test,BsrqAddress)1681 TEST_F(AssemblerX86_64Test, BsrqAddress) {
1682   GetAssembler()->bsrq(x86_64::CpuRegister(x86_64::R10), x86_64::Address(
1683       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12));
1684   GetAssembler()->bsrq(x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
1685       x86_64::CpuRegister(x86_64::R10), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12));
1686   GetAssembler()->bsrq(x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
1687       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12));
1688   const char* expected =
1689     "bsrq 0xc(%RDI,%RBX,4), %R10\n"
1690     "bsrq 0xc(%R10,%RBX,4), %RDI\n"
1691     "bsrq 0xc(%RDI,%R9,4), %RDI\n";
1692 
1693   DriverStr(expected, "bsrq_address");
1694 }
1695 
TEST_F(AssemblerX86_64Test,Popcntl)1696 TEST_F(AssemblerX86_64Test, Popcntl) {
1697   DriverStr(Repeatrr(&x86_64::X86_64Assembler::popcntl, "popcntl %{reg2}, %{reg1}"), "popcntl");
1698 }
1699 
TEST_F(AssemblerX86_64Test,PopcntlAddress)1700 TEST_F(AssemblerX86_64Test, PopcntlAddress) {
1701   GetAssembler()->popcntl(x86_64::CpuRegister(x86_64::R10), x86_64::Address(
1702       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12));
1703   GetAssembler()->popcntl(x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
1704       x86_64::CpuRegister(x86_64::R10), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12));
1705   GetAssembler()->popcntl(x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
1706       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12));
1707   const char* expected =
1708     "popcntl 0xc(%RDI,%RBX,4), %R10d\n"
1709     "popcntl 0xc(%R10,%RBX,4), %edi\n"
1710     "popcntl 0xc(%RDI,%R9,4), %edi\n";
1711 
1712   DriverStr(expected, "popcntl_address");
1713 }
1714 
TEST_F(AssemblerX86_64Test,Popcntq)1715 TEST_F(AssemblerX86_64Test, Popcntq) {
1716   DriverStr(RepeatRR(&x86_64::X86_64Assembler::popcntq, "popcntq %{reg2}, %{reg1}"), "popcntq");
1717 }
1718 
TEST_F(AssemblerX86_64Test,PopcntqAddress)1719 TEST_F(AssemblerX86_64Test, PopcntqAddress) {
1720   GetAssembler()->popcntq(x86_64::CpuRegister(x86_64::R10), x86_64::Address(
1721       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12));
1722   GetAssembler()->popcntq(x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
1723       x86_64::CpuRegister(x86_64::R10), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12));
1724   GetAssembler()->popcntq(x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
1725       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12));
1726   const char* expected =
1727     "popcntq 0xc(%RDI,%RBX,4), %R10\n"
1728     "popcntq 0xc(%R10,%RBX,4), %RDI\n"
1729     "popcntq 0xc(%RDI,%R9,4), %RDI\n";
1730 
1731   DriverStr(expected, "popcntq_address");
1732 }
1733 
TEST_F(AssemblerX86_64Test,CmovlAddress)1734 TEST_F(AssemblerX86_64Test, CmovlAddress) {
1735   GetAssembler()->cmov(x86_64::kEqual, x86_64::CpuRegister(x86_64::R10), x86_64::Address(
1736       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12), false);
1737   GetAssembler()->cmov(x86_64::kNotEqual, x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
1738       x86_64::CpuRegister(x86_64::R10), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12), false);
1739   GetAssembler()->cmov(x86_64::kEqual, x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
1740       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12), false);
1741   const char* expected =
1742     "cmovzl 0xc(%RDI,%RBX,4), %R10d\n"
1743     "cmovnzl 0xc(%R10,%RBX,4), %edi\n"
1744     "cmovzl 0xc(%RDI,%R9,4), %edi\n";
1745 
1746   DriverStr(expected, "cmovl_address");
1747 }
1748 
TEST_F(AssemblerX86_64Test,CmovqAddress)1749 TEST_F(AssemblerX86_64Test, CmovqAddress) {
1750   GetAssembler()->cmov(x86_64::kEqual, x86_64::CpuRegister(x86_64::R10), x86_64::Address(
1751       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12), true);
1752   GetAssembler()->cmov(x86_64::kNotEqual, x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
1753       x86_64::CpuRegister(x86_64::R10), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12), true);
1754   GetAssembler()->cmov(x86_64::kEqual, x86_64::CpuRegister(x86_64::RDI), x86_64::Address(
1755       x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12), true);
1756   const char* expected =
1757     "cmovzq 0xc(%RDI,%RBX,4), %R10\n"
1758     "cmovnzq 0xc(%R10,%RBX,4), %rdi\n"
1759     "cmovzq 0xc(%RDI,%R9,4), %rdi\n";
1760 
1761   DriverStr(expected, "cmovq_address");
1762 }
1763 
1764 
1765 /////////////////
1766 // Near labels //
1767 /////////////////
1768 
TEST_F(AssemblerX86_64Test,Jrcxz)1769 TEST_F(AssemblerX86_64Test, Jrcxz) {
1770   x86_64::NearLabel target;
1771   GetAssembler()->jrcxz(&target);
1772   GetAssembler()->addl(x86_64::CpuRegister(x86_64::RDI),
1773                        x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 4));
1774   GetAssembler()->Bind(&target);
1775   const char* expected =
1776     "jrcxz 1f\n"
1777     "addl 4(%RSP),%EDI\n"
1778     "1:\n";
1779 
1780   DriverStr(expected, "jrcxz");
1781 }
1782 
TEST_F(AssemblerX86_64Test,NearLabel)1783 TEST_F(AssemblerX86_64Test, NearLabel) {
1784   // Test both forward and backward branches.
1785   x86_64::NearLabel start, target;
1786   GetAssembler()->Bind(&start);
1787   GetAssembler()->j(x86_64::kEqual, &target);
1788   GetAssembler()->jmp(&target);
1789   GetAssembler()->jrcxz(&target);
1790   GetAssembler()->addl(x86_64::CpuRegister(x86_64::RDI),
1791                        x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 4));
1792   GetAssembler()->Bind(&target);
1793   GetAssembler()->j(x86_64::kNotEqual, &start);
1794   GetAssembler()->jmp(&start);
1795   const char* expected =
1796     "1: je 2f\n"
1797     "jmp 2f\n"
1798     "jrcxz 2f\n"
1799     "addl 4(%RSP),%EDI\n"
1800     "2: jne 1b\n"
1801     "jmp 1b\n";
1802 
1803   DriverStr(expected, "near_label");
1804 }
1805 
setcc_test_fn(AssemblerX86_64Test::Base * assembler_test,x86_64::X86_64Assembler * assembler)1806 std::string setcc_test_fn(AssemblerX86_64Test::Base* assembler_test,
1807                           x86_64::X86_64Assembler* assembler) {
1808   // From Condition
1809   /*
1810   kOverflow     =  0,
1811   kNoOverflow   =  1,
1812   kBelow        =  2,
1813   kAboveEqual   =  3,
1814   kEqual        =  4,
1815   kNotEqual     =  5,
1816   kBelowEqual   =  6,
1817   kAbove        =  7,
1818   kSign         =  8,
1819   kNotSign      =  9,
1820   kParityEven   = 10,
1821   kParityOdd    = 11,
1822   kLess         = 12,
1823   kGreaterEqual = 13,
1824   kLessEqual    = 14,
1825   */
1826   std::string suffixes[15] = { "o", "no", "b", "ae", "e", "ne", "be", "a", "s", "ns", "pe", "po",
1827                                "l", "ge", "le" };
1828 
1829   std::vector<x86_64::CpuRegister*> registers = assembler_test->GetRegisters();
1830   std::ostringstream str;
1831 
1832   for (auto reg : registers) {
1833     for (size_t i = 0; i < 15; ++i) {
1834       assembler->setcc(static_cast<x86_64::Condition>(i), *reg);
1835       str << "set" << suffixes[i] << " %" << assembler_test->GetQuaternaryRegisterName(*reg) << "\n";
1836     }
1837   }
1838 
1839   return str.str();
1840 }
1841 
TEST_F(AssemblerX86_64Test,SetCC)1842 TEST_F(AssemblerX86_64Test, SetCC) {
1843   DriverFn(&setcc_test_fn, "setcc");
1844 }
1845 
TEST_F(AssemblerX86_64Test,MovzxbRegs)1846 TEST_F(AssemblerX86_64Test, MovzxbRegs) {
1847   DriverStr(Repeatrb(&x86_64::X86_64Assembler::movzxb, "movzbl %{reg2}, %{reg1}"), "movzxb");
1848 }
1849 
TEST_F(AssemblerX86_64Test,MovsxbRegs)1850 TEST_F(AssemblerX86_64Test, MovsxbRegs) {
1851   DriverStr(Repeatrb(&x86_64::X86_64Assembler::movsxb, "movsbl %{reg2}, %{reg1}"), "movsxb");
1852 }
1853 
TEST_F(AssemblerX86_64Test,Repnescasw)1854 TEST_F(AssemblerX86_64Test, Repnescasw) {
1855   GetAssembler()->repne_scasw();
1856   const char* expected = "repne scasw\n";
1857   DriverStr(expected, "Repnescasw");
1858 }
1859 
TEST_F(AssemblerX86_64Test,Repecmpsw)1860 TEST_F(AssemblerX86_64Test, Repecmpsw) {
1861   GetAssembler()->repe_cmpsw();
1862   const char* expected = "repe cmpsw\n";
1863   DriverStr(expected, "Repecmpsw");
1864 }
1865 
TEST_F(AssemblerX86_64Test,Repecmpsl)1866 TEST_F(AssemblerX86_64Test, Repecmpsl) {
1867   GetAssembler()->repe_cmpsl();
1868   const char* expected = "repe cmpsl\n";
1869   DriverStr(expected, "Repecmpsl");
1870 }
1871 
TEST_F(AssemblerX86_64Test,Repecmpsq)1872 TEST_F(AssemblerX86_64Test, Repecmpsq) {
1873   GetAssembler()->repe_cmpsq();
1874   const char* expected = "repe cmpsq\n";
1875   DriverStr(expected, "Repecmpsq");
1876 }
1877 
TEST_F(AssemblerX86_64Test,Cmpb)1878 TEST_F(AssemblerX86_64Test, Cmpb) {
1879   GetAssembler()->cmpb(x86_64::Address(x86_64::CpuRegister(x86_64::RDI), 128),
1880                        x86_64::Immediate(0));
1881   const char* expected = "cmpb $0, 128(%RDI)\n";
1882   DriverStr(expected, "cmpb");
1883 }
1884 
TEST_F(AssemblerX86_64Test,TestbAddressImmediate)1885 TEST_F(AssemblerX86_64Test, TestbAddressImmediate) {
1886   GetAssembler()->testb(
1887       x86_64::Address(x86_64::CpuRegister(x86_64::RDI),
1888                       x86_64::CpuRegister(x86_64::RBX),
1889                       x86_64::TIMES_4,
1890                       12),
1891       x86_64::Immediate(1));
1892   GetAssembler()->testb(
1893       x86_64::Address(x86_64::CpuRegister(x86_64::RSP), FrameOffset(7)),
1894       x86_64::Immediate(-128));
1895   GetAssembler()->testb(
1896       x86_64::Address(x86_64::CpuRegister(x86_64::RBX), MemberOffset(130)),
1897       x86_64::Immediate(127));
1898   const char* expected =
1899       "testb $1, 0xc(%RDI,%RBX,4)\n"
1900       "testb $-128, 0x7(%RSP)\n"
1901       "testb $127, 0x82(%RBX)\n";
1902 
1903   DriverStr(expected, "TestbAddressImmediate");
1904 }
1905 
TEST_F(AssemblerX86_64Test,TestlAddressImmediate)1906 TEST_F(AssemblerX86_64Test, TestlAddressImmediate) {
1907   GetAssembler()->testl(
1908       x86_64::Address(x86_64::CpuRegister(x86_64::RDI),
1909                       x86_64::CpuRegister(x86_64::RBX),
1910                       x86_64::TIMES_4,
1911                       12),
1912       x86_64::Immediate(1));
1913   GetAssembler()->testl(
1914       x86_64::Address(x86_64::CpuRegister(x86_64::RSP), FrameOffset(7)),
1915       x86_64::Immediate(-100000));
1916   GetAssembler()->testl(
1917       x86_64::Address(x86_64::CpuRegister(x86_64::RBX), MemberOffset(130)),
1918       x86_64::Immediate(77777777));
1919   const char* expected =
1920       "testl $1, 0xc(%RDI,%RBX,4)\n"
1921       "testl $-100000, 0x7(%RSP)\n"
1922       "testl $77777777, 0x82(%RBX)\n";
1923 
1924   DriverStr(expected, "TestlAddressImmediate");
1925 }
1926 
1927 class JNIMacroAssemblerX86_64Test : public JNIMacroAssemblerTest<x86_64::X86_64JNIMacroAssembler> {
1928  public:
1929   using Base = JNIMacroAssemblerTest<x86_64::X86_64JNIMacroAssembler>;
1930 
1931  protected:
1932   // Get the typically used name for this architecture, e.g., aarch64, x86-64, ...
GetArchitectureString()1933   std::string GetArchitectureString() OVERRIDE {
1934     return "x86_64";
1935   }
1936 
GetDisassembleParameters()1937   std::string GetDisassembleParameters() OVERRIDE {
1938     return " -D -bbinary -mi386:x86-64 -Mx86-64,addr64,data32 --no-show-raw-insn";
1939   }
1940 
1941  private:
1942 };
1943 
ManagedFromCpu(x86_64::Register r)1944 static x86_64::X86_64ManagedRegister ManagedFromCpu(x86_64::Register r) {
1945   return x86_64::X86_64ManagedRegister::FromCpuRegister(r);
1946 }
1947 
ManagedFromFpu(x86_64::FloatRegister r)1948 static x86_64::X86_64ManagedRegister ManagedFromFpu(x86_64::FloatRegister r) {
1949   return x86_64::X86_64ManagedRegister::FromXmmRegister(r);
1950 }
1951 
buildframe_test_fn(JNIMacroAssemblerX86_64Test::Base * assembler_test ATTRIBUTE_UNUSED,x86_64::X86_64JNIMacroAssembler * assembler)1952 std::string buildframe_test_fn(JNIMacroAssemblerX86_64Test::Base* assembler_test ATTRIBUTE_UNUSED,
1953                                x86_64::X86_64JNIMacroAssembler* assembler) {
1954   // TODO: more interesting spill registers / entry spills.
1955 
1956   // Two random spill regs.
1957   const ManagedRegister raw_spill_regs[] = {
1958       ManagedFromCpu(x86_64::R10),
1959       ManagedFromCpu(x86_64::RSI)
1960   };
1961   ArrayRef<const ManagedRegister> spill_regs(raw_spill_regs);
1962 
1963   // Three random entry spills.
1964   ManagedRegisterEntrySpills entry_spills;
1965   ManagedRegisterSpill spill(ManagedFromCpu(x86_64::RAX), 8, 0);
1966   entry_spills.push_back(spill);
1967   ManagedRegisterSpill spill2(ManagedFromCpu(x86_64::RBX), 8, 8);
1968   entry_spills.push_back(spill2);
1969   ManagedRegisterSpill spill3(ManagedFromFpu(x86_64::XMM1), 8, 16);
1970   entry_spills.push_back(spill3);
1971 
1972   x86_64::X86_64ManagedRegister method_reg = ManagedFromCpu(x86_64::RDI);
1973 
1974   size_t frame_size = 10 * kStackAlignment;
1975   assembler->BuildFrame(10 * kStackAlignment, method_reg, spill_regs, entry_spills);
1976 
1977   // Construct assembly text counterpart.
1978   std::ostringstream str;
1979   // 1) Push the spill_regs.
1980   str << "pushq %rsi\n";
1981   str << "pushq %r10\n";
1982   // 2) Move down the stack pointer.
1983   ssize_t displacement = static_cast<ssize_t>(frame_size) - (spill_regs.size() * 8 + 8);
1984   str << "subq $" << displacement << ", %rsp\n";
1985   // 3) Store method reference.
1986   str << "movq %rdi, (%rsp)\n";
1987   // 4) Entry spills.
1988   str << "movq %rax, " << frame_size + 0 << "(%rsp)\n";
1989   str << "movq %rbx, " << frame_size + 8 << "(%rsp)\n";
1990   str << "movsd %xmm1, " << frame_size + 16 << "(%rsp)\n";
1991 
1992   return str.str();
1993 }
1994 
TEST_F(JNIMacroAssemblerX86_64Test,BuildFrame)1995 TEST_F(JNIMacroAssemblerX86_64Test, BuildFrame) {
1996   DriverFn(&buildframe_test_fn, "BuildFrame");
1997 }
1998 
removeframe_test_fn(JNIMacroAssemblerX86_64Test::Base * assembler_test ATTRIBUTE_UNUSED,x86_64::X86_64JNIMacroAssembler * assembler)1999 std::string removeframe_test_fn(JNIMacroAssemblerX86_64Test::Base* assembler_test ATTRIBUTE_UNUSED,
2000                                 x86_64::X86_64JNIMacroAssembler* assembler) {
2001   // TODO: more interesting spill registers / entry spills.
2002 
2003   // Two random spill regs.
2004   const ManagedRegister raw_spill_regs[] = {
2005       ManagedFromCpu(x86_64::R10),
2006       ManagedFromCpu(x86_64::RSI)
2007   };
2008   ArrayRef<const ManagedRegister> spill_regs(raw_spill_regs);
2009 
2010   size_t frame_size = 10 * kStackAlignment;
2011   assembler->RemoveFrame(10 * kStackAlignment, spill_regs);
2012 
2013   // Construct assembly text counterpart.
2014   std::ostringstream str;
2015   // 1) Move up the stack pointer.
2016   ssize_t displacement = static_cast<ssize_t>(frame_size) - spill_regs.size() * 8 - 8;
2017   str << "addq $" << displacement << ", %rsp\n";
2018   // 2) Pop spill regs.
2019   str << "popq %r10\n";
2020   str << "popq %rsi\n";
2021   str << "ret\n";
2022 
2023   return str.str();
2024 }
2025 
TEST_F(JNIMacroAssemblerX86_64Test,RemoveFrame)2026 TEST_F(JNIMacroAssemblerX86_64Test, RemoveFrame) {
2027   DriverFn(&removeframe_test_fn, "RemoveFrame");
2028 }
2029 
increaseframe_test_fn(JNIMacroAssemblerX86_64Test::Base * assembler_test ATTRIBUTE_UNUSED,x86_64::X86_64JNIMacroAssembler * assembler)2030 std::string increaseframe_test_fn(
2031     JNIMacroAssemblerX86_64Test::Base* assembler_test ATTRIBUTE_UNUSED,
2032     x86_64::X86_64JNIMacroAssembler* assembler) {
2033   assembler->IncreaseFrameSize(0U);
2034   assembler->IncreaseFrameSize(kStackAlignment);
2035   assembler->IncreaseFrameSize(10 * kStackAlignment);
2036 
2037   // Construct assembly text counterpart.
2038   std::ostringstream str;
2039   str << "addq $0, %rsp\n";
2040   str << "addq $-" << kStackAlignment << ", %rsp\n";
2041   str << "addq $-" << 10 * kStackAlignment << ", %rsp\n";
2042 
2043   return str.str();
2044 }
2045 
TEST_F(JNIMacroAssemblerX86_64Test,IncreaseFrame)2046 TEST_F(JNIMacroAssemblerX86_64Test, IncreaseFrame) {
2047   DriverFn(&increaseframe_test_fn, "IncreaseFrame");
2048 }
2049 
decreaseframe_test_fn(JNIMacroAssemblerX86_64Test::Base * assembler_test ATTRIBUTE_UNUSED,x86_64::X86_64JNIMacroAssembler * assembler)2050 std::string decreaseframe_test_fn(
2051     JNIMacroAssemblerX86_64Test::Base* assembler_test ATTRIBUTE_UNUSED,
2052     x86_64::X86_64JNIMacroAssembler* assembler) {
2053   assembler->DecreaseFrameSize(0U);
2054   assembler->DecreaseFrameSize(kStackAlignment);
2055   assembler->DecreaseFrameSize(10 * kStackAlignment);
2056 
2057   // Construct assembly text counterpart.
2058   std::ostringstream str;
2059   str << "addq $0, %rsp\n";
2060   str << "addq $" << kStackAlignment << ", %rsp\n";
2061   str << "addq $" << 10 * kStackAlignment << ", %rsp\n";
2062 
2063   return str.str();
2064 }
2065 
TEST_F(JNIMacroAssemblerX86_64Test,DecreaseFrame)2066 TEST_F(JNIMacroAssemblerX86_64Test, DecreaseFrame) {
2067   DriverFn(&decreaseframe_test_fn, "DecreaseFrame");
2068 }
2069 
2070 }  // namespace art
2071