liftoff-assembler-ia32.h 19.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_WASM_BASELINE_LIFTOFF_ASSEMBLER_IA32_H_
#define V8_WASM_BASELINE_LIFTOFF_ASSEMBLER_IA32_H_

#include "src/wasm/baseline/liftoff-assembler.h"

#include "src/assembler.h"
#include "src/wasm/wasm-opcodes.h"

namespace v8 {
namespace internal {
namespace wasm {

namespace liftoff {

19 20 21 22 23 24
// ebp-8 holds the stack marker, ebp-16 is the wasm context, first stack slot
// is located at ebp-24.
constexpr int32_t kConstantStackSpace = 16;
constexpr int32_t kFirstStackSlotOffset =
    kConstantStackSpace + LiftoffAssembler::kStackSlotSize;

25
inline Operand GetStackSlot(uint32_t index) {
26
  return Operand(
27
      ebp, -kFirstStackSlotOffset - index * LiftoffAssembler::kStackSlotSize);
28 29
}

30 31 32
// TODO(clemensh): Make this a constexpr variable once Operand is constexpr.
inline Operand GetContextOperand() { return Operand(ebp, -16); }

33 34 35 36 37 38
static constexpr LiftoffRegList kByteRegs =
    LiftoffRegList::FromBits<Register::ListOf<eax, ecx, edx, ebx>()>();
static_assert(kByteRegs.GetNumRegsSet() == 4, "should have four byte regs");
static_assert((kByteRegs & kGpCacheRegList) == kByteRegs,
              "kByteRegs only contains gp cache registers");

39 40 41 42
// Use this register to store the address of the last argument pushed on the
// stack for a call to C.
static constexpr Register kCCallLastArgAddrReg = eax;

43 44
}  // namespace liftoff

45 46
static constexpr DoubleRegister kScratchDoubleReg = xmm7;

47 48
void LiftoffAssembler::ReserveStackSpace(uint32_t stack_slots) {
  uint32_t bytes = liftoff::kConstantStackSpace + kStackSlotSize * stack_slots;
49
  DCHECK_LE(bytes, kMaxInt);
50
  sub(esp, Immediate(bytes));
51 52
}

53 54
void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value,
                                    RelocInfo::Mode rmode) {
55 56
  switch (value.type()) {
    case kWasmI32:
57 58 59
      TurboAssembler::Move(
          reg.gp(),
          Immediate(reinterpret_cast<Address>(value.to_i32()), rmode));
60
      break;
61 62 63 64
    case kWasmF32: {
      Register tmp = GetUnusedRegister(kGpReg).gp();
      mov(tmp, Immediate(value.to_f32_boxed().get_bits()));
      movd(reg.fp(), tmp);
65
      break;
66
    }
67
    default:
68
      UNREACHABLE();
69 70 71
  }
}

72 73 74 75 76 77 78 79 80 81
void LiftoffAssembler::LoadFromContext(Register dst, uint32_t offset,
                                       int size) {
  DCHECK_LE(offset, kMaxInt);
  mov(dst, liftoff::GetContextOperand());
  DCHECK_EQ(4, size);
  mov(dst, Operand(dst, offset));
}

void LiftoffAssembler::SpillContext(Register context) {
  mov(liftoff::GetContextOperand(), context);
82 83
}

84 85 86 87
void LiftoffAssembler::FillContextInto(Register dst) {
  mov(dst, liftoff::GetContextOperand());
}

88
void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr,
89
                            Register offset_reg, uint32_t offset_imm,
90 91
                            LoadType type, LiftoffRegList pinned,
                            uint32_t* protected_load_pc) {
92 93 94
  Operand src_op = offset_reg == no_reg
                       ? Operand(src_addr, offset_imm)
                       : Operand(src_addr, offset_reg, times_1, offset_imm);
95 96 97
  if (offset_imm > kMaxInt) {
    // The immediate can not be encoded in the operand. Load it to a register
    // first.
98
    Register src = GetUnusedRegister(kGpReg, pinned).gp();
99
    mov(src, Immediate(offset_imm));
100 101 102
    if (offset_reg != no_reg) {
      emit_ptrsize_add(src, src, offset_reg);
    }
103 104
    src_op = Operand(src_addr, src, times_1, 0);
  }
105
  if (protected_load_pc) *protected_load_pc = pc_offset();
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
  switch (type.value()) {
    case LoadType::kI32Load8U:
      movzx_b(dst.gp(), src_op);
      break;
    case LoadType::kI32Load8S:
      movsx_b(dst.gp(), src_op);
      break;
    case LoadType::kI32Load16U:
      movzx_w(dst.gp(), src_op);
      break;
    case LoadType::kI32Load16S:
      movsx_w(dst.gp(), src_op);
      break;
    case LoadType::kI32Load:
      mov(dst.gp(), src_op);
      break;
122 123 124
    case LoadType::kF32Load:
      movss(dst.fp(), src_op);
      break;
125 126 127
    default:
      UNREACHABLE();
  }
128 129
}

130 131
void LiftoffAssembler::Store(Register dst_addr, Register offset_reg,
                             uint32_t offset_imm, LiftoffRegister src,
132 133
                             StoreType type, LiftoffRegList pinned,
                             uint32_t* protected_store_pc) {
134 135 136
  Operand dst_op = offset_reg == no_reg
                       ? Operand(dst_addr, offset_imm)
                       : Operand(dst_addr, offset_reg, times_1, offset_imm);
137 138 139
  if (offset_imm > kMaxInt) {
    // The immediate can not be encoded in the operand. Load it to a register
    // first.
140
    Register dst = pinned.set(GetUnusedRegister(kGpReg, pinned).gp());
141
    mov(dst, Immediate(offset_imm));
142 143 144
    if (offset_reg != no_reg) {
      emit_ptrsize_add(dst, dst, offset_reg);
    }
145 146
    dst_op = Operand(dst_addr, dst, times_1, 0);
  }
147
  if (protected_store_pc) *protected_store_pc = pc_offset();
148 149
  switch (type.value()) {
    case StoreType::kI32Store8:
150 151 152 153 154 155 156 157
      // Only the lower 4 registers can be addressed as 8-bit registers.
      if (src.gp().is_byte_register()) {
        mov_b(dst_op, src.gp());
      } else {
        Register byte_src = GetUnusedRegister(liftoff::kByteRegs, pinned).gp();
        mov(byte_src, src.gp());
        mov_b(dst_op, byte_src);
      }
158 159 160 161 162 163 164
      break;
    case StoreType::kI32Store16:
      mov_w(dst_op, src.gp());
      break;
    case StoreType::kI32Store:
      mov(dst_op, src.gp());
      break;
165 166 167
    case StoreType::kF32Store:
      movss(dst_op, src.fp());
      break;
168 169 170
    default:
      UNREACHABLE();
  }
171 172
}

173
void LiftoffAssembler::LoadCallerFrameSlot(LiftoffRegister dst,
174
                                           uint32_t caller_slot_idx) {
175
  Operand src(ebp, kPointerSize * (caller_slot_idx + 1));
176 177 178
  if (dst.is_gp()) {
    mov(dst.gp(), src);
  } else {
179
    movss(dst.fp(), src);
180
  }
181 182
}

183 184
void LiftoffAssembler::MoveStackValue(uint32_t dst_index, uint32_t src_index,
                                      ValueType type) {
185
  DCHECK_NE(dst_index, src_index);
186 187
  if (cache_state_.has_unused_register(kGpReg)) {
    LiftoffRegister reg = GetUnusedRegister(kGpReg);
188 189
    Fill(reg, src_index, type);
    Spill(dst_index, reg, type);
190 191 192 193 194 195
  } else {
    push(liftoff::GetStackSlot(src_index));
    pop(liftoff::GetStackSlot(dst_index));
  }
}

196
void LiftoffAssembler::MoveToReturnRegister(LiftoffRegister reg) {
197 198 199 200 201
  // TODO(wasm): Extract the destination register from the CallDescriptor.
  // TODO(wasm): Add multi-return support.
  LiftoffRegister dst =
      reg.is_gp() ? LiftoffRegister(eax) : LiftoffRegister(xmm1);
  if (reg != dst) Move(dst, reg);
202 203
}

204 205 206 207 208 209 210 211 212 213 214 215 216 217
void LiftoffAssembler::Move(LiftoffRegister dst, LiftoffRegister src) {
  // The caller should check that the registers are not equal. For most
  // occurences, this is already guaranteed, so no need to check within this
  // method.
  DCHECK_NE(dst, src);
  DCHECK_EQ(dst.reg_class(), src.reg_class());
  // TODO(clemensh): Handle different sizes here.
  if (dst.is_gp()) {
    mov(dst.gp(), src.gp());
  } else {
    movsd(dst.fp(), src.fp());
  }
}

218 219
void LiftoffAssembler::Spill(uint32_t index, LiftoffRegister reg,
                             ValueType type) {
220
  Operand dst = liftoff::GetStackSlot(index);
221 222 223 224 225 226 227 228 229 230 231 232
  switch (type) {
    case kWasmI32:
      mov(dst, reg.gp());
      break;
    case kWasmF32:
      movss(dst, reg.fp());
      break;
    case kWasmF64:
      movsd(dst, reg.fp());
      break;
    default:
      UNREACHABLE();
233
  }
234 235 236
}

void LiftoffAssembler::Spill(uint32_t index, WasmValue value) {
237 238 239 240 241 242 243 244 245 246 247
  Operand dst = liftoff::GetStackSlot(index);
  switch (value.type()) {
    case kWasmI32:
      mov(dst, Immediate(value.to_i32()));
      break;
    case kWasmF32:
      mov(dst, Immediate(value.to_f32_boxed().get_bits()));
      break;
    default:
      UNREACHABLE();
  }
248 249
}

250 251
void LiftoffAssembler::Fill(LiftoffRegister reg, uint32_t index,
                            ValueType type) {
252
  Operand src = liftoff::GetStackSlot(index);
253 254 255 256 257 258 259 260 261 262 263 264
  switch (type) {
    case kWasmI32:
      mov(reg.gp(), src);
      break;
    case kWasmF32:
      movss(reg.fp(), src);
      break;
    case kWasmF64:
      movsd(reg.fp(), src);
      break;
    default:
      UNREACHABLE();
265
  }
266 267 268
}

void LiftoffAssembler::emit_i32_add(Register dst, Register lhs, Register rhs) {
269
  if (lhs != dst) {
270 271 272 273 274 275
    lea(dst, Operand(lhs, rhs, times_1, 0));
  } else {
    add(dst, rhs);
  }
}

276 277 278 279 280 281 282 283 284 285 286
void LiftoffAssembler::emit_i32_sub(Register dst, Register lhs, Register rhs) {
  if (dst == rhs) {
    neg(dst);
    add(dst, lhs);
  } else {
    if (dst != lhs) mov(dst, lhs);
    sub(dst, rhs);
  }
}

#define COMMUTATIVE_I32_BINOP(name, instruction)                     \
287 288
  void LiftoffAssembler::emit_i32_##name(Register dst, Register lhs, \
                                         Register rhs) {             \
289 290 291 292 293
    if (dst == rhs) {                                                \
      instruction(dst, lhs);                                         \
    } else {                                                         \
      if (dst != lhs) mov(dst, lhs);                                 \
      instruction(dst, rhs);                                         \
294 295 296 297
    }                                                                \
  }

