1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2011 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker *
4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker *
8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker *
10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker */
16*795d594fSAndroid Build Coastguard Worker
17*795d594fSAndroid Build Coastguard Worker #include "instruction_set_features.h"
18*795d594fSAndroid Build Coastguard Worker
19*795d594fSAndroid Build Coastguard Worker #include <algorithm>
20*795d594fSAndroid Build Coastguard Worker #include <ostream>
21*795d594fSAndroid Build Coastguard Worker
22*795d594fSAndroid Build Coastguard Worker #include "android-base/strings.h"
23*795d594fSAndroid Build Coastguard Worker #include "arm/instruction_set_features_arm.h"
24*795d594fSAndroid Build Coastguard Worker #include "arm64/instruction_set_features_arm64.h"
25*795d594fSAndroid Build Coastguard Worker #include "base/casts.h"
26*795d594fSAndroid Build Coastguard Worker #include "base/utils.h"
27*795d594fSAndroid Build Coastguard Worker #include "riscv64/instruction_set_features_riscv64.h"
28*795d594fSAndroid Build Coastguard Worker #include "x86/instruction_set_features_x86.h"
29*795d594fSAndroid Build Coastguard Worker #include "x86_64/instruction_set_features_x86_64.h"
30*795d594fSAndroid Build Coastguard Worker
31*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN {
32*795d594fSAndroid Build Coastguard Worker
FromVariant(InstructionSet isa,const std::string & variant,std::string * error_msg)33*795d594fSAndroid Build Coastguard Worker std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::FromVariant(
34*795d594fSAndroid Build Coastguard Worker InstructionSet isa, const std::string& variant, std::string* error_msg) {
35*795d594fSAndroid Build Coastguard Worker switch (isa) {
36*795d594fSAndroid Build Coastguard Worker case InstructionSet::kArm:
37*795d594fSAndroid Build Coastguard Worker case InstructionSet::kThumb2:
38*795d594fSAndroid Build Coastguard Worker return ArmInstructionSetFeatures::FromVariant(variant, error_msg);
39*795d594fSAndroid Build Coastguard Worker case InstructionSet::kArm64:
40*795d594fSAndroid Build Coastguard Worker return Arm64InstructionSetFeatures::FromVariant(variant, error_msg);
41*795d594fSAndroid Build Coastguard Worker case InstructionSet::kRiscv64:
42*795d594fSAndroid Build Coastguard Worker return Riscv64InstructionSetFeatures::FromVariant(variant, error_msg);
43*795d594fSAndroid Build Coastguard Worker case InstructionSet::kX86:
44*795d594fSAndroid Build Coastguard Worker return X86InstructionSetFeatures::FromVariant(variant, error_msg);
45*795d594fSAndroid Build Coastguard Worker case InstructionSet::kX86_64:
46*795d594fSAndroid Build Coastguard Worker return X86_64InstructionSetFeatures::FromVariant(variant, error_msg);
47*795d594fSAndroid Build Coastguard Worker
48*795d594fSAndroid Build Coastguard Worker default:
49*795d594fSAndroid Build Coastguard Worker break;
50*795d594fSAndroid Build Coastguard Worker }
51*795d594fSAndroid Build Coastguard Worker UNIMPLEMENTED(FATAL) << isa;
52*795d594fSAndroid Build Coastguard Worker UNREACHABLE();
53*795d594fSAndroid Build Coastguard Worker }
54*795d594fSAndroid Build Coastguard Worker
FromVariantAndHwcap(InstructionSet isa,const std::string & variant,std::string * error_msg)55*795d594fSAndroid Build Coastguard Worker std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::FromVariantAndHwcap(
56*795d594fSAndroid Build Coastguard Worker InstructionSet isa, const std::string& variant, std::string* error_msg) {
57*795d594fSAndroid Build Coastguard Worker auto variant_features = FromVariant(isa, variant, error_msg);
58*795d594fSAndroid Build Coastguard Worker if (variant_features == nullptr) {
59*795d594fSAndroid Build Coastguard Worker return nullptr;
60*795d594fSAndroid Build Coastguard Worker }
61*795d594fSAndroid Build Coastguard Worker // Pixel3a is wrongly reporting itself as cortex-a75, so validate the features
62*795d594fSAndroid Build Coastguard Worker // with hwcaps.
63*795d594fSAndroid Build Coastguard Worker // Note that when cross-compiling on device (using dex2oat32 for compiling
64*795d594fSAndroid Build Coastguard Worker // arm64), the hwcaps will report that no feature is supported. This is
65*795d594fSAndroid Build Coastguard Worker // currently our best approach to be safe/correct. Maybe using the
66*795d594fSAndroid Build Coastguard Worker // cpu_features library could fix this issue.
67*795d594fSAndroid Build Coastguard Worker if (isa == InstructionSet::kArm64) {
68*795d594fSAndroid Build Coastguard Worker auto new_features = down_cast<const Arm64InstructionSetFeatures*>(variant_features.get())
69*795d594fSAndroid Build Coastguard Worker ->IntersectWithHwcap();
70*795d594fSAndroid Build Coastguard Worker if (!variant_features->Equals(new_features.get())) {
71*795d594fSAndroid Build Coastguard Worker LOG(WARNING) << "Mismatch between instruction set variant of device ("
72*795d594fSAndroid Build Coastguard Worker << *variant_features
73*795d594fSAndroid Build Coastguard Worker << ") and features returned by the hardware (" << *new_features << ")";
74*795d594fSAndroid Build Coastguard Worker }
75*795d594fSAndroid Build Coastguard Worker return new_features;
76*795d594fSAndroid Build Coastguard Worker } else {
77*795d594fSAndroid Build Coastguard Worker // TODO: Implement this validation on all architectures.
78*795d594fSAndroid Build Coastguard Worker return variant_features;
79*795d594fSAndroid Build Coastguard Worker }
80*795d594fSAndroid Build Coastguard Worker }
81*795d594fSAndroid Build Coastguard Worker
FromBitmap(InstructionSet isa,uint32_t bitmap)82*795d594fSAndroid Build Coastguard Worker std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::FromBitmap(InstructionSet isa,
83*795d594fSAndroid Build Coastguard Worker uint32_t bitmap) {
84*795d594fSAndroid Build Coastguard Worker std::unique_ptr<const InstructionSetFeatures> result;
85*795d594fSAndroid Build Coastguard Worker switch (isa) {
86*795d594fSAndroid Build Coastguard Worker case InstructionSet::kArm:
87*795d594fSAndroid Build Coastguard Worker case InstructionSet::kThumb2:
88*795d594fSAndroid Build Coastguard Worker result = ArmInstructionSetFeatures::FromBitmap(bitmap);
89*795d594fSAndroid Build Coastguard Worker break;
90*795d594fSAndroid Build Coastguard Worker case InstructionSet::kArm64:
91*795d594fSAndroid Build Coastguard Worker result = Arm64InstructionSetFeatures::FromBitmap(bitmap);
92*795d594fSAndroid Build Coastguard Worker break;
93*795d594fSAndroid Build Coastguard Worker case InstructionSet::kRiscv64:
94*795d594fSAndroid Build Coastguard Worker result = Riscv64InstructionSetFeatures::FromBitmap(bitmap);
95*795d594fSAndroid Build Coastguard Worker break;
96*795d594fSAndroid Build Coastguard Worker case InstructionSet::kX86:
97*795d594fSAndroid Build Coastguard Worker result = X86InstructionSetFeatures::FromBitmap(bitmap);
98*795d594fSAndroid Build Coastguard Worker break;
99*795d594fSAndroid Build Coastguard Worker case InstructionSet::kX86_64:
100*795d594fSAndroid Build Coastguard Worker result = X86_64InstructionSetFeatures::FromBitmap(bitmap);
101*795d594fSAndroid Build Coastguard Worker break;
102*795d594fSAndroid Build Coastguard Worker
103*795d594fSAndroid Build Coastguard Worker default:
104*795d594fSAndroid Build Coastguard Worker UNIMPLEMENTED(FATAL) << isa;
105*795d594fSAndroid Build Coastguard Worker UNREACHABLE();
106*795d594fSAndroid Build Coastguard Worker }
107*795d594fSAndroid Build Coastguard Worker CHECK_EQ(bitmap, result->AsBitmap());
108*795d594fSAndroid Build Coastguard Worker return result;
109*795d594fSAndroid Build Coastguard Worker }
110*795d594fSAndroid Build Coastguard Worker
FromCppDefines()111*795d594fSAndroid Build Coastguard Worker std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::FromCppDefines() {
112*795d594fSAndroid Build Coastguard Worker switch (kRuntimeISA) {
113*795d594fSAndroid Build Coastguard Worker case InstructionSet::kArm:
114*795d594fSAndroid Build Coastguard Worker case InstructionSet::kThumb2:
115*795d594fSAndroid Build Coastguard Worker return ArmInstructionSetFeatures::FromCppDefines();
116*795d594fSAndroid Build Coastguard Worker case InstructionSet::kArm64:
117*795d594fSAndroid Build Coastguard Worker return Arm64InstructionSetFeatures::FromCppDefines();
118*795d594fSAndroid Build Coastguard Worker case InstructionSet::kRiscv64:
119*795d594fSAndroid Build Coastguard Worker return Riscv64InstructionSetFeatures::FromCppDefines();
120*795d594fSAndroid Build Coastguard Worker case InstructionSet::kX86:
121*795d594fSAndroid Build Coastguard Worker return X86InstructionSetFeatures::FromCppDefines();
122*795d594fSAndroid Build Coastguard Worker case InstructionSet::kX86_64:
123*795d594fSAndroid Build Coastguard Worker return X86_64InstructionSetFeatures::FromCppDefines();
124*795d594fSAndroid Build Coastguard Worker
125*795d594fSAndroid Build Coastguard Worker default:
126*795d594fSAndroid Build Coastguard Worker break;
127*795d594fSAndroid Build Coastguard Worker }
128*795d594fSAndroid Build Coastguard Worker UNIMPLEMENTED(FATAL) << kRuntimeISA;
129*795d594fSAndroid Build Coastguard Worker UNREACHABLE();
130*795d594fSAndroid Build Coastguard Worker }
131*795d594fSAndroid Build Coastguard Worker
FromRuntimeDetection()132*795d594fSAndroid Build Coastguard Worker std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::FromRuntimeDetection() {
133*795d594fSAndroid Build Coastguard Worker switch (kRuntimeISA) {
134*795d594fSAndroid Build Coastguard Worker #ifdef ART_TARGET_ANDROID
135*795d594fSAndroid Build Coastguard Worker case InstructionSet::kArm64:
136*795d594fSAndroid Build Coastguard Worker return Arm64InstructionSetFeatures::FromHwcap();
137*795d594fSAndroid Build Coastguard Worker #endif
138*795d594fSAndroid Build Coastguard Worker default:
139*795d594fSAndroid Build Coastguard Worker return nullptr;
140*795d594fSAndroid Build Coastguard Worker }
141*795d594fSAndroid Build Coastguard Worker }
142*795d594fSAndroid Build Coastguard Worker
FromCpuInfo()143*795d594fSAndroid Build Coastguard Worker std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::FromCpuInfo() {
144*795d594fSAndroid Build Coastguard Worker switch (kRuntimeISA) {
145*795d594fSAndroid Build Coastguard Worker case InstructionSet::kArm:
146*795d594fSAndroid Build Coastguard Worker case InstructionSet::kThumb2:
147*795d594fSAndroid Build Coastguard Worker return ArmInstructionSetFeatures::FromCpuInfo();
148*795d594fSAndroid Build Coastguard Worker case InstructionSet::kArm64:
149*795d594fSAndroid Build Coastguard Worker return Arm64InstructionSetFeatures::FromCpuInfo();
150*795d594fSAndroid Build Coastguard Worker case InstructionSet::kRiscv64:
151*795d594fSAndroid Build Coastguard Worker return Riscv64InstructionSetFeatures::FromCpuInfo();
152*795d594fSAndroid Build Coastguard Worker case InstructionSet::kX86:
153*795d594fSAndroid Build Coastguard Worker return X86InstructionSetFeatures::FromCpuInfo();
154*795d594fSAndroid Build Coastguard Worker case InstructionSet::kX86_64:
155*795d594fSAndroid Build Coastguard Worker return X86_64InstructionSetFeatures::FromCpuInfo();
156*795d594fSAndroid Build Coastguard Worker
157*795d594fSAndroid Build Coastguard Worker default:
158*795d594fSAndroid Build Coastguard Worker break;
159*795d594fSAndroid Build Coastguard Worker }
160*795d594fSAndroid Build Coastguard Worker UNIMPLEMENTED(FATAL) << kRuntimeISA;
161*795d594fSAndroid Build Coastguard Worker UNREACHABLE();
162*795d594fSAndroid Build Coastguard Worker }
163*795d594fSAndroid Build Coastguard Worker
FromHwcap()164*795d594fSAndroid Build Coastguard Worker std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::FromHwcap() {
165*795d594fSAndroid Build Coastguard Worker switch (kRuntimeISA) {
166*795d594fSAndroid Build Coastguard Worker case InstructionSet::kArm:
167*795d594fSAndroid Build Coastguard Worker case InstructionSet::kThumb2:
168*795d594fSAndroid Build Coastguard Worker return ArmInstructionSetFeatures::FromHwcap();
169*795d594fSAndroid Build Coastguard Worker case InstructionSet::kArm64:
170*795d594fSAndroid Build Coastguard Worker return Arm64InstructionSetFeatures::FromHwcap();
171*795d594fSAndroid Build Coastguard Worker case InstructionSet::kRiscv64:
172*795d594fSAndroid Build Coastguard Worker return Riscv64InstructionSetFeatures::FromHwcap();
173*795d594fSAndroid Build Coastguard Worker case InstructionSet::kX86:
174*795d594fSAndroid Build Coastguard Worker return X86InstructionSetFeatures::FromHwcap();
175*795d594fSAndroid Build Coastguard Worker case InstructionSet::kX86_64:
176*795d594fSAndroid Build Coastguard Worker return X86_64InstructionSetFeatures::FromHwcap();
177*795d594fSAndroid Build Coastguard Worker
178*795d594fSAndroid Build Coastguard Worker default:
179*795d594fSAndroid Build Coastguard Worker break;
180*795d594fSAndroid Build Coastguard Worker }
181*795d594fSAndroid Build Coastguard Worker UNIMPLEMENTED(FATAL) << kRuntimeISA;
182*795d594fSAndroid Build Coastguard Worker UNREACHABLE();
183*795d594fSAndroid Build Coastguard Worker }
184*795d594fSAndroid Build Coastguard Worker
FromAssembly()185*795d594fSAndroid Build Coastguard Worker std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::FromAssembly() {
186*795d594fSAndroid Build Coastguard Worker switch (kRuntimeISA) {
187*795d594fSAndroid Build Coastguard Worker case InstructionSet::kArm:
188*795d594fSAndroid Build Coastguard Worker case InstructionSet::kThumb2:
189*795d594fSAndroid Build Coastguard Worker return ArmInstructionSetFeatures::FromAssembly();
190*795d594fSAndroid Build Coastguard Worker case InstructionSet::kArm64:
191*795d594fSAndroid Build Coastguard Worker return Arm64InstructionSetFeatures::FromAssembly();
192*795d594fSAndroid Build Coastguard Worker case InstructionSet::kRiscv64:
193*795d594fSAndroid Build Coastguard Worker return Riscv64InstructionSetFeatures::FromAssembly();
194*795d594fSAndroid Build Coastguard Worker case InstructionSet::kX86:
195*795d594fSAndroid Build Coastguard Worker return X86InstructionSetFeatures::FromAssembly();
196*795d594fSAndroid Build Coastguard Worker case InstructionSet::kX86_64:
197*795d594fSAndroid Build Coastguard Worker return X86_64InstructionSetFeatures::FromAssembly();
198*795d594fSAndroid Build Coastguard Worker
199*795d594fSAndroid Build Coastguard Worker default:
200*795d594fSAndroid Build Coastguard Worker break;
201*795d594fSAndroid Build Coastguard Worker }
202*795d594fSAndroid Build Coastguard Worker UNIMPLEMENTED(FATAL) << kRuntimeISA;
203*795d594fSAndroid Build Coastguard Worker UNREACHABLE();
204*795d594fSAndroid Build Coastguard Worker }
205*795d594fSAndroid Build Coastguard Worker
FromCpuFeatures()206*795d594fSAndroid Build Coastguard Worker std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::FromCpuFeatures() {
207*795d594fSAndroid Build Coastguard Worker switch (kRuntimeISA) {
208*795d594fSAndroid Build Coastguard Worker case InstructionSet::kArm:
209*795d594fSAndroid Build Coastguard Worker case InstructionSet::kThumb2:
210*795d594fSAndroid Build Coastguard Worker return ArmInstructionSetFeatures::FromCpuFeatures();
211*795d594fSAndroid Build Coastguard Worker case InstructionSet::kArm64:
212*795d594fSAndroid Build Coastguard Worker return Arm64InstructionSetFeatures::FromCpuFeatures();
213*795d594fSAndroid Build Coastguard Worker case InstructionSet::kRiscv64:
214*795d594fSAndroid Build Coastguard Worker return Riscv64InstructionSetFeatures::FromCpuFeatures();
215*795d594fSAndroid Build Coastguard Worker case InstructionSet::kX86:
216*795d594fSAndroid Build Coastguard Worker return X86InstructionSetFeatures::FromCpuFeatures();
217*795d594fSAndroid Build Coastguard Worker case InstructionSet::kX86_64:
218*795d594fSAndroid Build Coastguard Worker return X86_64InstructionSetFeatures::FromCpuFeatures();
219*795d594fSAndroid Build Coastguard Worker
220*795d594fSAndroid Build Coastguard Worker default:
221*795d594fSAndroid Build Coastguard Worker break;
222*795d594fSAndroid Build Coastguard Worker }
223*795d594fSAndroid Build Coastguard Worker UNIMPLEMENTED(FATAL) << kRuntimeISA;
224*795d594fSAndroid Build Coastguard Worker UNREACHABLE();
225*795d594fSAndroid Build Coastguard Worker }
226*795d594fSAndroid Build Coastguard Worker
AddFeaturesFromString(const std::string & feature_list,std::string * error_msg) const227*795d594fSAndroid Build Coastguard Worker std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::AddFeaturesFromString(
228*795d594fSAndroid Build Coastguard Worker const std::string& feature_list, /* out */ std::string* error_msg) const {
229*795d594fSAndroid Build Coastguard Worker std::vector<std::string> features;
230*795d594fSAndroid Build Coastguard Worker Split(feature_list, ',', &features);
231*795d594fSAndroid Build Coastguard Worker std::transform(std::begin(features), std::end(features), std::begin(features),
232*795d594fSAndroid Build Coastguard Worker [](const std::string &s) { return android::base::Trim(s); });
233*795d594fSAndroid Build Coastguard Worker auto empty_strings_begin = std::copy_if(std::begin(features), std::end(features),
234*795d594fSAndroid Build Coastguard Worker std::begin(features),
235*795d594fSAndroid Build Coastguard Worker [](const std::string& s) { return !s.empty(); });
236*795d594fSAndroid Build Coastguard Worker features.erase(empty_strings_begin, std::end(features));
237*795d594fSAndroid Build Coastguard Worker if (features.empty()) {
238*795d594fSAndroid Build Coastguard Worker *error_msg = "No instruction set features specified";
239*795d594fSAndroid Build Coastguard Worker return nullptr;
240*795d594fSAndroid Build Coastguard Worker }
241*795d594fSAndroid Build Coastguard Worker
242*795d594fSAndroid Build Coastguard Worker bool use_default = false;
243*795d594fSAndroid Build Coastguard Worker bool use_runtime_detection = false;
244*795d594fSAndroid Build Coastguard Worker for (const std::string& feature : features) {
245*795d594fSAndroid Build Coastguard Worker if (feature == "default") {
246*795d594fSAndroid Build Coastguard Worker if (features.size() > 1) {
247*795d594fSAndroid Build Coastguard Worker *error_msg = "Specific instruction set feature(s) cannot be used when 'default' is used.";
248*795d594fSAndroid Build Coastguard Worker return nullptr;
249*795d594fSAndroid Build Coastguard Worker }
250*795d594fSAndroid Build Coastguard Worker use_default = true;
251*795d594fSAndroid Build Coastguard Worker features.pop_back();
252*795d594fSAndroid Build Coastguard Worker break;
253*795d594fSAndroid Build Coastguard Worker } else if (feature == "runtime") {
254*795d594fSAndroid Build Coastguard Worker if (features.size() > 1) {
255*795d594fSAndroid Build Coastguard Worker *error_msg = "Specific instruction set feature(s) cannot be used when 'runtime' is used.";
256*795d594fSAndroid Build Coastguard Worker return nullptr;
257*795d594fSAndroid Build Coastguard Worker }
258*795d594fSAndroid Build Coastguard Worker use_runtime_detection = true;
259*795d594fSAndroid Build Coastguard Worker features.pop_back();
260*795d594fSAndroid Build Coastguard Worker break;
261*795d594fSAndroid Build Coastguard Worker }
262*795d594fSAndroid Build Coastguard Worker }
263*795d594fSAndroid Build Coastguard Worker // Expectation: "default" and "runtime" are standalone, no other feature names.
264*795d594fSAndroid Build Coastguard Worker // But an empty features vector after processing can also come along if the
265*795d594fSAndroid Build Coastguard Worker // handled feature names are the only ones in the list. So
266*795d594fSAndroid Build Coastguard Worker // logically, we check "default or runtime => features.empty."
267*795d594fSAndroid Build Coastguard Worker DCHECK((!use_default && !use_runtime_detection) || features.empty());
268*795d594fSAndroid Build Coastguard Worker
269*795d594fSAndroid Build Coastguard Worker std::unique_ptr<const InstructionSetFeatures> runtime_detected_features;
270*795d594fSAndroid Build Coastguard Worker if (use_runtime_detection) {
271*795d594fSAndroid Build Coastguard Worker runtime_detected_features = FromRuntimeDetection();
272*795d594fSAndroid Build Coastguard Worker }
273*795d594fSAndroid Build Coastguard Worker
274*795d594fSAndroid Build Coastguard Worker if (runtime_detected_features != nullptr) {
275*795d594fSAndroid Build Coastguard Worker return AddRuntimeDetectedFeatures(runtime_detected_features.get());
276*795d594fSAndroid Build Coastguard Worker } else {
277*795d594fSAndroid Build Coastguard Worker return AddFeaturesFromSplitString(features, error_msg);
278*795d594fSAndroid Build Coastguard Worker }
279*795d594fSAndroid Build Coastguard Worker }
280*795d594fSAndroid Build Coastguard Worker
AsArmInstructionSetFeatures() const281*795d594fSAndroid Build Coastguard Worker const ArmInstructionSetFeatures* InstructionSetFeatures::AsArmInstructionSetFeatures() const {
282*795d594fSAndroid Build Coastguard Worker DCHECK_EQ(InstructionSet::kArm, GetInstructionSet());
283*795d594fSAndroid Build Coastguard Worker return down_cast<const ArmInstructionSetFeatures*>(this);
284*795d594fSAndroid Build Coastguard Worker }
285*795d594fSAndroid Build Coastguard Worker
AsArm64InstructionSetFeatures() const286*795d594fSAndroid Build Coastguard Worker const Arm64InstructionSetFeatures* InstructionSetFeatures::AsArm64InstructionSetFeatures() const {
287*795d594fSAndroid Build Coastguard Worker DCHECK_EQ(InstructionSet::kArm64, GetInstructionSet());
288*795d594fSAndroid Build Coastguard Worker return down_cast<const Arm64InstructionSetFeatures*>(this);
289*795d594fSAndroid Build Coastguard Worker }
290*795d594fSAndroid Build Coastguard Worker
AsRiscv64InstructionSetFeatures() const291*795d594fSAndroid Build Coastguard Worker const Riscv64InstructionSetFeatures* InstructionSetFeatures::AsRiscv64InstructionSetFeatures()
292*795d594fSAndroid Build Coastguard Worker const {
293*795d594fSAndroid Build Coastguard Worker DCHECK_EQ(InstructionSet::kRiscv64, GetInstructionSet());
294*795d594fSAndroid Build Coastguard Worker return down_cast<const Riscv64InstructionSetFeatures*>(this);
295*795d594fSAndroid Build Coastguard Worker }
296*795d594fSAndroid Build Coastguard Worker
AsX86InstructionSetFeatures() const297*795d594fSAndroid Build Coastguard Worker const X86InstructionSetFeatures* InstructionSetFeatures::AsX86InstructionSetFeatures() const {
298*795d594fSAndroid Build Coastguard Worker DCHECK(InstructionSet::kX86 == GetInstructionSet() ||
299*795d594fSAndroid Build Coastguard Worker InstructionSet::kX86_64 == GetInstructionSet());
300*795d594fSAndroid Build Coastguard Worker return down_cast<const X86InstructionSetFeatures*>(this);
301*795d594fSAndroid Build Coastguard Worker }
302*795d594fSAndroid Build Coastguard Worker
AsX86_64InstructionSetFeatures() const303*795d594fSAndroid Build Coastguard Worker const X86_64InstructionSetFeatures* InstructionSetFeatures::AsX86_64InstructionSetFeatures() const {
304*795d594fSAndroid Build Coastguard Worker DCHECK_EQ(InstructionSet::kX86_64, GetInstructionSet());
305*795d594fSAndroid Build Coastguard Worker return down_cast<const X86_64InstructionSetFeatures*>(this);
306*795d594fSAndroid Build Coastguard Worker }
307*795d594fSAndroid Build Coastguard Worker
FindVariantInArray(const char * const variants[],size_t num_variants,const std::string & variant)308*795d594fSAndroid Build Coastguard Worker bool InstructionSetFeatures::FindVariantInArray(const char* const variants[], size_t num_variants,
309*795d594fSAndroid Build Coastguard Worker const std::string& variant) {
310*795d594fSAndroid Build Coastguard Worker const char* const * begin = variants;
311*795d594fSAndroid Build Coastguard Worker const char* const * end = begin + num_variants;
312*795d594fSAndroid Build Coastguard Worker return std::find(begin, end, variant) != end;
313*795d594fSAndroid Build Coastguard Worker }
314*795d594fSAndroid Build Coastguard Worker
AddRuntimeDetectedFeatures(const InstructionSetFeatures * features) const315*795d594fSAndroid Build Coastguard Worker std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::AddRuntimeDetectedFeatures(
316*795d594fSAndroid Build Coastguard Worker [[maybe_unused]] const InstructionSetFeatures* features) const {
317*795d594fSAndroid Build Coastguard Worker UNIMPLEMENTED(FATAL) << kRuntimeISA;
318*795d594fSAndroid Build Coastguard Worker UNREACHABLE();
319*795d594fSAndroid Build Coastguard Worker }
320*795d594fSAndroid Build Coastguard Worker
operator <<(std::ostream & os,const InstructionSetFeatures & rhs)321*795d594fSAndroid Build Coastguard Worker std::ostream& operator<<(std::ostream& os, const InstructionSetFeatures& rhs) {
322*795d594fSAndroid Build Coastguard Worker os << "ISA: " << rhs.GetInstructionSet() << " Feature string: " << rhs.GetFeatureString();
323*795d594fSAndroid Build Coastguard Worker return os;
324*795d594fSAndroid Build Coastguard Worker }
325*795d594fSAndroid Build Coastguard Worker
326*795d594fSAndroid Build Coastguard Worker } // namespace art
327