1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ART_RUNTIME_ARCH_ARM64_INSTRUCTION_SET_FEATURES_ARM64_H_ 18 #define ART_RUNTIME_ARCH_ARM64_INSTRUCTION_SET_FEATURES_ARM64_H_ 19 20 #include "arch/instruction_set_features.h" 21 22 namespace art { 23 24 // SVE is currently not enabled. 25 static constexpr bool kArm64AllowSVE = false; 26 27 class Arm64InstructionSetFeatures; 28 using Arm64FeaturesUniquePtr = std::unique_ptr<const Arm64InstructionSetFeatures>; 29 30 // Instruction set features relevant to the ARM64 architecture. 31 class Arm64InstructionSetFeatures final : public InstructionSetFeatures { 32 public: 33 // Process a CPU variant string like "krait" or "cortex-a15" and create InstructionSetFeatures. 34 static Arm64FeaturesUniquePtr FromVariant(const std::string& variant, std::string* error_msg); 35 36 // Parse a bitmap and create an InstructionSetFeatures. 37 static Arm64FeaturesUniquePtr FromBitmap(uint32_t bitmap); 38 39 // Turn C pre-processor #defines into the equivalent instruction set features. 40 static Arm64FeaturesUniquePtr FromCppDefines(); 41 42 // Process /proc/cpuinfo and use kRuntimeISA to produce InstructionSetFeatures. 43 static Arm64FeaturesUniquePtr FromCpuInfo(); 44 45 // Process the auxiliary vector AT_HWCAP entry and use kRuntimeISA to produce 46 // InstructionSetFeatures. 47 static Arm64FeaturesUniquePtr FromHwcap(); 48 49 // Use assembly tests of the current runtime (ie kRuntimeISA) to determine the 50 // InstructionSetFeatures. This works around kernel bugs in AT_HWCAP and /proc/cpuinfo. 51 static Arm64FeaturesUniquePtr FromAssembly(); 52 53 // Use external cpu_features library. 54 static Arm64FeaturesUniquePtr FromCpuFeatures(); 55 56 // Return a new set of instruction set features, intersecting `this` features 57 // with hardware capabilities. 58 Arm64FeaturesUniquePtr IntersectWithHwcap() const; 59 60 bool Equals(const InstructionSetFeatures* other) const override; 61 62 // Note that newer CPUs do not have a53 erratum 835769 and 843419, 63 // so the two a53 fix features (fix_cortex_a53_835769 and fix_cortex_a53_843419) 64 // are not tested for HasAtLeast. 65 bool HasAtLeast(const InstructionSetFeatures* other) const override; 66 GetInstructionSet()67 InstructionSet GetInstructionSet() const override { 68 return InstructionSet::kArm64; 69 } 70 71 uint32_t AsBitmap() const override; 72 73 // Return a string of the form "a53" or "none". 74 std::string GetFeatureString() const override; 75 76 // Generate code addressing Cortex-A53 erratum 835769? NeedFixCortexA53_835769()77 bool NeedFixCortexA53_835769() const { 78 return fix_cortex_a53_835769_; 79 } 80 81 // Generate code addressing Cortex-A53 erratum 843419? NeedFixCortexA53_843419()82 bool NeedFixCortexA53_843419() const { 83 return fix_cortex_a53_843419_; 84 } 85 HasCRC()86 bool HasCRC() const { 87 return has_crc_; 88 } 89 HasLSE()90 bool HasLSE() const { 91 return has_lse_; 92 } 93 HasFP16()94 bool HasFP16() const { 95 return has_fp16_; 96 } 97 98 // Are Dot Product instructions (UDOT/SDOT) available? HasDotProd()99 bool HasDotProd() const { 100 return has_dotprod_; 101 } 102 HasSVE()103 bool HasSVE() const { 104 return kArm64AllowSVE && has_sve_; 105 } 106 GetSVEVectorLength()107 size_t GetSVEVectorLength() const { 108 // TODO: support SVE vector length detection. 109 return kArm64DefaultSVEVectorLength; 110 } 111 ~Arm64InstructionSetFeatures()112 virtual ~Arm64InstructionSetFeatures() {} 113 114 protected: 115 // Parse a vector of the form "a53" adding these to a new ArmInstructionSetFeatures. 116 std::unique_ptr<const InstructionSetFeatures> 117 AddFeaturesFromSplitString(const std::vector<std::string>& features, 118 std::string* error_msg) const override; 119 120 std::unique_ptr<const InstructionSetFeatures> 121 AddRuntimeDetectedFeatures(const InstructionSetFeatures *features) const override; 122 123 private: Arm64InstructionSetFeatures(bool needs_a53_835769_fix,bool needs_a53_843419_fix,bool has_crc,bool has_lse,bool has_fp16,bool has_dotprod,bool has_sve)124 Arm64InstructionSetFeatures(bool needs_a53_835769_fix, 125 bool needs_a53_843419_fix, 126 bool has_crc, 127 bool has_lse, 128 bool has_fp16, 129 bool has_dotprod, 130 bool has_sve) 131 : InstructionSetFeatures(), 132 fix_cortex_a53_835769_(needs_a53_835769_fix), 133 fix_cortex_a53_843419_(needs_a53_843419_fix), 134 has_crc_(has_crc), 135 has_lse_(has_lse), 136 has_fp16_(has_fp16), 137 has_dotprod_(has_dotprod), 138 has_sve_(has_sve) { 139 } 140 141 // Bitmap positions for encoding features as a bitmap. 142 enum { 143 kA53Bitfield = 1 << 0, 144 kCRCBitField = 1 << 1, 145 kLSEBitField = 1 << 2, 146 kFP16BitField = 1 << 3, 147 kDotProdBitField = 1 << 4, 148 kSVEBitField = 1 << 5, 149 }; 150 151 const bool fix_cortex_a53_835769_; 152 const bool fix_cortex_a53_843419_; 153 const bool has_crc_; // optional in ARMv8.0, mandatory in ARMv8.1. 154 const bool has_lse_; // ARMv8.1 Large System Extensions. 155 const bool has_fp16_; // ARMv8.2 FP16 extensions. 156 const bool has_dotprod_; // optional in ARMv8.2, mandatory in ARMv8.4. 157 const bool has_sve_; // optional in ARMv8.2. 158 159 DISALLOW_COPY_AND_ASSIGN(Arm64InstructionSetFeatures); 160 }; 161 162 } // namespace art 163 164 #endif // ART_RUNTIME_ARCH_ARM64_INSTRUCTION_SET_FEATURES_ARM64_H_ 165