assembler-ia32.cc 76.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
// Copyright (c) 1994-2006 Sun Microsystems Inc.
// All Rights Reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// - Redistribution in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// - Neither the name of Sun Microsystems or the names of contributors may
// be used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.

// The original source code covered by the above license above has been modified
// significantly by Google Inc.
35
// Copyright 2012 the V8 project authors. All rights reserved.
36

37 38
#include "src/ia32/assembler-ia32.h"

39 40 41 42
#include <cstring>

#if V8_TARGET_ARCH_IA32

43 44 45
#if V8_LIBC_MSVCRT
#include <intrin.h>  // _xgetbv()
#endif
46 47 48
#if V8_OS_MACOSX
#include <sys/sysctl.h>
#endif
49

50
#include "src/assembler-inl.h"
51
#include "src/base/bits.h"
52
#include "src/base/cpu.h"
53
#include "src/code-stubs.h"
54
#include "src/conversions-inl.h"
55
#include "src/deoptimizer.h"
56 57
#include "src/disassembler.h"
#include "src/macro-assembler.h"
58
#include "src/string-constants.h"
59
#include "src/v8.h"
60

61 62
namespace v8 {
namespace internal {
63

64 65 66 67
Immediate Immediate::EmbeddedNumber(double value) {
  int32_t smi;
  if (DoubleToSmiInteger(value, &smi)) return Immediate(Smi::FromInt(smi));
  Immediate result(0, RelocInfo::EMBEDDED_OBJECT);
68 69 70 71 72 73 74 75 76
  result.is_heap_object_request_ = true;
  result.value_.heap_object_request = HeapObjectRequest(value);
  return result;
}

Immediate Immediate::EmbeddedCode(CodeStub* stub) {
  Immediate result(0, RelocInfo::CODE_TARGET);
  result.is_heap_object_request_ = true;
  result.value_.heap_object_request = HeapObjectRequest(stub);
77 78 79
  return result;
}

80 81 82 83 84 85 86
Immediate Immediate::EmbeddedStringConstant(const StringConstantBase* str) {
  Immediate result(0, RelocInfo::EMBEDDED_OBJECT);
  result.is_heap_object_request_ = true;
  result.value_.heap_object_request = HeapObjectRequest(str);
  return result;
}

87 88 89
// -----------------------------------------------------------------------------
// Implementation of CpuFeatures

90 91
namespace {

92 93 94 95 96 97 98 99
#if !V8_LIBC_MSVCRT

V8_INLINE uint64_t _xgetbv(unsigned int xcr) {
  unsigned eax, edx;
  // Check xgetbv; this uses a .byte sequence instead of the instruction
  // directly because older assemblers do not include support for xgetbv and
  // there is no easy way to conditionally compile based on the assembler
  // used.
100
  __asm__ volatile(".byte 0x0F, 0x01, 0xD0" : "=a"(eax), "=d"(edx) : "c"(xcr));
101 102 103 104 105 106 107 108 109
  return static_cast<uint64_t>(eax) | (static_cast<uint64_t>(edx) << 32);
}

#define _XCR_XFEATURE_ENABLED_MASK 0

#endif  // !V8_LIBC_MSVCRT


bool OSHasAVXSupport() {
110
#if V8_OS_MACOSX
111 112
  // Mac OS X up to 10.9 has a bug where AVX transitions were indeed being
  // caused by ISRs, so we detect that here and disable AVX in that case.
113 114
  char buffer[128];
  size_t buffer_size = arraysize(buffer);
115
  int ctl_name[] = {CTL_KERN, KERN_OSRELEASE};
116
  if (sysctl(ctl_name, 2, buffer, &buffer_size, nullptr, 0) != 0) {
117
    FATAL("V8 failed to get kernel version");
118 119
  }
  // The buffer now contains a string of the form XX.YY.ZZ, where
120 121 122 123 124 125
  // XX is the major kernel version component.
  char* period_pos = strchr(buffer, '.');
  DCHECK_NOT_NULL(period_pos);
  *period_pos = '\0';
  long kernel_version_major = strtol(buffer, nullptr, 10);  // NOLINT
  if (kernel_version_major <= 13) return false;
126
#endif  // V8_OS_MACOSX
127 128 129
  // Check whether OS claims to support AVX.
  uint64_t feature_mask = _xgetbv(_XCR_XFEATURE_ENABLED_MASK);
  return (feature_mask & 0x6) == 0x6;
130 131 132 133 134
}

}  // namespace


135
void CpuFeatures::ProbeImpl(bool cross_compile) {
136
  base::CPU cpu;
137
  CHECK(cpu.has_sse2());  // SSE2 support is mandatory.
138
  CHECK(cpu.has_cmov());  // CMOV support is mandatory.
139

140 141
  // Only use statically determined features for cross compile (snapshot).
  if (cross_compile) return;
142

143
  if (cpu.has_sse41() && FLAG_enable_sse4_1) supported_ |= 1u << SSE4_1;
144
  if (cpu.has_ssse3() && FLAG_enable_ssse3) supported_ |= 1u << SSSE3;
145
  if (cpu.has_sse3() && FLAG_enable_sse3) supported_ |= 1u << SSE3;
146 147 148 149 150 151 152 153
  if (cpu.has_avx() && FLAG_enable_avx && cpu.has_osxsave() &&
      OSHasAVXSupport()) {
    supported_ |= 1u << AVX;
  }
  if (cpu.has_fma3() && FLAG_enable_fma3 && cpu.has_osxsave() &&
      OSHasAVXSupport()) {
    supported_ |= 1u << FMA3;
  }
154 155 156 157
  if (cpu.has_bmi1() && FLAG_enable_bmi1) supported_ |= 1u << BMI1;
  if (cpu.has_bmi2() && FLAG_enable_bmi2) supported_ |= 1u << BMI2;
  if (cpu.has_lzcnt() && FLAG_enable_lzcnt) supported_ |= 1u << LZCNT;
  if (cpu.has_popcnt() && FLAG_enable_popcnt) supported_ |= 1u << POPCNT;
158 159 160 161 162
  if (strcmp(FLAG_mcpu, "auto") == 0) {
    if (cpu.is_atom()) supported_ |= 1u << ATOM;
  } else if (strcmp(FLAG_mcpu, "atom") == 0) {
    supported_ |= 1u << ATOM;
  }
163 164 165
}


166
void CpuFeatures::PrintTarget() { }
167
void CpuFeatures::PrintFeatures() {
168
  printf(
169 170 171 172 173 174 175
      "SSE3=%d SSSE3=%d SSE4_1=%d AVX=%d FMA3=%d BMI1=%d BMI2=%d LZCNT=%d "
      "POPCNT=%d ATOM=%d\n",
      CpuFeatures::IsSupported(SSE3), CpuFeatures::IsSupported(SSSE3),
      CpuFeatures::IsSupported(SSE4_1), CpuFeatures::IsSupported(AVX),
      CpuFeatures::IsSupported(FMA3), CpuFeatures::IsSupported(BMI1),
      CpuFeatures::IsSupported(BMI2), CpuFeatures::IsSupported(LZCNT),
      CpuFeatures::IsSupported(POPCNT), CpuFeatures::IsSupported(ATOM));
176
}
177 178


179
// -----------------------------------------------------------------------------
180 181 182
// Implementation of Displacement

void Displacement::init(Label* L, Type type) {
183
  DCHECK(!L->is_bound());
184 185 186
  int next = 0;
  if (L->is_linked()) {
    next = L->pos();
187
    DCHECK_GT(next, 0);  // Displacements must be at positions > 0
188
  }
189
  // Ensure that we _never_ overflow the next field.
190
  DCHECK(NextField::is_valid(Assembler::kMaximalBufferSize));
191 192
  data_ = NextField::encode(next) | TypeField::encode(type);
}
193 194 195 196 197


// -----------------------------------------------------------------------------
// Implementation of RelocInfo

198
const int RelocInfo::kApplyMask =
199 200
    RelocInfo::ModeMask(RelocInfo::CODE_TARGET) |
    RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE) |
201 202
    RelocInfo::ModeMask(RelocInfo::OFF_HEAP_TARGET) |
    RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY);
203

204 205 206 207 208
bool RelocInfo::IsCodedSpecially() {
  // The deserializer needs to know whether a pointer is specially coded.  Being
  // specially coded on IA32 means that it is a relative address, as used by
  // branch instructions.  These are also the ones that need changing when a
  // code object moves.
209
  return RelocInfo::ModeMask(rmode_) & kApplyMask;
210 211 212
}


213 214 215 216
bool RelocInfo::IsInConstantPool() {
  return false;
}

217 218 219 220 221
int RelocInfo::GetDeoptimizationId(Isolate* isolate, DeoptimizeKind kind) {
  DCHECK(IsRuntimeEntry(rmode_));
  return Deoptimizer::GetDeoptimizationId(isolate, target_address(), kind);
}

222 223
uint32_t RelocInfo::wasm_call_tag() const {
  DCHECK(rmode_ == WASM_CALL || rmode_ == WASM_STUB_CALL);
224
  return Memory<uint32_t>(pc_);
225 226
}

227 228 229
// -----------------------------------------------------------------------------
// Implementation of Operand

230
Operand::Operand(Register base, int32_t disp, RelocInfo::Mode rmode) {
231
  // [base + disp/r]
232
  if (disp == 0 && RelocInfo::IsNone(rmode) && base != ebp) {
233 234
    // [base]
    set_modrm(0, base);
235
    if (base == esp) set_sib(times_1, esp, base);
236
  } else if (is_int8(disp) && RelocInfo::IsNone(rmode)) {
237 238
    // [base + disp8]
    set_modrm(1, base);
239
    if (base == esp) set_sib(times_1, esp, base);
240 241 242 243
    set_disp8(disp);
  } else {
    // [base + disp/r]
    set_modrm(2, base);
244
    if (base == esp) set_sib(times_1, esp, base);
245 246 247 248 249 250 251 252 253
    set_dispr(disp, rmode);
  }
}


Operand::Operand(Register base,
                 Register index,
                 ScaleFactor scale,
                 int32_t disp,
254
                 RelocInfo::Mode rmode) {
255
  DCHECK(index != esp);  // illegal addressing mode
256
  // [base + index*scale + disp/r]
257
  if (disp == 0 && RelocInfo::IsNone(rmode) && base != ebp) {
258 259 260
    // [base + index*scale]
    set_modrm(0, esp);
    set_sib(scale, index, base);
261
  } else if (is_int8(disp) && RelocInfo::IsNone(rmode)) {
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
    // [base + index*scale + disp8]
    set_modrm(1, esp);
    set_sib(scale, index, base);
    set_disp8(disp);
  } else {
    // [base + index*scale + disp/r]
    set_modrm(2, esp);
    set_sib(scale, index, base);
    set_dispr(disp, rmode);
  }
}


Operand::Operand(Register index,
                 ScaleFactor scale,
                 int32_t disp,
278
                 RelocInfo::Mode rmode) {
279
  DCHECK(index != esp);  // illegal addressing mode
280 281 282 283 284 285 286
  // [index*scale + disp/r]
  set_modrm(0, esp);
  set_sib(scale, index, ebp);
  set_dispr(disp, rmode);
}


287 288 289 290 291 292
bool Operand::is_reg_only() const {
  return (buf_[0] & 0xF8) == 0xC0;  // Addressing mode is register only.
}


Register Operand::reg() const {
293
  DCHECK(is_reg_only());
294 295 296
  return Register::from_code(buf_[0] & 0x07);
}

297
void Assembler::AllocateAndInstallRequestedHeapObjects(Isolate* isolate) {
298
  DCHECK_IMPLIES(isolate == nullptr, heap_object_requests_.empty());
299 300 301 302
  for (auto& request : heap_object_requests_) {
    Handle<HeapObject> object;
    switch (request.kind()) {
      case HeapObjectRequest::kHeapNumber:
303 304
        object =
            isolate->factory()->NewHeapNumber(request.heap_number(), TENURED);
305 306 307 308 309
        break;
      case HeapObjectRequest::kCodeStub:
        request.code_stub()->set_isolate(isolate);
        object = request.code_stub()->GetCode();
        break;
310 311 312 313 314 315
      case HeapObjectRequest::kStringConstant: {
        const StringConstantBase* str = request.string();
        CHECK_NOT_NULL(str);
        object = str->AllocateStringConstant(isolate);
        break;
      }
316
    }
317
    Address pc = reinterpret_cast<Address>(buffer_) + request.offset();
318
    Memory<Handle<Object>>(pc) = object;
319 320
  }
}
321

322
// -----------------------------------------------------------------------------
323
// Implementation of Assembler.
324 325 326 327 328

// Emit a single byte. Must always be inlined.
#define EMIT(x)                                 \
  *pc_++ = (x)

329 330
Assembler::Assembler(const AssemblerOptions& options, void* buffer,
                     int buffer_size)
331
    : AssemblerBase(options, buffer, buffer_size) {
332 333
// Clear the buffer in debug mode unless it was provided by the
// caller in which case we can't be sure it's okay to overwrite
334
// existing code in it.
335
#ifdef DEBUG
336
  if (own_buffer_) ZapCode(reinterpret_cast<Address>(buffer_), buffer_size_);
337
#endif
338

339
  reloc_info_writer.Reposition(buffer_ + buffer_size_, pc_);
340 341
}

