Home | History | Annotate | Download | only in x86
      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_INSTRUCTION_SET_FEATURES_X86_H_
     18 #define ART_RUNTIME_ARCH_X86_INSTRUCTION_SET_FEATURES_X86_H_
     19 
     20 #include "arch/instruction_set_features.h"
     21 
     22 namespace art {
     23 
     24 // Instruction set features relevant to the X86 architecture.
     25 class X86InstructionSetFeatures : public InstructionSetFeatures {
     26  public:
     27   // Process a CPU variant string like "atom" or "nehalem" and create InstructionSetFeatures.
     28   static const X86InstructionSetFeatures* FromVariant(const std::string& variant,
     29                                                         std::string* error_msg,
     30                                                         bool x86_64 = false);
     31 
     32   // Parse a bitmap and create an InstructionSetFeatures.
     33   static const X86InstructionSetFeatures* FromBitmap(uint32_t bitmap, bool x86_64 = false);
     34 
     35   // Turn C pre-processor #defines into the equivalent instruction set features.
     36   static const X86InstructionSetFeatures* FromCppDefines(bool x86_64 = false);
     37 
     38   // Process /proc/cpuinfo and use kRuntimeISA to produce InstructionSetFeatures.
     39   static const X86InstructionSetFeatures* FromCpuInfo(bool x86_64 = false);
     40 
     41   // Process the auxiliary vector AT_HWCAP entry and use kRuntimeISA to produce
     42   // InstructionSetFeatures.
     43   static const X86InstructionSetFeatures* FromHwcap(bool x86_64 = false);
     44 
     45   // Use assembly tests of the current runtime (ie kRuntimeISA) to determine the
     46   // InstructionSetFeatures. This works around kernel bugs in AT_HWCAP and /proc/cpuinfo.
     47   static const X86InstructionSetFeatures* FromAssembly(bool x86_64 = false);
     48 
     49   bool Equals(const InstructionSetFeatures* other) const OVERRIDE;
     50 
     51   virtual InstructionSet GetInstructionSet() const OVERRIDE {
     52     return kX86;
     53   }
     54 
     55   uint32_t AsBitmap() const OVERRIDE;
     56 
     57   std::string GetFeatureString() const OVERRIDE;
     58 
     59   virtual ~X86InstructionSetFeatures() {}
     60 
     61   bool HasSSE4_1() const { return has_SSE4_1_; }
     62 
     63  protected:
     64   // Parse a string of the form "ssse3" adding these to a new InstructionSetFeatures.
     65   virtual const InstructionSetFeatures*
     66       AddFeaturesFromSplitString(const bool smp, const std::vector<std::string>& features,
     67                                  std::string* error_msg) const OVERRIDE {
     68     return AddFeaturesFromSplitString(smp, features, false, error_msg);
     69   }
     70 
     71   const InstructionSetFeatures*
     72       AddFeaturesFromSplitString(const bool smp, const std::vector<std::string>& features,
     73                                  bool x86_64, std::string* error_msg) const;
     74 
     75   X86InstructionSetFeatures(bool smp, bool has_SSSE3, bool has_SSE4_1, bool has_SSE4_2,
     76                             bool has_AVX, bool has_AVX2)
     77       : InstructionSetFeatures(smp), has_SSSE3_(has_SSSE3), has_SSE4_1_(has_SSE4_1),
     78         has_SSE4_2_(has_SSE4_2), has_AVX_(has_AVX), has_AVX2_(has_AVX2) {
     79   }
     80 
     81  private:
     82   // Bitmap positions for encoding features as a bitmap.
     83   enum {
     84     kSmpBitfield = 1,
     85     kSsse3Bitfield = 2,
     86     kSse4_1Bitfield = 4,
     87     kSse4_2Bitfield = 8,
     88     kAvxBitfield = 16,
     89     kAvx2Bitfield = 32,
     90   };
     91 
     92   const bool has_SSSE3_;   // x86 128bit SIMD - Supplemental SSE.
     93   const bool has_SSE4_1_;  // x86 128bit SIMD SSE4.1.
     94   const bool has_SSE4_2_;  // x86 128bit SIMD SSE4.2.
     95   const bool has_AVX_;     // x86 256bit SIMD AVX.
     96   const bool has_AVX2_;    // x86 256bit SIMD AVX 2.0.
     97 
     98   DISALLOW_COPY_AND_ASSIGN(X86InstructionSetFeatures);
     99 };
    100 
    101 }  // namespace art
    102 
    103 #endif  // ART_RUNTIME_ARCH_X86_INSTRUCTION_SET_FEATURES_X86_H_
    104