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_X86_64_INSTRUCTION_SET_FEATURES_X86_64_H_ 18 #define ART_RUNTIME_ARCH_X86_64_INSTRUCTION_SET_FEATURES_X86_64_H_ 19 20 #include "arch/x86/instruction_set_features_x86.h" 21 22 namespace art { 23 24 // Instruction set features relevant to the X86_64 architecture. 25 class X86_64InstructionSetFeatures FINAL : public X86InstructionSetFeatures { 26 public: 27 // Process a CPU variant string like "atom" or "nehalem" and create InstructionSetFeatures. 28 static const X86_64InstructionSetFeatures* FromVariant(const std::string& variant, 29 std::string* error_msg) { 30 return X86InstructionSetFeatures::FromVariant(variant, error_msg, true) 31 ->AsX86_64InstructionSetFeatures(); 32 } 33 34 // Parse a bitmap and create an InstructionSetFeatures. 35 static const X86_64InstructionSetFeatures* FromBitmap(uint32_t bitmap) { 36 return X86InstructionSetFeatures::FromBitmap(bitmap, true)->AsX86_64InstructionSetFeatures(); 37 } 38 39 // Turn C pre-processor #defines into the equivalent instruction set features. 40 static const X86_64InstructionSetFeatures* FromCppDefines() { 41 return X86InstructionSetFeatures::FromCppDefines(true)->AsX86_64InstructionSetFeatures(); 42 } 43 44 // Process /proc/cpuinfo and use kRuntimeISA to produce InstructionSetFeatures. 45 static const X86_64InstructionSetFeatures* FromCpuInfo() { 46 return X86InstructionSetFeatures::FromCpuInfo(true)->AsX86_64InstructionSetFeatures(); 47 } 48 49 // Process the auxiliary vector AT_HWCAP entry and use kRuntimeISA to produce 50 // InstructionSetFeatures. 51 static const X86_64InstructionSetFeatures* FromHwcap() { 52 return X86InstructionSetFeatures::FromHwcap(true)->AsX86_64InstructionSetFeatures(); 53 } 54 55 // Use assembly tests of the current runtime (ie kRuntimeISA) to determine the 56 // InstructionSetFeatures. This works around kernel bugs in AT_HWCAP and /proc/cpuinfo. 57 static const X86_64InstructionSetFeatures* FromAssembly() { 58 return X86InstructionSetFeatures::FromAssembly(true)->AsX86_64InstructionSetFeatures(); 59 } 60 61 InstructionSet GetInstructionSet() const OVERRIDE { 62 return kX86_64; 63 } 64 65 virtual ~X86_64InstructionSetFeatures() {} 66 67 protected: 68 // Parse a string of the form "ssse3" adding these to a new InstructionSetFeatures. 69 const InstructionSetFeatures* 70 AddFeaturesFromSplitString(const bool smp, const std::vector<std::string>& features, 71 std::string* error_msg) const OVERRIDE { 72 return X86InstructionSetFeatures::AddFeaturesFromSplitString(smp, features, true, error_msg); 73 } 74 75 private: 76 X86_64InstructionSetFeatures(bool smp, bool has_SSSE3, bool has_SSE4_1, bool has_SSE4_2, 77 bool has_AVX, bool has_AVX2, bool prefers_locked_add, 78 bool has_POPCNT) 79 : X86InstructionSetFeatures(smp, has_SSSE3, has_SSE4_1, has_SSE4_2, has_AVX, 80 has_AVX2, prefers_locked_add, has_POPCNT) { 81 } 82 83 friend class X86InstructionSetFeatures; 84 85 DISALLOW_COPY_AND_ASSIGN(X86_64InstructionSetFeatures); 86 }; 87 88 } // namespace art 89 90 #endif // ART_RUNTIME_ARCH_X86_64_INSTRUCTION_SET_FEATURES_X86_64_H_ 91