342
void Assembler::GetCode(Isolate* isolate, CodeDesc* desc) {
343 344
  // Finalize code (at this point overflow() may be true, but the gap ensures
  // that we are still not overlapping instructions and relocation info).
345
  DCHECK(pc_ <= reloc_info_writer.pos());  // No overlap.
346

347
  AllocateAndInstallRequestedHeapObjects(isolate);
348

349
  // Set up code descriptor.
350 351 352 353
  desc->buffer = buffer_;
  desc->buffer_size = buffer_size_;
  desc->instr_size = pc_offset();
  desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos();
354
  desc->origin = this;
355
  desc->constant_pool_size = 0;
356 357
  desc->unwinding_info_size = 0;
  desc->unwinding_info = nullptr;
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376

  // Collection stage
  auto jump_opt = jump_optimization_info();
  if (jump_opt && jump_opt->is_collecting()) {
    auto& bitmap = jump_opt->farjmp_bitmap();
    int num = static_cast<int>(farjmp_positions_.size());
    if (num && bitmap.empty()) {
      bool can_opt = false;

      bitmap.resize((num + 31) / 32, 0);
      for (int i = 0; i < num; i++) {
        int disp_pos = farjmp_positions_[i];
        int disp = long_at(disp_pos);
        if (is_int8(disp)) {
          bitmap[i / 32] |= 1 << (i & 31);
          can_opt = true;
        }
      }
      if (can_opt) {
377
        jump_opt->set_optimizable();
378 379 380
      }
    }
  }
381 382 383
}


384
void Assembler::Align(int m) {
385
  DCHECK(base::bits::IsPowerOfTwo(m));
386 387 388 389 390 391 392
  int mask = m - 1;
  int addr = pc_offset();
  Nop((m - (addr & mask)) & mask);
}


bool Assembler::IsNop(Address addr) {
393
  byte* a = reinterpret_cast<byte*>(addr);
394 395
  while (*a == 0x66) a++;
  if (*a == 0x90) return true;
396
  if (a[0] == 0xF && a[1] == 0x1F) return true;
397 398 399 400 401 402 403 404 405 406 407 408
  return false;
}


void Assembler::Nop(int bytes) {
  EnsureSpace ensure_space(this);

  // Multi byte nops from http://support.amd.com/us/Processor_TechDocs/40546.pdf
  while (bytes > 0) {
    switch (bytes) {
      case 2:
        EMIT(0x66);
409
        V8_FALLTHROUGH;
410 411 412 413
      case 1:
        EMIT(0x90);
        return;
      case 3:
414 415
        EMIT(0xF);
        EMIT(0x1F);
416 417 418
        EMIT(0);
        return;
      case 4:
419 420
        EMIT(0xF);
        EMIT(0x1F);
421 422 423 424 425
        EMIT(0x40);
        EMIT(0);
        return;
      case 6:
        EMIT(0x66);
426
        V8_FALLTHROUGH;
427
      case 5:
428 429
        EMIT(0xF);
        EMIT(0x1F);
430 431 432 433 434
        EMIT(0x44);
        EMIT(0);
        EMIT(0);
        return;
      case 7:
435 436
        EMIT(0xF);
        EMIT(0x1F);
437 438 439 440 441 442 443 444 445 446
        EMIT(0x80);
        EMIT(0);
        EMIT(0);
        EMIT(0);
        EMIT(0);
        return;
      default:
      case 11:
        EMIT(0x66);
        bytes--;
447
        V8_FALLTHROUGH;
448 449 450
      case 10:
        EMIT(0x66);
        bytes--;
451
        V8_FALLTHROUGH;
452 453 454
      case 9:
        EMIT(0x66);
        bytes--;
455
        V8_FALLTHROUGH;
456
      case 8:
457 458
        EMIT(0xF);
        EMIT(0x1F);
459 460 461 462 463 464 465 466
        EMIT(0x84);
        EMIT(0);
        EMIT(0);
        EMIT(0);
        EMIT(0);
        EMIT(0);
        bytes -= 8;
    }
467 468 469 470
  }
}


471 472 473 474 475
void Assembler::CodeTargetAlign() {
  Align(16);  // Preferred alignment of jump targets on ia32.
}


476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
void Assembler::cpuid() {
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xA2);
}


void Assembler::pushad() {
  EnsureSpace ensure_space(this);
  EMIT(0x60);
}


void Assembler::popad() {
  EnsureSpace ensure_space(this);
  EMIT(0x61);
}


void Assembler::pushfd() {
  EnsureSpace ensure_space(this);
  EMIT(0x9C);
}


void Assembler::popfd() {
  EnsureSpace ensure_space(this);
  EMIT(0x9D);
}


void Assembler::push(const Immediate& x) {
  EnsureSpace ensure_space(this);
  if (x.is_int8()) {
510
    EMIT(0x6A);
511
    EMIT(x.immediate());
512 513 514 515 516 517 518
  } else {
    EMIT(0x68);
    emit(x);
  }
}


519 520 521 522 523 524 525
void Assembler::push_imm32(int32_t imm32) {
  EnsureSpace ensure_space(this);
  EMIT(0x68);
  emit(imm32);
}


526 527 528 529 530
void Assembler::push(Register src) {
  EnsureSpace ensure_space(this);
  EMIT(0x50 | src.code());
}

531
void Assembler::push(Operand src) {
532 533 534 535 536 537 538
  EnsureSpace ensure_space(this);
  EMIT(0xFF);
  emit_operand(esi, src);
}


void Assembler::pop(Register dst) {
539
  DCHECK_NOT_NULL(reloc_info_writer.last_pc());
540 541 542 543
  EnsureSpace ensure_space(this);
  EMIT(0x58 | dst.code());
}

544
void Assembler::pop(Operand dst) {
545 546 547 548 549 550
  EnsureSpace ensure_space(this);
  EMIT(0x8F);
  emit_operand(eax, dst);
}


551 552 553 554 555 556 557 558 559 560 561 562 563
void Assembler::enter(const Immediate& size) {
  EnsureSpace ensure_space(this);
  EMIT(0xC8);
  emit_w(size);
  EMIT(0);
}


void Assembler::leave() {
  EnsureSpace ensure_space(this);
  EMIT(0xC9);
}

564
void Assembler::mov_b(Register dst, Operand src) {
565
  CHECK(dst.is_byte_register());
566 567 568 569 570
  EnsureSpace ensure_space(this);
  EMIT(0x8A);
  emit_operand(dst, src);
}

571
void Assembler::mov_b(Operand dst, const Immediate& src) {
572 573 574
  EnsureSpace ensure_space(this);
  EMIT(0xC6);
  emit_operand(eax, dst);
575
  EMIT(static_cast<int8_t>(src.immediate()));
576 577
}

578
void Assembler::mov_b(Operand dst, Register src) {
579
  CHECK(src.is_byte_register());
580 581 582 583 584
  EnsureSpace ensure_space(this);
  EMIT(0x88);
  emit_operand(src, dst);
}

585
void Assembler::mov_w(Register dst, Operand src) {
586 587 588 589 590 591
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x8B);
  emit_operand(dst, src);
}

592
void Assembler::mov_w(Operand dst, Register src) {
593 594 595 596 597 598
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x89);
  emit_operand(src, dst);
}

599
void Assembler::mov_w(Operand dst, const Immediate& src) {
600 601 602 603
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0xC7);
  emit_operand(eax, dst);
604
  EMIT(static_cast<int8_t>(src.immediate() & 0xFF));
605
  EMIT(static_cast<int8_t>(src.immediate() >> 8));
606 607 608
}


609 610 611 612 613 614 615
void Assembler::mov(Register dst, int32_t imm32) {
  EnsureSpace ensure_space(this);
  EMIT(0xB8 | dst.code());
  emit(imm32);
}


616 617 618 619 620 621
void Assembler::mov(Register dst, const Immediate& x) {
  EnsureSpace ensure_space(this);
  EMIT(0xB8 | dst.code());
  emit(x);
}

622
void Assembler::mov(Register dst, Handle<HeapObject> handle) {
623 624 625 626 627
  EnsureSpace ensure_space(this);
  EMIT(0xB8 | dst.code());
  emit(handle);
}

628
void Assembler::mov(Register dst, Operand src) {
629 630 631 632 633 634
  EnsureSpace ensure_space(this);
  EMIT(0x8B);
  emit_operand(dst, src);
}


635 636 637 638 639 640
void Assembler::mov(Register dst, Register src) {
  EnsureSpace ensure_space(this);
  EMIT(0x89);
  EMIT(0xC0 | src.code() << 3 | dst.code());
}

641
void Assembler::mov(Operand dst, const Immediate& x) {
642 643 644 645 646 647
  EnsureSpace ensure_space(this);
  EMIT(0xC7);
  emit_operand(eax, dst);
  emit(x);
}

648
void Assembler::mov(Operand dst, Address src, RelocInfo::Mode rmode) {
649 650 651
  EnsureSpace ensure_space(this);
  EMIT(0xC7);
  emit_operand(eax, dst);
652
  emit(src, rmode);
653 654
}

655
void Assembler::mov(Operand dst, Handle<HeapObject> handle) {
656 657 658 659 660 661
  EnsureSpace ensure_space(this);
  EMIT(0xC7);
  emit_operand(eax, dst);
  emit(handle);
}

662
void Assembler::mov(Operand dst, Register src) {
663 664 665 666 667
  EnsureSpace ensure_space(this);
  EMIT(0x89);
  emit_operand(src, dst);
}

668
void Assembler::movsx_b(Register dst, Operand src) {
669
  DCHECK_IMPLIES(src.is_reg_only(), src.reg().is_byte_register());
670 671 672 673 674 675
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xBE);
  emit_operand(dst, src);
}

676
void Assembler::movsx_w(Register dst, Operand src) {
677 678 679 680 681 682
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xBF);
  emit_operand(dst, src);
}

683
void Assembler::movzx_b(Register dst, Operand src) {
684
  DCHECK_IMPLIES(src.is_reg_only(), src.reg().is_byte_register());
685 686 687 688 689 690
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xB6);
  emit_operand(dst, src);
}

691
void Assembler::movzx_w(Register dst, Operand src) {
692 693 694 695 696 697
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xB7);
  emit_operand(dst, src);
}

698 699 700 701 702 703 704 705
void Assembler::movq(XMMRegister dst, Operand src) {
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0x0F);
  EMIT(0x7E);
  emit_operand(dst, src);
}

706
void Assembler::cmov(Condition cc, Register dst, Operand src) {
707
  EnsureSpace ensure_space(this);
708
  // Opcode: 0f 40 + cc /r.
709 710 711
  EMIT(0x0F);
  EMIT(0x40 + cc);
  emit_operand(dst, src);
712 713 714
}


715 716 717 718 719 720
void Assembler::cld() {
  EnsureSpace ensure_space(this);
  EMIT(0xFC);
}


721 722 723 724 725 726 727
void Assembler::rep_movs() {
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0xA5);
}


728 729 730 731 732 733 734
void Assembler::rep_stos() {
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0xAB);
}


735 736 737 738 739 740
void Assembler::stos() {
  EnsureSpace ensure_space(this);
  EMIT(0xAB);
}


741 742
void Assembler::xchg(Register dst, Register src) {
  EnsureSpace ensure_space(this);
743 744
  if (src == eax || dst == eax) {  // Single-byte encoding.
    EMIT(0x90 | (src == eax ? dst.code() : src.code()));
745 746 747 748 749 750
  } else {
    EMIT(0x87);
    EMIT(0xC0 | src.code() << 3 | dst.code());
  }
}

751
void Assembler::xchg(Register dst, Operand src) {
752 753 754 755 756
  EnsureSpace ensure_space(this);
  EMIT(0x87);
  emit_operand(dst, src);
}

757
void Assembler::xchg_b(Register reg, Operand op) {
758
  DCHECK(reg.is_byte_register());
759 760 761 762 763
  EnsureSpace ensure_space(this);
  EMIT(0x86);
  emit_operand(reg, op);
}

764
void Assembler::xchg_w(Register reg, Operand op) {
765 766 767 768 769
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x87);
  emit_operand(reg, op);
}
770

771 772 773 774 775
void Assembler::lock() {
  EnsureSpace ensure_space(this);
  EMIT(0xF0);
}

776
void Assembler::cmpxchg(Operand dst, Register src) {
777 778 779 780 781 782
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xB1);
  emit_operand(src, dst);
}

783
void Assembler::cmpxchg_b(Operand dst, Register src) {
784
  DCHECK(src.is_byte_register());
785 786 787 788 789 790
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xB0);
  emit_operand(src, dst);
}

791
void Assembler::cmpxchg_w(Operand dst, Register src) {
792 793 794 795 796 797 798
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0xB1);
  emit_operand(src, dst);
}

799 800 801 802 803 804 805
void Assembler::cmpxchg8b(Operand dst) {
  EnsureSpace enure_space(this);
  EMIT(0x0F);
  EMIT(0xC7);
  emit_operand(ecx, dst);
}

806 807 808 809 810 811 812
void Assembler::lfence() {
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xAE);
  EMIT(0xE8);
}

813 814 815 816 817 818
void Assembler::pause() {
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0x90);
}

819 820 821 822 823
void Assembler::adc(Register dst, int32_t imm32) {
  EnsureSpace ensure_space(this);
  emit_arith(2, Operand(dst), Immediate(imm32));
}

824
void Assembler::adc(Register dst, Operand src) {
825 826 827 828 829
  EnsureSpace ensure_space(this);
  EMIT(0x13);
  emit_operand(dst, src);
}

830
void Assembler::add(Register dst, Operand src) {
831 832 833 834 835
  EnsureSpace ensure_space(this);
  EMIT(0x03);
  emit_operand(dst, src);
}

836
void Assembler::add(Operand dst, Register src) {
837 838 839 840 841
  EnsureSpace ensure_space(this);
  EMIT(0x01);
  emit_operand(src, dst);
}

842
void Assembler::add(Operand dst, const Immediate& x) {
843
  DCHECK_NOT_NULL(reloc_info_writer.last_pc());
844 845 846 847 848 849
  EnsureSpace ensure_space(this);
  emit_arith(0, dst, x);
}


void Assembler::and_(Register dst, int32_t imm32) {
850 851 852 853 854
  and_(dst, Immediate(imm32));
}


void Assembler::and_(Register dst, const Immediate& x) {
855
  EnsureSpace ensure_space(this);
856
  emit_arith(4, Operand(dst), x);
857 858
}

