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_ARM_INSTRUCTION_SET_FEATURES_ARM_H_ 18 #define ART_RUNTIME_ARCH_ARM_INSTRUCTION_SET_FEATURES_ARM_H_ 19 20 #include "arch/instruction_set_features.h" 21 22 namespace art { 23 24 class ArmInstructionSetFeatures; 25 using ArmFeaturesUniquePtr = std::unique_ptr<const ArmInstructionSetFeatures>; 26 27 // Instruction set features relevant to the ARM architecture. 28 class ArmInstructionSetFeatures final : public InstructionSetFeatures { 29 public: 30 // Process a CPU variant string like "krait" or "cortex-a15" and create InstructionSetFeatures. 31 static ArmFeaturesUniquePtr FromVariant(const std::string& variant, std::string* error_msg); 32 33 // Parse a bitmap and create an InstructionSetFeatures. 34 static ArmFeaturesUniquePtr FromBitmap(uint32_t bitmap); 35 36 // Turn C pre-processor #defines into the equivalent instruction set features. 37 static ArmFeaturesUniquePtr FromCppDefines(); 38 39 // Process /proc/cpuinfo and use kRuntimeISA to produce InstructionSetFeatures. 40 static ArmFeaturesUniquePtr FromCpuInfo(); 41 42 // Process the auxiliary vector AT_HWCAP entry and use kRuntimeISA to produce 43 // InstructionSetFeatures. 44 static ArmFeaturesUniquePtr 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 ArmFeaturesUniquePtr FromAssembly(); 49 50 // Use external cpu_features library. 51 static ArmFeaturesUniquePtr FromCpuFeatures(); 52 53 bool Equals(const InstructionSetFeatures* other) const override; 54 55 bool HasAtLeast(const InstructionSetFeatures* other) const override; 56 GetInstructionSet()57 InstructionSet GetInstructionSet() const override { 58 return InstructionSet::kArm; 59 } 60 61 uint32_t AsBitmap() const override; 62 63 // Return a string of the form "div,lpae" or "none". 64 std::string GetFeatureString() const override; 65 66 // Is the divide instruction feature enabled? HasDivideInstruction()67 bool HasDivideInstruction() const { 68 return has_div_; 69 } 70 71 // Are the ldrd and strd instructions atomic? This is commonly true when the Large Physical 72 // Address Extension (LPAE) is present. HasAtomicLdrdAndStrd()73 bool HasAtomicLdrdAndStrd() const { 74 return has_atomic_ldrd_strd_; 75 } 76 77 // Are ARMv8-A instructions available? HasARMv8AInstructions()78 bool HasARMv8AInstructions() const { 79 return has_armv8a_; 80 } 81 ~ArmInstructionSetFeatures()82 virtual ~ArmInstructionSetFeatures() {} 83 84 protected: 85 // Parse a vector of the form "div", "lpae" adding these to a new ArmInstructionSetFeatures. 86 std::unique_ptr<const InstructionSetFeatures> 87 AddFeaturesFromSplitString(const std::vector<std::string>& features, 88 std::string* error_msg) const override; 89 90 private: ArmInstructionSetFeatures(bool has_div,bool has_atomic_ldrd_strd,bool has_armv8a)91 ArmInstructionSetFeatures(bool has_div, 92 bool has_atomic_ldrd_strd, 93 bool has_armv8a) 94 : InstructionSetFeatures(), 95 has_div_(has_div), 96 has_atomic_ldrd_strd_(has_atomic_ldrd_strd), 97 has_armv8a_(has_armv8a) {} 98 99 // Bitmap positions for encoding features as a bitmap. 100 enum { 101 kDivBitfield = 1 << 0, 102 kAtomicLdrdStrdBitfield = 1 << 1, 103 kARMv8A = 1 << 2, 104 }; 105 106 const bool has_div_; 107 const bool has_atomic_ldrd_strd_; 108 const bool has_armv8a_; 109 110 DISALLOW_COPY_AND_ASSIGN(ArmInstructionSetFeatures); 111 }; 112 113 } // namespace art 114 115 #endif // ART_RUNTIME_ARCH_ARM_INSTRUCTION_SET_FEATURES_ARM_H_ 116