// clang-format off
298 299 300 301
COMMUTATIVE_I32_BINOP(mul, imul)
COMMUTATIVE_I32_BINOP(and, and_)
COMMUTATIVE_I32_BINOP(or, or_)
COMMUTATIVE_I32_BINOP(xor, xor_)
302 303
// clang-format on

304
#undef COMMUTATIVE_I32_BINOP
305

306 307 308
namespace liftoff {
inline void EmitShiftOperation(LiftoffAssembler* assm, Register dst,
                               Register lhs, Register rhs,
309 310 311 312 313
                               void (Assembler::*emit_shift)(Register),
                               LiftoffRegList pinned) {
  pinned.set(dst);
  pinned.set(lhs);
  pinned.set(rhs);
314 315 316 317 318 319 320 321 322 323 324 325 326 327
  // If dst is ecx, compute into a tmp register first, then move to ecx.
  if (dst == ecx) {
    Register tmp = assm->GetUnusedRegister(kGpReg, pinned).gp();
    assm->mov(tmp, lhs);
    if (rhs != ecx) assm->mov(ecx, rhs);
    (assm->*emit_shift)(tmp);
    assm->mov(ecx, tmp);
    return;
  }

  // Move rhs into ecx. If ecx is in use, move its content to a tmp register
  // first. If lhs is ecx, lhs is now the tmp register.
  Register tmp_reg = no_reg;
  if (rhs != ecx) {
328 329
    if (assm->cache_state()->is_used(LiftoffRegister(ecx)) ||
        pinned.has(LiftoffRegister(ecx))) {
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
      tmp_reg = assm->GetUnusedRegister(kGpReg, pinned).gp();
      assm->mov(tmp_reg, ecx);
      if (lhs == ecx) lhs = tmp_reg;
    }
    assm->mov(ecx, rhs);
  }

  // Do the actual shift.
  if (dst != lhs) assm->mov(dst, lhs);
  (assm->*emit_shift)(dst);

  // Restore ecx if needed.
  if (tmp_reg.is_valid()) assm->mov(ecx, tmp_reg);
}
}  // namespace liftoff