859
void Assembler::and_(Register dst, Operand src) {
860 861 862 863 864
  EnsureSpace ensure_space(this);
  EMIT(0x23);
  emit_operand(dst, src);
}

865
void Assembler::and_(Operand dst, const Immediate& x) {
866 867 868 869
  EnsureSpace ensure_space(this);
  emit_arith(4, dst, x);
}

870
void Assembler::and_(Operand dst, Register src) {
871 872
  EnsureSpace ensure_space(this);
  EMIT(0x21);
873
  emit_operand(src, dst);
874 875
}

876
void Assembler::cmpb(Operand op, Immediate imm8) {
877
  DCHECK(imm8.is_int8() || imm8.is_uint8());
878
  EnsureSpace ensure_space(this);
879 880 881 882 883 884
  if (op.is_reg(eax)) {
    EMIT(0x3C);
  } else {
    EMIT(0x80);
    emit_operand(edi, op);  // edi == 7
  }
885
  emit_b(imm8);
886 887
}

888
void Assembler::cmpb(Operand op, Register reg) {
889
  CHECK(reg.is_byte_register());
890 891
  EnsureSpace ensure_space(this);
  EMIT(0x38);
892
  emit_operand(reg, op);
893 894
}

895
void Assembler::cmpb(Register reg, Operand op) {
896
  CHECK(reg.is_byte_register());
897 898
  EnsureSpace ensure_space(this);
  EMIT(0x3A);
899
  emit_operand(reg, op);
900 901
}

902
void Assembler::cmpw(Operand op, Immediate imm16) {
903
  DCHECK(imm16.is_int16() || imm16.is_uint16());
904 905 906 907 908 909 910
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x81);
  emit_operand(edi, op);
  emit_w(imm16);
}

911
void Assembler::cmpw(Register reg, Operand op) {
912 913
  EnsureSpace ensure_space(this);
  EMIT(0x66);
epertoso's avatar
epertoso committed
914
  EMIT(0x3B);
915 916 917
  emit_operand(reg, op);
}

918
void Assembler::cmpw(Operand op, Register reg) {
919 920
  EnsureSpace ensure_space(this);
  EMIT(0x66);
epertoso's avatar
epertoso committed
921
  EMIT(0x39);
922 923
  emit_operand(reg, op);
}
924

925 926 927 928 929
void Assembler::cmp(Register reg, int32_t imm32) {
  EnsureSpace ensure_space(this);
  emit_arith(7, Operand(reg), Immediate(imm32));
}

930
void Assembler::cmp(Register reg, Handle<HeapObject> handle) {
931 932 933 934
  EnsureSpace ensure_space(this);
  emit_arith(7, Operand(reg), Immediate(handle));
}

935
void Assembler::cmp(Register reg, Operand op) {
936 937 938 939 940
  EnsureSpace ensure_space(this);
  EMIT(0x3B);
  emit_operand(reg, op);
}

941
void Assembler::cmp(Operand op, Register reg) {
942 943 944 945
  EnsureSpace ensure_space(this);
  EMIT(0x39);
  emit_operand(reg, op);
}
946

947
void Assembler::cmp(Operand op, const Immediate& imm) {
948 949 950 951
  EnsureSpace ensure_space(this);
  emit_arith(7, op, imm);
}

952
void Assembler::cmp(Operand op, Handle<HeapObject> handle) {
953 954 955 956
  EnsureSpace ensure_space(this);
  emit_arith(7, op, Immediate(handle));
}

957
void Assembler::cmpb_al(Operand op) {
958
  EnsureSpace ensure_space(this);
959 960
  EMIT(0x38);  // CMP r/m8, r8
  emit_operand(eax, op);  // eax has same code as register al.
961 962
}

963
void Assembler::cmpw_ax(Operand op) {
964
  EnsureSpace ensure_space(this);
965 966 967
  EMIT(0x66);
  EMIT(0x39);  // CMP r/m16, r16
  emit_operand(eax, op);  // eax has same code as register ax.
968 969 970
}


971
void Assembler::dec_b(Register dst) {
972
  CHECK(dst.is_byte_register());
973 974 975 976 977
  EnsureSpace ensure_space(this);
  EMIT(0xFE);
  EMIT(0xC8 | dst.code());
}

978
void Assembler::dec_b(Operand dst) {
979 980 981 982 983 984
  EnsureSpace ensure_space(this);
  EMIT(0xFE);
  emit_operand(ecx, dst);
}


985 986 987 988 989
void Assembler::dec(Register dst) {
  EnsureSpace ensure_space(this);
  EMIT(0x48 | dst.code());
}

990
void Assembler::dec(Operand dst) {
991 992 993 994 995 996 997 998 999 1000 1001
  EnsureSpace ensure_space(this);
  EMIT(0xFF);
  emit_operand(ecx, dst);
}


void Assembler::cdq() {
  EnsureSpace ensure_space(this);
  EMIT(0x99);
}

1002
void Assembler::idiv(Operand src) {
1003 1004 1005 1006 1007
  EnsureSpace ensure_space(this);
  EMIT(0xF7);
  emit_operand(edi, src);
}

1008
void Assembler::div(Operand src) {
1009 1010
  EnsureSpace ensure_space(this);
  EMIT(0xF7);
1011
  emit_operand(esi, src);
1012 1013 1014
}


1015 1016 1017 1018 1019 1020
void Assembler::imul(Register reg) {
  EnsureSpace ensure_space(this);
  EMIT(0xF7);
  EMIT(0xE8 | reg.code());
}

1021
void Assembler::imul(Register dst, Operand src) {
1022 1023 1024 1025 1026 1027 1028 1029
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xAF);
  emit_operand(dst, src);
}


void Assembler::imul(Register dst, Register src, int32_t imm32) {
1030 1031 1032
  imul(dst, Operand(src), imm32);
}

1033
void Assembler::imul(Register dst, Operand src, int32_t imm32) {
1034 1035 1036
  EnsureSpace ensure_space(this);
  if (is_int8(imm32)) {
    EMIT(0x6B);
1037
    emit_operand(dst, src);
1038 1039 1040
    EMIT(imm32);
  } else {
    EMIT(0x69);
1041
    emit_operand(dst, src);
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
    emit(imm32);
  }
}


void Assembler::inc(Register dst) {
  EnsureSpace ensure_space(this);
  EMIT(0x40 | dst.code());
}

1052
void Assembler::inc(Operand dst) {
1053 1054 1055 1056 1057
  EnsureSpace ensure_space(this);
  EMIT(0xFF);
  emit_operand(eax, dst);
}

1058
void Assembler::lea(Register dst, Operand src) {
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
  EnsureSpace ensure_space(this);
  EMIT(0x8D);
  emit_operand(dst, src);
}


void Assembler::mul(Register src) {
  EnsureSpace ensure_space(this);
  EMIT(0xF7);
  EMIT(0xE0 | src.code());
}


void Assembler::neg(Register dst) {
  EnsureSpace ensure_space(this);
  EMIT(0xF7);
  EMIT(0xD8 | dst.code());
}

1078
void Assembler::neg(Operand dst) {
1079 1080 1081 1082 1083 1084
  EnsureSpace ensure_space(this);
  EMIT(0xF7);
  emit_operand(ebx, dst);
}


1085 1086 1087 1088 1089 1090
void Assembler::not_(Register dst) {
  EnsureSpace ensure_space(this);
  EMIT(0xF7);
  EMIT(0xD0 | dst.code());
}

1091
void Assembler::not_(Operand dst) {
1092 1093 1094 1095 1096 1097
  EnsureSpace ensure_space(this);
  EMIT(0xF7);
  emit_operand(edx, dst);
}


1098 1099 1100 1101 1102
void Assembler::or_(Register dst, int32_t imm32) {
  EnsureSpace ensure_space(this);
  emit_arith(1, Operand(dst), Immediate(imm32));
}

1103
void Assembler::or_(Register dst, Operand src) {
1104 1105 1106 1107 1108
  EnsureSpace ensure_space(this);
  EMIT(0x0B);
  emit_operand(dst, src);
}

1109
void Assembler::or_(Operand dst, const Immediate& x) {
1110 1111 1112 1113
  EnsureSpace ensure_space(this);
  emit_arith(1, dst, x);
}

1114
void Assembler::or_(Operand dst, Register src) {
1115 1116
  EnsureSpace ensure_space(this);
  EMIT(0x09);
1117
  emit_operand(src, dst);
1118 1119 1120 1121 1122
}


void Assembler::rcl(Register dst, uint8_t imm8) {
  EnsureSpace ensure_space(this);
1123
  DCHECK(is_uint5(imm8));  // illegal shift count
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134
  if (imm8 == 1) {
    EMIT(0xD1);
    EMIT(0xD0 | dst.code());
  } else {
    EMIT(0xC1);
    EMIT(0xD0 | dst.code());
    EMIT(imm8);
  }
}


1135 1136
void Assembler::rcr(Register dst, uint8_t imm8) {
  EnsureSpace ensure_space(this);
1137
  DCHECK(is_uint5(imm8));  // illegal shift count
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
  if (imm8 == 1) {
    EMIT(0xD1);
    EMIT(0xD8 | dst.code());
  } else {
    EMIT(0xC1);
    EMIT(0xD8 | dst.code());
    EMIT(imm8);
  }
}

1148
void Assembler::ror(Operand dst, uint8_t imm8) {
1149
  EnsureSpace ensure_space(this);
1150
  DCHECK(is_uint5(imm8));  // illegal shift count
1151 1152
  if (imm8 == 1) {
    EMIT(0xD1);
1153
    emit_operand(ecx, dst);
1154 1155
  } else {
    EMIT(0xC1);
1156
    emit_operand(ecx, dst);
1157 1158 1159 1160
    EMIT(imm8);
  }
}

1161
void Assembler::ror_cl(Operand dst) {
1162 1163
  EnsureSpace ensure_space(this);
  EMIT(0xD3);
1164
  emit_operand(ecx, dst);
1165 1166
}

1167
void Assembler::sar(Operand dst, uint8_t imm8) {
1168
  EnsureSpace ensure_space(this);
1169
  DCHECK(is_uint5(imm8));  // illegal shift count
1170 1171
  if (imm8 == 1) {
    EMIT(0xD1);
1172
    emit_operand(edi, dst);
1173 1174
  } else {
    EMIT(0xC1);
1175
    emit_operand(edi, dst);
1176 1177 1178 1179
    EMIT(imm8);
  }
}

1180
void Assembler::sar_cl(Operand dst) {
1181 1182
  EnsureSpace ensure_space(this);
  EMIT(0xD3);
1183
  emit_operand(edi, dst);
1184 1185
}

1186
void Assembler::sbb(Register dst, Operand src) {
1187 1188 1189 1190 1191
  EnsureSpace ensure_space(this);
  EMIT(0x1B);
  emit_operand(dst, src);
}

1192 1193 1194 1195 1196 1197 1198 1199
void Assembler::shld(Register dst, Register src, uint8_t shift) {
  DCHECK(is_uint5(shift));
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xA4);
  emit_operand(src, Operand(dst));
  EMIT(shift);
}
1200

1201
void Assembler::shld_cl(Register dst, Register src) {
1202 1203 1204
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xA5);
1205
  emit_operand(src, Operand(dst));
1206 1207
}

1208
void Assembler::shl(Operand dst, uint8_t imm8) {
1209
  EnsureSpace ensure_space(this);
1210
  DCHECK(is_uint5(imm8));  // illegal shift count
1211 1212
  if (imm8 == 1) {
    EMIT(0xD1);
1213
    emit_operand(esp, dst);
1214 1215
  } else {
    EMIT(0xC1);
1216
    emit_operand(esp, dst);
1217 1218 1219 1220
    EMIT(imm8);
  }
}

1221
void Assembler::shl_cl(Operand dst) {
1222 1223
  EnsureSpace ensure_space(this);
  EMIT(0xD3);
1224
  emit_operand(esp, dst);
1225 1226
}

1227
void Assembler::shr(Operand dst, uint8_t imm8) {
1228
  EnsureSpace ensure_space(this);
1229
  DCHECK(is_uint5(imm8));  // illegal shift count
1230 1231
  if (imm8 == 1) {
    EMIT(0xD1);
1232
    emit_operand(ebp, dst);
1233 1234
  } else {
    EMIT(0xC1);
1235
    emit_operand(ebp, dst);
1236 1237
    EMIT(imm8);
  }
1238 1239
}

1240
void Assembler::shr_cl(Operand dst) {
1241
  EnsureSpace ensure_space(this);
1242
  EMIT(0xD3);
1243
  emit_operand(ebp, dst);
1244 1245
}

1246 1247 1248 1249 1250 1251 1252 1253 1254
void Assembler::shrd(Register dst, Register src, uint8_t shift) {
  DCHECK(is_uint5(shift));
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xAC);
  emit_operand(dst, Operand(src));
  EMIT(shift);
}

1255
void Assembler::shrd_cl(Operand dst, Register src) {
1256 1257 1258 1259 1260
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xAD);
  emit_operand(src, dst);
}
1261

1262
void Assembler::sub(Operand dst, const Immediate& x) {
1263 1264 1265 1266
  EnsureSpace ensure_space(this);
  emit_arith(5, dst, x);
}

1267
void Assembler::sub(Register dst, Operand src) {
1268 1269 1270 1271 1272
  EnsureSpace ensure_space(this);
  EMIT(0x2B);
  emit_operand(dst, src);
}

1273
void Assembler::sub(Operand dst, Register src) {
1274 1275
  EnsureSpace ensure_space(this);
  EMIT(0x29);
1276
  emit_operand(src, dst);
1277 1278
}

