Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 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 | #include "instruction_set_features_arm.h" |
| 18 | |
Bilyan Borisov | bb661c0 | 2016-04-04 16:27:32 +0100 | [diff] [blame] | 19 | #if defined(ART_TARGET_ANDROID) && defined(__arm__) |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 20 | #include <asm/hwcap.h> |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame^] | 21 | #include <sys/auxv.h> |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 22 | #endif |
| 23 | |
| 24 | #include "signal.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame^] | 25 | |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 26 | #include <fstream> |
| 27 | |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 28 | #include "android-base/stringprintf.h" |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 29 | #include "android-base/strings.h" |
| 30 | |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 31 | #include "base/logging.h" |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 32 | |
| 33 | #if defined(__arm__) |
| 34 | extern "C" bool artCheckForArmSdivInstruction(); |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 35 | extern "C" bool artCheckForArmv8AInstructions(); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 36 | #endif |
| 37 | |
| 38 | namespace art { |
| 39 | |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 40 | using android::base::StringPrintf; |
| 41 | |
Andreas Gampe | 0415b4e | 2015-01-06 15:17:07 -0800 | [diff] [blame] | 42 | ArmFeaturesUniquePtr ArmInstructionSetFeatures::FromVariant( |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 43 | const std::string& variant, std::string* error_msg) { |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 44 | static const char* arm_variants_with_armv8a[] = { |
| 45 | "cortex-a32", |
| 46 | "cortex-a35", |
| 47 | "cortex-a53", |
| 48 | "cortex-a53.a57", |
| 49 | "cortex-a53.a72", |
| 50 | "cortex-a57", |
| 51 | "cortex-a72", |
| 52 | "cortex-a73", |
| 53 | "exynos-m1", |
| 54 | "denver", |
| 55 | "kryo" |
| 56 | }; |
| 57 | bool has_armv8a = FindVariantInArray(arm_variants_with_armv8a, |
| 58 | arraysize(arm_variants_with_armv8a), |
| 59 | variant); |
| 60 | |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 61 | // Look for variants that have divide support. |
| 62 | static const char* arm_variants_with_div[] = { |
Serban Constantinescu | b8472ee | 2016-10-26 11:15:00 +0100 | [diff] [blame] | 63 | "cortex-a7", |
| 64 | "cortex-a12", |
| 65 | "cortex-a15", |
| 66 | "cortex-a17", |
Serban Constantinescu | b8472ee | 2016-10-26 11:15:00 +0100 | [diff] [blame] | 67 | "krait", |
| 68 | }; |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 69 | bool has_div = has_armv8a || FindVariantInArray(arm_variants_with_div, |
| 70 | arraysize(arm_variants_with_div), |
| 71 | variant); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 72 | |
| 73 | // Look for variants that have LPAE support. |
| 74 | static const char* arm_variants_with_lpae[] = { |
Serban Constantinescu | b8472ee | 2016-10-26 11:15:00 +0100 | [diff] [blame] | 75 | "cortex-a7", |
| 76 | "cortex-a12", |
| 77 | "cortex-a15", |
| 78 | "cortex-a17", |
Serban Constantinescu | b8472ee | 2016-10-26 11:15:00 +0100 | [diff] [blame] | 79 | "krait", |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 80 | }; |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 81 | bool has_atomic_ldrd_strd = has_armv8a || FindVariantInArray(arm_variants_with_lpae, |
| 82 | arraysize(arm_variants_with_lpae), |
| 83 | variant); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 84 | |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 85 | if (has_armv8a == false && has_div == false && has_atomic_ldrd_strd == false) { |
Serban Constantinescu | b8472ee | 2016-10-26 11:15:00 +0100 | [diff] [blame] | 86 | static const char* arm_variants_with_default_features[] = { |
| 87 | "cortex-a5", |
| 88 | "cortex-a8", |
| 89 | "cortex-a9", |
| 90 | "cortex-a9-mp", |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 91 | "default", |
Serban Constantinescu | b8472ee | 2016-10-26 11:15:00 +0100 | [diff] [blame] | 92 | "generic" |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 93 | }; |
Serban Constantinescu | b8472ee | 2016-10-26 11:15:00 +0100 | [diff] [blame] | 94 | if (!FindVariantInArray(arm_variants_with_default_features, |
| 95 | arraysize(arm_variants_with_default_features), |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 96 | variant)) { |
Serban Constantinescu | b8472ee | 2016-10-26 11:15:00 +0100 | [diff] [blame] | 97 | *error_msg = StringPrintf("Attempt to use unsupported ARM variant: %s", variant.c_str()); |
| 98 | return nullptr; |
| 99 | } else { |
| 100 | // Warn if we use the default features. |
| 101 | LOG(WARNING) << "Using default instruction set features for ARM CPU variant (" << variant |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 102 | << ") using conservative defaults"; |
| 103 | } |
| 104 | } |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 105 | return ArmFeaturesUniquePtr(new ArmInstructionSetFeatures(has_div, |
| 106 | has_atomic_ldrd_strd, |
| 107 | has_armv8a)); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 108 | } |
| 109 | |
Andreas Gampe | 0415b4e | 2015-01-06 15:17:07 -0800 | [diff] [blame] | 110 | ArmFeaturesUniquePtr ArmInstructionSetFeatures::FromBitmap(uint32_t bitmap) { |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 111 | bool has_div = (bitmap & kDivBitfield) != 0; |
| 112 | bool has_atomic_ldrd_strd = (bitmap & kAtomicLdrdStrdBitfield) != 0; |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 113 | bool has_armv8a = (bitmap & kARMv8A) != 0; |
| 114 | return ArmFeaturesUniquePtr(new ArmInstructionSetFeatures(has_div, |
| 115 | has_atomic_ldrd_strd, |
| 116 | has_armv8a)); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 117 | } |
| 118 | |
Andreas Gampe | 0415b4e | 2015-01-06 15:17:07 -0800 | [diff] [blame] | 119 | ArmFeaturesUniquePtr ArmInstructionSetFeatures::FromCppDefines() { |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 120 | // Note: This will not work for now since we still build the 32-bit as __ARCH_ARM_7A__. |
| 121 | #if defined(__ARM_ARCH_8A__) |
| 122 | const bool has_armv8a = true; |
| 123 | #else |
| 124 | const bool has_armv8a = false; |
| 125 | #endif |
| 126 | #if defined (__ARM_ARCH_8A__) || defined(__ARM_ARCH_EXT_IDIV__) |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 127 | const bool has_div = true; |
| 128 | #else |
| 129 | const bool has_div = false; |
| 130 | #endif |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 131 | #if defined (__ARM_ARCH_8A__) || defined(__ARM_FEATURE_LPAE) |
| 132 | const bool has_atomic_ldrd_strd = true; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 133 | #else |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 134 | const bool has_atomic_ldrd_strd = false; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 135 | #endif |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 136 | return ArmFeaturesUniquePtr(new ArmInstructionSetFeatures(has_div, |
| 137 | has_atomic_ldrd_strd, |
| 138 | has_armv8a)); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Andreas Gampe | 0415b4e | 2015-01-06 15:17:07 -0800 | [diff] [blame] | 141 | ArmFeaturesUniquePtr ArmInstructionSetFeatures::FromCpuInfo() { |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 142 | // Look in /proc/cpuinfo for features we need. Only use this when we can guarantee that |
| 143 | // the kernel puts the appropriate feature flags in here. Sometimes it doesn't. |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 144 | bool has_atomic_ldrd_strd = false; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 145 | bool has_div = false; |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 146 | bool has_armv8a = false; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 147 | |
| 148 | std::ifstream in("/proc/cpuinfo"); |
| 149 | if (!in.fail()) { |
| 150 | while (!in.eof()) { |
| 151 | std::string line; |
| 152 | std::getline(in, line); |
| 153 | if (!in.eof()) { |
| 154 | LOG(INFO) << "cpuinfo line: " << line; |
| 155 | if (line.find("Features") != std::string::npos) { |
| 156 | LOG(INFO) << "found features"; |
| 157 | if (line.find("idivt") != std::string::npos) { |
| 158 | // We always expect both ARM and Thumb divide instructions to be available or not |
| 159 | // available. |
| 160 | CHECK_NE(line.find("idiva"), std::string::npos); |
| 161 | has_div = true; |
| 162 | } |
| 163 | if (line.find("lpae") != std::string::npos) { |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 164 | has_atomic_ldrd_strd = true; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 165 | } |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 166 | } |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 167 | if (line.find("architecture") != std::string::npos |
| 168 | && line.find(": 8") != std::string::npos) { |
| 169 | LOG(INFO) << "found architecture ARMv8"; |
| 170 | // Android is only run on A cores, so ARMv8 implies ARMv8-A. |
| 171 | has_armv8a = true; |
| 172 | // ARMv8 CPUs have LPAE and div support. |
| 173 | has_div = true; |
| 174 | has_atomic_ldrd_strd = true; |
| 175 | } |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | in.close(); |
| 179 | } else { |
| 180 | LOG(ERROR) << "Failed to open /proc/cpuinfo"; |
| 181 | } |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 182 | return ArmFeaturesUniquePtr(new ArmInstructionSetFeatures(has_div, |
| 183 | has_atomic_ldrd_strd, |
| 184 | has_armv8a)); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 185 | } |
| 186 | |
Andreas Gampe | 0415b4e | 2015-01-06 15:17:07 -0800 | [diff] [blame] | 187 | ArmFeaturesUniquePtr ArmInstructionSetFeatures::FromHwcap() { |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 188 | bool has_div = false; |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 189 | bool has_atomic_ldrd_strd = false; |
| 190 | bool has_armv8a = false; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 191 | |
Bilyan Borisov | bb661c0 | 2016-04-04 16:27:32 +0100 | [diff] [blame] | 192 | #if defined(ART_TARGET_ANDROID) && defined(__arm__) |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 193 | uint64_t hwcaps = getauxval(AT_HWCAP); |
| 194 | LOG(INFO) << "hwcaps=" << hwcaps; |
| 195 | if ((hwcaps & HWCAP_IDIVT) != 0) { |
| 196 | // We always expect both ARM and Thumb divide instructions to be available or not |
| 197 | // available. |
| 198 | CHECK_NE(hwcaps & HWCAP_IDIVA, 0U); |
| 199 | has_div = true; |
| 200 | } |
| 201 | if ((hwcaps & HWCAP_LPAE) != 0) { |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 202 | has_atomic_ldrd_strd = true; |
| 203 | } |
| 204 | // TODO: Fix this once FPMISC makes it upstream. |
| 205 | // For now we detect if we run on an ARMv8 CPU by looking for CRC32 and SHA1 |
| 206 | // (only available on ARMv8 CPUs). |
| 207 | if ((hwcaps & HWCAP2_CRC32) != 0 && (hwcaps & HWCAP2_SHA1) != 0) { |
| 208 | has_armv8a = true; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 209 | } |
| 210 | #endif |
| 211 | |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 212 | return ArmFeaturesUniquePtr(new ArmInstructionSetFeatures(has_div, |
| 213 | has_atomic_ldrd_strd, |
| 214 | has_armv8a)); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | // A signal handler called by a fault for an illegal instruction. We record the fact in r0 |
| 218 | // and then increment the PC in the signal context to return to the next instruction. We know the |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 219 | // instruction is 4 bytes long. |
| 220 | static void bad_instr_handle(int signo ATTRIBUTE_UNUSED, |
| 221 | siginfo_t* si ATTRIBUTE_UNUSED, |
| 222 | void* data) { |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 223 | #if defined(__arm__) |
| 224 | struct ucontext *uc = (struct ucontext *)data; |
| 225 | struct sigcontext *sc = &uc->uc_mcontext; |
| 226 | sc->arm_r0 = 0; // Set R0 to #0 to signal error. |
| 227 | sc->arm_pc += 4; // Skip offending instruction. |
| 228 | #else |
| 229 | UNUSED(data); |
| 230 | #endif |
| 231 | } |
| 232 | |
Andreas Gampe | 0415b4e | 2015-01-06 15:17:07 -0800 | [diff] [blame] | 233 | ArmFeaturesUniquePtr ArmInstructionSetFeatures::FromAssembly() { |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 234 | // See if have a sdiv instruction. Register a signal handler and try to execute an sdiv |
| 235 | // instruction. If we get a SIGILL then it's not supported. |
| 236 | struct sigaction sa, osa; |
| 237 | sa.sa_flags = SA_ONSTACK | SA_RESTART | SA_SIGINFO; |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 238 | sa.sa_sigaction = bad_instr_handle; |
Andreas Gampe | eeca2b2 | 2016-06-14 17:24:51 -0700 | [diff] [blame] | 239 | sigemptyset(&sa.sa_mask); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 240 | sigaction(SIGILL, &sa, &osa); |
| 241 | |
| 242 | bool has_div = false; |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 243 | bool has_armv8a = false; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 244 | #if defined(__arm__) |
| 245 | if (artCheckForArmSdivInstruction()) { |
| 246 | has_div = true; |
| 247 | } |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 248 | if (artCheckForArmv8AInstructions()) { |
| 249 | has_armv8a = true; |
| 250 | } |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 251 | #endif |
| 252 | |
| 253 | // Restore the signal handler. |
| 254 | sigaction(SIGILL, &osa, nullptr); |
| 255 | |
| 256 | // Use compile time features to "detect" LPAE support. |
| 257 | // TODO: write an assembly LPAE support test. |
| 258 | #if defined(__ARM_FEATURE_LPAE) |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 259 | const bool has_atomic_ldrd_strd = true; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 260 | #else |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 261 | const bool has_atomic_ldrd_strd = false; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 262 | #endif |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 263 | return ArmFeaturesUniquePtr(new ArmInstructionSetFeatures(has_div, |
| 264 | has_atomic_ldrd_strd, |
| 265 | has_armv8a)); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | bool ArmInstructionSetFeatures::Equals(const InstructionSetFeatures* other) const { |
| 269 | if (kArm != other->GetInstructionSet()) { |
| 270 | return false; |
| 271 | } |
| 272 | const ArmInstructionSetFeatures* other_as_arm = other->AsArmInstructionSetFeatures(); |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 273 | return has_div_ == other_as_arm->has_div_ |
| 274 | && has_atomic_ldrd_strd_ == other_as_arm->has_atomic_ldrd_strd_ |
| 275 | && has_armv8a_ == other_as_arm->has_armv8a_; |
| 276 | } |
| 277 | |
| 278 | bool ArmInstructionSetFeatures::HasAtLeast(const InstructionSetFeatures* other) const { |
| 279 | if (kArm != other->GetInstructionSet()) { |
| 280 | return false; |
| 281 | } |
| 282 | const ArmInstructionSetFeatures* other_as_arm = other->AsArmInstructionSetFeatures(); |
Aart Bik | 5354af9 | 2017-07-19 11:13:27 -0700 | [diff] [blame] | 283 | return (has_div_ || !other_as_arm->has_div_) |
| 284 | && (has_atomic_ldrd_strd_ || !other_as_arm->has_atomic_ldrd_strd_) |
| 285 | && (has_armv8a_ || !other_as_arm->has_armv8a_); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | uint32_t ArmInstructionSetFeatures::AsBitmap() const { |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 289 | return (has_div_ ? kDivBitfield : 0) |
| 290 | | (has_atomic_ldrd_strd_ ? kAtomicLdrdStrdBitfield : 0) |
| 291 | | (has_armv8a_ ? kARMv8A : 0); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | std::string ArmInstructionSetFeatures::GetFeatureString() const { |
| 295 | std::string result; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 296 | if (has_div_) { |
Serban Constantinescu | b595b40 | 2016-09-23 11:06:03 +0100 | [diff] [blame] | 297 | result += "div"; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 298 | } else { |
Serban Constantinescu | b595b40 | 2016-09-23 11:06:03 +0100 | [diff] [blame] | 299 | result += "-div"; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 300 | } |
| 301 | if (has_atomic_ldrd_strd_) { |
| 302 | result += ",atomic_ldrd_strd"; |
| 303 | } else { |
| 304 | result += ",-atomic_ldrd_strd"; |
| 305 | } |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 306 | if (has_armv8a_) { |
| 307 | result += ",armv8a"; |
| 308 | } else { |
| 309 | result += ",-armv8a"; |
| 310 | } |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 311 | return result; |
| 312 | } |
| 313 | |
Andreas Gampe | 0415b4e | 2015-01-06 15:17:07 -0800 | [diff] [blame] | 314 | std::unique_ptr<const InstructionSetFeatures> |
| 315 | ArmInstructionSetFeatures::AddFeaturesFromSplitString( |
Serban Constantinescu | b595b40 | 2016-09-23 11:06:03 +0100 | [diff] [blame] | 316 | const std::vector<std::string>& features, std::string* error_msg) const { |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 317 | bool has_atomic_ldrd_strd = has_atomic_ldrd_strd_; |
| 318 | bool has_div = has_div_; |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 319 | bool has_armv8a = has_armv8a_; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 320 | for (auto i = features.begin(); i != features.end(); i++) { |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 321 | std::string feature = android::base::Trim(*i); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 322 | if (feature == "div") { |
| 323 | has_div = true; |
| 324 | } else if (feature == "-div") { |
| 325 | has_div = false; |
| 326 | } else if (feature == "atomic_ldrd_strd") { |
| 327 | has_atomic_ldrd_strd = true; |
| 328 | } else if (feature == "-atomic_ldrd_strd") { |
| 329 | has_atomic_ldrd_strd = false; |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 330 | } else if (feature == "armv8a") { |
| 331 | has_armv8a = true; |
| 332 | } else if (feature == "-armv8a") { |
| 333 | has_armv8a = false; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 334 | } else { |
| 335 | *error_msg = StringPrintf("Unknown instruction set feature: '%s'", feature.c_str()); |
| 336 | return nullptr; |
| 337 | } |
| 338 | } |
Andreas Gampe | 0415b4e | 2015-01-06 15:17:07 -0800 | [diff] [blame] | 339 | return std::unique_ptr<const InstructionSetFeatures>( |
Serban Constantinescu | d747c13 | 2016-10-26 09:30:21 +0100 | [diff] [blame] | 340 | new ArmInstructionSetFeatures(has_div, has_atomic_ldrd_strd, has_armv8a)); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | } // namespace art |