Ian Rogers | 8afeb85 | 2014-04-02 14:55:49 -0700 | [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 | |
| 17 | #include "instruction_set.h" |
| 18 | |
Andreas Gampe | af13ad9 | 2014-04-11 12:07:48 -0700 | [diff] [blame] | 19 | #include "globals.h" |
| 20 | #include "base/logging.h" // Logging is required for FATAL in the helper functions. |
| 21 | |
Ian Rogers | 8afeb85 | 2014-04-02 14:55:49 -0700 | [diff] [blame] | 22 | namespace art { |
| 23 | |
Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame^] | 24 | const char* GetInstructionSetString(const InstructionSet isa) { |
| 25 | switch (isa) { |
| 26 | case kArm: |
| 27 | case kThumb2: |
| 28 | return "arm"; |
| 29 | case kArm64: |
| 30 | return "arm64"; |
| 31 | case kX86: |
| 32 | return "x86"; |
| 33 | case kX86_64: |
| 34 | return "x86_64"; |
| 35 | case kMips: |
| 36 | return "mips"; |
| 37 | case kNone: |
| 38 | return "none"; |
| 39 | default: |
| 40 | LOG(FATAL) << "Unknown ISA " << isa; |
| 41 | return nullptr; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | InstructionSet GetInstructionSetFromString(const char* isa_str) { |
| 46 | CHECK(isa_str != nullptr); |
| 47 | |
| 48 | if (!strcmp("arm", isa_str)) { |
| 49 | return kArm; |
| 50 | } else if (!strcmp("arm64", isa_str)) { |
| 51 | return kArm64; |
| 52 | } else if (!strcmp("x86", isa_str)) { |
| 53 | return kX86; |
| 54 | } else if (!strcmp("x86_64", isa_str)) { |
| 55 | return kX86_64; |
| 56 | } else if (!strcmp("mips", isa_str)) { |
| 57 | return kMips; |
| 58 | } else if (!strcmp("none", isa_str)) { |
| 59 | return kNone; |
| 60 | } |
| 61 | |
| 62 | LOG(FATAL) << "Unknown ISA " << isa_str; |
| 63 | return kNone; |
| 64 | } |
| 65 | |
Andreas Gampe | af13ad9 | 2014-04-11 12:07:48 -0700 | [diff] [blame] | 66 | size_t GetInstructionSetPointerSize(InstructionSet isa) { |
| 67 | switch (isa) { |
| 68 | case kArm: |
| 69 | // Fall-through. |
| 70 | case kThumb2: |
| 71 | return kArmPointerSize; |
| 72 | case kArm64: |
| 73 | return kArm64PointerSize; |
| 74 | case kX86: |
| 75 | return kX86PointerSize; |
| 76 | case kX86_64: |
| 77 | return kX86_64PointerSize; |
| 78 | case kMips: |
| 79 | return kMipsPointerSize; |
| 80 | case kNone: |
| 81 | LOG(FATAL) << "ISA kNone does not have pointer size."; |
| 82 | return 0; |
| 83 | default: |
| 84 | LOG(FATAL) << "Unknown ISA " << isa; |
| 85 | return 0; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | size_t GetInstructionSetAlignment(InstructionSet isa) { |
| 90 | switch (isa) { |
| 91 | case kArm: |
| 92 | // Fall-through. |
| 93 | case kThumb2: |
| 94 | return kArmAlignment; |
| 95 | case kArm64: |
| 96 | return kArm64Alignment; |
| 97 | case kX86: |
| 98 | // Fall-through. |
| 99 | case kX86_64: |
| 100 | return kX86Alignment; |
| 101 | case kMips: |
| 102 | return kMipsAlignment; |
| 103 | case kNone: |
| 104 | LOG(FATAL) << "ISA kNone does not have alignment."; |
| 105 | return 0; |
| 106 | default: |
| 107 | LOG(FATAL) << "Unknown ISA " << isa; |
| 108 | return 0; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | bool Is64BitInstructionSet(InstructionSet isa) { |
| 113 | switch (isa) { |
| 114 | case kArm: |
| 115 | case kThumb2: |
| 116 | case kX86: |
| 117 | case kMips: |
| 118 | return false; |
| 119 | |
| 120 | case kArm64: |
| 121 | case kX86_64: |
| 122 | return true; |
| 123 | |
| 124 | case kNone: |
| 125 | LOG(FATAL) << "ISA kNone does not have bit width."; |
| 126 | return 0; |
| 127 | default: |
| 128 | LOG(FATAL) << "Unknown ISA " << isa; |
| 129 | return 0; |
| 130 | } |
| 131 | } |
| 132 | |
Ian Rogers | 8afeb85 | 2014-04-02 14:55:49 -0700 | [diff] [blame] | 133 | std::string InstructionSetFeatures::GetFeatureString() const { |
| 134 | std::string result; |
| 135 | if ((mask_ & kHwDiv) != 0) { |
| 136 | result += "div"; |
| 137 | } |
| 138 | if (result.size() == 0) { |
| 139 | result = "none"; |
| 140 | } |
| 141 | return result; |
| 142 | } |
| 143 | |
| 144 | } // namespace art |