Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
constants.h
Go to the documentation of this file.
1// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_VM_CONSTANTS_H_
6#define RUNTIME_VM_CONSTANTS_H_
7
8#if defined(TARGET_ARCH_IA32)
9#include "vm/constants_ia32.h"
10#elif defined(TARGET_ARCH_X64)
11#include "vm/constants_x64.h"
12#elif defined(TARGET_ARCH_ARM)
13#include "vm/constants_arm.h"
14#elif defined(TARGET_ARCH_ARM64)
15#include "vm/constants_arm64.h"
16#elif defined(TARGET_ARCH_RISCV32) || defined(TARGET_ARCH_RISCV64)
17#include "vm/constants_riscv.h"
18#else
19#error Unknown architecture.
20#endif
21
22#include "platform/assert.h"
23#include "platform/utils.h"
24
25#include "vm/pointer_tagging.h"
26
27namespace dart {
28
29// An architecture independent ABI for the InstantiateType stub.
30//
31// We re-use registers from another ABI to avoid duplicating this ABI across 4
32// architectures.
43
45 public:
46 static const char* RegisterName(Register reg) {
47 ASSERT((0 <= reg) && (reg < kNumberOfCpuRegisters));
48 return cpu_reg_names[reg];
49 }
50 static const char* RegisterAbiName(Register reg) {
51 ASSERT((0 <= reg) && (reg < kNumberOfCpuRegisters));
52 return cpu_reg_abi_names[reg];
53 }
54 static const char* FpuRegisterName(FpuRegister reg) {
55 ASSERT((0 <= reg) && (reg < kNumberOfFpuRegisters));
56 return fpu_reg_names[reg];
57 }
58#if defined(TARGET_ARCH_ARM)
59 static const char* FpuSRegisterName(SRegister reg) {
60 ASSERT((0 <= reg) && (reg < kNumberOfSRegisters));
61 return fpu_s_reg_names[reg];
62 }
63 static const char* FpuDRegisterName(DRegister reg) {
64 ASSERT((0 <= reg) && (reg < kNumberOfDRegisters));
65 return fpu_d_reg_names[reg];
66 }
67#endif // defined(TARGET_ARCH_ARM)
68
69#if defined(TARGET_ARCH_X64) || defined(TARGET_ARCH_IA32)
70 static const char* RegisterByteName(ByteRegister reg) {
71 ASSERT((0 <= reg) && (reg < kNumberOfByteRegisters));
72 return cpu_reg_byte_names[reg];
73 }
74#endif // defined(TARGET_ARCH_X64) || defined(TARGET_ARCH_IA32)
75};
76
77static constexpr bool IsArgumentRegister(Register reg) {
78 return ((1 << reg) & CallingConventions::kArgumentRegisters) != 0;
79}
80
81static constexpr bool IsFpuArgumentRegister(FpuRegister reg) {
82 return ((1 << reg) & CallingConventions::kFpuArgumentRegisters) != 0;
83}
84
85static constexpr bool IsCalleeSavedRegister(Register reg) {
86 return ((1 << reg) & CallingConventions::kCalleeSaveCpuRegisters) != 0;
87}
88
89#if !defined(TARGET_ARCH_IA32)
90constexpr bool IsAbiPreservedRegister(Register reg) {
91 return (kAbiPreservedCpuRegs & (1 << reg)) != 0;
92}
93#endif
94
95static inline ScaleFactor ToScaleFactor(intptr_t index_scale,
96 bool index_unboxed) {
97 RELEASE_ASSERT(index_scale >= 0);
98 const intptr_t shift = Utils::ShiftForPowerOfTwo(index_scale) -
99 (index_unboxed ? 0 : kSmiTagShift);
100 // index_scale < kSmiTagShift for boxed indexes must be handled by the caller,
101 // and ScaleFactor is currently only defined up to TIMES_16 == 4.
102 RELEASE_ASSERT(shift >= 0 && shift <= 4);
103 return static_cast<ScaleFactor>(shift);
104}
105
106// Helper for using register sets with range loops:
107//
108// for (auto reg : RegisterRange(kDartAvailableCpuRegs)) { ... }
109//
110static inline Utils::BitsRange<Register> RegisterRange(uint32_t regs) {
111 return Utils::BitsRange<Register>(regs);
112}
113
114} // namespace dart
115
116#endif // RUNTIME_VM_CONSTANTS_H_
#define RELEASE_ASSERT(cond)
Definition assert.h:327
static constexpr intptr_t kCalleeSaveCpuRegisters
static constexpr intptr_t kFpuArgumentRegisters
static constexpr intptr_t kArgumentRegisters
static const char * FpuRegisterName(FpuRegister reg)
Definition constants.h:54
static const char * RegisterName(Register reg)
Definition constants.h:46
static const char * RegisterAbiName(Register reg)
Definition constants.h:50
static constexpr int ShiftForPowerOfTwo(T x)
Definition utils.h:66
#define ASSERT(E)
constexpr bool IsAbiPreservedRegister(Register reg)
Definition constants.h:90
static Utils::BitsRange< Register > RegisterRange(uint32_t regs)
Definition constants.h:110
static constexpr bool IsCalleeSavedRegister(Register reg)
Definition constants.h:85
const char *const fpu_reg_names[kNumberOfFpuRegisters]
@ kNumberOfCpuRegisters
const int kNumberOfFpuRegisters
const RegList kAbiPreservedCpuRegs
static constexpr bool IsArgumentRegister(Register reg)
Definition constants.h:77
const char *const fpu_d_reg_names[kNumberOfDRegisters]
@ kNumberOfSRegisters
static constexpr bool IsFpuArgumentRegister(FpuRegister reg)
Definition constants.h:81
const char *const cpu_reg_names[kNumberOfCpuRegisters]
@ kNumberOfByteRegisters
@ kNumberOfDRegisters
const char *const cpu_reg_byte_names[kNumberOfByteRegisters]
static ScaleFactor ToScaleFactor(intptr_t index_scale, bool index_unboxed)
Definition constants.h:95
const char *const fpu_s_reg_names[kNumberOfSRegisters]
const char *const cpu_reg_abi_names[kNumberOfCpuRegisters]
static constexpr Register kFunctionTypeArgumentsReg
Definition constants.h:38
static constexpr Register kTypeReg
Definition constants.h:34
static constexpr Register kScratchReg
Definition constants.h:41
static constexpr Register kInstantiatorTypeArgumentsReg
Definition constants.h:36
static constexpr Register kResultTypeReg
Definition constants.h:40
static constexpr Register kInstantiatorTypeArgumentsReg
static constexpr Register kScratchReg
static constexpr Register kResultTypeReg
static constexpr Register kUninstantiatedTypeArgumentsReg
static constexpr Register kFunctionTypeArgumentsReg