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 23namespace art { 24 25TEST(AssemblerX86, CreateBuffer) { 26 ArenaPool pool; 27 ArenaAllocator arena(&pool); 28 AssemblerBuffer buffer(&arena); 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 36class AssemblerX86Test : public AssemblerTest<x86::X86Assembler, x86::Register, 37 x86::XmmRegister, x86::Immediate> { 38 public: 39 typedef AssemblerTest<x86::X86Assembler, x86::Register, 40 x86::XmmRegister, x86::Immediate> Base; 41 42 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(®isters_); 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 115TEST_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 125TEST_F(AssemblerX86Test, LoadLongConstant) { 126 GetAssembler()->LoadLongConstant(x86::XMM0, 51); 127 const char* expected = 128 "push $0x0\n" 129 "push $0x33\n" 130 "movsd 0(%esp), %xmm0\n" 131 "add $8, %esp\n"; 132 DriverStr(expected, "LoadLongConstant"); 133} 134 135TEST_F(AssemblerX86Test, LockCmpxchgl) { 136 GetAssembler()->LockCmpxchgl(x86::Address( 137 x86::Register(x86::EDI), x86::Register(x86::EBX), x86::TIMES_4, 12), 138 x86::Register(x86::ESI)); 139 GetAssembler()->LockCmpxchgl(x86::Address( 140 x86::Register(x86::EDI), x86::Register(x86::ESI), x86::TIMES_4, 12), 141 x86::Register(x86::ESI)); 142 GetAssembler()->LockCmpxchgl(x86::Address( 143 x86::Register(x86::EDI), x86::Register(x86::ESI), x86::TIMES_4, 12), 144 x86::Register(x86::EDI)); 145 GetAssembler()->LockCmpxchgl(x86::Address( 146 x86::Register(x86::EBP), 0), x86::Register(x86::ESI)); 147 GetAssembler()->LockCmpxchgl(x86::Address( 148 x86::Register(x86::EBP), x86::Register(x86::ESI), x86::TIMES_1, 0), 149 x86::Register(x86::ESI)); 150 const char* expected = 151 "lock cmpxchgl %ESI, 0xc(%EDI,%EBX,4)\n" 152 "lock cmpxchgl %ESI, 0xc(%EDI,%ESI,4)\n" 153 "lock cmpxchgl %EDI, 0xc(%EDI,%ESI,4)\n" 154 "lock cmpxchgl %ESI, (%EBP)\n" 155 "lock cmpxchgl %ESI, (%EBP,%ESI,1)\n"; 156 157 DriverStr(expected, "lock_cmpxchgl"); 158} 159 160TEST_F(AssemblerX86Test, LockCmpxchg8b) { 161 GetAssembler()->LockCmpxchg8b(x86::Address( 162 x86::Register(x86::EDI), x86::Register(x86::EBX), x86::TIMES_4, 12)); 163 GetAssembler()->LockCmpxchg8b(x86::Address( 164 x86::Register(x86::EDI), x86::Register(x86::ESI), x86::TIMES_4, 12)); 165 GetAssembler()->LockCmpxchg8b(x86::Address( 166 x86::Register(x86::EDI), x86::Register(x86::ESI), x86::TIMES_4, 12)); 167 GetAssembler()->LockCmpxchg8b(x86::Address(x86::Register(x86::EBP), 0)); 168 GetAssembler()->LockCmpxchg8b(x86::Address( 169 x86::Register(x86::EBP), x86::Register(x86::ESI), x86::TIMES_1, 0)); 170 const char* expected = 171 "lock cmpxchg8b 0xc(%EDI,%EBX,4)\n" 172 "lock cmpxchg8b 0xc(%EDI,%ESI,4)\n" 173 "lock cmpxchg8b 0xc(%EDI,%ESI,4)\n" 174 "lock cmpxchg8b (%EBP)\n" 175 "lock cmpxchg8b (%EBP,%ESI,1)\n"; 176 177 DriverStr(expected, "lock_cmpxchg8b"); 178} 179 180TEST_F(AssemblerX86Test, FPUIntegerLoad) { 181 GetAssembler()->filds(x86::Address(x86::Register(x86::ESP), 4)); 182 GetAssembler()->fildl(x86::Address(x86::Register(x86::ESP), 12)); 183 const char* expected = 184 "fildl 0x4(%ESP)\n" 185 "fildll 0xc(%ESP)\n"; 186 DriverStr(expected, "FPUIntegerLoad"); 187} 188 189TEST_F(AssemblerX86Test, FPUIntegerStore) { 190 GetAssembler()->fistps(x86::Address(x86::Register(x86::ESP), 16)); 191 GetAssembler()->fistpl(x86::Address(x86::Register(x86::ESP), 24)); 192 const char* expected = 193 "fistpl 0x10(%ESP)\n" 194 "fistpll 0x18(%ESP)\n"; 195 DriverStr(expected, "FPUIntegerStore"); 196} 197 198TEST_F(AssemblerX86Test, Repnescasb) { 199 GetAssembler()->repne_scasb(); 200 const char* expected = "repne scasb\n"; 201 DriverStr(expected, "Repnescasb"); 202} 203 204TEST_F(AssemblerX86Test, Repnescasw) { 205 GetAssembler()->repne_scasw(); 206 const char* expected = "repne scasw\n"; 207 DriverStr(expected, "Repnescasw"); 208} 209 210TEST_F(AssemblerX86Test, Repecmpsb) { 211 GetAssembler()->repe_cmpsb(); 212 const char* expected = "repe cmpsb\n"; 213 DriverStr(expected, "Repecmpsb"); 214} 215 216TEST_F(AssemblerX86Test, Repecmpsw) { 217 GetAssembler()->repe_cmpsw(); 218 const char* expected = "repe cmpsw\n"; 219 DriverStr(expected, "Repecmpsw"); 220} 221 222TEST_F(AssemblerX86Test, Repecmpsl) { 223 GetAssembler()->repe_cmpsl(); 224 const char* expected = "repe cmpsl\n"; 225 DriverStr(expected, "Repecmpsl"); 226} 227 228TEST_F(AssemblerX86Test, RepMovsb) { 229 GetAssembler()->rep_movsb(); 230 const char* expected = "rep movsb\n"; 231 DriverStr(expected, "rep_movsb"); 232} 233 234TEST_F(AssemblerX86Test, RepMovsw) { 235 GetAssembler()->rep_movsw(); 236 const char* expected = "rep movsw\n"; 237 DriverStr(expected, "rep_movsw"); 238} 239 240TEST_F(AssemblerX86Test, Bsfl) { 241 DriverStr(RepeatRR(&x86::X86Assembler::bsfl, "bsfl %{reg2}, %{reg1}"), "bsfl"); 242} 243 244TEST_F(AssemblerX86Test, BsflAddress) { 245 GetAssembler()->bsfl(x86::Register(x86::EDI), x86::Address( 246 x86::Register(x86::EDI), x86::Register(x86::EBX), x86::TIMES_4, 12)); 247 const char* expected = 248 "bsfl 0xc(%EDI,%EBX,4), %EDI\n"; 249 250 DriverStr(expected, "bsfl_address"); 251} 252 253TEST_F(AssemblerX86Test, Bsrl) { 254 DriverStr(RepeatRR(&x86::X86Assembler::bsrl, "bsrl %{reg2}, %{reg1}"), "bsrl"); 255} 256 257TEST_F(AssemblerX86Test, BsrlAddress) { 258 GetAssembler()->bsrl(x86::Register(x86::EDI), x86::Address( 259 x86::Register(x86::EDI), x86::Register(x86::EBX), x86::TIMES_4, 12)); 260 const char* expected = 261 "bsrl 0xc(%EDI,%EBX,4), %EDI\n"; 262 263 DriverStr(expected, "bsrl_address"); 264} 265 266TEST_F(AssemblerX86Test, Popcntl) { 267 DriverStr(RepeatRR(&x86::X86Assembler::popcntl, "popcntl %{reg2}, %{reg1}"), "popcntl"); 268} 269 270TEST_F(AssemblerX86Test, PopcntlAddress) { 271 GetAssembler()->popcntl(x86::Register(x86::EDI), x86::Address( 272 x86::Register(x86::EDI), x86::Register(x86::EBX), x86::TIMES_4, 12)); 273 const char* expected = 274 "popcntl 0xc(%EDI,%EBX,4), %EDI\n"; 275 276 DriverStr(expected, "popcntl_address"); 277} 278 279// Rorl only allows CL as the shift count. 280std::string rorl_fn(AssemblerX86Test::Base* assembler_test, x86::X86Assembler* assembler) { 281 std::ostringstream str; 282 283 std::vector<x86::Register*> registers = assembler_test->GetRegisters(); 284 285 x86::Register shifter(x86::ECX); 286 for (auto reg : registers) { 287 assembler->rorl(*reg, shifter); 288 str << "rorl %cl, %" << assembler_test->GetRegisterName(*reg) << "\n"; 289 } 290 291 return str.str(); 292} 293 294TEST_F(AssemblerX86Test, RorlReg) { 295 DriverFn(&rorl_fn, "rorl"); 296} 297 298TEST_F(AssemblerX86Test, RorlImm) { 299 DriverStr(RepeatRI(&x86::X86Assembler::rorl, 1U, "rorl ${imm}, %{reg}"), "rorli"); 300} 301 302// Roll only allows CL as the shift count. 303std::string roll_fn(AssemblerX86Test::Base* assembler_test, x86::X86Assembler* assembler) { 304 std::ostringstream str; 305 306 std::vector<x86::Register*> registers = assembler_test->GetRegisters(); 307 308 x86::Register shifter(x86::ECX); 309 for (auto reg : registers) { 310 assembler->roll(*reg, shifter); 311 str << "roll %cl, %" << assembler_test->GetRegisterName(*reg) << "\n"; 312 } 313 314 return str.str(); 315} 316 317TEST_F(AssemblerX86Test, RollReg) { 318 DriverFn(&roll_fn, "roll"); 319} 320 321TEST_F(AssemblerX86Test, RollImm) { 322 DriverStr(RepeatRI(&x86::X86Assembler::roll, 1U, "roll ${imm}, %{reg}"), "rolli"); 323} 324 325TEST_F(AssemblerX86Test, Cvtdq2ps) { 326 DriverStr(RepeatFF(&x86::X86Assembler::cvtdq2ps, "cvtdq2ps %{reg2}, %{reg1}"), "cvtdq2ps"); 327} 328 329TEST_F(AssemblerX86Test, Cvtdq2pd) { 330 DriverStr(RepeatFF(&x86::X86Assembler::cvtdq2pd, "cvtdq2pd %{reg2}, %{reg1}"), "cvtdq2pd"); 331} 332 333TEST_F(AssemblerX86Test, ComissAddr) { 334 GetAssembler()->comiss(x86::XmmRegister(x86::XMM0), x86::Address(x86::EAX, 0)); 335 const char* expected = "comiss 0(%EAX), %xmm0\n"; 336 DriverStr(expected, "comiss"); 337} 338 339TEST_F(AssemblerX86Test, UComissAddr) { 340 GetAssembler()->ucomiss(x86::XmmRegister(x86::XMM0), x86::Address(x86::EAX, 0)); 341 const char* expected = "ucomiss 0(%EAX), %xmm0\n"; 342 DriverStr(expected, "ucomiss"); 343} 344 345TEST_F(AssemblerX86Test, ComisdAddr) { 346 GetAssembler()->comisd(x86::XmmRegister(x86::XMM0), x86::Address(x86::EAX, 0)); 347 const char* expected = "comisd 0(%EAX), %xmm0\n"; 348 DriverStr(expected, "comisd"); 349} 350 351TEST_F(AssemblerX86Test, UComisdAddr) { 352 GetAssembler()->ucomisd(x86::XmmRegister(x86::XMM0), x86::Address(x86::EAX, 0)); 353 const char* expected = "ucomisd 0(%EAX), %xmm0\n"; 354 DriverStr(expected, "ucomisd"); 355} 356 357TEST_F(AssemblerX86Test, RoundSS) { 358 GetAssembler()->roundss( 359 x86::XmmRegister(x86::XMM0), x86::XmmRegister(x86::XMM1), x86::Immediate(1)); 360 const char* expected = "roundss $1, %xmm1, %xmm0\n"; 361 DriverStr(expected, "roundss"); 362} 363 364TEST_F(AssemblerX86Test, RoundSD) { 365 GetAssembler()->roundsd( 366 x86::XmmRegister(x86::XMM0), x86::XmmRegister(x86::XMM1), x86::Immediate(1)); 367 const char* expected = "roundsd $1, %xmm1, %xmm0\n"; 368 DriverStr(expected, "roundsd"); 369} 370 371TEST_F(AssemblerX86Test, CmovlAddress) { 372 GetAssembler()->cmovl(x86::kEqual, x86::Register(x86::EAX), x86::Address( 373 x86::Register(x86::EDI), x86::Register(x86::EBX), x86::TIMES_4, 12)); 374 GetAssembler()->cmovl(x86::kNotEqual, x86::Register(x86::EDI), x86::Address( 375 x86::Register(x86::ESI), x86::Register(x86::EBX), x86::TIMES_4, 12)); 376 GetAssembler()->cmovl(x86::kEqual, x86::Register(x86::EDI), x86::Address( 377 x86::Register(x86::EDI), x86::Register(x86::EAX), x86::TIMES_4, 12)); 378 const char* expected = 379 "cmovzl 0xc(%EDI,%EBX,4), %eax\n" 380 "cmovnzl 0xc(%ESI,%EBX,4), %edi\n" 381 "cmovzl 0xc(%EDI,%EAX,4), %edi\n"; 382 383 DriverStr(expected, "cmovl_address"); 384} 385 386TEST_F(AssemblerX86Test, TestbAddressImmediate) { 387 GetAssembler()->testb( 388 x86::Address(x86::Register(x86::EDI), x86::Register(x86::EBX), x86::TIMES_4, 12), 389 x86::Immediate(1)); 390 GetAssembler()->testb( 391 x86::Address(x86::Register(x86::ESP), FrameOffset(7)), 392 x86::Immediate(-128)); 393 GetAssembler()->testb( 394 x86::Address(x86::Register(x86::EBX), MemberOffset(130)), 395 x86::Immediate(127)); 396 const char* expected = 397 "testb $1, 0xc(%EDI,%EBX,4)\n" 398 "testb $-128, 0x7(%ESP)\n" 399 "testb $127, 0x82(%EBX)\n"; 400 401 DriverStr(expected, "TestbAddressImmediate"); 402} 403 404TEST_F(AssemblerX86Test, TestlAddressImmediate) { 405 GetAssembler()->testl( 406 x86::Address(x86::Register(x86::EDI), x86::Register(x86::EBX), x86::TIMES_4, 12), 407 x86::Immediate(1)); 408 GetAssembler()->testl( 409 x86::Address(x86::Register(x86::ESP), FrameOffset(7)), 410 x86::Immediate(-100000)); 411 GetAssembler()->testl( 412 x86::Address(x86::Register(x86::EBX), MemberOffset(130)), 413 x86::Immediate(77777777)); 414 const char* expected = 415 "testl $1, 0xc(%EDI,%EBX,4)\n" 416 "testl $-100000, 0x7(%ESP)\n" 417 "testl $77777777, 0x82(%EBX)\n"; 418 419 DriverStr(expected, "TestlAddressImmediate"); 420} 421 422TEST_F(AssemblerX86Test, Movaps) { 423 DriverStr(RepeatFF(&x86::X86Assembler::movaps, "movaps %{reg2}, %{reg1}"), "movaps"); 424} 425 426TEST_F(AssemblerX86Test, MovapsAddr) { 427 GetAssembler()->movaps(x86::XmmRegister(x86::XMM0), x86::Address(x86::Register(x86::ESP), 4)); 428 GetAssembler()->movaps(x86::Address(x86::Register(x86::ESP), 2), x86::XmmRegister(x86::XMM1)); 429 const char* expected = 430 "movaps 0x4(%ESP), %xmm0\n" 431 "movaps %xmm1, 0x2(%ESP)\n"; 432 DriverStr(expected, "movaps_address"); 433} 434 435TEST_F(AssemblerX86Test, MovupsAddr) { 436 GetAssembler()->movups(x86::XmmRegister(x86::XMM0), x86::Address(x86::Register(x86::ESP), 4)); 437 GetAssembler()->movups(x86::Address(x86::Register(x86::ESP), 2), x86::XmmRegister(x86::XMM1)); 438 const char* expected = 439 "movups 0x4(%ESP), %xmm0\n" 440 "movups %xmm1, 0x2(%ESP)\n"; 441 DriverStr(expected, "movups_address"); 442} 443 444TEST_F(AssemblerX86Test, Movapd) { 445 DriverStr(RepeatFF(&x86::X86Assembler::movapd, "movapd %{reg2}, %{reg1}"), "movapd"); 446} 447 448TEST_F(AssemblerX86Test, MovapdAddr) { 449 GetAssembler()->movapd(x86::XmmRegister(x86::XMM0), x86::Address(x86::Register(x86::ESP), 4)); 450 GetAssembler()->movapd(x86::Address(x86::Register(x86::ESP), 2), x86::XmmRegister(x86::XMM1)); 451 const char* expected = 452 "movapd 0x4(%ESP), %xmm0\n" 453 "movapd %xmm1, 0x2(%ESP)\n"; 454 DriverStr(expected, "movapd_address"); 455} 456 457TEST_F(AssemblerX86Test, MovupdAddr) { 458 GetAssembler()->movupd(x86::XmmRegister(x86::XMM0), x86::Address(x86::Register(x86::ESP), 4)); 459 GetAssembler()->movupd(x86::Address(x86::Register(x86::ESP), 2), x86::XmmRegister(x86::XMM1)); 460 const char* expected = 461 "movupd 0x4(%ESP), %xmm0\n" 462 "movupd %xmm1, 0x2(%ESP)\n"; 463 DriverStr(expected, "movupd_address"); 464} 465 466TEST_F(AssemblerX86Test, Movdqa) { 467 DriverStr(RepeatFF(&x86::X86Assembler::movdqa, "movdqa %{reg2}, %{reg1}"), "movdqa"); 468} 469 470TEST_F(AssemblerX86Test, MovdqaAddr) { 471 GetAssembler()->movdqa(x86::XmmRegister(x86::XMM0), x86::Address(x86::Register(x86::ESP), 4)); 472 GetAssembler()->movdqa(x86::Address(x86::Register(x86::ESP), 2), x86::XmmRegister(x86::XMM1)); 473 const char* expected = 474 "movdqa 0x4(%ESP), %xmm0\n" 475 "movdqa %xmm1, 0x2(%ESP)\n"; 476 DriverStr(expected, "movdqa_address"); 477} 478 479TEST_F(AssemblerX86Test, MovdquAddr) { 480 GetAssembler()->movdqu(x86::XmmRegister(x86::XMM0), x86::Address(x86::Register(x86::ESP), 4)); 481 GetAssembler()->movdqu(x86::Address(x86::Register(x86::ESP), 2), x86::XmmRegister(x86::XMM1)); 482 const char* expected = 483 "movdqu 0x4(%ESP), %xmm0\n" 484 "movdqu %xmm1, 0x2(%ESP)\n"; 485 DriverStr(expected, "movdqu_address"); 486} 487 488TEST_F(AssemblerX86Test, AddPS) { 489 DriverStr(RepeatFF(&x86::X86Assembler::addps, "addps %{reg2}, %{reg1}"), "addps"); 490} 491 492TEST_F(AssemblerX86Test, AddPD) { 493 DriverStr(RepeatFF(&x86::X86Assembler::addpd, "addpd %{reg2}, %{reg1}"), "addpd"); 494} 495 496TEST_F(AssemblerX86Test, SubPS) { 497 DriverStr(RepeatFF(&x86::X86Assembler::subps, "subps %{reg2}, %{reg1}"), "subps"); 498} 499 500TEST_F(AssemblerX86Test, SubPD) { 501 DriverStr(RepeatFF(&x86::X86Assembler::subpd, "subpd %{reg2}, %{reg1}"), "subpd"); 502} 503 504TEST_F(AssemblerX86Test, MulPS) { 505 DriverStr(RepeatFF(&x86::X86Assembler::mulps, "mulps %{reg2}, %{reg1}"), "mulps"); 506} 507 508TEST_F(AssemblerX86Test, MulPD) { 509 DriverStr(RepeatFF(&x86::X86Assembler::mulpd, "mulpd %{reg2}, %{reg1}"), "mulpd"); 510} 511 512TEST_F(AssemblerX86Test, DivPS) { 513 DriverStr(RepeatFF(&x86::X86Assembler::divps, "divps %{reg2}, %{reg1}"), "divps"); 514} 515 516TEST_F(AssemblerX86Test, DivPD) { 517 DriverStr(RepeatFF(&x86::X86Assembler::divpd, "divpd %{reg2}, %{reg1}"), "divpd"); 518} 519 520TEST_F(AssemblerX86Test, PAddB) { 521 DriverStr(RepeatFF(&x86::X86Assembler::paddb, "paddb %{reg2}, %{reg1}"), "paddb"); 522} 523 524TEST_F(AssemblerX86Test, PSubB) { 525 DriverStr(RepeatFF(&x86::X86Assembler::psubb, "psubb %{reg2}, %{reg1}"), "psubb"); 526} 527 528TEST_F(AssemblerX86Test, PAddW) { 529 DriverStr(RepeatFF(&x86::X86Assembler::paddw, "paddw %{reg2}, %{reg1}"), "paddw"); 530} 531 532TEST_F(AssemblerX86Test, PSubW) { 533 DriverStr(RepeatFF(&x86::X86Assembler::psubw, "psubw %{reg2}, %{reg1}"), "psubw"); 534} 535 536TEST_F(AssemblerX86Test, PMullW) { 537 DriverStr(RepeatFF(&x86::X86Assembler::pmullw, "pmullw %{reg2}, %{reg1}"), "pmullw"); 538} 539 540TEST_F(AssemblerX86Test, PAddD) { 541 DriverStr(RepeatFF(&x86::X86Assembler::paddd, "paddd %{reg2}, %{reg1}"), "paddd"); 542} 543 544TEST_F(AssemblerX86Test, PSubD) { 545 DriverStr(RepeatFF(&x86::X86Assembler::psubd, "psubd %{reg2}, %{reg1}"), "psubd"); 546} 547 548TEST_F(AssemblerX86Test, PMullD) { 549 DriverStr(RepeatFF(&x86::X86Assembler::pmulld, "pmulld %{reg2}, %{reg1}"), "pmulld"); 550} 551 552TEST_F(AssemblerX86Test, PAddQ) { 553 DriverStr(RepeatFF(&x86::X86Assembler::paddq, "paddq %{reg2}, %{reg1}"), "paddq"); 554} 555 556TEST_F(AssemblerX86Test, PSubQ) { 557 DriverStr(RepeatFF(&x86::X86Assembler::psubq, "psubq %{reg2}, %{reg1}"), "psubq"); 558} 559 560TEST_F(AssemblerX86Test, XorPD) { 561 DriverStr(RepeatFF(&x86::X86Assembler::xorpd, "xorpd %{reg2}, %{reg1}"), "xorpd"); 562} 563 564TEST_F(AssemblerX86Test, XorPS) { 565 DriverStr(RepeatFF(&x86::X86Assembler::xorps, "xorps %{reg2}, %{reg1}"), "xorps"); 566} 567 568TEST_F(AssemblerX86Test, PXor) { 569 DriverStr(RepeatFF(&x86::X86Assembler::pxor, "pxor %{reg2}, %{reg1}"), "pxor"); 570} 571 572TEST_F(AssemblerX86Test, AndPD) { 573 DriverStr(RepeatFF(&x86::X86Assembler::andpd, "andpd %{reg2}, %{reg1}"), "andpd"); 574} 575 576TEST_F(AssemblerX86Test, AndPS) { 577 DriverStr(RepeatFF(&x86::X86Assembler::andps, "andps %{reg2}, %{reg1}"), "andps"); 578} 579 580TEST_F(AssemblerX86Test, PAnd) { 581 DriverStr(RepeatFF(&x86::X86Assembler::pand, "pand %{reg2}, %{reg1}"), "pand"); 582} 583 584TEST_F(AssemblerX86Test, AndnPD) { 585 DriverStr(RepeatFF(&x86::X86Assembler::andnpd, "andnpd %{reg2}, %{reg1}"), "andnpd"); 586} 587 588TEST_F(AssemblerX86Test, AndnPS) { 589 DriverStr(RepeatFF(&x86::X86Assembler::andnps, "andnps %{reg2}, %{reg1}"), "andnps"); 590} 591 592TEST_F(AssemblerX86Test, PAndn) { 593 DriverStr(RepeatFF(&x86::X86Assembler::pandn, "pandn %{reg2}, %{reg1}"), "pandn"); 594} 595 596TEST_F(AssemblerX86Test, OrPD) { 597 DriverStr(RepeatFF(&x86::X86Assembler::orpd, "orpd %{reg2}, %{reg1}"), "orpd"); 598} 599 600TEST_F(AssemblerX86Test, OrPS) { 601 DriverStr(RepeatFF(&x86::X86Assembler::orps, "orps %{reg2}, %{reg1}"), "orps"); 602} 603 604TEST_F(AssemblerX86Test, POr) { 605 DriverStr(RepeatFF(&x86::X86Assembler::por, "por %{reg2}, %{reg1}"), "por"); 606} 607 608TEST_F(AssemblerX86Test, PAvgB) { 609 DriverStr(RepeatFF(&x86::X86Assembler::pavgb, "pavgb %{reg2}, %{reg1}"), "pavgb"); 610} 611 612TEST_F(AssemblerX86Test, PAvgW) { 613 DriverStr(RepeatFF(&x86::X86Assembler::pavgw, "pavgw %{reg2}, %{reg1}"), "pavgw"); 614} 615 616TEST_F(AssemblerX86Test, PCmpeqB) { 617 DriverStr(RepeatFF(&x86::X86Assembler::pcmpeqb, "pcmpeqb %{reg2}, %{reg1}"), "cmpeqb"); 618} 619 620TEST_F(AssemblerX86Test, PCmpeqW) { 621 DriverStr(RepeatFF(&x86::X86Assembler::pcmpeqw, "pcmpeqw %{reg2}, %{reg1}"), "cmpeqw"); 622} 623 624TEST_F(AssemblerX86Test, PCmpeqD) { 625 DriverStr(RepeatFF(&x86::X86Assembler::pcmpeqd, "pcmpeqd %{reg2}, %{reg1}"), "cmpeqd"); 626} 627 628TEST_F(AssemblerX86Test, PCmpeqQ) { 629 DriverStr(RepeatFF(&x86::X86Assembler::pcmpeqq, "pcmpeqq %{reg2}, %{reg1}"), "cmpeqq"); 630} 631 632TEST_F(AssemblerX86Test, PCmpgtB) { 633 DriverStr(RepeatFF(&x86::X86Assembler::pcmpgtb, "pcmpgtb %{reg2}, %{reg1}"), "cmpgtb"); 634} 635 636TEST_F(AssemblerX86Test, PCmpgtW) { 637 DriverStr(RepeatFF(&x86::X86Assembler::pcmpgtw, "pcmpgtw %{reg2}, %{reg1}"), "cmpgtw"); 638} 639 640TEST_F(AssemblerX86Test, PCmpgtD) { 641 DriverStr(RepeatFF(&x86::X86Assembler::pcmpgtd, "pcmpgtd %{reg2}, %{reg1}"), "cmpgtd"); 642} 643 644TEST_F(AssemblerX86Test, PCmpgtQ) { 645 DriverStr(RepeatFF(&x86::X86Assembler::pcmpgtq, "pcmpgtq %{reg2}, %{reg1}"), "cmpgtq"); 646} 647 648TEST_F(AssemblerX86Test, ShufPS) { 649 DriverStr(RepeatFFI(&x86::X86Assembler::shufps, 1, "shufps ${imm}, %{reg2}, %{reg1}"), "shufps"); 650} 651 652TEST_F(AssemblerX86Test, ShufPD) { 653 DriverStr(RepeatFFI(&x86::X86Assembler::shufpd, 1, "shufpd ${imm}, %{reg2}, %{reg1}"), "shufpd"); 654} 655 656TEST_F(AssemblerX86Test, PShufD) { 657 DriverStr(RepeatFFI(&x86::X86Assembler::pshufd, 1, "pshufd ${imm}, %{reg2}, %{reg1}"), "pshufd"); 658} 659 660TEST_F(AssemblerX86Test, Punpcklbw) { 661 DriverStr(RepeatFF(&x86::X86Assembler::punpcklbw, "punpcklbw %{reg2}, %{reg1}"), "punpcklbw"); 662} 663 664TEST_F(AssemblerX86Test, Punpcklwd) { 665 DriverStr(RepeatFF(&x86::X86Assembler::punpcklwd, "punpcklwd %{reg2}, %{reg1}"), "punpcklwd"); 666} 667 668TEST_F(AssemblerX86Test, Punpckldq) { 669 DriverStr(RepeatFF(&x86::X86Assembler::punpckldq, "punpckldq %{reg2}, %{reg1}"), "punpckldq"); 670} 671 672TEST_F(AssemblerX86Test, Punpcklqdq) { 673 DriverStr(RepeatFF(&x86::X86Assembler::punpcklqdq, "punpcklqdq %{reg2}, %{reg1}"), "punpcklqdq"); 674} 675 676TEST_F(AssemblerX86Test, psllw) { 677 GetAssembler()->psllw(x86::XMM0, CreateImmediate(16)); 678 DriverStr("psllw $0x10, %xmm0\n", "psllwi"); 679} 680 681TEST_F(AssemblerX86Test, pslld) { 682 GetAssembler()->pslld(x86::XMM0, CreateImmediate(16)); 683 DriverStr("pslld $0x10, %xmm0\n", "pslldi"); 684} 685 686TEST_F(AssemblerX86Test, psllq) { 687 GetAssembler()->psllq(x86::XMM0, CreateImmediate(16)); 688 DriverStr("psllq $0x10, %xmm0\n", "psllqi"); 689} 690 691TEST_F(AssemblerX86Test, psraw) { 692 GetAssembler()->psraw(x86::XMM0, CreateImmediate(16)); 693 DriverStr("psraw $0x10, %xmm0\n", "psrawi"); 694} 695 696TEST_F(AssemblerX86Test, psrad) { 697 GetAssembler()->psrad(x86::XMM0, CreateImmediate(16)); 698 DriverStr("psrad $0x10, %xmm0\n", "psradi"); 699} 700 701TEST_F(AssemblerX86Test, psrlw) { 702 GetAssembler()->psrlw(x86::XMM0, CreateImmediate(16)); 703 DriverStr("psrlw $0x10, %xmm0\n", "psrlwi"); 704} 705 706TEST_F(AssemblerX86Test, psrld) { 707 GetAssembler()->psrld(x86::XMM0, CreateImmediate(16)); 708 DriverStr("psrld $0x10, %xmm0\n", "psrldi"); 709} 710 711TEST_F(AssemblerX86Test, psrlq) { 712 GetAssembler()->psrlq(x86::XMM0, CreateImmediate(16)); 713 DriverStr("psrlq $0x10, %xmm0\n", "psrlqi"); 714} 715 716TEST_F(AssemblerX86Test, psrldq) { 717 GetAssembler()->psrldq(x86::XMM0, CreateImmediate(16)); 718 DriverStr("psrldq $0x10, %xmm0\n", "psrldqi"); 719} 720 721///////////////// 722// Near labels // 723///////////////// 724 725TEST_F(AssemblerX86Test, Jecxz) { 726 x86::NearLabel target; 727 GetAssembler()->jecxz(&target); 728 GetAssembler()->addl(x86::EDI, x86::Address(x86::ESP, 4)); 729 GetAssembler()->Bind(&target); 730 const char* expected = 731 "jecxz 1f\n" 732 "addl 4(%ESP),%EDI\n" 733 "1:\n"; 734 735 DriverStr(expected, "jecxz"); 736} 737 738TEST_F(AssemblerX86Test, NearLabel) { 739 // Test both forward and backward branches. 740 x86::NearLabel start, target; 741 GetAssembler()->Bind(&start); 742 GetAssembler()->j(x86::kEqual, &target); 743 GetAssembler()->jmp(&target); 744 GetAssembler()->jecxz(&target); 745 GetAssembler()->addl(x86::EDI, x86::Address(x86::ESP, 4)); 746 GetAssembler()->Bind(&target); 747 GetAssembler()->j(x86::kNotEqual, &start); 748 GetAssembler()->jmp(&start); 749 const char* expected = 750 "1: je 2f\n" 751 "jmp 2f\n" 752 "jecxz 2f\n" 753 "addl 4(%ESP),%EDI\n" 754 "2: jne 1b\n" 755 "jmp 1b\n"; 756 757 DriverStr(expected, "near_label"); 758} 759 760TEST_F(AssemblerX86Test, Cmpb) { 761 GetAssembler()->cmpb(x86::Address(x86::EDI, 128), x86::Immediate(0)); 762 const char* expected = "cmpb $0, 128(%EDI)\n"; 763 DriverStr(expected, "cmpb"); 764} 765 766} // namespace art 767