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 // Instruction set features relevant to the ARM64 architecture.
25 class Arm64InstructionSetFeatures FINAL : public InstructionSetFeatures {
26  public:
27   // Process a CPU variant string like "krait" or "cortex-a15" and create InstructionSetFeatures.
28   static const Arm64InstructionSetFeatures* FromVariant(const std::string& variant,
29                                                         std::string* error_msg);
30 
31   // Parse a bitmap and create an InstructionSetFeatures.
32   static const Arm64InstructionSetFeatures* FromBitmap(uint32_t bitmap);
33 
34   // Turn C pre-processor #defines into the equivalent instruction set features.
35   static const Arm64InstructionSetFeatures* FromCppDefines();
36 
37   // Process /proc/cpuinfo and use kRuntimeISA to produce InstructionSetFeatures.
38   static const Arm64InstructionSetFeatures* FromCpuInfo();
39 
40   // Process the auxiliary vector AT_HWCAP entry and use kRuntimeISA to produce
41   // InstructionSetFeatures.
42   static const Arm64InstructionSetFeatures* FromHwcap();
43 
44   // Use assembly tests of the current runtime (ie kRuntimeISA) to determine the
45   // InstructionSetFeatures. This works around kernel bugs in AT_HWCAP and /proc/cpuinfo.
46   static const Arm64InstructionSetFeatures* FromAssembly();
47 
48   bool Equals(const InstructionSetFeatures* other) const OVERRIDE;
49 
GetInstructionSet()50   InstructionSet GetInstructionSet() const OVERRIDE {
51     return kArm64;
52   }
53 
54   uint32_t AsBitmap() const OVERRIDE;
55 
56   // Return a string of the form "a53" or "none".
57   std::string GetFeatureString() const OVERRIDE;
58 
59   // Generate code addressing Cortex-A53 erratum 835769?
NeedFixCortexA53_835769()60   bool NeedFixCortexA53_835769() const {
61       return fix_cortex_a53_835769_;
62   }
63 
64   // Generate code addressing Cortex-A53 erratum 843419?
NeedFixCortexA53_843419()65   bool NeedFixCortexA53_843419() const {
66       return fix_cortex_a53_843419_;
67   }
68 
69   // NOTE: This flag can be tunned on a CPU basis. In general all ARMv8 CPUs
70   // should prefer the Acquire-Release semantics over the explicit DMBs when
71   // handling load/store-volatile. For a specific use case see the ARM64
72   // Optimizing backend.
PreferAcquireRelease()73   bool PreferAcquireRelease() const {
74     return true;
75   }
76 
~Arm64InstructionSetFeatures()77   virtual ~Arm64InstructionSetFeatures() {}
78 
79  protected:
80   // Parse a vector of the form "a53" adding these to a new ArmInstructionSetFeatures.
81   const InstructionSetFeatures*
82       AddFeaturesFromSplitString(const bool smp, const std::vector<std::string>& features,
83                                  std::string* error_msg) const OVERRIDE;
84 
85  private:
Arm64InstructionSetFeatures(bool smp,bool needs_a53_835769_fix,bool needs_a53_843419_fix)86   explicit Arm64InstructionSetFeatures(bool smp,
87                                        bool needs_a53_835769_fix,
88                                        bool needs_a53_843419_fix)
89       : InstructionSetFeatures(smp),
90         fix_cortex_a53_835769_(needs_a53_835769_fix),
91         fix_cortex_a53_843419_(needs_a53_843419_fix) {
92   }
93 
94   // Bitmap positions for encoding features as a bitmap.
95   enum {
96     kSmpBitfield = 1,
97     kA53Bitfield = 2,
98   };
99 
100   const bool fix_cortex_a53_835769_;
101   const bool fix_cortex_a53_843419_;
102 
103   DISALLOW_COPY_AND_ASSIGN(Arm64InstructionSetFeatures);
104 };
105 
106 }  // namespace art
107 
108 #endif  // ART_RUNTIME_ARCH_ARM64_INSTRUCTION_SET_FEATURES_ARM64_H_
109