11cb0ef41Sopenharmony_ci// Copyright 2012 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#include <limits.h>  // For LONG_MIN, LONG_MAX.
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#if V8_TARGET_ARCH_ARM
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci#include "src/base/bits.h"
101cb0ef41Sopenharmony_ci#include "src/base/division-by-constant.h"
111cb0ef41Sopenharmony_ci#include "src/base/numbers/double.h"
121cb0ef41Sopenharmony_ci#include "src/base/utils/random-number-generator.h"
131cb0ef41Sopenharmony_ci#include "src/codegen/assembler-inl.h"
141cb0ef41Sopenharmony_ci#include "src/codegen/callable.h"
151cb0ef41Sopenharmony_ci#include "src/codegen/code-factory.h"
161cb0ef41Sopenharmony_ci#include "src/codegen/external-reference-table.h"
171cb0ef41Sopenharmony_ci#include "src/codegen/interface-descriptors-inl.h"
181cb0ef41Sopenharmony_ci#include "src/codegen/macro-assembler.h"
191cb0ef41Sopenharmony_ci#include "src/codegen/register-configuration.h"
201cb0ef41Sopenharmony_ci#include "src/debug/debug.h"
211cb0ef41Sopenharmony_ci#include "src/deoptimizer/deoptimizer.h"
221cb0ef41Sopenharmony_ci#include "src/execution/frames-inl.h"
231cb0ef41Sopenharmony_ci#include "src/heap/memory-chunk.h"
241cb0ef41Sopenharmony_ci#include "src/init/bootstrapper.h"
251cb0ef41Sopenharmony_ci#include "src/logging/counters.h"
261cb0ef41Sopenharmony_ci#include "src/objects/objects-inl.h"
271cb0ef41Sopenharmony_ci#include "src/runtime/runtime.h"
281cb0ef41Sopenharmony_ci#include "src/snapshot/snapshot.h"
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY
311cb0ef41Sopenharmony_ci#include "src/wasm/wasm-code-manager.h"
321cb0ef41Sopenharmony_ci#endif  // V8_ENABLE_WEBASSEMBLY
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci// Satisfy cpplint check, but don't include platform-specific header. It is
351cb0ef41Sopenharmony_ci// included recursively via macro-assembler.h.
361cb0ef41Sopenharmony_ci#if 0
371cb0ef41Sopenharmony_ci#include "src/codegen/arm/macro-assembler-arm.h"
381cb0ef41Sopenharmony_ci#endif
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_cinamespace v8 {
411cb0ef41Sopenharmony_cinamespace internal {
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ciint TurboAssembler::RequiredStackSizeForCallerSaved(SaveFPRegsMode fp_mode,
441cb0ef41Sopenharmony_ci                                                    Register exclusion1,
451cb0ef41Sopenharmony_ci                                                    Register exclusion2,
461cb0ef41Sopenharmony_ci                                                    Register exclusion3) const {
471cb0ef41Sopenharmony_ci  int bytes = 0;
481cb0ef41Sopenharmony_ci  RegList exclusions = {exclusion1, exclusion2, exclusion3};
491cb0ef41Sopenharmony_ci  RegList list = (kCallerSaved | lr) - exclusions;
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci  bytes += list.Count() * kPointerSize;
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci  if (fp_mode == SaveFPRegsMode::kSave) {
541cb0ef41Sopenharmony_ci    bytes += DwVfpRegister::kNumRegisters * DwVfpRegister::kSizeInBytes;
551cb0ef41Sopenharmony_ci  }
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci  return bytes;
581cb0ef41Sopenharmony_ci}
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ciint TurboAssembler::PushCallerSaved(SaveFPRegsMode fp_mode, Register exclusion1,
611cb0ef41Sopenharmony_ci                                    Register exclusion2, Register exclusion3) {
621cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
631cb0ef41Sopenharmony_ci  int bytes = 0;
641cb0ef41Sopenharmony_ci  RegList exclusions = {exclusion1, exclusion2, exclusion3};
651cb0ef41Sopenharmony_ci  RegList list = (kCallerSaved | lr) - exclusions;
661cb0ef41Sopenharmony_ci  stm(db_w, sp, list);
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_ci  bytes += list.Count() * kPointerSize;
691cb0ef41Sopenharmony_ci
701cb0ef41Sopenharmony_ci  if (fp_mode == SaveFPRegsMode::kSave) {
711cb0ef41Sopenharmony_ci    SaveFPRegs(sp, lr);
721cb0ef41Sopenharmony_ci    bytes += DwVfpRegister::kNumRegisters * DwVfpRegister::kSizeInBytes;
731cb0ef41Sopenharmony_ci  }
741cb0ef41Sopenharmony_ci
751cb0ef41Sopenharmony_ci  return bytes;
761cb0ef41Sopenharmony_ci}
771cb0ef41Sopenharmony_ci
781cb0ef41Sopenharmony_ciint TurboAssembler::PopCallerSaved(SaveFPRegsMode fp_mode, Register exclusion1,
791cb0ef41Sopenharmony_ci                                   Register exclusion2, Register exclusion3) {
801cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
811cb0ef41Sopenharmony_ci  int bytes = 0;
821cb0ef41Sopenharmony_ci  if (fp_mode == SaveFPRegsMode::kSave) {
831cb0ef41Sopenharmony_ci    RestoreFPRegs(sp, lr);
841cb0ef41Sopenharmony_ci    bytes += DwVfpRegister::kNumRegisters * DwVfpRegister::kSizeInBytes;
851cb0ef41Sopenharmony_ci  }
861cb0ef41Sopenharmony_ci
871cb0ef41Sopenharmony_ci  RegList exclusions = {exclusion1, exclusion2, exclusion3};
881cb0ef41Sopenharmony_ci  RegList list = (kCallerSaved | lr) - exclusions;
891cb0ef41Sopenharmony_ci  ldm(ia_w, sp, list);
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ci  bytes += list.Count() * kPointerSize;
921cb0ef41Sopenharmony_ci
931cb0ef41Sopenharmony_ci  return bytes;
941cb0ef41Sopenharmony_ci}
951cb0ef41Sopenharmony_ci
961cb0ef41Sopenharmony_civoid TurboAssembler::LoadFromConstantsTable(Register destination,
971cb0ef41Sopenharmony_ci                                            int constant_index) {
981cb0ef41Sopenharmony_ci  DCHECK(RootsTable::IsImmortalImmovable(RootIndex::kBuiltinsConstantsTable));
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_ci  const uint32_t offset =
1011cb0ef41Sopenharmony_ci      FixedArray::kHeaderSize + constant_index * kPointerSize - kHeapObjectTag;
1021cb0ef41Sopenharmony_ci
1031cb0ef41Sopenharmony_ci  LoadRoot(destination, RootIndex::kBuiltinsConstantsTable);
1041cb0ef41Sopenharmony_ci  ldr(destination, MemOperand(destination, offset));
1051cb0ef41Sopenharmony_ci}
1061cb0ef41Sopenharmony_ci
1071cb0ef41Sopenharmony_civoid TurboAssembler::LoadRootRelative(Register destination, int32_t offset) {
1081cb0ef41Sopenharmony_ci  ldr(destination, MemOperand(kRootRegister, offset));
1091cb0ef41Sopenharmony_ci}
1101cb0ef41Sopenharmony_ci
1111cb0ef41Sopenharmony_civoid TurboAssembler::LoadRootRegisterOffset(Register destination,
1121cb0ef41Sopenharmony_ci                                            intptr_t offset) {
1131cb0ef41Sopenharmony_ci  if (offset == 0) {
1141cb0ef41Sopenharmony_ci    Move(destination, kRootRegister);
1151cb0ef41Sopenharmony_ci  } else {
1161cb0ef41Sopenharmony_ci    add(destination, kRootRegister, Operand(offset));
1171cb0ef41Sopenharmony_ci  }
1181cb0ef41Sopenharmony_ci}
1191cb0ef41Sopenharmony_ci
1201cb0ef41Sopenharmony_civoid TurboAssembler::Jump(Register target, Condition cond) { bx(target, cond); }
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_civoid TurboAssembler::Jump(intptr_t target, RelocInfo::Mode rmode,
1231cb0ef41Sopenharmony_ci                          Condition cond) {
1241cb0ef41Sopenharmony_ci  mov(pc, Operand(target, rmode), LeaveCC, cond);
1251cb0ef41Sopenharmony_ci}
1261cb0ef41Sopenharmony_ci
1271cb0ef41Sopenharmony_civoid TurboAssembler::Jump(Address target, RelocInfo::Mode rmode,
1281cb0ef41Sopenharmony_ci                          Condition cond) {
1291cb0ef41Sopenharmony_ci  DCHECK(!RelocInfo::IsCodeTarget(rmode));
1301cb0ef41Sopenharmony_ci  Jump(static_cast<intptr_t>(target), rmode, cond);
1311cb0ef41Sopenharmony_ci}
1321cb0ef41Sopenharmony_ci
1331cb0ef41Sopenharmony_civoid TurboAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode,
1341cb0ef41Sopenharmony_ci                          Condition cond) {
1351cb0ef41Sopenharmony_ci  DCHECK(RelocInfo::IsCodeTarget(rmode));
1361cb0ef41Sopenharmony_ci  DCHECK_IMPLIES(options().isolate_independent_code,
1371cb0ef41Sopenharmony_ci                 Builtins::IsIsolateIndependentBuiltin(*code));
1381cb0ef41Sopenharmony_ci  DCHECK_IMPLIES(options().use_pc_relative_calls_and_jumps,
1391cb0ef41Sopenharmony_ci                 Builtins::IsIsolateIndependentBuiltin(*code));
1401cb0ef41Sopenharmony_ci
1411cb0ef41Sopenharmony_ci  Builtin builtin = Builtin::kNoBuiltinId;
1421cb0ef41Sopenharmony_ci  bool target_is_builtin =
1431cb0ef41Sopenharmony_ci      isolate()->builtins()->IsBuiltinHandle(code, &builtin);
1441cb0ef41Sopenharmony_ci
1451cb0ef41Sopenharmony_ci  if (options().use_pc_relative_calls_and_jumps && target_is_builtin) {
1461cb0ef41Sopenharmony_ci    int32_t code_target_index = AddCodeTarget(code);
1471cb0ef41Sopenharmony_ci    b(code_target_index * kInstrSize, cond, RelocInfo::RELATIVE_CODE_TARGET);
1481cb0ef41Sopenharmony_ci    return;
1491cb0ef41Sopenharmony_ci  } else if (root_array_available_ && options().isolate_independent_code) {
1501cb0ef41Sopenharmony_ci    // This branch is taken only for specific cctests, where we force isolate
1511cb0ef41Sopenharmony_ci    // creation at runtime. At this point, Code space isn't restricted to a
1521cb0ef41Sopenharmony_ci    // size s.t. pc-relative calls may be used.
1531cb0ef41Sopenharmony_ci    UseScratchRegisterScope temps(this);
1541cb0ef41Sopenharmony_ci    Register scratch = temps.Acquire();
1551cb0ef41Sopenharmony_ci    int offset = IsolateData::BuiltinEntrySlotOffset(code->builtin_id());
1561cb0ef41Sopenharmony_ci    ldr(scratch, MemOperand(kRootRegister, offset));
1571cb0ef41Sopenharmony_ci    Jump(scratch, cond);
1581cb0ef41Sopenharmony_ci    return;
1591cb0ef41Sopenharmony_ci  } else if (options().inline_offheap_trampolines && target_is_builtin) {
1601cb0ef41Sopenharmony_ci    // Inline the trampoline.
1611cb0ef41Sopenharmony_ci    RecordCommentForOffHeapTrampoline(builtin);
1621cb0ef41Sopenharmony_ci    // Use ip directly instead of using UseScratchRegisterScope, as we do not
1631cb0ef41Sopenharmony_ci    // preserve scratch registers across calls.
1641cb0ef41Sopenharmony_ci    mov(ip, Operand(BuiltinEntry(builtin), RelocInfo::OFF_HEAP_TARGET));
1651cb0ef41Sopenharmony_ci    Jump(ip, cond);
1661cb0ef41Sopenharmony_ci    return;
1671cb0ef41Sopenharmony_ci  }
1681cb0ef41Sopenharmony_ci
1691cb0ef41Sopenharmony_ci  // 'code' is always generated ARM code, never THUMB code
1701cb0ef41Sopenharmony_ci  Jump(static_cast<intptr_t>(code.address()), rmode, cond);
1711cb0ef41Sopenharmony_ci}
1721cb0ef41Sopenharmony_ci
1731cb0ef41Sopenharmony_civoid TurboAssembler::Jump(const ExternalReference& reference) {
1741cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
1751cb0ef41Sopenharmony_ci  Register scratch = temps.Acquire();
1761cb0ef41Sopenharmony_ci  Move(scratch, reference);
1771cb0ef41Sopenharmony_ci  Jump(scratch);
1781cb0ef41Sopenharmony_ci}
1791cb0ef41Sopenharmony_ci
1801cb0ef41Sopenharmony_civoid TurboAssembler::Call(Register target, Condition cond) {
1811cb0ef41Sopenharmony_ci  // Block constant pool for the call instruction sequence.
1821cb0ef41Sopenharmony_ci  BlockConstPoolScope block_const_pool(this);
1831cb0ef41Sopenharmony_ci  blx(target, cond);
1841cb0ef41Sopenharmony_ci}
1851cb0ef41Sopenharmony_ci
1861cb0ef41Sopenharmony_civoid TurboAssembler::Call(Address target, RelocInfo::Mode rmode, Condition cond,
1871cb0ef41Sopenharmony_ci                          TargetAddressStorageMode mode,
1881cb0ef41Sopenharmony_ci                          bool check_constant_pool) {
1891cb0ef41Sopenharmony_ci  // Check if we have to emit the constant pool before we block it.
1901cb0ef41Sopenharmony_ci  if (check_constant_pool) MaybeCheckConstPool();
1911cb0ef41Sopenharmony_ci  // Block constant pool for the call instruction sequence.
1921cb0ef41Sopenharmony_ci  BlockConstPoolScope block_const_pool(this);
1931cb0ef41Sopenharmony_ci
1941cb0ef41Sopenharmony_ci  bool old_predictable_code_size = predictable_code_size();
1951cb0ef41Sopenharmony_ci  if (mode == NEVER_INLINE_TARGET_ADDRESS) {
1961cb0ef41Sopenharmony_ci    set_predictable_code_size(true);
1971cb0ef41Sopenharmony_ci  }
1981cb0ef41Sopenharmony_ci
1991cb0ef41Sopenharmony_ci  // Use ip directly instead of using UseScratchRegisterScope, as we do not
2001cb0ef41Sopenharmony_ci  // preserve scratch registers across calls.
2011cb0ef41Sopenharmony_ci
2021cb0ef41Sopenharmony_ci  // Call sequence on V7 or later may be :
2031cb0ef41Sopenharmony_ci  //  movw  ip, #... @ call address low 16
2041cb0ef41Sopenharmony_ci  //  movt  ip, #... @ call address high 16
2051cb0ef41Sopenharmony_ci  //  blx   ip
2061cb0ef41Sopenharmony_ci  //                      @ return address
2071cb0ef41Sopenharmony_ci  // Or for pre-V7 or values that may be back-patched
2081cb0ef41Sopenharmony_ci  // to avoid ICache flushes:
2091cb0ef41Sopenharmony_ci  //  ldr   ip, [pc, #...] @ call address
2101cb0ef41Sopenharmony_ci  //  blx   ip
2111cb0ef41Sopenharmony_ci  //                      @ return address
2121cb0ef41Sopenharmony_ci
2131cb0ef41Sopenharmony_ci  mov(ip, Operand(target, rmode));
2141cb0ef41Sopenharmony_ci  blx(ip, cond);
2151cb0ef41Sopenharmony_ci
2161cb0ef41Sopenharmony_ci  if (mode == NEVER_INLINE_TARGET_ADDRESS) {
2171cb0ef41Sopenharmony_ci    set_predictable_code_size(old_predictable_code_size);
2181cb0ef41Sopenharmony_ci  }
2191cb0ef41Sopenharmony_ci}
2201cb0ef41Sopenharmony_ci
2211cb0ef41Sopenharmony_civoid TurboAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode,
2221cb0ef41Sopenharmony_ci                          Condition cond, TargetAddressStorageMode mode,
2231cb0ef41Sopenharmony_ci                          bool check_constant_pool) {
2241cb0ef41Sopenharmony_ci  DCHECK(RelocInfo::IsCodeTarget(rmode));
2251cb0ef41Sopenharmony_ci  DCHECK_IMPLIES(options().isolate_independent_code,
2261cb0ef41Sopenharmony_ci                 Builtins::IsIsolateIndependentBuiltin(*code));
2271cb0ef41Sopenharmony_ci  DCHECK_IMPLIES(options().use_pc_relative_calls_and_jumps,
2281cb0ef41Sopenharmony_ci                 Builtins::IsIsolateIndependentBuiltin(*code));
2291cb0ef41Sopenharmony_ci
2301cb0ef41Sopenharmony_ci  Builtin builtin = Builtin::kNoBuiltinId;
2311cb0ef41Sopenharmony_ci  bool target_is_builtin =
2321cb0ef41Sopenharmony_ci      isolate()->builtins()->IsBuiltinHandle(code, &builtin);
2331cb0ef41Sopenharmony_ci
2341cb0ef41Sopenharmony_ci  if (target_is_builtin && options().use_pc_relative_calls_and_jumps) {
2351cb0ef41Sopenharmony_ci    int32_t code_target_index = AddCodeTarget(code);
2361cb0ef41Sopenharmony_ci    bl(code_target_index * kInstrSize, cond, RelocInfo::RELATIVE_CODE_TARGET);
2371cb0ef41Sopenharmony_ci    return;
2381cb0ef41Sopenharmony_ci  } else if (root_array_available_ && options().isolate_independent_code) {
2391cb0ef41Sopenharmony_ci    // This branch is taken only for specific cctests, where we force isolate
2401cb0ef41Sopenharmony_ci    // creation at runtime. At this point, Code space isn't restricted to a
2411cb0ef41Sopenharmony_ci    // size s.t. pc-relative calls may be used.
2421cb0ef41Sopenharmony_ci    int offset = IsolateData::BuiltinEntrySlotOffset(code->builtin_id());
2431cb0ef41Sopenharmony_ci    ldr(ip, MemOperand(kRootRegister, offset));
2441cb0ef41Sopenharmony_ci    Call(ip, cond);
2451cb0ef41Sopenharmony_ci    return;
2461cb0ef41Sopenharmony_ci  } else if (target_is_builtin && options().inline_offheap_trampolines) {
2471cb0ef41Sopenharmony_ci    // Inline the trampoline.
2481cb0ef41Sopenharmony_ci    CallBuiltin(builtin);
2491cb0ef41Sopenharmony_ci    return;
2501cb0ef41Sopenharmony_ci  }
2511cb0ef41Sopenharmony_ci
2521cb0ef41Sopenharmony_ci  // 'code' is always generated ARM code, never THUMB code
2531cb0ef41Sopenharmony_ci  DCHECK(code->IsExecutable());
2541cb0ef41Sopenharmony_ci  Call(code.address(), rmode, cond, mode);
2551cb0ef41Sopenharmony_ci}
2561cb0ef41Sopenharmony_ci
2571cb0ef41Sopenharmony_civoid TurboAssembler::LoadEntryFromBuiltinIndex(Register builtin_index) {
2581cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
2591cb0ef41Sopenharmony_ci  STATIC_ASSERT(kSystemPointerSize == 4);
2601cb0ef41Sopenharmony_ci  STATIC_ASSERT(kSmiShiftSize == 0);
2611cb0ef41Sopenharmony_ci  STATIC_ASSERT(kSmiTagSize == 1);
2621cb0ef41Sopenharmony_ci  STATIC_ASSERT(kSmiTag == 0);
2631cb0ef41Sopenharmony_ci
2641cb0ef41Sopenharmony_ci  // The builtin_index register contains the builtin index as a Smi.
2651cb0ef41Sopenharmony_ci  // Untagging is folded into the indexing operand below.
2661cb0ef41Sopenharmony_ci  mov(builtin_index,
2671cb0ef41Sopenharmony_ci      Operand(builtin_index, LSL, kSystemPointerSizeLog2 - kSmiTagSize));
2681cb0ef41Sopenharmony_ci  add(builtin_index, builtin_index,
2691cb0ef41Sopenharmony_ci      Operand(IsolateData::builtin_entry_table_offset()));
2701cb0ef41Sopenharmony_ci  ldr(builtin_index, MemOperand(kRootRegister, builtin_index));
2711cb0ef41Sopenharmony_ci}
2721cb0ef41Sopenharmony_ci
2731cb0ef41Sopenharmony_civoid TurboAssembler::CallBuiltinByIndex(Register builtin_index) {
2741cb0ef41Sopenharmony_ci  LoadEntryFromBuiltinIndex(builtin_index);
2751cb0ef41Sopenharmony_ci  Call(builtin_index);
2761cb0ef41Sopenharmony_ci}
2771cb0ef41Sopenharmony_ci
2781cb0ef41Sopenharmony_civoid TurboAssembler::LoadEntryFromBuiltin(Builtin builtin,
2791cb0ef41Sopenharmony_ci                                          Register destination) {
2801cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
2811cb0ef41Sopenharmony_ci  ldr(destination, EntryFromBuiltinAsOperand(builtin));
2821cb0ef41Sopenharmony_ci}
2831cb0ef41Sopenharmony_ci
2841cb0ef41Sopenharmony_ciMemOperand TurboAssembler::EntryFromBuiltinAsOperand(Builtin builtin) {
2851cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
2861cb0ef41Sopenharmony_ci  DCHECK(root_array_available());
2871cb0ef41Sopenharmony_ci  return MemOperand(kRootRegister,
2881cb0ef41Sopenharmony_ci                    IsolateData::BuiltinEntrySlotOffset(builtin));
2891cb0ef41Sopenharmony_ci}
2901cb0ef41Sopenharmony_ci
2911cb0ef41Sopenharmony_civoid TurboAssembler::CallBuiltin(Builtin builtin, Condition cond) {
2921cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT_STRING(this, CommentForOffHeapTrampoline("call", builtin));
2931cb0ef41Sopenharmony_ci  DCHECK(Builtins::IsBuiltinId(builtin));
2941cb0ef41Sopenharmony_ci  // Use ip directly instead of using UseScratchRegisterScope, as we do not
2951cb0ef41Sopenharmony_ci  // preserve scratch registers across calls.
2961cb0ef41Sopenharmony_ci  mov(ip, Operand(BuiltinEntry(builtin), RelocInfo::OFF_HEAP_TARGET));
2971cb0ef41Sopenharmony_ci  Call(ip, cond);
2981cb0ef41Sopenharmony_ci}
2991cb0ef41Sopenharmony_ci
3001cb0ef41Sopenharmony_civoid TurboAssembler::LoadCodeObjectEntry(Register destination,
3011cb0ef41Sopenharmony_ci                                         Register code_object) {
3021cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
3031cb0ef41Sopenharmony_ci  // Code objects are called differently depending on whether we are generating
3041cb0ef41Sopenharmony_ci  // builtin code (which will later be embedded into the binary) or compiling
3051cb0ef41Sopenharmony_ci  // user JS code at runtime.
3061cb0ef41Sopenharmony_ci  // * Builtin code runs in --jitless mode and thus must not call into on-heap
3071cb0ef41Sopenharmony_ci  //   Code targets. Instead, we dispatch through the builtins entry table.
3081cb0ef41Sopenharmony_ci  // * Codegen at runtime does not have this restriction and we can use the
3091cb0ef41Sopenharmony_ci  //   shorter, branchless instruction sequence. The assumption here is that
3101cb0ef41Sopenharmony_ci  //   targets are usually generated code and not builtin Code objects.
3111cb0ef41Sopenharmony_ci
3121cb0ef41Sopenharmony_ci  if (options().isolate_independent_code) {
3131cb0ef41Sopenharmony_ci    DCHECK(root_array_available());
3141cb0ef41Sopenharmony_ci    Label if_code_is_off_heap, out;
3151cb0ef41Sopenharmony_ci
3161cb0ef41Sopenharmony_ci    {
3171cb0ef41Sopenharmony_ci      UseScratchRegisterScope temps(this);
3181cb0ef41Sopenharmony_ci      Register scratch = temps.Acquire();
3191cb0ef41Sopenharmony_ci
3201cb0ef41Sopenharmony_ci      DCHECK(!AreAliased(destination, scratch));
3211cb0ef41Sopenharmony_ci      DCHECK(!AreAliased(code_object, scratch));
3221cb0ef41Sopenharmony_ci
3231cb0ef41Sopenharmony_ci      // Check whether the Code object is an off-heap trampoline. If so, call
3241cb0ef41Sopenharmony_ci      // its (off-heap) entry point directly without going through the (on-heap)
3251cb0ef41Sopenharmony_ci      // trampoline.  Otherwise, just call the Code object as always.
3261cb0ef41Sopenharmony_ci      ldr(scratch, FieldMemOperand(code_object, Code::kFlagsOffset));
3271cb0ef41Sopenharmony_ci      tst(scratch, Operand(Code::IsOffHeapTrampoline::kMask));
3281cb0ef41Sopenharmony_ci      b(ne, &if_code_is_off_heap);
3291cb0ef41Sopenharmony_ci
3301cb0ef41Sopenharmony_ci      // Not an off-heap trampoline, the entry point is at
3311cb0ef41Sopenharmony_ci      // Code::raw_instruction_start().
3321cb0ef41Sopenharmony_ci      add(destination, code_object,
3331cb0ef41Sopenharmony_ci          Operand(Code::kHeaderSize - kHeapObjectTag));
3341cb0ef41Sopenharmony_ci      jmp(&out);
3351cb0ef41Sopenharmony_ci
3361cb0ef41Sopenharmony_ci      // An off-heap trampoline, the entry point is loaded from the builtin
3371cb0ef41Sopenharmony_ci      // entry table.
3381cb0ef41Sopenharmony_ci      bind(&if_code_is_off_heap);
3391cb0ef41Sopenharmony_ci      ldr(scratch, FieldMemOperand(code_object, Code::kBuiltinIndexOffset));
3401cb0ef41Sopenharmony_ci      lsl(destination, scratch, Operand(kSystemPointerSizeLog2));
3411cb0ef41Sopenharmony_ci    }
3421cb0ef41Sopenharmony_ci    add(destination, destination, kRootRegister);
3431cb0ef41Sopenharmony_ci    ldr(destination,
3441cb0ef41Sopenharmony_ci        MemOperand(destination, IsolateData::builtin_entry_table_offset()));
3451cb0ef41Sopenharmony_ci
3461cb0ef41Sopenharmony_ci    bind(&out);
3471cb0ef41Sopenharmony_ci  } else {
3481cb0ef41Sopenharmony_ci    add(destination, code_object, Operand(Code::kHeaderSize - kHeapObjectTag));
3491cb0ef41Sopenharmony_ci  }
3501cb0ef41Sopenharmony_ci}
3511cb0ef41Sopenharmony_ci
3521cb0ef41Sopenharmony_civoid TurboAssembler::CallCodeObject(Register code_object) {
3531cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
3541cb0ef41Sopenharmony_ci  LoadCodeObjectEntry(code_object, code_object);
3551cb0ef41Sopenharmony_ci  Call(code_object);
3561cb0ef41Sopenharmony_ci}
3571cb0ef41Sopenharmony_ci
3581cb0ef41Sopenharmony_civoid TurboAssembler::JumpCodeObject(Register code_object, JumpMode jump_mode) {
3591cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
3601cb0ef41Sopenharmony_ci  DCHECK_EQ(JumpMode::kJump, jump_mode);
3611cb0ef41Sopenharmony_ci  LoadCodeObjectEntry(code_object, code_object);
3621cb0ef41Sopenharmony_ci  Jump(code_object);
3631cb0ef41Sopenharmony_ci}
3641cb0ef41Sopenharmony_ci
3651cb0ef41Sopenharmony_civoid TurboAssembler::StoreReturnAddressAndCall(Register target) {
3661cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
3671cb0ef41Sopenharmony_ci  // This generates the final instruction sequence for calls to C functions
3681cb0ef41Sopenharmony_ci  // once an exit frame has been constructed.
3691cb0ef41Sopenharmony_ci  //
3701cb0ef41Sopenharmony_ci  // Note that this assumes the caller code (i.e. the Code object currently
3711cb0ef41Sopenharmony_ci  // being generated) is immovable or that the callee function cannot trigger
3721cb0ef41Sopenharmony_ci  // GC, since the callee function will return to it.
3731cb0ef41Sopenharmony_ci
3741cb0ef41Sopenharmony_ci  // Compute the return address in lr to return to after the jump below. The pc
3751cb0ef41Sopenharmony_ci  // is already at '+ 8' from the current instruction; but return is after three
3761cb0ef41Sopenharmony_ci  // instructions, so add another 4 to pc to get the return address.
3771cb0ef41Sopenharmony_ci  Assembler::BlockConstPoolScope block_const_pool(this);
3781cb0ef41Sopenharmony_ci  add(lr, pc, Operand(4));
3791cb0ef41Sopenharmony_ci  str(lr, MemOperand(sp));
3801cb0ef41Sopenharmony_ci  Call(target);
3811cb0ef41Sopenharmony_ci}
3821cb0ef41Sopenharmony_ci
3831cb0ef41Sopenharmony_civoid TurboAssembler::Ret(Condition cond) { bx(lr, cond); }
3841cb0ef41Sopenharmony_ci
3851cb0ef41Sopenharmony_civoid TurboAssembler::Drop(int count, Condition cond) {
3861cb0ef41Sopenharmony_ci  if (count > 0) {
3871cb0ef41Sopenharmony_ci    add(sp, sp, Operand(count * kPointerSize), LeaveCC, cond);
3881cb0ef41Sopenharmony_ci  }
3891cb0ef41Sopenharmony_ci}
3901cb0ef41Sopenharmony_ci
3911cb0ef41Sopenharmony_civoid TurboAssembler::Drop(Register count, Condition cond) {
3921cb0ef41Sopenharmony_ci  add(sp, sp, Operand(count, LSL, kPointerSizeLog2), LeaveCC, cond);
3931cb0ef41Sopenharmony_ci}
3941cb0ef41Sopenharmony_ci
3951cb0ef41Sopenharmony_civoid TurboAssembler::Ret(int drop, Condition cond) {
3961cb0ef41Sopenharmony_ci  Drop(drop, cond);
3971cb0ef41Sopenharmony_ci  Ret(cond);
3981cb0ef41Sopenharmony_ci}
3991cb0ef41Sopenharmony_ci
4001cb0ef41Sopenharmony_civoid TurboAssembler::Call(Label* target) { bl(target); }
4011cb0ef41Sopenharmony_ci
4021cb0ef41Sopenharmony_civoid TurboAssembler::Push(Handle<HeapObject> handle) {
4031cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
4041cb0ef41Sopenharmony_ci  Register scratch = temps.Acquire();
4051cb0ef41Sopenharmony_ci  mov(scratch, Operand(handle));
4061cb0ef41Sopenharmony_ci  push(scratch);
4071cb0ef41Sopenharmony_ci}
4081cb0ef41Sopenharmony_ci
4091cb0ef41Sopenharmony_civoid TurboAssembler::Push(Smi smi) {
4101cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
4111cb0ef41Sopenharmony_ci  Register scratch = temps.Acquire();
4121cb0ef41Sopenharmony_ci  mov(scratch, Operand(smi));
4131cb0ef41Sopenharmony_ci  push(scratch);
4141cb0ef41Sopenharmony_ci}
4151cb0ef41Sopenharmony_ci
4161cb0ef41Sopenharmony_civoid TurboAssembler::PushArray(Register array, Register size, Register scratch,
4171cb0ef41Sopenharmony_ci                               PushArrayOrder order) {
4181cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
4191cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
4201cb0ef41Sopenharmony_ci  Register counter = scratch;
4211cb0ef41Sopenharmony_ci  Register tmp = temps.Acquire();
4221cb0ef41Sopenharmony_ci  DCHECK(!AreAliased(array, size, counter, tmp));
4231cb0ef41Sopenharmony_ci  Label loop, entry;
4241cb0ef41Sopenharmony_ci  if (order == PushArrayOrder::kReverse) {
4251cb0ef41Sopenharmony_ci    mov(counter, Operand(0));
4261cb0ef41Sopenharmony_ci    b(&entry);
4271cb0ef41Sopenharmony_ci    bind(&loop);
4281cb0ef41Sopenharmony_ci    ldr(tmp, MemOperand(array, counter, LSL, kSystemPointerSizeLog2));
4291cb0ef41Sopenharmony_ci    push(tmp);
4301cb0ef41Sopenharmony_ci    add(counter, counter, Operand(1));
4311cb0ef41Sopenharmony_ci    bind(&entry);
4321cb0ef41Sopenharmony_ci    cmp(counter, size);
4331cb0ef41Sopenharmony_ci    b(lt, &loop);
4341cb0ef41Sopenharmony_ci  } else {
4351cb0ef41Sopenharmony_ci    mov(counter, size);
4361cb0ef41Sopenharmony_ci    b(&entry);
4371cb0ef41Sopenharmony_ci    bind(&loop);
4381cb0ef41Sopenharmony_ci    ldr(tmp, MemOperand(array, counter, LSL, kSystemPointerSizeLog2));
4391cb0ef41Sopenharmony_ci    push(tmp);
4401cb0ef41Sopenharmony_ci    bind(&entry);
4411cb0ef41Sopenharmony_ci    sub(counter, counter, Operand(1), SetCC);
4421cb0ef41Sopenharmony_ci    b(ge, &loop);
4431cb0ef41Sopenharmony_ci  }
4441cb0ef41Sopenharmony_ci}
4451cb0ef41Sopenharmony_ci
4461cb0ef41Sopenharmony_civoid TurboAssembler::Move(Register dst, Smi smi) { mov(dst, Operand(smi)); }
4471cb0ef41Sopenharmony_ci
4481cb0ef41Sopenharmony_civoid TurboAssembler::Move(Register dst, Handle<HeapObject> value) {
4491cb0ef41Sopenharmony_ci  // TODO(jgruber,v8:8887): Also consider a root-relative load when generating
4501cb0ef41Sopenharmony_ci  // non-isolate-independent code. In many cases it might be cheaper than
4511cb0ef41Sopenharmony_ci  // embedding the relocatable value.
4521cb0ef41Sopenharmony_ci  if (root_array_available_ && options().isolate_independent_code) {
4531cb0ef41Sopenharmony_ci    IndirectLoadConstant(dst, value);
4541cb0ef41Sopenharmony_ci    return;
4551cb0ef41Sopenharmony_ci  }
4561cb0ef41Sopenharmony_ci  mov(dst, Operand(value));
4571cb0ef41Sopenharmony_ci}
4581cb0ef41Sopenharmony_ci
4591cb0ef41Sopenharmony_civoid TurboAssembler::Move(Register dst, ExternalReference reference) {
4601cb0ef41Sopenharmony_ci  // TODO(jgruber,v8:8887): Also consider a root-relative load when generating
4611cb0ef41Sopenharmony_ci  // non-isolate-independent code. In many cases it might be cheaper than
4621cb0ef41Sopenharmony_ci  // embedding the relocatable value.
4631cb0ef41Sopenharmony_ci  if (root_array_available_ && options().isolate_independent_code) {
4641cb0ef41Sopenharmony_ci    IndirectLoadExternalReference(dst, reference);
4651cb0ef41Sopenharmony_ci    return;
4661cb0ef41Sopenharmony_ci  }
4671cb0ef41Sopenharmony_ci  mov(dst, Operand(reference));
4681cb0ef41Sopenharmony_ci}
4691cb0ef41Sopenharmony_ci
4701cb0ef41Sopenharmony_civoid TurboAssembler::Move(Register dst, Register src, Condition cond) {
4711cb0ef41Sopenharmony_ci  if (dst != src) {
4721cb0ef41Sopenharmony_ci    mov(dst, src, LeaveCC, cond);
4731cb0ef41Sopenharmony_ci  }
4741cb0ef41Sopenharmony_ci}
4751cb0ef41Sopenharmony_ci
4761cb0ef41Sopenharmony_civoid TurboAssembler::Move(SwVfpRegister dst, SwVfpRegister src,
4771cb0ef41Sopenharmony_ci                          Condition cond) {
4781cb0ef41Sopenharmony_ci  if (dst != src) {
4791cb0ef41Sopenharmony_ci    vmov(dst, src, cond);
4801cb0ef41Sopenharmony_ci  }
4811cb0ef41Sopenharmony_ci}
4821cb0ef41Sopenharmony_ci
4831cb0ef41Sopenharmony_civoid TurboAssembler::Move(DwVfpRegister dst, DwVfpRegister src,
4841cb0ef41Sopenharmony_ci                          Condition cond) {
4851cb0ef41Sopenharmony_ci  if (dst != src) {
4861cb0ef41Sopenharmony_ci    vmov(dst, src, cond);
4871cb0ef41Sopenharmony_ci  }
4881cb0ef41Sopenharmony_ci}
4891cb0ef41Sopenharmony_ci
4901cb0ef41Sopenharmony_civoid TurboAssembler::Move(QwNeonRegister dst, QwNeonRegister src) {
4911cb0ef41Sopenharmony_ci  if (dst != src) {
4921cb0ef41Sopenharmony_ci    vmov(dst, src);
4931cb0ef41Sopenharmony_ci  }
4941cb0ef41Sopenharmony_ci}
4951cb0ef41Sopenharmony_ci
4961cb0ef41Sopenharmony_civoid TurboAssembler::MovePair(Register dst0, Register src0, Register dst1,
4971cb0ef41Sopenharmony_ci                              Register src1) {
4981cb0ef41Sopenharmony_ci  DCHECK_NE(dst0, dst1);
4991cb0ef41Sopenharmony_ci  if (dst0 != src1) {
5001cb0ef41Sopenharmony_ci    Move(dst0, src0);
5011cb0ef41Sopenharmony_ci    Move(dst1, src1);
5021cb0ef41Sopenharmony_ci  } else if (dst1 != src0) {
5031cb0ef41Sopenharmony_ci    // Swap the order of the moves to resolve the overlap.
5041cb0ef41Sopenharmony_ci    Move(dst1, src1);
5051cb0ef41Sopenharmony_ci    Move(dst0, src0);
5061cb0ef41Sopenharmony_ci  } else {
5071cb0ef41Sopenharmony_ci    // Worse case scenario, this is a swap.
5081cb0ef41Sopenharmony_ci    Swap(dst0, src0);
5091cb0ef41Sopenharmony_ci  }
5101cb0ef41Sopenharmony_ci}
5111cb0ef41Sopenharmony_ci
5121cb0ef41Sopenharmony_civoid TurboAssembler::Swap(Register srcdst0, Register srcdst1) {
5131cb0ef41Sopenharmony_ci  DCHECK(srcdst0 != srcdst1);
5141cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
5151cb0ef41Sopenharmony_ci  Register scratch = temps.Acquire();
5161cb0ef41Sopenharmony_ci  mov(scratch, srcdst0);
5171cb0ef41Sopenharmony_ci  mov(srcdst0, srcdst1);
5181cb0ef41Sopenharmony_ci  mov(srcdst1, scratch);
5191cb0ef41Sopenharmony_ci}
5201cb0ef41Sopenharmony_ci
5211cb0ef41Sopenharmony_civoid TurboAssembler::Swap(DwVfpRegister srcdst0, DwVfpRegister srcdst1) {
5221cb0ef41Sopenharmony_ci  DCHECK(srcdst0 != srcdst1);
5231cb0ef41Sopenharmony_ci  DCHECK(VfpRegisterIsAvailable(srcdst0));
5241cb0ef41Sopenharmony_ci  DCHECK(VfpRegisterIsAvailable(srcdst1));
5251cb0ef41Sopenharmony_ci
5261cb0ef41Sopenharmony_ci  if (CpuFeatures::IsSupported(NEON)) {
5271cb0ef41Sopenharmony_ci    vswp(srcdst0, srcdst1);
5281cb0ef41Sopenharmony_ci  } else {
5291cb0ef41Sopenharmony_ci    UseScratchRegisterScope temps(this);
5301cb0ef41Sopenharmony_ci    DwVfpRegister scratch = temps.AcquireD();
5311cb0ef41Sopenharmony_ci    vmov(scratch, srcdst0);
5321cb0ef41Sopenharmony_ci    vmov(srcdst0, srcdst1);
5331cb0ef41Sopenharmony_ci    vmov(srcdst1, scratch);
5341cb0ef41Sopenharmony_ci  }
5351cb0ef41Sopenharmony_ci}
5361cb0ef41Sopenharmony_ci
5371cb0ef41Sopenharmony_civoid TurboAssembler::Swap(QwNeonRegister srcdst0, QwNeonRegister srcdst1) {
5381cb0ef41Sopenharmony_ci  DCHECK(srcdst0 != srcdst1);
5391cb0ef41Sopenharmony_ci  vswp(srcdst0, srcdst1);
5401cb0ef41Sopenharmony_ci}
5411cb0ef41Sopenharmony_ci
5421cb0ef41Sopenharmony_civoid MacroAssembler::Mls(Register dst, Register src1, Register src2,
5431cb0ef41Sopenharmony_ci                         Register srcA, Condition cond) {
5441cb0ef41Sopenharmony_ci  if (CpuFeatures::IsSupported(ARMv7)) {
5451cb0ef41Sopenharmony_ci    CpuFeatureScope scope(this, ARMv7);
5461cb0ef41Sopenharmony_ci    mls(dst, src1, src2, srcA, cond);
5471cb0ef41Sopenharmony_ci  } else {
5481cb0ef41Sopenharmony_ci    UseScratchRegisterScope temps(this);
5491cb0ef41Sopenharmony_ci    Register scratch = temps.Acquire();
5501cb0ef41Sopenharmony_ci    DCHECK(srcA != scratch);
5511cb0ef41Sopenharmony_ci    mul(scratch, src1, src2, LeaveCC, cond);
5521cb0ef41Sopenharmony_ci    sub(dst, srcA, scratch, LeaveCC, cond);
5531cb0ef41Sopenharmony_ci  }
5541cb0ef41Sopenharmony_ci}
5551cb0ef41Sopenharmony_ci
5561cb0ef41Sopenharmony_civoid MacroAssembler::And(Register dst, Register src1, const Operand& src2,
5571cb0ef41Sopenharmony_ci                         Condition cond) {
5581cb0ef41Sopenharmony_ci  if (!src2.IsRegister() && !src2.MustOutputRelocInfo(this) &&
5591cb0ef41Sopenharmony_ci      src2.immediate() == 0) {
5601cb0ef41Sopenharmony_ci    mov(dst, Operand::Zero(), LeaveCC, cond);
5611cb0ef41Sopenharmony_ci  } else if (!(src2.InstructionsRequired(this) == 1) &&
5621cb0ef41Sopenharmony_ci             !src2.MustOutputRelocInfo(this) &&
5631cb0ef41Sopenharmony_ci             CpuFeatures::IsSupported(ARMv7) &&
5641cb0ef41Sopenharmony_ci             base::bits::IsPowerOfTwo(src2.immediate() + 1)) {
5651cb0ef41Sopenharmony_ci    CpuFeatureScope scope(this, ARMv7);
5661cb0ef41Sopenharmony_ci    ubfx(dst, src1, 0,
5671cb0ef41Sopenharmony_ci         base::bits::WhichPowerOfTwo(static_cast<uint32_t>(src2.immediate()) +
5681cb0ef41Sopenharmony_ci                                     1),
5691cb0ef41Sopenharmony_ci         cond);
5701cb0ef41Sopenharmony_ci  } else {
5711cb0ef41Sopenharmony_ci    and_(dst, src1, src2, LeaveCC, cond);
5721cb0ef41Sopenharmony_ci  }
5731cb0ef41Sopenharmony_ci}
5741cb0ef41Sopenharmony_ci
5751cb0ef41Sopenharmony_civoid MacroAssembler::Ubfx(Register dst, Register src1, int lsb, int width,
5761cb0ef41Sopenharmony_ci                          Condition cond) {
5771cb0ef41Sopenharmony_ci  DCHECK_LT(lsb, 32);
5781cb0ef41Sopenharmony_ci  if (!CpuFeatures::IsSupported(ARMv7) || predictable_code_size()) {
5791cb0ef41Sopenharmony_ci    int mask = (1u << (width + lsb)) - 1u - ((1u << lsb) - 1u);
5801cb0ef41Sopenharmony_ci    and_(dst, src1, Operand(mask), LeaveCC, cond);
5811cb0ef41Sopenharmony_ci    if (lsb != 0) {
5821cb0ef41Sopenharmony_ci      mov(dst, Operand(dst, LSR, lsb), LeaveCC, cond);
5831cb0ef41Sopenharmony_ci    }
5841cb0ef41Sopenharmony_ci  } else {
5851cb0ef41Sopenharmony_ci    CpuFeatureScope scope(this, ARMv7);
5861cb0ef41Sopenharmony_ci    ubfx(dst, src1, lsb, width, cond);
5871cb0ef41Sopenharmony_ci  }
5881cb0ef41Sopenharmony_ci}
5891cb0ef41Sopenharmony_ci
5901cb0ef41Sopenharmony_civoid MacroAssembler::Sbfx(Register dst, Register src1, int lsb, int width,
5911cb0ef41Sopenharmony_ci                          Condition cond) {
5921cb0ef41Sopenharmony_ci  DCHECK_LT(lsb, 32);
5931cb0ef41Sopenharmony_ci  if (!CpuFeatures::IsSupported(ARMv7) || predictable_code_size()) {
5941cb0ef41Sopenharmony_ci    int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1);
5951cb0ef41Sopenharmony_ci    and_(dst, src1, Operand(mask), LeaveCC, cond);
5961cb0ef41Sopenharmony_ci    int shift_up = 32 - lsb - width;
5971cb0ef41Sopenharmony_ci    int shift_down = lsb + shift_up;
5981cb0ef41Sopenharmony_ci    if (shift_up != 0) {
5991cb0ef41Sopenharmony_ci      mov(dst, Operand(dst, LSL, shift_up), LeaveCC, cond);
6001cb0ef41Sopenharmony_ci    }
6011cb0ef41Sopenharmony_ci    if (shift_down != 0) {
6021cb0ef41Sopenharmony_ci      mov(dst, Operand(dst, ASR, shift_down), LeaveCC, cond);
6031cb0ef41Sopenharmony_ci    }
6041cb0ef41Sopenharmony_ci  } else {
6051cb0ef41Sopenharmony_ci    CpuFeatureScope scope(this, ARMv7);
6061cb0ef41Sopenharmony_ci    sbfx(dst, src1, lsb, width, cond);
6071cb0ef41Sopenharmony_ci  }
6081cb0ef41Sopenharmony_ci}
6091cb0ef41Sopenharmony_ci
6101cb0ef41Sopenharmony_civoid TurboAssembler::Bfc(Register dst, Register src, int lsb, int width,
6111cb0ef41Sopenharmony_ci                         Condition cond) {
6121cb0ef41Sopenharmony_ci  DCHECK_LT(lsb, 32);
6131cb0ef41Sopenharmony_ci  if (!CpuFeatures::IsSupported(ARMv7) || predictable_code_size()) {
6141cb0ef41Sopenharmony_ci    int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1);
6151cb0ef41Sopenharmony_ci    bic(dst, src, Operand(mask));
6161cb0ef41Sopenharmony_ci  } else {
6171cb0ef41Sopenharmony_ci    CpuFeatureScope scope(this, ARMv7);
6181cb0ef41Sopenharmony_ci    Move(dst, src, cond);
6191cb0ef41Sopenharmony_ci    bfc(dst, lsb, width, cond);
6201cb0ef41Sopenharmony_ci  }
6211cb0ef41Sopenharmony_ci}
6221cb0ef41Sopenharmony_ci
6231cb0ef41Sopenharmony_civoid TurboAssembler::LoadRoot(Register destination, RootIndex index,
6241cb0ef41Sopenharmony_ci                              Condition cond) {
6251cb0ef41Sopenharmony_ci  ldr(destination,
6261cb0ef41Sopenharmony_ci      MemOperand(kRootRegister, RootRegisterOffsetForRootIndex(index)), cond);
6271cb0ef41Sopenharmony_ci}
6281cb0ef41Sopenharmony_ci
6291cb0ef41Sopenharmony_civoid MacroAssembler::RecordWriteField(Register object, int offset,
6301cb0ef41Sopenharmony_ci                                      Register value,
6311cb0ef41Sopenharmony_ci                                      LinkRegisterStatus lr_status,
6321cb0ef41Sopenharmony_ci                                      SaveFPRegsMode save_fp,
6331cb0ef41Sopenharmony_ci                                      RememberedSetAction remembered_set_action,
6341cb0ef41Sopenharmony_ci                                      SmiCheck smi_check) {
6351cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
6361cb0ef41Sopenharmony_ci  // First, check if a write barrier is even needed. The tests below
6371cb0ef41Sopenharmony_ci  // catch stores of Smis.
6381cb0ef41Sopenharmony_ci  Label done;
6391cb0ef41Sopenharmony_ci
6401cb0ef41Sopenharmony_ci  // Skip barrier if writing a smi.
6411cb0ef41Sopenharmony_ci  if (smi_check == SmiCheck::kInline) {
6421cb0ef41Sopenharmony_ci    JumpIfSmi(value, &done);
6431cb0ef41Sopenharmony_ci  }
6441cb0ef41Sopenharmony_ci
6451cb0ef41Sopenharmony_ci  // Although the object register is tagged, the offset is relative to the start
6461cb0ef41Sopenharmony_ci  // of the object, so so offset must be a multiple of kPointerSize.
6471cb0ef41Sopenharmony_ci  DCHECK(IsAligned(offset, kPointerSize));
6481cb0ef41Sopenharmony_ci
6491cb0ef41Sopenharmony_ci  if (FLAG_debug_code) {
6501cb0ef41Sopenharmony_ci    ASM_CODE_COMMENT_STRING(this, "Verify slot_address");
6511cb0ef41Sopenharmony_ci    Label ok;
6521cb0ef41Sopenharmony_ci    UseScratchRegisterScope temps(this);
6531cb0ef41Sopenharmony_ci    Register scratch = temps.Acquire();
6541cb0ef41Sopenharmony_ci    DCHECK(!AreAliased(object, value, scratch));
6551cb0ef41Sopenharmony_ci    add(scratch, object, Operand(offset - kHeapObjectTag));
6561cb0ef41Sopenharmony_ci    tst(scratch, Operand(kPointerSize - 1));
6571cb0ef41Sopenharmony_ci    b(eq, &ok);
6581cb0ef41Sopenharmony_ci    stop();
6591cb0ef41Sopenharmony_ci    bind(&ok);
6601cb0ef41Sopenharmony_ci  }
6611cb0ef41Sopenharmony_ci
6621cb0ef41Sopenharmony_ci  RecordWrite(object, Operand(offset - kHeapObjectTag), value, lr_status,
6631cb0ef41Sopenharmony_ci              save_fp, remembered_set_action, SmiCheck::kOmit);
6641cb0ef41Sopenharmony_ci
6651cb0ef41Sopenharmony_ci  bind(&done);
6661cb0ef41Sopenharmony_ci}
6671cb0ef41Sopenharmony_ci
6681cb0ef41Sopenharmony_civoid TurboAssembler::MaybeSaveRegisters(RegList registers) {
6691cb0ef41Sopenharmony_ci  if (registers.is_empty()) return;
6701cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
6711cb0ef41Sopenharmony_ci  stm(db_w, sp, registers);
6721cb0ef41Sopenharmony_ci}
6731cb0ef41Sopenharmony_ci
6741cb0ef41Sopenharmony_civoid TurboAssembler::MaybeRestoreRegisters(RegList registers) {
6751cb0ef41Sopenharmony_ci  if (registers.is_empty()) return;
6761cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
6771cb0ef41Sopenharmony_ci  ldm(ia_w, sp, registers);
6781cb0ef41Sopenharmony_ci}
6791cb0ef41Sopenharmony_ci
6801cb0ef41Sopenharmony_civoid TurboAssembler::CallEphemeronKeyBarrier(Register object, Operand offset,
6811cb0ef41Sopenharmony_ci                                             SaveFPRegsMode fp_mode) {
6821cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
6831cb0ef41Sopenharmony_ci  RegList registers = WriteBarrierDescriptor::ComputeSavedRegisters(object);
6841cb0ef41Sopenharmony_ci  MaybeSaveRegisters(registers);
6851cb0ef41Sopenharmony_ci
6861cb0ef41Sopenharmony_ci  Register object_parameter = WriteBarrierDescriptor::ObjectRegister();
6871cb0ef41Sopenharmony_ci  Register slot_address_parameter =
6881cb0ef41Sopenharmony_ci      WriteBarrierDescriptor::SlotAddressRegister();
6891cb0ef41Sopenharmony_ci  MoveObjectAndSlot(object_parameter, slot_address_parameter, object, offset);
6901cb0ef41Sopenharmony_ci
6911cb0ef41Sopenharmony_ci  Call(isolate()->builtins()->code_handle(
6921cb0ef41Sopenharmony_ci           Builtins::GetEphemeronKeyBarrierStub(fp_mode)),
6931cb0ef41Sopenharmony_ci       RelocInfo::CODE_TARGET);
6941cb0ef41Sopenharmony_ci  MaybeRestoreRegisters(registers);
6951cb0ef41Sopenharmony_ci}
6961cb0ef41Sopenharmony_ci
6971cb0ef41Sopenharmony_civoid TurboAssembler::CallRecordWriteStubSaveRegisters(
6981cb0ef41Sopenharmony_ci    Register object, Operand offset, RememberedSetAction remembered_set_action,
6991cb0ef41Sopenharmony_ci    SaveFPRegsMode fp_mode, StubCallMode mode) {
7001cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
7011cb0ef41Sopenharmony_ci  RegList registers = WriteBarrierDescriptor::ComputeSavedRegisters(object);
7021cb0ef41Sopenharmony_ci  MaybeSaveRegisters(registers);
7031cb0ef41Sopenharmony_ci
7041cb0ef41Sopenharmony_ci  Register object_parameter = WriteBarrierDescriptor::ObjectRegister();
7051cb0ef41Sopenharmony_ci  Register slot_address_parameter =
7061cb0ef41Sopenharmony_ci      WriteBarrierDescriptor::SlotAddressRegister();
7071cb0ef41Sopenharmony_ci  MoveObjectAndSlot(object_parameter, slot_address_parameter, object, offset);
7081cb0ef41Sopenharmony_ci
7091cb0ef41Sopenharmony_ci  CallRecordWriteStub(object_parameter, slot_address_parameter,
7101cb0ef41Sopenharmony_ci                      remembered_set_action, fp_mode, mode);
7111cb0ef41Sopenharmony_ci
7121cb0ef41Sopenharmony_ci  MaybeRestoreRegisters(registers);
7131cb0ef41Sopenharmony_ci}
7141cb0ef41Sopenharmony_ci
7151cb0ef41Sopenharmony_civoid TurboAssembler::CallRecordWriteStub(
7161cb0ef41Sopenharmony_ci    Register object, Register slot_address,
7171cb0ef41Sopenharmony_ci    RememberedSetAction remembered_set_action, SaveFPRegsMode fp_mode,
7181cb0ef41Sopenharmony_ci    StubCallMode mode) {
7191cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
7201cb0ef41Sopenharmony_ci  DCHECK_EQ(WriteBarrierDescriptor::ObjectRegister(), object);
7211cb0ef41Sopenharmony_ci  DCHECK_EQ(WriteBarrierDescriptor::SlotAddressRegister(), slot_address);
7221cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY
7231cb0ef41Sopenharmony_ci  if (mode == StubCallMode::kCallWasmRuntimeStub) {
7241cb0ef41Sopenharmony_ci    auto wasm_target =
7251cb0ef41Sopenharmony_ci        wasm::WasmCode::GetRecordWriteStub(remembered_set_action, fp_mode);
7261cb0ef41Sopenharmony_ci    Call(wasm_target, RelocInfo::WASM_STUB_CALL);
7271cb0ef41Sopenharmony_ci#else
7281cb0ef41Sopenharmony_ci  if (false) {
7291cb0ef41Sopenharmony_ci#endif
7301cb0ef41Sopenharmony_ci  } else {
7311cb0ef41Sopenharmony_ci    Builtin builtin =
7321cb0ef41Sopenharmony_ci        Builtins::GetRecordWriteStub(remembered_set_action, fp_mode);
7331cb0ef41Sopenharmony_ci    if (options().inline_offheap_trampolines) {
7341cb0ef41Sopenharmony_ci      CallBuiltin(builtin);
7351cb0ef41Sopenharmony_ci    } else {
7361cb0ef41Sopenharmony_ci      Handle<Code> code_target = isolate()->builtins()->code_handle(builtin);
7371cb0ef41Sopenharmony_ci      Call(code_target, RelocInfo::CODE_TARGET);
7381cb0ef41Sopenharmony_ci    }
7391cb0ef41Sopenharmony_ci  }
7401cb0ef41Sopenharmony_ci}
7411cb0ef41Sopenharmony_ci
7421cb0ef41Sopenharmony_civoid TurboAssembler::MoveObjectAndSlot(Register dst_object, Register dst_slot,
7431cb0ef41Sopenharmony_ci                                       Register object, Operand offset) {
7441cb0ef41Sopenharmony_ci  DCHECK_NE(dst_object, dst_slot);
7451cb0ef41Sopenharmony_ci  DCHECK(offset.IsRegister() || offset.IsImmediate());
7461cb0ef41Sopenharmony_ci  // If `offset` is a register, it cannot overlap with `object`.
7471cb0ef41Sopenharmony_ci  DCHECK_IMPLIES(offset.IsRegister(), offset.rm() != object);
7481cb0ef41Sopenharmony_ci
7491cb0ef41Sopenharmony_ci  // If the slot register does not overlap with the object register, we can
7501cb0ef41Sopenharmony_ci  // overwrite it.
7511cb0ef41Sopenharmony_ci  if (dst_slot != object) {
7521cb0ef41Sopenharmony_ci    add(dst_slot, object, offset);
7531cb0ef41Sopenharmony_ci    Move(dst_object, object);
7541cb0ef41Sopenharmony_ci    return;
7551cb0ef41Sopenharmony_ci  }
7561cb0ef41Sopenharmony_ci
7571cb0ef41Sopenharmony_ci  DCHECK_EQ(dst_slot, object);
7581cb0ef41Sopenharmony_ci
7591cb0ef41Sopenharmony_ci  // If the destination object register does not overlap with the offset
7601cb0ef41Sopenharmony_ci  // register, we can overwrite it.
7611cb0ef41Sopenharmony_ci  if (!offset.IsRegister() || (offset.rm() != dst_object)) {
7621cb0ef41Sopenharmony_ci    Move(dst_object, dst_slot);
7631cb0ef41Sopenharmony_ci    add(dst_slot, dst_slot, offset);
7641cb0ef41Sopenharmony_ci    return;
7651cb0ef41Sopenharmony_ci  }
7661cb0ef41Sopenharmony_ci
7671cb0ef41Sopenharmony_ci  DCHECK_EQ(dst_object, offset.rm());
7681cb0ef41Sopenharmony_ci
7691cb0ef41Sopenharmony_ci  // We only have `dst_slot` and `dst_object` left as distinct registers so we
7701cb0ef41Sopenharmony_ci  // have to swap them. We write this as a add+sub sequence to avoid using a
7711cb0ef41Sopenharmony_ci  // scratch register.
7721cb0ef41Sopenharmony_ci  add(dst_slot, dst_slot, dst_object);
7731cb0ef41Sopenharmony_ci  sub(dst_object, dst_slot, dst_object);
7741cb0ef41Sopenharmony_ci}
7751cb0ef41Sopenharmony_ci
7761cb0ef41Sopenharmony_ci// The register 'object' contains a heap object pointer. The heap object tag is
7771cb0ef41Sopenharmony_ci// shifted away. A scratch register also needs to be available.
7781cb0ef41Sopenharmony_civoid MacroAssembler::RecordWrite(Register object, Operand offset,
7791cb0ef41Sopenharmony_ci                                 Register value, LinkRegisterStatus lr_status,
7801cb0ef41Sopenharmony_ci                                 SaveFPRegsMode fp_mode,
7811cb0ef41Sopenharmony_ci                                 RememberedSetAction remembered_set_action,
7821cb0ef41Sopenharmony_ci                                 SmiCheck smi_check) {
7831cb0ef41Sopenharmony_ci  DCHECK(!AreAliased(object, value));
7841cb0ef41Sopenharmony_ci  if (FLAG_debug_code) {
7851cb0ef41Sopenharmony_ci    ASM_CODE_COMMENT_STRING(this, "Verify slot_address");
7861cb0ef41Sopenharmony_ci    UseScratchRegisterScope temps(this);
7871cb0ef41Sopenharmony_ci    Register scratch = temps.Acquire();
7881cb0ef41Sopenharmony_ci    DCHECK(!AreAliased(object, value, scratch));
7891cb0ef41Sopenharmony_ci    add(scratch, object, offset);
7901cb0ef41Sopenharmony_ci    ldr(scratch, MemOperand(scratch));
7911cb0ef41Sopenharmony_ci    cmp(scratch, value);
7921cb0ef41Sopenharmony_ci    Check(eq, AbortReason::kWrongAddressOrValuePassedToRecordWrite);
7931cb0ef41Sopenharmony_ci  }
7941cb0ef41Sopenharmony_ci
7951cb0ef41Sopenharmony_ci  if ((remembered_set_action == RememberedSetAction::kOmit &&
7961cb0ef41Sopenharmony_ci       !FLAG_incremental_marking) ||
7971cb0ef41Sopenharmony_ci      FLAG_disable_write_barriers) {
7981cb0ef41Sopenharmony_ci    return;
7991cb0ef41Sopenharmony_ci  }
8001cb0ef41Sopenharmony_ci
8011cb0ef41Sopenharmony_ci  // First, check if a write barrier is even needed. The tests below
8021cb0ef41Sopenharmony_ci  // catch stores of smis and stores into the young generation.
8031cb0ef41Sopenharmony_ci  Label done;
8041cb0ef41Sopenharmony_ci
8051cb0ef41Sopenharmony_ci  if (smi_check == SmiCheck::kInline) {
8061cb0ef41Sopenharmony_ci    JumpIfSmi(value, &done);
8071cb0ef41Sopenharmony_ci  }
8081cb0ef41Sopenharmony_ci
8091cb0ef41Sopenharmony_ci  CheckPageFlag(value, MemoryChunk::kPointersToHereAreInterestingMask, eq,
8101cb0ef41Sopenharmony_ci                &done);
8111cb0ef41Sopenharmony_ci  CheckPageFlag(object, MemoryChunk::kPointersFromHereAreInterestingMask, eq,
8121cb0ef41Sopenharmony_ci                &done);
8131cb0ef41Sopenharmony_ci
8141cb0ef41Sopenharmony_ci  // Record the actual write.
8151cb0ef41Sopenharmony_ci  if (lr_status == kLRHasNotBeenSaved) {
8161cb0ef41Sopenharmony_ci    push(lr);
8171cb0ef41Sopenharmony_ci  }
8181cb0ef41Sopenharmony_ci
8191cb0ef41Sopenharmony_ci  Register slot_address = WriteBarrierDescriptor::SlotAddressRegister();
8201cb0ef41Sopenharmony_ci  DCHECK(!AreAliased(object, value, slot_address));
8211cb0ef41Sopenharmony_ci  DCHECK(!offset.IsRegister());
8221cb0ef41Sopenharmony_ci  add(slot_address, object, offset);
8231cb0ef41Sopenharmony_ci  CallRecordWriteStub(object, slot_address, remembered_set_action, fp_mode);
8241cb0ef41Sopenharmony_ci  if (lr_status == kLRHasNotBeenSaved) {
8251cb0ef41Sopenharmony_ci    pop(lr);
8261cb0ef41Sopenharmony_ci  }
8271cb0ef41Sopenharmony_ci
8281cb0ef41Sopenharmony_ci  if (FLAG_debug_code) Move(slot_address, Operand(kZapValue));
8291cb0ef41Sopenharmony_ci
8301cb0ef41Sopenharmony_ci  bind(&done);
8311cb0ef41Sopenharmony_ci}
8321cb0ef41Sopenharmony_ci
8331cb0ef41Sopenharmony_civoid TurboAssembler::PushCommonFrame(Register marker_reg) {
8341cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
8351cb0ef41Sopenharmony_ci  if (marker_reg.is_valid()) {
8361cb0ef41Sopenharmony_ci    if (marker_reg.code() > fp.code()) {
8371cb0ef41Sopenharmony_ci      stm(db_w, sp, {fp, lr});
8381cb0ef41Sopenharmony_ci      mov(fp, Operand(sp));
8391cb0ef41Sopenharmony_ci      Push(marker_reg);
8401cb0ef41Sopenharmony_ci    } else {
8411cb0ef41Sopenharmony_ci      stm(db_w, sp, {marker_reg, fp, lr});
8421cb0ef41Sopenharmony_ci      add(fp, sp, Operand(kPointerSize));
8431cb0ef41Sopenharmony_ci    }
8441cb0ef41Sopenharmony_ci  } else {
8451cb0ef41Sopenharmony_ci    stm(db_w, sp, {fp, lr});
8461cb0ef41Sopenharmony_ci    mov(fp, sp);
8471cb0ef41Sopenharmony_ci  }
8481cb0ef41Sopenharmony_ci}
8491cb0ef41Sopenharmony_ci
8501cb0ef41Sopenharmony_civoid TurboAssembler::PushStandardFrame(Register function_reg) {
8511cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
8521cb0ef41Sopenharmony_ci  DCHECK(!function_reg.is_valid() || function_reg.code() < cp.code());
8531cb0ef41Sopenharmony_ci  stm(db_w, sp, {function_reg, cp, fp, lr});
8541cb0ef41Sopenharmony_ci  int offset = -StandardFrameConstants::kContextOffset;
8551cb0ef41Sopenharmony_ci  offset += function_reg.is_valid() ? kPointerSize : 0;
8561cb0ef41Sopenharmony_ci  add(fp, sp, Operand(offset));
8571cb0ef41Sopenharmony_ci  Push(kJavaScriptCallArgCountRegister);
8581cb0ef41Sopenharmony_ci}
8591cb0ef41Sopenharmony_ci
8601cb0ef41Sopenharmony_civoid TurboAssembler::VFPCanonicalizeNaN(const DwVfpRegister dst,
8611cb0ef41Sopenharmony_ci                                        const DwVfpRegister src,
8621cb0ef41Sopenharmony_ci                                        const Condition cond) {
8631cb0ef41Sopenharmony_ci  // Subtracting 0.0 preserves all inputs except for signalling NaNs, which
8641cb0ef41Sopenharmony_ci  // become quiet NaNs. We use vsub rather than vadd because vsub preserves -0.0
8651cb0ef41Sopenharmony_ci  // inputs: -0.0 + 0.0 = 0.0, but -0.0 - 0.0 = -0.0.
8661cb0ef41Sopenharmony_ci  vsub(dst, src, kDoubleRegZero, cond);
8671cb0ef41Sopenharmony_ci}
8681cb0ef41Sopenharmony_ci
8691cb0ef41Sopenharmony_civoid TurboAssembler::VFPCompareAndSetFlags(const SwVfpRegister src1,
8701cb0ef41Sopenharmony_ci                                           const SwVfpRegister src2,
8711cb0ef41Sopenharmony_ci                                           const Condition cond) {
8721cb0ef41Sopenharmony_ci  // Compare and move FPSCR flags to the normal condition flags.
8731cb0ef41Sopenharmony_ci  VFPCompareAndLoadFlags(src1, src2, pc, cond);
8741cb0ef41Sopenharmony_ci}
8751cb0ef41Sopenharmony_ci
8761cb0ef41Sopenharmony_civoid TurboAssembler::VFPCompareAndSetFlags(const SwVfpRegister src1,
8771cb0ef41Sopenharmony_ci                                           const float src2,
8781cb0ef41Sopenharmony_ci                                           const Condition cond) {
8791cb0ef41Sopenharmony_ci  // Compare and move FPSCR flags to the normal condition flags.
8801cb0ef41Sopenharmony_ci  VFPCompareAndLoadFlags(src1, src2, pc, cond);
8811cb0ef41Sopenharmony_ci}
8821cb0ef41Sopenharmony_ci
8831cb0ef41Sopenharmony_civoid TurboAssembler::VFPCompareAndSetFlags(const DwVfpRegister src1,
8841cb0ef41Sopenharmony_ci                                           const DwVfpRegister src2,
8851cb0ef41Sopenharmony_ci                                           const Condition cond) {
8861cb0ef41Sopenharmony_ci  // Compare and move FPSCR flags to the normal condition flags.
8871cb0ef41Sopenharmony_ci  VFPCompareAndLoadFlags(src1, src2, pc, cond);
8881cb0ef41Sopenharmony_ci}
8891cb0ef41Sopenharmony_ci
8901cb0ef41Sopenharmony_civoid TurboAssembler::VFPCompareAndSetFlags(const DwVfpRegister src1,
8911cb0ef41Sopenharmony_ci                                           const double src2,
8921cb0ef41Sopenharmony_ci                                           const Condition cond) {
8931cb0ef41Sopenharmony_ci  // Compare and move FPSCR flags to the normal condition flags.
8941cb0ef41Sopenharmony_ci  VFPCompareAndLoadFlags(src1, src2, pc, cond);
8951cb0ef41Sopenharmony_ci}
8961cb0ef41Sopenharmony_ci
8971cb0ef41Sopenharmony_civoid TurboAssembler::VFPCompareAndLoadFlags(const SwVfpRegister src1,
8981cb0ef41Sopenharmony_ci                                            const SwVfpRegister src2,
8991cb0ef41Sopenharmony_ci                                            const Register fpscr_flags,
9001cb0ef41Sopenharmony_ci                                            const Condition cond) {
9011cb0ef41Sopenharmony_ci  // Compare and load FPSCR.
9021cb0ef41Sopenharmony_ci  vcmp(src1, src2, cond);
9031cb0ef41Sopenharmony_ci  vmrs(fpscr_flags, cond);
9041cb0ef41Sopenharmony_ci}
9051cb0ef41Sopenharmony_ci
9061cb0ef41Sopenharmony_civoid TurboAssembler::VFPCompareAndLoadFlags(const SwVfpRegister src1,
9071cb0ef41Sopenharmony_ci                                            const float src2,
9081cb0ef41Sopenharmony_ci                                            const Register fpscr_flags,
9091cb0ef41Sopenharmony_ci                                            const Condition cond) {
9101cb0ef41Sopenharmony_ci  // Compare and load FPSCR.
9111cb0ef41Sopenharmony_ci  vcmp(src1, src2, cond);
9121cb0ef41Sopenharmony_ci  vmrs(fpscr_flags, cond);
9131cb0ef41Sopenharmony_ci}
9141cb0ef41Sopenharmony_ci
9151cb0ef41Sopenharmony_civoid TurboAssembler::VFPCompareAndLoadFlags(const DwVfpRegister src1,
9161cb0ef41Sopenharmony_ci                                            const DwVfpRegister src2,
9171cb0ef41Sopenharmony_ci                                            const Register fpscr_flags,
9181cb0ef41Sopenharmony_ci                                            const Condition cond) {
9191cb0ef41Sopenharmony_ci  // Compare and load FPSCR.
9201cb0ef41Sopenharmony_ci  vcmp(src1, src2, cond);
9211cb0ef41Sopenharmony_ci  vmrs(fpscr_flags, cond);
9221cb0ef41Sopenharmony_ci}
9231cb0ef41Sopenharmony_ci
9241cb0ef41Sopenharmony_civoid TurboAssembler::VFPCompareAndLoadFlags(const DwVfpRegister src1,
9251cb0ef41Sopenharmony_ci                                            const double src2,
9261cb0ef41Sopenharmony_ci                                            const Register fpscr_flags,
9271cb0ef41Sopenharmony_ci                                            const Condition cond) {
9281cb0ef41Sopenharmony_ci  // Compare and load FPSCR.
9291cb0ef41Sopenharmony_ci  vcmp(src1, src2, cond);
9301cb0ef41Sopenharmony_ci  vmrs(fpscr_flags, cond);
9311cb0ef41Sopenharmony_ci}
9321cb0ef41Sopenharmony_ci
9331cb0ef41Sopenharmony_civoid TurboAssembler::VmovHigh(Register dst, DwVfpRegister src) {
9341cb0ef41Sopenharmony_ci  if (src.code() < 16) {
9351cb0ef41Sopenharmony_ci    const LowDwVfpRegister loc = LowDwVfpRegister::from_code(src.code());
9361cb0ef41Sopenharmony_ci    vmov(dst, loc.high());
9371cb0ef41Sopenharmony_ci  } else {
9381cb0ef41Sopenharmony_ci    vmov(NeonS32, dst, src, 1);
9391cb0ef41Sopenharmony_ci  }
9401cb0ef41Sopenharmony_ci}
9411cb0ef41Sopenharmony_ci
9421cb0ef41Sopenharmony_civoid TurboAssembler::VmovHigh(DwVfpRegister dst, Register src) {
9431cb0ef41Sopenharmony_ci  if (dst.code() < 16) {
9441cb0ef41Sopenharmony_ci    const LowDwVfpRegister loc = LowDwVfpRegister::from_code(dst.code());
9451cb0ef41Sopenharmony_ci    vmov(loc.high(), src);
9461cb0ef41Sopenharmony_ci  } else {
9471cb0ef41Sopenharmony_ci    vmov(NeonS32, dst, 1, src);
9481cb0ef41Sopenharmony_ci  }
9491cb0ef41Sopenharmony_ci}
9501cb0ef41Sopenharmony_ci
9511cb0ef41Sopenharmony_civoid TurboAssembler::VmovLow(Register dst, DwVfpRegister src) {
9521cb0ef41Sopenharmony_ci  if (src.code() < 16) {
9531cb0ef41Sopenharmony_ci    const LowDwVfpRegister loc = LowDwVfpRegister::from_code(src.code());
9541cb0ef41Sopenharmony_ci    vmov(dst, loc.low());
9551cb0ef41Sopenharmony_ci  } else {
9561cb0ef41Sopenharmony_ci    vmov(NeonS32, dst, src, 0);
9571cb0ef41Sopenharmony_ci  }
9581cb0ef41Sopenharmony_ci}
9591cb0ef41Sopenharmony_ci
9601cb0ef41Sopenharmony_civoid TurboAssembler::VmovLow(DwVfpRegister dst, Register src) {
9611cb0ef41Sopenharmony_ci  if (dst.code() < 16) {
9621cb0ef41Sopenharmony_ci    const LowDwVfpRegister loc = LowDwVfpRegister::from_code(dst.code());
9631cb0ef41Sopenharmony_ci    vmov(loc.low(), src);
9641cb0ef41Sopenharmony_ci  } else {
9651cb0ef41Sopenharmony_ci    vmov(NeonS32, dst, 0, src);
9661cb0ef41Sopenharmony_ci  }
9671cb0ef41Sopenharmony_ci}
9681cb0ef41Sopenharmony_ci
9691cb0ef41Sopenharmony_civoid TurboAssembler::VmovExtended(Register dst, int src_code) {
9701cb0ef41Sopenharmony_ci  DCHECK_LE(SwVfpRegister::kNumRegisters, src_code);
9711cb0ef41Sopenharmony_ci  DCHECK_GT(SwVfpRegister::kNumRegisters * 2, src_code);
9721cb0ef41Sopenharmony_ci  if (src_code & 0x1) {
9731cb0ef41Sopenharmony_ci    VmovHigh(dst, DwVfpRegister::from_code(src_code / 2));
9741cb0ef41Sopenharmony_ci  } else {
9751cb0ef41Sopenharmony_ci    VmovLow(dst, DwVfpRegister::from_code(src_code / 2));
9761cb0ef41Sopenharmony_ci  }
9771cb0ef41Sopenharmony_ci}
9781cb0ef41Sopenharmony_ci
9791cb0ef41Sopenharmony_civoid TurboAssembler::VmovExtended(int dst_code, Register src) {
9801cb0ef41Sopenharmony_ci  DCHECK_LE(SwVfpRegister::kNumRegisters, dst_code);
9811cb0ef41Sopenharmony_ci  DCHECK_GT(SwVfpRegister::kNumRegisters * 2, dst_code);
9821cb0ef41Sopenharmony_ci  if (dst_code & 0x1) {
9831cb0ef41Sopenharmony_ci    VmovHigh(DwVfpRegister::from_code(dst_code / 2), src);
9841cb0ef41Sopenharmony_ci  } else {
9851cb0ef41Sopenharmony_ci    VmovLow(DwVfpRegister::from_code(dst_code / 2), src);
9861cb0ef41Sopenharmony_ci  }
9871cb0ef41Sopenharmony_ci}
9881cb0ef41Sopenharmony_ci
9891cb0ef41Sopenharmony_civoid TurboAssembler::VmovExtended(int dst_code, int src_code) {
9901cb0ef41Sopenharmony_ci  if (src_code == dst_code) return;
9911cb0ef41Sopenharmony_ci
9921cb0ef41Sopenharmony_ci  if (src_code < SwVfpRegister::kNumRegisters &&
9931cb0ef41Sopenharmony_ci      dst_code < SwVfpRegister::kNumRegisters) {
9941cb0ef41Sopenharmony_ci    // src and dst are both s-registers.
9951cb0ef41Sopenharmony_ci    vmov(SwVfpRegister::from_code(dst_code),
9961cb0ef41Sopenharmony_ci         SwVfpRegister::from_code(src_code));
9971cb0ef41Sopenharmony_ci    return;
9981cb0ef41Sopenharmony_ci  }
9991cb0ef41Sopenharmony_ci  DwVfpRegister dst_d_reg = DwVfpRegister::from_code(dst_code / 2);
10001cb0ef41Sopenharmony_ci  DwVfpRegister src_d_reg = DwVfpRegister::from_code(src_code / 2);
10011cb0ef41Sopenharmony_ci  int dst_offset = dst_code & 1;
10021cb0ef41Sopenharmony_ci  int src_offset = src_code & 1;
10031cb0ef41Sopenharmony_ci  if (CpuFeatures::IsSupported(NEON)) {
10041cb0ef41Sopenharmony_ci    UseScratchRegisterScope temps(this);
10051cb0ef41Sopenharmony_ci    DwVfpRegister scratch = temps.AcquireD();
10061cb0ef41Sopenharmony_ci    // On Neon we can shift and insert from d-registers.
10071cb0ef41Sopenharmony_ci    if (src_offset == dst_offset) {
10081cb0ef41Sopenharmony_ci      // Offsets are the same, use vdup to copy the source to the opposite lane.
10091cb0ef41Sopenharmony_ci      vdup(Neon32, scratch, src_d_reg, src_offset);
10101cb0ef41Sopenharmony_ci      // Here we are extending the lifetime of scratch.
10111cb0ef41Sopenharmony_ci      src_d_reg = scratch;
10121cb0ef41Sopenharmony_ci      src_offset = dst_offset ^ 1;
10131cb0ef41Sopenharmony_ci    }
10141cb0ef41Sopenharmony_ci    if (dst_offset) {
10151cb0ef41Sopenharmony_ci      if (dst_d_reg == src_d_reg) {
10161cb0ef41Sopenharmony_ci        vdup(Neon32, dst_d_reg, src_d_reg, 0);
10171cb0ef41Sopenharmony_ci      } else {
10181cb0ef41Sopenharmony_ci        vsli(Neon64, dst_d_reg, src_d_reg, 32);
10191cb0ef41Sopenharmony_ci      }
10201cb0ef41Sopenharmony_ci    } else {
10211cb0ef41Sopenharmony_ci      if (dst_d_reg == src_d_reg) {
10221cb0ef41Sopenharmony_ci        vdup(Neon32, dst_d_reg, src_d_reg, 1);
10231cb0ef41Sopenharmony_ci      } else {
10241cb0ef41Sopenharmony_ci        vsri(Neon64, dst_d_reg, src_d_reg, 32);
10251cb0ef41Sopenharmony_ci      }
10261cb0ef41Sopenharmony_ci    }
10271cb0ef41Sopenharmony_ci    return;
10281cb0ef41Sopenharmony_ci  }
10291cb0ef41Sopenharmony_ci
10301cb0ef41Sopenharmony_ci  // Without Neon, use the scratch registers to move src and/or dst into
10311cb0ef41Sopenharmony_ci  // s-registers.
10321cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
10331cb0ef41Sopenharmony_ci  LowDwVfpRegister d_scratch = temps.AcquireLowD();
10341cb0ef41Sopenharmony_ci  LowDwVfpRegister d_scratch2 = temps.AcquireLowD();
10351cb0ef41Sopenharmony_ci  int s_scratch_code = d_scratch.low().code();
10361cb0ef41Sopenharmony_ci  int s_scratch_code2 = d_scratch2.low().code();
10371cb0ef41Sopenharmony_ci  if (src_code < SwVfpRegister::kNumRegisters) {
10381cb0ef41Sopenharmony_ci    // src is an s-register, dst is not.
10391cb0ef41Sopenharmony_ci    vmov(d_scratch, dst_d_reg);
10401cb0ef41Sopenharmony_ci    vmov(SwVfpRegister::from_code(s_scratch_code + dst_offset),
10411cb0ef41Sopenharmony_ci         SwVfpRegister::from_code(src_code));
10421cb0ef41Sopenharmony_ci    vmov(dst_d_reg, d_scratch);
10431cb0ef41Sopenharmony_ci  } else if (dst_code < SwVfpRegister::kNumRegisters) {
10441cb0ef41Sopenharmony_ci    // dst is an s-register, src is not.
10451cb0ef41Sopenharmony_ci    vmov(d_scratch, src_d_reg);
10461cb0ef41Sopenharmony_ci    vmov(SwVfpRegister::from_code(dst_code),
10471cb0ef41Sopenharmony_ci         SwVfpRegister::from_code(s_scratch_code + src_offset));
10481cb0ef41Sopenharmony_ci  } else {
10491cb0ef41Sopenharmony_ci    // Neither src or dst are s-registers. Both scratch double registers are
10501cb0ef41Sopenharmony_ci    // available when there are 32 VFP registers.
10511cb0ef41Sopenharmony_ci    vmov(d_scratch, src_d_reg);
10521cb0ef41Sopenharmony_ci    vmov(d_scratch2, dst_d_reg);
10531cb0ef41Sopenharmony_ci    vmov(SwVfpRegister::from_code(s_scratch_code + dst_offset),
10541cb0ef41Sopenharmony_ci         SwVfpRegister::from_code(s_scratch_code2 + src_offset));
10551cb0ef41Sopenharmony_ci    vmov(dst_d_reg, d_scratch2);
10561cb0ef41Sopenharmony_ci  }
10571cb0ef41Sopenharmony_ci}
10581cb0ef41Sopenharmony_ci
10591cb0ef41Sopenharmony_civoid TurboAssembler::VmovExtended(int dst_code, const MemOperand& src) {
10601cb0ef41Sopenharmony_ci  if (dst_code < SwVfpRegister::kNumRegisters) {
10611cb0ef41Sopenharmony_ci    vldr(SwVfpRegister::from_code(dst_code), src);
10621cb0ef41Sopenharmony_ci  } else {
10631cb0ef41Sopenharmony_ci    UseScratchRegisterScope temps(this);
10641cb0ef41Sopenharmony_ci    LowDwVfpRegister scratch = temps.AcquireLowD();
10651cb0ef41Sopenharmony_ci    // TODO(bbudge) If Neon supported, use load single lane form of vld1.
10661cb0ef41Sopenharmony_ci    int dst_s_code = scratch.low().code() + (dst_code & 1);
10671cb0ef41Sopenharmony_ci    vmov(scratch, DwVfpRegister::from_code(dst_code / 2));
10681cb0ef41Sopenharmony_ci    vldr(SwVfpRegister::from_code(dst_s_code), src);
10691cb0ef41Sopenharmony_ci    vmov(DwVfpRegister::from_code(dst_code / 2), scratch);
10701cb0ef41Sopenharmony_ci  }
10711cb0ef41Sopenharmony_ci}
10721cb0ef41Sopenharmony_ci
10731cb0ef41Sopenharmony_civoid TurboAssembler::VmovExtended(const MemOperand& dst, int src_code) {
10741cb0ef41Sopenharmony_ci  if (src_code < SwVfpRegister::kNumRegisters) {
10751cb0ef41Sopenharmony_ci    vstr(SwVfpRegister::from_code(src_code), dst);
10761cb0ef41Sopenharmony_ci  } else {
10771cb0ef41Sopenharmony_ci    // TODO(bbudge) If Neon supported, use store single lane form of vst1.
10781cb0ef41Sopenharmony_ci    UseScratchRegisterScope temps(this);
10791cb0ef41Sopenharmony_ci    LowDwVfpRegister scratch = temps.AcquireLowD();
10801cb0ef41Sopenharmony_ci    int src_s_code = scratch.low().code() + (src_code & 1);
10811cb0ef41Sopenharmony_ci    vmov(scratch, DwVfpRegister::from_code(src_code / 2));
10821cb0ef41Sopenharmony_ci    vstr(SwVfpRegister::from_code(src_s_code), dst);
10831cb0ef41Sopenharmony_ci  }
10841cb0ef41Sopenharmony_ci}
10851cb0ef41Sopenharmony_ci
10861cb0ef41Sopenharmony_civoid TurboAssembler::ExtractLane(Register dst, QwNeonRegister src,
10871cb0ef41Sopenharmony_ci                                 NeonDataType dt, int lane) {
10881cb0ef41Sopenharmony_ci  int size = NeonSz(dt);  // 0, 1, 2
10891cb0ef41Sopenharmony_ci  int byte = lane << size;
10901cb0ef41Sopenharmony_ci  int double_word = byte >> kDoubleSizeLog2;
10911cb0ef41Sopenharmony_ci  int double_byte = byte & (kDoubleSize - 1);
10921cb0ef41Sopenharmony_ci  int double_lane = double_byte >> size;
10931cb0ef41Sopenharmony_ci  DwVfpRegister double_source =
10941cb0ef41Sopenharmony_ci      DwVfpRegister::from_code(src.code() * 2 + double_word);
10951cb0ef41Sopenharmony_ci  vmov(dt, dst, double_source, double_lane);
10961cb0ef41Sopenharmony_ci}
10971cb0ef41Sopenharmony_ci
10981cb0ef41Sopenharmony_civoid TurboAssembler::ExtractLane(Register dst, DwVfpRegister src,
10991cb0ef41Sopenharmony_ci                                 NeonDataType dt, int lane) {
11001cb0ef41Sopenharmony_ci  int size = NeonSz(dt);  // 0, 1, 2
11011cb0ef41Sopenharmony_ci  int byte = lane << size;
11021cb0ef41Sopenharmony_ci  int double_byte = byte & (kDoubleSize - 1);
11031cb0ef41Sopenharmony_ci  int double_lane = double_byte >> size;
11041cb0ef41Sopenharmony_ci  vmov(dt, dst, src, double_lane);
11051cb0ef41Sopenharmony_ci}
11061cb0ef41Sopenharmony_ci
11071cb0ef41Sopenharmony_civoid TurboAssembler::ExtractLane(SwVfpRegister dst, QwNeonRegister src,
11081cb0ef41Sopenharmony_ci                                 int lane) {
11091cb0ef41Sopenharmony_ci  int s_code = src.code() * 4 + lane;
11101cb0ef41Sopenharmony_ci  VmovExtended(dst.code(), s_code);
11111cb0ef41Sopenharmony_ci}
11121cb0ef41Sopenharmony_ci
11131cb0ef41Sopenharmony_civoid TurboAssembler::ExtractLane(DwVfpRegister dst, QwNeonRegister src,
11141cb0ef41Sopenharmony_ci                                 int lane) {
11151cb0ef41Sopenharmony_ci  DwVfpRegister double_dst = DwVfpRegister::from_code(src.code() * 2 + lane);
11161cb0ef41Sopenharmony_ci  vmov(dst, double_dst);
11171cb0ef41Sopenharmony_ci}
11181cb0ef41Sopenharmony_ci
11191cb0ef41Sopenharmony_civoid TurboAssembler::ReplaceLane(QwNeonRegister dst, QwNeonRegister src,
11201cb0ef41Sopenharmony_ci                                 Register src_lane, NeonDataType dt, int lane) {
11211cb0ef41Sopenharmony_ci  Move(dst, src);
11221cb0ef41Sopenharmony_ci  int size = NeonSz(dt);  // 0, 1, 2
11231cb0ef41Sopenharmony_ci  int byte = lane << size;
11241cb0ef41Sopenharmony_ci  int double_word = byte >> kDoubleSizeLog2;
11251cb0ef41Sopenharmony_ci  int double_byte = byte & (kDoubleSize - 1);
11261cb0ef41Sopenharmony_ci  int double_lane = double_byte >> size;
11271cb0ef41Sopenharmony_ci  DwVfpRegister double_dst =
11281cb0ef41Sopenharmony_ci      DwVfpRegister::from_code(dst.code() * 2 + double_word);
11291cb0ef41Sopenharmony_ci  vmov(dt, double_dst, double_lane, src_lane);
11301cb0ef41Sopenharmony_ci}
11311cb0ef41Sopenharmony_ci
11321cb0ef41Sopenharmony_civoid TurboAssembler::ReplaceLane(QwNeonRegister dst, QwNeonRegister src,
11331cb0ef41Sopenharmony_ci                                 SwVfpRegister src_lane, int lane) {
11341cb0ef41Sopenharmony_ci  Move(dst, src);
11351cb0ef41Sopenharmony_ci  int s_code = dst.code() * 4 + lane;
11361cb0ef41Sopenharmony_ci  VmovExtended(s_code, src_lane.code());
11371cb0ef41Sopenharmony_ci}
11381cb0ef41Sopenharmony_ci
11391cb0ef41Sopenharmony_civoid TurboAssembler::ReplaceLane(QwNeonRegister dst, QwNeonRegister src,
11401cb0ef41Sopenharmony_ci                                 DwVfpRegister src_lane, int lane) {
11411cb0ef41Sopenharmony_ci  Move(dst, src);
11421cb0ef41Sopenharmony_ci  DwVfpRegister double_dst = DwVfpRegister::from_code(dst.code() * 2 + lane);
11431cb0ef41Sopenharmony_ci  vmov(double_dst, src_lane);
11441cb0ef41Sopenharmony_ci}
11451cb0ef41Sopenharmony_ci
11461cb0ef41Sopenharmony_civoid TurboAssembler::LoadLane(NeonSize sz, NeonListOperand dst_list,
11471cb0ef41Sopenharmony_ci                              uint8_t lane, NeonMemOperand src) {
11481cb0ef41Sopenharmony_ci  if (sz == Neon64) {
11491cb0ef41Sopenharmony_ci    // vld1s is not valid for Neon64.
11501cb0ef41Sopenharmony_ci    vld1(Neon64, dst_list, src);
11511cb0ef41Sopenharmony_ci  } else {
11521cb0ef41Sopenharmony_ci    vld1s(sz, dst_list, lane, src);
11531cb0ef41Sopenharmony_ci  }
11541cb0ef41Sopenharmony_ci}
11551cb0ef41Sopenharmony_ci
11561cb0ef41Sopenharmony_civoid TurboAssembler::StoreLane(NeonSize sz, NeonListOperand src_list,
11571cb0ef41Sopenharmony_ci                               uint8_t lane, NeonMemOperand dst) {
11581cb0ef41Sopenharmony_ci  if (sz == Neon64) {
11591cb0ef41Sopenharmony_ci    // vst1s is not valid for Neon64.
11601cb0ef41Sopenharmony_ci    vst1(Neon64, src_list, dst);
11611cb0ef41Sopenharmony_ci  } else {
11621cb0ef41Sopenharmony_ci    vst1s(sz, src_list, lane, dst);
11631cb0ef41Sopenharmony_ci  }
11641cb0ef41Sopenharmony_ci}
11651cb0ef41Sopenharmony_ci
11661cb0ef41Sopenharmony_civoid TurboAssembler::LslPair(Register dst_low, Register dst_high,
11671cb0ef41Sopenharmony_ci                             Register src_low, Register src_high,
11681cb0ef41Sopenharmony_ci                             Register shift) {
11691cb0ef41Sopenharmony_ci  DCHECK(!AreAliased(dst_high, src_low));
11701cb0ef41Sopenharmony_ci  DCHECK(!AreAliased(dst_high, shift));
11711cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
11721cb0ef41Sopenharmony_ci  Register scratch = temps.Acquire();
11731cb0ef41Sopenharmony_ci
11741cb0ef41Sopenharmony_ci  Label less_than_32;
11751cb0ef41Sopenharmony_ci  Label done;
11761cb0ef41Sopenharmony_ci  rsb(scratch, shift, Operand(32), SetCC);
11771cb0ef41Sopenharmony_ci  b(gt, &less_than_32);
11781cb0ef41Sopenharmony_ci  // If shift >= 32
11791cb0ef41Sopenharmony_ci  and_(scratch, shift, Operand(0x1F));
11801cb0ef41Sopenharmony_ci  lsl(dst_high, src_low, Operand(scratch));
11811cb0ef41Sopenharmony_ci  mov(dst_low, Operand(0));
11821cb0ef41Sopenharmony_ci  jmp(&done);
11831cb0ef41Sopenharmony_ci  bind(&less_than_32);
11841cb0ef41Sopenharmony_ci  // If shift < 32
11851cb0ef41Sopenharmony_ci  lsl(dst_high, src_high, Operand(shift));
11861cb0ef41Sopenharmony_ci  orr(dst_high, dst_high, Operand(src_low, LSR, scratch));
11871cb0ef41Sopenharmony_ci  lsl(dst_low, src_low, Operand(shift));
11881cb0ef41Sopenharmony_ci  bind(&done);
11891cb0ef41Sopenharmony_ci}
11901cb0ef41Sopenharmony_ci
11911cb0ef41Sopenharmony_civoid TurboAssembler::LslPair(Register dst_low, Register dst_high,
11921cb0ef41Sopenharmony_ci                             Register src_low, Register src_high,
11931cb0ef41Sopenharmony_ci                             uint32_t shift) {
11941cb0ef41Sopenharmony_ci  DCHECK_GE(63, shift);
11951cb0ef41Sopenharmony_ci  DCHECK(!AreAliased(dst_high, src_low));
11961cb0ef41Sopenharmony_ci
11971cb0ef41Sopenharmony_ci  if (shift == 0) {
11981cb0ef41Sopenharmony_ci    Move(dst_high, src_high);
11991cb0ef41Sopenharmony_ci    Move(dst_low, src_low);
12001cb0ef41Sopenharmony_ci  } else if (shift == 32) {
12011cb0ef41Sopenharmony_ci    Move(dst_high, src_low);
12021cb0ef41Sopenharmony_ci    Move(dst_low, Operand(0));
12031cb0ef41Sopenharmony_ci  } else if (shift >= 32) {
12041cb0ef41Sopenharmony_ci    shift &= 0x1F;
12051cb0ef41Sopenharmony_ci    lsl(dst_high, src_low, Operand(shift));
12061cb0ef41Sopenharmony_ci    mov(dst_low, Operand(0));
12071cb0ef41Sopenharmony_ci  } else {
12081cb0ef41Sopenharmony_ci    lsl(dst_high, src_high, Operand(shift));
12091cb0ef41Sopenharmony_ci    orr(dst_high, dst_high, Operand(src_low, LSR, 32 - shift));
12101cb0ef41Sopenharmony_ci    lsl(dst_low, src_low, Operand(shift));
12111cb0ef41Sopenharmony_ci  }
12121cb0ef41Sopenharmony_ci}
12131cb0ef41Sopenharmony_ci
12141cb0ef41Sopenharmony_civoid TurboAssembler::LsrPair(Register dst_low, Register dst_high,
12151cb0ef41Sopenharmony_ci                             Register src_low, Register src_high,
12161cb0ef41Sopenharmony_ci                             Register shift) {
12171cb0ef41Sopenharmony_ci  DCHECK(!AreAliased(dst_low, src_high));
12181cb0ef41Sopenharmony_ci  DCHECK(!AreAliased(dst_low, shift));
12191cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
12201cb0ef41Sopenharmony_ci  Register scratch = temps.Acquire();
12211cb0ef41Sopenharmony_ci
12221cb0ef41Sopenharmony_ci  Label less_than_32;
12231cb0ef41Sopenharmony_ci  Label done;
12241cb0ef41Sopenharmony_ci  rsb(scratch, shift, Operand(32), SetCC);
12251cb0ef41Sopenharmony_ci  b(gt, &less_than_32);
12261cb0ef41Sopenharmony_ci  // If shift >= 32
12271cb0ef41Sopenharmony_ci  and_(scratch, shift, Operand(0x1F));
12281cb0ef41Sopenharmony_ci  lsr(dst_low, src_high, Operand(scratch));
12291cb0ef41Sopenharmony_ci  mov(dst_high, Operand(0));
12301cb0ef41Sopenharmony_ci  jmp(&done);
12311cb0ef41Sopenharmony_ci  bind(&less_than_32);
12321cb0ef41Sopenharmony_ci  // If shift < 32
12331cb0ef41Sopenharmony_ci
12341cb0ef41Sopenharmony_ci  lsr(dst_low, src_low, Operand(shift));
12351cb0ef41Sopenharmony_ci  orr(dst_low, dst_low, Operand(src_high, LSL, scratch));
12361cb0ef41Sopenharmony_ci  lsr(dst_high, src_high, Operand(shift));
12371cb0ef41Sopenharmony_ci  bind(&done);
12381cb0ef41Sopenharmony_ci}
12391cb0ef41Sopenharmony_ci
12401cb0ef41Sopenharmony_civoid TurboAssembler::LsrPair(Register dst_low, Register dst_high,
12411cb0ef41Sopenharmony_ci                             Register src_low, Register src_high,
12421cb0ef41Sopenharmony_ci                             uint32_t shift) {
12431cb0ef41Sopenharmony_ci  DCHECK_GE(63, shift);
12441cb0ef41Sopenharmony_ci  DCHECK(!AreAliased(dst_low, src_high));
12451cb0ef41Sopenharmony_ci
12461cb0ef41Sopenharmony_ci  if (shift == 32) {
12471cb0ef41Sopenharmony_ci    mov(dst_low, src_high);
12481cb0ef41Sopenharmony_ci    mov(dst_high, Operand(0));
12491cb0ef41Sopenharmony_ci  } else if (shift > 32) {
12501cb0ef41Sopenharmony_ci    shift &= 0x1F;
12511cb0ef41Sopenharmony_ci    lsr(dst_low, src_high, Operand(shift));
12521cb0ef41Sopenharmony_ci    mov(dst_high, Operand(0));
12531cb0ef41Sopenharmony_ci  } else if (shift == 0) {
12541cb0ef41Sopenharmony_ci    Move(dst_low, src_low);
12551cb0ef41Sopenharmony_ci    Move(dst_high, src_high);
12561cb0ef41Sopenharmony_ci  } else {
12571cb0ef41Sopenharmony_ci    lsr(dst_low, src_low, Operand(shift));
12581cb0ef41Sopenharmony_ci    orr(dst_low, dst_low, Operand(src_high, LSL, 32 - shift));
12591cb0ef41Sopenharmony_ci    lsr(dst_high, src_high, Operand(shift));
12601cb0ef41Sopenharmony_ci  }
12611cb0ef41Sopenharmony_ci}
12621cb0ef41Sopenharmony_ci
12631cb0ef41Sopenharmony_civoid TurboAssembler::AsrPair(Register dst_low, Register dst_high,
12641cb0ef41Sopenharmony_ci                             Register src_low, Register src_high,
12651cb0ef41Sopenharmony_ci                             Register shift) {
12661cb0ef41Sopenharmony_ci  DCHECK(!AreAliased(dst_low, src_high));
12671cb0ef41Sopenharmony_ci  DCHECK(!AreAliased(dst_low, shift));
12681cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
12691cb0ef41Sopenharmony_ci  Register scratch = temps.Acquire();
12701cb0ef41Sopenharmony_ci
12711cb0ef41Sopenharmony_ci  Label less_than_32;
12721cb0ef41Sopenharmony_ci  Label done;
12731cb0ef41Sopenharmony_ci  rsb(scratch, shift, Operand(32), SetCC);
12741cb0ef41Sopenharmony_ci  b(gt, &less_than_32);
12751cb0ef41Sopenharmony_ci  // If shift >= 32
12761cb0ef41Sopenharmony_ci  and_(scratch, shift, Operand(0x1F));
12771cb0ef41Sopenharmony_ci  asr(dst_low, src_high, Operand(scratch));
12781cb0ef41Sopenharmony_ci  asr(dst_high, src_high, Operand(31));
12791cb0ef41Sopenharmony_ci  jmp(&done);
12801cb0ef41Sopenharmony_ci  bind(&less_than_32);
12811cb0ef41Sopenharmony_ci  // If shift < 32
12821cb0ef41Sopenharmony_ci  lsr(dst_low, src_low, Operand(shift));
12831cb0ef41Sopenharmony_ci  orr(dst_low, dst_low, Operand(src_high, LSL, scratch));
12841cb0ef41Sopenharmony_ci  asr(dst_high, src_high, Operand(shift));
12851cb0ef41Sopenharmony_ci  bind(&done);
12861cb0ef41Sopenharmony_ci}
12871cb0ef41Sopenharmony_ci
12881cb0ef41Sopenharmony_civoid TurboAssembler::AsrPair(Register dst_low, Register dst_high,
12891cb0ef41Sopenharmony_ci                             Register src_low, Register src_high,
12901cb0ef41Sopenharmony_ci                             uint32_t shift) {
12911cb0ef41Sopenharmony_ci  DCHECK_GE(63, shift);
12921cb0ef41Sopenharmony_ci  DCHECK(!AreAliased(dst_low, src_high));
12931cb0ef41Sopenharmony_ci
12941cb0ef41Sopenharmony_ci  if (shift == 32) {
12951cb0ef41Sopenharmony_ci    mov(dst_low, src_high);
12961cb0ef41Sopenharmony_ci    asr(dst_high, src_high, Operand(31));
12971cb0ef41Sopenharmony_ci  } else if (shift > 32) {
12981cb0ef41Sopenharmony_ci    shift &= 0x1F;
12991cb0ef41Sopenharmony_ci    asr(dst_low, src_high, Operand(shift));
13001cb0ef41Sopenharmony_ci    asr(dst_high, src_high, Operand(31));
13011cb0ef41Sopenharmony_ci  } else if (shift == 0) {
13021cb0ef41Sopenharmony_ci    Move(dst_low, src_low);
13031cb0ef41Sopenharmony_ci    Move(dst_high, src_high);
13041cb0ef41Sopenharmony_ci  } else {
13051cb0ef41Sopenharmony_ci    lsr(dst_low, src_low, Operand(shift));
13061cb0ef41Sopenharmony_ci    orr(dst_low, dst_low, Operand(src_high, LSL, 32 - shift));
13071cb0ef41Sopenharmony_ci    asr(dst_high, src_high, Operand(shift));
13081cb0ef41Sopenharmony_ci  }
13091cb0ef41Sopenharmony_ci}
13101cb0ef41Sopenharmony_ci
13111cb0ef41Sopenharmony_civoid TurboAssembler::StubPrologue(StackFrame::Type type) {
13121cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
13131cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
13141cb0ef41Sopenharmony_ci  Register scratch = temps.Acquire();
13151cb0ef41Sopenharmony_ci  mov(scratch, Operand(StackFrame::TypeToMarker(type)));
13161cb0ef41Sopenharmony_ci  PushCommonFrame(scratch);
13171cb0ef41Sopenharmony_ci}
13181cb0ef41Sopenharmony_ci
13191cb0ef41Sopenharmony_civoid TurboAssembler::Prologue() { PushStandardFrame(r1); }
13201cb0ef41Sopenharmony_ci
13211cb0ef41Sopenharmony_civoid TurboAssembler::DropArguments(Register count, ArgumentsCountType type,
13221cb0ef41Sopenharmony_ci                                   ArgumentsCountMode mode) {
13231cb0ef41Sopenharmony_ci  int receiver_bytes = (mode == kCountExcludesReceiver) ? kPointerSize : 0;
13241cb0ef41Sopenharmony_ci  switch (type) {
13251cb0ef41Sopenharmony_ci    case kCountIsInteger: {
13261cb0ef41Sopenharmony_ci      add(sp, sp, Operand(count, LSL, kPointerSizeLog2), LeaveCC);
13271cb0ef41Sopenharmony_ci      break;
13281cb0ef41Sopenharmony_ci    }
13291cb0ef41Sopenharmony_ci    case kCountIsSmi: {
13301cb0ef41Sopenharmony_ci      STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
13311cb0ef41Sopenharmony_ci      add(sp, sp, Operand(count, LSL, kPointerSizeLog2 - kSmiTagSize), LeaveCC);
13321cb0ef41Sopenharmony_ci      break;
13331cb0ef41Sopenharmony_ci    }
13341cb0ef41Sopenharmony_ci    case kCountIsBytes: {
13351cb0ef41Sopenharmony_ci      add(sp, sp, count, LeaveCC);
13361cb0ef41Sopenharmony_ci      break;
13371cb0ef41Sopenharmony_ci    }
13381cb0ef41Sopenharmony_ci  }
13391cb0ef41Sopenharmony_ci  if (receiver_bytes != 0) {
13401cb0ef41Sopenharmony_ci    add(sp, sp, Operand(receiver_bytes), LeaveCC);
13411cb0ef41Sopenharmony_ci  }
13421cb0ef41Sopenharmony_ci}
13431cb0ef41Sopenharmony_ci
13441cb0ef41Sopenharmony_civoid TurboAssembler::DropArgumentsAndPushNewReceiver(Register argc,
13451cb0ef41Sopenharmony_ci                                                     Register receiver,
13461cb0ef41Sopenharmony_ci                                                     ArgumentsCountType type,
13471cb0ef41Sopenharmony_ci                                                     ArgumentsCountMode mode) {
13481cb0ef41Sopenharmony_ci  DCHECK(!AreAliased(argc, receiver));
13491cb0ef41Sopenharmony_ci  if (mode == kCountExcludesReceiver) {
13501cb0ef41Sopenharmony_ci    // Drop arguments without receiver and override old receiver.
13511cb0ef41Sopenharmony_ci    DropArguments(argc, type, kCountIncludesReceiver);
13521cb0ef41Sopenharmony_ci    str(receiver, MemOperand(sp, 0));
13531cb0ef41Sopenharmony_ci  } else {
13541cb0ef41Sopenharmony_ci    DropArguments(argc, type, mode);
13551cb0ef41Sopenharmony_ci    push(receiver);
13561cb0ef41Sopenharmony_ci  }
13571cb0ef41Sopenharmony_ci}
13581cb0ef41Sopenharmony_ci
13591cb0ef41Sopenharmony_civoid TurboAssembler::EnterFrame(StackFrame::Type type,
13601cb0ef41Sopenharmony_ci                                bool load_constant_pool_pointer_reg) {
13611cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
13621cb0ef41Sopenharmony_ci  // r0-r3: preserved
13631cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
13641cb0ef41Sopenharmony_ci  Register scratch = no_reg;
13651cb0ef41Sopenharmony_ci  if (!StackFrame::IsJavaScript(type)) {
13661cb0ef41Sopenharmony_ci    scratch = temps.Acquire();
13671cb0ef41Sopenharmony_ci    mov(scratch, Operand(StackFrame::TypeToMarker(type)));
13681cb0ef41Sopenharmony_ci  }
13691cb0ef41Sopenharmony_ci  PushCommonFrame(scratch);
13701cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY
13711cb0ef41Sopenharmony_ci  if (type == StackFrame::WASM) Push(kWasmInstanceRegister);
13721cb0ef41Sopenharmony_ci#endif  // V8_ENABLE_WEBASSEMBLY
13731cb0ef41Sopenharmony_ci}
13741cb0ef41Sopenharmony_ci
13751cb0ef41Sopenharmony_ciint TurboAssembler::LeaveFrame(StackFrame::Type type) {
13761cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
13771cb0ef41Sopenharmony_ci  // r0: preserved
13781cb0ef41Sopenharmony_ci  // r1: preserved
13791cb0ef41Sopenharmony_ci  // r2: preserved
13801cb0ef41Sopenharmony_ci
13811cb0ef41Sopenharmony_ci  // Drop the execution stack down to the frame pointer and restore
13821cb0ef41Sopenharmony_ci  // the caller frame pointer and return address.
13831cb0ef41Sopenharmony_ci  mov(sp, fp);
13841cb0ef41Sopenharmony_ci  int frame_ends = pc_offset();
13851cb0ef41Sopenharmony_ci  ldm(ia_w, sp, {fp, lr});
13861cb0ef41Sopenharmony_ci  return frame_ends;
13871cb0ef41Sopenharmony_ci}
13881cb0ef41Sopenharmony_ci
13891cb0ef41Sopenharmony_ci#ifdef V8_OS_WIN
13901cb0ef41Sopenharmony_civoid TurboAssembler::AllocateStackSpace(Register bytes_scratch) {
13911cb0ef41Sopenharmony_ci  // "Functions that allocate 4 KB or more on the stack must ensure that each
13921cb0ef41Sopenharmony_ci  // page prior to the final page is touched in order." Source:
13931cb0ef41Sopenharmony_ci  // https://docs.microsoft.com/en-us/cpp/build/overview-of-arm-abi-conventions?view=vs-2019#stack
13941cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
13951cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
13961cb0ef41Sopenharmony_ci  DwVfpRegister scratch = temps.AcquireD();
13971cb0ef41Sopenharmony_ci  Label check_offset;
13981cb0ef41Sopenharmony_ci  Label touch_next_page;
13991cb0ef41Sopenharmony_ci  jmp(&check_offset);
14001cb0ef41Sopenharmony_ci  bind(&touch_next_page);
14011cb0ef41Sopenharmony_ci  sub(sp, sp, Operand(kStackPageSize));
14021cb0ef41Sopenharmony_ci  // Just to touch the page, before we increment further.
14031cb0ef41Sopenharmony_ci  vldr(scratch, MemOperand(sp));
14041cb0ef41Sopenharmony_ci  sub(bytes_scratch, bytes_scratch, Operand(kStackPageSize));
14051cb0ef41Sopenharmony_ci
14061cb0ef41Sopenharmony_ci  bind(&check_offset);
14071cb0ef41Sopenharmony_ci  cmp(bytes_scratch, Operand(kStackPageSize));
14081cb0ef41Sopenharmony_ci  b(gt, &touch_next_page);
14091cb0ef41Sopenharmony_ci
14101cb0ef41Sopenharmony_ci  sub(sp, sp, bytes_scratch);
14111cb0ef41Sopenharmony_ci}
14121cb0ef41Sopenharmony_ci
14131cb0ef41Sopenharmony_civoid TurboAssembler::AllocateStackSpace(int bytes) {
14141cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
14151cb0ef41Sopenharmony_ci  DCHECK_GE(bytes, 0);
14161cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
14171cb0ef41Sopenharmony_ci  DwVfpRegister scratch = no_dreg;
14181cb0ef41Sopenharmony_ci  while (bytes > kStackPageSize) {
14191cb0ef41Sopenharmony_ci    if (scratch == no_dreg) {
14201cb0ef41Sopenharmony_ci      scratch = temps.AcquireD();
14211cb0ef41Sopenharmony_ci    }
14221cb0ef41Sopenharmony_ci    sub(sp, sp, Operand(kStackPageSize));
14231cb0ef41Sopenharmony_ci    vldr(scratch, MemOperand(sp));
14241cb0ef41Sopenharmony_ci    bytes -= kStackPageSize;
14251cb0ef41Sopenharmony_ci  }
14261cb0ef41Sopenharmony_ci  if (bytes == 0) return;
14271cb0ef41Sopenharmony_ci  sub(sp, sp, Operand(bytes));
14281cb0ef41Sopenharmony_ci}
14291cb0ef41Sopenharmony_ci#endif
14301cb0ef41Sopenharmony_ci
14311cb0ef41Sopenharmony_civoid MacroAssembler::EnterExitFrame(bool save_doubles, int stack_space,
14321cb0ef41Sopenharmony_ci                                    StackFrame::Type frame_type) {
14331cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
14341cb0ef41Sopenharmony_ci  DCHECK(frame_type == StackFrame::EXIT ||
14351cb0ef41Sopenharmony_ci         frame_type == StackFrame::BUILTIN_EXIT);
14361cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
14371cb0ef41Sopenharmony_ci  Register scratch = temps.Acquire();
14381cb0ef41Sopenharmony_ci
14391cb0ef41Sopenharmony_ci  // Set up the frame structure on the stack.
14401cb0ef41Sopenharmony_ci  DCHECK_EQ(2 * kPointerSize, ExitFrameConstants::kCallerSPDisplacement);
14411cb0ef41Sopenharmony_ci  DCHECK_EQ(1 * kPointerSize, ExitFrameConstants::kCallerPCOffset);
14421cb0ef41Sopenharmony_ci  DCHECK_EQ(0 * kPointerSize, ExitFrameConstants::kCallerFPOffset);
14431cb0ef41Sopenharmony_ci  mov(scratch, Operand(StackFrame::TypeToMarker(frame_type)));
14441cb0ef41Sopenharmony_ci  PushCommonFrame(scratch);
14451cb0ef41Sopenharmony_ci  // Reserve room for saved entry sp.
14461cb0ef41Sopenharmony_ci  sub(sp, fp, Operand(ExitFrameConstants::kFixedFrameSizeFromFp));
14471cb0ef41Sopenharmony_ci  if (FLAG_debug_code) {
14481cb0ef41Sopenharmony_ci    mov(scratch, Operand::Zero());
14491cb0ef41Sopenharmony_ci    str(scratch, MemOperand(fp, ExitFrameConstants::kSPOffset));
14501cb0ef41Sopenharmony_ci  }
14511cb0ef41Sopenharmony_ci
14521cb0ef41Sopenharmony_ci  // Save the frame pointer and the context in top.
14531cb0ef41Sopenharmony_ci  Move(scratch, ExternalReference::Create(IsolateAddressId::kCEntryFPAddress,
14541cb0ef41Sopenharmony_ci                                          isolate()));
14551cb0ef41Sopenharmony_ci  str(fp, MemOperand(scratch));
14561cb0ef41Sopenharmony_ci  Move(scratch,
14571cb0ef41Sopenharmony_ci       ExternalReference::Create(IsolateAddressId::kContextAddress, isolate()));
14581cb0ef41Sopenharmony_ci  str(cp, MemOperand(scratch));
14591cb0ef41Sopenharmony_ci
14601cb0ef41Sopenharmony_ci  // Optionally save all double registers.
14611cb0ef41Sopenharmony_ci  if (save_doubles) {
14621cb0ef41Sopenharmony_ci    SaveFPRegs(sp, scratch);
14631cb0ef41Sopenharmony_ci    // Note that d0 will be accessible at
14641cb0ef41Sopenharmony_ci    //   fp - ExitFrameConstants::kFrameSize -
14651cb0ef41Sopenharmony_ci    //   DwVfpRegister::kNumRegisters * kDoubleSize,
14661cb0ef41Sopenharmony_ci    // since the sp slot and code slot were pushed after the fp.
14671cb0ef41Sopenharmony_ci  }
14681cb0ef41Sopenharmony_ci
14691cb0ef41Sopenharmony_ci  // Reserve place for the return address and stack space and align the frame
14701cb0ef41Sopenharmony_ci  // preparing for calling the runtime function.
14711cb0ef41Sopenharmony_ci  const int frame_alignment = MacroAssembler::ActivationFrameAlignment();
14721cb0ef41Sopenharmony_ci  AllocateStackSpace((stack_space + 1) * kPointerSize);
14731cb0ef41Sopenharmony_ci  if (frame_alignment > 0) {
14741cb0ef41Sopenharmony_ci    DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
14751cb0ef41Sopenharmony_ci    and_(sp, sp, Operand(-frame_alignment));
14761cb0ef41Sopenharmony_ci  }
14771cb0ef41Sopenharmony_ci
14781cb0ef41Sopenharmony_ci  // Set the exit frame sp value to point just before the return address
14791cb0ef41Sopenharmony_ci  // location.
14801cb0ef41Sopenharmony_ci  add(scratch, sp, Operand(kPointerSize));
14811cb0ef41Sopenharmony_ci  str(scratch, MemOperand(fp, ExitFrameConstants::kSPOffset));
14821cb0ef41Sopenharmony_ci}
14831cb0ef41Sopenharmony_ci
14841cb0ef41Sopenharmony_ciint TurboAssembler::ActivationFrameAlignment() {
14851cb0ef41Sopenharmony_ci#if V8_HOST_ARCH_ARM
14861cb0ef41Sopenharmony_ci  // Running on the real platform. Use the alignment as mandated by the local
14871cb0ef41Sopenharmony_ci  // environment.
14881cb0ef41Sopenharmony_ci  // Note: This will break if we ever start generating snapshots on one ARM
14891cb0ef41Sopenharmony_ci  // platform for another ARM platform with a different alignment.
14901cb0ef41Sopenharmony_ci  return base::OS::ActivationFrameAlignment();
14911cb0ef41Sopenharmony_ci#else   // V8_HOST_ARCH_ARM
14921cb0ef41Sopenharmony_ci  // If we are using the simulator then we should always align to the expected
14931cb0ef41Sopenharmony_ci  // alignment. As the simulator is used to generate snapshots we do not know
14941cb0ef41Sopenharmony_ci  // if the target platform will need alignment, so this is controlled from a
14951cb0ef41Sopenharmony_ci  // flag.
14961cb0ef41Sopenharmony_ci  return FLAG_sim_stack_alignment;
14971cb0ef41Sopenharmony_ci#endif  // V8_HOST_ARCH_ARM
14981cb0ef41Sopenharmony_ci}
14991cb0ef41Sopenharmony_ci
15001cb0ef41Sopenharmony_civoid MacroAssembler::LeaveExitFrame(bool save_doubles, Register argument_count,
15011cb0ef41Sopenharmony_ci                                    bool argument_count_is_length) {
15021cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
15031cb0ef41Sopenharmony_ci  ConstantPoolUnavailableScope constant_pool_unavailable(this);
15041cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
15051cb0ef41Sopenharmony_ci  Register scratch = temps.Acquire();
15061cb0ef41Sopenharmony_ci
15071cb0ef41Sopenharmony_ci  // Optionally restore all double registers.
15081cb0ef41Sopenharmony_ci  if (save_doubles) {
15091cb0ef41Sopenharmony_ci    // Calculate the stack location of the saved doubles and restore them.
15101cb0ef41Sopenharmony_ci    const int offset = ExitFrameConstants::kFixedFrameSizeFromFp;
15111cb0ef41Sopenharmony_ci    sub(r3, fp, Operand(offset + DwVfpRegister::kNumRegisters * kDoubleSize));
15121cb0ef41Sopenharmony_ci    RestoreFPRegs(r3, scratch);
15131cb0ef41Sopenharmony_ci  }
15141cb0ef41Sopenharmony_ci
15151cb0ef41Sopenharmony_ci  // Clear top frame.
15161cb0ef41Sopenharmony_ci  mov(r3, Operand::Zero());
15171cb0ef41Sopenharmony_ci  Move(scratch, ExternalReference::Create(IsolateAddressId::kCEntryFPAddress,
15181cb0ef41Sopenharmony_ci                                          isolate()));
15191cb0ef41Sopenharmony_ci  str(r3, MemOperand(scratch));
15201cb0ef41Sopenharmony_ci
15211cb0ef41Sopenharmony_ci  // Restore current context from top and clear it in debug mode.
15221cb0ef41Sopenharmony_ci  Move(scratch,
15231cb0ef41Sopenharmony_ci       ExternalReference::Create(IsolateAddressId::kContextAddress, isolate()));
15241cb0ef41Sopenharmony_ci  ldr(cp, MemOperand(scratch));
15251cb0ef41Sopenharmony_ci#ifdef DEBUG
15261cb0ef41Sopenharmony_ci  mov(r3, Operand(Context::kInvalidContext));
15271cb0ef41Sopenharmony_ci  Move(scratch,
15281cb0ef41Sopenharmony_ci       ExternalReference::Create(IsolateAddressId::kContextAddress, isolate()));
15291cb0ef41Sopenharmony_ci  str(r3, MemOperand(scratch));
15301cb0ef41Sopenharmony_ci#endif
15311cb0ef41Sopenharmony_ci
15321cb0ef41Sopenharmony_ci  // Tear down the exit frame, pop the arguments, and return.
15331cb0ef41Sopenharmony_ci  mov(sp, Operand(fp));
15341cb0ef41Sopenharmony_ci  ldm(ia_w, sp, {fp, lr});
15351cb0ef41Sopenharmony_ci  if (argument_count.is_valid()) {
15361cb0ef41Sopenharmony_ci    if (argument_count_is_length) {
15371cb0ef41Sopenharmony_ci      add(sp, sp, argument_count);
15381cb0ef41Sopenharmony_ci    } else {
15391cb0ef41Sopenharmony_ci      add(sp, sp, Operand(argument_count, LSL, kPointerSizeLog2));
15401cb0ef41Sopenharmony_ci    }
15411cb0ef41Sopenharmony_ci  }
15421cb0ef41Sopenharmony_ci}
15431cb0ef41Sopenharmony_ci
15441cb0ef41Sopenharmony_civoid TurboAssembler::MovFromFloatResult(const DwVfpRegister dst) {
15451cb0ef41Sopenharmony_ci  if (use_eabi_hardfloat()) {
15461cb0ef41Sopenharmony_ci    Move(dst, d0);
15471cb0ef41Sopenharmony_ci  } else {
15481cb0ef41Sopenharmony_ci    vmov(dst, r0, r1);
15491cb0ef41Sopenharmony_ci  }
15501cb0ef41Sopenharmony_ci}
15511cb0ef41Sopenharmony_ci
15521cb0ef41Sopenharmony_ci// On ARM this is just a synonym to make the purpose clear.
15531cb0ef41Sopenharmony_civoid TurboAssembler::MovFromFloatParameter(DwVfpRegister dst) {
15541cb0ef41Sopenharmony_ci  MovFromFloatResult(dst);
15551cb0ef41Sopenharmony_ci}
15561cb0ef41Sopenharmony_ci
15571cb0ef41Sopenharmony_civoid MacroAssembler::LoadStackLimit(Register destination, StackLimitKind kind) {
15581cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
15591cb0ef41Sopenharmony_ci  DCHECK(root_array_available());
15601cb0ef41Sopenharmony_ci  Isolate* isolate = this->isolate();
15611cb0ef41Sopenharmony_ci  ExternalReference limit =
15621cb0ef41Sopenharmony_ci      kind == StackLimitKind::kRealStackLimit
15631cb0ef41Sopenharmony_ci          ? ExternalReference::address_of_real_jslimit(isolate)
15641cb0ef41Sopenharmony_ci          : ExternalReference::address_of_jslimit(isolate);
15651cb0ef41Sopenharmony_ci  DCHECK(TurboAssembler::IsAddressableThroughRootRegister(isolate, limit));
15661cb0ef41Sopenharmony_ci
15671cb0ef41Sopenharmony_ci  intptr_t offset =
15681cb0ef41Sopenharmony_ci      TurboAssembler::RootRegisterOffsetForExternalReference(isolate, limit);
15691cb0ef41Sopenharmony_ci  CHECK(is_int32(offset));
15701cb0ef41Sopenharmony_ci  ldr(destination, MemOperand(kRootRegister, offset));
15711cb0ef41Sopenharmony_ci}
15721cb0ef41Sopenharmony_ci
15731cb0ef41Sopenharmony_civoid MacroAssembler::StackOverflowCheck(Register num_args, Register scratch,
15741cb0ef41Sopenharmony_ci                                        Label* stack_overflow) {
15751cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
15761cb0ef41Sopenharmony_ci  // Check the stack for overflow. We are not trying to catch
15771cb0ef41Sopenharmony_ci  // interruptions (e.g. debug break and preemption) here, so the "real stack
15781cb0ef41Sopenharmony_ci  // limit" is checked.
15791cb0ef41Sopenharmony_ci  LoadStackLimit(scratch, StackLimitKind::kRealStackLimit);
15801cb0ef41Sopenharmony_ci  // Make scratch the space we have left. The stack might already be overflowed
15811cb0ef41Sopenharmony_ci  // here which will cause scratch to become negative.
15821cb0ef41Sopenharmony_ci  sub(scratch, sp, scratch);
15831cb0ef41Sopenharmony_ci  // Check if the arguments will overflow the stack.
15841cb0ef41Sopenharmony_ci  cmp(scratch, Operand(num_args, LSL, kPointerSizeLog2));
15851cb0ef41Sopenharmony_ci  b(le, stack_overflow);  // Signed comparison.
15861cb0ef41Sopenharmony_ci}
15871cb0ef41Sopenharmony_ci
15881cb0ef41Sopenharmony_civoid MacroAssembler::InvokePrologue(Register expected_parameter_count,
15891cb0ef41Sopenharmony_ci                                    Register actual_parameter_count,
15901cb0ef41Sopenharmony_ci                                    Label* done, InvokeType type) {
15911cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
15921cb0ef41Sopenharmony_ci  Label regular_invoke;
15931cb0ef41Sopenharmony_ci  //  r0: actual arguments count
15941cb0ef41Sopenharmony_ci  //  r1: function (passed through to callee)
15951cb0ef41Sopenharmony_ci  //  r2: expected arguments count
15961cb0ef41Sopenharmony_ci  DCHECK_EQ(actual_parameter_count, r0);
15971cb0ef41Sopenharmony_ci  DCHECK_EQ(expected_parameter_count, r2);
15981cb0ef41Sopenharmony_ci
15991cb0ef41Sopenharmony_ci  // If the expected parameter count is equal to the adaptor sentinel, no need
16001cb0ef41Sopenharmony_ci  // to push undefined value as arguments.
16011cb0ef41Sopenharmony_ci  if (kDontAdaptArgumentsSentinel != 0) {
16021cb0ef41Sopenharmony_ci    cmp(expected_parameter_count, Operand(kDontAdaptArgumentsSentinel));
16031cb0ef41Sopenharmony_ci    b(eq, &regular_invoke);
16041cb0ef41Sopenharmony_ci  }
16051cb0ef41Sopenharmony_ci
16061cb0ef41Sopenharmony_ci  // If overapplication or if the actual argument count is equal to the
16071cb0ef41Sopenharmony_ci  // formal parameter count, no need to push extra undefined values.
16081cb0ef41Sopenharmony_ci  sub(expected_parameter_count, expected_parameter_count,
16091cb0ef41Sopenharmony_ci      actual_parameter_count, SetCC);
16101cb0ef41Sopenharmony_ci  b(le, &regular_invoke);
16111cb0ef41Sopenharmony_ci
16121cb0ef41Sopenharmony_ci  Label stack_overflow;
16131cb0ef41Sopenharmony_ci  Register scratch = r4;
16141cb0ef41Sopenharmony_ci  StackOverflowCheck(expected_parameter_count, scratch, &stack_overflow);
16151cb0ef41Sopenharmony_ci
16161cb0ef41Sopenharmony_ci  // Underapplication. Move the arguments already in the stack, including the
16171cb0ef41Sopenharmony_ci  // receiver and the return address.
16181cb0ef41Sopenharmony_ci  {
16191cb0ef41Sopenharmony_ci    Label copy, check;
16201cb0ef41Sopenharmony_ci    Register num = r5, src = r6, dest = r9;  // r7 and r8 are context and root.
16211cb0ef41Sopenharmony_ci    mov(src, sp);
16221cb0ef41Sopenharmony_ci    // Update stack pointer.
16231cb0ef41Sopenharmony_ci    lsl(scratch, expected_parameter_count, Operand(kSystemPointerSizeLog2));
16241cb0ef41Sopenharmony_ci    AllocateStackSpace(scratch);
16251cb0ef41Sopenharmony_ci    mov(dest, sp);
16261cb0ef41Sopenharmony_ci    mov(num, actual_parameter_count);
16271cb0ef41Sopenharmony_ci    b(&check);
16281cb0ef41Sopenharmony_ci    bind(&copy);
16291cb0ef41Sopenharmony_ci    ldr(scratch, MemOperand(src, kSystemPointerSize, PostIndex));
16301cb0ef41Sopenharmony_ci    str(scratch, MemOperand(dest, kSystemPointerSize, PostIndex));
16311cb0ef41Sopenharmony_ci    sub(num, num, Operand(1), SetCC);
16321cb0ef41Sopenharmony_ci    bind(&check);
16331cb0ef41Sopenharmony_ci    b(gt, &copy);
16341cb0ef41Sopenharmony_ci  }
16351cb0ef41Sopenharmony_ci
16361cb0ef41Sopenharmony_ci  // Fill remaining expected arguments with undefined values.
16371cb0ef41Sopenharmony_ci  LoadRoot(scratch, RootIndex::kUndefinedValue);
16381cb0ef41Sopenharmony_ci  {
16391cb0ef41Sopenharmony_ci    Label loop;
16401cb0ef41Sopenharmony_ci    bind(&loop);
16411cb0ef41Sopenharmony_ci    str(scratch, MemOperand(r9, kSystemPointerSize, PostIndex));
16421cb0ef41Sopenharmony_ci    sub(expected_parameter_count, expected_parameter_count, Operand(1), SetCC);
16431cb0ef41Sopenharmony_ci    b(gt, &loop);
16441cb0ef41Sopenharmony_ci  }
16451cb0ef41Sopenharmony_ci  b(&regular_invoke);
16461cb0ef41Sopenharmony_ci
16471cb0ef41Sopenharmony_ci  bind(&stack_overflow);
16481cb0ef41Sopenharmony_ci  {
16491cb0ef41Sopenharmony_ci    FrameScope frame(
16501cb0ef41Sopenharmony_ci        this, has_frame() ? StackFrame::NO_FRAME_TYPE : StackFrame::INTERNAL);
16511cb0ef41Sopenharmony_ci    CallRuntime(Runtime::kThrowStackOverflow);
16521cb0ef41Sopenharmony_ci    bkpt(0);
16531cb0ef41Sopenharmony_ci  }
16541cb0ef41Sopenharmony_ci
16551cb0ef41Sopenharmony_ci  bind(&regular_invoke);
16561cb0ef41Sopenharmony_ci}
16571cb0ef41Sopenharmony_ci
16581cb0ef41Sopenharmony_civoid MacroAssembler::CallDebugOnFunctionCall(Register fun, Register new_target,
16591cb0ef41Sopenharmony_ci                                             Register expected_parameter_count,
16601cb0ef41Sopenharmony_ci                                             Register actual_parameter_count) {
16611cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
16621cb0ef41Sopenharmony_ci  // Load receiver to pass it later to DebugOnFunctionCall hook.
16631cb0ef41Sopenharmony_ci  ldr(r4, ReceiverOperand(actual_parameter_count));
16641cb0ef41Sopenharmony_ci  FrameScope frame(
16651cb0ef41Sopenharmony_ci      this, has_frame() ? StackFrame::NO_FRAME_TYPE : StackFrame::INTERNAL);
16661cb0ef41Sopenharmony_ci
16671cb0ef41Sopenharmony_ci  SmiTag(expected_parameter_count);
16681cb0ef41Sopenharmony_ci  Push(expected_parameter_count);
16691cb0ef41Sopenharmony_ci
16701cb0ef41Sopenharmony_ci  SmiTag(actual_parameter_count);
16711cb0ef41Sopenharmony_ci  Push(actual_parameter_count);
16721cb0ef41Sopenharmony_ci
16731cb0ef41Sopenharmony_ci  if (new_target.is_valid()) {
16741cb0ef41Sopenharmony_ci    Push(new_target);
16751cb0ef41Sopenharmony_ci  }
16761cb0ef41Sopenharmony_ci  Push(fun);
16771cb0ef41Sopenharmony_ci  Push(fun);
16781cb0ef41Sopenharmony_ci  Push(r4);
16791cb0ef41Sopenharmony_ci  CallRuntime(Runtime::kDebugOnFunctionCall);
16801cb0ef41Sopenharmony_ci  Pop(fun);
16811cb0ef41Sopenharmony_ci  if (new_target.is_valid()) {
16821cb0ef41Sopenharmony_ci    Pop(new_target);
16831cb0ef41Sopenharmony_ci  }
16841cb0ef41Sopenharmony_ci
16851cb0ef41Sopenharmony_ci  Pop(actual_parameter_count);
16861cb0ef41Sopenharmony_ci  SmiUntag(actual_parameter_count);
16871cb0ef41Sopenharmony_ci
16881cb0ef41Sopenharmony_ci  Pop(expected_parameter_count);
16891cb0ef41Sopenharmony_ci  SmiUntag(expected_parameter_count);
16901cb0ef41Sopenharmony_ci}
16911cb0ef41Sopenharmony_ci
16921cb0ef41Sopenharmony_civoid MacroAssembler::InvokeFunctionCode(Register function, Register new_target,
16931cb0ef41Sopenharmony_ci                                        Register expected_parameter_count,
16941cb0ef41Sopenharmony_ci                                        Register actual_parameter_count,
16951cb0ef41Sopenharmony_ci                                        InvokeType type) {
16961cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
16971cb0ef41Sopenharmony_ci  // You can't call a function without a valid frame.
16981cb0ef41Sopenharmony_ci  DCHECK_IMPLIES(type == InvokeType::kCall, has_frame());
16991cb0ef41Sopenharmony_ci  DCHECK_EQ(function, r1);
17001cb0ef41Sopenharmony_ci  DCHECK_IMPLIES(new_target.is_valid(), new_target == r3);
17011cb0ef41Sopenharmony_ci
17021cb0ef41Sopenharmony_ci  // On function call, call into the debugger if necessary.
17031cb0ef41Sopenharmony_ci  Label debug_hook, continue_after_hook;
17041cb0ef41Sopenharmony_ci  {
17051cb0ef41Sopenharmony_ci    ExternalReference debug_hook_active =
17061cb0ef41Sopenharmony_ci        ExternalReference::debug_hook_on_function_call_address(isolate());
17071cb0ef41Sopenharmony_ci    Move(r4, debug_hook_active);
17081cb0ef41Sopenharmony_ci    ldrsb(r4, MemOperand(r4));
17091cb0ef41Sopenharmony_ci    cmp(r4, Operand(0));
17101cb0ef41Sopenharmony_ci    b(ne, &debug_hook);
17111cb0ef41Sopenharmony_ci  }
17121cb0ef41Sopenharmony_ci  bind(&continue_after_hook);
17131cb0ef41Sopenharmony_ci
17141cb0ef41Sopenharmony_ci  // Clear the new.target register if not given.
17151cb0ef41Sopenharmony_ci  if (!new_target.is_valid()) {
17161cb0ef41Sopenharmony_ci    LoadRoot(r3, RootIndex::kUndefinedValue);
17171cb0ef41Sopenharmony_ci  }
17181cb0ef41Sopenharmony_ci
17191cb0ef41Sopenharmony_ci  Label done;
17201cb0ef41Sopenharmony_ci  InvokePrologue(expected_parameter_count, actual_parameter_count, &done, type);
17211cb0ef41Sopenharmony_ci  // We call indirectly through the code field in the function to
17221cb0ef41Sopenharmony_ci  // allow recompilation to take effect without changing any of the
17231cb0ef41Sopenharmony_ci  // call sites.
17241cb0ef41Sopenharmony_ci  Register code = kJavaScriptCallCodeStartRegister;
17251cb0ef41Sopenharmony_ci  ldr(code, FieldMemOperand(function, JSFunction::kCodeOffset));
17261cb0ef41Sopenharmony_ci  switch (type) {
17271cb0ef41Sopenharmony_ci    case InvokeType::kCall:
17281cb0ef41Sopenharmony_ci      CallCodeObject(code);
17291cb0ef41Sopenharmony_ci      break;
17301cb0ef41Sopenharmony_ci    case InvokeType::kJump:
17311cb0ef41Sopenharmony_ci      JumpCodeObject(code);
17321cb0ef41Sopenharmony_ci      break;
17331cb0ef41Sopenharmony_ci  }
17341cb0ef41Sopenharmony_ci  b(&done);
17351cb0ef41Sopenharmony_ci
17361cb0ef41Sopenharmony_ci  // Deferred debug hook.
17371cb0ef41Sopenharmony_ci  bind(&debug_hook);
17381cb0ef41Sopenharmony_ci  CallDebugOnFunctionCall(function, new_target, expected_parameter_count,
17391cb0ef41Sopenharmony_ci                          actual_parameter_count);
17401cb0ef41Sopenharmony_ci  b(&continue_after_hook);
17411cb0ef41Sopenharmony_ci
17421cb0ef41Sopenharmony_ci  // Continue here if InvokePrologue does handle the invocation due to
17431cb0ef41Sopenharmony_ci  // mismatched parameter counts.
17441cb0ef41Sopenharmony_ci  bind(&done);
17451cb0ef41Sopenharmony_ci}
17461cb0ef41Sopenharmony_ci
17471cb0ef41Sopenharmony_civoid MacroAssembler::InvokeFunctionWithNewTarget(
17481cb0ef41Sopenharmony_ci    Register fun, Register new_target, Register actual_parameter_count,
17491cb0ef41Sopenharmony_ci    InvokeType type) {
17501cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
17511cb0ef41Sopenharmony_ci  // You can't call a function without a valid frame.
17521cb0ef41Sopenharmony_ci  DCHECK_IMPLIES(type == InvokeType::kCall, has_frame());
17531cb0ef41Sopenharmony_ci
17541cb0ef41Sopenharmony_ci  // Contract with called JS functions requires that function is passed in r1.
17551cb0ef41Sopenharmony_ci  DCHECK_EQ(fun, r1);
17561cb0ef41Sopenharmony_ci
17571cb0ef41Sopenharmony_ci  Register expected_reg = r2;
17581cb0ef41Sopenharmony_ci  Register temp_reg = r4;
17591cb0ef41Sopenharmony_ci
17601cb0ef41Sopenharmony_ci  ldr(temp_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
17611cb0ef41Sopenharmony_ci  ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
17621cb0ef41Sopenharmony_ci  ldrh(expected_reg,
17631cb0ef41Sopenharmony_ci       FieldMemOperand(temp_reg,
17641cb0ef41Sopenharmony_ci                       SharedFunctionInfo::kFormalParameterCountOffset));
17651cb0ef41Sopenharmony_ci
17661cb0ef41Sopenharmony_ci  InvokeFunctionCode(fun, new_target, expected_reg, actual_parameter_count,
17671cb0ef41Sopenharmony_ci                     type);
17681cb0ef41Sopenharmony_ci}
17691cb0ef41Sopenharmony_ci
17701cb0ef41Sopenharmony_civoid MacroAssembler::InvokeFunction(Register function,
17711cb0ef41Sopenharmony_ci                                    Register expected_parameter_count,
17721cb0ef41Sopenharmony_ci                                    Register actual_parameter_count,
17731cb0ef41Sopenharmony_ci                                    InvokeType type) {
17741cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
17751cb0ef41Sopenharmony_ci  // You can't call a function without a valid frame.
17761cb0ef41Sopenharmony_ci  DCHECK_IMPLIES(type == InvokeType::kCall, has_frame());
17771cb0ef41Sopenharmony_ci
17781cb0ef41Sopenharmony_ci  // Contract with called JS functions requires that function is passed in r1.
17791cb0ef41Sopenharmony_ci  DCHECK_EQ(function, r1);
17801cb0ef41Sopenharmony_ci
17811cb0ef41Sopenharmony_ci  // Get the function and setup the context.
17821cb0ef41Sopenharmony_ci  ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
17831cb0ef41Sopenharmony_ci
17841cb0ef41Sopenharmony_ci  InvokeFunctionCode(r1, no_reg, expected_parameter_count,
17851cb0ef41Sopenharmony_ci                     actual_parameter_count, type);
17861cb0ef41Sopenharmony_ci}
17871cb0ef41Sopenharmony_ci
17881cb0ef41Sopenharmony_civoid MacroAssembler::PushStackHandler() {
17891cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
17901cb0ef41Sopenharmony_ci  // Adjust this code if not the case.
17911cb0ef41Sopenharmony_ci  STATIC_ASSERT(StackHandlerConstants::kSize == 2 * kPointerSize);
17921cb0ef41Sopenharmony_ci  STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0 * kPointerSize);
17931cb0ef41Sopenharmony_ci
17941cb0ef41Sopenharmony_ci  Push(Smi::zero());  // Padding.
17951cb0ef41Sopenharmony_ci  // Link the current handler as the next handler.
17961cb0ef41Sopenharmony_ci  Move(r6,
17971cb0ef41Sopenharmony_ci       ExternalReference::Create(IsolateAddressId::kHandlerAddress, isolate()));
17981cb0ef41Sopenharmony_ci  ldr(r5, MemOperand(r6));
17991cb0ef41Sopenharmony_ci  push(r5);
18001cb0ef41Sopenharmony_ci  // Set this new handler as the current one.
18011cb0ef41Sopenharmony_ci  str(sp, MemOperand(r6));
18021cb0ef41Sopenharmony_ci}
18031cb0ef41Sopenharmony_ci
18041cb0ef41Sopenharmony_civoid MacroAssembler::PopStackHandler() {
18051cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
18061cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
18071cb0ef41Sopenharmony_ci  Register scratch = temps.Acquire();
18081cb0ef41Sopenharmony_ci  STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0);
18091cb0ef41Sopenharmony_ci  pop(r1);
18101cb0ef41Sopenharmony_ci  Move(scratch,
18111cb0ef41Sopenharmony_ci       ExternalReference::Create(IsolateAddressId::kHandlerAddress, isolate()));
18121cb0ef41Sopenharmony_ci  str(r1, MemOperand(scratch));
18131cb0ef41Sopenharmony_ci  add(sp, sp, Operand(StackHandlerConstants::kSize - kPointerSize));
18141cb0ef41Sopenharmony_ci}
18151cb0ef41Sopenharmony_ci
18161cb0ef41Sopenharmony_civoid MacroAssembler::CompareObjectType(Register object, Register map,
18171cb0ef41Sopenharmony_ci                                       Register type_reg, InstanceType type) {
18181cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
18191cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
18201cb0ef41Sopenharmony_ci  const Register temp = type_reg == no_reg ? temps.Acquire() : type_reg;
18211cb0ef41Sopenharmony_ci
18221cb0ef41Sopenharmony_ci  LoadMap(map, object);
18231cb0ef41Sopenharmony_ci  CompareInstanceType(map, temp, type);
18241cb0ef41Sopenharmony_ci}
18251cb0ef41Sopenharmony_ci
18261cb0ef41Sopenharmony_civoid MacroAssembler::CompareInstanceType(Register map, Register type_reg,
18271cb0ef41Sopenharmony_ci                                         InstanceType type) {
18281cb0ef41Sopenharmony_ci  ldrh(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset));
18291cb0ef41Sopenharmony_ci  cmp(type_reg, Operand(type));
18301cb0ef41Sopenharmony_ci}
18311cb0ef41Sopenharmony_ci
18321cb0ef41Sopenharmony_civoid MacroAssembler::CompareRange(Register value, unsigned lower_limit,
18331cb0ef41Sopenharmony_ci                                  unsigned higher_limit) {
18341cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
18351cb0ef41Sopenharmony_ci  DCHECK_LT(lower_limit, higher_limit);
18361cb0ef41Sopenharmony_ci  if (lower_limit != 0) {
18371cb0ef41Sopenharmony_ci    UseScratchRegisterScope temps(this);
18381cb0ef41Sopenharmony_ci    Register scratch = temps.Acquire();
18391cb0ef41Sopenharmony_ci    sub(scratch, value, Operand(lower_limit));
18401cb0ef41Sopenharmony_ci    cmp(scratch, Operand(higher_limit - lower_limit));
18411cb0ef41Sopenharmony_ci  } else {
18421cb0ef41Sopenharmony_ci    cmp(value, Operand(higher_limit));
18431cb0ef41Sopenharmony_ci  }
18441cb0ef41Sopenharmony_ci}
18451cb0ef41Sopenharmony_civoid MacroAssembler::CompareInstanceTypeRange(Register map, Register type_reg,
18461cb0ef41Sopenharmony_ci                                              InstanceType lower_limit,
18471cb0ef41Sopenharmony_ci                                              InstanceType higher_limit) {
18481cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
18491cb0ef41Sopenharmony_ci  DCHECK_LT(lower_limit, higher_limit);
18501cb0ef41Sopenharmony_ci  ldrh(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset));
18511cb0ef41Sopenharmony_ci  CompareRange(type_reg, lower_limit, higher_limit);
18521cb0ef41Sopenharmony_ci}
18531cb0ef41Sopenharmony_ci
18541cb0ef41Sopenharmony_civoid MacroAssembler::CompareRoot(Register obj, RootIndex index) {
18551cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
18561cb0ef41Sopenharmony_ci  Register scratch = temps.Acquire();
18571cb0ef41Sopenharmony_ci  DCHECK(obj != scratch);
18581cb0ef41Sopenharmony_ci  LoadRoot(scratch, index);
18591cb0ef41Sopenharmony_ci  cmp(obj, scratch);
18601cb0ef41Sopenharmony_ci}
18611cb0ef41Sopenharmony_ci
18621cb0ef41Sopenharmony_civoid MacroAssembler::JumpIfIsInRange(Register value, unsigned lower_limit,
18631cb0ef41Sopenharmony_ci                                     unsigned higher_limit,
18641cb0ef41Sopenharmony_ci                                     Label* on_in_range) {
18651cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
18661cb0ef41Sopenharmony_ci  CompareRange(value, lower_limit, higher_limit);
18671cb0ef41Sopenharmony_ci  b(ls, on_in_range);
18681cb0ef41Sopenharmony_ci}
18691cb0ef41Sopenharmony_ci
18701cb0ef41Sopenharmony_civoid TurboAssembler::TryInlineTruncateDoubleToI(Register result,
18711cb0ef41Sopenharmony_ci                                                DwVfpRegister double_input,
18721cb0ef41Sopenharmony_ci                                                Label* done) {
18731cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
18741cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
18751cb0ef41Sopenharmony_ci  SwVfpRegister single_scratch = SwVfpRegister::no_reg();
18761cb0ef41Sopenharmony_ci  if (temps.CanAcquireVfp<SwVfpRegister>()) {
18771cb0ef41Sopenharmony_ci    single_scratch = temps.AcquireS();
18781cb0ef41Sopenharmony_ci  } else {
18791cb0ef41Sopenharmony_ci    // Re-use the input as a scratch register. However, we can only do this if
18801cb0ef41Sopenharmony_ci    // the input register is d0-d15 as there are no s32+ registers.
18811cb0ef41Sopenharmony_ci    DCHECK_LT(double_input.code(), LowDwVfpRegister::kNumRegisters);
18821cb0ef41Sopenharmony_ci    LowDwVfpRegister double_scratch =
18831cb0ef41Sopenharmony_ci        LowDwVfpRegister::from_code(double_input.code());
18841cb0ef41Sopenharmony_ci    single_scratch = double_scratch.low();
18851cb0ef41Sopenharmony_ci  }
18861cb0ef41Sopenharmony_ci  vcvt_s32_f64(single_scratch, double_input);
18871cb0ef41Sopenharmony_ci  vmov(result, single_scratch);
18881cb0ef41Sopenharmony_ci
18891cb0ef41Sopenharmony_ci  Register scratch = temps.Acquire();
18901cb0ef41Sopenharmony_ci  // If result is not saturated (0x7FFFFFFF or 0x80000000), we are done.
18911cb0ef41Sopenharmony_ci  sub(scratch, result, Operand(1));
18921cb0ef41Sopenharmony_ci  cmp(scratch, Operand(0x7FFFFFFE));
18931cb0ef41Sopenharmony_ci  b(lt, done);
18941cb0ef41Sopenharmony_ci}
18951cb0ef41Sopenharmony_ci
18961cb0ef41Sopenharmony_civoid TurboAssembler::TruncateDoubleToI(Isolate* isolate, Zone* zone,
18971cb0ef41Sopenharmony_ci                                       Register result,
18981cb0ef41Sopenharmony_ci                                       DwVfpRegister double_input,
18991cb0ef41Sopenharmony_ci                                       StubCallMode stub_mode) {
19001cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
19011cb0ef41Sopenharmony_ci  Label done;
19021cb0ef41Sopenharmony_ci
19031cb0ef41Sopenharmony_ci  TryInlineTruncateDoubleToI(result, double_input, &done);
19041cb0ef41Sopenharmony_ci
19051cb0ef41Sopenharmony_ci  // If we fell through then inline version didn't succeed - call stub instead.
19061cb0ef41Sopenharmony_ci  push(lr);
19071cb0ef41Sopenharmony_ci  AllocateStackSpace(kDoubleSize);  // Put input on stack.
19081cb0ef41Sopenharmony_ci  vstr(double_input, MemOperand(sp, 0));
19091cb0ef41Sopenharmony_ci
19101cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY
19111cb0ef41Sopenharmony_ci  if (stub_mode == StubCallMode::kCallWasmRuntimeStub) {
19121cb0ef41Sopenharmony_ci    Call(wasm::WasmCode::kDoubleToI, RelocInfo::WASM_STUB_CALL);
19131cb0ef41Sopenharmony_ci#else
19141cb0ef41Sopenharmony_ci  // For balance.
19151cb0ef41Sopenharmony_ci  if (false) {
19161cb0ef41Sopenharmony_ci#endif  // V8_ENABLE_WEBASSEMBLY
19171cb0ef41Sopenharmony_ci  } else if (options().inline_offheap_trampolines) {
19181cb0ef41Sopenharmony_ci    CallBuiltin(Builtin::kDoubleToI);
19191cb0ef41Sopenharmony_ci  } else {
19201cb0ef41Sopenharmony_ci    Call(BUILTIN_CODE(isolate, DoubleToI), RelocInfo::CODE_TARGET);
19211cb0ef41Sopenharmony_ci  }
19221cb0ef41Sopenharmony_ci  ldr(result, MemOperand(sp, 0));
19231cb0ef41Sopenharmony_ci
19241cb0ef41Sopenharmony_ci  add(sp, sp, Operand(kDoubleSize));
19251cb0ef41Sopenharmony_ci  pop(lr);
19261cb0ef41Sopenharmony_ci
19271cb0ef41Sopenharmony_ci  bind(&done);
19281cb0ef41Sopenharmony_ci}
19291cb0ef41Sopenharmony_ci
19301cb0ef41Sopenharmony_civoid MacroAssembler::CallRuntime(const Runtime::Function* f, int num_arguments,
19311cb0ef41Sopenharmony_ci                                 SaveFPRegsMode save_doubles) {
19321cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
19331cb0ef41Sopenharmony_ci  // All parameters are on the stack.  r0 has the return value after call.
19341cb0ef41Sopenharmony_ci
19351cb0ef41Sopenharmony_ci  // If the expected number of arguments of the runtime function is
19361cb0ef41Sopenharmony_ci  // constant, we check that the actual number of arguments match the
19371cb0ef41Sopenharmony_ci  // expectation.
19381cb0ef41Sopenharmony_ci  CHECK(f->nargs < 0 || f->nargs == num_arguments);
19391cb0ef41Sopenharmony_ci
19401cb0ef41Sopenharmony_ci  // TODO(1236192): Most runtime routines don't need the number of
19411cb0ef41Sopenharmony_ci  // arguments passed in because it is constant. At some point we
19421cb0ef41Sopenharmony_ci  // should remove this need and make the runtime routine entry code
19431cb0ef41Sopenharmony_ci  // smarter.
19441cb0ef41Sopenharmony_ci  mov(r0, Operand(num_arguments));
19451cb0ef41Sopenharmony_ci  Move(r1, ExternalReference::Create(f));
19461cb0ef41Sopenharmony_ci  Handle<Code> code =
19471cb0ef41Sopenharmony_ci      CodeFactory::CEntry(isolate(), f->result_size, save_doubles);
19481cb0ef41Sopenharmony_ci  Call(code, RelocInfo::CODE_TARGET);
19491cb0ef41Sopenharmony_ci}
19501cb0ef41Sopenharmony_ci
19511cb0ef41Sopenharmony_civoid MacroAssembler::TailCallRuntime(Runtime::FunctionId fid) {
19521cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
19531cb0ef41Sopenharmony_ci  const Runtime::Function* function = Runtime::FunctionForId(fid);
19541cb0ef41Sopenharmony_ci  DCHECK_EQ(1, function->result_size);
19551cb0ef41Sopenharmony_ci  if (function->nargs >= 0) {
19561cb0ef41Sopenharmony_ci    // TODO(1236192): Most runtime routines don't need the number of
19571cb0ef41Sopenharmony_ci    // arguments passed in because it is constant. At some point we
19581cb0ef41Sopenharmony_ci    // should remove this need and make the runtime routine entry code
19591cb0ef41Sopenharmony_ci    // smarter.
19601cb0ef41Sopenharmony_ci    mov(r0, Operand(function->nargs));
19611cb0ef41Sopenharmony_ci  }
19621cb0ef41Sopenharmony_ci  JumpToExternalReference(ExternalReference::Create(fid));
19631cb0ef41Sopenharmony_ci}
19641cb0ef41Sopenharmony_ci
19651cb0ef41Sopenharmony_civoid MacroAssembler::JumpToExternalReference(const ExternalReference& builtin,
19661cb0ef41Sopenharmony_ci                                             bool builtin_exit_frame) {
19671cb0ef41Sopenharmony_ci#if defined(__thumb__)
19681cb0ef41Sopenharmony_ci  // Thumb mode builtin.
19691cb0ef41Sopenharmony_ci  DCHECK_EQ(builtin.address() & 1, 1);
19701cb0ef41Sopenharmony_ci#endif
19711cb0ef41Sopenharmony_ci  Move(r1, builtin);
19721cb0ef41Sopenharmony_ci  Handle<Code> code = CodeFactory::CEntry(isolate(), 1, SaveFPRegsMode::kIgnore,
19731cb0ef41Sopenharmony_ci                                          ArgvMode::kStack, builtin_exit_frame);
19741cb0ef41Sopenharmony_ci  Jump(code, RelocInfo::CODE_TARGET);
19751cb0ef41Sopenharmony_ci}
19761cb0ef41Sopenharmony_ci
19771cb0ef41Sopenharmony_civoid MacroAssembler::JumpToOffHeapInstructionStream(Address entry) {
19781cb0ef41Sopenharmony_ci  mov(kOffHeapTrampolineRegister, Operand(entry, RelocInfo::OFF_HEAP_TARGET));
19791cb0ef41Sopenharmony_ci  Jump(kOffHeapTrampolineRegister);
19801cb0ef41Sopenharmony_ci}
19811cb0ef41Sopenharmony_ci
19821cb0ef41Sopenharmony_civoid MacroAssembler::LoadWeakValue(Register out, Register in,
19831cb0ef41Sopenharmony_ci                                   Label* target_if_cleared) {
19841cb0ef41Sopenharmony_ci  cmp(in, Operand(kClearedWeakHeapObjectLower32));
19851cb0ef41Sopenharmony_ci  b(eq, target_if_cleared);
19861cb0ef41Sopenharmony_ci
19871cb0ef41Sopenharmony_ci  and_(out, in, Operand(~kWeakHeapObjectMask));
19881cb0ef41Sopenharmony_ci}
19891cb0ef41Sopenharmony_ci
19901cb0ef41Sopenharmony_civoid MacroAssembler::EmitIncrementCounter(StatsCounter* counter, int value,
19911cb0ef41Sopenharmony_ci                                          Register scratch1,
19921cb0ef41Sopenharmony_ci                                          Register scratch2) {
19931cb0ef41Sopenharmony_ci  DCHECK_GT(value, 0);
19941cb0ef41Sopenharmony_ci  if (FLAG_native_code_counters && counter->Enabled()) {
19951cb0ef41Sopenharmony_ci    ASM_CODE_COMMENT(this);
19961cb0ef41Sopenharmony_ci    Move(scratch2, ExternalReference::Create(counter));
19971cb0ef41Sopenharmony_ci    ldr(scratch1, MemOperand(scratch2));
19981cb0ef41Sopenharmony_ci    add(scratch1, scratch1, Operand(value));
19991cb0ef41Sopenharmony_ci    str(scratch1, MemOperand(scratch2));
20001cb0ef41Sopenharmony_ci  }
20011cb0ef41Sopenharmony_ci}
20021cb0ef41Sopenharmony_ci
20031cb0ef41Sopenharmony_civoid MacroAssembler::EmitDecrementCounter(StatsCounter* counter, int value,
20041cb0ef41Sopenharmony_ci                                          Register scratch1,
20051cb0ef41Sopenharmony_ci                                          Register scratch2) {
20061cb0ef41Sopenharmony_ci  DCHECK_GT(value, 0);
20071cb0ef41Sopenharmony_ci  if (FLAG_native_code_counters && counter->Enabled()) {
20081cb0ef41Sopenharmony_ci    ASM_CODE_COMMENT(this);
20091cb0ef41Sopenharmony_ci    Move(scratch2, ExternalReference::Create(counter));
20101cb0ef41Sopenharmony_ci    ldr(scratch1, MemOperand(scratch2));
20111cb0ef41Sopenharmony_ci    sub(scratch1, scratch1, Operand(value));
20121cb0ef41Sopenharmony_ci    str(scratch1, MemOperand(scratch2));
20131cb0ef41Sopenharmony_ci  }
20141cb0ef41Sopenharmony_ci}
20151cb0ef41Sopenharmony_ci
20161cb0ef41Sopenharmony_civoid TurboAssembler::Assert(Condition cond, AbortReason reason) {
20171cb0ef41Sopenharmony_ci  if (FLAG_debug_code) Check(cond, reason);
20181cb0ef41Sopenharmony_ci}
20191cb0ef41Sopenharmony_ci
20201cb0ef41Sopenharmony_civoid TurboAssembler::AssertUnreachable(AbortReason reason) {
20211cb0ef41Sopenharmony_ci  if (FLAG_debug_code) Abort(reason);
20221cb0ef41Sopenharmony_ci}
20231cb0ef41Sopenharmony_ci
20241cb0ef41Sopenharmony_civoid TurboAssembler::Check(Condition cond, AbortReason reason) {
20251cb0ef41Sopenharmony_ci  Label L;
20261cb0ef41Sopenharmony_ci  b(cond, &L);
20271cb0ef41Sopenharmony_ci  Abort(reason);
20281cb0ef41Sopenharmony_ci  // will not return here
20291cb0ef41Sopenharmony_ci  bind(&L);
20301cb0ef41Sopenharmony_ci}
20311cb0ef41Sopenharmony_ci
20321cb0ef41Sopenharmony_civoid TurboAssembler::Abort(AbortReason reason) {
20331cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
20341cb0ef41Sopenharmony_ci  Label abort_start;
20351cb0ef41Sopenharmony_ci  bind(&abort_start);
20361cb0ef41Sopenharmony_ci  if (FLAG_code_comments) {
20371cb0ef41Sopenharmony_ci    const char* msg = GetAbortReason(reason);
20381cb0ef41Sopenharmony_ci    RecordComment("Abort message: ");
20391cb0ef41Sopenharmony_ci    RecordComment(msg);
20401cb0ef41Sopenharmony_ci  }
20411cb0ef41Sopenharmony_ci
20421cb0ef41Sopenharmony_ci  // Avoid emitting call to builtin if requested.
20431cb0ef41Sopenharmony_ci  if (trap_on_abort()) {
20441cb0ef41Sopenharmony_ci    stop();
20451cb0ef41Sopenharmony_ci    return;
20461cb0ef41Sopenharmony_ci  }
20471cb0ef41Sopenharmony_ci
20481cb0ef41Sopenharmony_ci  if (should_abort_hard()) {
20491cb0ef41Sopenharmony_ci    // We don't care if we constructed a frame. Just pretend we did.
20501cb0ef41Sopenharmony_ci    FrameScope assume_frame(this, StackFrame::NO_FRAME_TYPE);
20511cb0ef41Sopenharmony_ci    Move32BitImmediate(r0, Operand(static_cast<int>(reason)));
20521cb0ef41Sopenharmony_ci    PrepareCallCFunction(1, 0, r1);
20531cb0ef41Sopenharmony_ci    Move(r1, ExternalReference::abort_with_reason());
20541cb0ef41Sopenharmony_ci    // Use Call directly to avoid any unneeded overhead. The function won't
20551cb0ef41Sopenharmony_ci    // return anyway.
20561cb0ef41Sopenharmony_ci    Call(r1);
20571cb0ef41Sopenharmony_ci    return;
20581cb0ef41Sopenharmony_ci  }
20591cb0ef41Sopenharmony_ci
20601cb0ef41Sopenharmony_ci  Move(r1, Smi::FromInt(static_cast<int>(reason)));
20611cb0ef41Sopenharmony_ci
20621cb0ef41Sopenharmony_ci  // Disable stub call restrictions to always allow calls to abort.
20631cb0ef41Sopenharmony_ci  if (!has_frame()) {
20641cb0ef41Sopenharmony_ci    // We don't actually want to generate a pile of code for this, so just
20651cb0ef41Sopenharmony_ci    // claim there is a stack frame, without generating one.
20661cb0ef41Sopenharmony_ci    FrameScope scope(this, StackFrame::NO_FRAME_TYPE);
20671cb0ef41Sopenharmony_ci    Call(BUILTIN_CODE(isolate(), Abort), RelocInfo::CODE_TARGET);
20681cb0ef41Sopenharmony_ci  } else {
20691cb0ef41Sopenharmony_ci    Call(BUILTIN_CODE(isolate(), Abort), RelocInfo::CODE_TARGET);
20701cb0ef41Sopenharmony_ci  }
20711cb0ef41Sopenharmony_ci  // will not return here
20721cb0ef41Sopenharmony_ci}
20731cb0ef41Sopenharmony_ci
20741cb0ef41Sopenharmony_civoid TurboAssembler::LoadMap(Register destination, Register object) {
20751cb0ef41Sopenharmony_ci  ldr(destination, FieldMemOperand(object, HeapObject::kMapOffset));
20761cb0ef41Sopenharmony_ci}
20771cb0ef41Sopenharmony_ci
20781cb0ef41Sopenharmony_civoid MacroAssembler::LoadGlobalProxy(Register dst) {
20791cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
20801cb0ef41Sopenharmony_ci  LoadNativeContextSlot(dst, Context::GLOBAL_PROXY_INDEX);
20811cb0ef41Sopenharmony_ci}
20821cb0ef41Sopenharmony_ci
20831cb0ef41Sopenharmony_civoid MacroAssembler::LoadNativeContextSlot(Register dst, int index) {
20841cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
20851cb0ef41Sopenharmony_ci  LoadMap(dst, cp);
20861cb0ef41Sopenharmony_ci  ldr(dst, FieldMemOperand(
20871cb0ef41Sopenharmony_ci               dst, Map::kConstructorOrBackPointerOrNativeContextOffset));
20881cb0ef41Sopenharmony_ci  ldr(dst, MemOperand(dst, Context::SlotOffset(index)));
20891cb0ef41Sopenharmony_ci}
20901cb0ef41Sopenharmony_ci
20911cb0ef41Sopenharmony_civoid TurboAssembler::InitializeRootRegister() {
20921cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
20931cb0ef41Sopenharmony_ci  ExternalReference isolate_root = ExternalReference::isolate_root(isolate());
20941cb0ef41Sopenharmony_ci  mov(kRootRegister, Operand(isolate_root));
20951cb0ef41Sopenharmony_ci}
20961cb0ef41Sopenharmony_ci
20971cb0ef41Sopenharmony_civoid MacroAssembler::SmiTag(Register reg, SBit s) {
20981cb0ef41Sopenharmony_ci  add(reg, reg, Operand(reg), s);
20991cb0ef41Sopenharmony_ci}
21001cb0ef41Sopenharmony_ci
21011cb0ef41Sopenharmony_civoid MacroAssembler::SmiTag(Register dst, Register src, SBit s) {
21021cb0ef41Sopenharmony_ci  add(dst, src, Operand(src), s);
21031cb0ef41Sopenharmony_ci}
21041cb0ef41Sopenharmony_ci
21051cb0ef41Sopenharmony_civoid MacroAssembler::SmiTst(Register value) {
21061cb0ef41Sopenharmony_ci  tst(value, Operand(kSmiTagMask));
21071cb0ef41Sopenharmony_ci}
21081cb0ef41Sopenharmony_ci
21091cb0ef41Sopenharmony_civoid TurboAssembler::JumpIfSmi(Register value, Label* smi_label) {
21101cb0ef41Sopenharmony_ci  tst(value, Operand(kSmiTagMask));
21111cb0ef41Sopenharmony_ci  b(eq, smi_label);
21121cb0ef41Sopenharmony_ci}
21131cb0ef41Sopenharmony_ci
21141cb0ef41Sopenharmony_civoid TurboAssembler::JumpIfEqual(Register x, int32_t y, Label* dest) {
21151cb0ef41Sopenharmony_ci  cmp(x, Operand(y));
21161cb0ef41Sopenharmony_ci  b(eq, dest);
21171cb0ef41Sopenharmony_ci}
21181cb0ef41Sopenharmony_ci
21191cb0ef41Sopenharmony_civoid TurboAssembler::JumpIfLessThan(Register x, int32_t y, Label* dest) {
21201cb0ef41Sopenharmony_ci  cmp(x, Operand(y));
21211cb0ef41Sopenharmony_ci  b(lt, dest);
21221cb0ef41Sopenharmony_ci}
21231cb0ef41Sopenharmony_ci
21241cb0ef41Sopenharmony_civoid MacroAssembler::JumpIfNotSmi(Register value, Label* not_smi_label) {
21251cb0ef41Sopenharmony_ci  tst(value, Operand(kSmiTagMask));
21261cb0ef41Sopenharmony_ci  b(ne, not_smi_label);
21271cb0ef41Sopenharmony_ci}
21281cb0ef41Sopenharmony_ci
21291cb0ef41Sopenharmony_civoid MacroAssembler::AssertNotSmi(Register object) {
21301cb0ef41Sopenharmony_ci  if (!FLAG_debug_code) return;
21311cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
21321cb0ef41Sopenharmony_ci  STATIC_ASSERT(kSmiTag == 0);
21331cb0ef41Sopenharmony_ci  tst(object, Operand(kSmiTagMask));
21341cb0ef41Sopenharmony_ci  Check(ne, AbortReason::kOperandIsASmi);
21351cb0ef41Sopenharmony_ci}
21361cb0ef41Sopenharmony_ci
21371cb0ef41Sopenharmony_civoid MacroAssembler::AssertSmi(Register object) {
21381cb0ef41Sopenharmony_ci  if (!FLAG_debug_code) return;
21391cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
21401cb0ef41Sopenharmony_ci  STATIC_ASSERT(kSmiTag == 0);
21411cb0ef41Sopenharmony_ci  tst(object, Operand(kSmiTagMask));
21421cb0ef41Sopenharmony_ci  Check(eq, AbortReason::kOperandIsNotASmi);
21431cb0ef41Sopenharmony_ci}
21441cb0ef41Sopenharmony_ci
21451cb0ef41Sopenharmony_civoid MacroAssembler::AssertConstructor(Register object) {
21461cb0ef41Sopenharmony_ci  if (!FLAG_debug_code) return;
21471cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
21481cb0ef41Sopenharmony_ci  STATIC_ASSERT(kSmiTag == 0);
21491cb0ef41Sopenharmony_ci  tst(object, Operand(kSmiTagMask));
21501cb0ef41Sopenharmony_ci  Check(ne, AbortReason::kOperandIsASmiAndNotAConstructor);
21511cb0ef41Sopenharmony_ci  push(object);
21521cb0ef41Sopenharmony_ci  LoadMap(object, object);
21531cb0ef41Sopenharmony_ci  ldrb(object, FieldMemOperand(object, Map::kBitFieldOffset));
21541cb0ef41Sopenharmony_ci  tst(object, Operand(Map::Bits1::IsConstructorBit::kMask));
21551cb0ef41Sopenharmony_ci  pop(object);
21561cb0ef41Sopenharmony_ci  Check(ne, AbortReason::kOperandIsNotAConstructor);
21571cb0ef41Sopenharmony_ci}
21581cb0ef41Sopenharmony_ci
21591cb0ef41Sopenharmony_civoid MacroAssembler::AssertFunction(Register object) {
21601cb0ef41Sopenharmony_ci  if (!FLAG_debug_code) return;
21611cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
21621cb0ef41Sopenharmony_ci  STATIC_ASSERT(kSmiTag == 0);
21631cb0ef41Sopenharmony_ci  tst(object, Operand(kSmiTagMask));
21641cb0ef41Sopenharmony_ci  Check(ne, AbortReason::kOperandIsASmiAndNotAFunction);
21651cb0ef41Sopenharmony_ci  push(object);
21661cb0ef41Sopenharmony_ci  LoadMap(object, object);
21671cb0ef41Sopenharmony_ci  CompareInstanceTypeRange(object, object, FIRST_JS_FUNCTION_TYPE,
21681cb0ef41Sopenharmony_ci                           LAST_JS_FUNCTION_TYPE);
21691cb0ef41Sopenharmony_ci  pop(object);
21701cb0ef41Sopenharmony_ci  Check(ls, AbortReason::kOperandIsNotAFunction);
21711cb0ef41Sopenharmony_ci}
21721cb0ef41Sopenharmony_ci
21731cb0ef41Sopenharmony_civoid MacroAssembler::AssertCallableFunction(Register object) {
21741cb0ef41Sopenharmony_ci  if (!FLAG_debug_code) return;
21751cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
21761cb0ef41Sopenharmony_ci  STATIC_ASSERT(kSmiTag == 0);
21771cb0ef41Sopenharmony_ci  tst(object, Operand(kSmiTagMask));
21781cb0ef41Sopenharmony_ci  Check(ne, AbortReason::kOperandIsASmiAndNotAFunction);
21791cb0ef41Sopenharmony_ci  push(object);
21801cb0ef41Sopenharmony_ci  LoadMap(object, object);
21811cb0ef41Sopenharmony_ci  CompareInstanceTypeRange(object, object, FIRST_CALLABLE_JS_FUNCTION_TYPE,
21821cb0ef41Sopenharmony_ci                           LAST_CALLABLE_JS_FUNCTION_TYPE);
21831cb0ef41Sopenharmony_ci  pop(object);
21841cb0ef41Sopenharmony_ci  Check(ls, AbortReason::kOperandIsNotACallableFunction);
21851cb0ef41Sopenharmony_ci}
21861cb0ef41Sopenharmony_ci
21871cb0ef41Sopenharmony_civoid MacroAssembler::AssertBoundFunction(Register object) {
21881cb0ef41Sopenharmony_ci  if (!FLAG_debug_code) return;
21891cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
21901cb0ef41Sopenharmony_ci  STATIC_ASSERT(kSmiTag == 0);
21911cb0ef41Sopenharmony_ci  tst(object, Operand(kSmiTagMask));
21921cb0ef41Sopenharmony_ci  Check(ne, AbortReason::kOperandIsASmiAndNotABoundFunction);
21931cb0ef41Sopenharmony_ci  push(object);
21941cb0ef41Sopenharmony_ci  CompareObjectType(object, object, object, JS_BOUND_FUNCTION_TYPE);
21951cb0ef41Sopenharmony_ci  pop(object);
21961cb0ef41Sopenharmony_ci  Check(eq, AbortReason::kOperandIsNotABoundFunction);
21971cb0ef41Sopenharmony_ci}
21981cb0ef41Sopenharmony_ci
21991cb0ef41Sopenharmony_civoid MacroAssembler::AssertGeneratorObject(Register object) {
22001cb0ef41Sopenharmony_ci  if (!FLAG_debug_code) return;
22011cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
22021cb0ef41Sopenharmony_ci  tst(object, Operand(kSmiTagMask));
22031cb0ef41Sopenharmony_ci  Check(ne, AbortReason::kOperandIsASmiAndNotAGeneratorObject);
22041cb0ef41Sopenharmony_ci
22051cb0ef41Sopenharmony_ci  // Load map
22061cb0ef41Sopenharmony_ci  Register map = object;
22071cb0ef41Sopenharmony_ci  push(object);
22081cb0ef41Sopenharmony_ci  LoadMap(map, object);
22091cb0ef41Sopenharmony_ci
22101cb0ef41Sopenharmony_ci  // Check if JSGeneratorObject
22111cb0ef41Sopenharmony_ci  Label do_check;
22121cb0ef41Sopenharmony_ci  Register instance_type = object;
22131cb0ef41Sopenharmony_ci  CompareInstanceType(map, instance_type, JS_GENERATOR_OBJECT_TYPE);
22141cb0ef41Sopenharmony_ci  b(eq, &do_check);
22151cb0ef41Sopenharmony_ci
22161cb0ef41Sopenharmony_ci  // Check if JSAsyncFunctionObject (See MacroAssembler::CompareInstanceType)
22171cb0ef41Sopenharmony_ci  cmp(instance_type, Operand(JS_ASYNC_FUNCTION_OBJECT_TYPE));
22181cb0ef41Sopenharmony_ci  b(eq, &do_check);
22191cb0ef41Sopenharmony_ci
22201cb0ef41Sopenharmony_ci  // Check if JSAsyncGeneratorObject (See MacroAssembler::CompareInstanceType)
22211cb0ef41Sopenharmony_ci  cmp(instance_type, Operand(JS_ASYNC_GENERATOR_OBJECT_TYPE));
22221cb0ef41Sopenharmony_ci
22231cb0ef41Sopenharmony_ci  bind(&do_check);
22241cb0ef41Sopenharmony_ci  // Restore generator object to register and perform assertion
22251cb0ef41Sopenharmony_ci  pop(object);
22261cb0ef41Sopenharmony_ci  Check(eq, AbortReason::kOperandIsNotAGeneratorObject);
22271cb0ef41Sopenharmony_ci}
22281cb0ef41Sopenharmony_ci
22291cb0ef41Sopenharmony_civoid MacroAssembler::AssertUndefinedOrAllocationSite(Register object,
22301cb0ef41Sopenharmony_ci                                                     Register scratch) {
22311cb0ef41Sopenharmony_ci  if (!FLAG_debug_code) return;
22321cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
22331cb0ef41Sopenharmony_ci  Label done_checking;
22341cb0ef41Sopenharmony_ci  AssertNotSmi(object);
22351cb0ef41Sopenharmony_ci  CompareRoot(object, RootIndex::kUndefinedValue);
22361cb0ef41Sopenharmony_ci  b(eq, &done_checking);
22371cb0ef41Sopenharmony_ci  LoadMap(scratch, object);
22381cb0ef41Sopenharmony_ci  CompareInstanceType(scratch, scratch, ALLOCATION_SITE_TYPE);
22391cb0ef41Sopenharmony_ci  Assert(eq, AbortReason::kExpectedUndefinedOrCell);
22401cb0ef41Sopenharmony_ci  bind(&done_checking);
22411cb0ef41Sopenharmony_ci}
22421cb0ef41Sopenharmony_ci
22431cb0ef41Sopenharmony_civoid TurboAssembler::CheckFor32DRegs(Register scratch) {
22441cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
22451cb0ef41Sopenharmony_ci  Move(scratch, ExternalReference::cpu_features());
22461cb0ef41Sopenharmony_ci  ldr(scratch, MemOperand(scratch));
22471cb0ef41Sopenharmony_ci  tst(scratch, Operand(1u << VFP32DREGS));
22481cb0ef41Sopenharmony_ci}
22491cb0ef41Sopenharmony_ci
22501cb0ef41Sopenharmony_civoid TurboAssembler::SaveFPRegs(Register location, Register scratch) {
22511cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
22521cb0ef41Sopenharmony_ci  CpuFeatureScope scope(this, VFP32DREGS, CpuFeatureScope::kDontCheckSupported);
22531cb0ef41Sopenharmony_ci  CheckFor32DRegs(scratch);
22541cb0ef41Sopenharmony_ci  vstm(db_w, location, d16, d31, ne);
22551cb0ef41Sopenharmony_ci  sub(location, location, Operand(16 * kDoubleSize), LeaveCC, eq);
22561cb0ef41Sopenharmony_ci  vstm(db_w, location, d0, d15);
22571cb0ef41Sopenharmony_ci}
22581cb0ef41Sopenharmony_ci
22591cb0ef41Sopenharmony_civoid TurboAssembler::RestoreFPRegs(Register location, Register scratch) {
22601cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
22611cb0ef41Sopenharmony_ci  CpuFeatureScope scope(this, VFP32DREGS, CpuFeatureScope::kDontCheckSupported);
22621cb0ef41Sopenharmony_ci  CheckFor32DRegs(scratch);
22631cb0ef41Sopenharmony_ci  vldm(ia_w, location, d0, d15);
22641cb0ef41Sopenharmony_ci  vldm(ia_w, location, d16, d31, ne);
22651cb0ef41Sopenharmony_ci  add(location, location, Operand(16 * kDoubleSize), LeaveCC, eq);
22661cb0ef41Sopenharmony_ci}
22671cb0ef41Sopenharmony_ci
22681cb0ef41Sopenharmony_civoid TurboAssembler::SaveFPRegsToHeap(Register location, Register scratch) {
22691cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
22701cb0ef41Sopenharmony_ci  CpuFeatureScope scope(this, VFP32DREGS, CpuFeatureScope::kDontCheckSupported);
22711cb0ef41Sopenharmony_ci  CheckFor32DRegs(scratch);
22721cb0ef41Sopenharmony_ci  vstm(ia_w, location, d0, d15);
22731cb0ef41Sopenharmony_ci  vstm(ia_w, location, d16, d31, ne);
22741cb0ef41Sopenharmony_ci  add(location, location, Operand(16 * kDoubleSize), LeaveCC, eq);
22751cb0ef41Sopenharmony_ci}
22761cb0ef41Sopenharmony_ci
22771cb0ef41Sopenharmony_civoid TurboAssembler::RestoreFPRegsFromHeap(Register location,
22781cb0ef41Sopenharmony_ci                                           Register scratch) {
22791cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
22801cb0ef41Sopenharmony_ci  CpuFeatureScope scope(this, VFP32DREGS, CpuFeatureScope::kDontCheckSupported);
22811cb0ef41Sopenharmony_ci  CheckFor32DRegs(scratch);
22821cb0ef41Sopenharmony_ci  vldm(ia_w, location, d0, d15);
22831cb0ef41Sopenharmony_ci  vldm(ia_w, location, d16, d31, ne);
22841cb0ef41Sopenharmony_ci  add(location, location, Operand(16 * kDoubleSize), LeaveCC, eq);
22851cb0ef41Sopenharmony_ci}
22861cb0ef41Sopenharmony_ci
22871cb0ef41Sopenharmony_citemplate <typename T>
22881cb0ef41Sopenharmony_civoid TurboAssembler::FloatMaxHelper(T result, T left, T right,
22891cb0ef41Sopenharmony_ci                                    Label* out_of_line) {
22901cb0ef41Sopenharmony_ci  // This trivial case is caught sooner, so that the out-of-line code can be
22911cb0ef41Sopenharmony_ci  // completely avoided.
22921cb0ef41Sopenharmony_ci  DCHECK(left != right);
22931cb0ef41Sopenharmony_ci
22941cb0ef41Sopenharmony_ci  if (CpuFeatures::IsSupported(ARMv8)) {
22951cb0ef41Sopenharmony_ci    CpuFeatureScope scope(this, ARMv8);
22961cb0ef41Sopenharmony_ci    VFPCompareAndSetFlags(left, right);
22971cb0ef41Sopenharmony_ci    b(vs, out_of_line);
22981cb0ef41Sopenharmony_ci    vmaxnm(result, left, right);
22991cb0ef41Sopenharmony_ci  } else {
23001cb0ef41Sopenharmony_ci    Label done;
23011cb0ef41Sopenharmony_ci    VFPCompareAndSetFlags(left, right);
23021cb0ef41Sopenharmony_ci    b(vs, out_of_line);
23031cb0ef41Sopenharmony_ci    // Avoid a conditional instruction if the result register is unique.
23041cb0ef41Sopenharmony_ci    bool aliased_result_reg = result == left || result == right;
23051cb0ef41Sopenharmony_ci    Move(result, right, aliased_result_reg ? mi : al);
23061cb0ef41Sopenharmony_ci    Move(result, left, gt);
23071cb0ef41Sopenharmony_ci    b(ne, &done);
23081cb0ef41Sopenharmony_ci    // Left and right are equal, but check for +/-0.
23091cb0ef41Sopenharmony_ci    VFPCompareAndSetFlags(left, 0.0);
23101cb0ef41Sopenharmony_ci    b(eq, out_of_line);
23111cb0ef41Sopenharmony_ci    // The arguments are equal and not zero, so it doesn't matter which input we
23121cb0ef41Sopenharmony_ci    // pick. We have already moved one input into the result (if it didn't
23131cb0ef41Sopenharmony_ci    // already alias) so there's nothing more to do.
23141cb0ef41Sopenharmony_ci    bind(&done);
23151cb0ef41Sopenharmony_ci  }
23161cb0ef41Sopenharmony_ci}
23171cb0ef41Sopenharmony_ci
23181cb0ef41Sopenharmony_citemplate <typename T>
23191cb0ef41Sopenharmony_civoid TurboAssembler::FloatMaxOutOfLineHelper(T result, T left, T right) {
23201cb0ef41Sopenharmony_ci  DCHECK(left != right);
23211cb0ef41Sopenharmony_ci
23221cb0ef41Sopenharmony_ci  // ARMv8: At least one of left and right is a NaN.
23231cb0ef41Sopenharmony_ci  // Anything else: At least one of left and right is a NaN, or both left and
23241cb0ef41Sopenharmony_ci  // right are zeroes with unknown sign.
23251cb0ef41Sopenharmony_ci
23261cb0ef41Sopenharmony_ci  // If left and right are +/-0, select the one with the most positive sign.
23271cb0ef41Sopenharmony_ci  // If left or right are NaN, vadd propagates the appropriate one.
23281cb0ef41Sopenharmony_ci  vadd(result, left, right);
23291cb0ef41Sopenharmony_ci}
23301cb0ef41Sopenharmony_ci
23311cb0ef41Sopenharmony_citemplate <typename T>
23321cb0ef41Sopenharmony_civoid TurboAssembler::FloatMinHelper(T result, T left, T right,
23331cb0ef41Sopenharmony_ci                                    Label* out_of_line) {
23341cb0ef41Sopenharmony_ci  // This trivial case is caught sooner, so that the out-of-line code can be
23351cb0ef41Sopenharmony_ci  // completely avoided.
23361cb0ef41Sopenharmony_ci  DCHECK(left != right);
23371cb0ef41Sopenharmony_ci
23381cb0ef41Sopenharmony_ci  if (CpuFeatures::IsSupported(ARMv8)) {
23391cb0ef41Sopenharmony_ci    CpuFeatureScope scope(this, ARMv8);
23401cb0ef41Sopenharmony_ci    VFPCompareAndSetFlags(left, right);
23411cb0ef41Sopenharmony_ci    b(vs, out_of_line);
23421cb0ef41Sopenharmony_ci    vminnm(result, left, right);
23431cb0ef41Sopenharmony_ci  } else {
23441cb0ef41Sopenharmony_ci    Label done;
23451cb0ef41Sopenharmony_ci    VFPCompareAndSetFlags(left, right);
23461cb0ef41Sopenharmony_ci    b(vs, out_of_line);
23471cb0ef41Sopenharmony_ci    // Avoid a conditional instruction if the result register is unique.
23481cb0ef41Sopenharmony_ci    bool aliased_result_reg = result == left || result == right;
23491cb0ef41Sopenharmony_ci    Move(result, left, aliased_result_reg ? mi : al);
23501cb0ef41Sopenharmony_ci    Move(result, right, gt);
23511cb0ef41Sopenharmony_ci    b(ne, &done);
23521cb0ef41Sopenharmony_ci    // Left and right are equal, but check for +/-0.
23531cb0ef41Sopenharmony_ci    VFPCompareAndSetFlags(left, 0.0);
23541cb0ef41Sopenharmony_ci    // If the arguments are equal and not zero, it doesn't matter which input we
23551cb0ef41Sopenharmony_ci    // pick. We have already moved one input into the result (if it didn't
23561cb0ef41Sopenharmony_ci    // already alias) so there's nothing more to do.
23571cb0ef41Sopenharmony_ci    b(ne, &done);
23581cb0ef41Sopenharmony_ci    // At this point, both left and right are either 0 or -0.
23591cb0ef41Sopenharmony_ci    // We could use a single 'vorr' instruction here if we had NEON support.
23601cb0ef41Sopenharmony_ci    // The algorithm used is -((-L) + (-R)), which is most efficiently expressed
23611cb0ef41Sopenharmony_ci    // as -((-L) - R).
23621cb0ef41Sopenharmony_ci    if (left == result) {
23631cb0ef41Sopenharmony_ci      DCHECK(right != result);
23641cb0ef41Sopenharmony_ci      vneg(result, left);
23651cb0ef41Sopenharmony_ci      vsub(result, result, right);
23661cb0ef41Sopenharmony_ci      vneg(result, result);
23671cb0ef41Sopenharmony_ci    } else {
23681cb0ef41Sopenharmony_ci      DCHECK(left != result);
23691cb0ef41Sopenharmony_ci      vneg(result, right);
23701cb0ef41Sopenharmony_ci      vsub(result, result, left);
23711cb0ef41Sopenharmony_ci      vneg(result, result);
23721cb0ef41Sopenharmony_ci    }
23731cb0ef41Sopenharmony_ci    bind(&done);
23741cb0ef41Sopenharmony_ci  }
23751cb0ef41Sopenharmony_ci}
23761cb0ef41Sopenharmony_ci
23771cb0ef41Sopenharmony_citemplate <typename T>
23781cb0ef41Sopenharmony_civoid TurboAssembler::FloatMinOutOfLineHelper(T result, T left, T right) {
23791cb0ef41Sopenharmony_ci  DCHECK(left != right);
23801cb0ef41Sopenharmony_ci
23811cb0ef41Sopenharmony_ci  // At least one of left and right is a NaN. Use vadd to propagate the NaN
23821cb0ef41Sopenharmony_ci  // appropriately. +/-0 is handled inline.
23831cb0ef41Sopenharmony_ci  vadd(result, left, right);
23841cb0ef41Sopenharmony_ci}
23851cb0ef41Sopenharmony_ci
23861cb0ef41Sopenharmony_civoid TurboAssembler::FloatMax(SwVfpRegister result, SwVfpRegister left,
23871cb0ef41Sopenharmony_ci                              SwVfpRegister right, Label* out_of_line) {
23881cb0ef41Sopenharmony_ci  FloatMaxHelper(result, left, right, out_of_line);
23891cb0ef41Sopenharmony_ci}
23901cb0ef41Sopenharmony_ci
23911cb0ef41Sopenharmony_civoid TurboAssembler::FloatMin(SwVfpRegister result, SwVfpRegister left,
23921cb0ef41Sopenharmony_ci                              SwVfpRegister right, Label* out_of_line) {
23931cb0ef41Sopenharmony_ci  FloatMinHelper(result, left, right, out_of_line);
23941cb0ef41Sopenharmony_ci}
23951cb0ef41Sopenharmony_ci
23961cb0ef41Sopenharmony_civoid TurboAssembler::FloatMax(DwVfpRegister result, DwVfpRegister left,
23971cb0ef41Sopenharmony_ci                              DwVfpRegister right, Label* out_of_line) {
23981cb0ef41Sopenharmony_ci  FloatMaxHelper(result, left, right, out_of_line);
23991cb0ef41Sopenharmony_ci}
24001cb0ef41Sopenharmony_ci
24011cb0ef41Sopenharmony_civoid TurboAssembler::FloatMin(DwVfpRegister result, DwVfpRegister left,
24021cb0ef41Sopenharmony_ci                              DwVfpRegister right, Label* out_of_line) {
24031cb0ef41Sopenharmony_ci  FloatMinHelper(result, left, right, out_of_line);
24041cb0ef41Sopenharmony_ci}
24051cb0ef41Sopenharmony_ci
24061cb0ef41Sopenharmony_civoid TurboAssembler::FloatMaxOutOfLine(SwVfpRegister result, SwVfpRegister left,
24071cb0ef41Sopenharmony_ci                                       SwVfpRegister right) {
24081cb0ef41Sopenharmony_ci  FloatMaxOutOfLineHelper(result, left, right);
24091cb0ef41Sopenharmony_ci}
24101cb0ef41Sopenharmony_ci
24111cb0ef41Sopenharmony_civoid TurboAssembler::FloatMinOutOfLine(SwVfpRegister result, SwVfpRegister left,
24121cb0ef41Sopenharmony_ci                                       SwVfpRegister right) {
24131cb0ef41Sopenharmony_ci  FloatMinOutOfLineHelper(result, left, right);
24141cb0ef41Sopenharmony_ci}
24151cb0ef41Sopenharmony_ci
24161cb0ef41Sopenharmony_civoid TurboAssembler::FloatMaxOutOfLine(DwVfpRegister result, DwVfpRegister left,
24171cb0ef41Sopenharmony_ci                                       DwVfpRegister right) {
24181cb0ef41Sopenharmony_ci  FloatMaxOutOfLineHelper(result, left, right);
24191cb0ef41Sopenharmony_ci}
24201cb0ef41Sopenharmony_ci
24211cb0ef41Sopenharmony_civoid TurboAssembler::FloatMinOutOfLine(DwVfpRegister result, DwVfpRegister left,
24221cb0ef41Sopenharmony_ci                                       DwVfpRegister right) {
24231cb0ef41Sopenharmony_ci  FloatMinOutOfLineHelper(result, left, right);
24241cb0ef41Sopenharmony_ci}
24251cb0ef41Sopenharmony_ci
24261cb0ef41Sopenharmony_cistatic const int kRegisterPassedArguments = 4;
24271cb0ef41Sopenharmony_ci// The hardfloat calling convention passes double arguments in registers d0-d7.
24281cb0ef41Sopenharmony_cistatic const int kDoubleRegisterPassedArguments = 8;
24291cb0ef41Sopenharmony_ci
24301cb0ef41Sopenharmony_ciint TurboAssembler::CalculateStackPassedWords(int num_reg_arguments,
24311cb0ef41Sopenharmony_ci                                              int num_double_arguments) {
24321cb0ef41Sopenharmony_ci  int stack_passed_words = 0;
24331cb0ef41Sopenharmony_ci  if (use_eabi_hardfloat()) {
24341cb0ef41Sopenharmony_ci    // In the hard floating point calling convention, we can use the first 8
24351cb0ef41Sopenharmony_ci    // registers to pass doubles.
24361cb0ef41Sopenharmony_ci    if (num_double_arguments > kDoubleRegisterPassedArguments) {
24371cb0ef41Sopenharmony_ci      stack_passed_words +=
24381cb0ef41Sopenharmony_ci          2 * (num_double_arguments - kDoubleRegisterPassedArguments);
24391cb0ef41Sopenharmony_ci    }
24401cb0ef41Sopenharmony_ci  } else {
24411cb0ef41Sopenharmony_ci    // In the soft floating point calling convention, every double
24421cb0ef41Sopenharmony_ci    // argument is passed using two registers.
24431cb0ef41Sopenharmony_ci    num_reg_arguments += 2 * num_double_arguments;
24441cb0ef41Sopenharmony_ci  }
24451cb0ef41Sopenharmony_ci  // Up to four simple arguments are passed in registers r0..r3.
24461cb0ef41Sopenharmony_ci  if (num_reg_arguments > kRegisterPassedArguments) {
24471cb0ef41Sopenharmony_ci    stack_passed_words += num_reg_arguments - kRegisterPassedArguments;
24481cb0ef41Sopenharmony_ci  }
24491cb0ef41Sopenharmony_ci  return stack_passed_words;
24501cb0ef41Sopenharmony_ci}
24511cb0ef41Sopenharmony_ci
24521cb0ef41Sopenharmony_civoid TurboAssembler::PrepareCallCFunction(int num_reg_arguments,
24531cb0ef41Sopenharmony_ci                                          int num_double_arguments,
24541cb0ef41Sopenharmony_ci                                          Register scratch) {
24551cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
24561cb0ef41Sopenharmony_ci  int frame_alignment = ActivationFrameAlignment();
24571cb0ef41Sopenharmony_ci  int stack_passed_arguments =
24581cb0ef41Sopenharmony_ci      CalculateStackPassedWords(num_reg_arguments, num_double_arguments);
24591cb0ef41Sopenharmony_ci  if (frame_alignment > kPointerSize) {
24601cb0ef41Sopenharmony_ci    UseScratchRegisterScope temps(this);
24611cb0ef41Sopenharmony_ci    if (!scratch.is_valid()) scratch = temps.Acquire();
24621cb0ef41Sopenharmony_ci    // Make stack end at alignment and make room for num_arguments - 4 words
24631cb0ef41Sopenharmony_ci    // and the original value of sp.
24641cb0ef41Sopenharmony_ci    mov(scratch, sp);
24651cb0ef41Sopenharmony_ci    AllocateStackSpace((stack_passed_arguments + 1) * kPointerSize);
24661cb0ef41Sopenharmony_ci    DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
24671cb0ef41Sopenharmony_ci    and_(sp, sp, Operand(-frame_alignment));
24681cb0ef41Sopenharmony_ci    str(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize));
24691cb0ef41Sopenharmony_ci  } else if (stack_passed_arguments > 0) {
24701cb0ef41Sopenharmony_ci    AllocateStackSpace(stack_passed_arguments * kPointerSize);
24711cb0ef41Sopenharmony_ci  }
24721cb0ef41Sopenharmony_ci}
24731cb0ef41Sopenharmony_ci
24741cb0ef41Sopenharmony_civoid TurboAssembler::MovToFloatParameter(DwVfpRegister src) {
24751cb0ef41Sopenharmony_ci  DCHECK(src == d0);
24761cb0ef41Sopenharmony_ci  if (!use_eabi_hardfloat()) {
24771cb0ef41Sopenharmony_ci    vmov(r0, r1, src);
24781cb0ef41Sopenharmony_ci  }
24791cb0ef41Sopenharmony_ci}
24801cb0ef41Sopenharmony_ci
24811cb0ef41Sopenharmony_ci// On ARM this is just a synonym to make the purpose clear.
24821cb0ef41Sopenharmony_civoid TurboAssembler::MovToFloatResult(DwVfpRegister src) {
24831cb0ef41Sopenharmony_ci  MovToFloatParameter(src);
24841cb0ef41Sopenharmony_ci}
24851cb0ef41Sopenharmony_ci
24861cb0ef41Sopenharmony_civoid TurboAssembler::MovToFloatParameters(DwVfpRegister src1,
24871cb0ef41Sopenharmony_ci                                          DwVfpRegister src2) {
24881cb0ef41Sopenharmony_ci  DCHECK(src1 == d0);
24891cb0ef41Sopenharmony_ci  DCHECK(src2 == d1);
24901cb0ef41Sopenharmony_ci  if (!use_eabi_hardfloat()) {
24911cb0ef41Sopenharmony_ci    vmov(r0, r1, src1);
24921cb0ef41Sopenharmony_ci    vmov(r2, r3, src2);
24931cb0ef41Sopenharmony_ci  }
24941cb0ef41Sopenharmony_ci}
24951cb0ef41Sopenharmony_ci
24961cb0ef41Sopenharmony_civoid TurboAssembler::CallCFunction(ExternalReference function,
24971cb0ef41Sopenharmony_ci                                   int num_reg_arguments,
24981cb0ef41Sopenharmony_ci                                   int num_double_arguments) {
24991cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
25001cb0ef41Sopenharmony_ci  Register scratch = temps.Acquire();
25011cb0ef41Sopenharmony_ci  Move(scratch, function);
25021cb0ef41Sopenharmony_ci  CallCFunctionHelper(scratch, num_reg_arguments, num_double_arguments);
25031cb0ef41Sopenharmony_ci}
25041cb0ef41Sopenharmony_ci
25051cb0ef41Sopenharmony_civoid TurboAssembler::CallCFunction(Register function, int num_reg_arguments,
25061cb0ef41Sopenharmony_ci                                   int num_double_arguments) {
25071cb0ef41Sopenharmony_ci  CallCFunctionHelper(function, num_reg_arguments, num_double_arguments);
25081cb0ef41Sopenharmony_ci}
25091cb0ef41Sopenharmony_ci
25101cb0ef41Sopenharmony_civoid TurboAssembler::CallCFunction(ExternalReference function,
25111cb0ef41Sopenharmony_ci                                   int num_arguments) {
25121cb0ef41Sopenharmony_ci  CallCFunction(function, num_arguments, 0);
25131cb0ef41Sopenharmony_ci}
25141cb0ef41Sopenharmony_ci
25151cb0ef41Sopenharmony_civoid TurboAssembler::CallCFunction(Register function, int num_arguments) {
25161cb0ef41Sopenharmony_ci  CallCFunction(function, num_arguments, 0);
25171cb0ef41Sopenharmony_ci}
25181cb0ef41Sopenharmony_ci
25191cb0ef41Sopenharmony_civoid TurboAssembler::CallCFunctionHelper(Register function,
25201cb0ef41Sopenharmony_ci                                         int num_reg_arguments,
25211cb0ef41Sopenharmony_ci                                         int num_double_arguments) {
25221cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
25231cb0ef41Sopenharmony_ci  DCHECK_LE(num_reg_arguments + num_double_arguments, kMaxCParameters);
25241cb0ef41Sopenharmony_ci  DCHECK(has_frame());
25251cb0ef41Sopenharmony_ci  // Make sure that the stack is aligned before calling a C function unless
25261cb0ef41Sopenharmony_ci  // running in the simulator. The simulator has its own alignment check which
25271cb0ef41Sopenharmony_ci  // provides more information.
25281cb0ef41Sopenharmony_ci#if V8_HOST_ARCH_ARM
25291cb0ef41Sopenharmony_ci  if (FLAG_debug_code) {
25301cb0ef41Sopenharmony_ci    int frame_alignment = base::OS::ActivationFrameAlignment();
25311cb0ef41Sopenharmony_ci    int frame_alignment_mask = frame_alignment - 1;
25321cb0ef41Sopenharmony_ci    if (frame_alignment > kPointerSize) {
25331cb0ef41Sopenharmony_ci      ASM_CODE_COMMENT_STRING(this, "Check stack alignment");
25341cb0ef41Sopenharmony_ci      DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
25351cb0ef41Sopenharmony_ci      Label alignment_as_expected;
25361cb0ef41Sopenharmony_ci      tst(sp, Operand(frame_alignment_mask));
25371cb0ef41Sopenharmony_ci      b(eq, &alignment_as_expected);
25381cb0ef41Sopenharmony_ci      // Don't use Check here, as it will call Runtime_Abort possibly
25391cb0ef41Sopenharmony_ci      // re-entering here.
25401cb0ef41Sopenharmony_ci      stop();
25411cb0ef41Sopenharmony_ci      bind(&alignment_as_expected);
25421cb0ef41Sopenharmony_ci    }
25431cb0ef41Sopenharmony_ci  }
25441cb0ef41Sopenharmony_ci#endif
25451cb0ef41Sopenharmony_ci
25461cb0ef41Sopenharmony_ci  // Save the frame pointer and PC so that the stack layout remains iterable,
25471cb0ef41Sopenharmony_ci  // even without an ExitFrame which normally exists between JS and C frames.
25481cb0ef41Sopenharmony_ci  Register addr_scratch = r4;
25491cb0ef41Sopenharmony_ci  // See x64 code for reasoning about how to address the isolate data fields.
25501cb0ef41Sopenharmony_ci  if (root_array_available()) {
25511cb0ef41Sopenharmony_ci    str(pc,
25521cb0ef41Sopenharmony_ci        MemOperand(kRootRegister, IsolateData::fast_c_call_caller_pc_offset()));
25531cb0ef41Sopenharmony_ci    str(fp,
25541cb0ef41Sopenharmony_ci        MemOperand(kRootRegister, IsolateData::fast_c_call_caller_fp_offset()));
25551cb0ef41Sopenharmony_ci  } else {
25561cb0ef41Sopenharmony_ci    DCHECK_NOT_NULL(isolate());
25571cb0ef41Sopenharmony_ci    Push(addr_scratch);
25581cb0ef41Sopenharmony_ci
25591cb0ef41Sopenharmony_ci    Move(addr_scratch,
25601cb0ef41Sopenharmony_ci         ExternalReference::fast_c_call_caller_pc_address(isolate()));
25611cb0ef41Sopenharmony_ci    str(pc, MemOperand(addr_scratch));
25621cb0ef41Sopenharmony_ci    Move(addr_scratch,
25631cb0ef41Sopenharmony_ci         ExternalReference::fast_c_call_caller_fp_address(isolate()));
25641cb0ef41Sopenharmony_ci    str(fp, MemOperand(addr_scratch));
25651cb0ef41Sopenharmony_ci
25661cb0ef41Sopenharmony_ci    Pop(addr_scratch);
25671cb0ef41Sopenharmony_ci  }
25681cb0ef41Sopenharmony_ci
25691cb0ef41Sopenharmony_ci  // Just call directly. The function called cannot cause a GC, or
25701cb0ef41Sopenharmony_ci  // allow preemption, so the return address in the link register
25711cb0ef41Sopenharmony_ci  // stays correct.
25721cb0ef41Sopenharmony_ci  Call(function);
25731cb0ef41Sopenharmony_ci
25741cb0ef41Sopenharmony_ci  // We don't unset the PC; the FP is the source of truth.
25751cb0ef41Sopenharmony_ci  Register zero_scratch = r5;
25761cb0ef41Sopenharmony_ci  Push(zero_scratch);
25771cb0ef41Sopenharmony_ci  mov(zero_scratch, Operand::Zero());
25781cb0ef41Sopenharmony_ci
25791cb0ef41Sopenharmony_ci  if (root_array_available()) {
25801cb0ef41Sopenharmony_ci    str(zero_scratch,
25811cb0ef41Sopenharmony_ci        MemOperand(kRootRegister, IsolateData::fast_c_call_caller_fp_offset()));
25821cb0ef41Sopenharmony_ci  } else {
25831cb0ef41Sopenharmony_ci    DCHECK_NOT_NULL(isolate());
25841cb0ef41Sopenharmony_ci    Push(addr_scratch);
25851cb0ef41Sopenharmony_ci    Move(addr_scratch,
25861cb0ef41Sopenharmony_ci         ExternalReference::fast_c_call_caller_fp_address(isolate()));
25871cb0ef41Sopenharmony_ci    str(zero_scratch, MemOperand(addr_scratch));
25881cb0ef41Sopenharmony_ci    Pop(addr_scratch);
25891cb0ef41Sopenharmony_ci  }
25901cb0ef41Sopenharmony_ci
25911cb0ef41Sopenharmony_ci  Pop(zero_scratch);
25921cb0ef41Sopenharmony_ci
25931cb0ef41Sopenharmony_ci  int stack_passed_arguments =
25941cb0ef41Sopenharmony_ci      CalculateStackPassedWords(num_reg_arguments, num_double_arguments);
25951cb0ef41Sopenharmony_ci  if (ActivationFrameAlignment() > kPointerSize) {
25961cb0ef41Sopenharmony_ci    ldr(sp, MemOperand(sp, stack_passed_arguments * kPointerSize));
25971cb0ef41Sopenharmony_ci  } else {
25981cb0ef41Sopenharmony_ci    add(sp, sp, Operand(stack_passed_arguments * kPointerSize));
25991cb0ef41Sopenharmony_ci  }
26001cb0ef41Sopenharmony_ci}
26011cb0ef41Sopenharmony_ci
26021cb0ef41Sopenharmony_civoid TurboAssembler::CheckPageFlag(Register object, int mask, Condition cc,
26031cb0ef41Sopenharmony_ci                                   Label* condition_met) {
26041cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
26051cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
26061cb0ef41Sopenharmony_ci  Register scratch = temps.Acquire();
26071cb0ef41Sopenharmony_ci  DCHECK(!AreAliased(object, scratch));
26081cb0ef41Sopenharmony_ci  DCHECK(cc == eq || cc == ne);
26091cb0ef41Sopenharmony_ci  Bfc(scratch, object, 0, kPageSizeBits);
26101cb0ef41Sopenharmony_ci  ldr(scratch, MemOperand(scratch, BasicMemoryChunk::kFlagsOffset));
26111cb0ef41Sopenharmony_ci  tst(scratch, Operand(mask));
26121cb0ef41Sopenharmony_ci  b(cc, condition_met);
26131cb0ef41Sopenharmony_ci}
26141cb0ef41Sopenharmony_ci
26151cb0ef41Sopenharmony_ciRegister GetRegisterThatIsNotOneOf(Register reg1, Register reg2, Register reg3,
26161cb0ef41Sopenharmony_ci                                   Register reg4, Register reg5,
26171cb0ef41Sopenharmony_ci                                   Register reg6) {
26181cb0ef41Sopenharmony_ci  RegList regs = {reg1, reg2, reg3, reg4, reg5, reg6};
26191cb0ef41Sopenharmony_ci
26201cb0ef41Sopenharmony_ci  const RegisterConfiguration* config = RegisterConfiguration::Default();
26211cb0ef41Sopenharmony_ci  for (int i = 0; i < config->num_allocatable_general_registers(); ++i) {
26221cb0ef41Sopenharmony_ci    int code = config->GetAllocatableGeneralCode(i);
26231cb0ef41Sopenharmony_ci    Register candidate = Register::from_code(code);
26241cb0ef41Sopenharmony_ci    if (regs.has(candidate)) continue;
26251cb0ef41Sopenharmony_ci    return candidate;
26261cb0ef41Sopenharmony_ci  }
26271cb0ef41Sopenharmony_ci  UNREACHABLE();
26281cb0ef41Sopenharmony_ci}
26291cb0ef41Sopenharmony_ci
26301cb0ef41Sopenharmony_civoid TurboAssembler::ComputeCodeStartAddress(Register dst) {
26311cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
26321cb0ef41Sopenharmony_ci  // We can use the register pc - 8 for the address of the current instruction.
26331cb0ef41Sopenharmony_ci  sub(dst, pc, Operand(pc_offset() + Instruction::kPcLoadDelta));
26341cb0ef41Sopenharmony_ci}
26351cb0ef41Sopenharmony_ci
26361cb0ef41Sopenharmony_civoid TurboAssembler::CallForDeoptimization(Builtin target, int, Label* exit,
26371cb0ef41Sopenharmony_ci                                           DeoptimizeKind kind, Label* ret,
26381cb0ef41Sopenharmony_ci                                           Label*) {
26391cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
26401cb0ef41Sopenharmony_ci
26411cb0ef41Sopenharmony_ci  // All constants should have been emitted prior to deoptimization exit
26421cb0ef41Sopenharmony_ci  // emission. See PrepareForDeoptimizationExits.
26431cb0ef41Sopenharmony_ci  DCHECK(!has_pending_constants());
26441cb0ef41Sopenharmony_ci  BlockConstPoolScope block_const_pool(this);
26451cb0ef41Sopenharmony_ci
26461cb0ef41Sopenharmony_ci  CHECK_LE(target, Builtins::kLastTier0);
26471cb0ef41Sopenharmony_ci  ldr(ip,
26481cb0ef41Sopenharmony_ci      MemOperand(kRootRegister, IsolateData::BuiltinEntrySlotOffset(target)));
26491cb0ef41Sopenharmony_ci  Call(ip);
26501cb0ef41Sopenharmony_ci  DCHECK_EQ(SizeOfCodeGeneratedSince(exit),
26511cb0ef41Sopenharmony_ci            (kind == DeoptimizeKind::kLazy) ? Deoptimizer::kLazyDeoptExitSize
26521cb0ef41Sopenharmony_ci                                            : Deoptimizer::kEagerDeoptExitSize);
26531cb0ef41Sopenharmony_ci
26541cb0ef41Sopenharmony_ci  // The above code must not emit constants either.
26551cb0ef41Sopenharmony_ci  DCHECK(!has_pending_constants());
26561cb0ef41Sopenharmony_ci}
26571cb0ef41Sopenharmony_ci
26581cb0ef41Sopenharmony_civoid TurboAssembler::Trap() { stop(); }
26591cb0ef41Sopenharmony_civoid TurboAssembler::DebugBreak() { stop(); }
26601cb0ef41Sopenharmony_ci
26611cb0ef41Sopenharmony_civoid TurboAssembler::I64x2BitMask(Register dst, QwNeonRegister src) {
26621cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
26631cb0ef41Sopenharmony_ci  QwNeonRegister tmp1 = temps.AcquireQ();
26641cb0ef41Sopenharmony_ci  Register tmp = temps.Acquire();
26651cb0ef41Sopenharmony_ci
26661cb0ef41Sopenharmony_ci  vshr(NeonU64, tmp1, src, 63);
26671cb0ef41Sopenharmony_ci  vmov(NeonU32, dst, tmp1.low(), 0);
26681cb0ef41Sopenharmony_ci  vmov(NeonU32, tmp, tmp1.high(), 0);
26691cb0ef41Sopenharmony_ci  add(dst, dst, Operand(tmp, LSL, 1));
26701cb0ef41Sopenharmony_ci}
26711cb0ef41Sopenharmony_ci
26721cb0ef41Sopenharmony_civoid TurboAssembler::I64x2Eq(QwNeonRegister dst, QwNeonRegister src1,
26731cb0ef41Sopenharmony_ci                             QwNeonRegister src2) {
26741cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
26751cb0ef41Sopenharmony_ci  Simd128Register scratch = temps.AcquireQ();
26761cb0ef41Sopenharmony_ci  vceq(Neon32, dst, src1, src2);
26771cb0ef41Sopenharmony_ci  vrev64(Neon32, scratch, dst);
26781cb0ef41Sopenharmony_ci  vand(dst, dst, scratch);
26791cb0ef41Sopenharmony_ci}
26801cb0ef41Sopenharmony_ci
26811cb0ef41Sopenharmony_civoid TurboAssembler::I64x2Ne(QwNeonRegister dst, QwNeonRegister src1,
26821cb0ef41Sopenharmony_ci                             QwNeonRegister src2) {
26831cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
26841cb0ef41Sopenharmony_ci  Simd128Register tmp = temps.AcquireQ();
26851cb0ef41Sopenharmony_ci  vceq(Neon32, dst, src1, src2);
26861cb0ef41Sopenharmony_ci  vrev64(Neon32, tmp, dst);
26871cb0ef41Sopenharmony_ci  vmvn(dst, dst);
26881cb0ef41Sopenharmony_ci  vorn(dst, dst, tmp);
26891cb0ef41Sopenharmony_ci}
26901cb0ef41Sopenharmony_ci
26911cb0ef41Sopenharmony_civoid TurboAssembler::I64x2GtS(QwNeonRegister dst, QwNeonRegister src1,
26921cb0ef41Sopenharmony_ci                              QwNeonRegister src2) {
26931cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
26941cb0ef41Sopenharmony_ci  vqsub(NeonS64, dst, src2, src1);
26951cb0ef41Sopenharmony_ci  vshr(NeonS64, dst, dst, 63);
26961cb0ef41Sopenharmony_ci}
26971cb0ef41Sopenharmony_ci
26981cb0ef41Sopenharmony_civoid TurboAssembler::I64x2GeS(QwNeonRegister dst, QwNeonRegister src1,
26991cb0ef41Sopenharmony_ci                              QwNeonRegister src2) {
27001cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
27011cb0ef41Sopenharmony_ci  vqsub(NeonS64, dst, src1, src2);
27021cb0ef41Sopenharmony_ci  vshr(NeonS64, dst, dst, 63);
27031cb0ef41Sopenharmony_ci  vmvn(dst, dst);
27041cb0ef41Sopenharmony_ci}
27051cb0ef41Sopenharmony_ci
27061cb0ef41Sopenharmony_civoid TurboAssembler::I64x2AllTrue(Register dst, QwNeonRegister src) {
27071cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
27081cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
27091cb0ef41Sopenharmony_ci  QwNeonRegister tmp = temps.AcquireQ();
27101cb0ef41Sopenharmony_ci  // src = | a | b | c | d |
27111cb0ef41Sopenharmony_ci  // tmp = | max(a,b) | max(c,d) | ...
27121cb0ef41Sopenharmony_ci  vpmax(NeonU32, tmp.low(), src.low(), src.high());
27131cb0ef41Sopenharmony_ci  // tmp = | max(a,b) == 0 | max(c,d) == 0 | ...
27141cb0ef41Sopenharmony_ci  vceq(Neon32, tmp, tmp, 0);
27151cb0ef41Sopenharmony_ci  // tmp = | max(a,b) == 0 or max(c,d) == 0 | ...
27161cb0ef41Sopenharmony_ci  vpmax(NeonU32, tmp.low(), tmp.low(), tmp.low());
27171cb0ef41Sopenharmony_ci  // dst = (max(a,b) == 0 || max(c,d) == 0)
27181cb0ef41Sopenharmony_ci  // dst will either be -1 or 0.
27191cb0ef41Sopenharmony_ci  vmov(NeonS32, dst, tmp.low(), 0);
27201cb0ef41Sopenharmony_ci  // dst = !dst (-1 -> 0, 0 -> 1)
27211cb0ef41Sopenharmony_ci  add(dst, dst, Operand(1));
27221cb0ef41Sopenharmony_ci  // This works because:
27231cb0ef41Sopenharmony_ci  // !dst
27241cb0ef41Sopenharmony_ci  // = !(max(a,b) == 0 || max(c,d) == 0)
27251cb0ef41Sopenharmony_ci  // = max(a,b) != 0 && max(c,d) != 0
27261cb0ef41Sopenharmony_ci  // = (a != 0 || b != 0) && (c != 0 || d != 0)
27271cb0ef41Sopenharmony_ci  // = defintion of i64x2.all_true.
27281cb0ef41Sopenharmony_ci}
27291cb0ef41Sopenharmony_ci
27301cb0ef41Sopenharmony_civoid TurboAssembler::I64x2Abs(QwNeonRegister dst, QwNeonRegister src) {
27311cb0ef41Sopenharmony_ci  ASM_CODE_COMMENT(this);
27321cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(this);
27331cb0ef41Sopenharmony_ci  Simd128Register tmp = temps.AcquireQ();
27341cb0ef41Sopenharmony_ci  vshr(NeonS64, tmp, src, 63);
27351cb0ef41Sopenharmony_ci  veor(dst, src, tmp);
27361cb0ef41Sopenharmony_ci  vsub(Neon64, dst, dst, tmp);
27371cb0ef41Sopenharmony_ci}
27381cb0ef41Sopenharmony_ci
27391cb0ef41Sopenharmony_cinamespace {
27401cb0ef41Sopenharmony_ciusing AssemblerFunc = void (Assembler::*)(DwVfpRegister, SwVfpRegister,
27411cb0ef41Sopenharmony_ci                                          VFPConversionMode, const Condition);
27421cb0ef41Sopenharmony_ci// Helper function for f64x2 convert low instructions.
27431cb0ef41Sopenharmony_ci// This ensures that we do not overwrite src, if dst == src.
27441cb0ef41Sopenharmony_civoid F64x2ConvertLowHelper(Assembler* assm, QwNeonRegister dst,
27451cb0ef41Sopenharmony_ci                           QwNeonRegister src, AssemblerFunc convert_fn) {
27461cb0ef41Sopenharmony_ci  LowDwVfpRegister src_d = LowDwVfpRegister::from_code(src.low().code());
27471cb0ef41Sopenharmony_ci  UseScratchRegisterScope temps(assm);
27481cb0ef41Sopenharmony_ci  if (dst == src) {
27491cb0ef41Sopenharmony_ci    LowDwVfpRegister tmp = temps.AcquireLowD();
27501cb0ef41Sopenharmony_ci    assm->vmov(tmp, src_d);
27511cb0ef41Sopenharmony_ci    src_d = tmp;
27521cb0ef41Sopenharmony_ci  }
27531cb0ef41Sopenharmony_ci  // Default arguments are not part of the function type
27541cb0ef41Sopenharmony_ci  (assm->*convert_fn)(dst.low(), src_d.low(), kDefaultRoundToZero, al);
27551cb0ef41Sopenharmony_ci  (assm->*convert_fn)(dst.high(), src_d.high(), kDefaultRoundToZero, al);
27561cb0ef41Sopenharmony_ci}
27571cb0ef41Sopenharmony_ci}  // namespace
27581cb0ef41Sopenharmony_ci
27591cb0ef41Sopenharmony_civoid TurboAssembler::F64x2ConvertLowI32x4S(QwNeonRegister dst,
27601cb0ef41Sopenharmony_ci                                           QwNeonRegister src) {
27611cb0ef41Sopenharmony_ci  F64x2ConvertLowHelper(this, dst, src, &Assembler::vcvt_f64_s32);
27621cb0ef41Sopenharmony_ci}
27631cb0ef41Sopenharmony_ci
27641cb0ef41Sopenharmony_civoid TurboAssembler::F64x2ConvertLowI32x4U(QwNeonRegister dst,
27651cb0ef41Sopenharmony_ci                                           QwNeonRegister src) {
27661cb0ef41Sopenharmony_ci  F64x2ConvertLowHelper(this, dst, src, &Assembler::vcvt_f64_u32);
27671cb0ef41Sopenharmony_ci}
27681cb0ef41Sopenharmony_ci
27691cb0ef41Sopenharmony_civoid TurboAssembler::F64x2PromoteLowF32x4(QwNeonRegister dst,
27701cb0ef41Sopenharmony_ci                                          QwNeonRegister src) {
27711cb0ef41Sopenharmony_ci  F64x2ConvertLowHelper(this, dst, src, &Assembler::vcvt_f64_f32);
27721cb0ef41Sopenharmony_ci}
27731cb0ef41Sopenharmony_ci
27741cb0ef41Sopenharmony_ci}  // namespace internal
27751cb0ef41Sopenharmony_ci}  // namespace v8
27761cb0ef41Sopenharmony_ci
27771cb0ef41Sopenharmony_ci#endif  // V8_TARGET_ARCH_ARM
2778