346 347 348
void LiftoffAssembler::emit_i32_shl(Register dst, Register lhs, Register rhs,
                                    LiftoffRegList pinned) {
  liftoff::EmitShiftOperation(this, dst, lhs, rhs, &Assembler::shl_cl, pinned);
349 350
}

351 352 353
void LiftoffAssembler::emit_i32_sar(Register dst, Register lhs, Register rhs,
                                    LiftoffRegList pinned) {
  liftoff::EmitShiftOperation(this, dst, lhs, rhs, &Assembler::sar_cl, pinned);
354 355
}

356 357 358
void LiftoffAssembler::emit_i32_shr(Register dst, Register lhs, Register rhs,
                                    LiftoffRegList pinned) {
  liftoff::EmitShiftOperation(this, dst, lhs, rhs, &Assembler::shr_cl, pinned);
359 360
}

361
bool LiftoffAssembler::emit_i32_clz(Register dst, Register src) {
362 363 364 365 366 367 368 369 370 371 372 373 374 375
  Label nonzero_input;
  Label continuation;
  test(src, src);
  j(not_zero, &nonzero_input, Label::kNear);
  mov(dst, Immediate(32));
  jmp(&continuation, Label::kNear);

  bind(&nonzero_input);
  // Get most significant bit set (MSBS).
  bsr(dst, src);
  // CLZ = 31 - MSBS = MSBS ^ 31.
  xor_(dst, 31);

  bind(&continuation);
376
  return true;
377 378
}

