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