1279 1280 1281 1282 1283 1284 1285
void Assembler::sub_sp_32(uint32_t imm) {
  EnsureSpace ensure_space(this);
  EMIT(0x81);  // using a literal 32-bit immediate.
  static constexpr Register ireg = Register::from_code<5>();
  emit_operand(ireg, Operand(esp));
  emit(imm);
}
1286 1287

void Assembler::test(Register reg, const Immediate& imm) {
1288 1289
  if (imm.is_uint8()) {
    test_b(reg, imm);
1290 1291 1292
    return;
  }

1293
  EnsureSpace ensure_space(this);
1294 1295
  // This is not using emit_arith because test doesn't support
  // sign-extension of 8-bit operands.
1296
  if (reg == eax) {
1297
    EMIT(0xA9);
1298
  } else {
1299 1300
    EMIT(0xF7);
    EMIT(0xC0 | reg.code());
1301
  }
1302
  emit(imm);
1303 1304
}

1305
void Assembler::test(Register reg, Operand op) {
1306 1307 1308 1309 1310
  EnsureSpace ensure_space(this);
  EMIT(0x85);
  emit_operand(reg, op);
}

1311
void Assembler::test_b(Register reg, Operand op) {
1312
  CHECK(reg.is_byte_register());
1313 1314 1315 1316 1317
  EnsureSpace ensure_space(this);
  EMIT(0x84);
  emit_operand(reg, op);
}

1318
void Assembler::test(Operand op, const Immediate& imm) {
1319 1320 1321 1322
  if (op.is_reg_only()) {
    test(op.reg(), imm);
    return;
  }
1323 1324
  if (imm.is_uint8()) {
    return test_b(op, imm);
1325
  }
1326 1327 1328 1329 1330 1331
  EnsureSpace ensure_space(this);
  EMIT(0xF7);
  emit_operand(eax, op);
  emit(imm);
}

1332 1333
void Assembler::test_b(Register reg, Immediate imm8) {
  DCHECK(imm8.is_uint8());
1334 1335 1336
  EnsureSpace ensure_space(this);
  // Only use test against byte for registers that have a byte
  // variant: eax, ebx, ecx, and edx.
1337
  if (reg == eax) {
1338
    EMIT(0xA8);
1339
    emit_b(imm8);
1340
  } else if (reg.is_byte_register()) {
1341
    emit_arith_b(0xF6, 0xC0, reg, static_cast<uint8_t>(imm8.immediate()));
1342
  } else {
1343
    EMIT(0x66);
1344 1345
    EMIT(0xF7);
    EMIT(0xC0 | reg.code());
1346
    emit_w(imm8);
1347 1348 1349
  }
}

1350
void Assembler::test_b(Operand op, Immediate imm8) {
1351 1352
  if (op.is_reg_only()) {
    test_b(op.reg(), imm8);
1353 1354
    return;
  }
1355 1356 1357
  EnsureSpace ensure_space(this);
  EMIT(0xF6);
  emit_operand(eax, op);
1358
  emit_b(imm8);
1359 1360
}

1361 1362 1363
void Assembler::test_w(Register reg, Immediate imm16) {
  DCHECK(imm16.is_int16() || imm16.is_uint16());
  EnsureSpace ensure_space(this);
1364
  if (reg == eax) {
1365 1366 1367 1368 1369
    EMIT(0xA9);
    emit_w(imm16);
  } else {
    EMIT(0x66);
    EMIT(0xF7);
1370
    EMIT(0xC0 | reg.code());
1371 1372 1373 1374
    emit_w(imm16);
  }
}

1375
void Assembler::test_w(Register reg, Operand op) {
1376 1377 1378 1379 1380 1381
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x85);
  emit_operand(reg, op);
}

1382
void Assembler::test_w(Operand op, Immediate imm16) {
1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393
  DCHECK(imm16.is_int16() || imm16.is_uint16());
  if (op.is_reg_only()) {
    test_w(op.reg(), imm16);
    return;
  }
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0xF7);
  emit_operand(eax, op);
  emit_w(imm16);
}
1394

1395 1396 1397 1398 1399
void Assembler::xor_(Register dst, int32_t imm32) {
  EnsureSpace ensure_space(this);
  emit_arith(6, Operand(dst), Immediate(imm32));
}

1400
void Assembler::xor_(Register dst, Operand src) {
1401 1402 1403 1404 1405
  EnsureSpace ensure_space(this);
  EMIT(0x33);
  emit_operand(dst, src);
}

1406
void Assembler::xor_(Operand dst, Register src) {
1407 1408
  EnsureSpace ensure_space(this);
  EMIT(0x31);
1409
  emit_operand(src, dst);
1410 1411
}

1412
void Assembler::xor_(Operand dst, const Immediate& x) {
1413 1414 1415 1416
  EnsureSpace ensure_space(this);
  emit_arith(6, dst, x);
}

1417 1418 1419 1420 1421 1422
void Assembler::bswap(Register dst) {
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xC8 + dst.code());
}

1423
void Assembler::bt(Operand dst, Register src) {
1424 1425 1426 1427 1428 1429
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xA3);
  emit_operand(src, dst);
}

1430
void Assembler::bts(Operand dst, Register src) {
1431 1432 1433 1434 1435 1436
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xAB);
  emit_operand(src, dst);
}

1437
void Assembler::bsr(Register dst, Operand src) {
1438 1439 1440 1441 1442 1443
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xBD);
  emit_operand(dst, src);
}

1444
void Assembler::bsf(Register dst, Operand src) {
1445 1446 1447 1448 1449 1450 1451
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xBC);
  emit_operand(dst, src);
}


1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471
void Assembler::hlt() {
  EnsureSpace ensure_space(this);
  EMIT(0xF4);
}


void Assembler::int3() {
  EnsureSpace ensure_space(this);
  EMIT(0xCC);
}


void Assembler::nop() {
  EnsureSpace ensure_space(this);
  EMIT(0x90);
}


void Assembler::ret(int imm16) {
  EnsureSpace ensure_space(this);
1472
  DCHECK(is_uint16(imm16));
1473 1474 1475 1476 1477 1478 1479 1480 1481 1482
  if (imm16 == 0) {
    EMIT(0xC3);
  } else {
    EMIT(0xC2);
    EMIT(imm16 & 0xFF);
    EMIT((imm16 >> 8) & 0xFF);
  }
}


1483 1484 1485 1486 1487 1488 1489
void Assembler::ud2() {
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0x0B);
}


1490 1491 1492 1493 1494 1495 1496 1497 1498 1499
// Labels refer to positions in the (to be) generated code.
// There are bound, linked, and unused labels.
//
// Bound labels refer to known positions in the already
// generated code. pos() is the position the label refers to.
//
// Linked labels refer to unknown positions in the code
// to be generated; pos() is the position of the 32bit
// Displacement of the last instruction using the label.

1500
void Assembler::print(const Label* L) {
1501 1502 1503 1504 1505
  if (L->is_unused()) {
    PrintF("unused label\n");
  } else if (L->is_bound()) {
    PrintF("bound label to %d\n", L->pos());
  } else if (L->is_linked()) {
1506 1507
    Label l;
    l.link_to(L->pos());
1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523
    PrintF("unbound label");
    while (l.is_linked()) {
      Displacement disp = disp_at(&l);
      PrintF("@ %d ", l.pos());
      disp.print();
      PrintF("\n");
      disp.next(&l);
    }
  } else {
    PrintF("label in inconsistent state (pos = %d)\n", L->pos_);
  }
}


void Assembler::bind_to(Label* L, int pos) {
  EnsureSpace ensure_space(this);
1524
  DCHECK(0 <= pos && pos <= pc_offset());  // must have a valid binding position
1525 1526 1527
  while (L->is_linked()) {
    Displacement disp = disp_at(L);
    int fixup_pos = L->pos();
1528 1529 1530 1531
    if (disp.type() == Displacement::CODE_ABSOLUTE) {
      long_at_put(fixup_pos, reinterpret_cast<int>(buffer_ + pos));
      internal_reference_positions_.push_back(fixup_pos);
    } else if (disp.type() == Displacement::CODE_RELATIVE) {
1532 1533
      // Relative to Code* heap object pointer.
      long_at_put(fixup_pos, pos + Code::kHeaderSize - kHeapObjectTag);
1534 1535
    } else {
      if (disp.type() == Displacement::UNCONDITIONAL_JUMP) {
1536
        DCHECK_EQ(byte_at(fixup_pos - 1), 0xE9);  // jmp expected
1537
      }
1538
      // Relative address, relative to point after address.
1539 1540
      int imm32 = pos - (fixup_pos + sizeof(int32_t));
      long_at_put(fixup_pos, imm32);
1541 1542 1543
    }
    disp.next(L);
  }
1544 1545 1546 1547
  while (L->is_near_linked()) {
    int fixup_pos = L->near_link_pos();
    int offset_to_next =
        static_cast<int>(*reinterpret_cast<int8_t*>(addr_at(fixup_pos)));
1548
    DCHECK_LE(offset_to_next, 0);
1549 1550
    // Relative address, relative to point after address.
    int disp = pos - fixup_pos - sizeof(int8_t);
1551
    CHECK(0 <= disp && disp <= 127);
1552 1553 1554 1555 1556 1557 1558
    set_byte_at(fixup_pos, disp);
    if (offset_to_next < 0) {
      L->link_to(fixup_pos + offset_to_next, Label::kNear);
    } else {
      L->UnuseNear();
    }
  }
1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573

  // Optimization stage
  auto jump_opt = jump_optimization_info();
  if (jump_opt && jump_opt->is_optimizing()) {
    auto it = label_farjmp_maps_.find(L);
    if (it != label_farjmp_maps_.end()) {
      auto& pos_vector = it->second;
      for (auto fixup_pos : pos_vector) {
        int disp = pos - (fixup_pos + sizeof(int8_t));
        CHECK(is_int8(disp));
        set_byte_at(fixup_pos, disp);
      }
      label_farjmp_maps_.erase(it);
    }
  }
1574 1575 1576 1577 1578 1579
  L->bind_to(pos);
}


void Assembler::bind(Label* L) {
  EnsureSpace ensure_space(this);
1580
  DCHECK(!L->is_bound());  // label can only be bound once
1581 1582 1583
  bind_to(L, pc_offset());
}

1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598
void Assembler::record_farjmp_position(Label* L, int pos) {
  auto& pos_vector = label_farjmp_maps_[L];
  pos_vector.push_back(pos);
}

bool Assembler::is_optimizable_farjmp(int idx) {
  if (predictable_code_size()) return false;

  auto jump_opt = jump_optimization_info();
  CHECK(jump_opt->is_optimizing());

  auto& bitmap = jump_opt->farjmp_bitmap();
  CHECK(idx < static_cast<int>(bitmap.size() * 32));
  return !!(bitmap[idx / 32] & (1 << (idx & 31)));
}
1599 1600 1601 1602 1603 1604

void Assembler::call(Label* L) {
  EnsureSpace ensure_space(this);
  if (L->is_bound()) {
    const int long_size = 5;
    int offs = L->pos() - pc_offset();
1605
    DCHECK_LE(offs, 0);
1606
    // 1110 1000 #32-bit disp.
1607 1608 1609
    EMIT(0xE8);
    emit(offs - long_size);
  } else {
1610
    // 1110 1000 #32-bit disp.
1611 1612 1613 1614 1615
    EMIT(0xE8);
    emit_disp(L, Displacement::OTHER);
  }
}

1616
void Assembler::call(Address entry, RelocInfo::Mode rmode) {
1617
  EnsureSpace ensure_space(this);
1618
  DCHECK(!RelocInfo::IsCodeTarget(rmode));
1619
  EMIT(0xE8);
1620
  if (RelocInfo::IsRuntimeEntry(rmode)) {
1621
    emit(entry, rmode);
1622
  } else {
1623
    emit(entry - (reinterpret_cast<Address>(pc_) + sizeof(int32_t)), rmode);
1624
  }
1625 1626
}

1627 1628 1629
void Assembler::wasm_call(Address entry, RelocInfo::Mode rmode) {
  EnsureSpace ensure_space(this);
  EMIT(0xE8);
1630
  emit(entry, rmode);
1631
}
1632

1633
void Assembler::call(Operand adr) {
1634 1635 1636
  EnsureSpace ensure_space(this);
  EMIT(0xFF);
  emit_operand(edx, adr);
1637 1638
}

1639
void Assembler::call(Handle<Code> code, RelocInfo::Mode rmode) {
1640
  EnsureSpace ensure_space(this);
1641
  DCHECK(RelocInfo::IsCodeTarget(rmode));
1642
  EMIT(0xE8);
1643
  emit(code, rmode);
1644 1645
}

1646 1647 1648 1649 1650
void Assembler::call(CodeStub* stub) {
  EnsureSpace ensure_space(this);
  EMIT(0xE8);
  emit(Immediate::EmbeddedCode(stub));
}
1651

1652
void Assembler::jmp_rel(int offset) {
1653
  EnsureSpace ensure_space(this);
1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667
  const int short_size = 2;
  const int long_size = 5;
  if (is_int8(offset - short_size)) {
    // 1110 1011 #8-bit disp.
    EMIT(0xEB);
    EMIT((offset - short_size) & 0xFF);
  } else {
    // 1110 1001 #32-bit disp.
    EMIT(0xE9);
    emit(offset - long_size);
  }
}

void Assembler::jmp(Label* L, Label::Distance distance) {
1668
  if (L->is_bound()) {
1669 1670 1671 1672 1673 1674 1675 1676
    int offset = L->pos() - pc_offset();
    DCHECK_LE(offset, 0);  // backward jump.
    jmp_rel(offset);
    return;
  }

  EnsureSpace ensure_space(this);
  if (distance == Label::kNear) {
1677 1678
    EMIT(0xEB);
    emit_near_disp(L);
1679
  } else {
1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691
    auto jump_opt = jump_optimization_info();
    if (V8_UNLIKELY(jump_opt)) {
      if (jump_opt->is_optimizing() && is_optimizable_farjmp(farjmp_num_++)) {
        EMIT(0xEB);
        record_farjmp_position(L, pc_offset());
        EMIT(0);
        return;
      }
      if (jump_opt->is_collecting()) {
        farjmp_positions_.push_back(pc_offset() + 1);
      }
    }
1692
    // 1110 1001 #32-bit disp.
1693 1694 1695 1696 1697
    EMIT(0xE9);
    emit_disp(L, Displacement::UNCONDITIONAL_JUMP);
  }
}

