blob: 2c6e6995bcd25dcde648ce75e6d7d86acd522696 [file] [log] [blame]
Ian Rogersd582fa42014-11-05 23:46:43 -08001/*
2 * Copyright (C) 2011 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_INSTRUCTION_SET_FEATURES_H_
18#define ART_RUNTIME_ARCH_INSTRUCTION_SET_FEATURES_H_
19
20#include <ostream>
21#include <vector>
22
23#include "base/macros.h"
24#include "instruction_set.h"
25
26namespace art {
27
28class ArmInstructionSetFeatures;
29class Arm64InstructionSetFeatures;
30class MipsInstructionSetFeatures;
31class X86InstructionSetFeatures;
32class X86_64InstructionSetFeatures;
33
34// Abstraction used to describe features of a different instruction sets.
35class InstructionSetFeatures {
36 public:
37 // Process a CPU variant string for the given ISA and create an InstructionSetFeatures.
38 static const InstructionSetFeatures* FromVariant(InstructionSet isa,
39 const std::string& variant,
40 std::string* error_msg);
41
42 // Parse a bitmap for the given isa and create an InstructionSetFeatures.
43 static const InstructionSetFeatures* FromBitmap(InstructionSet isa, uint32_t bitmap);
44
45 // Turn C pre-processor #defines into the equivalent instruction set features for kRuntimeISA.
46 static const InstructionSetFeatures* FromCppDefines();
47
48 // Process /proc/cpuinfo and use kRuntimeISA to produce InstructionSetFeatures.
49 static const InstructionSetFeatures* FromCpuInfo();
50
51 // Process the auxiliary vector AT_HWCAP entry and use kRuntimeISA to produce
52 // InstructionSetFeatures.
53 static const InstructionSetFeatures* FromHwcap();
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 InstructionSetFeatures* FromAssembly();
58
59 // Parse a string of the form "div,-atomic_ldrd_strd" adding and removing these features to
60 // create a new InstructionSetFeatures.
61 const InstructionSetFeatures* AddFeaturesFromString(const std::string& feature_list,
62 std::string* error_msg) const WARN_UNUSED;
63
64 // Are these features the same as the other given features?
65 virtual bool Equals(const InstructionSetFeatures* other) const = 0;
66
67 // Return the ISA these features relate to.
68 virtual InstructionSet GetInstructionSet() const = 0;
69
70 // Return a bitmap that represents the features. ISA specific.
71 virtual uint32_t AsBitmap() const = 0;
72
73 // Return a string of the form "div,lpae" or "none".
74 virtual std::string GetFeatureString() const = 0;
75
76 // Does the instruction set variant require instructions for correctness with SMP?
77 bool IsSmp() const {
78 return smp_;
79 }
80
81 // Down cast this ArmInstructionFeatures.
82 const ArmInstructionSetFeatures* AsArmInstructionSetFeatures() const;
83
84 // Down cast this Arm64InstructionFeatures.
85 const Arm64InstructionSetFeatures* AsArm64InstructionSetFeatures() const;
86
87 // Down cast this MipsInstructionFeatures.
88 const MipsInstructionSetFeatures* AsMipsInstructionSetFeatures() const;
89
90 // Down cast this X86InstructionFeatures.
91 const X86InstructionSetFeatures* AsX86InstructionSetFeatures() const;
92
93 // Down cast this X86_64InstructionFeatures.
94 const X86_64InstructionSetFeatures* AsX86_64InstructionSetFeatures() const;
95
96 virtual ~InstructionSetFeatures() {}
97
98 protected:
99 explicit InstructionSetFeatures(bool smp) : smp_(smp) {}
100
101 // Returns true if variant appears in the array variants.
102 static bool FindVariantInArray(const char* variants[], size_t num_variants,
103 const std::string& variant);
104
105 // Add architecture specific features in sub-classes.
106 virtual const InstructionSetFeatures*
107 AddFeaturesFromSplitString(bool smp, const std::vector<std::string>& features,
108 std::string* error_msg) const = 0;
109
110 private:
111 const bool smp_;
112
113 DISALLOW_COPY_AND_ASSIGN(InstructionSetFeatures);
114};
115std::ostream& operator<<(std::ostream& os, const InstructionSetFeatures& rhs);
116
117} // namespace art
118
119#endif // ART_RUNTIME_ARCH_INSTRUCTION_SET_FEATURES_H_