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 class Arm64InstructionSetFeatures; 25 using Arm64FeaturesUniquePtr = std::unique_ptr<const Arm64InstructionSetFeatures>; 26 27 // Instruction set features relevant to the ARM64 architecture. 28 class Arm64InstructionSetFeatures final : public InstructionSetFeatures { 29 public: 30 // Process a CPU variant string like "krait" or "cortex-a15" and create InstructionSetFeatures. 31 static Arm64FeaturesUniquePtr FromVariant(const std::string& variant, std::string* error_msg); 32 33 // Parse a bitmap and create an InstructionSetFeatures. 34 static Arm64FeaturesUniquePtr FromBitmap(uint32_t bitmap); 35 36 // Turn C pre-processor #defines into the equivalent instruction set features. 37 static Arm64FeaturesUniquePtr FromCppDefines(); 38 39 // Process /proc/cpuinfo and use kRuntimeISA to produce InstructionSetFeatures. 40 static Arm64FeaturesUniquePtr FromCpuInfo(); 41 42 // Process the auxiliary vector AT_HWCAP entry and use kRuntimeISA to produce 43 // InstructionSetFeatures. 44 static Arm64FeaturesUniquePtr FromHwcap(); 45 46 // Use assembly tests of the current runtime (ie kRuntimeISA) to determine the 47 // InstructionSetFeatures. This works around kernel bugs in AT_HWCAP and /proc/cpuinfo. 48 static Arm64FeaturesUniquePtr FromAssembly(); 49 50 bool Equals(const InstructionSetFeatures* other) const override; 51 52 // Note that newer CPUs do not have a53 erratum 835769 and 843419, 53 // so the two a53 fix features (fix_cortex_a53_835769 and fix_cortex_a53_843419) 54 // are not tested for HasAtLeast. 55 bool HasAtLeast(const InstructionSetFeatures* other) const override; 56 GetInstructionSet()57 InstructionSet GetInstructionSet() const override { 58 return InstructionSet::kArm64; 59 } 60 61 uint32_t AsBitmap() const override; 62 63 // Return a string of the form "a53" or "none". 64 std::string GetFeatureString() const override; 65 66 // Generate code addressing Cortex-A53 erratum 835769? NeedFixCortexA53_835769()67 bool NeedFixCortexA53_835769() const { 68 return fix_cortex_a53_835769_; 69 } 70 71 // Generate code addressing Cortex-A53 erratum 843419? NeedFixCortexA53_843419()72 bool NeedFixCortexA53_843419() const { 73 return fix_cortex_a53_843419_; 74 } 75 HasCRC()76 bool HasCRC() const { 77 return has_crc_; 78 } 79 HasLSE()80 bool HasLSE() const { 81 return has_lse_; 82 } 83 HasFP16()84 bool HasFP16() const { 85 return has_fp16_; 86 } 87 88 // Are Dot Product instructions (UDOT/SDOT) available? HasDotProd()89 bool HasDotProd() const { 90 return has_dotprod_; 91 } 92 ~Arm64InstructionSetFeatures()93 virtual ~Arm64InstructionSetFeatures() {} 94 95 protected: 96 // Parse a vector of the form "a53" adding these to a new ArmInstructionSetFeatures. 97 std::unique_ptr<const InstructionSetFeatures> 98 AddFeaturesFromSplitString(const std::vector<std::string>& features, 99 std::string* error_msg) const override; 100 101 std::unique_ptr<const InstructionSetFeatures> 102 AddRuntimeDetectedFeatures(const InstructionSetFeatures *features) const override; 103 104 private: Arm64InstructionSetFeatures(bool needs_a53_835769_fix,bool needs_a53_843419_fix,bool has_crc,bool has_lse,bool has_fp16,bool has_dotprod)105 Arm64InstructionSetFeatures(bool needs_a53_835769_fix, 106 bool needs_a53_843419_fix, 107 bool has_crc, 108 bool has_lse, 109 bool has_fp16, 110 bool has_dotprod) 111 : InstructionSetFeatures(), 112 fix_cortex_a53_835769_(needs_a53_835769_fix), 113 fix_cortex_a53_843419_(needs_a53_843419_fix), 114 has_crc_(has_crc), 115 has_lse_(has_lse), 116 has_fp16_(has_fp16), 117 has_dotprod_(has_dotprod) { 118 } 119 120 // Bitmap positions for encoding features as a bitmap. 121 enum { 122 kA53Bitfield = 1 << 0, 123 kCRCBitField = 1 << 1, 124 kLSEBitField = 1 << 2, 125 kFP16BitField = 1 << 3, 126 kDotProdBitField = 1 << 4, 127 }; 128 129 const bool fix_cortex_a53_835769_; 130 const bool fix_cortex_a53_843419_; 131 const bool has_crc_; // optional in ARMv8.0, mandatory in ARMv8.1. 132 const bool has_lse_; // ARMv8.1 Large System Extensions. 133 const bool has_fp16_; // ARMv8.2 FP16 extensions. 134 const bool has_dotprod_; // optional in ARMv8.2, mandatory in ARMv8.4. 135 136 DISALLOW_COPY_AND_ASSIGN(Arm64InstructionSetFeatures); 137 }; 138 139 } // namespace art 140 141 #endif // ART_RUNTIME_ARCH_ARM64_INSTRUCTION_SET_FEATURES_ARM64_H_ 142