11cb0ef41Sopenharmony_ci// Copyright 2014 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 "src/codegen/register-configuration.h"
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#include "src/base/lazy-instance.h"
81cb0ef41Sopenharmony_ci#include "src/codegen/cpu-features.h"
91cb0ef41Sopenharmony_ci#include "src/codegen/register.h"
101cb0ef41Sopenharmony_ci#include "src/common/globals.h"
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cinamespace v8 {
131cb0ef41Sopenharmony_cinamespace internal {
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_cinamespace {
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci#define REGISTER_COUNT(R) 1 +
181cb0ef41Sopenharmony_cistatic const int kMaxAllocatableGeneralRegisterCount =
191cb0ef41Sopenharmony_ci    ALLOCATABLE_GENERAL_REGISTERS(REGISTER_COUNT) 0;
201cb0ef41Sopenharmony_cistatic const int kMaxAllocatableDoubleRegisterCount =
211cb0ef41Sopenharmony_ci    ALLOCATABLE_DOUBLE_REGISTERS(REGISTER_COUNT) 0;
221cb0ef41Sopenharmony_ci#if V8_TARGET_ARCH_RISCV64
231cb0ef41Sopenharmony_cistatic const int kMaxAllocatableSIMD128RegisterCount =
241cb0ef41Sopenharmony_ci    ALLOCATABLE_SIMD128_REGISTERS(REGISTER_COUNT) 0;
251cb0ef41Sopenharmony_ci#endif
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_cistatic const int kAllocatableGeneralCodes[] = {
281cb0ef41Sopenharmony_ci#define REGISTER_CODE(R) kRegCode_##R,
291cb0ef41Sopenharmony_ci    ALLOCATABLE_GENERAL_REGISTERS(REGISTER_CODE)};
301cb0ef41Sopenharmony_ci#undef REGISTER_CODE
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci#define REGISTER_CODE(R) kDoubleCode_##R,
331cb0ef41Sopenharmony_cistatic const int kAllocatableDoubleCodes[] = {
341cb0ef41Sopenharmony_ci    ALLOCATABLE_DOUBLE_REGISTERS(REGISTER_CODE)};
351cb0ef41Sopenharmony_ci#if V8_TARGET_ARCH_ARM
361cb0ef41Sopenharmony_cistatic const int kAllocatableNoVFP32DoubleCodes[] = {
371cb0ef41Sopenharmony_ci    ALLOCATABLE_NO_VFP32_DOUBLE_REGISTERS(REGISTER_CODE)};
381cb0ef41Sopenharmony_ci#endif  // V8_TARGET_ARCH_ARM
391cb0ef41Sopenharmony_ci#undef REGISTER_CODE
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci#if V8_TARGET_ARCH_RISCV64
421cb0ef41Sopenharmony_cistatic const int kAllocatableSIMD128Codes[] = {
431cb0ef41Sopenharmony_ci#define REGISTER_CODE(R) kVRCode_##R,
441cb0ef41Sopenharmony_ci    ALLOCATABLE_SIMD128_REGISTERS(REGISTER_CODE)};
451cb0ef41Sopenharmony_ci#undef REGISTER_CODE
461cb0ef41Sopenharmony_ci#endif  // V8_TARGET_ARCH_RISCV64
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ciSTATIC_ASSERT(RegisterConfiguration::kMaxGeneralRegisters >=
491cb0ef41Sopenharmony_ci              Register::kNumRegisters);
501cb0ef41Sopenharmony_ciSTATIC_ASSERT(RegisterConfiguration::kMaxFPRegisters >=
511cb0ef41Sopenharmony_ci              FloatRegister::kNumRegisters);
521cb0ef41Sopenharmony_ciSTATIC_ASSERT(RegisterConfiguration::kMaxFPRegisters >=
531cb0ef41Sopenharmony_ci              DoubleRegister::kNumRegisters);
541cb0ef41Sopenharmony_ciSTATIC_ASSERT(RegisterConfiguration::kMaxFPRegisters >=
551cb0ef41Sopenharmony_ci              Simd128Register::kNumRegisters);
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_cistatic int get_num_simd128_registers() {
581cb0ef41Sopenharmony_ci  return
591cb0ef41Sopenharmony_ci#if V8_TARGET_ARCH_RISCV64
601cb0ef41Sopenharmony_ci      Simd128Register::kNumRegisters;
611cb0ef41Sopenharmony_ci#else
621cb0ef41Sopenharmony_ci      0;
631cb0ef41Sopenharmony_ci#endif  // V8_TARGET_ARCH_RISCV64
641cb0ef41Sopenharmony_ci}
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_ci// Callers on architectures other than Arm expect this to be be constant
671cb0ef41Sopenharmony_ci// between build and runtime. Avoid adding variability on other platforms.
681cb0ef41Sopenharmony_cistatic int get_num_allocatable_double_registers() {
691cb0ef41Sopenharmony_ci  return
701cb0ef41Sopenharmony_ci#if V8_TARGET_ARCH_IA32
711cb0ef41Sopenharmony_ci      kMaxAllocatableDoubleRegisterCount;
721cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_X64
731cb0ef41Sopenharmony_ci      kMaxAllocatableDoubleRegisterCount;
741cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_ARM
751cb0ef41Sopenharmony_ci      CpuFeatures::IsSupported(VFP32DREGS)
761cb0ef41Sopenharmony_ci          ? kMaxAllocatableDoubleRegisterCount
771cb0ef41Sopenharmony_ci          : (ALLOCATABLE_NO_VFP32_DOUBLE_REGISTERS(REGISTER_COUNT) 0);
781cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_ARM64
791cb0ef41Sopenharmony_ci      kMaxAllocatableDoubleRegisterCount;
801cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_MIPS
811cb0ef41Sopenharmony_ci      kMaxAllocatableDoubleRegisterCount;
821cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_MIPS64
831cb0ef41Sopenharmony_ci      kMaxAllocatableDoubleRegisterCount;
841cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_LOONG64
851cb0ef41Sopenharmony_ci      kMaxAllocatableDoubleRegisterCount;
861cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_PPC
871cb0ef41Sopenharmony_ci      kMaxAllocatableDoubleRegisterCount;
881cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_PPC64
891cb0ef41Sopenharmony_ci      kMaxAllocatableDoubleRegisterCount;
901cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_S390
911cb0ef41Sopenharmony_ci      kMaxAllocatableDoubleRegisterCount;
921cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_RISCV64
931cb0ef41Sopenharmony_ci      kMaxAllocatableDoubleRegisterCount;
941cb0ef41Sopenharmony_ci#else
951cb0ef41Sopenharmony_ci#error Unsupported target architecture.
961cb0ef41Sopenharmony_ci#endif
971cb0ef41Sopenharmony_ci}
981cb0ef41Sopenharmony_ci
991cb0ef41Sopenharmony_ci#undef REGISTER_COUNT
1001cb0ef41Sopenharmony_ci
1011cb0ef41Sopenharmony_cistatic int get_num_allocatable_simd128_registers() {
1021cb0ef41Sopenharmony_ci  return
1031cb0ef41Sopenharmony_ci#if V8_TARGET_ARCH_RISCV64
1041cb0ef41Sopenharmony_ci      kMaxAllocatableSIMD128RegisterCount;
1051cb0ef41Sopenharmony_ci#else
1061cb0ef41Sopenharmony_ci      0;
1071cb0ef41Sopenharmony_ci#endif
1081cb0ef41Sopenharmony_ci}
1091cb0ef41Sopenharmony_ci
1101cb0ef41Sopenharmony_ci// Callers on architectures other than Arm expect this to be be constant
1111cb0ef41Sopenharmony_ci// between build and runtime. Avoid adding variability on other platforms.
1121cb0ef41Sopenharmony_cistatic const int* get_allocatable_double_codes() {
1131cb0ef41Sopenharmony_ci  return
1141cb0ef41Sopenharmony_ci#if V8_TARGET_ARCH_ARM
1151cb0ef41Sopenharmony_ci      CpuFeatures::IsSupported(VFP32DREGS) ? kAllocatableDoubleCodes
1161cb0ef41Sopenharmony_ci                                           : kAllocatableNoVFP32DoubleCodes;
1171cb0ef41Sopenharmony_ci#else
1181cb0ef41Sopenharmony_ci      kAllocatableDoubleCodes;
1191cb0ef41Sopenharmony_ci#endif
1201cb0ef41Sopenharmony_ci}
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_cistatic const int* get_allocatable_simd128_codes() {
1231cb0ef41Sopenharmony_ci  return
1241cb0ef41Sopenharmony_ci#if V8_TARGET_ARCH_RISCV64
1251cb0ef41Sopenharmony_ci      kAllocatableSIMD128Codes;
1261cb0ef41Sopenharmony_ci#else
1271cb0ef41Sopenharmony_ci      kAllocatableDoubleCodes;
1281cb0ef41Sopenharmony_ci#endif
1291cb0ef41Sopenharmony_ci}
1301cb0ef41Sopenharmony_ci
1311cb0ef41Sopenharmony_ciclass ArchDefaultRegisterConfiguration : public RegisterConfiguration {
1321cb0ef41Sopenharmony_ci public:
1331cb0ef41Sopenharmony_ci  ArchDefaultRegisterConfiguration()
1341cb0ef41Sopenharmony_ci      : RegisterConfiguration(
1351cb0ef41Sopenharmony_ci            kFPAliasing, Register::kNumRegisters, DoubleRegister::kNumRegisters,
1361cb0ef41Sopenharmony_ci            get_num_simd128_registers(), kMaxAllocatableGeneralRegisterCount,
1371cb0ef41Sopenharmony_ci            get_num_allocatable_double_registers(),
1381cb0ef41Sopenharmony_ci            get_num_allocatable_simd128_registers(), kAllocatableGeneralCodes,
1391cb0ef41Sopenharmony_ci            get_allocatable_double_codes(), get_allocatable_simd128_codes()) {}
1401cb0ef41Sopenharmony_ci};
1411cb0ef41Sopenharmony_ci
1421cb0ef41Sopenharmony_ciDEFINE_LAZY_LEAKY_OBJECT_GETTER(ArchDefaultRegisterConfiguration,
1431cb0ef41Sopenharmony_ci                                GetDefaultRegisterConfiguration)
1441cb0ef41Sopenharmony_ci
1451cb0ef41Sopenharmony_ci// RestrictedRegisterConfiguration uses the subset of allocatable general
1461cb0ef41Sopenharmony_ci// registers the architecture support, which results into generating assembly
1471cb0ef41Sopenharmony_ci// to use less registers. Currently, it's only used by RecordWrite code stub.
1481cb0ef41Sopenharmony_ciclass RestrictedRegisterConfiguration : public RegisterConfiguration {
1491cb0ef41Sopenharmony_ci public:
1501cb0ef41Sopenharmony_ci  RestrictedRegisterConfiguration(
1511cb0ef41Sopenharmony_ci      int num_allocatable_general_registers,
1521cb0ef41Sopenharmony_ci      std::unique_ptr<int[]> allocatable_general_register_codes,
1531cb0ef41Sopenharmony_ci      std::unique_ptr<char const*[]> allocatable_general_register_names)
1541cb0ef41Sopenharmony_ci      : RegisterConfiguration(
1551cb0ef41Sopenharmony_ci            kFPAliasing, Register::kNumRegisters, DoubleRegister::kNumRegisters,
1561cb0ef41Sopenharmony_ci            get_num_simd128_registers(), num_allocatable_general_registers,
1571cb0ef41Sopenharmony_ci            get_num_allocatable_double_registers(),
1581cb0ef41Sopenharmony_ci            get_num_allocatable_simd128_registers(),
1591cb0ef41Sopenharmony_ci            allocatable_general_register_codes.get(),
1601cb0ef41Sopenharmony_ci            get_allocatable_double_codes(), get_allocatable_simd128_codes()),
1611cb0ef41Sopenharmony_ci        allocatable_general_register_codes_(
1621cb0ef41Sopenharmony_ci            std::move(allocatable_general_register_codes)),
1631cb0ef41Sopenharmony_ci        allocatable_general_register_names_(
1641cb0ef41Sopenharmony_ci            std::move(allocatable_general_register_names)) {
1651cb0ef41Sopenharmony_ci    for (int i = 0; i < num_allocatable_general_registers; ++i) {
1661cb0ef41Sopenharmony_ci      DCHECK(
1671cb0ef41Sopenharmony_ci          IsAllocatableGeneralRegister(allocatable_general_register_codes_[i]));
1681cb0ef41Sopenharmony_ci    }
1691cb0ef41Sopenharmony_ci  }
1701cb0ef41Sopenharmony_ci
1711cb0ef41Sopenharmony_ci  bool IsAllocatableGeneralRegister(int code) {
1721cb0ef41Sopenharmony_ci    for (int i = 0; i < kMaxAllocatableGeneralRegisterCount; ++i) {
1731cb0ef41Sopenharmony_ci      if (code == kAllocatableGeneralCodes[i]) {
1741cb0ef41Sopenharmony_ci        return true;
1751cb0ef41Sopenharmony_ci      }
1761cb0ef41Sopenharmony_ci    }
1771cb0ef41Sopenharmony_ci    return false;
1781cb0ef41Sopenharmony_ci  }
1791cb0ef41Sopenharmony_ci
1801cb0ef41Sopenharmony_ci private:
1811cb0ef41Sopenharmony_ci  std::unique_ptr<int[]> allocatable_general_register_codes_;
1821cb0ef41Sopenharmony_ci  std::unique_ptr<char const*[]> allocatable_general_register_names_;
1831cb0ef41Sopenharmony_ci};
1841cb0ef41Sopenharmony_ci
1851cb0ef41Sopenharmony_ci}  // namespace
1861cb0ef41Sopenharmony_ci
1871cb0ef41Sopenharmony_ciconst RegisterConfiguration* RegisterConfiguration::Default() {
1881cb0ef41Sopenharmony_ci  return GetDefaultRegisterConfiguration();
1891cb0ef41Sopenharmony_ci}
1901cb0ef41Sopenharmony_ci
1911cb0ef41Sopenharmony_ciconst RegisterConfiguration* RegisterConfiguration::RestrictGeneralRegisters(
1921cb0ef41Sopenharmony_ci    RegList registers) {
1931cb0ef41Sopenharmony_ci  int num = registers.Count();
1941cb0ef41Sopenharmony_ci  std::unique_ptr<int[]> codes{new int[num]};
1951cb0ef41Sopenharmony_ci  std::unique_ptr<char const* []> names { new char const*[num] };
1961cb0ef41Sopenharmony_ci  int counter = 0;
1971cb0ef41Sopenharmony_ci  for (int i = 0; i < Default()->num_allocatable_general_registers(); ++i) {
1981cb0ef41Sopenharmony_ci    auto reg = Register::from_code(Default()->GetAllocatableGeneralCode(i));
1991cb0ef41Sopenharmony_ci    if (registers.has(reg)) {
2001cb0ef41Sopenharmony_ci      DCHECK(counter < num);
2011cb0ef41Sopenharmony_ci      codes[counter] = reg.code();
2021cb0ef41Sopenharmony_ci      names[counter] = RegisterName(Register::from_code(i));
2031cb0ef41Sopenharmony_ci      counter++;
2041cb0ef41Sopenharmony_ci    }
2051cb0ef41Sopenharmony_ci  }
2061cb0ef41Sopenharmony_ci
2071cb0ef41Sopenharmony_ci  return new RestrictedRegisterConfiguration(num, std::move(codes),
2081cb0ef41Sopenharmony_ci                                             std::move(names));
2091cb0ef41Sopenharmony_ci}
2101cb0ef41Sopenharmony_ci
2111cb0ef41Sopenharmony_ciRegisterConfiguration::RegisterConfiguration(
2121cb0ef41Sopenharmony_ci    AliasingKind fp_aliasing_kind, int num_general_registers,
2131cb0ef41Sopenharmony_ci    int num_double_registers, int num_simd128_registers,
2141cb0ef41Sopenharmony_ci    int num_allocatable_general_registers, int num_allocatable_double_registers,
2151cb0ef41Sopenharmony_ci    int num_allocatable_simd128_registers, const int* allocatable_general_codes,
2161cb0ef41Sopenharmony_ci    const int* allocatable_double_codes,
2171cb0ef41Sopenharmony_ci    const int* independent_allocatable_simd128_codes)
2181cb0ef41Sopenharmony_ci    : num_general_registers_(num_general_registers),
2191cb0ef41Sopenharmony_ci      num_float_registers_(0),
2201cb0ef41Sopenharmony_ci      num_double_registers_(num_double_registers),
2211cb0ef41Sopenharmony_ci      num_simd128_registers_(num_simd128_registers),
2221cb0ef41Sopenharmony_ci      num_allocatable_general_registers_(num_allocatable_general_registers),
2231cb0ef41Sopenharmony_ci      num_allocatable_float_registers_(0),
2241cb0ef41Sopenharmony_ci      num_allocatable_double_registers_(num_allocatable_double_registers),
2251cb0ef41Sopenharmony_ci      num_allocatable_simd128_registers_(num_allocatable_simd128_registers),
2261cb0ef41Sopenharmony_ci      allocatable_general_codes_mask_(0),
2271cb0ef41Sopenharmony_ci      allocatable_float_codes_mask_(0),
2281cb0ef41Sopenharmony_ci      allocatable_double_codes_mask_(0),
2291cb0ef41Sopenharmony_ci      allocatable_simd128_codes_mask_(0),
2301cb0ef41Sopenharmony_ci      allocatable_general_codes_(allocatable_general_codes),
2311cb0ef41Sopenharmony_ci      allocatable_double_codes_(allocatable_double_codes),
2321cb0ef41Sopenharmony_ci      fp_aliasing_kind_(fp_aliasing_kind) {
2331cb0ef41Sopenharmony_ci  DCHECK_LE(num_general_registers_,
2341cb0ef41Sopenharmony_ci            RegisterConfiguration::kMaxGeneralRegisters);
2351cb0ef41Sopenharmony_ci  DCHECK_LE(num_double_registers_, RegisterConfiguration::kMaxFPRegisters);
2361cb0ef41Sopenharmony_ci  for (int i = 0; i < num_allocatable_general_registers_; ++i) {
2371cb0ef41Sopenharmony_ci    allocatable_general_codes_mask_ |= (1 << allocatable_general_codes_[i]);
2381cb0ef41Sopenharmony_ci  }
2391cb0ef41Sopenharmony_ci  for (int i = 0; i < num_allocatable_double_registers_; ++i) {
2401cb0ef41Sopenharmony_ci    allocatable_double_codes_mask_ |= (1 << allocatable_double_codes_[i]);
2411cb0ef41Sopenharmony_ci  }
2421cb0ef41Sopenharmony_ci
2431cb0ef41Sopenharmony_ci  if (fp_aliasing_kind_ == AliasingKind::kCombine) {
2441cb0ef41Sopenharmony_ci    num_float_registers_ = num_double_registers_ * 2 <= kMaxFPRegisters
2451cb0ef41Sopenharmony_ci                               ? num_double_registers_ * 2
2461cb0ef41Sopenharmony_ci                               : kMaxFPRegisters;
2471cb0ef41Sopenharmony_ci    num_allocatable_float_registers_ = 0;
2481cb0ef41Sopenharmony_ci    for (int i = 0; i < num_allocatable_double_registers_; i++) {
2491cb0ef41Sopenharmony_ci      int base_code = allocatable_double_codes_[i] * 2;
2501cb0ef41Sopenharmony_ci      if (base_code >= kMaxFPRegisters) continue;
2511cb0ef41Sopenharmony_ci      allocatable_float_codes_[num_allocatable_float_registers_++] = base_code;
2521cb0ef41Sopenharmony_ci      allocatable_float_codes_[num_allocatable_float_registers_++] =
2531cb0ef41Sopenharmony_ci          base_code + 1;
2541cb0ef41Sopenharmony_ci      allocatable_float_codes_mask_ |= (0x3 << base_code);
2551cb0ef41Sopenharmony_ci    }
2561cb0ef41Sopenharmony_ci    num_simd128_registers_ = num_double_registers_ / 2;
2571cb0ef41Sopenharmony_ci    num_allocatable_simd128_registers_ = 0;
2581cb0ef41Sopenharmony_ci    int last_simd128_code = allocatable_double_codes_[0] / 2;
2591cb0ef41Sopenharmony_ci    for (int i = 1; i < num_allocatable_double_registers_; i++) {
2601cb0ef41Sopenharmony_ci      int next_simd128_code = allocatable_double_codes_[i] / 2;
2611cb0ef41Sopenharmony_ci      // This scheme assumes allocatable_double_codes_ are strictly increasing.
2621cb0ef41Sopenharmony_ci      DCHECK_GE(next_simd128_code, last_simd128_code);
2631cb0ef41Sopenharmony_ci      if (last_simd128_code == next_simd128_code) {
2641cb0ef41Sopenharmony_ci        allocatable_simd128_codes_[num_allocatable_simd128_registers_++] =
2651cb0ef41Sopenharmony_ci            next_simd128_code;
2661cb0ef41Sopenharmony_ci        allocatable_simd128_codes_mask_ |= (0x1 << next_simd128_code);
2671cb0ef41Sopenharmony_ci      }
2681cb0ef41Sopenharmony_ci      last_simd128_code = next_simd128_code;
2691cb0ef41Sopenharmony_ci    }
2701cb0ef41Sopenharmony_ci  } else if (fp_aliasing_kind_ == AliasingKind::kOverlap) {
2711cb0ef41Sopenharmony_ci    num_float_registers_ = num_simd128_registers_ = num_double_registers_;
2721cb0ef41Sopenharmony_ci    num_allocatable_float_registers_ = num_allocatable_simd128_registers_ =
2731cb0ef41Sopenharmony_ci        num_allocatable_double_registers_;
2741cb0ef41Sopenharmony_ci    for (int i = 0; i < num_allocatable_float_registers_; ++i) {
2751cb0ef41Sopenharmony_ci      allocatable_float_codes_[i] = allocatable_simd128_codes_[i] =
2761cb0ef41Sopenharmony_ci          allocatable_double_codes_[i];
2771cb0ef41Sopenharmony_ci    }
2781cb0ef41Sopenharmony_ci    allocatable_float_codes_mask_ = allocatable_simd128_codes_mask_ =
2791cb0ef41Sopenharmony_ci        allocatable_double_codes_mask_;
2801cb0ef41Sopenharmony_ci  } else {
2811cb0ef41Sopenharmony_ci    DCHECK_EQ(fp_aliasing_kind_, AliasingKind::kIndependent);
2821cb0ef41Sopenharmony_ci    DCHECK_NE(independent_allocatable_simd128_codes, nullptr);
2831cb0ef41Sopenharmony_ci    num_float_registers_ = num_double_registers_;
2841cb0ef41Sopenharmony_ci    num_allocatable_float_registers_ = num_allocatable_double_registers_;
2851cb0ef41Sopenharmony_ci    for (int i = 0; i < num_allocatable_float_registers_; ++i) {
2861cb0ef41Sopenharmony_ci      allocatable_float_codes_[i] = allocatable_double_codes_[i];
2871cb0ef41Sopenharmony_ci    }
2881cb0ef41Sopenharmony_ci    allocatable_float_codes_mask_ = allocatable_double_codes_mask_;
2891cb0ef41Sopenharmony_ci    for (int i = 0; i < num_allocatable_simd128_registers; i++) {
2901cb0ef41Sopenharmony_ci      allocatable_simd128_codes_[i] = independent_allocatable_simd128_codes[i];
2911cb0ef41Sopenharmony_ci    }
2921cb0ef41Sopenharmony_ci    for (int i = 0; i < num_allocatable_simd128_registers_; ++i) {
2931cb0ef41Sopenharmony_ci      allocatable_simd128_codes_mask_ |= (1 << allocatable_simd128_codes_[i]);
2941cb0ef41Sopenharmony_ci    }
2951cb0ef41Sopenharmony_ci  }
2961cb0ef41Sopenharmony_ci}
2971cb0ef41Sopenharmony_ci
2981cb0ef41Sopenharmony_ci// Assert that kFloat32, kFloat64, and kSimd128 are consecutive values.
2991cb0ef41Sopenharmony_ciSTATIC_ASSERT(static_cast<int>(MachineRepresentation::kSimd128) ==
3001cb0ef41Sopenharmony_ci              static_cast<int>(MachineRepresentation::kFloat64) + 1);
3011cb0ef41Sopenharmony_ciSTATIC_ASSERT(static_cast<int>(MachineRepresentation::kFloat64) ==
3021cb0ef41Sopenharmony_ci              static_cast<int>(MachineRepresentation::kFloat32) + 1);
3031cb0ef41Sopenharmony_ci
3041cb0ef41Sopenharmony_ciint RegisterConfiguration::GetAliases(MachineRepresentation rep, int index,
3051cb0ef41Sopenharmony_ci                                      MachineRepresentation other_rep,
3061cb0ef41Sopenharmony_ci                                      int* alias_base_index) const {
3071cb0ef41Sopenharmony_ci  DCHECK(fp_aliasing_kind_ == AliasingKind::kCombine);
3081cb0ef41Sopenharmony_ci  DCHECK(IsFloatingPoint(rep) && IsFloatingPoint(other_rep));
3091cb0ef41Sopenharmony_ci  if (rep == other_rep) {
3101cb0ef41Sopenharmony_ci    *alias_base_index = index;
3111cb0ef41Sopenharmony_ci    return 1;
3121cb0ef41Sopenharmony_ci  }
3131cb0ef41Sopenharmony_ci  int rep_int = static_cast<int>(rep);
3141cb0ef41Sopenharmony_ci  int other_rep_int = static_cast<int>(other_rep);
3151cb0ef41Sopenharmony_ci  if (rep_int > other_rep_int) {
3161cb0ef41Sopenharmony_ci    int shift = rep_int - other_rep_int;
3171cb0ef41Sopenharmony_ci    int base_index = index << shift;
3181cb0ef41Sopenharmony_ci    if (base_index >= kMaxFPRegisters) {
3191cb0ef41Sopenharmony_ci      // Alias indices would be out of FP register range.
3201cb0ef41Sopenharmony_ci      return 0;
3211cb0ef41Sopenharmony_ci    }
3221cb0ef41Sopenharmony_ci    *alias_base_index = base_index;
3231cb0ef41Sopenharmony_ci    return 1 << shift;
3241cb0ef41Sopenharmony_ci  }
3251cb0ef41Sopenharmony_ci  int shift = other_rep_int - rep_int;
3261cb0ef41Sopenharmony_ci  *alias_base_index = index >> shift;
3271cb0ef41Sopenharmony_ci  return 1;
3281cb0ef41Sopenharmony_ci}
3291cb0ef41Sopenharmony_ci
3301cb0ef41Sopenharmony_cibool RegisterConfiguration::AreAliases(MachineRepresentation rep, int index,
3311cb0ef41Sopenharmony_ci                                       MachineRepresentation other_rep,
3321cb0ef41Sopenharmony_ci                                       int other_index) const {
3331cb0ef41Sopenharmony_ci  DCHECK(fp_aliasing_kind_ == AliasingKind::kCombine);
3341cb0ef41Sopenharmony_ci  DCHECK(IsFloatingPoint(rep) && IsFloatingPoint(other_rep));
3351cb0ef41Sopenharmony_ci  if (rep == other_rep) {
3361cb0ef41Sopenharmony_ci    return index == other_index;
3371cb0ef41Sopenharmony_ci  }
3381cb0ef41Sopenharmony_ci  int rep_int = static_cast<int>(rep);
3391cb0ef41Sopenharmony_ci  int other_rep_int = static_cast<int>(other_rep);
3401cb0ef41Sopenharmony_ci  if (rep_int > other_rep_int) {
3411cb0ef41Sopenharmony_ci    int shift = rep_int - other_rep_int;
3421cb0ef41Sopenharmony_ci    return index == other_index >> shift;
3431cb0ef41Sopenharmony_ci  }
3441cb0ef41Sopenharmony_ci  int shift = other_rep_int - rep_int;
3451cb0ef41Sopenharmony_ci  return index >> shift == other_index;
3461cb0ef41Sopenharmony_ci}
3471cb0ef41Sopenharmony_ci
3481cb0ef41Sopenharmony_ci}  // namespace internal
3491cb0ef41Sopenharmony_ci}  // namespace v8
350