379
bool LiftoffAssembler::emit_i32_ctz(Register dst, Register src) {
380 381 382 383 384 385 386 387 388 389 390 391
  Label nonzero_input;
  Label continuation;
  test(src, src);
  j(not_zero, &nonzero_input, Label::kNear);
  mov(dst, Immediate(32));
  jmp(&continuation, Label::kNear);

  bind(&nonzero_input);
  // Get least significant bit set, which equals number of trailing zeros.
  bsf(dst, src);

  bind(&continuation);
392 393 394 395 396 397 398 399
  return true;
}

bool LiftoffAssembler::emit_i32_popcnt(Register dst, Register src) {
  if (!CpuFeatures::IsSupported(POPCNT)) return false;
  CpuFeatureScope scope(this, POPCNT);
  popcnt(dst, src);
  return true;
400 401 402 403 404 405 406
}

void LiftoffAssembler::emit_ptrsize_add(Register dst, Register lhs,
                                        Register rhs) {
  emit_i32_add(dst, lhs, rhs);
}

407 408 409 410 411
void LiftoffAssembler::emit_f32_add(DoubleRegister dst, DoubleRegister lhs,
                                    DoubleRegister rhs) {
  if (CpuFeatures::IsSupported(AVX)) {
    CpuFeatureScope scope(this, AVX);
    vaddss(dst, lhs, rhs);
412
  } else if (dst == rhs) {
413 414 415 416 417 418 419 420 421 422 423 424
    addss(dst, lhs);
  } else {
    if (dst != lhs) movss(dst, lhs);
    addss(dst, rhs);
  }
}

void LiftoffAssembler::emit_f32_sub(DoubleRegister dst, DoubleRegister lhs,
                                    DoubleRegister rhs) {
  if (CpuFeatures::IsSupported(AVX)) {
    CpuFeatureScope scope(this, AVX);
    vsubss(dst, lhs, rhs);
425
  } else if (dst == rhs) {
426 427 428 429 430 431 432 433 434 435 436 437 438 439
    movss(kScratchDoubleReg, rhs);
    movss(dst, lhs);
    subss(dst, kScratchDoubleReg);
  } else {
    if (dst != lhs) movss(dst, lhs);
    subss(dst, rhs);
  }
}

