1 /*
2  * Copyright (C) 2011 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.h"
18 
19 #include "base/arena_allocator.h"
20 #include "base/stl_util.h"
21 #include "utils/assembler_test.h"
22 
23 namespace art {
24 
TEST(AssemblerX86,CreateBuffer)25 TEST(AssemblerX86, CreateBuffer) {
26   ArenaPool pool;
27   ArenaAllocator allocator(&pool);
28   AssemblerBuffer buffer(&allocator);
29   AssemblerBuffer::EnsureCapacity ensured(&buffer);
30   buffer.Emit<uint8_t>(0x42);
31   ASSERT_EQ(static_cast<size_t>(1), buffer.Size());
32   buffer.Emit<int32_t>(42);
33   ASSERT_EQ(static_cast<size_t>(5), buffer.Size());
34 }
35 
36 //
37 // Test fixture.
38 //
39 
40 class AssemblerX86Test : public AssemblerTest<x86::X86Assembler,
41                                               x86::Address,
42                                               x86::Register,
43                                               x86::XmmRegister,
44                                               x86::Immediate> {
45  public:
46   typedef AssemblerTest<x86::X86Assembler,
47                         x86::Address,
48                         x86::Register,
49                         x86::XmmRegister,
50                         x86::Immediate> Base;
51 
52  protected:
GetArchitectureString()53   std::string GetArchitectureString() OVERRIDE {
54     return "x86";
55   }
56 
GetAssemblerParameters()57   std::string GetAssemblerParameters() OVERRIDE {
58     return " --32";
59   }
60 
GetDisassembleParameters()61   std::string GetDisassembleParameters() OVERRIDE {
62     return " -D -bbinary -mi386 --no-show-raw-insn";
63   }
64 
SetUpHelpers()65   void SetUpHelpers() OVERRIDE {
66     if (addresses_singleton_.size() == 0) {
67       // One addressing mode to test the repeat drivers.
68       addresses_singleton_.push_back(x86::Address(x86::EAX, x86::EBX, x86::TIMES_1, 2));
69     }
70 
71     if (addresses_.size() == 0) {
72       // Several addressing modes.
73       addresses_.push_back(x86::Address(x86::EDI, x86::EAX, x86::TIMES_1, 15));
74       addresses_.push_back(x86::Address(x86::EDI, x86::EBX, x86::TIMES_2, 16));
75       addresses_.push_back(x86::Address(x86::EDI, x86::ECX, x86::TIMES_4, 17));
76       addresses_.push_back(x86::Address(x86::EDI, x86::EDX, x86::TIMES_8, 18));
77       addresses_.push_back(x86::Address(x86::EAX, -1));
78       addresses_.push_back(x86::Address(x86::EBX, 0));
79       addresses_.push_back(x86::Address(x86::ESI, 1));
80       addresses_.push_back(x86::Address(x86::EDI, 987654321));
81       // Several addressing modes with the special ESP.
82       addresses_.push_back(x86::Address(x86::ESP, x86::EAX, x86::TIMES_1, 15));
83       addresses_.push_back(x86::Address(x86::ESP, x86::EBX, x86::TIMES_2, 16));
84       addresses_.push_back(x86::Address(x86::ESP, x86::ECX, x86::TIMES_4, 17));
85       addresses_.push_back(x86::Address(x86::ESP, x86::EDX, x86::TIMES_8, 18));
86       addresses_.push_back(x86::Address(x86::ESP, -1));
87       addresses_.push_back(x86::Address(x86::ESP, 0));
88       addresses_.push_back(x86::Address(x86::ESP, 1));
89       addresses_.push_back(x86::Address(x86::ESP, 987654321));
90     }
91     if (registers_.size() == 0) {
92       registers_.insert(end(registers_),
93                         {
94                           new x86::Register(x86::EAX),
95                           new x86::Register(x86::EBX),
96                           new x86::Register(x86::ECX),
97                           new x86::Register(x86::EDX),
98                           new x86::Register(x86::EBP),
99                           new x86::Register(x86::ESP),
100                           new x86::Register(x86::ESI),
101                           new x86::Register(x86::EDI)
102                         });
103     }
104 
105     if (fp_registers_.size() == 0) {
106       fp_registers_.insert(end(fp_registers_),
107                            {
108                              new x86::XmmRegister(x86::XMM0),
109                              new x86::XmmRegister(x86::XMM1),
110                              new x86::XmmRegister(x86::XMM2),
111                              new x86::XmmRegister(x86::XMM3),
112                              new x86::XmmRegister(x86::XMM4),
113                              new x86::XmmRegister(x86::XMM5),
114                              new x86::XmmRegister(x86::XMM6),
115                              new x86::XmmRegister(x86::XMM7)
116                            });
117     }
118   }
119 
TearDown()120   void TearDown() OVERRIDE {
121     AssemblerTest::TearDown();
122     STLDeleteElements(&registers_);
123     STLDeleteElements(&fp_registers_);
124   }
125 
GetAddresses()126   std::vector<x86::Address> GetAddresses() OVERRIDE {
127     return addresses_;
128   }
129 
GetRegisters()130   std::vector<x86::Register*> GetRegisters() OVERRIDE {
131     return registers_;
132   }
133 
GetFPRegisters()134   std::vector<x86::XmmRegister*> GetFPRegisters() OVERRIDE {
135     return fp_registers_;
136   }
137 
CreateImmediate(int64_t imm_value)138   x86::Immediate CreateImmediate(int64_t imm_value) OVERRIDE {
139     return x86::Immediate(imm_value);
140   }
141 
142   std::vector<x86::Address> addresses_singleton_;
143 
144  private:
145   std::vector<x86::Address> addresses_;
146   std::vector<x86::Register*> registers_;
147   std::vector<x86::XmmRegister*> fp_registers_;
148 };
149 
150 //
151 // Test some repeat drivers used in the tests.
152 //
153 
TEST_F(AssemblerX86Test,RepeatRR)154 TEST_F(AssemblerX86Test, RepeatRR) {
155   EXPECT_NE(RepeatRR(/*f*/ nullptr, "%{reg1} %{reg2}")
156             .find("%eax %eax\n%eax %ebx\n%eax %ecx\n%eax %edx\n%eax %ebp\n%eax %esp\n%eax %esi\n"
157                   "%eax %edi\n%ebx %eax\n%ebx %ebx\n%ebx %ecx\n%ebx %edx\n%ebx %ebp\n%ebx %esp\n"),
158             std::string::npos);
159 }
160 
TEST_F(AssemblerX86Test,RepeatRI)161 TEST_F(AssemblerX86Test, RepeatRI) {
162   EXPECT_EQ("%eax $0\n%eax $-1\n%eax $18\n%ebx $0\n%ebx $-1\n%ebx $18\n%ecx $0\n%ecx $-1\n"
163             "%ecx $18\n%edx $0\n%edx $-1\n%edx $18\n%ebp $0\n%ebp $-1\n%ebp $18\n%esp $0\n"
164             "%esp $-1\n%esp $18\n%esi $0\n%esi $-1\n%esi $18\n%edi $0\n%edi $-1\n%edi $18\n",
165             RepeatRI(/*f*/ nullptr, /*imm_bytes*/ 1U, "%{reg} ${imm}"));
166 }
167 
TEST_F(AssemblerX86Test,RepeatFF)168 TEST_F(AssemblerX86Test, RepeatFF) {
169   EXPECT_NE(RepeatFF(/*f*/ nullptr, "%{reg1} %{reg2}")
170             .find("%XMM0 %XMM0\n%XMM0 %XMM1\n%XMM0 %XMM2\n%XMM0 %XMM3\n%XMM0 %XMM4\n%XMM0 %XMM5\n"
171                   "%XMM0 %XMM6\n%XMM0 %XMM7\n%XMM1 %XMM0\n%XMM1 %XMM1\n%XMM1 %XMM2\n%XMM1 %XMM3\n"),
172             std::string::npos);
173 }
174 
TEST_F(AssemblerX86Test,RepeatFFI)175 TEST_F(AssemblerX86Test, RepeatFFI) {
176   EXPECT_NE(RepeatFFI(/*f*/ nullptr, /*imm_bytes*/ 1U, "%{reg1} %{reg2} ${imm}")
177             .find("%XMM0 %XMM0 $0\n%XMM0 %XMM0 $-1\n%XMM0 %XMM0 $18\n"
178                   "%XMM0 %XMM1 $0\n%XMM0 %XMM1 $-1\n%XMM0 %XMM1 $18\n"),
179             std::string::npos);
180 }
181 
TEST_F(AssemblerX86Test,RepeatA)182 TEST_F(AssemblerX86Test, RepeatA) {
183   EXPECT_EQ("2(%eax,%ebx,1)\n", RepeatA(/*f*/ nullptr, addresses_singleton_, "{mem}"));
184 }
185 
TEST_F(AssemblerX86Test,RepeatAI)186 TEST_F(AssemblerX86Test, RepeatAI) {
187   EXPECT_EQ("2(%eax,%ebx,1) $0\n2(%eax,%ebx,1) $-1\n2(%eax,%ebx,1) $18\n",
188             RepeatAI(/*f*/ nullptr, /*imm_bytes*/ 1U, addresses_singleton_, "{mem} ${imm}"));
189 }
190 
TEST_F(AssemblerX86Test,RepeatRA)191 TEST_F(AssemblerX86Test, RepeatRA) {
192   EXPECT_EQ("%eax 2(%eax,%ebx,1)\n%ebx 2(%eax,%ebx,1)\n%ecx 2(%eax,%ebx,1)\n"
193             "%edx 2(%eax,%ebx,1)\n%ebp 2(%eax,%ebx,1)\n%esp 2(%eax,%ebx,1)\n"
194             "%esi 2(%eax,%ebx,1)\n%edi 2(%eax,%ebx,1)\n",
195             RepeatRA(/*f*/ nullptr, addresses_singleton_, "%{reg} {mem}"));
196 }
197 
TEST_F(AssemblerX86Test,RepeatAR)198 TEST_F(AssemblerX86Test, RepeatAR) {
199   EXPECT_EQ("2(%eax,%ebx,1) %eax\n2(%eax,%ebx,1) %ebx\n2(%eax,%ebx,1) %ecx\n"
200             "2(%eax,%ebx,1) %edx\n2(%eax,%ebx,1) %ebp\n2(%eax,%ebx,1) %esp\n"
201             "2(%eax,%ebx,1) %esi\n2(%eax,%ebx,1) %edi\n",
202             RepeatAR(/*f*/ nullptr, addresses_singleton_, "{mem} %{reg}"));
203 }
204 
TEST_F(AssemblerX86Test,RepeatFA)205 TEST_F(AssemblerX86Test, RepeatFA) {
206   EXPECT_EQ("%XMM0 2(%eax,%ebx,1)\n%XMM1 2(%eax,%ebx,1)\n%XMM2 2(%eax,%ebx,1)\n"
207             "%XMM3 2(%eax,%ebx,1)\n%XMM4 2(%eax,%ebx,1)\n%XMM5 2(%eax,%ebx,1)\n"
208             "%XMM6 2(%eax,%ebx,1)\n%XMM7 2(%eax,%ebx,1)\n",
209             RepeatFA(/*f*/ nullptr, addresses_singleton_, "%{reg} {mem}"));
210 }
211 
TEST_F(AssemblerX86Test,RepeatAF)212 TEST_F(AssemblerX86Test, RepeatAF) {
213   EXPECT_EQ("2(%eax,%ebx,1) %XMM0\n2(%eax,%ebx,1) %XMM1\n2(%eax,%ebx,1) %XMM2\n"
214             "2(%eax,%ebx,1) %XMM3\n2(%eax,%ebx,1) %XMM4\n2(%eax,%ebx,1) %XMM5\n"
215             "2(%eax,%ebx,1) %XMM6\n2(%eax,%ebx,1) %XMM7\n",
216             RepeatAF(/*f*/ nullptr, addresses_singleton_, "{mem} %{reg}"));
217 }
218 
219 //
220 // Actual x86 instruction assembler tests.
221 //
222 
TEST_F(AssemblerX86Test,PoplAllAddresses)223 TEST_F(AssemblerX86Test, PoplAllAddresses) {
224   // Make sure all addressing modes combinations are tested at least once.
225   std::vector<x86::Address> all_addresses;
226   for (x86::Register* base : GetRegisters()) {
227     // Base only.
228     all_addresses.push_back(x86::Address(*base, -1));
229     all_addresses.push_back(x86::Address(*base, 0));
230     all_addresses.push_back(x86::Address(*base, 1));
231     all_addresses.push_back(x86::Address(*base, 123456789));
232     for (x86::Register* index : GetRegisters()) {
233       if (*index == x86::ESP) {
234         // Index cannot be ESP.
235         continue;
236       } else if (*base == *index) {
237        // Index only.
238        all_addresses.push_back(x86::Address(*index, x86::TIMES_1, -1));
239        all_addresses.push_back(x86::Address(*index, x86::TIMES_2, 0));
240        all_addresses.push_back(x86::Address(*index, x86::TIMES_4, 1));
241        all_addresses.push_back(x86::Address(*index, x86::TIMES_8, 123456789));
242       }
243       // Base and index.
244       all_addresses.push_back(x86::Address(*base, *index, x86::TIMES_1, -1));
245       all_addresses.push_back(x86::Address(*base, *index, x86::TIMES_2, 0));
246       all_addresses.push_back(x86::Address(*base, *index, x86::TIMES_4, 1));
247       all_addresses.push_back(x86::Address(*base, *index, x86::TIMES_8, 123456789));
248     }
249   }
250   DriverStr(RepeatA(&x86::X86Assembler::popl, all_addresses, "popl {mem}"), "popq");
251 }
252 
TEST_F(AssemblerX86Test,Movl)253 TEST_F(AssemblerX86Test, Movl) {
254   DriverStr(RepeatRR(&x86::X86Assembler::movl, "movl %{reg2}, %{reg1}"), "movl");
255 }
256 
TEST_F(AssemblerX86Test,MovlLoad)257 TEST_F(AssemblerX86Test, MovlLoad) {
258   DriverStr(RepeatRA(&x86::X86Assembler::movl, "movl {mem}, %{reg}"), "movl-load");
259 }
260 
TEST_F(AssemblerX86Test,Addw)261 TEST_F(AssemblerX86Test, Addw) {
262   DriverStr(RepeatAI(&x86::X86Assembler::addw, /*imm_bytes*/ 2U, "addw ${imm}, {mem}"), "addw");
263 }
264 
TEST_F(AssemblerX86Test,MovlStore)265 TEST_F(AssemblerX86Test, MovlStore) {
266   DriverStr(RepeatAR(&x86::X86Assembler::movl, "movl %{reg}, {mem}"), "movl-store");
267 }
268 
TEST_F(AssemblerX86Test,Movntl)269 TEST_F(AssemblerX86Test, Movntl) {
270   DriverStr(RepeatAR(&x86::X86Assembler::movntl, "movntil %{reg}, {mem}"), "movntl");
271 }
272 
TEST_F(AssemblerX86Test,LoadLongConstant)273 TEST_F(AssemblerX86Test, LoadLongConstant) {
274   GetAssembler()->LoadLongConstant(x86::XMM0, 51);
275   const char* expected =
276       "push $0x0\n"
277       "push $0x33\n"
278       "movsd 0(%esp), %xmm0\n"
279       "add $8, %esp\n";
280   DriverStr(expected, "LoadLongConstant");
281 }
282 
TEST_F(AssemblerX86Test,LockCmpxchgl)283 TEST_F(AssemblerX86Test, LockCmpxchgl) {
284   DriverStr(RepeatAR(&x86::X86Assembler::LockCmpxchgl,
285                      "lock cmpxchgl %{reg}, {mem}"), "lock_cmpxchgl");
286 }
287 
TEST_F(AssemblerX86Test,LockCmpxchg8b)288 TEST_F(AssemblerX86Test, LockCmpxchg8b) {
289   DriverStr(RepeatA(&x86::X86Assembler::LockCmpxchg8b,
290                     "lock cmpxchg8b {mem}"), "lock_cmpxchg8b");
291 }
292 
TEST_F(AssemblerX86Test,FPUIntegerLoadS)293 TEST_F(AssemblerX86Test, FPUIntegerLoadS) {
294   DriverStr(RepeatA(&x86::X86Assembler::filds, "fildl {mem}"), "fildd");
295 }
296 
TEST_F(AssemblerX86Test,FPUIntegerLoadL)297 TEST_F(AssemblerX86Test, FPUIntegerLoadL) {
298   DriverStr(RepeatA(&x86::X86Assembler::fildl, "fildll {mem}"), "fildl");
299 }
300 
TEST_F(AssemblerX86Test,FPUIntegerStoreS)301 TEST_F(AssemblerX86Test, FPUIntegerStoreS) {
302   DriverStr(RepeatA(&x86::X86Assembler::fistps, "fistpl {mem}"), "fistps");
303 }
304 
TEST_F(AssemblerX86Test,FPUIntegerStoreL)305 TEST_F(AssemblerX86Test, FPUIntegerStoreL) {
306   DriverStr(RepeatA(&x86::X86Assembler::fistpl, "fistpll {mem}"), "fistpl");
307 }
308 
TEST_F(AssemblerX86Test,Repnescasb)309 TEST_F(AssemblerX86Test, Repnescasb) {
310   GetAssembler()->repne_scasb();
311   const char* expected = "repne scasb\n";
312   DriverStr(expected, "Repnescasb");
313 }
314 
TEST_F(AssemblerX86Test,Repnescasw)315 TEST_F(AssemblerX86Test, Repnescasw) {
316   GetAssembler()->repne_scasw();
317   const char* expected = "repne scasw\n";
318   DriverStr(expected, "Repnescasw");
319 }
320 
TEST_F(AssemblerX86Test,Repecmpsb)321 TEST_F(AssemblerX86Test, Repecmpsb) {
322   GetAssembler()->repe_cmpsb();
323   const char* expected = "repe cmpsb\n";
324   DriverStr(expected, "Repecmpsb");
325 }
326 
TEST_F(AssemblerX86Test,Repecmpsw)327 TEST_F(AssemblerX86Test, Repecmpsw) {
328   GetAssembler()->repe_cmpsw();
329   const char* expected = "repe cmpsw\n";
330   DriverStr(expected, "Repecmpsw");
331 }
332 
TEST_F(AssemblerX86Test,Repecmpsl)333 TEST_F(AssemblerX86Test, Repecmpsl) {
334   GetAssembler()->repe_cmpsl();
335   const char* expected = "repe cmpsl\n";
336   DriverStr(expected, "Repecmpsl");
337 }
338 
TEST_F(AssemblerX86Test,RepMovsb)339 TEST_F(AssemblerX86Test, RepMovsb) {
340   GetAssembler()->rep_movsb();
341   const char* expected = "rep movsb\n";
342   DriverStr(expected, "rep_movsb");
343 }
344 
TEST_F(AssemblerX86Test,RepMovsw)345 TEST_F(AssemblerX86Test, RepMovsw) {
346   GetAssembler()->rep_movsw();
347   const char* expected = "rep movsw\n";
348   DriverStr(expected, "rep_movsw");
349 }
350 
TEST_F(AssemblerX86Test,Bsfl)351 TEST_F(AssemblerX86Test, Bsfl) {
352   DriverStr(RepeatRR(&x86::X86Assembler::bsfl, "bsfl %{reg2}, %{reg1}"), "bsfl");
353 }
354 
TEST_F(AssemblerX86Test,BsflAddress)355 TEST_F(AssemblerX86Test, BsflAddress) {
356   DriverStr(RepeatRA(&x86::X86Assembler::bsfl, "bsfl {mem}, %{reg}"), "bsfl_address");
357 }
358 
TEST_F(AssemblerX86Test,Bsrl)359 TEST_F(AssemblerX86Test, Bsrl) {
360   DriverStr(RepeatRR(&x86::X86Assembler::bsrl, "bsrl %{reg2}, %{reg1}"), "bsrl");
361 }
362 
TEST_F(AssemblerX86Test,BsrlAddress)363 TEST_F(AssemblerX86Test, BsrlAddress) {
364   DriverStr(RepeatRA(&x86::X86Assembler::bsrl, "bsrl {mem}, %{reg}"), "bsrl_address");
365 }
366 
TEST_F(AssemblerX86Test,Popcntl)367 TEST_F(AssemblerX86Test, Popcntl) {
368   DriverStr(RepeatRR(&x86::X86Assembler::popcntl, "popcntl %{reg2}, %{reg1}"), "popcntl");
369 }
370 
TEST_F(AssemblerX86Test,PopcntlAddress)371 TEST_F(AssemblerX86Test, PopcntlAddress) {
372   DriverStr(RepeatRA(&x86::X86Assembler::popcntl, "popcntl {mem}, %{reg}"), "popcntl_address");
373 }
374 
375 // Rorl only allows CL as the shift count.
rorl_fn(AssemblerX86Test::Base * assembler_test,x86::X86Assembler * assembler)376 std::string rorl_fn(AssemblerX86Test::Base* assembler_test, x86::X86Assembler* assembler) {
377   std::ostringstream str;
378   std::vector<x86::Register*> registers = assembler_test->GetRegisters();
379   x86::Register shifter(x86::ECX);
380   for (auto reg : registers) {
381     assembler->rorl(*reg, shifter);
382     str << "rorl %cl, %" << assembler_test->GetRegisterName(*reg) << "\n";
383   }
384   return str.str();
385 }
386 
TEST_F(AssemblerX86Test,RorlReg)387 TEST_F(AssemblerX86Test, RorlReg) {
388   DriverFn(&rorl_fn, "rorl");
389 }
390 
TEST_F(AssemblerX86Test,RorlImm)391 TEST_F(AssemblerX86Test, RorlImm) {
392   DriverStr(RepeatRI(&x86::X86Assembler::rorl, /*imm_bytes*/ 1U, "rorl ${imm}, %{reg}"), "rorli");
393 }
394 
395 // Roll only allows CL as the shift count.
roll_fn(AssemblerX86Test::Base * assembler_test,x86::X86Assembler * assembler)396 std::string roll_fn(AssemblerX86Test::Base* assembler_test, x86::X86Assembler* assembler) {
397   std::ostringstream str;
398   std::vector<x86::Register*> registers = assembler_test->GetRegisters();
399   x86::Register shifter(x86::ECX);
400   for (auto reg : registers) {
401     assembler->roll(*reg, shifter);
402     str << "roll %cl, %" << assembler_test->GetRegisterName(*reg) << "\n";
403   }
404   return str.str();
405 }
406 
TEST_F(AssemblerX86Test,RollReg)407 TEST_F(AssemblerX86Test, RollReg) {
408   DriverFn(&roll_fn, "roll");
409 }
410 
TEST_F(AssemblerX86Test,RollImm)411 TEST_F(AssemblerX86Test, RollImm) {
412   DriverStr(RepeatRI(&x86::X86Assembler::roll, /*imm_bytes*/ 1U, "roll ${imm}, %{reg}"), "rolli");
413 }
414 
TEST_F(AssemblerX86Test,Cvtdq2ps)415 TEST_F(AssemblerX86Test, Cvtdq2ps) {
416   DriverStr(RepeatFF(&x86::X86Assembler::cvtdq2ps, "cvtdq2ps %{reg2}, %{reg1}"), "cvtdq2ps");
417 }
418 
TEST_F(AssemblerX86Test,Cvtdq2pd)419 TEST_F(AssemblerX86Test, Cvtdq2pd) {
420   DriverStr(RepeatFF(&x86::X86Assembler::cvtdq2pd, "cvtdq2pd %{reg2}, %{reg1}"), "cvtdq2pd");
421 }
422 
TEST_F(AssemblerX86Test,ComissAddr)423 TEST_F(AssemblerX86Test, ComissAddr) {
424   DriverStr(RepeatFA(&x86::X86Assembler::comiss, "comiss {mem}, %{reg}"), "comiss");
425 }
426 
TEST_F(AssemblerX86Test,UComissAddr)427 TEST_F(AssemblerX86Test, UComissAddr) {
428   DriverStr(RepeatFA(&x86::X86Assembler::ucomiss, "ucomiss {mem}, %{reg}"), "ucomiss");
429 }
430 
TEST_F(AssemblerX86Test,ComisdAddr)431 TEST_F(AssemblerX86Test, ComisdAddr) {
432   DriverStr(RepeatFA(&x86::X86Assembler::comisd, "comisd {mem}, %{reg}"), "comisd");
433 }
434 
TEST_F(AssemblerX86Test,UComisdAddr)435 TEST_F(AssemblerX86Test, UComisdAddr) {
436   DriverStr(RepeatFA(&x86::X86Assembler::ucomisd, "ucomisd {mem}, %{reg}"), "ucomisd");
437 }
438 
TEST_F(AssemblerX86Test,RoundSS)439 TEST_F(AssemblerX86Test, RoundSS) {
440   DriverStr(RepeatFFI(&x86::X86Assembler::roundss, /*imm_bytes*/ 1U,
441                       "roundss ${imm}, %{reg2}, %{reg1}"), "roundss");
442 }
443 
TEST_F(AssemblerX86Test,RoundSD)444 TEST_F(AssemblerX86Test, RoundSD) {
445   DriverStr(RepeatFFI(&x86::X86Assembler::roundsd, /*imm_bytes*/ 1U,
446                       "roundsd ${imm}, %{reg2}, %{reg1}"), "roundsd");
447 }
448 
TEST_F(AssemblerX86Test,CmovlAddress)449 TEST_F(AssemblerX86Test, CmovlAddress) {
450   GetAssembler()->cmovl(x86::kEqual, x86::Register(x86::EAX), x86::Address(
451       x86::Register(x86::EDI), x86::Register(x86::EBX), x86::TIMES_4, 12));
452   GetAssembler()->cmovl(x86::kNotEqual, x86::Register(x86::EDI), x86::Address(
453       x86::Register(x86::ESI), x86::Register(x86::EBX), x86::TIMES_4, 12));
454   GetAssembler()->cmovl(x86::kEqual, x86::Register(x86::EDI), x86::Address(
455       x86::Register(x86::EDI), x86::Register(x86::EAX), x86::TIMES_4, 12));
456   const char* expected =
457     "cmovzl 0xc(%EDI,%EBX,4), %eax\n"
458     "cmovnzl 0xc(%ESI,%EBX,4), %edi\n"
459     "cmovzl 0xc(%EDI,%EAX,4), %edi\n";
460   DriverStr(expected, "cmovl_address");
461 }
462 
TEST_F(AssemblerX86Test,TestbAddressImmediate)463 TEST_F(AssemblerX86Test, TestbAddressImmediate) {
464   DriverStr(RepeatAI(&x86::X86Assembler::testb, /*imm_bytes*/ 1U, "testb ${imm}, {mem}"), "testb");
465 }
466 
TEST_F(AssemblerX86Test,TestlAddressImmediate)467 TEST_F(AssemblerX86Test, TestlAddressImmediate) {
468   DriverStr(RepeatAI(&x86::X86Assembler::testl, /*imm_bytes*/ 4U, "testl ${imm}, {mem}"), "testl");
469 }
470 
TEST_F(AssemblerX86Test,Movaps)471 TEST_F(AssemblerX86Test, Movaps) {
472   DriverStr(RepeatFF(&x86::X86Assembler::movaps, "movaps %{reg2}, %{reg1}"), "movaps");
473 }
474 
TEST_F(AssemblerX86Test,MovapsLoad)475 TEST_F(AssemblerX86Test, MovapsLoad) {
476   DriverStr(RepeatFA(&x86::X86Assembler::movaps, "movaps {mem}, %{reg}"), "movaps_load");
477 }
478 
TEST_F(AssemblerX86Test,MovapsStore)479 TEST_F(AssemblerX86Test, MovapsStore) {
480   DriverStr(RepeatAF(&x86::X86Assembler::movaps, "movaps %{reg}, {mem}"), "movaps_store");
481 }
482 
TEST_F(AssemblerX86Test,MovupsLoad)483 TEST_F(AssemblerX86Test, MovupsLoad) {
484   DriverStr(RepeatFA(&x86::X86Assembler::movups, "movups {mem}, %{reg}"), "movups_load");
485 }
486 
TEST_F(AssemblerX86Test,MovupsStore)487 TEST_F(AssemblerX86Test, MovupsStore) {
488   DriverStr(RepeatAF(&x86::X86Assembler::movups, "movups %{reg}, {mem}"), "movups_store");
489 }
490 
TEST_F(AssemblerX86Test,Movapd)491 TEST_F(AssemblerX86Test, Movapd) {
492   DriverStr(RepeatFF(&x86::X86Assembler::movapd, "movapd %{reg2}, %{reg1}"), "movapd");
493 }
494 
TEST_F(AssemblerX86Test,MovapdLoad)495 TEST_F(AssemblerX86Test, MovapdLoad) {
496   DriverStr(RepeatFA(&x86::X86Assembler::movapd, "movapd {mem}, %{reg}"), "movapd_load");
497 }
498 
TEST_F(AssemblerX86Test,MovapdStore)499 TEST_F(AssemblerX86Test, MovapdStore) {
500   DriverStr(RepeatAF(&x86::X86Assembler::movapd, "movapd %{reg}, {mem}"), "movapd_store");
501 }
502 
TEST_F(AssemblerX86Test,MovupdLoad)503 TEST_F(AssemblerX86Test, MovupdLoad) {
504   DriverStr(RepeatFA(&x86::X86Assembler::movupd, "movupd {mem}, %{reg}"), "movupd_load");
505 }
506 
TEST_F(AssemblerX86Test,MovupdStore)507 TEST_F(AssemblerX86Test, MovupdStore) {
508   DriverStr(RepeatAF(&x86::X86Assembler::movupd, "movupd %{reg}, {mem}"), "movupd_store");
509 }
510 
TEST_F(AssemblerX86Test,Movdqa)511 TEST_F(AssemblerX86Test, Movdqa) {
512   DriverStr(RepeatFF(&x86::X86Assembler::movdqa, "movdqa %{reg2}, %{reg1}"), "movdqa");
513 }
514 
TEST_F(AssemblerX86Test,MovdqaLoad)515 TEST_F(AssemblerX86Test, MovdqaLoad) {
516   DriverStr(RepeatFA(&x86::X86Assembler::movdqa, "movdqa {mem}, %{reg}"), "movdqa_load");
517 }
518 
TEST_F(AssemblerX86Test,MovdqaStore)519 TEST_F(AssemblerX86Test, MovdqaStore) {
520   DriverStr(RepeatAF(&x86::X86Assembler::movdqa, "movdqa %{reg}, {mem}"), "movdqa_store");
521 }
522 
TEST_F(AssemblerX86Test,MovdquLoad)523 TEST_F(AssemblerX86Test, MovdquLoad) {
524   DriverStr(RepeatFA(&x86::X86Assembler::movdqu, "movdqu {mem}, %{reg}"), "movdqu_load");
525 }
526 
TEST_F(AssemblerX86Test,MovdquStore)527 TEST_F(AssemblerX86Test, MovdquStore) {
528   DriverStr(RepeatAF(&x86::X86Assembler::movdqu, "movdqu %{reg}, {mem}"), "movdqu_store");
529 }
530 
TEST_F(AssemblerX86Test,AddPS)531 TEST_F(AssemblerX86Test, AddPS) {
532   DriverStr(RepeatFF(&x86::X86Assembler::addps, "addps %{reg2}, %{reg1}"), "addps");
533 }
534 
TEST_F(AssemblerX86Test,AddPD)535 TEST_F(AssemblerX86Test, AddPD) {
536   DriverStr(RepeatFF(&x86::X86Assembler::addpd, "addpd %{reg2}, %{reg1}"), "addpd");
537 }
538 
TEST_F(AssemblerX86Test,SubPS)539 TEST_F(AssemblerX86Test, SubPS) {
540   DriverStr(RepeatFF(&x86::X86Assembler::subps, "subps %{reg2}, %{reg1}"), "subps");
541 }
542 
TEST_F(AssemblerX86Test,SubPD)543 TEST_F(AssemblerX86Test, SubPD) {
544   DriverStr(RepeatFF(&x86::X86Assembler::subpd, "subpd %{reg2}, %{reg1}"), "subpd");
545 }
546 
TEST_F(AssemblerX86Test,MulPS)547 TEST_F(AssemblerX86Test, MulPS) {
548   DriverStr(RepeatFF(&x86::X86Assembler::mulps, "mulps %{reg2}, %{reg1}"), "mulps");
549 }
550 
TEST_F(AssemblerX86Test,MulPD)551 TEST_F(AssemblerX86Test, MulPD) {
552   DriverStr(RepeatFF(&x86::X86Assembler::mulpd, "mulpd %{reg2}, %{reg1}"), "mulpd");
553 }
554 
TEST_F(AssemblerX86Test,DivPS)555 TEST_F(AssemblerX86Test, DivPS) {
556   DriverStr(RepeatFF(&x86::X86Assembler::divps, "divps %{reg2}, %{reg1}"), "divps");
557 }
558 
TEST_F(AssemblerX86Test,DivPD)559 TEST_F(AssemblerX86Test, DivPD) {
560   DriverStr(RepeatFF(&x86::X86Assembler::divpd, "divpd %{reg2}, %{reg1}"), "divpd");
561 }
562 
TEST_F(AssemblerX86Test,PAddB)563 TEST_F(AssemblerX86Test, PAddB) {
564   DriverStr(RepeatFF(&x86::X86Assembler::paddb, "paddb %{reg2}, %{reg1}"), "paddb");
565 }
566 
TEST_F(AssemblerX86Test,PSubB)567 TEST_F(AssemblerX86Test, PSubB) {
568   DriverStr(RepeatFF(&x86::X86Assembler::psubb, "psubb %{reg2}, %{reg1}"), "psubb");
569 }
570 
TEST_F(AssemblerX86Test,PAddW)571 TEST_F(AssemblerX86Test, PAddW) {
572   DriverStr(RepeatFF(&x86::X86Assembler::paddw, "paddw %{reg2}, %{reg1}"), "paddw");
573 }
574 
TEST_F(AssemblerX86Test,PSubW)575 TEST_F(AssemblerX86Test, PSubW) {
576   DriverStr(RepeatFF(&x86::X86Assembler::psubw, "psubw %{reg2}, %{reg1}"), "psubw");
577 }
578 
TEST_F(AssemblerX86Test,PMullW)579 TEST_F(AssemblerX86Test, PMullW) {
580   DriverStr(RepeatFF(&x86::X86Assembler::pmullw, "pmullw %{reg2}, %{reg1}"), "pmullw");
581 }
582 
TEST_F(AssemblerX86Test,PAddD)583 TEST_F(AssemblerX86Test, PAddD) {
584   DriverStr(RepeatFF(&x86::X86Assembler::paddd, "paddd %{reg2}, %{reg1}"), "paddd");
585 }
586 
TEST_F(AssemblerX86Test,PSubD)587 TEST_F(AssemblerX86Test, PSubD) {
588   DriverStr(RepeatFF(&x86::X86Assembler::psubd, "psubd %{reg2}, %{reg1}"), "psubd");
589 }
590 
TEST_F(AssemblerX86Test,PMullD)591 TEST_F(AssemblerX86Test, PMullD) {
592   DriverStr(RepeatFF(&x86::X86Assembler::pmulld, "pmulld %{reg2}, %{reg1}"), "pmulld");
593 }
594 
TEST_F(AssemblerX86Test,PAddQ)595 TEST_F(AssemblerX86Test, PAddQ) {
596   DriverStr(RepeatFF(&x86::X86Assembler::paddq, "paddq %{reg2}, %{reg1}"), "paddq");
597 }
598 
TEST_F(AssemblerX86Test,PSubQ)599 TEST_F(AssemblerX86Test, PSubQ) {
600   DriverStr(RepeatFF(&x86::X86Assembler::psubq, "psubq %{reg2}, %{reg1}"), "psubq");
601 }
602 
TEST_F(AssemblerX86Test,XorPD)603 TEST_F(AssemblerX86Test, XorPD) {
604   DriverStr(RepeatFF(&x86::X86Assembler::xorpd, "xorpd %{reg2}, %{reg1}"), "xorpd");
605 }
606 
TEST_F(AssemblerX86Test,XorPS)607 TEST_F(AssemblerX86Test, XorPS) {
608   DriverStr(RepeatFF(&x86::X86Assembler::xorps, "xorps %{reg2}, %{reg1}"), "xorps");
609 }
610 
TEST_F(AssemblerX86Test,PXor)611 TEST_F(AssemblerX86Test, PXor) {
612   DriverStr(RepeatFF(&x86::X86Assembler::pxor, "pxor %{reg2}, %{reg1}"), "pxor");
613 }
614 
TEST_F(AssemblerX86Test,AndPD)615 TEST_F(AssemblerX86Test, AndPD) {
616   DriverStr(RepeatFF(&x86::X86Assembler::andpd, "andpd %{reg2}, %{reg1}"), "andpd");
617 }
618 
TEST_F(AssemblerX86Test,AndPS)619 TEST_F(AssemblerX86Test, AndPS) {
620   DriverStr(RepeatFF(&x86::X86Assembler::andps, "andps %{reg2}, %{reg1}"), "andps");
621 }
622 
TEST_F(AssemblerX86Test,PAnd)623 TEST_F(AssemblerX86Test, PAnd) {
624   DriverStr(RepeatFF(&x86::X86Assembler::pand, "pand %{reg2}, %{reg1}"), "pand");
625 }
626 
TEST_F(AssemblerX86Test,AndnPD)627 TEST_F(AssemblerX86Test, AndnPD) {
628   DriverStr(RepeatFF(&x86::X86Assembler::andnpd, "andnpd %{reg2}, %{reg1}"), "andnpd");
629 }
630 
TEST_F(AssemblerX86Test,AndnPS)631 TEST_F(AssemblerX86Test, AndnPS) {
632   DriverStr(RepeatFF(&x86::X86Assembler::andnps, "andnps %{reg2}, %{reg1}"), "andnps");
633 }
634 
TEST_F(AssemblerX86Test,PAndn)635 TEST_F(AssemblerX86Test, PAndn) {
636   DriverStr(RepeatFF(&x86::X86Assembler::pandn, "pandn %{reg2}, %{reg1}"), "pandn");
637 }
638 
TEST_F(AssemblerX86Test,OrPD)639 TEST_F(AssemblerX86Test, OrPD) {
640   DriverStr(RepeatFF(&x86::X86Assembler::orpd, "orpd %{reg2}, %{reg1}"), "orpd");
641 }
642 
TEST_F(AssemblerX86Test,OrPS)643 TEST_F(AssemblerX86Test, OrPS) {
644   DriverStr(RepeatFF(&x86::X86Assembler::orps, "orps %{reg2}, %{reg1}"), "orps");
645 }
646 
TEST_F(AssemblerX86Test,POr)647 TEST_F(AssemblerX86Test, POr) {
648   DriverStr(RepeatFF(&x86::X86Assembler::por, "por %{reg2}, %{reg1}"), "por");
649 }
650 
TEST_F(AssemblerX86Test,PAvgB)651 TEST_F(AssemblerX86Test, PAvgB) {
652   DriverStr(RepeatFF(&x86::X86Assembler::pavgb, "pavgb %{reg2}, %{reg1}"), "pavgb");
653 }
654 
TEST_F(AssemblerX86Test,PAvgW)655 TEST_F(AssemblerX86Test, PAvgW) {
656   DriverStr(RepeatFF(&x86::X86Assembler::pavgw, "pavgw %{reg2}, %{reg1}"), "pavgw");
657 }
658 
TEST_F(AssemblerX86Test,PSadBW)659 TEST_F(AssemblerX86Test, PSadBW) {
660   DriverStr(RepeatFF(&x86::X86Assembler::psadbw, "psadbw %{reg2}, %{reg1}"), "psadbw");
661 }
662 
TEST_F(AssemblerX86Test,PMAddWD)663 TEST_F(AssemblerX86Test, PMAddWD) {
664   DriverStr(RepeatFF(&x86::X86Assembler::pmaddwd, "pmaddwd %{reg2}, %{reg1}"), "pmaddwd");
665 }
666 
TEST_F(AssemblerX86Test,PHAddW)667 TEST_F(AssemblerX86Test, PHAddW) {
668   DriverStr(RepeatFF(&x86::X86Assembler::phaddw, "phaddw %{reg2}, %{reg1}"), "phaddw");
669 }
670 
TEST_F(AssemblerX86Test,PHAddD)671 TEST_F(AssemblerX86Test, PHAddD) {
672   DriverStr(RepeatFF(&x86::X86Assembler::phaddd, "phaddd %{reg2}, %{reg1}"), "phaddd");
673 }
674 
TEST_F(AssemblerX86Test,HAddPS)675 TEST_F(AssemblerX86Test, HAddPS) {
676   DriverStr(RepeatFF(&x86::X86Assembler::haddps, "haddps %{reg2}, %{reg1}"), "haddps");
677 }
678 
TEST_F(AssemblerX86Test,HAddPD)679 TEST_F(AssemblerX86Test, HAddPD) {
680   DriverStr(RepeatFF(&x86::X86Assembler::haddpd, "haddpd %{reg2}, %{reg1}"), "haddpd");
681 }
682 
TEST_F(AssemblerX86Test,PHSubW)683 TEST_F(AssemblerX86Test, PHSubW) {
684   DriverStr(RepeatFF(&x86::X86Assembler::phsubw, "phsubw %{reg2}, %{reg1}"), "phsubw");
685 }
686 
TEST_F(AssemblerX86Test,PHSubD)687 TEST_F(AssemblerX86Test, PHSubD) {
688   DriverStr(RepeatFF(&x86::X86Assembler::phsubd, "phsubd %{reg2}, %{reg1}"), "phsubd");
689 }
690 
TEST_F(AssemblerX86Test,HSubPS)691 TEST_F(AssemblerX86Test, HSubPS) {
692   DriverStr(RepeatFF(&x86::X86Assembler::hsubps, "hsubps %{reg2}, %{reg1}"), "hsubps");
693 }
694 
TEST_F(AssemblerX86Test,HSubPD)695 TEST_F(AssemblerX86Test, HSubPD) {
696   DriverStr(RepeatFF(&x86::X86Assembler::hsubpd, "hsubpd %{reg2}, %{reg1}"), "hsubpd");
697 }
698 
TEST_F(AssemblerX86Test,PMinSB)699 TEST_F(AssemblerX86Test, PMinSB) {
700   DriverStr(RepeatFF(&x86::X86Assembler::pminsb, "pminsb %{reg2}, %{reg1}"), "pminsb");
701 }
702 
TEST_F(AssemblerX86Test,PMaxSB)703 TEST_F(AssemblerX86Test, PMaxSB) {
704   DriverStr(RepeatFF(&x86::X86Assembler::pmaxsb, "pmaxsb %{reg2}, %{reg1}"), "pmaxsb");
705 }
706 
TEST_F(AssemblerX86Test,PMinSW)707 TEST_F(AssemblerX86Test, PMinSW) {
708   DriverStr(RepeatFF(&x86::X86Assembler::pminsw, "pminsw %{reg2}, %{reg1}"), "pminsw");
709 }
710 
TEST_F(AssemblerX86Test,PMaxSW)711 TEST_F(AssemblerX86Test, PMaxSW) {
712   DriverStr(RepeatFF(&x86::X86Assembler::pmaxsw, "pmaxsw %{reg2}, %{reg1}"), "pmaxsw");
713 }
714 
TEST_F(AssemblerX86Test,PMinSD)715 TEST_F(AssemblerX86Test, PMinSD) {
716   DriverStr(RepeatFF(&x86::X86Assembler::pminsd, "pminsd %{reg2}, %{reg1}"), "pminsd");
717 }
718 
TEST_F(AssemblerX86Test,PMaxSD)719 TEST_F(AssemblerX86Test, PMaxSD) {
720   DriverStr(RepeatFF(&x86::X86Assembler::pmaxsd, "pmaxsd %{reg2}, %{reg1}"), "pmaxsd");
721 }
722 
TEST_F(AssemblerX86Test,PMinUB)723 TEST_F(AssemblerX86Test, PMinUB) {
724   DriverStr(RepeatFF(&x86::X86Assembler::pminub, "pminub %{reg2}, %{reg1}"), "pminub");
725 }
726 
TEST_F(AssemblerX86Test,PMaxUB)727 TEST_F(AssemblerX86Test, PMaxUB) {
728   DriverStr(RepeatFF(&x86::X86Assembler::pmaxub, "pmaxub %{reg2}, %{reg1}"), "pmaxub");
729 }
730 
TEST_F(AssemblerX86Test,PMinUW)731 TEST_F(AssemblerX86Test, PMinUW) {
732   DriverStr(RepeatFF(&x86::X86Assembler::pminuw, "pminuw %{reg2}, %{reg1}"), "pminuw");
733 }
734 
TEST_F(AssemblerX86Test,PMaxUW)735 TEST_F(AssemblerX86Test, PMaxUW) {
736   DriverStr(RepeatFF(&x86::X86Assembler::pmaxuw, "pmaxuw %{reg2}, %{reg1}"), "pmaxuw");
737 }
738 
TEST_F(AssemblerX86Test,PMinUD)739 TEST_F(AssemblerX86Test, PMinUD) {
740   DriverStr(RepeatFF(&x86::X86Assembler::pminud, "pminud %{reg2}, %{reg1}"), "pminud");
741 }
742 
TEST_F(AssemblerX86Test,PMaxUD)743 TEST_F(AssemblerX86Test, PMaxUD) {
744   DriverStr(RepeatFF(&x86::X86Assembler::pmaxud, "pmaxud %{reg2}, %{reg1}"), "pmaxud");
745 }
746 
TEST_F(AssemblerX86Test,MinPS)747 TEST_F(AssemblerX86Test, MinPS) {
748   DriverStr(RepeatFF(&x86::X86Assembler::minps, "minps %{reg2}, %{reg1}"), "minps");
749 }
750 
TEST_F(AssemblerX86Test,MaxPS)751 TEST_F(AssemblerX86Test, MaxPS) {
752   DriverStr(RepeatFF(&x86::X86Assembler::maxps, "maxps %{reg2}, %{reg1}"), "maxps");
753 }
754 
TEST_F(AssemblerX86Test,MinPD)755 TEST_F(AssemblerX86Test, MinPD) {
756   DriverStr(RepeatFF(&x86::X86Assembler::minpd, "minpd %{reg2}, %{reg1}"), "minpd");
757 }
758 
TEST_F(AssemblerX86Test,MaxPD)759 TEST_F(AssemblerX86Test, MaxPD) {
760   DriverStr(RepeatFF(&x86::X86Assembler::maxpd, "maxpd %{reg2}, %{reg1}"), "maxpd");
761 }
762 
TEST_F(AssemblerX86Test,PCmpeqB)763 TEST_F(AssemblerX86Test, PCmpeqB) {
764   DriverStr(RepeatFF(&x86::X86Assembler::pcmpeqb, "pcmpeqb %{reg2}, %{reg1}"), "cmpeqb");
765 }
766 
TEST_F(AssemblerX86Test,PCmpeqW)767 TEST_F(AssemblerX86Test, PCmpeqW) {
768   DriverStr(RepeatFF(&x86::X86Assembler::pcmpeqw, "pcmpeqw %{reg2}, %{reg1}"), "cmpeqw");
769 }
770 
TEST_F(AssemblerX86Test,PCmpeqD)771 TEST_F(AssemblerX86Test, PCmpeqD) {
772   DriverStr(RepeatFF(&x86::X86Assembler::pcmpeqd, "pcmpeqd %{reg2}, %{reg1}"), "cmpeqd");
773 }
774 
TEST_F(AssemblerX86Test,PCmpeqQ)775 TEST_F(AssemblerX86Test, PCmpeqQ) {
776   DriverStr(RepeatFF(&x86::X86Assembler::pcmpeqq, "pcmpeqq %{reg2}, %{reg1}"), "cmpeqq");
777 }
778 
TEST_F(AssemblerX86Test,PCmpgtB)779 TEST_F(AssemblerX86Test, PCmpgtB) {
780   DriverStr(RepeatFF(&x86::X86Assembler::pcmpgtb, "pcmpgtb %{reg2}, %{reg1}"), "cmpgtb");
781 }
782 
TEST_F(AssemblerX86Test,PCmpgtW)783 TEST_F(AssemblerX86Test, PCmpgtW) {
784   DriverStr(RepeatFF(&x86::X86Assembler::pcmpgtw, "pcmpgtw %{reg2}, %{reg1}"), "cmpgtw");
785 }
786 
TEST_F(AssemblerX86Test,PCmpgtD)787 TEST_F(AssemblerX86Test, PCmpgtD) {
788   DriverStr(RepeatFF(&x86::X86Assembler::pcmpgtd, "pcmpgtd %{reg2}, %{reg1}"), "cmpgtd");
789 }
790 
TEST_F(AssemblerX86Test,PCmpgtQ)791 TEST_F(AssemblerX86Test, PCmpgtQ) {
792   DriverStr(RepeatFF(&x86::X86Assembler::pcmpgtq, "pcmpgtq %{reg2}, %{reg1}"), "cmpgtq");
793 }
794 
TEST_F(AssemblerX86Test,ShufPS)795 TEST_F(AssemblerX86Test, ShufPS) {
796   DriverStr(RepeatFFI(&x86::X86Assembler::shufps, 1, "shufps ${imm}, %{reg2}, %{reg1}"), "shufps");
797 }
798 
TEST_F(AssemblerX86Test,ShufPD)799 TEST_F(AssemblerX86Test, ShufPD) {
800   DriverStr(RepeatFFI(&x86::X86Assembler::shufpd, 1, "shufpd ${imm}, %{reg2}, %{reg1}"), "shufpd");
801 }
802 
TEST_F(AssemblerX86Test,PShufD)803 TEST_F(AssemblerX86Test, PShufD) {
804   DriverStr(RepeatFFI(&x86::X86Assembler::pshufd, 1, "pshufd ${imm}, %{reg2}, %{reg1}"), "pshufd");
805 }
806 
TEST_F(AssemblerX86Test,Punpcklbw)807 TEST_F(AssemblerX86Test, Punpcklbw) {
808   DriverStr(RepeatFF(&x86::X86Assembler::punpcklbw, "punpcklbw %{reg2}, %{reg1}"), "punpcklbw");
809 }
810 
TEST_F(AssemblerX86Test,Punpcklwd)811 TEST_F(AssemblerX86Test, Punpcklwd) {
812   DriverStr(RepeatFF(&x86::X86Assembler::punpcklwd, "punpcklwd %{reg2}, %{reg1}"), "punpcklwd");
813 }
814 
TEST_F(AssemblerX86Test,Punpckldq)815 TEST_F(AssemblerX86Test, Punpckldq) {
816   DriverStr(RepeatFF(&x86::X86Assembler::punpckldq, "punpckldq %{reg2}, %{reg1}"), "punpckldq");
817 }
818 
TEST_F(AssemblerX86Test,Punpcklqdq)819 TEST_F(AssemblerX86Test, Punpcklqdq) {
820   DriverStr(RepeatFF(&x86::X86Assembler::punpcklqdq, "punpcklqdq %{reg2}, %{reg1}"), "punpcklqdq");
821 }
822 
TEST_F(AssemblerX86Test,Punpckhbw)823 TEST_F(AssemblerX86Test, Punpckhbw) {
824   DriverStr(RepeatFF(&x86::X86Assembler::punpckhbw, "punpckhbw %{reg2}, %{reg1}"), "punpckhbw");
825 }
826 
TEST_F(AssemblerX86Test,Punpckhwd)827 TEST_F(AssemblerX86Test, Punpckhwd) {
828   DriverStr(RepeatFF(&x86::X86Assembler::punpckhwd, "punpckhwd %{reg2}, %{reg1}"), "punpckhwd");
829 }
830 
TEST_F(AssemblerX86Test,Punpckhdq)831 TEST_F(AssemblerX86Test, Punpckhdq) {
832   DriverStr(RepeatFF(&x86::X86Assembler::punpckhdq, "punpckhdq %{reg2}, %{reg1}"), "punpckhdq");
833 }
834 
TEST_F(AssemblerX86Test,Punpckhqdq)835 TEST_F(AssemblerX86Test, Punpckhqdq) {
836   DriverStr(RepeatFF(&x86::X86Assembler::punpckhqdq, "punpckhqdq %{reg2}, %{reg1}"), "punpckhqdq");
837 }
838 
TEST_F(AssemblerX86Test,psllw)839 TEST_F(AssemblerX86Test, psllw) {
840   GetAssembler()->psllw(x86::XMM0, CreateImmediate(16));
841   DriverStr("psllw $0x10, %xmm0\n", "psllwi");
842 }
843 
TEST_F(AssemblerX86Test,pslld)844 TEST_F(AssemblerX86Test, pslld) {
845   GetAssembler()->pslld(x86::XMM0, CreateImmediate(16));
846   DriverStr("pslld $0x10, %xmm0\n", "pslldi");
847 }
848 
TEST_F(AssemblerX86Test,psllq)849 TEST_F(AssemblerX86Test, psllq) {
850   GetAssembler()->psllq(x86::XMM0, CreateImmediate(16));
851   DriverStr("psllq $0x10, %xmm0\n", "psllqi");
852 }
853 
TEST_F(AssemblerX86Test,psraw)854 TEST_F(AssemblerX86Test, psraw) {
855   GetAssembler()->psraw(x86::XMM0, CreateImmediate(16));
856   DriverStr("psraw $0x10, %xmm0\n", "psrawi");
857 }
858 
TEST_F(AssemblerX86Test,psrad)859 TEST_F(AssemblerX86Test, psrad) {
860   GetAssembler()->psrad(x86::XMM0, CreateImmediate(16));
861   DriverStr("psrad $0x10, %xmm0\n", "psradi");
862 }
863 
TEST_F(AssemblerX86Test,psrlw)864 TEST_F(AssemblerX86Test, psrlw) {
865   GetAssembler()->psrlw(x86::XMM0, CreateImmediate(16));
866   DriverStr("psrlw $0x10, %xmm0\n", "psrlwi");
867 }
868 
TEST_F(AssemblerX86Test,psrld)869 TEST_F(AssemblerX86Test, psrld) {
870   GetAssembler()->psrld(x86::XMM0, CreateImmediate(16));
871   DriverStr("psrld $0x10, %xmm0\n", "psrldi");
872 }
873 
TEST_F(AssemblerX86Test,psrlq)874 TEST_F(AssemblerX86Test, psrlq) {
875   GetAssembler()->psrlq(x86::XMM0, CreateImmediate(16));
876   DriverStr("psrlq $0x10, %xmm0\n", "psrlqi");
877 }
878 
TEST_F(AssemblerX86Test,psrldq)879 TEST_F(AssemblerX86Test, psrldq) {
880   GetAssembler()->psrldq(x86::XMM0, CreateImmediate(16));
881   DriverStr("psrldq $0x10, %xmm0\n", "psrldqi");
882 }
883 
TEST_F(AssemblerX86Test,Jecxz)884 TEST_F(AssemblerX86Test, Jecxz) {
885   x86::NearLabel target;
886   GetAssembler()->jecxz(&target);
887   GetAssembler()->addl(x86::EDI, x86::Address(x86::ESP, 4));
888   GetAssembler()->Bind(&target);
889   const char* expected =
890     "jecxz 1f\n"
891     "addl 4(%ESP),%EDI\n"
892     "1:\n";
893   DriverStr(expected, "jecxz");
894 }
895 
TEST_F(AssemblerX86Test,NearLabel)896 TEST_F(AssemblerX86Test, NearLabel) {
897   // Test both forward and backward branches.
898   x86::NearLabel start, target;
899   GetAssembler()->Bind(&start);
900   GetAssembler()->j(x86::kEqual, &target);
901   GetAssembler()->jmp(&target);
902   GetAssembler()->jecxz(&target);
903   GetAssembler()->addl(x86::EDI, x86::Address(x86::ESP, 4));
904   GetAssembler()->Bind(&target);
905   GetAssembler()->j(x86::kNotEqual, &start);
906   GetAssembler()->jmp(&start);
907   const char* expected =
908     "1: je 2f\n"
909     "jmp 2f\n"
910     "jecxz 2f\n"
911     "addl 4(%ESP),%EDI\n"
912     "2: jne 1b\n"
913     "jmp 1b\n";
914   DriverStr(expected, "near_label");
915 }
916 
TEST_F(AssemblerX86Test,Cmpb)917 TEST_F(AssemblerX86Test, Cmpb) {
918   DriverStr(RepeatAI(&x86::X86Assembler::cmpb,
919                      /*imm_bytes*/ 1U,
920                      "cmpb ${imm}, {mem}"), "cmpb");
921 }
922 
TEST_F(AssemblerX86Test,Cmpw)923 TEST_F(AssemblerX86Test, Cmpw) {
924   DriverStr(RepeatAI(&x86::X86Assembler::cmpw, /*imm_bytes*/ 2U, "cmpw ${imm}, {mem}"), "cmpw");
925 }
926 
927 }  // namespace art
928