| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#ifndef VIXL_CPU_AARCH64_H |
| 28 |
#define VIXL_CPU_AARCH64_H |
| 29 |
|
| 30 |
#include "jit/arm64/vixl/Cpu-Features-vixl.h" |
| 31 |
#include "jit/arm64/vixl/Globals-vixl.h" |
| 32 |
|
| 33 |
#include "jit/arm64/vixl/Instructions-vixl.h" |
| 34 |
|
| 35 |
#ifndef VIXL_INCLUDE_TARGET_AARCH64 |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
#error cpu-aarch64.h requires VIXL_INCLUDE_TARGET_AARCH64 (scons target=a64). |
| 44 |
#endif |
| 45 |
|
| 46 |
namespace vixl { |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
class IDRegister { |
| 51 |
protected: |
| 52 |
explicit IDRegister(uint64_t value = 0) : value_(value) {} |
| 53 |
|
| 54 |
class Field { |
| 55 |
public: |
| 56 |
enum Type { kUnsigned, kSigned }; |
| 57 |
|
| 58 |
explicit Field(int lsb, Type type = kUnsigned) : lsb_(lsb), type_(type) {} |
| 59 |
|
| 60 |
static const int kMaxWidthInBits = 4; |
| 61 |
|
| 62 |
int GetWidthInBits() const { |
| 63 |
|
| 64 |
return kMaxWidthInBits; |
| 65 |
} |
| 66 |
int GetLsb() const { return lsb_; } |
| 67 |
int GetMsb() const { return lsb_ + GetWidthInBits() - 1; } |
| 68 |
Type GetType() const { return type_; } |
| 69 |
|
| 70 |
private: |
| 71 |
int lsb_; |
| 72 |
Type type_; |
| 73 |
}; |
| 74 |
|
| 75 |
public: |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
int Get(Field field) const; |
| 80 |
|
| 81 |
private: |
| 82 |
uint64_t value_; |
| 83 |
}; |
| 84 |
|
| 85 |
class AA64PFR0 : public IDRegister { |
| 86 |
public: |
| 87 |
explicit AA64PFR0(uint64_t value) : IDRegister(value) {} |
| 88 |
|
| 89 |
CPUFeatures GetCPUFeatures() const; |
| 90 |
|
| 91 |
private: |
| 92 |
static const Field kFP; |
| 93 |
static const Field kAdvSIMD; |
| 94 |
static const Field kSVE; |
| 95 |
static const Field kDIT; |
| 96 |
}; |
| 97 |
|
| 98 |
class AA64PFR1 : public IDRegister { |
| 99 |
public: |
| 100 |
explicit AA64PFR1(uint64_t value) : IDRegister(value) {} |
| 101 |
|
| 102 |
CPUFeatures GetCPUFeatures() const; |
| 103 |
|
| 104 |
private: |
| 105 |
static const Field kBT; |
| 106 |
}; |
| 107 |
|
| 108 |
class AA64ISAR0 : public IDRegister { |
| 109 |
public: |
| 110 |
explicit AA64ISAR0(uint64_t value) : IDRegister(value) {} |
| 111 |
|
| 112 |
CPUFeatures GetCPUFeatures() const; |
| 113 |
|
| 114 |
private: |
| 115 |
static const Field kAES; |
| 116 |
static const Field kSHA1; |
| 117 |
static const Field kSHA2; |
| 118 |
static const Field kCRC32; |
| 119 |
static const Field kAtomic; |
| 120 |
static const Field kRDM; |
| 121 |
static const Field kSHA3; |
| 122 |
static const Field kSM3; |
| 123 |
static const Field kSM4; |
| 124 |
static const Field kDP; |
| 125 |
static const Field kFHM; |
| 126 |
static const Field kTS; |
| 127 |
}; |
| 128 |
|
| 129 |
class AA64ISAR1 : public IDRegister { |
| 130 |
public: |
| 131 |
explicit AA64ISAR1(uint64_t value) : IDRegister(value) {} |
| 132 |
|
| 133 |
CPUFeatures GetCPUFeatures() const; |
| 134 |
|
| 135 |
private: |
| 136 |
static const Field kDPB; |
| 137 |
static const Field kAPA; |
| 138 |
static const Field kAPI; |
| 139 |
static const Field kJSCVT; |
| 140 |
static const Field kFCMA; |
| 141 |
static const Field kLRCPC; |
| 142 |
static const Field kGPA; |
| 143 |
static const Field kGPI; |
| 144 |
static const Field kFRINTTS; |
| 145 |
static const Field kSB; |
| 146 |
static const Field kSPECRES; |
| 147 |
}; |
| 148 |
|
| 149 |
class AA64MMFR1 : public IDRegister { |
| 150 |
public: |
| 151 |
explicit AA64MMFR1(uint64_t value) : IDRegister(value) {} |
| 152 |
|
| 153 |
CPUFeatures GetCPUFeatures() const; |
| 154 |
|
| 155 |
private: |
| 156 |
static const Field kLO; |
| 157 |
}; |
| 158 |
|
| 159 |
class CPU { |
| 160 |
public: |
| 161 |
|
| 162 |
static void SetUp(); |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
static void EnsureIAndDCacheCoherency(void* address, size_t length); |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
static void FlushExecutionContext(); |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
static CPUFeatures InferCPUFeaturesFromIDRegisters(); |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
static CPUFeatures InferCPUFeaturesFromOS( |
| 187 |
CPUFeatures::QueryIDRegistersOption option = |
| 188 |
CPUFeatures::kQueryIDRegistersIfAvailable); |
| 189 |
|
| 190 |
|
| 191 |
template <typename T> |
| 192 |
static T SetPointerTag(T pointer, uint64_t tag) { |
| 193 |
VIXL_ASSERT(IsUintN(kAddressTagWidth, tag)); |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
uint64_t raw = (uint64_t)pointer; |
| 199 |
VIXL_STATIC_ASSERT(sizeof(pointer) == sizeof(raw)); |
| 200 |
|
| 201 |
raw = (raw & ~kAddressTagMask) | (tag << kAddressTagOffset); |
| 202 |
return (T)raw; |
| 203 |
} |
| 204 |
|
| 205 |
template <typename T> |
| 206 |
static uint64_t GetPointerTag(T pointer) { |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
uint64_t raw = (uint64_t)pointer; |
| 211 |
VIXL_STATIC_ASSERT(sizeof(pointer) == sizeof(raw)); |
| 212 |
|
| 213 |
return (raw & kAddressTagMask) >> kAddressTagOffset; |
| 214 |
} |
| 215 |
|
| 216 |
private: |
| 217 |
#define VIXL_AARCH64_ID_REG_LIST(V) \ |
| 218 |
V(AA64PFR0) \ |
| 219 |
V(AA64PFR1) \ |
| 220 |
V(AA64ISAR0) \ |
| 221 |
V(AA64ISAR1) \ |
| 222 |
V(AA64MMFR1) |
| 223 |
|
| 224 |
#define VIXL_READ_ID_REG(NAME) static NAME Read##NAME(); |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
VIXL_AARCH64_ID_REG_LIST(VIXL_READ_ID_REG) |
| 229 |
#undef VIXL_READ_ID_REG |
| 230 |
|
| 231 |
|
| 232 |
static uint32_t GetCacheType(); |
| 233 |
|
| 234 |
|
| 235 |
static unsigned icache_line_size_; |
| 236 |
static unsigned dcache_line_size_; |
| 237 |
}; |
| 238 |
|
| 239 |
} |
| 240 |
|
| 241 |
#endif |