void LiftoffAssembler::emit_f32_mul(DoubleRegister dst, DoubleRegister lhs,
                                    DoubleRegister rhs) {
  if (CpuFeatures::IsSupported(AVX)) {
    CpuFeatureScope scope(this, AVX);
    vmulss(dst, lhs, rhs);
440
  } else if (dst == rhs) {
441 442 443 444 445 446 447
    mulss(dst, lhs);
  } else {
    if (dst != lhs) movss(dst, lhs);
    mulss(dst, rhs);
  }
}

448 449 450 451 452 453
void LiftoffAssembler::emit_i32_test(Register reg) { test(reg, reg); }

void LiftoffAssembler::emit_i32_compare(Register lhs, Register rhs) {
  cmp(lhs, rhs);
}

454 455 456 457
void LiftoffAssembler::emit_ptrsize_compare(Register lhs, Register rhs) {
  emit_i32_compare(lhs, rhs);
}

458 459 460 461
void LiftoffAssembler::emit_jump(Label* label) { jmp(label); }

void LiftoffAssembler::emit_cond_jump(Condition cond, Label* label) {
  j(cond, label);
462 463
}

464 465 466 467 468 469 470 471 472 473 474 475 476 477
void LiftoffAssembler::emit_i32_set_cond(Condition cond, Register dst) {
  Register tmp_byte_reg = dst;
  // Only the lower 4 registers can be addressed as 8-bit registers.
  if (!dst.is_byte_register()) {
    LiftoffRegList pinned = LiftoffRegList::ForRegs(dst);
    // {mov} does not change the status flags, so calling {GetUnusedRegister}
    // should be fine here.
    tmp_byte_reg = GetUnusedRegister(liftoff::kByteRegs, pinned).gp();
  }

  setcc(cond, tmp_byte_reg);
  movzx_b(dst, tmp_byte_reg);
}

478 479 480 481 482 483 484
void LiftoffAssembler::StackCheck(Label* ool_code) {
  Register limit = GetUnusedRegister(kGpReg).gp();
  mov(limit, Immediate(ExternalReference::address_of_stack_limit(isolate())));
  cmp(esp, Operand(limit, 0));
  j(below_equal, ool_code);
}

485 486 487 488 489 490
void LiftoffAssembler::CallTrapCallbackForTesting() {
  PrepareCallCFunction(0, GetUnusedRegister(kGpReg).gp());
  CallCFunction(
      ExternalReference::wasm_call_trap_callback_for_testing(isolate()), 0);
}

491
void LiftoffAssembler::AssertUnreachable(AbortReason reason) {
492 493 494
  TurboAssembler::AssertUnreachable(reason);
}

495 496 497 498 499 500 501 502
void LiftoffAssembler::PushCallerFrameSlot(const VarState& src,
                                           uint32_t src_index) {
  switch (src.loc()) {
    case VarState::kStack:
      DCHECK_NE(kWasmF64, src.type());  // TODO(clemensh): Implement this.
      push(liftoff::GetStackSlot(src_index));
      break;
    case VarState::kRegister:
503
      PushCallerFrameSlot(src.reg());
504
      break;
505
    case VarState::kI32Const:
506 507 508 509 510
      push(Immediate(src.i32_const()));
      break;
  }
}

511 512 513 514 515 516 517 518 519
void LiftoffAssembler::PushCallerFrameSlot(LiftoffRegister reg) {
  if (reg.is_gp()) {
    push(reg.gp());
  } else {
    sub(esp, Immediate(kPointerSize));
    movss(Operand(esp, 0), reg.fp());
  }
}

520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
void LiftoffAssembler::PushRegisters(LiftoffRegList regs) {
  LiftoffRegList gp_regs = regs & kGpCacheRegList;
  while (!gp_regs.is_empty()) {
    LiftoffRegister reg = gp_regs.GetFirstRegSet();
    push(reg.gp());
    gp_regs.clear(reg);
  }
  LiftoffRegList fp_regs = regs & kFpCacheRegList;
  unsigned num_fp_regs = fp_regs.GetNumRegsSet();
  if (num_fp_regs) {
    sub(esp, Immediate(num_fp_regs * kStackSlotSize));
    unsigned offset = 0;
    while (!fp_regs.is_empty()) {
      LiftoffRegister reg = fp_regs.GetFirstRegSet();
      movsd(Operand(esp, offset), reg.fp());
      fp_regs.clear(reg);
      offset += sizeof(double);
    }
    DCHECK_EQ(offset, num_fp_regs * sizeof(double));
  }
}

