blob: c1931a94148c17b24b42970270f051b642a759dd [file] [log] [blame]
Ian Rogers8afeb852014-04-02 14:55:49 -07001/*
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 Gampeaf13ad92014-04-11 12:07:48 -070019#include "globals.h"
20#include "base/logging.h" // Logging is required for FATAL in the helper functions.
21
Ian Rogers8afeb852014-04-02 14:55:49 -070022namespace art {
23
Narayan Kamath11d9f062014-04-23 20:24:57 +010024const 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
45InstructionSet 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 Gampeaf13ad92014-04-11 12:07:48 -070066size_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
Nicolas Geoffray42fcd982014-04-22 11:03:52 +000089size_t GetBytesPerGprSpillLocation(InstructionSet isa) {
90 switch (isa) {
91 case kArm:
92 // Fall-through.
93 case kThumb2:
94 return 4;
95 case kArm64:
96 return 8;
97 case kX86:
98 return 4;
99 case kX86_64:
100 return 8;
101 case kMips:
102 return 4;
103 case kNone:
104 LOG(FATAL) << "ISA kNone does not have spills.";
105 return 0;
106 default:
107 LOG(FATAL) << "Unknown ISA " << isa;
108 return 0;
109 }
110}
111
112size_t GetBytesPerFprSpillLocation(InstructionSet isa) {
113 switch (isa) {
114 case kArm:
115 // Fall-through.
116 case kThumb2:
117 return 4;
118 case kArm64:
119 return 8;
120 case kX86:
121 return 8;
122 case kX86_64:
123 return 8;
124 case kMips:
125 return 4;
126 case kNone:
127 LOG(FATAL) << "ISA kNone does not have spills.";
128 return 0;
129 default:
130 LOG(FATAL) << "Unknown ISA " << isa;
131 return 0;
132 }
133}
134
Andreas Gampeaf13ad92014-04-11 12:07:48 -0700135size_t GetInstructionSetAlignment(InstructionSet isa) {
136 switch (isa) {
137 case kArm:
138 // Fall-through.
139 case kThumb2:
140 return kArmAlignment;
141 case kArm64:
142 return kArm64Alignment;
143 case kX86:
144 // Fall-through.
145 case kX86_64:
146 return kX86Alignment;
147 case kMips:
148 return kMipsAlignment;
149 case kNone:
150 LOG(FATAL) << "ISA kNone does not have alignment.";
151 return 0;
152 default:
153 LOG(FATAL) << "Unknown ISA " << isa;
154 return 0;
155 }
156}
157
158bool Is64BitInstructionSet(InstructionSet isa) {
159 switch (isa) {
160 case kArm:
161 case kThumb2:
162 case kX86:
163 case kMips:
164 return false;
165
166 case kArm64:
167 case kX86_64:
168 return true;
169
170 case kNone:
171 LOG(FATAL) << "ISA kNone does not have bit width.";
172 return 0;
173 default:
174 LOG(FATAL) << "Unknown ISA " << isa;
175 return 0;
176 }
177}
178
Ian Rogers8afeb852014-04-02 14:55:49 -0700179std::string InstructionSetFeatures::GetFeatureString() const {
180 std::string result;
181 if ((mask_ & kHwDiv) != 0) {
182 result += "div";
183 }
184 if (result.size() == 0) {
185 result = "none";
186 }
187 return result;
188}
189
190} // namespace art