blob: c6ab893aea769f9fe69272a12d88eada8e5d0adf [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 */
Ian Rogersb033c752011-07-20 12:22:35 -070016
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070017#include "assembler_x86.h"
Jesse Wilsonc981ace2011-06-22 14:17:14 -070018
Vladimir Marko93205e32016-04-13 11:59:46 +010019#include "base/arena_allocator.h"
Roland Levillain647b9ed2014-11-27 12:06:00 +000020#include "base/stl_util.h"
21#include "utils/assembler_test.h"
Jesse Wilsonc981ace2011-06-22 14:17:14 -070022
Ian Rogersb033c752011-07-20 12:22:35 -070023namespace art {
24
25TEST(AssemblerX86, CreateBuffer) {
Vladimir Marko93205e32016-04-13 11:59:46 +010026 ArenaPool pool;
27 ArenaAllocator arena(&pool);
28 AssemblerBuffer buffer(&arena);
Ian Rogersb033c752011-07-20 12:22:35 -070029 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());
Jesse Wilsonc981ace2011-06-22 14:17:14 -070034}
Ian Rogersb033c752011-07-20 12:22:35 -070035
Roland Levillain647b9ed2014-11-27 12:06:00 +000036class AssemblerX86Test : public AssemblerTest<x86::X86Assembler, x86::Register,
37 x86::XmmRegister, x86::Immediate> {
Mark Mendellbcee0922015-09-15 21:45:01 -040038 public:
39 typedef AssemblerTest<x86::X86Assembler, x86::Register,
40 x86::XmmRegister, x86::Immediate> Base;
41
Roland Levillain647b9ed2014-11-27 12:06:00 +000042 protected:
43 std::string GetArchitectureString() OVERRIDE {
44 return "x86";
45 }
46
47 std::string GetAssemblerParameters() OVERRIDE {
48 return " --32";
49 }
50
51 std::string GetDisassembleParameters() OVERRIDE {
52 return " -D -bbinary -mi386 --no-show-raw-insn";
53 }
54
55 void SetUpHelpers() OVERRIDE {
56 if (registers_.size() == 0) {
57 registers_.insert(end(registers_),
58 { // NOLINT(whitespace/braces)
59 new x86::Register(x86::EAX),
60 new x86::Register(x86::EBX),
61 new x86::Register(x86::ECX),
62 new x86::Register(x86::EDX),
63 new x86::Register(x86::EBP),
64 new x86::Register(x86::ESP),
65 new x86::Register(x86::ESI),
66 new x86::Register(x86::EDI)
67 });
68 }
69
70 if (fp_registers_.size() == 0) {
71 fp_registers_.insert(end(fp_registers_),
72 { // NOLINT(whitespace/braces)
73 new x86::XmmRegister(x86::XMM0),
74 new x86::XmmRegister(x86::XMM1),
75 new x86::XmmRegister(x86::XMM2),
76 new x86::XmmRegister(x86::XMM3),
77 new x86::XmmRegister(x86::XMM4),
78 new x86::XmmRegister(x86::XMM5),
79 new x86::XmmRegister(x86::XMM6),
80 new x86::XmmRegister(x86::XMM7)
81 });
82 }
83 }
84
85 void TearDown() OVERRIDE {
86 AssemblerTest::TearDown();
87 STLDeleteElements(&registers_);
88 STLDeleteElements(&fp_registers_);
89 }
90
91 std::vector<x86::Register*> GetRegisters() OVERRIDE {
92 return registers_;
93 }
94
95 std::vector<x86::XmmRegister*> GetFPRegisters() OVERRIDE {
96 return fp_registers_;
97 }
98
99 x86::Immediate CreateImmediate(int64_t imm_value) OVERRIDE {
100 return x86::Immediate(imm_value);
101 }
102
103 private:
104 std::vector<x86::Register*> registers_;
105 std::vector<x86::XmmRegister*> fp_registers_;
106};
107
108
109TEST_F(AssemblerX86Test, Movl) {
110 GetAssembler()->movl(x86::EAX, x86::EBX);
111 const char* expected = "mov %ebx, %eax\n";
112 DriverStr(expected, "movl");
113}
114
Mark Mendell7a08fb52015-07-15 14:09:35 -0400115TEST_F(AssemblerX86Test, Movntl) {
116 GetAssembler()->movntl(x86::Address(x86::EDI, x86::EBX, x86::TIMES_4, 12), x86::EAX);
117 GetAssembler()->movntl(x86::Address(x86::EDI, 0), x86::EAX);
118 const char* expected =
119 "movntil %EAX, 0xc(%EDI,%EBX,4)\n"
120 "movntil %EAX, (%EDI)\n";
121
122 DriverStr(expected, "movntl");
123}
124
Calin Juravle52c48962014-12-16 17:02:57 +0000125TEST_F(AssemblerX86Test, psrlq) {
126 GetAssembler()->psrlq(x86::XMM0, CreateImmediate(32));
127 const char* expected = "psrlq $0x20, %xmm0\n";
128 DriverStr(expected, "psrlq");
129}
130
131TEST_F(AssemblerX86Test, punpckldq) {
132 GetAssembler()->punpckldq(x86::XMM0, x86::XMM1);
133 const char* expected = "punpckldq %xmm1, %xmm0\n";
134 DriverStr(expected, "punpckldq");
135}
136
Roland Levillain647b9ed2014-11-27 12:06:00 +0000137TEST_F(AssemblerX86Test, LoadLongConstant) {
138 GetAssembler()->LoadLongConstant(x86::XMM0, 51);
139 const char* expected =
140 "push $0x0\n"
141 "push $0x33\n"
142 "movsd 0(%esp), %xmm0\n"
143 "add $8, %esp\n";
144 DriverStr(expected, "LoadLongConstant");
145}
146
Mark Mendell58d25fd2015-04-03 14:52:31 -0400147TEST_F(AssemblerX86Test, LockCmpxchgl) {
148 GetAssembler()->LockCmpxchgl(x86::Address(
149 x86::Register(x86::EDI), x86::Register(x86::EBX), x86::TIMES_4, 12),
150 x86::Register(x86::ESI));
151 GetAssembler()->LockCmpxchgl(x86::Address(
152 x86::Register(x86::EDI), x86::Register(x86::ESI), x86::TIMES_4, 12),
153 x86::Register(x86::ESI));
154 GetAssembler()->LockCmpxchgl(x86::Address(
155 x86::Register(x86::EDI), x86::Register(x86::ESI), x86::TIMES_4, 12),
156 x86::Register(x86::EDI));
157 GetAssembler()->LockCmpxchgl(x86::Address(
158 x86::Register(x86::EBP), 0), x86::Register(x86::ESI));
159 GetAssembler()->LockCmpxchgl(x86::Address(
160 x86::Register(x86::EBP), x86::Register(x86::ESI), x86::TIMES_1, 0),
161 x86::Register(x86::ESI));
162 const char* expected =
163 "lock cmpxchgl %ESI, 0xc(%EDI,%EBX,4)\n"
164 "lock cmpxchgl %ESI, 0xc(%EDI,%ESI,4)\n"
165 "lock cmpxchgl %EDI, 0xc(%EDI,%ESI,4)\n"
166 "lock cmpxchgl %ESI, (%EBP)\n"
167 "lock cmpxchgl %ESI, (%EBP,%ESI,1)\n";
168
169 DriverStr(expected, "lock_cmpxchgl");
170}
171
172TEST_F(AssemblerX86Test, LockCmpxchg8b) {
173 GetAssembler()->LockCmpxchg8b(x86::Address(
174 x86::Register(x86::EDI), x86::Register(x86::EBX), x86::TIMES_4, 12));
175 GetAssembler()->LockCmpxchg8b(x86::Address(
176 x86::Register(x86::EDI), x86::Register(x86::ESI), x86::TIMES_4, 12));
177 GetAssembler()->LockCmpxchg8b(x86::Address(
178 x86::Register(x86::EDI), x86::Register(x86::ESI), x86::TIMES_4, 12));
179 GetAssembler()->LockCmpxchg8b(x86::Address(x86::Register(x86::EBP), 0));
180 GetAssembler()->LockCmpxchg8b(x86::Address(
181 x86::Register(x86::EBP), x86::Register(x86::ESI), x86::TIMES_1, 0));
182 const char* expected =
183 "lock cmpxchg8b 0xc(%EDI,%EBX,4)\n"
184 "lock cmpxchg8b 0xc(%EDI,%ESI,4)\n"
185 "lock cmpxchg8b 0xc(%EDI,%ESI,4)\n"
186 "lock cmpxchg8b (%EBP)\n"
187 "lock cmpxchg8b (%EBP,%ESI,1)\n";
188
189 DriverStr(expected, "lock_cmpxchg8b");
190}
191
Roland Levillain0a186012015-04-13 17:00:20 +0100192TEST_F(AssemblerX86Test, FPUIntegerLoad) {
193 GetAssembler()->filds(x86::Address(x86::Register(x86::ESP), 4));
194 GetAssembler()->fildl(x86::Address(x86::Register(x86::ESP), 12));
195 const char* expected =
196 "fildl 0x4(%ESP)\n"
197 "fildll 0xc(%ESP)\n";
198 DriverStr(expected, "FPUIntegerLoad");
199}
200
201TEST_F(AssemblerX86Test, FPUIntegerStore) {
202 GetAssembler()->fistps(x86::Address(x86::Register(x86::ESP), 16));
203 GetAssembler()->fistpl(x86::Address(x86::Register(x86::ESP), 24));
204 const char* expected =
205 "fistpl 0x10(%ESP)\n"
206 "fistpll 0x18(%ESP)\n";
207 DriverStr(expected, "FPUIntegerStore");
208}
209
jessicahandojob03d6402016-09-07 12:16:53 -0700210TEST_F(AssemblerX86Test, Repnescasb) {
211 GetAssembler()->repne_scasb();
212 const char* expected = "repne scasb\n";
213 DriverStr(expected, "Repnescasb");
214}
215
Andreas Gampe21030dd2015-05-07 14:46:15 -0700216TEST_F(AssemblerX86Test, Repnescasw) {
217 GetAssembler()->repne_scasw();
218 const char* expected = "repne scasw\n";
219 DriverStr(expected, "Repnescasw");
220}
221
jessicahandojob03d6402016-09-07 12:16:53 -0700222TEST_F(AssemblerX86Test, Repecmpsb) {
223 GetAssembler()->repe_cmpsb();
224 const char* expected = "repe cmpsb\n";
225 DriverStr(expected, "Repecmpsb");
226}
227
agicsaki71311f82015-07-27 11:34:13 -0700228TEST_F(AssemblerX86Test, Repecmpsw) {
229 GetAssembler()->repe_cmpsw();
230 const char* expected = "repe cmpsw\n";
231 DriverStr(expected, "Repecmpsw");
232}
233
agicsaki970abfb2015-07-31 10:31:14 -0700234TEST_F(AssemblerX86Test, Repecmpsl) {
235 GetAssembler()->repe_cmpsl();
236 const char* expected = "repe cmpsl\n";
237 DriverStr(expected, "Repecmpsl");
238}
239
jessicahandojob03d6402016-09-07 12:16:53 -0700240TEST_F(AssemblerX86Test, RepMovsb) {
241 GetAssembler()->rep_movsb();
242 const char* expected = "rep movsb\n";
243 DriverStr(expected, "rep_movsb");
Mark Mendellb9c4bbe2015-07-01 14:26:52 -0400244}
245
246TEST_F(AssemblerX86Test, RepMovsw) {
247 GetAssembler()->rep_movsw();
248 const char* expected = "rep movsw\n";
249 DriverStr(expected, "rep_movsw");
250}
251
Mark Mendellbcee0922015-09-15 21:45:01 -0400252TEST_F(AssemblerX86Test, Bsfl) {
253 DriverStr(RepeatRR(&x86::X86Assembler::bsfl, "bsfl %{reg2}, %{reg1}"), "bsfl");
254}
255
256TEST_F(AssemblerX86Test, BsflAddress) {
257 GetAssembler()->bsfl(x86::Register(x86::EDI), x86::Address(
258 x86::Register(x86::EDI), x86::Register(x86::EBX), x86::TIMES_4, 12));
259 const char* expected =
260 "bsfl 0xc(%EDI,%EBX,4), %EDI\n";
261
262 DriverStr(expected, "bsfl_address");
263}
264
Mark Mendell8ae3ffb2015-08-12 21:16:41 -0400265TEST_F(AssemblerX86Test, Bsrl) {
266 DriverStr(RepeatRR(&x86::X86Assembler::bsrl, "bsrl %{reg2}, %{reg1}"), "bsrl");
267}
268
269TEST_F(AssemblerX86Test, BsrlAddress) {
270 GetAssembler()->bsrl(x86::Register(x86::EDI), x86::Address(
271 x86::Register(x86::EDI), x86::Register(x86::EBX), x86::TIMES_4, 12));
272 const char* expected =
273 "bsrl 0xc(%EDI,%EBX,4), %EDI\n";
274
275 DriverStr(expected, "bsrl_address");
276}
277
Aart Bikc39dac12016-01-21 08:59:48 -0800278TEST_F(AssemblerX86Test, Popcntl) {
279 DriverStr(RepeatRR(&x86::X86Assembler::popcntl, "popcntl %{reg2}, %{reg1}"), "popcntl");
280}
281
282TEST_F(AssemblerX86Test, PopcntlAddress) {
283 GetAssembler()->popcntl(x86::Register(x86::EDI), x86::Address(
284 x86::Register(x86::EDI), x86::Register(x86::EBX), x86::TIMES_4, 12));
285 const char* expected =
286 "popcntl 0xc(%EDI,%EBX,4), %EDI\n";
287
288 DriverStr(expected, "popcntl_address");
289}
290
Mark Mendellbcee0922015-09-15 21:45:01 -0400291// Rorl only allows CL as the shift count.
292std::string rorl_fn(AssemblerX86Test::Base* assembler_test, x86::X86Assembler* assembler) {
293 std::ostringstream str;
294
295 std::vector<x86::Register*> registers = assembler_test->GetRegisters();
296
297 x86::Register shifter(x86::ECX);
298 for (auto reg : registers) {
299 assembler->rorl(*reg, shifter);
300 str << "rorl %cl, %" << assembler_test->GetRegisterName(*reg) << "\n";
301 }
302
303 return str.str();
304}
305
306TEST_F(AssemblerX86Test, RorlReg) {
307 DriverFn(&rorl_fn, "rorl");
308}
309
310TEST_F(AssemblerX86Test, RorlImm) {
311 DriverStr(RepeatRI(&x86::X86Assembler::rorl, 1U, "rorl ${imm}, %{reg}"), "rorli");
312}
313
314// Roll only allows CL as the shift count.
315std::string roll_fn(AssemblerX86Test::Base* assembler_test, x86::X86Assembler* assembler) {
316 std::ostringstream str;
317
318 std::vector<x86::Register*> registers = assembler_test->GetRegisters();
319
320 x86::Register shifter(x86::ECX);
321 for (auto reg : registers) {
322 assembler->roll(*reg, shifter);
323 str << "roll %cl, %" << assembler_test->GetRegisterName(*reg) << "\n";
324 }
325
326 return str.str();
327}
328
329TEST_F(AssemblerX86Test, RollReg) {
330 DriverFn(&roll_fn, "roll");
331}
332
333TEST_F(AssemblerX86Test, RollImm) {
334 DriverStr(RepeatRI(&x86::X86Assembler::roll, 1U, "roll ${imm}, %{reg}"), "rolli");
335}
336
Aart Bik18ba1212016-08-01 14:11:20 -0700337TEST_F(AssemblerX86Test, ComissAddr) {
338 GetAssembler()->comiss(x86::XmmRegister(x86::XMM0), x86::Address(x86::EAX, 0));
339 const char* expected = "comiss 0(%EAX), %xmm0\n";
340 DriverStr(expected, "comiss");
341}
342
Mark Mendell9f51f262015-10-30 09:21:37 -0400343TEST_F(AssemblerX86Test, UComissAddr) {
344 GetAssembler()->ucomiss(x86::XmmRegister(x86::XMM0), x86::Address(x86::EAX, 0));
345 const char* expected = "ucomiss 0(%EAX), %xmm0\n";
346 DriverStr(expected, "ucomiss");
347}
348
Aart Bik18ba1212016-08-01 14:11:20 -0700349TEST_F(AssemblerX86Test, ComisdAddr) {
350 GetAssembler()->comisd(x86::XmmRegister(x86::XMM0), x86::Address(x86::EAX, 0));
351 const char* expected = "comisd 0(%EAX), %xmm0\n";
352 DriverStr(expected, "comisd");
353}
354
Mark Mendell9f51f262015-10-30 09:21:37 -0400355TEST_F(AssemblerX86Test, UComisdAddr) {
356 GetAssembler()->ucomisd(x86::XmmRegister(x86::XMM0), x86::Address(x86::EAX, 0));
357 const char* expected = "ucomisd 0(%EAX), %xmm0\n";
358 DriverStr(expected, "ucomisd");
359}
360
Aart Bik33dd9092016-08-01 15:55:36 -0700361TEST_F(AssemblerX86Test, RoundSS) {
362 GetAssembler()->roundss(
363 x86::XmmRegister(x86::XMM0), x86::XmmRegister(x86::XMM1), x86::Immediate(1));
364 const char* expected = "roundss $1, %xmm1, %xmm0\n";
365 DriverStr(expected, "roundss");
366}
367
368TEST_F(AssemblerX86Test, RoundSD) {
369 GetAssembler()->roundsd(
370 x86::XmmRegister(x86::XMM0), x86::XmmRegister(x86::XMM1), x86::Immediate(1));
371 const char* expected = "roundsd $1, %xmm1, %xmm0\n";
372 DriverStr(expected, "roundsd");
373}
Mark Mendell9f51f262015-10-30 09:21:37 -0400374
Mark Mendellabdac472016-02-12 13:49:03 -0500375TEST_F(AssemblerX86Test, CmovlAddress) {
376 GetAssembler()->cmovl(x86::kEqual, x86::Register(x86::EAX), x86::Address(
377 x86::Register(x86::EDI), x86::Register(x86::EBX), x86::TIMES_4, 12));
378 GetAssembler()->cmovl(x86::kNotEqual, x86::Register(x86::EDI), x86::Address(
379 x86::Register(x86::ESI), x86::Register(x86::EBX), x86::TIMES_4, 12));
380 GetAssembler()->cmovl(x86::kEqual, x86::Register(x86::EDI), x86::Address(
381 x86::Register(x86::EDI), x86::Register(x86::EAX), x86::TIMES_4, 12));
382 const char* expected =
383 "cmovzl 0xc(%EDI,%EBX,4), %eax\n"
384 "cmovnzl 0xc(%ESI,%EBX,4), %edi\n"
385 "cmovzl 0xc(%EDI,%EAX,4), %edi\n";
386
387 DriverStr(expected, "cmovl_address");
388}
389
Vladimir Marko953437b2016-08-24 08:30:46 +0000390TEST_F(AssemblerX86Test, TestbAddressImmediate) {
391 GetAssembler()->testb(
392 x86::Address(x86::Register(x86::EDI), x86::Register(x86::EBX), x86::TIMES_4, 12),
393 x86::Immediate(1));
394 GetAssembler()->testb(
395 x86::Address(x86::Register(x86::ESP), FrameOffset(7)),
396 x86::Immediate(-128));
397 GetAssembler()->testb(
398 x86::Address(x86::Register(x86::EBX), MemberOffset(130)),
399 x86::Immediate(127));
400 const char* expected =
401 "testb $1, 0xc(%EDI,%EBX,4)\n"
402 "testb $-128, 0x7(%ESP)\n"
403 "testb $127, 0x82(%EBX)\n";
404
405 DriverStr(expected, "TestbAddressImmediate");
406}
407
408TEST_F(AssemblerX86Test, TestlAddressImmediate) {
409 GetAssembler()->testl(
410 x86::Address(x86::Register(x86::EDI), x86::Register(x86::EBX), x86::TIMES_4, 12),
411 x86::Immediate(1));
412 GetAssembler()->testl(
413 x86::Address(x86::Register(x86::ESP), FrameOffset(7)),
414 x86::Immediate(-100000));
415 GetAssembler()->testl(
416 x86::Address(x86::Register(x86::EBX), MemberOffset(130)),
417 x86::Immediate(77777777));
418 const char* expected =
419 "testl $1, 0xc(%EDI,%EBX,4)\n"
420 "testl $-100000, 0x7(%ESP)\n"
421 "testl $77777777, 0x82(%EBX)\n";
422
423 DriverStr(expected, "TestlAddressImmediate");
424}
425
Aart Bikc7782262017-01-13 16:20:08 -0800426TEST_F(AssemblerX86Test, Movaps) {
427 DriverStr(RepeatFF(&x86::X86Assembler::movaps, "movaps %{reg2}, %{reg1}"), "movaps");
428}
429
430TEST_F(AssemblerX86Test, MovapsAddr) {
431 GetAssembler()->movaps(x86::XmmRegister(x86::XMM0), x86::Address(x86::Register(x86::ESP), 4));
432 GetAssembler()->movaps(x86::Address(x86::Register(x86::ESP), 2), x86::XmmRegister(x86::XMM1));
433 const char* expected =
434 "movaps 0x4(%ESP), %xmm0\n"
435 "movaps %xmm1, 0x2(%ESP)\n";
436 DriverStr(expected, "movaps_address");
437}
438
439TEST_F(AssemblerX86Test, MovupsAddr) {
440 GetAssembler()->movups(x86::XmmRegister(x86::XMM0), x86::Address(x86::Register(x86::ESP), 4));
441 GetAssembler()->movups(x86::Address(x86::Register(x86::ESP), 2), x86::XmmRegister(x86::XMM1));
442 const char* expected =
443 "movups 0x4(%ESP), %xmm0\n"
444 "movups %xmm1, 0x2(%ESP)\n";
445 DriverStr(expected, "movups_address");
446}
447
448TEST_F(AssemblerX86Test, Movapd) {
449 DriverStr(RepeatFF(&x86::X86Assembler::movapd, "movapd %{reg2}, %{reg1}"), "movapd");
450}
451
452TEST_F(AssemblerX86Test, MovapdAddr) {
453 GetAssembler()->movapd(x86::XmmRegister(x86::XMM0), x86::Address(x86::Register(x86::ESP), 4));
454 GetAssembler()->movapd(x86::Address(x86::Register(x86::ESP), 2), x86::XmmRegister(x86::XMM1));
455 const char* expected =
456 "movapd 0x4(%ESP), %xmm0\n"
457 "movapd %xmm1, 0x2(%ESP)\n";
458 DriverStr(expected, "movapd_address");
459}
460
461TEST_F(AssemblerX86Test, MovupdAddr) {
462 GetAssembler()->movupd(x86::XmmRegister(x86::XMM0), x86::Address(x86::Register(x86::ESP), 4));
463 GetAssembler()->movupd(x86::Address(x86::Register(x86::ESP), 2), x86::XmmRegister(x86::XMM1));
464 const char* expected =
465 "movupd 0x4(%ESP), %xmm0\n"
466 "movupd %xmm1, 0x2(%ESP)\n";
467 DriverStr(expected, "movupd_address");
468}
469
Aart Bik68555e92017-02-13 14:28:45 -0800470TEST_F(AssemblerX86Test, Movdqa) {
471 DriverStr(RepeatFF(&x86::X86Assembler::movdqa, "movdqa %{reg2}, %{reg1}"), "movdqa");
472}
473
474TEST_F(AssemblerX86Test, MovdqaAddr) {
475 GetAssembler()->movdqa(x86::XmmRegister(x86::XMM0), x86::Address(x86::Register(x86::ESP), 4));
476 GetAssembler()->movdqa(x86::Address(x86::Register(x86::ESP), 2), x86::XmmRegister(x86::XMM1));
477 const char* expected =
478 "movdqa 0x4(%ESP), %xmm0\n"
479 "movdqa %xmm1, 0x2(%ESP)\n";
480 DriverStr(expected, "movdqa_address");
481}
482
483TEST_F(AssemblerX86Test, MovdquAddr) {
484 GetAssembler()->movdqu(x86::XmmRegister(x86::XMM0), x86::Address(x86::Register(x86::ESP), 4));
485 GetAssembler()->movdqu(x86::Address(x86::Register(x86::ESP), 2), x86::XmmRegister(x86::XMM1));
486 const char* expected =
487 "movdqu 0x4(%ESP), %xmm0\n"
488 "movdqu %xmm1, 0x2(%ESP)\n";
489 DriverStr(expected, "movdqu_address");
490}
491
Aart Bikc7782262017-01-13 16:20:08 -0800492TEST_F(AssemblerX86Test, AddPS) {
Aart Bik12e06ed2017-01-31 16:11:24 -0800493 DriverStr(RepeatFF(&x86::X86Assembler::addps, "addps %{reg2}, %{reg1}"), "addps");
Aart Bikc7782262017-01-13 16:20:08 -0800494}
495
496TEST_F(AssemblerX86Test, AddPD) {
Aart Bik12e06ed2017-01-31 16:11:24 -0800497 DriverStr(RepeatFF(&x86::X86Assembler::addpd, "addpd %{reg2}, %{reg1}"), "addpd");
Aart Bikc7782262017-01-13 16:20:08 -0800498}
499
500TEST_F(AssemblerX86Test, SubPS) {
Aart Bik12e06ed2017-01-31 16:11:24 -0800501 DriverStr(RepeatFF(&x86::X86Assembler::subps, "subps %{reg2}, %{reg1}"), "subps");
Aart Bikc7782262017-01-13 16:20:08 -0800502}
503
504TEST_F(AssemblerX86Test, SubPD) {
Aart Bik12e06ed2017-01-31 16:11:24 -0800505 DriverStr(RepeatFF(&x86::X86Assembler::subpd, "subpd %{reg2}, %{reg1}"), "subpd");
Aart Bikc7782262017-01-13 16:20:08 -0800506}
507
508TEST_F(AssemblerX86Test, MulPS) {
Aart Bik12e06ed2017-01-31 16:11:24 -0800509 DriverStr(RepeatFF(&x86::X86Assembler::mulps, "mulps %{reg2}, %{reg1}"), "mulps");
Aart Bikc7782262017-01-13 16:20:08 -0800510}
511
512TEST_F(AssemblerX86Test, MulPD) {
Aart Bik12e06ed2017-01-31 16:11:24 -0800513 DriverStr(RepeatFF(&x86::X86Assembler::mulpd, "mulpd %{reg2}, %{reg1}"), "mulpd");
Aart Bikc7782262017-01-13 16:20:08 -0800514}
515
516TEST_F(AssemblerX86Test, DivPS) {
Aart Bik12e06ed2017-01-31 16:11:24 -0800517 DriverStr(RepeatFF(&x86::X86Assembler::divps, "divps %{reg2}, %{reg1}"), "divps");
Aart Bikc7782262017-01-13 16:20:08 -0800518}
519
520TEST_F(AssemblerX86Test, DivPD) {
Aart Bik12e06ed2017-01-31 16:11:24 -0800521 DriverStr(RepeatFF(&x86::X86Assembler::divpd, "divpd %{reg2}, %{reg1}"), "divpd");
522}
523
Aart Bik68555e92017-02-13 14:28:45 -0800524TEST_F(AssemblerX86Test, PAddD) {
525 DriverStr(RepeatFF(&x86::X86Assembler::paddd, "paddd %{reg2}, %{reg1}"), "paddd");
526}
527
528TEST_F(AssemblerX86Test, PSubD) {
529 DriverStr(RepeatFF(&x86::X86Assembler::psubd, "psubd %{reg2}, %{reg1}"), "psubd");
530}
531
532TEST_F(AssemblerX86Test, PMullD) {
533 DriverStr(RepeatFF(&x86::X86Assembler::pmulld, "pmulld %{reg2}, %{reg1}"), "pmulld");
534}
535
536TEST_F(AssemblerX86Test, XorPD) {
537 DriverStr(RepeatFF(&x86::X86Assembler::xorpd, "xorpd %{reg2}, %{reg1}"), "xorpd");
538}
539
540TEST_F(AssemblerX86Test, XorPS) {
541 DriverStr(RepeatFF(&x86::X86Assembler::xorps, "xorps %{reg2}, %{reg1}"), "xorps");
542}
543
544TEST_F(AssemblerX86Test, PXor) {
545 DriverStr(RepeatFF(&x86::X86Assembler::pxor, "pxor %{reg2}, %{reg1}"), "pxor");
546}
547
548TEST_F(AssemblerX86Test, AndPD) {
549 DriverStr(RepeatFF(&x86::X86Assembler::andpd, "andpd %{reg2}, %{reg1}"), "andpd");
550}
551
552TEST_F(AssemblerX86Test, AndPS) {
553 DriverStr(RepeatFF(&x86::X86Assembler::andps, "andps %{reg2}, %{reg1}"), "andps");
554}
555
556TEST_F(AssemblerX86Test, PAnd) {
557 DriverStr(RepeatFF(&x86::X86Assembler::pand, "pand %{reg2}, %{reg1}"), "pand");
558}
559
560TEST_F(AssemblerX86Test, OrPD) {
561 DriverStr(RepeatFF(&x86::X86Assembler::orpd, "orpd %{reg2}, %{reg1}"), "orpd");
562}
563
564TEST_F(AssemblerX86Test, OrPS) {
565 DriverStr(RepeatFF(&x86::X86Assembler::orps, "orps %{reg2}, %{reg1}"), "orps");
566}
567
568TEST_F(AssemblerX86Test, POr) {
569 DriverStr(RepeatFF(&x86::X86Assembler::por, "por %{reg2}, %{reg1}"), "por");
570}
571
Aart Bik12e06ed2017-01-31 16:11:24 -0800572TEST_F(AssemblerX86Test, ShufPS) {
573 DriverStr(RepeatFFI(&x86::X86Assembler::shufps, 1, "shufps ${imm}, %{reg2}, %{reg1}"), "shufps");
574}
575
576TEST_F(AssemblerX86Test, ShufPD) {
577 DriverStr(RepeatFFI(&x86::X86Assembler::shufpd, 1, "shufpd ${imm}, %{reg2}, %{reg1}"), "shufpd");
Aart Bikc7782262017-01-13 16:20:08 -0800578}
579
Aart Bik68555e92017-02-13 14:28:45 -0800580TEST_F(AssemblerX86Test, PShufD) {
581 DriverStr(RepeatFFI(&x86::X86Assembler::pshufd, 1, "pshufd ${imm}, %{reg2}, %{reg1}"), "pshufd");
582}
583
Mark Mendell73f455e2015-08-21 09:30:05 -0400584/////////////////
585// Near labels //
586/////////////////
587
588TEST_F(AssemblerX86Test, Jecxz) {
589 x86::NearLabel target;
590 GetAssembler()->jecxz(&target);
591 GetAssembler()->addl(x86::EDI, x86::Address(x86::ESP, 4));
592 GetAssembler()->Bind(&target);
593 const char* expected =
594 "jecxz 1f\n"
595 "addl 4(%ESP),%EDI\n"
596 "1:\n";
597
598 DriverStr(expected, "jecxz");
599}
600
601TEST_F(AssemblerX86Test, NearLabel) {
602 // Test both forward and backward branches.
603 x86::NearLabel start, target;
604 GetAssembler()->Bind(&start);
605 GetAssembler()->j(x86::kEqual, &target);
606 GetAssembler()->jmp(&target);
607 GetAssembler()->jecxz(&target);
608 GetAssembler()->addl(x86::EDI, x86::Address(x86::ESP, 4));
609 GetAssembler()->Bind(&target);
610 GetAssembler()->j(x86::kNotEqual, &start);
611 GetAssembler()->jmp(&start);
612 const char* expected =
613 "1: je 2f\n"
614 "jmp 2f\n"
615 "jecxz 2f\n"
616 "addl 4(%ESP),%EDI\n"
617 "2: jne 1b\n"
618 "jmp 1b\n";
619
620 DriverStr(expected, "near_label");
621}
622
Serguei Katkov3b625932016-05-06 10:24:17 +0600623TEST_F(AssemblerX86Test, Cmpb) {
624 GetAssembler()->cmpb(x86::Address(x86::EDI, 128), x86::Immediate(0));
625 const char* expected = "cmpb $0, 128(%EDI)\n";
626 DriverStr(expected, "cmpb");
627}
628
Ian Rogersb033c752011-07-20 12:22:35 -0700629} // namespace art