1698
void Assembler::jmp(Address entry, RelocInfo::Mode rmode) {
1699
  EnsureSpace ensure_space(this);
1700
  DCHECK(!RelocInfo::IsCodeTarget(rmode));
1701
  EMIT(0xE9);
1702
  if (RelocInfo::IsRuntimeEntry(rmode)) {
1703
    emit(entry, rmode);
1704
  } else {
1705
    emit(entry - (reinterpret_cast<Address>(pc_) + sizeof(int32_t)), rmode);
1706
  }
1707 1708
}

1709
void Assembler::jmp(Operand adr) {
1710 1711 1712 1713 1714 1715
  EnsureSpace ensure_space(this);
  EMIT(0xFF);
  emit_operand(esp, adr);
}


1716
void Assembler::jmp(Handle<Code> code, RelocInfo::Mode rmode) {
1717
  EnsureSpace ensure_space(this);
1718
  DCHECK(RelocInfo::IsCodeTarget(rmode));
1719
  EMIT(0xE9);
1720
  emit(code, rmode);
1721 1722 1723
}


1724
void Assembler::j(Condition cc, Label* L, Label::Distance distance) {
1725
  EnsureSpace ensure_space(this);
1726
  DCHECK(0 <= cc && static_cast<int>(cc) < 16);
1727 1728 1729 1730
  if (L->is_bound()) {
    const int short_size = 2;
    const int long_size  = 6;
    int offs = L->pos() - pc_offset();
1731
    DCHECK_LE(offs, 0);
1732 1733 1734 1735 1736 1737 1738 1739 1740 1741
    if (is_int8(offs - short_size)) {
      // 0111 tttn #8-bit disp
      EMIT(0x70 | cc);
      EMIT((offs - short_size) & 0xFF);
    } else {
      // 0000 1111 1000 tttn #32-bit disp
      EMIT(0x0F);
      EMIT(0x80 | cc);
      emit(offs - long_size);
    }
1742 1743 1744
  } else if (distance == Label::kNear) {
    EMIT(0x70 | cc);
    emit_near_disp(L);
1745
  } else {
1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758
    auto jump_opt = jump_optimization_info();
    if (V8_UNLIKELY(jump_opt)) {
      if (jump_opt->is_optimizing() && is_optimizable_farjmp(farjmp_num_++)) {
        // 0111 tttn #8-bit disp
        EMIT(0x70 | cc);
        record_farjmp_position(L, pc_offset());
        EMIT(0);
        return;
      }
      if (jump_opt->is_collecting()) {
        farjmp_positions_.push_back(pc_offset() + 2);
      }
    }
1759 1760 1761 1762 1763 1764 1765 1766 1767 1768
    // 0000 1111 1000 tttn #32-bit disp
    // Note: could eliminate cond. jumps to this jump if condition
    //       is the same however, seems to be rather unlikely case.
    EMIT(0x0F);
    EMIT(0x80 | cc);
    emit_disp(L, Displacement::OTHER);
  }
}


1769
void Assembler::j(Condition cc, byte* entry, RelocInfo::Mode rmode) {
1770
  EnsureSpace ensure_space(this);
1771
  DCHECK((0 <= cc) && (static_cast<int>(cc) < 16));
1772
  // 0000 1111 1000 tttn #32-bit disp.
1773 1774
  EMIT(0x0F);
  EMIT(0x80 | cc);
1775 1776 1777 1778 1779
  if (RelocInfo::IsRuntimeEntry(rmode)) {
    emit(reinterpret_cast<uint32_t>(entry), rmode);
  } else {
    emit(entry - (pc_ + sizeof(int32_t)), rmode);
  }
1780 1781 1782
}


1783
void Assembler::j(Condition cc, Handle<Code> code, RelocInfo::Mode rmode) {
1784 1785 1786 1787
  EnsureSpace ensure_space(this);
  // 0000 1111 1000 tttn #32-bit disp
  EMIT(0x0F);
  EMIT(0x80 | cc);
1788
  emit(code, rmode);
1789 1790 1791
}


1792
// FPU instructions.
1793 1794 1795 1796 1797 1798 1799

void Assembler::fld(int i) {
  EnsureSpace ensure_space(this);
  emit_farith(0xD9, 0xC0, i);
}


1800 1801 1802 1803 1804 1805
void Assembler::fstp(int i) {
  EnsureSpace ensure_space(this);
  emit_farith(0xDD, 0xD8, i);
}


1806 1807 1808 1809 1810 1811 1812
void Assembler::fld1() {
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  EMIT(0xE8);
}


1813 1814 1815 1816 1817 1818 1819
void Assembler::fldpi() {
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  EMIT(0xEB);
}


1820 1821 1822 1823 1824 1825 1826
void Assembler::fldz() {
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  EMIT(0xEE);
}


1827 1828 1829 1830 1831 1832
void Assembler::fldln2() {
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  EMIT(0xED);
}

1833
void Assembler::fld_s(Operand adr) {
1834 1835 1836 1837 1838
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  emit_operand(eax, adr);
}

1839
void Assembler::fld_d(Operand adr) {
1840 1841 1842 1843 1844
  EnsureSpace ensure_space(this);
  EMIT(0xDD);
  emit_operand(eax, adr);
}

1845
void Assembler::fstp_s(Operand adr) {
1846 1847 1848 1849 1850
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  emit_operand(ebx, adr);
}

1851
void Assembler::fst_s(Operand adr) {
1852 1853 1854 1855 1856
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  emit_operand(edx, adr);
}

1857
void Assembler::fstp_d(Operand adr) {
1858 1859 1860 1861 1862
  EnsureSpace ensure_space(this);
  EMIT(0xDD);
  emit_operand(ebx, adr);
}

1863
void Assembler::fst_d(Operand adr) {
1864 1865 1866 1867 1868
  EnsureSpace ensure_space(this);
  EMIT(0xDD);
  emit_operand(edx, adr);
}

1869
void Assembler::fild_s(Operand adr) {
1870 1871 1872 1873 1874
  EnsureSpace ensure_space(this);
  EMIT(0xDB);
  emit_operand(eax, adr);
}

1875
void Assembler::fild_d(Operand adr) {
1876 1877 1878 1879 1880
  EnsureSpace ensure_space(this);
  EMIT(0xDF);
  emit_operand(ebp, adr);
}

1881
void Assembler::fistp_s(Operand adr) {
1882 1883 1884 1885 1886
  EnsureSpace ensure_space(this);
  EMIT(0xDB);
  emit_operand(ebx, adr);
}

1887
void Assembler::fisttp_s(Operand adr) {
1888
  DCHECK(IsEnabled(SSE3));
1889 1890 1891 1892 1893
  EnsureSpace ensure_space(this);
  EMIT(0xDB);
  emit_operand(ecx, adr);
}

1894
void Assembler::fisttp_d(Operand adr) {
1895
  DCHECK(IsEnabled(SSE3));
1896 1897 1898 1899 1900
  EnsureSpace ensure_space(this);
  EMIT(0xDD);
  emit_operand(ecx, adr);
}

1901
void Assembler::fist_s(Operand adr) {
1902 1903 1904 1905 1906
  EnsureSpace ensure_space(this);
  EMIT(0xDB);
  emit_operand(edx, adr);
}

1907
void Assembler::fistp_d(Operand adr) {
1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927
  EnsureSpace ensure_space(this);
  EMIT(0xDF);
  emit_operand(edi, adr);
}


void Assembler::fabs() {
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  EMIT(0xE1);
}


void Assembler::fchs() {
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  EMIT(0xE0);
}


1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941
void Assembler::fcos() {
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  EMIT(0xFF);
}


void Assembler::fsin() {
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  EMIT(0xFE);
}


1942 1943 1944 1945 1946 1947 1948
void Assembler::fptan() {
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  EMIT(0xF2);
}


1949 1950 1951 1952 1953 1954 1955
void Assembler::fyl2x() {
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  EMIT(0xF1);
}


1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976
void Assembler::f2xm1() {
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  EMIT(0xF0);
}


void Assembler::fscale() {
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  EMIT(0xFD);
}


void Assembler::fninit() {
  EnsureSpace ensure_space(this);
  EMIT(0xDB);
  EMIT(0xE3);
}


1977 1978 1979 1980 1981 1982
void Assembler::fadd(int i) {
  EnsureSpace ensure_space(this);
  emit_farith(0xDC, 0xC0, i);
}


1983 1984 1985 1986 1987 1988
void Assembler::fadd_i(int i) {
  EnsureSpace ensure_space(this);
  emit_farith(0xD8, 0xC0, i);
}


1989 1990 1991 1992 1993 1994
void Assembler::fsub(int i) {
  EnsureSpace ensure_space(this);
  emit_farith(0xDC, 0xE8, i);
}


1995 1996 1997 1998 1999
void Assembler::fsub_i(int i) {
  EnsureSpace ensure_space(this);
  emit_farith(0xD8, 0xE0, i);
}

2000
void Assembler::fisub_s(Operand adr) {
2001 2002 2003 2004 2005 2006
  EnsureSpace ensure_space(this);
  EMIT(0xDA);
  emit_operand(esp, adr);
}


2007 2008 2009 2010 2011 2012
void Assembler::fmul_i(int i) {
  EnsureSpace ensure_space(this);
  emit_farith(0xD8, 0xC8, i);
}


2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024
void Assembler::fmul(int i) {
  EnsureSpace ensure_space(this);
  emit_farith(0xDC, 0xC8, i);
}


void Assembler::fdiv(int i) {
  EnsureSpace ensure_space(this);
  emit_farith(0xDC, 0xF8, i);
}


2025 2026 2027 2028 2029 2030
void Assembler::fdiv_i(int i) {
  EnsureSpace ensure_space(this);
  emit_farith(0xD8, 0xF0, i);
}


2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113
void Assembler::faddp(int i) {
  EnsureSpace ensure_space(this);
  emit_farith(0xDE, 0xC0, i);
}


void Assembler::fsubp(int i) {
  EnsureSpace ensure_space(this);
  emit_farith(0xDE, 0xE8, i);
}


void Assembler::fsubrp(int i) {
  EnsureSpace ensure_space(this);
  emit_farith(0xDE, 0xE0, i);
}


void Assembler::fmulp(int i) {
  EnsureSpace ensure_space(this);
  emit_farith(0xDE, 0xC8, i);
}


void Assembler::fdivp(int i) {
  EnsureSpace ensure_space(this);
  emit_farith(0xDE, 0xF8, i);
}


void Assembler::fprem() {
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  EMIT(0xF8);
}


void Assembler::fprem1() {
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  EMIT(0xF5);
}


void Assembler::fxch(int i) {
  EnsureSpace ensure_space(this);
  emit_farith(0xD9, 0xC8, i);
}


void Assembler::fincstp() {
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  EMIT(0xF7);
}


void Assembler::ffree(int i) {
  EnsureSpace ensure_space(this);
  emit_farith(0xDD, 0xC0, i);
}


void Assembler::ftst() {
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  EMIT(0xE4);
}


void Assembler::fucomp(int i) {
  EnsureSpace ensure_space(this);
  emit_farith(0xDD, 0xE8, i);
}


void Assembler::fucompp() {
  EnsureSpace ensure_space(this);
  EMIT(0xDA);
  EMIT(0xE9);
}


2114 2115 2116 2117 2118 2119 2120
void Assembler::fucomi(int i) {
  EnsureSpace ensure_space(this);
  EMIT(0xDB);
  EMIT(0xE8 + i);
}


2121 2122 2123 2124 2125 2126 2127
void Assembler::fucomip() {
  EnsureSpace ensure_space(this);
  EMIT(0xDF);
  EMIT(0xE9);
}


2128 2129 2130 2131 2132 2133 2134 2135 2136
void Assembler::fcompp() {
  EnsureSpace ensure_space(this);
  EMIT(0xDE);
  EMIT(0xD9);
}


void Assembler::fnstsw_ax() {
  EnsureSpace ensure_space(this);
2137
  EMIT(0xDF);
2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154
  EMIT(0xE0);
}


void Assembler::fwait() {
  EnsureSpace ensure_space(this);
  EMIT(0x9B);
}


void Assembler::frndint() {
  EnsureSpace ensure_space(this);
  EMIT(0xD9);
  EMIT(0xFC);
}


2155 2156 2157 2158 2159 2160 2161
void Assembler::fnclex() {
  EnsureSpace ensure_space(this);
  EMIT(0xDB);
  EMIT(0xE2);
}


2162 2163 2164 2165 2166 2167
void Assembler::sahf() {
  EnsureSpace ensure_space(this);
  EMIT(0x9E);
}


2168
void Assembler::setcc(Condition cc, Register reg) {
2169
  DCHECK(reg.is_byte_register());
2170 2171 2172 2173 2174 2175
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0x90 | cc);
  EMIT(0xC0 | reg.code());
}

2176
void Assembler::cvttss2si(Register dst, Operand src) {
2177
  EnsureSpace ensure_space(this);
2178 2179
  // The [src] might contain ebx's register code, but in
  // this case, it refers to xmm3, so it is OK to emit.
2180 2181 2182 2183 2184 2185
  EMIT(0xF3);
  EMIT(0x0F);
  EMIT(0x2C);
  emit_operand(dst, src);
}