void LiftoffAssembler::PopRegisters(LiftoffRegList regs) {
  LiftoffRegList fp_regs = regs & kFpCacheRegList;
  unsigned fp_offset = 0;
  while (!fp_regs.is_empty()) {
    LiftoffRegister reg = fp_regs.GetFirstRegSet();
    movsd(reg.fp(), Operand(esp, fp_offset));
    fp_regs.clear(reg);
    fp_offset += sizeof(double);
  }
  if (fp_offset) add(esp, Immediate(fp_offset));
  LiftoffRegList gp_regs = regs & kGpCacheRegList;
  while (!gp_regs.is_empty()) {
    LiftoffRegister reg = gp_regs.GetLastRegSet();
    pop(reg.gp());
    gp_regs.clear(reg);
  }
}

void LiftoffAssembler::DropStackSlotsAndRet(uint32_t num_stack_slots) {
  DCHECK_LT(num_stack_slots, (1 << 16) / kPointerSize);  // 16 bit immediate
  ret(static_cast<int>(num_stack_slots * kPointerSize));
}

565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
void LiftoffAssembler::PrepareCCall(uint32_t num_params, const Register* args) {
  for (size_t param = 0; param < num_params; ++param) {
    push(args[param]);
  }
  mov(liftoff::kCCallLastArgAddrReg, esp);
  constexpr Register kScratch = ebx;
  static_assert(kScratch != liftoff::kCCallLastArgAddrReg, "collision");
  PrepareCallCFunction(num_params, kScratch);
}

void LiftoffAssembler::SetCCallRegParamAddr(Register dst, uint32_t param_idx,
                                            uint32_t num_params) {
  int offset = kPointerSize * static_cast<int>(num_params - 1 - param_idx);
  lea(dst, Operand(liftoff::kCCallLastArgAddrReg, offset));
}

void LiftoffAssembler::SetCCallStackParamAddr(uint32_t stack_param_idx,
                                              uint32_t param_idx,
                                              uint32_t num_params) {
  constexpr Register kScratch = ebx;
  static_assert(kScratch != liftoff::kCCallLastArgAddrReg, "collision");
  int offset = kPointerSize * static_cast<int>(num_params - 1 - param_idx);
  lea(kScratch, Operand(liftoff::kCCallLastArgAddrReg, offset));
  mov(Operand(esp, param_idx * kPointerSize), kScratch);
}

591
void LiftoffAssembler::CallC(ExternalReference ext_ref, uint32_t num_params) {
592 593 594
  CallCFunction(ext_ref, static_cast<int>(num_params));
}

595 596 597 598
void LiftoffAssembler::CallNativeWasmCode(Address addr) {
  wasm_call(addr, RelocInfo::WASM_CALL);
}

599 600 601 602 603 604
void LiftoffAssembler::CallRuntime(Zone* zone, Runtime::FunctionId fid) {
  // Set context to zero.
  xor_(esi, esi);
  CallRuntimeDelayed(zone, fid);
}

605 606
void LiftoffAssembler::CallIndirect(wasm::FunctionSig* sig,
                                    compiler::CallDescriptor* call_desc,
607 608 609
                                    Register target,
                                    uint32_t* max_used_spill_slot) {
  PrepareCall(sig, call_desc, max_used_spill_slot, &target);
610 611 612 613 614 615 616 617
  if (target == no_reg) {
    add(esp, Immediate(kPointerSize));
    call(Operand(esp, -4));
  } else {
    call(target);
  }
}

618 619 620 621 622 623 624 625 626
void LiftoffAssembler::AllocateStackSlot(Register addr, uint32_t size) {
  sub(esp, Immediate(size));
  mov(addr, esp);
}

void LiftoffAssembler::DeallocateStackSlot(uint32_t size) {
  add(esp, Immediate(size));
}

627 628 629 630 631
}  // namespace wasm
}  // namespace internal
}  // namespace v8

#endif  // V8_WASM_BASELINE_LIFTOFF_ASSEMBLER_IA32_H_