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