Debian Codegraph @

js/src/jit/mips-shared/Architecture-mips-shared.h

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef jit_mips_shared_Architecture_mips_shared_h
8 #define jit_mips_shared_Architecture_mips_shared_h
9
10 #include "mozilla/MathAlgorithms.h"
11
12 #include <algorithm>
13 #include <limits.h>
14 #include <stdint.h>
15
16 #include "jit/shared/Architecture-shared.h"
17
18 #include "js/Utility.h"
19
20 // gcc appears to use _mips_hard_float to denote
21 // that the target is a hard-float target.
22 #ifdef _mips_hard_float
23 # define JS_CODEGEN_MIPS_HARDFP
24 #endif
25
26 #if (defined(_MIPS_SIM) && (_MIPS_SIM == _ABIO32))
27 # define USES_O32_ABI
28 #elif (defined(_MIPS_SIM) && (_MIPS_SIM == _ABI64)) || \
29 defined(JS_SIMULATOR_MIPS64)
30 # define USES_N64_ABI
31 #else
32 # error "Unsupported ABI"
33 #endif
34
35 #if (defined(__mips_isa_rev) && (__mips_isa_rev >= 6))
36 # define MIPSR6
37 #endif
38
39 namespace js {
40 namespace jit {
41
42 // How far forward/back can a jump go? Provide a generous buffer for thunks.
43 static const uint32_t JumpImmediateRange = UINT32_MAX;
44
45 class Registers {
46 public:
47 enum RegisterID {
48 r0 = 0,
49 r1,
50 r2,
51 r3,
52 r4,
53 r5,
54 r6,
55 r7,
56 r8,
57 r9,
58 r10,
59 r11,
60 r12,
61 r13,
62 r14,
63 r15,
64 r16,
65 r17,
66 r18,
67 r19,
68 r20,
69 r21,
70 r22,
71 r23,
72 r24,
73 r25,
74 r26,
75 r27,
76 r28,
77 r29,
78 r30,
79 r31,
80 zero = r0,
81 at = r1,
82 v0 = r2,
83 v1 = r3,
84 a0 = r4,
85 a1 = r5,
86 a2 = r6,
87 a3 = r7,
88 #if defined(USES_O32_ABI)
89 t0 = r8,
90 t1 = r9,
91 t2 = r10,
92 t3 = r11,
93 t4 = r12,
94 t5 = r13,
95 t6 = r14,
96 t7 = r15,
97 ta0 = t4,
98 ta1 = t5,
99 ta2 = t6,
100 ta3 = t7,
101 #elif defined(USES_N64_ABI)
102 a4 = r8,
103 a5 = r9,
104 a6 = r10,
105 a7 = r11,
106 t0 = r12,
107 t1 = r13,
108 t2 = r14,
109 t3 = r15,
110 ta0 = a4,
111 ta1 = a5,
112 ta2 = a6,
113 ta3 = a7,
114 #endif
115 s0 = r16,
116 s1 = r17,
117 s2 = r18,
118 s3 = r19,
119 s4 = r20,
120 s5 = r21,
121 s6 = r22,
122 s7 = r23,
123 t8 = r24,
124 t9 = r25,
125 k0 = r26,
126 k1 = r27,
127 gp = r28,
128 sp = r29,
129 fp = r30,
130 ra = r31,
131 invalid_reg
132 };
133 typedef uint8_t Code;
134 typedef RegisterID Encoding;
135
136 // Content spilled during bailouts.
137 union RegisterContent {
138 uintptr_t r;
139 };
140
141 static const char* const RegNames[];
142 static const char* GetName(Code code) {
143 MOZ_ASSERT(code < Total);
144 return RegNames[code];
145 }
146 static const char* GetName(Encoding i) { return GetName(Code(i)); }
147
148 static Code FromName(const char* name);
149
150 static const Encoding StackPointer = sp;
151 static const Encoding Invalid = invalid_reg;
152
153 static const uint32_t Total = 32;
154 static const uint32_t Allocatable;
155
156 typedef uint32_t SetType;
157 static const SetType AllMask = 0xffffffff;
158 static const SetType SharedArgRegMask =
159 (1 << a0) | (1 << a1) | (1 << a2) | (1 << a3);
160 static const SetType ArgRegMask;
161
162 static const SetType VolatileMask =
163 (1 << Registers::v0) | (1 << Registers::v1) | (1 << Registers::a0) |
164 (1 << Registers::a1) | (1 << Registers::a2) | (1 << Registers::a3) |
165 (1 << Registers::t0) | (1 << Registers::t1) | (1 << Registers::t2) |
166 (1 << Registers::t3) | (1 << Registers::ta0) | (1 << Registers::ta1) |
167 (1 << Registers::ta2) | (1 << Registers::ta3);
168
169 // We use this constant to save registers when entering functions. This
170 // is why $ra is added here even though it is not "Non Volatile".
171 static const SetType NonVolatileMask =
172 (1 << Registers::s0) | (1 << Registers::s1) | (1 << Registers::s2) |
173 (1 << Registers::s3) | (1 << Registers::s4) | (1 << Registers::s5) |
174 (1 << Registers::s6) | (1 << Registers::s7) | (1 << Registers::fp) |
175 (1 << Registers::ra);
176
177 static const SetType WrapperMask = VolatileMask | // = arguments
178 (1 << Registers::t0) | // = outReg
179 (1 << Registers::t1); // = argBase
180
181 static const SetType NonAllocatableMask =
182 (1 << Registers::zero) | (1 << Registers::at) | // at = scratch
183 (1 << Registers::t8) | // t8 = scratch
184 (1 << Registers::t9) | // t9 = scratch
185 (1 << Registers::k0) | (1 << Registers::k1) | (1 << Registers::gp) |
186 (1 << Registers::sp) | (1 << Registers::ra) | (1 << Registers::fp);
187
188 // Registers returned from a JS -> JS call.
189 static const SetType JSCallMask;
190
191 // Registers returned from a JS -> C call.
192 static const SetType SharedCallMask = (1 << Registers::v0);
193 static const SetType CallMask;
194
195 static const SetType AllocatableMask = AllMask & ~NonAllocatableMask;
196
197 static uint32_t SetSize(SetType x) {
198 static_assert(sizeof(SetType) == 4, "SetType must be 32 bits");
199 return mozilla::CountPopulation32(x);
200 }
201 static uint32_t FirstBit(SetType x) {
202 return mozilla::CountTrailingZeroes32(x);
203 }
204 static uint32_t LastBit(SetType x) {
205 return 31 - mozilla::CountLeadingZeroes32(x);
206 }
207 };
208
209 // Smallest integer type that can hold a register bitmask.
210 typedef uint32_t PackedRegisterMask;
211
212 class FloatRegistersMIPSShared {
213 public:
214 enum FPRegisterID {
215 f0 = 0,
216 f1,
217 f2,
218 f3,
219 f4,
220 f5,
221 f6,
222 f7,
223 f8,
224 f9,
225 f10,
226 f11,
227 f12,
228 f13,
229 f14,
230 f15,
231 f16,
232 f17,
233 f18,
234 f19,
235 f20,
236 f21,
237 f22,
238 f23,
239 f24,
240 f25,
241 f26,
242 f27,
243 f28,
244 f29,
245 f30,
246 f31,
247 invalid_freg
248 };
249 typedef uint32_t Code;
250 typedef FPRegisterID Encoding;
251
252 // Content spilled during bailouts.
253 union RegisterContent {
254 double d;
255 };
256
257 static const char* GetName(Encoding code) {
258 static const char* const Names[] = {
259 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
260 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
261 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
262 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31"};
263 return Names[code];
264 }
265
266 static const Encoding Invalid = invalid_freg;
267
268 typedef uint64_t SetType;
269 };
270
271 static const uint32_t SpillSlotSize =
272 std::max(sizeof(Registers::RegisterContent),
273 sizeof(FloatRegistersMIPSShared::RegisterContent));
274
275 template <typename T>
276 class TypedRegisterSet;
277
278 class FloatRegisterMIPSShared {
279 public:
280 bool isSimd128() const { return false; }
281
282 typedef FloatRegistersMIPSShared::SetType SetType;
283
284 static uint32_t SetSize(SetType x) {
285 static_assert(sizeof(SetType) == 8, "SetType must be 64 bits");
286 return mozilla::CountPopulation64(x);
287 }
288 static uint32_t FirstBit(SetType x) {
289 static_assert(sizeof(SetType) == 8, "SetType must be 64 bits");
290 return mozilla::CountTrailingZeroes64(x);
291 }
292 static uint32_t LastBit(SetType x) {
293 static_assert(sizeof(SetType) == 8, "SetType must be 64 bits");
294 return 63 - mozilla::CountLeadingZeroes64(x);
295 }
296 };
297
298 namespace mips_private {
299 extern uint32_t Flags;
300 extern bool hasFPU;
301 extern bool isLoongson;
302 extern bool hasR2;
303 } // namespace mips_private
304
305 inline uint32_t GetMIPSFlags() { return mips_private::Flags; }
306 inline bool hasFPU() { return mips_private::hasFPU; }
307 inline bool isLoongson() { return mips_private::isLoongson; }
308 inline bool hasR2() { return mips_private::hasR2; }
309
310 // MIPS doesn't have double registers that can NOT be treated as float32.
311 inline bool hasUnaliasedDouble() { return false; }
312
313 // MIPS64 doesn't support it.
314 inline bool hasMultiAlias() { return false; }
315
316 } // namespace jit
317 } // namespace js
318
319 #endif /* jit_mips_shared_Architecture_mips_shared_h */