2186
void Assembler::cvttsd2si(Register dst, Operand src) {
2187
  EnsureSpace ensure_space(this);
2188 2189
  // The [src] might contain ebx's register code, but in
  // this case, it refers to xmm3, so it is OK to emit.
2190 2191 2192 2193 2194 2195 2196
  EMIT(0xF2);
  EMIT(0x0F);
  EMIT(0x2C);
  emit_operand(dst, src);
}


2197 2198 2199 2200 2201 2202 2203 2204
void Assembler::cvtsd2si(Register dst, XMMRegister src) {
  EnsureSpace ensure_space(this);
  EMIT(0xF2);
  EMIT(0x0F);
  EMIT(0x2D);
  emit_sse_operand(dst, src);
}

2205
void Assembler::cvtsi2ss(XMMRegister dst, Operand src) {
2206 2207 2208 2209 2210 2211 2212
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0x0F);
  EMIT(0x2A);
  emit_sse_operand(dst, src);
}

2213
void Assembler::cvtsi2sd(XMMRegister dst, Operand src) {
2214 2215 2216 2217 2218 2219 2220
  EnsureSpace ensure_space(this);
  EMIT(0xF2);
  EMIT(0x0F);
  EMIT(0x2A);
  emit_sse_operand(dst, src);
}

2221
void Assembler::cvtss2sd(XMMRegister dst, Operand src) {
2222 2223 2224 2225 2226 2227 2228
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0x0F);
  EMIT(0x5A);
  emit_sse_operand(dst, src);
}

2229
void Assembler::cvtsd2ss(XMMRegister dst, Operand src) {
2230 2231 2232 2233 2234 2235 2236
  EnsureSpace ensure_space(this);
  EMIT(0xF2);
  EMIT(0x0F);
  EMIT(0x5A);
  emit_sse_operand(dst, src);
}

2237
void Assembler::cvtdq2ps(XMMRegister dst, Operand src) {
2238 2239 2240 2241 2242 2243
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0x5B);
  emit_sse_operand(dst, src);
}

2244
void Assembler::cvttps2dq(XMMRegister dst, Operand src) {
2245 2246 2247 2248 2249 2250
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0x0F);
  EMIT(0x5B);
  emit_sse_operand(dst, src);
}
2251

2252
void Assembler::addsd(XMMRegister dst, Operand src) {
2253 2254 2255 2256 2257 2258 2259
  EnsureSpace ensure_space(this);
  EMIT(0xF2);
  EMIT(0x0F);
  EMIT(0x58);
  emit_sse_operand(dst, src);
}

2260
void Assembler::mulsd(XMMRegister dst, Operand src) {
2261 2262 2263 2264 2265 2266 2267
  EnsureSpace ensure_space(this);
  EMIT(0xF2);
  EMIT(0x0F);
  EMIT(0x59);
  emit_sse_operand(dst, src);
}

2268
void Assembler::subsd(XMMRegister dst, Operand src) {
2269 2270 2271 2272 2273 2274 2275
  EnsureSpace ensure_space(this);
  EMIT(0xF2);
  EMIT(0x0F);
  EMIT(0x5C);
  emit_sse_operand(dst, src);
}

2276
void Assembler::divsd(XMMRegister dst, Operand src) {
2277 2278 2279 2280 2281 2282 2283
  EnsureSpace ensure_space(this);
  EMIT(0xF2);
  EMIT(0x0F);
  EMIT(0x5E);
  emit_sse_operand(dst, src);
}

2284
void Assembler::xorpd(XMMRegister dst, Operand src) {
2285 2286 2287 2288 2289 2290 2291
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x57);
  emit_sse_operand(dst, src);
}

2292
void Assembler::andps(XMMRegister dst, Operand src) {
2293 2294 2295 2296 2297 2298
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0x54);
  emit_sse_operand(dst, src);
}

2299
void Assembler::orps(XMMRegister dst, Operand src) {
2300 2301 2302 2303 2304 2305
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0x56);
  emit_sse_operand(dst, src);
}

2306
void Assembler::xorps(XMMRegister dst, Operand src) {
2307 2308 2309 2310 2311 2312
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0x57);
  emit_sse_operand(dst, src);
}

2313
void Assembler::addps(XMMRegister dst, Operand src) {
2314 2315
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
2316
  EMIT(0x58);
2317 2318 2319
  emit_sse_operand(dst, src);
}

2320
void Assembler::subps(XMMRegister dst, Operand src) {
2321 2322
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
2323
  EMIT(0x5C);
2324 2325 2326
  emit_sse_operand(dst, src);
}

2327
void Assembler::mulps(XMMRegister dst, Operand src) {
2328 2329 2330 2331 2332 2333
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0x59);
  emit_sse_operand(dst, src);
}

2334
void Assembler::divps(XMMRegister dst, Operand src) {
2335 2336 2337 2338 2339 2340
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0x5E);
  emit_sse_operand(dst, src);
}

2341
void Assembler::rcpps(XMMRegister dst, Operand src) {
2342 2343 2344 2345 2346 2347
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0x53);
  emit_sse_operand(dst, src);
}

2348
void Assembler::rsqrtps(XMMRegister dst, Operand src) {
2349 2350 2351 2352 2353 2354
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0x52);
  emit_sse_operand(dst, src);
}

2355
void Assembler::minps(XMMRegister dst, Operand src) {
2356 2357 2358 2359 2360 2361
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0x5D);
  emit_sse_operand(dst, src);
}

2362
void Assembler::maxps(XMMRegister dst, Operand src) {
2363 2364 2365 2366 2367
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0x5F);
  emit_sse_operand(dst, src);
}
2368

2369
void Assembler::cmpps(XMMRegister dst, Operand src, uint8_t cmp) {
2370 2371 2372 2373 2374 2375 2376
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xC2);
  emit_sse_operand(dst, src);
  EMIT(cmp);
}

2377
void Assembler::sqrtsd(XMMRegister dst, Operand src) {
2378 2379 2380 2381 2382 2383 2384
  EnsureSpace ensure_space(this);
  EMIT(0xF2);
  EMIT(0x0F);
  EMIT(0x51);
  emit_sse_operand(dst, src);
}

2385
void Assembler::haddps(XMMRegister dst, Operand src) {
2386
  DCHECK(IsEnabled(SSE3));
2387 2388 2389 2390 2391 2392
  EnsureSpace ensure_space(this);
  EMIT(0xF2);
  EMIT(0x0F);
  EMIT(0x7C);
  emit_sse_operand(dst, src);
}
2393

2394
void Assembler::andpd(XMMRegister dst, Operand src) {
2395 2396 2397
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
2398
  EMIT(0x54);
2399 2400 2401
  emit_sse_operand(dst, src);
}

2402
void Assembler::orpd(XMMRegister dst, Operand src) {
2403 2404 2405
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
2406
  EMIT(0x56);
2407 2408 2409
  emit_sse_operand(dst, src);
}

2410
void Assembler::ucomisd(XMMRegister dst, Operand src) {
2411 2412 2413 2414 2415 2416 2417 2418
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x2E);
  emit_sse_operand(dst, src);
}


2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431
void Assembler::roundss(XMMRegister dst, XMMRegister src, RoundingMode mode) {
  DCHECK(IsEnabled(SSE4_1));
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x3A);
  EMIT(0x0A);
  emit_sse_operand(dst, src);
  // Mask precision exeption.
  EMIT(static_cast<byte>(mode) | 0x8);
}


2432
void Assembler::roundsd(XMMRegister dst, XMMRegister src, RoundingMode mode) {
2433
  DCHECK(IsEnabled(SSE4_1));
2434 2435 2436 2437 2438 2439 2440 2441 2442 2443
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x3A);
  EMIT(0x0B);
  emit_sse_operand(dst, src);
  // Mask precision exeption.
  EMIT(static_cast<byte>(mode) | 0x8);
}

2444

2445 2446 2447 2448 2449 2450 2451 2452 2453
void Assembler::movmskpd(Register dst, XMMRegister src) {
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x50);
  emit_sse_operand(dst, src);
}


2454 2455 2456 2457 2458 2459 2460
void Assembler::movmskps(Register dst, XMMRegister src) {
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0x50);
  emit_sse_operand(dst, src);
}

2461
void Assembler::maxsd(XMMRegister dst, Operand src) {
2462 2463 2464 2465 2466 2467 2468
  EnsureSpace ensure_space(this);
  EMIT(0xF2);
  EMIT(0x0F);
  EMIT(0x5F);
  emit_sse_operand(dst, src);
}

2469
void Assembler::minsd(XMMRegister dst, Operand src) {
2470 2471 2472 2473 2474 2475 2476 2477
  EnsureSpace ensure_space(this);
  EMIT(0xF2);
  EMIT(0x0F);
  EMIT(0x5D);
  emit_sse_operand(dst, src);
}


2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494
void Assembler::cmpltsd(XMMRegister dst, XMMRegister src) {
  EnsureSpace ensure_space(this);
  EMIT(0xF2);
  EMIT(0x0F);
  EMIT(0xC2);
  emit_sse_operand(dst, src);
  EMIT(1);  // LT == 1
}


void Assembler::movaps(XMMRegister dst, XMMRegister src) {
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0x28);
  emit_sse_operand(dst, src);
}

2495 2496 2497
void Assembler::movups(XMMRegister dst, XMMRegister src) {
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
2498
  EMIT(0x10);
2499 2500 2501
  emit_sse_operand(dst, src);
}

2502
void Assembler::movups(XMMRegister dst, Operand src) {
2503 2504 2505 2506 2507 2508
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0x10);
  emit_sse_operand(dst, src);
}

2509
void Assembler::movups(Operand dst, XMMRegister src) {
2510 2511 2512 2513 2514
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0x11);
  emit_sse_operand(src, dst);
}
2515

2516
void Assembler::shufps(XMMRegister dst, XMMRegister src, byte imm8) {
2517
  DCHECK(is_uint8(imm8));
2518 2519 2520 2521 2522 2523 2524
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0xC6);
  emit_sse_operand(dst, src);
  EMIT(imm8);
}

2525
void Assembler::movdqa(Operand dst, XMMRegister src) {
2526 2527 2528 2529 2530 2531 2532
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x7F);
  emit_sse_operand(src, dst);
}

2533
void Assembler::movdqa(XMMRegister dst, Operand src) {
2534 2535 2536 2537 2538 2539 2540
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x6F);
  emit_sse_operand(dst, src);
}

2541
void Assembler::movdqu(Operand dst, XMMRegister src) {
2542 2543 2544 2545 2546 2547 2548
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0x0F);
  EMIT(0x7F);
  emit_sse_operand(src, dst);
}

2549
void Assembler::movdqu(XMMRegister dst, Operand src) {
2550 2551 2552 2553 2554 2555 2556
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0x0F);
  EMIT(0x6F);
  emit_sse_operand(dst, src);
}

2557
void Assembler::prefetch(Operand src, int level) {
2558
  DCHECK(is_uint2(level));
2559 2560 2561
  EnsureSpace ensure_space(this);
  EMIT(0x0F);
  EMIT(0x18);
2562 2563
  // Emit hint number in Reg position of RegR/M.
  XMMRegister code = XMMRegister::from_code(level);
2564 2565 2566
  emit_sse_operand(code, src);
}

2567
void Assembler::movsd(Operand dst, XMMRegister src) {
2568 2569 2570 2571 2572 2573 2574
  EnsureSpace ensure_space(this);
  EMIT(0xF2);  // double
  EMIT(0x0F);
  EMIT(0x11);  // store
  emit_sse_operand(src, dst);
}

2575
void Assembler::movsd(XMMRegister dst, Operand src) {
2576 2577 2578 2579 2580 2581 2582
  EnsureSpace ensure_space(this);
  EMIT(0xF2);  // double
  EMIT(0x0F);
  EMIT(0x10);  // load
  emit_sse_operand(dst, src);
}

2583
void Assembler::movss(Operand dst, XMMRegister src) {
2584 2585 2586 2587 2588 2589 2590
  EnsureSpace ensure_space(this);
  EMIT(0xF3);  // float
  EMIT(0x0F);
  EMIT(0x11);  // store
  emit_sse_operand(src, dst);
}

2591
void Assembler::movss(XMMRegister dst, Operand src) {
2592 2593 2594 2595 2596 2597 2598
  EnsureSpace ensure_space(this);
  EMIT(0xF3);  // float
  EMIT(0x0F);
  EMIT(0x10);  // load
  emit_sse_operand(dst, src);
}

2599
void Assembler::movd(XMMRegister dst, Operand src) {
2600 2601 2602 2603 2604 2605 2606
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x6E);
  emit_sse_operand(dst, src);
}

2607
void Assembler::movd(Operand dst, XMMRegister src) {
2608 2609 2610 2611 2612 2613 2614 2615
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x7E);
  emit_sse_operand(src, dst);
}


2616
void Assembler::extractps(Register dst, XMMRegister src, byte imm8) {
2617 2618
  DCHECK(IsEnabled(SSE4_1));
  DCHECK(is_uint8(imm8));
2619 2620 2621 2622 2623
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x3A);
  EMIT(0x17);
2624
  emit_sse_operand(src, dst);
2625 2626 2627
  EMIT(imm8);
}

2628
void Assembler::psllw(XMMRegister reg, uint8_t shift) {
2629 2630 2631 2632 2633 2634 2635
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x71);
  emit_sse_operand(esi, reg);  // esi == 6
  EMIT(shift);
}
2636

2637
void Assembler::pslld(XMMRegister reg, uint8_t shift) {
2638 2639 2640 2641 2642 2643 2644 2645
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x72);
  emit_sse_operand(esi, reg);  // esi == 6
  EMIT(shift);
}

2646
void Assembler::psrlw(XMMRegister reg, uint8_t shift) {
2647 2648 2649 2650 2651 2652 2653
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x71);
  emit_sse_operand(edx, reg);  // edx == 2
  EMIT(shift);
}
2654

