• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
GetInstructionSet()52   InstructionSet GetInstructionSet() const OVERRIDE {
53     return kArm64;
54   }
55 
56   uint32_t AsBitmap() const OVERRIDE;
57 
58   // Return a string of the form "a53" or "none".
59   std::string GetFeatureString() const OVERRIDE;
60 
61   // Generate code addressing Cortex-A53 erratum 835769?
NeedFixCortexA53_835769()62   bool NeedFixCortexA53_835769() const {
63       return fix_cortex_a53_835769_;
64   }
65 
66   // Generate code addressing Cortex-A53 erratum 843419?
NeedFixCortexA53_843419()67   bool NeedFixCortexA53_843419() const {
68       return fix_cortex_a53_843419_;
69   }
70 
~Arm64InstructionSetFeatures()71   virtual ~Arm64InstructionSetFeatures() {}
72 
73  protected:
74   // Parse a vector of the form "a53" adding these to a new ArmInstructionSetFeatures.
75   std::unique_ptr<const InstructionSetFeatures>
76       AddFeaturesFromSplitString(const std::vector<std::string>& features,
77                                  std::string* error_msg) const OVERRIDE;
78 
79  private:
Arm64InstructionSetFeatures(bool needs_a53_835769_fix,bool needs_a53_843419_fix)80   Arm64InstructionSetFeatures(bool needs_a53_835769_fix, bool needs_a53_843419_fix)
81       : InstructionSetFeatures(),
82         fix_cortex_a53_835769_(needs_a53_835769_fix),
83         fix_cortex_a53_843419_(needs_a53_843419_fix) {
84   }
85 
86   // Bitmap positions for encoding features as a bitmap.
87   enum {
88     kA53Bitfield = 1 << 0,
89   };
90 
91   const bool fix_cortex_a53_835769_;
92   const bool fix_cortex_a53_843419_;
93 
94   DISALLOW_COPY_AND_ASSIGN(Arm64InstructionSetFeatures);
95 };
96 
97 }  // namespace art
98 
99 #endif  // ART_RUNTIME_ARCH_ARM64_INSTRUCTION_SET_FEATURES_ARM64_H_
100