Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
xueliang.zhong | 7f88c1a | 2018-11-06 11:42:41 +0000 | [diff] [blame] | 17 | #include <algorithm> |
| 18 | |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 19 | #include "instruction_set_features.h" |
| 20 | |
Andreas Gampe | 8764dc3 | 2019-01-07 15:20:12 -0800 | [diff] [blame] | 21 | #include <algorithm> |
| 22 | #include <ostream> |
| 23 | |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 24 | #include "android-base/strings.h" |
| 25 | |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 26 | #include "base/casts.h" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 27 | #include "base/utils.h" |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 28 | |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 29 | #include "arm/instruction_set_features_arm.h" |
| 30 | #include "arm64/instruction_set_features_arm64.h" |
| 31 | #include "mips/instruction_set_features_mips.h" |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 32 | #include "mips64/instruction_set_features_mips64.h" |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 33 | #include "x86/instruction_set_features_x86.h" |
| 34 | #include "x86_64/instruction_set_features_x86_64.h" |
| 35 | |
| 36 | namespace art { |
| 37 | |
Andreas Gampe | 0415b4e | 2015-01-06 15:17:07 -0800 | [diff] [blame] | 38 | std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::FromVariant( |
| 39 | InstructionSet isa, const std::string& variant, std::string* error_msg) { |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 40 | switch (isa) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 41 | case InstructionSet::kArm: |
| 42 | case InstructionSet::kThumb2: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 43 | return ArmInstructionSetFeatures::FromVariant(variant, error_msg); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 44 | case InstructionSet::kArm64: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 45 | return Arm64InstructionSetFeatures::FromVariant(variant, error_msg); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 46 | case InstructionSet::kMips: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 47 | return MipsInstructionSetFeatures::FromVariant(variant, error_msg); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 48 | case InstructionSet::kMips64: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 49 | return Mips64InstructionSetFeatures::FromVariant(variant, error_msg); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 50 | case InstructionSet::kX86: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 51 | return X86InstructionSetFeatures::FromVariant(variant, error_msg); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 52 | case InstructionSet::kX86_64: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 53 | return X86_64InstructionSetFeatures::FromVariant(variant, error_msg); |
| 54 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 55 | case InstructionSet::kNone: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 56 | break; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 57 | } |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 58 | UNIMPLEMENTED(FATAL) << isa; |
| 59 | UNREACHABLE(); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Andreas Gampe | 0415b4e | 2015-01-06 15:17:07 -0800 | [diff] [blame] | 62 | std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::FromBitmap(InstructionSet isa, |
| 63 | uint32_t bitmap) { |
| 64 | std::unique_ptr<const InstructionSetFeatures> result; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 65 | switch (isa) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 66 | case InstructionSet::kArm: |
| 67 | case InstructionSet::kThumb2: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 68 | result = ArmInstructionSetFeatures::FromBitmap(bitmap); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 69 | break; |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 70 | case InstructionSet::kArm64: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 71 | result = Arm64InstructionSetFeatures::FromBitmap(bitmap); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 72 | break; |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 73 | case InstructionSet::kMips: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 74 | result = MipsInstructionSetFeatures::FromBitmap(bitmap); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 75 | break; |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 76 | case InstructionSet::kMips64: |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 77 | result = Mips64InstructionSetFeatures::FromBitmap(bitmap); |
| 78 | break; |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 79 | case InstructionSet::kX86: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 80 | result = X86InstructionSetFeatures::FromBitmap(bitmap); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 81 | break; |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 82 | case InstructionSet::kX86_64: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 83 | result = X86_64InstructionSetFeatures::FromBitmap(bitmap); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 84 | break; |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 85 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 86 | case InstructionSet::kNone: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 87 | default: |
| 88 | UNIMPLEMENTED(FATAL) << isa; |
| 89 | UNREACHABLE(); |
| 90 | } |
| 91 | CHECK_EQ(bitmap, result->AsBitmap()); |
| 92 | return result; |
| 93 | } |
| 94 | |
Andreas Gampe | 0415b4e | 2015-01-06 15:17:07 -0800 | [diff] [blame] | 95 | std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::FromCppDefines() { |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 96 | switch (kRuntimeISA) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 97 | case InstructionSet::kArm: |
| 98 | case InstructionSet::kThumb2: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 99 | return ArmInstructionSetFeatures::FromCppDefines(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 100 | case InstructionSet::kArm64: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 101 | return Arm64InstructionSetFeatures::FromCppDefines(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 102 | case InstructionSet::kMips: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 103 | return MipsInstructionSetFeatures::FromCppDefines(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 104 | case InstructionSet::kMips64: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 105 | return Mips64InstructionSetFeatures::FromCppDefines(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 106 | case InstructionSet::kX86: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 107 | return X86InstructionSetFeatures::FromCppDefines(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 108 | case InstructionSet::kX86_64: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 109 | return X86_64InstructionSetFeatures::FromCppDefines(); |
| 110 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 111 | case InstructionSet::kNone: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 112 | break; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 113 | } |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 114 | UNIMPLEMENTED(FATAL) << kRuntimeISA; |
| 115 | UNREACHABLE(); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 116 | } |
| 117 | |
xueliang.zhong | 7f88c1a | 2018-11-06 11:42:41 +0000 | [diff] [blame] | 118 | std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::FromRuntimeDetection() { |
| 119 | switch (kRuntimeISA) { |
| 120 | #ifdef ART_TARGET_ANDROID |
| 121 | case InstructionSet::kArm64: |
| 122 | return Arm64InstructionSetFeatures::FromHwcap(); |
| 123 | #endif |
| 124 | default: |
| 125 | return nullptr; |
| 126 | } |
| 127 | } |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 128 | |
Andreas Gampe | 0415b4e | 2015-01-06 15:17:07 -0800 | [diff] [blame] | 129 | std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::FromCpuInfo() { |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 130 | switch (kRuntimeISA) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 131 | case InstructionSet::kArm: |
| 132 | case InstructionSet::kThumb2: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 133 | return ArmInstructionSetFeatures::FromCpuInfo(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 134 | case InstructionSet::kArm64: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 135 | return Arm64InstructionSetFeatures::FromCpuInfo(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 136 | case InstructionSet::kMips: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 137 | return MipsInstructionSetFeatures::FromCpuInfo(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 138 | case InstructionSet::kMips64: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 139 | return Mips64InstructionSetFeatures::FromCpuInfo(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 140 | case InstructionSet::kX86: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 141 | return X86InstructionSetFeatures::FromCpuInfo(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 142 | case InstructionSet::kX86_64: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 143 | return X86_64InstructionSetFeatures::FromCpuInfo(); |
| 144 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 145 | case InstructionSet::kNone: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 146 | break; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 147 | } |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 148 | UNIMPLEMENTED(FATAL) << kRuntimeISA; |
| 149 | UNREACHABLE(); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 150 | } |
| 151 | |
Andreas Gampe | 0415b4e | 2015-01-06 15:17:07 -0800 | [diff] [blame] | 152 | std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::FromHwcap() { |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 153 | switch (kRuntimeISA) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 154 | case InstructionSet::kArm: |
| 155 | case InstructionSet::kThumb2: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 156 | return ArmInstructionSetFeatures::FromHwcap(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 157 | case InstructionSet::kArm64: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 158 | return Arm64InstructionSetFeatures::FromHwcap(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 159 | case InstructionSet::kMips: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 160 | return MipsInstructionSetFeatures::FromHwcap(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 161 | case InstructionSet::kMips64: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 162 | return Mips64InstructionSetFeatures::FromHwcap(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 163 | case InstructionSet::kX86: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 164 | return X86InstructionSetFeatures::FromHwcap(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 165 | case InstructionSet::kX86_64: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 166 | return X86_64InstructionSetFeatures::FromHwcap(); |
| 167 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 168 | case InstructionSet::kNone: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 169 | break; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 170 | } |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 171 | UNIMPLEMENTED(FATAL) << kRuntimeISA; |
| 172 | UNREACHABLE(); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 173 | } |
| 174 | |
Andreas Gampe | 0415b4e | 2015-01-06 15:17:07 -0800 | [diff] [blame] | 175 | std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::FromAssembly() { |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 176 | switch (kRuntimeISA) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 177 | case InstructionSet::kArm: |
| 178 | case InstructionSet::kThumb2: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 179 | return ArmInstructionSetFeatures::FromAssembly(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 180 | case InstructionSet::kArm64: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 181 | return Arm64InstructionSetFeatures::FromAssembly(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 182 | case InstructionSet::kMips: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 183 | return MipsInstructionSetFeatures::FromAssembly(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 184 | case InstructionSet::kMips64: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 185 | return Mips64InstructionSetFeatures::FromAssembly(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 186 | case InstructionSet::kX86: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 187 | return X86InstructionSetFeatures::FromAssembly(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 188 | case InstructionSet::kX86_64: |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 189 | return X86_64InstructionSetFeatures::FromAssembly(); |
| 190 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 191 | case InstructionSet::kNone: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 192 | break; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 193 | } |
Andreas Gampe | 8d01c37 | 2017-05-30 13:21:28 -0700 | [diff] [blame] | 194 | UNIMPLEMENTED(FATAL) << kRuntimeISA; |
| 195 | UNREACHABLE(); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 196 | } |
| 197 | |
Andreas Gampe | 0415b4e | 2015-01-06 15:17:07 -0800 | [diff] [blame] | 198 | std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::AddFeaturesFromString( |
xueliang.zhong | 7f88c1a | 2018-11-06 11:42:41 +0000 | [diff] [blame] | 199 | const std::string& feature_list, /* out */ std::string* error_msg) const { |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 200 | std::vector<std::string> features; |
| 201 | Split(feature_list, ',', &features); |
xueliang.zhong | 7f88c1a | 2018-11-06 11:42:41 +0000 | [diff] [blame] | 202 | std::transform(std::begin(features), std::end(features), std::begin(features), |
| 203 | [](const std::string &s) { return android::base::Trim(s); }); |
| 204 | auto empty_strings_begin = std::copy_if(std::begin(features), std::end(features), |
| 205 | std::begin(features), |
| 206 | [](const std::string& s) { return !s.empty(); }); |
| 207 | features.erase(empty_strings_begin, std::end(features)); |
| 208 | if (features.empty()) { |
| 209 | *error_msg = "No instruction set features specified"; |
| 210 | return nullptr; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 211 | } |
Goran Jakovljevic | a7d38fc | 2015-03-12 15:32:55 +0100 | [diff] [blame] | 212 | |
xueliang.zhong | 7f88c1a | 2018-11-06 11:42:41 +0000 | [diff] [blame] | 213 | bool use_default = false; |
| 214 | bool use_runtime_detection = false; |
| 215 | for (const std::string& feature : features) { |
| 216 | if (feature == "default") { |
| 217 | if (features.size() > 1) { |
| 218 | *error_msg = "Specific instruction set feature(s) cannot be used when 'default' is used."; |
| 219 | return nullptr; |
| 220 | } |
| 221 | use_default = true; |
| 222 | features.pop_back(); |
| 223 | break; |
| 224 | } else if (feature == "runtime") { |
| 225 | if (features.size() > 1) { |
| 226 | *error_msg = "Specific instruction set feature(s) cannot be used when 'runtime' is used."; |
| 227 | return nullptr; |
| 228 | } |
| 229 | use_runtime_detection = true; |
| 230 | features.pop_back(); |
| 231 | break; |
| 232 | } |
| 233 | } |
| 234 | // Expectation: "default" and "runtime" are standalone, no other feature names. |
| 235 | // But an empty features vector after processing can also come along if the |
| 236 | // handled feature names are the only ones in the list. So |
| 237 | // logically, we check "default or runtime => features.empty." |
| 238 | DCHECK((!use_default && !use_runtime_detection) || features.empty()); |
| 239 | |
| 240 | std::unique_ptr<const InstructionSetFeatures> runtime_detected_features; |
| 241 | if (use_runtime_detection) { |
| 242 | runtime_detected_features = FromRuntimeDetection(); |
| 243 | } |
| 244 | |
| 245 | if (runtime_detected_features != nullptr) { |
| 246 | return AddRuntimeDetectedFeatures(runtime_detected_features.get()); |
| 247 | } else { |
| 248 | return AddFeaturesFromSplitString(features, error_msg); |
| 249 | } |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | const ArmInstructionSetFeatures* InstructionSetFeatures::AsArmInstructionSetFeatures() const { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 253 | DCHECK_EQ(InstructionSet::kArm, GetInstructionSet()); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 254 | return down_cast<const ArmInstructionSetFeatures*>(this); |
| 255 | } |
| 256 | |
| 257 | const Arm64InstructionSetFeatures* InstructionSetFeatures::AsArm64InstructionSetFeatures() const { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 258 | DCHECK_EQ(InstructionSet::kArm64, GetInstructionSet()); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 259 | return down_cast<const Arm64InstructionSetFeatures*>(this); |
| 260 | } |
| 261 | |
| 262 | const MipsInstructionSetFeatures* InstructionSetFeatures::AsMipsInstructionSetFeatures() const { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 263 | DCHECK_EQ(InstructionSet::kMips, GetInstructionSet()); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 264 | return down_cast<const MipsInstructionSetFeatures*>(this); |
| 265 | } |
| 266 | |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 267 | const Mips64InstructionSetFeatures* InstructionSetFeatures::AsMips64InstructionSetFeatures() const { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 268 | DCHECK_EQ(InstructionSet::kMips64, GetInstructionSet()); |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 269 | return down_cast<const Mips64InstructionSetFeatures*>(this); |
| 270 | } |
| 271 | |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 272 | const X86InstructionSetFeatures* InstructionSetFeatures::AsX86InstructionSetFeatures() const { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 273 | DCHECK(InstructionSet::kX86 == GetInstructionSet() || |
| 274 | InstructionSet::kX86_64 == GetInstructionSet()); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 275 | return down_cast<const X86InstructionSetFeatures*>(this); |
| 276 | } |
| 277 | |
| 278 | const X86_64InstructionSetFeatures* InstructionSetFeatures::AsX86_64InstructionSetFeatures() const { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 279 | DCHECK_EQ(InstructionSet::kX86_64, GetInstructionSet()); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 280 | return down_cast<const X86_64InstructionSetFeatures*>(this); |
| 281 | } |
| 282 | |
Andreas Gampe | 24a05f4 | 2015-04-03 13:46:54 -0700 | [diff] [blame] | 283 | bool InstructionSetFeatures::FindVariantInArray(const char* const variants[], size_t num_variants, |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 284 | const std::string& variant) { |
Andreas Gampe | 24a05f4 | 2015-04-03 13:46:54 -0700 | [diff] [blame] | 285 | const char* const * begin = variants; |
| 286 | const char* const * end = begin + num_variants; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 287 | return std::find(begin, end, variant) != end; |
| 288 | } |
| 289 | |
xueliang.zhong | 7f88c1a | 2018-11-06 11:42:41 +0000 | [diff] [blame] | 290 | std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::AddRuntimeDetectedFeatures( |
| 291 | const InstructionSetFeatures *features ATTRIBUTE_UNUSED) const { |
| 292 | UNIMPLEMENTED(FATAL) << kRuntimeISA; |
| 293 | UNREACHABLE(); |
| 294 | } |
| 295 | |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 296 | std::ostream& operator<<(std::ostream& os, const InstructionSetFeatures& rhs) { |
| 297 | os << "ISA: " << rhs.GetInstructionSet() << " Feature string: " << rhs.GetFeatureString(); |
| 298 | return os; |
| 299 | } |
| 300 | |
| 301 | } // namespace art |