2655
void Assembler::psrld(XMMRegister reg, uint8_t shift) {
2656 2657 2658 2659 2660 2661 2662 2663
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x72);
  emit_sse_operand(edx, reg);  // edx == 2
  EMIT(shift);
}

2664
void Assembler::psraw(XMMRegister reg, uint8_t shift) {
2665 2666 2667 2668 2669 2670 2671 2672
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x71);
  emit_sse_operand(esp, reg);  // esp == 4
  EMIT(shift);
}

2673
void Assembler::psrad(XMMRegister reg, uint8_t shift) {
2674 2675 2676 2677 2678 2679 2680
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x72);
  emit_sse_operand(esp, reg);  // esp == 4
  EMIT(shift);
}
2681

2682
void Assembler::psllq(XMMRegister reg, uint8_t shift) {
2683 2684 2685 2686 2687
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x73);
  emit_sse_operand(esi, reg);  // esi == 6
2688 2689 2690 2691
  EMIT(shift);
}


2692 2693 2694 2695 2696 2697 2698 2699
void Assembler::psllq(XMMRegister dst, XMMRegister src) {
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0xF3);
  emit_sse_operand(dst, src);
}

2700
void Assembler::psrlq(XMMRegister reg, uint8_t shift) {
2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x73);
  emit_sse_operand(edx, reg);  // edx == 2
  EMIT(shift);
}


void Assembler::psrlq(XMMRegister dst, XMMRegister src) {
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0xD3);
  emit_sse_operand(dst, src);
}

2718 2719 2720 2721 2722 2723 2724 2725 2726
void Assembler::pshufhw(XMMRegister dst, Operand src, uint8_t shuffle) {
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0x0F);
  EMIT(0x70);
  emit_sse_operand(dst, src);
  EMIT(shuffle);
}

2727
void Assembler::pshuflw(XMMRegister dst, Operand src, uint8_t shuffle) {
2728 2729 2730 2731 2732 2733 2734 2735
  EnsureSpace ensure_space(this);
  EMIT(0xF2);
  EMIT(0x0F);
  EMIT(0x70);
  emit_sse_operand(dst, src);
  EMIT(shuffle);
}

2736
void Assembler::pshufd(XMMRegister dst, Operand src, uint8_t shuffle) {
2737 2738 2739 2740 2741 2742 2743 2744
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x70);
  emit_sse_operand(dst, src);
  EMIT(shuffle);
}

2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755
void Assembler::pblendw(XMMRegister dst, Operand src, uint8_t mask) {
  DCHECK(IsEnabled(SSE4_1));
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x3A);
  EMIT(0x0E);
  emit_sse_operand(dst, src);
  EMIT(mask);
}

2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766
void Assembler::palignr(XMMRegister dst, Operand src, uint8_t mask) {
  DCHECK(IsEnabled(SSSE3));
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x3A);
  EMIT(0x0F);
  emit_sse_operand(dst, src);
  EMIT(mask);
}

2767
void Assembler::pextrb(Operand dst, XMMRegister src, uint8_t offset) {
2768 2769 2770 2771 2772 2773 2774 2775 2776 2777
  DCHECK(IsEnabled(SSE4_1));
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x3A);
  EMIT(0x14);
  emit_sse_operand(src, dst);
  EMIT(offset);
}

2778
void Assembler::pextrw(Operand dst, XMMRegister src, uint8_t offset) {
2779 2780 2781 2782 2783 2784 2785 2786 2787
  DCHECK(IsEnabled(SSE4_1));
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x3A);
  EMIT(0x15);
  emit_sse_operand(src, dst);
  EMIT(offset);
}
2788

2789
void Assembler::pextrd(Operand dst, XMMRegister src, uint8_t offset) {
2790
  DCHECK(IsEnabled(SSE4_1));
2791 2792 2793 2794 2795 2796 2797
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x3A);
  EMIT(0x16);
  emit_sse_operand(src, dst);
  EMIT(offset);
2798 2799
}

2800
void Assembler::insertps(XMMRegister dst, Operand src, uint8_t offset) {
2801 2802 2803 2804 2805 2806 2807 2808 2809 2810
  DCHECK(IsEnabled(SSE4_1));
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x3A);
  EMIT(0x21);
  emit_sse_operand(dst, src);
  EMIT(offset);
}

2811
void Assembler::pinsrb(XMMRegister dst, Operand src, uint8_t offset) {
2812 2813 2814 2815 2816 2817 2818 2819 2820 2821
  DCHECK(IsEnabled(SSE4_1));
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x3A);
  EMIT(0x20);
  emit_sse_operand(dst, src);
  EMIT(offset);
}

2822
void Assembler::pinsrw(XMMRegister dst, Operand src, uint8_t offset) {
2823 2824 2825 2826 2827 2828 2829 2830
  DCHECK(is_uint8(offset));
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0xC4);
  emit_sse_operand(dst, src);
  EMIT(offset);
}
2831

2832
void Assembler::pinsrd(XMMRegister dst, Operand src, uint8_t offset) {
2833
  DCHECK(IsEnabled(SSE4_1));
2834 2835 2836 2837 2838 2839 2840
  EnsureSpace ensure_space(this);
  EMIT(0x66);
  EMIT(0x0F);
  EMIT(0x3A);
  EMIT(0x22);
  emit_sse_operand(dst, src);
  EMIT(offset);
2841 2842
}

2843
void Assembler::addss(XMMRegister dst, Operand src) {
2844 2845 2846 2847 2848 2849 2850
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0x0F);
  EMIT(0x58);
  emit_sse_operand(dst, src);
}

2851
void Assembler::subss(XMMRegister dst, Operand src) {
2852 2853 2854 2855 2856 2857 2858
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0x0F);
  EMIT(0x5C);
  emit_sse_operand(dst, src);
}

2859
void Assembler::mulss(XMMRegister dst, Operand src) {
2860 2861 2862 2863 2864 2865 2866
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0x0F);
  EMIT(0x59);
  emit_sse_operand(dst, src);
}

2867
void Assembler::divss(XMMRegister dst, Operand src) {
2868 2869 2870 2871 2872 2873 2874
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0x0F);
  EMIT(0x5E);
  emit_sse_operand(dst, src);
}

2875
void Assembler::sqrtss(XMMRegister dst, Operand src) {
2876 2877 2878 2879 2880 2881 2882
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0x0F);
  EMIT(0x51);
  emit_sse_operand(dst, src);
}

2883
void Assembler::ucomiss(XMMRegister dst, Operand src) {
2884
  EnsureSpace ensure_space(this);
2885 2886
  EMIT(0x0F);
  EMIT(0x2E);
2887 2888 2889
  emit_sse_operand(dst, src);
}

2890
void Assembler::maxss(XMMRegister dst, Operand src) {
2891 2892 2893 2894 2895 2896 2897
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0x0F);
  EMIT(0x5F);
  emit_sse_operand(dst, src);
}

2898
void Assembler::minss(XMMRegister dst, Operand src) {
2899 2900 2901 2902 2903 2904 2905 2906
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0x0F);
  EMIT(0x5D);
  emit_sse_operand(dst, src);
}


2907 2908
// AVX instructions
void Assembler::vfmasd(byte op, XMMRegister dst, XMMRegister src1,
2909
                       Operand src2) {
2910 2911 2912 2913 2914 2915 2916 2917
  DCHECK(IsEnabled(FMA3));
  EnsureSpace ensure_space(this);
  emit_vex_prefix(src1, kLIG, k66, k0F38, kW1);
  EMIT(op);
  emit_sse_operand(dst, src2);
}

void Assembler::vfmass(byte op, XMMRegister dst, XMMRegister src1,
2918
                       Operand src2) {
2919 2920 2921 2922 2923 2924 2925
  DCHECK(IsEnabled(FMA3));
  EnsureSpace ensure_space(this);
  emit_vex_prefix(src1, kLIG, k66, k0F38, kW0);
  EMIT(op);
  emit_sse_operand(dst, src2);
}

2926
void Assembler::vsd(byte op, XMMRegister dst, XMMRegister src1, Operand src2) {
2927
  vinstr(op, dst, src1, src2, kF2, k0F, kWIG);
2928 2929
}

2930
void Assembler::vss(byte op, XMMRegister dst, XMMRegister src1, Operand src2) {
2931
  vinstr(op, dst, src1, src2, kF3, k0F, kWIG);
2932 2933
}

2934
void Assembler::vps(byte op, XMMRegister dst, XMMRegister src1, Operand src2) {
2935
  vinstr(op, dst, src1, src2, kNone, k0F, kWIG);
2936 2937
}

2938
void Assembler::vpd(byte op, XMMRegister dst, XMMRegister src1, Operand src2) {
2939
  vinstr(op, dst, src1, src2, k66, k0F, kWIG);
2940 2941
}

2942
void Assembler::vcmpps(XMMRegister dst, XMMRegister src1, Operand src2,
2943
                       uint8_t cmp) {
2944 2945 2946 2947
  vps(0xC2, dst, src1, src2);
  EMIT(cmp);
}

2948
void Assembler::vshufps(XMMRegister dst, XMMRegister src1, Operand src2,
2949 2950 2951 2952 2953 2954
                        byte imm8) {
  DCHECK(is_uint8(imm8));
  vps(0xC6, dst, src1, src2);
  EMIT(imm8);
}

2955
void Assembler::vpsllw(XMMRegister dst, XMMRegister src, uint8_t imm8) {
2956
  XMMRegister iop = XMMRegister::from_code(6);
2957 2958 2959 2960
  vinstr(0x71, iop, dst, Operand(src), k66, k0F, kWIG);
  EMIT(imm8);
}

2961
void Assembler::vpslld(XMMRegister dst, XMMRegister src, uint8_t imm8) {
2962
  XMMRegister iop = XMMRegister::from_code(6);
2963 2964 2965 2966
  vinstr(0x72, iop, dst, Operand(src), k66, k0F, kWIG);
  EMIT(imm8);
}

2967
void Assembler::vpsrlw(XMMRegister dst, XMMRegister src, uint8_t imm8) {
2968
  XMMRegister iop = XMMRegister::from_code(2);
2969 2970 2971 2972
  vinstr(0x71, iop, dst, Operand(src), k66, k0F, kWIG);
  EMIT(imm8);
}

2973
void Assembler::vpsrld(XMMRegister dst, XMMRegister src, uint8_t imm8) {
2974
  XMMRegister iop = XMMRegister::from_code(2);
2975 2976 2977 2978
  vinstr(0x72, iop, dst, Operand(src), k66, k0F, kWIG);
  EMIT(imm8);
}

2979
void Assembler::vpsraw(XMMRegister dst, XMMRegister src, uint8_t imm8) {
2980
  XMMRegister iop = XMMRegister::from_code(4);
2981 2982 2983 2984
  vinstr(0x71, iop, dst, Operand(src), k66, k0F, kWIG);
  EMIT(imm8);
}

2985
void Assembler::vpsrad(XMMRegister dst, XMMRegister src, uint8_t imm8) {
2986
  XMMRegister iop = XMMRegister::from_code(4);
2987 2988 2989
  vinstr(0x72, iop, dst, Operand(src), k66, k0F, kWIG);
  EMIT(imm8);
}
2990

2991 2992 2993 2994 2995
void Assembler::vpshufhw(XMMRegister dst, Operand src, uint8_t shuffle) {
  vinstr(0x70, dst, xmm0, src, kF3, k0F, kWIG);
  EMIT(shuffle);
}

2996
void Assembler::vpshuflw(XMMRegister dst, Operand src, uint8_t shuffle) {
2997 2998 2999 3000
  vinstr(0x70, dst, xmm0, src, kF2, k0F, kWIG);
  EMIT(shuffle);
}

3001
void Assembler::vpshufd(XMMRegister dst, Operand src, uint8_t shuffle) {
3002 3003 3004 3005
  vinstr(0x70, dst, xmm0, src, k66, k0F, kWIG);
  EMIT(shuffle);
}

3006 3007 3008 3009 3010 3011
void Assembler::vpblendw(XMMRegister dst, XMMRegister src1, Operand src2,
                         uint8_t mask) {
  vinstr(0x0E, dst, src1, src2, k66, k0F3A, kWIG);
  EMIT(mask);
}

3012 3013 3014 3015 3016 3017
void Assembler::vpalignr(XMMRegister dst, XMMRegister src1, Operand src2,
                         uint8_t mask) {
  vinstr(0x0F, dst, src1, src2, k66, k0F3A, kWIG);
  EMIT(mask);
}

3018
void Assembler::vpextrb(Operand dst, XMMRegister src, uint8_t offset) {
3019 3020 3021 3022
  vinstr(0x14, src, xmm0, dst, k66, k0F3A, kWIG);
  EMIT(offset);
}

3023
void Assembler::vpextrw(Operand dst, XMMRegister src, uint8_t offset) {
3024 3025 3026 3027
  vinstr(0x15, src, xmm0, dst, k66, k0F3A, kWIG);
  EMIT(offset);
}

3028
void Assembler::vpextrd(Operand dst, XMMRegister src, uint8_t offset) {
3029 3030 3031 3032
  vinstr(0x16, src, xmm0, dst, k66, k0F3A, kWIG);
  EMIT(offset);
}

3033
void Assembler::vinsertps(XMMRegister dst, XMMRegister src1, Operand src2,
3034
                          uint8_t offset) {
3035 3036 3037 3038
  vinstr(0x21, dst, src1, src2, k66, k0F3A, kWIG);
  EMIT(offset);
}

3039
void Assembler::vpinsrb(XMMRegister dst, XMMRegister src1, Operand src2,
3040
                        uint8_t offset) {
3041 3042 3043 3044
  vinstr(0x20, dst, src1, src2, k66, k0F3A, kWIG);
  EMIT(offset);
}

3045
void Assembler::vpinsrw(XMMRegister dst, XMMRegister src1, Operand src2,
3046
                        uint8_t offset) {
3047 3048 3049 3050
  vinstr(0xC4, dst, src1, src2, k66, k0F, kWIG);
  EMIT(offset);
}

3051
void Assembler::vpinsrd(XMMRegister dst, XMMRegister src1, Operand src2,
3052
                        uint8_t offset) {
3053 3054 3055 3056
  vinstr(0x22, dst, src1, src2, k66, k0F3A, kWIG);
  EMIT(offset);
}

3057
void Assembler::bmi1(byte op, Register reg, Register vreg, Operand rm) {
3058 3059 3060 3061 3062 3063 3064
  DCHECK(IsEnabled(BMI1));
  EnsureSpace ensure_space(this);
  emit_vex_prefix(vreg, kLZ, kNone, k0F38, kW0);
  EMIT(op);
  emit_operand(reg, rm);
}

3065
void Assembler::tzcnt(Register dst, Operand src) {
3066 3067 3068 3069 3070 3071 3072 3073
  DCHECK(IsEnabled(BMI1));
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0x0F);
  EMIT(0xBC);
  emit_operand(dst, src);
}

3074
void Assembler::lzcnt(Register dst, Operand src) {
3075 3076 3077 3078 3079 3080 3081 3082
  DCHECK(IsEnabled(LZCNT));
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0x0F);
  EMIT(0xBD);
  emit_operand(dst, src);
}

3083
void Assembler::popcnt(Register dst, Operand src) {
3084 3085 3086 3087 3088 3089 3090 3091 3092
  DCHECK(IsEnabled(POPCNT));
  EnsureSpace ensure_space(this);
  EMIT(0xF3);
  EMIT(0x0F);
  EMIT(0xB8);
  emit_operand(dst, src);
}

void Assembler::bmi2(SIMDPrefix pp, byte op, Register reg, Register vreg,
3093
                     Operand rm) {
3094 3095 3096 3097 3098 3099 3100
  DCHECK(IsEnabled(BMI2));
  EnsureSpace ensure_space(this);
  emit_vex_prefix(vreg, kLZ, pp, k0F38, kW0);
  EMIT(op);
  emit_operand(reg, rm);
}

3101
void Assembler::rorx(Register dst, Operand src, byte imm8) {
3102 3103
  DCHECK(IsEnabled(BMI2));
  DCHECK(is_uint8(imm8));
3104
  Register vreg = Register::from_code<0>();  // VEX.vvvv unused
3105 3106 3107 3108 3109 3110 3111
  EnsureSpace ensure_space(this);
  emit_vex_prefix(vreg, kLZ, kF2, k0F3A, kW0);
  EMIT(0xF0);
  emit_operand(dst, src);
  EMIT(imm8);
}

3112
void Assembler::sse2_instr(XMMRegister dst, Operand src, byte prefix,
3113 3114 3115 3116 3117 3118 3119 3120
                           byte escape, byte opcode) {
  EnsureSpace ensure_space(this);
  EMIT(prefix);
  EMIT(escape);
  EMIT(opcode);
  emit_sse_operand(dst, src);
}

3121
void Assembler::ssse3_instr(XMMRegister dst, Operand src, byte prefix,
3122 3123 3124 3125 3126 3127 3128 3129 3130 3131
                            byte escape1, byte escape2, byte opcode) {
  DCHECK(IsEnabled(SSSE3));
  EnsureSpace ensure_space(this);
  EMIT(prefix);
  EMIT(escape1);
  EMIT(escape2);
  EMIT(opcode);
  emit_sse_operand(dst, src);
}

3132
void Assembler::sse4_instr(XMMRegister dst, Operand src, byte prefix,
3133 3134 3135 3136 3137 3138 3139 3140 3141 3142
                           byte escape1, byte escape2, byte opcode) {
  DCHECK(IsEnabled(SSE4_1));
  EnsureSpace ensure_space(this);
  EMIT(prefix);
  EMIT(escape1);
  EMIT(escape2);
  EMIT(opcode);
  emit_sse_operand(dst, src);
}

3143 3144
void Assembler::vinstr(byte op, XMMRegister dst, XMMRegister src1, Operand src2,
                       SIMDPrefix pp, LeadingOpcode m, VexW w) {
3145 3146 3147 3148 3149 3150
  DCHECK(IsEnabled(AVX));
  EnsureSpace ensure_space(this);
  emit_vex_prefix(src1, kL128, pp, m, w);
  EMIT(op);
  emit_sse_operand(dst, src2);
}
3151

3152
void Assembler::emit_sse_operand(XMMRegister reg, Operand adr) {
3153
  Register ireg = Register::from_code(reg.code());
3154 3155 3156 3157 3158 3159 3160 3161 3162
  emit_operand(ireg, adr);
}


void Assembler::emit_sse_operand(XMMRegister dst, XMMRegister src) {
  EMIT(0xC0 | dst.code() << 3 | src.code());
}


3163 3164 3165 3166 3167
void Assembler::emit_sse_operand(Register dst, XMMRegister src) {
  EMIT(0xC0 | dst.code() << 3 | src.code());
}


3168 3169 3170 3171 3172
void Assembler::emit_sse_operand(XMMRegister dst, Register src) {
  EMIT(0xC0 | (dst.code() << 3) | src.code());
}


3173 3174 3175
void Assembler::emit_vex_prefix(XMMRegister vreg, VectorLength l, SIMDPrefix pp,
                                LeadingOpcode mm, VexW w) {
  if (mm != k0F || w != kW0) {
3176
    EMIT(0xC4);
3177
    // Change RXB from "110" to "111" to align with gdb disassembler.
3178 3179
    EMIT(0xE0 | mm);
    EMIT(w | ((~vreg.code() & 0xF) << 3) | l | pp);
3180
  } else {
3181
    EMIT(0xC5);
3182 3183 3184 3185 3186
    EMIT(((~vreg.code()) << 3) | l | pp);
  }
}


3187 3188
void Assembler::emit_vex_prefix(Register vreg, VectorLength l, SIMDPrefix pp,
                                LeadingOpcode mm, VexW w) {
3189
  XMMRegister ivreg = XMMRegister::from_code(vreg.code());
3190 3191 3192 3193
  emit_vex_prefix(ivreg, l, pp, mm, w);
}


3194
void Assembler::GrowBuffer() {
3195
  DCHECK(buffer_overflow());
3196 3197
  if (!own_buffer_) FATAL("external code buffer is too small");

3198
  // Compute new buffer size.
3199
  CodeDesc desc;  // the new buffer
3200 3201
  desc.buffer_size = 2 * buffer_size_;

3202 3203
  // Some internal data structures overflow for very large buffers,
  // they must ensure that kMaximalBufferSize is not too large.
3204
  if (desc.buffer_size > kMaximalBufferSize) {
3205
    V8::FatalProcessOutOfMemory(nullptr, "Assembler::GrowBuffer");
3206 3207
  }

3208
  // Set up new buffer.
3209
  desc.buffer = NewArray<byte>(desc.buffer_size);
jochen's avatar
jochen committed
3210
  desc.origin = this;
3211 3212 3213 3214 3215
  desc.instr_size = pc_offset();
  desc.reloc_size = (buffer_ + buffer_size_) - (reloc_info_writer.pos());

  // Clear the buffer in debug mode. Use 'int3' instructions to make
  // sure to get into problems if we ever run uninitialized code.
3216
#ifdef DEBUG
3217
  ZapCode(reinterpret_cast<Address>(desc.buffer), desc.buffer_size);
3218
#endif
3219

3220
  // Copy the data.
3221 3222
  int pc_delta = desc.buffer - buffer_;
  int rc_delta = (desc.buffer + desc.buffer_size) - (buffer_ + buffer_size_);
3223 3224 3225
  MemMove(desc.buffer, buffer_, desc.instr_size);
  MemMove(rc_delta + reloc_info_writer.pos(), reloc_info_writer.pos(),
          desc.reloc_size);
3226

3227
  // Switch buffers.
3228
  DeleteArray(buffer_);
3229 3230 3231 3232 3233 3234
  buffer_ = desc.buffer;
  buffer_size_ = desc.buffer_size;
  pc_ += pc_delta;
  reloc_info_writer.Reposition(reloc_info_writer.pos() + rc_delta,
                               reloc_info_writer.last_pc() + pc_delta);

3235 3236 3237 3238
  // Relocate internal references.
  for (auto pos : internal_reference_positions_) {
    int32_t* p = reinterpret_cast<int32_t*>(buffer_ + pos);
    *p += pc_delta;
3239 3240
  }

3241
  // Relocate pc-relative references.
3242
  int mode_mask = RelocInfo::ModeMask(RelocInfo::OFF_HEAP_TARGET);
3243 3244
  DCHECK_EQ(mode_mask, RelocInfo::kApplyMask & mode_mask);
  for (RelocIterator it(desc, mode_mask); !it.done(); it.next()) {
3245 3246 3247
    it.rinfo()->apply(pc_delta);
  }

3248
  DCHECK(!buffer_overflow());
3249 3250 3251 3252
}


void Assembler::emit_arith_b(int op1, int op2, Register dst, int imm8) {
3253 3254
  DCHECK(is_uint8(op1) && is_uint8(op2));  // wrong opcode
  DCHECK(is_uint8(imm8));
3255
  DCHECK_EQ(op1 & 0x01, 0);  // should be 8bit operation
3256 3257 3258 3259 3260 3261 3262
  EMIT(op1);
  EMIT(op2 | dst.code());
  EMIT(imm8);
}


void Assembler::emit_arith(int sel, Operand dst, const Immediate& x) {
3263
  DCHECK((0 <= sel) && (sel <= 7));
3264
  Register ireg = Register::from_code(sel);
3265 3266 3267
  if (x.is_int8()) {
    EMIT(0x83);  // using a sign-extended 8-bit immediate.
    emit_operand(ireg, dst);
3268
    EMIT(x.immediate() & 0xFF);
3269 3270 3271 3272 3273 3274 3275 3276 3277 3278
  } else if (dst.is_reg(eax)) {
    EMIT((sel << 3) | 0x05);  // short form if the destination is eax.
    emit(x);
  } else {
    EMIT(0x81);  // using a literal 32-bit immediate.
    emit_operand(ireg, dst);
    emit(x);
  }
}

3279
void Assembler::emit_operand(Register reg, Operand adr) {
3280 3281 3282 3283 3284 3285 3286 3287 3288
  emit_operand(reg.code(), adr);
}

void Assembler::emit_operand(XMMRegister reg, Operand adr) {
  Register ireg = Register::from_code(reg.code());
  emit_operand(ireg, adr);
}

void Assembler::emit_operand(int code, Operand adr) {
3289 3290 3291 3292 3293
  // Isolate-independent code may not embed relocatable addresses.
  DCHECK(!options().isolate_independent_code ||
         adr.rmode_ != RelocInfo::CODE_TARGET);
  DCHECK(!options().isolate_independent_code ||
         adr.rmode_ != RelocInfo::EMBEDDED_OBJECT);
3294 3295
  DCHECK(!options().isolate_independent_code ||
         adr.rmode_ != RelocInfo::EXTERNAL_REFERENCE);
3296

3297
  const unsigned length = adr.len_;
3298
  DCHECK_GT(length, 0);
3299 3300

  // Emit updated ModRM byte containing the given register.
3301
  pc_[0] = (adr.buf_[0] & ~0x38) | (code << 3);
3302 3303 3304 3305 3306 3307

  // Emit the rest of the encoded operand.
  for (unsigned i = 1; i < length; i++) pc_[i] = adr.buf_[i];
  pc_ += length;

  // Emit relocation information if necessary.
3308
  if (length >= sizeof(int32_t) && !RelocInfo::IsNone(adr.rmode_)) {
3309 3310
    pc_ -= sizeof(int32_t);  // pc_ must be *at* disp32
    RecordRelocInfo(adr.rmode_);
3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325
    if (adr.rmode_ == RelocInfo::INTERNAL_REFERENCE) {  // Fixup for labels
      emit_label(*reinterpret_cast<Label**>(pc_));
    } else {
      pc_ += sizeof(int32_t);
    }
  }
}


void Assembler::emit_label(Label* label) {
  if (label->is_bound()) {
    internal_reference_positions_.push_back(pc_offset());
    emit(reinterpret_cast<uint32_t>(buffer_ + label->pos()));
  } else {
    emit_disp(label, Displacement::CODE_ABSOLUTE);
3326 3327 3328 3329 3330
  }
}


void Assembler::emit_farith(int b1, int b2, int i) {
3331 3332
  DCHECK(is_uint8(b1) && is_uint8(b2));  // wrong opcode
  DCHECK(0 <= i &&  i < 8);  // illegal stack offset
3333 3334 3335 3336
  EMIT(b1);
  EMIT(b2 + i);
}

kasperl@chromium.org's avatar
kasperl@chromium.org committed
3337

3338 3339 3340 3341 3342 3343 3344
void Assembler::db(uint8_t data) {
  EnsureSpace ensure_space(this);
  EMIT(data);
}


void Assembler::dd(uint32_t data) {
3345
  EnsureSpace ensure_space(this);
3346
  emit(data);
3347 3348
}

3349

3350 3351 3352 3353 3354 3355
void Assembler::dq(uint64_t data) {
  EnsureSpace ensure_space(this);
  emit_q(data);
}


3356 3357 3358 3359 3360 3361 3362
void Assembler::dd(Label* label) {
  EnsureSpace ensure_space(this);
  RecordRelocInfo(RelocInfo::INTERNAL_REFERENCE);
  emit_label(label);
}


3363
void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) {
3364
  if (!ShouldRecordRelocInfo(rmode)) return;
3365
  RelocInfo rinfo(reinterpret_cast<Address>(pc_), rmode, data, nullptr);
3366 3367 3368
  reloc_info_writer.Write(&rinfo);
}

3369 3370
}  // namespace internal
}  // namespace v8
3371 3372

#endif  // V8_TARGET_ARCH_IA32