blob: 66e3894204c9ae42a82b6f3ec01290985f9f2e6b [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
2 * Copyright (C) 2012 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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_COMPILER_DEX_QUICK_MIPS_MIPS_LIR_H_
18#define ART_COMPILER_DEX_QUICK_MIPS_MIPS_LIR_H_
Brian Carlstrom7940e442013-07-12 13:46:57 -070019
Andreas Gampe0b9203e2015-01-22 20:39:27 -080020#include "dex/reg_location.h"
21#include "dex/reg_storage.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070022
23namespace art {
24
25/*
26 * Runtime register conventions.
27 *
28 * zero is always the value 0
29 * at is scratch (normally used as temp reg by assembler)
30 * v0, v1 are scratch (normally hold subroutine return values)
31 * a0-a3 are scratch (normally hold subroutine arguments)
32 * t0-t8 are scratch
33 * t9 is scratch (normally used for function calls)
34 * s0 (rMIPS_SUSPEND) is reserved [holds suspend-check counter]
35 * s1 (rMIPS_SELF) is reserved [holds current &Thread]
36 * s2-s7 are callee save (promotion target)
37 * k0, k1 are reserved for use by interrupt handlers
38 * gp is reserved for global pointer
39 * sp is reserved
40 * s8 is callee save (promotion target)
41 * ra is scratch (normally holds the return addr)
42 *
43 * Preserved across C calls: s0-s8
44 * Trashed across C calls: at, v0-v1, a0-a3, t0-t9, gp, ra
45 *
46 * Floating pointer registers
47 * NOTE: there are 32 fp registers (16 df pairs), but currently
48 * only support 16 fp registers (8 df pairs).
49 * f0-f15
50 * df0-df7, where df0={f0,f1}, df1={f2,f3}, ... , df7={f14,f15}
51 *
52 * f0-f15 (df0-df7) trashed across C calls
53 *
54 * For mips32 code use:
55 * a0-a3 to hold operands
56 * v0-v1 to hold results
57 * t0-t9 for temps
58 *
59 * All jump/branch instructions have a delay slot after it.
60 *
61 * Stack frame diagram (stack grows down, higher addresses at top):
62 *
63 * +------------------------+
64 * | IN[ins-1] | {Note: resides in caller's frame}
65 * | . |
66 * | IN[0] |
67 * | caller's Method* |
68 * +========================+ {Note: start of callee's frame}
69 * | spill region | {variable sized - will include lr if non-leaf.}
70 * +------------------------+
71 * | ...filler word... | {Note: used as 2nd word of V[locals-1] if long]
72 * +------------------------+
73 * | V[locals-1] |
74 * | V[locals-2] |
75 * | . |
76 * | . |
77 * | V[1] |
78 * | V[0] |
79 * +------------------------+
80 * | 0 to 3 words padding |
81 * +------------------------+
82 * | OUT[outs-1] |
83 * | OUT[outs-2] |
84 * | . |
85 * | OUT[0] |
86 * | cur_method* | <<== sp w/ 16-byte alignment
87 * +========================+
88 */
89
Brian Carlstrom7940e442013-07-12 13:46:57 -070090
Brian Carlstrom7940e442013-07-12 13:46:57 -070091#define LOWORD_OFFSET 0
92#define HIWORD_OFFSET 4
buzbee2700f7e2014-03-07 09:46:20 -080093#define rARG0 rA0
94#define rs_rARG0 rs_rA0
95#define rARG1 rA1
96#define rs_rARG1 rs_rA1
97#define rARG2 rA2
98#define rs_rARG2 rs_rA2
99#define rARG3 rA3
100#define rs_rARG3 rs_rA3
101#define rRESULT0 rV0
102#define rs_rRESULT0 rs_rV0
103#define rRESULT1 rV1
104#define rs_rRESULT1 rs_rV1
Brian Carlstrom7940e442013-07-12 13:46:57 -0700105
buzbee2700f7e2014-03-07 09:46:20 -0800106#define rFARG0 rF12
107#define rs_rFARG0 rs_rF12
108#define rFARG1 rF13
109#define rs_rFARG1 rs_rF13
110#define rFARG2 rF14
111#define rs_rFARG2 rs_rF14
112#define rFARG3 rF15
113#define rs_rFARG3 rs_rF15
114#define rFRESULT0 rF0
115#define rs_rFRESULT0 rs_rF0
116#define rFRESULT1 rF1
117#define rs_rFRESULT1 rs_rF1
Brian Carlstrom7940e442013-07-12 13:46:57 -0700118
119// Regs not used for Mips.
buzbee2700f7e2014-03-07 09:46:20 -0800120#define rMIPS_LR RegStorage::kInvalidRegVal
121#define rMIPS_PC RegStorage::kInvalidRegVal
Brian Carlstrom7940e442013-07-12 13:46:57 -0700122
Brian Carlstrom7940e442013-07-12 13:46:57 -0700123enum MipsResourceEncodingPos {
124 kMipsGPReg0 = 0,
125 kMipsRegSP = 29,
126 kMipsRegLR = 31,
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700127 kMipsFPReg0 = 32, // only 16 fp regs supported currently.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700128 kMipsFPRegEnd = 48,
129 kMipsRegHI = kMipsFPRegEnd,
130 kMipsRegLO,
131 kMipsRegPC,
132 kMipsRegEnd = 51,
133};
134
135#define ENCODE_MIPS_REG_LIST(N) (static_cast<uint64_t>(N))
136#define ENCODE_MIPS_REG_SP (1ULL << kMipsRegSP)
137#define ENCODE_MIPS_REG_LR (1ULL << kMipsRegLR)
138#define ENCODE_MIPS_REG_PC (1ULL << kMipsRegPC)
buzbee9da5c102014-03-28 12:59:18 -0700139#define ENCODE_MIPS_REG_HI (1ULL << kMipsRegHI)
140#define ENCODE_MIPS_REG_LO (1ULL << kMipsRegLO)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700141
Douglas Leung2db3e262014-06-25 16:02:55 -0700142// Set FR_BIT to 0
143// This bit determines how the CPU access FP registers.
144#define FR_BIT 0
145
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700146enum MipsNativeRegisterPool { // private marker to avoid generate-operator-out.py from processing.
buzbee091cc402014-03-31 10:14:40 -0700147 rZERO = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 0,
148 rAT = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 1,
149 rV0 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 2,
150 rV1 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 3,
151 rA0 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 4,
152 rA1 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 5,
153 rA2 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 6,
154 rA3 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 7,
155 rT0 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 8,
156 rT1 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 9,
157 rT2 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 10,
158 rT3 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 11,
159 rT4 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 12,
160 rT5 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 13,
161 rT6 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 14,
162 rT7 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 15,
163 rS0 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 16,
164 rS1 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 17,
165 rS2 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 18,
166 rS3 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 19,
167 rS4 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 20,
168 rS5 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 21,
169 rS6 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 22,
170 rS7 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 23,
171 rT8 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 24,
172 rT9 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 25,
173 rK0 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 26,
174 rK1 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 27,
175 rGP = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 28,
176 rSP = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 29,
177 rFP = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 30,
178 rRA = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 31,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700179
buzbee091cc402014-03-31 10:14:40 -0700180 rF0 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 0,
181 rF1 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 1,
182 rF2 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 2,
183 rF3 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 3,
184 rF4 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 4,
185 rF5 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 5,
186 rF6 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 6,
187 rF7 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 7,
188 rF8 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 8,
189 rF9 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 9,
190 rF10 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 10,
191 rF11 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 11,
192 rF12 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 12,
193 rF13 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 13,
194 rF14 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 14,
195 rF15 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 15,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700196#if 0
197 /*
198 * TODO: The shared resource mask doesn't have enough bit positions to describe all
199 * MIPS registers. Expand it and enable use of fp registers 16 through 31.
200 */
buzbee091cc402014-03-31 10:14:40 -0700201 rF16 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 16,
202 rF17 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 17,
203 rF18 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 18,
204 rF19 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 19,
205 rF20 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 20,
206 rF21 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 21,
207 rF22 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 22,
208 rF23 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 23,
209 rF24 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 24,
210 rF25 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 25,
211 rF26 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 26,
212 rF27 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 27,
213 rF28 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 28,
214 rF29 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 29,
215 rF30 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 30,
216 rF31 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 31,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700217#endif
Ian Rogersd582fa42014-11-05 23:46:43 -0800218 // Double precision registers where the FPU is in 32-bit mode.
219 rD0_fr0 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 0,
220 rD1_fr0 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 2,
221 rD2_fr0 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 4,
222 rD3_fr0 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 6,
223 rD4_fr0 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 8,
224 rD5_fr0 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 10,
225 rD6_fr0 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 12,
226 rD7_fr0 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 14,
Douglas Leung2db3e262014-06-25 16:02:55 -0700227#if 0 // TODO: expand resource mask to enable use of all MIPS fp registers.
Ian Rogersd582fa42014-11-05 23:46:43 -0800228 rD8_fr0 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 16,
229 rD9_fr0 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 18,
230 rD10_fr0 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 20,
231 rD11_fr0 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 22,
232 rD12_fr0 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 24,
233 rD13_fr0 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 26,
234 rD14_fr0 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 28,
235 rD15_fr0 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 30,
Douglas Leung2db3e262014-06-25 16:02:55 -0700236#endif
Ian Rogersd582fa42014-11-05 23:46:43 -0800237 // Double precision registers where the FPU is in 64-bit mode.
238 rD0_fr1 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 0,
239 rD1_fr1 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 1,
240 rD2_fr1 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 2,
241 rD3_fr1 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 3,
242 rD4_fr1 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 4,
243 rD5_fr1 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 5,
244 rD6_fr1 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 6,
245 rD7_fr1 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 7,
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700246#if 0 // TODO: expand resource mask to enable use of all MIPS fp registers.
Ian Rogersd582fa42014-11-05 23:46:43 -0800247 rD8_fr1 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 8,
248 rD9_fr1 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 9,
249 rD10_fr1 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 10,
250 rD11_fr1 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 11,
251 rD12_fr1 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 12,
252 rD13_fr1 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 13,
253 rD14_fr1 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 14,
254 rD15_fr1 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 15,
Douglas Leung2db3e262014-06-25 16:02:55 -0700255#endif
Brian Carlstrom7940e442013-07-12 13:46:57 -0700256};
257
buzbee091cc402014-03-31 10:14:40 -0700258constexpr RegStorage rs_rZERO(RegStorage::kValid | rZERO);
259constexpr RegStorage rs_rAT(RegStorage::kValid | rAT);
260constexpr RegStorage rs_rV0(RegStorage::kValid | rV0);
261constexpr RegStorage rs_rV1(RegStorage::kValid | rV1);
262constexpr RegStorage rs_rA0(RegStorage::kValid | rA0);
263constexpr RegStorage rs_rA1(RegStorage::kValid | rA1);
264constexpr RegStorage rs_rA2(RegStorage::kValid | rA2);
265constexpr RegStorage rs_rA3(RegStorage::kValid | rA3);
266constexpr RegStorage rs_rT0(RegStorage::kValid | rT0);
267constexpr RegStorage rs_rT1(RegStorage::kValid | rT1);
268constexpr RegStorage rs_rT2(RegStorage::kValid | rT2);
269constexpr RegStorage rs_rT3(RegStorage::kValid | rT3);
270constexpr RegStorage rs_rT4(RegStorage::kValid | rT4);
271constexpr RegStorage rs_rT5(RegStorage::kValid | rT5);
272constexpr RegStorage rs_rT6(RegStorage::kValid | rT6);
273constexpr RegStorage rs_rT7(RegStorage::kValid | rT7);
274constexpr RegStorage rs_rS0(RegStorage::kValid | rS0);
275constexpr RegStorage rs_rS1(RegStorage::kValid | rS1);
276constexpr RegStorage rs_rS2(RegStorage::kValid | rS2);
277constexpr RegStorage rs_rS3(RegStorage::kValid | rS3);
278constexpr RegStorage rs_rS4(RegStorage::kValid | rS4);
279constexpr RegStorage rs_rS5(RegStorage::kValid | rS5);
280constexpr RegStorage rs_rS6(RegStorage::kValid | rS6);
281constexpr RegStorage rs_rS7(RegStorage::kValid | rS7);
282constexpr RegStorage rs_rT8(RegStorage::kValid | rT8);
283constexpr RegStorage rs_rT9(RegStorage::kValid | rT9);
284constexpr RegStorage rs_rK0(RegStorage::kValid | rK0);
285constexpr RegStorage rs_rK1(RegStorage::kValid | rK1);
286constexpr RegStorage rs_rGP(RegStorage::kValid | rGP);
287constexpr RegStorage rs_rSP(RegStorage::kValid | rSP);
288constexpr RegStorage rs_rFP(RegStorage::kValid | rFP);
289constexpr RegStorage rs_rRA(RegStorage::kValid | rRA);
290
291constexpr RegStorage rs_rMIPS_LR(RegStorage::kInvalid); // Not used for MIPS.
292constexpr RegStorage rs_rMIPS_PC(RegStorage::kInvalid); // Not used for MIPS.
293constexpr RegStorage rs_rMIPS_COUNT(RegStorage::kInvalid); // Not used for MIPS.
294
295constexpr RegStorage rs_rF0(RegStorage::kValid | rF0);
296constexpr RegStorage rs_rF1(RegStorage::kValid | rF1);
297constexpr RegStorage rs_rF2(RegStorage::kValid | rF2);
298constexpr RegStorage rs_rF3(RegStorage::kValid | rF3);
299constexpr RegStorage rs_rF4(RegStorage::kValid | rF4);
300constexpr RegStorage rs_rF5(RegStorage::kValid | rF5);
301constexpr RegStorage rs_rF6(RegStorage::kValid | rF6);
302constexpr RegStorage rs_rF7(RegStorage::kValid | rF7);
303constexpr RegStorage rs_rF8(RegStorage::kValid | rF8);
304constexpr RegStorage rs_rF9(RegStorage::kValid | rF9);
305constexpr RegStorage rs_rF10(RegStorage::kValid | rF10);
306constexpr RegStorage rs_rF11(RegStorage::kValid | rF11);
307constexpr RegStorage rs_rF12(RegStorage::kValid | rF12);
308constexpr RegStorage rs_rF13(RegStorage::kValid | rF13);
309constexpr RegStorage rs_rF14(RegStorage::kValid | rF14);
310constexpr RegStorage rs_rF15(RegStorage::kValid | rF15);
311
Ian Rogersd582fa42014-11-05 23:46:43 -0800312constexpr RegStorage rs_rD0_fr0(RegStorage::kValid | rD0_fr0);
313constexpr RegStorage rs_rD1_fr0(RegStorage::kValid | rD1_fr0);
314constexpr RegStorage rs_rD2_fr0(RegStorage::kValid | rD2_fr0);
315constexpr RegStorage rs_rD3_fr0(RegStorage::kValid | rD3_fr0);
316constexpr RegStorage rs_rD4_fr0(RegStorage::kValid | rD4_fr0);
317constexpr RegStorage rs_rD5_fr0(RegStorage::kValid | rD5_fr0);
318constexpr RegStorage rs_rD6_fr0(RegStorage::kValid | rD6_fr0);
319constexpr RegStorage rs_rD7_fr0(RegStorage::kValid | rD7_fr0);
320
321constexpr RegStorage rs_rD0_fr1(RegStorage::kValid | rD0_fr1);
322constexpr RegStorage rs_rD1_fr1(RegStorage::kValid | rD1_fr1);
323constexpr RegStorage rs_rD2_fr1(RegStorage::kValid | rD2_fr1);
324constexpr RegStorage rs_rD3_fr1(RegStorage::kValid | rD3_fr1);
325constexpr RegStorage rs_rD4_fr1(RegStorage::kValid | rD4_fr1);
326constexpr RegStorage rs_rD5_fr1(RegStorage::kValid | rD5_fr1);
327constexpr RegStorage rs_rD6_fr1(RegStorage::kValid | rD6_fr1);
328constexpr RegStorage rs_rD7_fr1(RegStorage::kValid | rD7_fr1);
buzbee2700f7e2014-03-07 09:46:20 -0800329
330// TODO: reduce/eliminate use of these.
331#define rMIPS_SUSPEND rS0
332#define rs_rMIPS_SUSPEND rs_rS0
333#define rMIPS_SELF rS1
334#define rs_rMIPS_SELF rs_rS1
335#define rMIPS_SP rSP
336#define rs_rMIPS_SP rs_rSP
337#define rMIPS_ARG0 rARG0
338#define rs_rMIPS_ARG0 rs_rARG0
339#define rMIPS_ARG1 rARG1
340#define rs_rMIPS_ARG1 rs_rARG1
341#define rMIPS_ARG2 rARG2
342#define rs_rMIPS_ARG2 rs_rARG2
343#define rMIPS_ARG3 rARG3
344#define rs_rMIPS_ARG3 rs_rARG3
345#define rMIPS_FARG0 rFARG0
346#define rs_rMIPS_FARG0 rs_rFARG0
347#define rMIPS_FARG1 rFARG1
348#define rs_rMIPS_FARG1 rs_rFARG1
349#define rMIPS_FARG2 rFARG2
350#define rs_rMIPS_FARG2 rs_rFARG2
351#define rMIPS_FARG3 rFARG3
buzbee091cc402014-03-31 10:14:40 -0700352#define rs_rMIPS_FARG3 rs_rFARG3
buzbee2700f7e2014-03-07 09:46:20 -0800353#define rMIPS_RET0 rRESULT0
buzbee091cc402014-03-31 10:14:40 -0700354#define rs_rMIPS_RET0 rs_rRESULT0
buzbee2700f7e2014-03-07 09:46:20 -0800355#define rMIPS_RET1 rRESULT1
356#define rs_rMIPS_RET1 rs_rRESULT1
357#define rMIPS_INVOKE_TGT rT9
358#define rs_rMIPS_INVOKE_TGT rs_rT9
359#define rMIPS_COUNT RegStorage::kInvalidRegVal
Brian Carlstrom7940e442013-07-12 13:46:57 -0700360
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000361// RegisterLocation templates return values (r_V0, or r_V0/r_V1).
362const RegLocation mips_loc_c_return
buzbee091cc402014-03-31 10:14:40 -0700363 {kLocPhysReg, 0, 0, 0, 0, 0, 0, 0, 1,
buzbee2700f7e2014-03-07 09:46:20 -0800364 RegStorage(RegStorage::k32BitSolo, rV0), INVALID_SREG, INVALID_SREG};
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000365const RegLocation mips_loc_c_return_wide
buzbee091cc402014-03-31 10:14:40 -0700366 {kLocPhysReg, 1, 0, 0, 0, 0, 0, 0, 1,
buzbee2700f7e2014-03-07 09:46:20 -0800367 RegStorage(RegStorage::k64BitPair, rV0, rV1), INVALID_SREG, INVALID_SREG};
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000368const RegLocation mips_loc_c_return_float
buzbee091cc402014-03-31 10:14:40 -0700369 {kLocPhysReg, 0, 0, 0, 1, 0, 0, 0, 1,
buzbee2700f7e2014-03-07 09:46:20 -0800370 RegStorage(RegStorage::k32BitSolo, rF0), INVALID_SREG, INVALID_SREG};
buzbee091cc402014-03-31 10:14:40 -0700371// FIXME: move MIPS to k64Bitsolo for doubles
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000372const RegLocation mips_loc_c_return_double
buzbee091cc402014-03-31 10:14:40 -0700373 {kLocPhysReg, 1, 0, 0, 1, 0, 0, 0, 1,
buzbee2700f7e2014-03-07 09:46:20 -0800374 RegStorage(RegStorage::k64BitPair, rF0, rF1), INVALID_SREG, INVALID_SREG};
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000375
Brian Carlstrom7940e442013-07-12 13:46:57 -0700376enum MipsShiftEncodings {
377 kMipsLsl = 0x0,
378 kMipsLsr = 0x1,
379 kMipsAsr = 0x2,
380 kMipsRor = 0x3
381};
382
383// MIPS sync kinds (Note: support for kinds other than kSYNC0 may not exist).
384#define kSYNC0 0x00
385#define kSYNC_WMB 0x04
386#define kSYNC_MB 0x01
387#define kSYNC_ACQUIRE 0x11
388#define kSYNC_RELEASE 0x12
389#define kSYNC_RMB 0x13
390
391// TODO: Use smaller hammer when appropriate for target CPU.
392#define kST kSYNC0
393#define kSY kSYNC0
394
395/*
396 * The following enum defines the list of supported Thumb instructions by the
397 * assembler. Their corresponding EncodingMap positions will be defined in
398 * Assemble.cc.
399 */
400enum MipsOpCode {
401 kMipsFirst = 0,
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700402 kMips32BitData = kMipsFirst, // data [31..0].
403 kMipsAddiu, // addiu t,s,imm16 [001001] s[25..21] t[20..16] imm16[15..0].
Brian Carlstrom7940e442013-07-12 13:46:57 -0700404 kMipsAddu, // add d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000100001].
405 kMipsAnd, // and d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000100100].
406 kMipsAndi, // andi t,s,imm16 [001100] s[25..21] t[20..16] imm16[15..0].
407 kMipsB, // b o [0001000000000000] o[15..0].
408 kMipsBal, // bal o [0000010000010001] o[15..0].
409 // NOTE: the code tests the range kMipsBeq thru kMipsBne, so adding an instruction in this
410 // range may require updates.
411 kMipsBeq, // beq s,t,o [000100] s[25..21] t[20..16] o[15..0].
412 kMipsBeqz, // beqz s,o [000100] s[25..21] [00000] o[15..0].
413 kMipsBgez, // bgez s,o [000001] s[25..21] [00001] o[15..0].
414 kMipsBgtz, // bgtz s,o [000111] s[25..21] [00000] o[15..0].
415 kMipsBlez, // blez s,o [000110] s[25..21] [00000] o[15..0].
416 kMipsBltz, // bltz s,o [000001] s[25..21] [00000] o[15..0].
417 kMipsBnez, // bnez s,o [000101] s[25..21] [00000] o[15..0].
418 kMipsBne, // bne s,t,o [000101] s[25..21] t[20..16] o[15..0].
419 kMipsDiv, // div s,t [000000] s[25..21] t[20..16] [0000000000011010].
Brian Carlstrom7940e442013-07-12 13:46:57 -0700420 kMipsExt, // ext t,s,p,z [011111] s[25..21] t[20..16] z[15..11] p[10..6] [000000].
Brian Carlstrom7940e442013-07-12 13:46:57 -0700421 kMipsJal, // jal t [000011] t[25..0].
422 kMipsJalr, // jalr d,s [000000] s[25..21] [00000] d[15..11] hint[10..6] [001001].
423 kMipsJr, // jr s [000000] s[25..21] [0000000000] hint[10..6] [001000].
424 kMipsLahi, // lui t,imm16 [00111100000] t[20..16] imm16[15..0] load addr hi.
425 kMipsLalo, // ori t,s,imm16 [001001] s[25..21] t[20..16] imm16[15..0] load addr lo.
426 kMipsLui, // lui t,imm16 [00111100000] t[20..16] imm16[15..0].
427 kMipsLb, // lb t,o(b) [100000] b[25..21] t[20..16] o[15..0].
428 kMipsLbu, // lbu t,o(b) [100100] b[25..21] t[20..16] o[15..0].
429 kMipsLh, // lh t,o(b) [100001] b[25..21] t[20..16] o[15..0].
430 kMipsLhu, // lhu t,o(b) [100101] b[25..21] t[20..16] o[15..0].
431 kMipsLw, // lw t,o(b) [100011] b[25..21] t[20..16] o[15..0].
432 kMipsMfhi, // mfhi d [0000000000000000] d[15..11] [00000010000].
433 kMipsMflo, // mflo d [0000000000000000] d[15..11] [00000010010].
434 kMipsMove, // move d,s [000000] s[25..21] [00000] d[15..11] [00000100101].
435 kMipsMovz, // movz d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000001010].
436 kMipsMul, // mul d,s,t [011100] s[25..21] t[20..16] d[15..11] [00000000010].
437 kMipsNop, // nop [00000000000000000000000000000000].
438 kMipsNor, // nor d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000100111].
439 kMipsOr, // or d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000100101].
440 kMipsOri, // ori t,s,imm16 [001001] s[25..21] t[20..16] imm16[15..0].
441 kMipsPref, // pref h,o(b) [101011] b[25..21] h[20..16] o[15..0].
442 kMipsSb, // sb t,o(b) [101000] b[25..21] t[20..16] o[15..0].
Brian Carlstrom7940e442013-07-12 13:46:57 -0700443 kMipsSeb, // seb d,t [01111100000] t[20..16] d[15..11] [10000100000].
444 kMipsSeh, // seh d,t [01111100000] t[20..16] d[15..11] [11000100000].
Brian Carlstrom7940e442013-07-12 13:46:57 -0700445 kMipsSh, // sh t,o(b) [101001] b[25..21] t[20..16] o[15..0].
446 kMipsSll, // sll d,t,a [00000000000] t[20..16] d[15..11] a[10..6] [000000].
447 kMipsSllv, // sllv d,t,s [000000] s[25..21] t[20..16] d[15..11] [00000000100].
448 kMipsSlt, // slt d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000101010].
449 kMipsSlti, // slti t,s,imm16 [001010] s[25..21] t[20..16] imm16[15..0].
450 kMipsSltu, // sltu d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000101011].
451 kMipsSra, // sra d,s,imm5 [00000000000] t[20..16] d[15..11] imm5[10..6] [000011].
452 kMipsSrav, // srav d,t,s [000000] s[25..21] t[20..16] d[15..11] [00000000111].
453 kMipsSrl, // srl d,t,a [00000000000] t[20..16] d[20..16] a[10..6] [000010].
454 kMipsSrlv, // srlv d,t,s [000000] s[25..21] t[20..16] d[15..11] [00000000110].
455 kMipsSubu, // subu d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000100011].
456 kMipsSw, // sw t,o(b) [101011] b[25..21] t[20..16] o[15..0].
457 kMipsXor, // xor d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000100110].
458 kMipsXori, // xori t,s,imm16 [001110] s[25..21] t[20..16] imm16[15..0].
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700459 kMipsFadds, // add.s d,s,t [01000110000] t[20..16] s[15..11] d[10..6] [000000].
460 kMipsFsubs, // sub.s d,s,t [01000110000] t[20..16] s[15..11] d[10..6] [000001].
461 kMipsFmuls, // mul.s d,s,t [01000110000] t[20..16] s[15..11] d[10..6] [000010].
462 kMipsFdivs, // div.s d,s,t [01000110000] t[20..16] s[15..11] d[10..6] [000011].
463 kMipsFaddd, // add.d d,s,t [01000110001] t[20..16] s[15..11] d[10..6] [000000].
464 kMipsFsubd, // sub.d d,s,t [01000110001] t[20..16] s[15..11] d[10..6] [000001].
465 kMipsFmuld, // mul.d d,s,t [01000110001] t[20..16] s[15..11] d[10..6] [000010].
466 kMipsFdivd, // div.d d,s,t [01000110001] t[20..16] s[15..11] d[10..6] [000011].
467 kMipsFcvtsd, // cvt.s.d d,s [01000110001] [00000] s[15..11] d[10..6] [100000].
468 kMipsFcvtsw, // cvt.s.w d,s [01000110100] [00000] s[15..11] d[10..6] [100000].
469 kMipsFcvtds, // cvt.d.s d,s [01000110000] [00000] s[15..11] d[10..6] [100001].
470 kMipsFcvtdw, // cvt.d.w d,s [01000110100] [00000] s[15..11] d[10..6] [100001].
471 kMipsFcvtws, // cvt.w.d d,s [01000110000] [00000] s[15..11] d[10..6] [100100].
472 kMipsFcvtwd, // cvt.w.d d,s [01000110001] [00000] s[15..11] d[10..6] [100100].
473 kMipsFmovs, // mov.s d,s [01000110000] [00000] s[15..11] d[10..6] [000110].
474 kMipsFmovd, // mov.d d,s [01000110001] [00000] s[15..11] d[10..6] [000110].
475 kMipsFlwc1, // lwc1 t,o(b) [110001] b[25..21] t[20..16] o[15..0].
476 kMipsFldc1, // ldc1 t,o(b) [110101] b[25..21] t[20..16] o[15..0].
477 kMipsFswc1, // swc1 t,o(b) [111001] b[25..21] t[20..16] o[15..0].
478 kMipsFsdc1, // sdc1 t,o(b) [111101] b[25..21] t[20..16] o[15..0].
Brian Carlstrom7940e442013-07-12 13:46:57 -0700479 kMipsMfc1, // mfc1 t,s [01000100000] t[20..16] s[15..11] [00000000000].
480 kMipsMtc1, // mtc1 t,s [01000100100] t[20..16] s[15..11] [00000000000].
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700481 kMipsDelta, // Psuedo for ori t, s, <label>-<label>.
482 kMipsDeltaHi, // Pseudo for lui t, high16(<label>-<label>).
483 kMipsDeltaLo, // Pseudo for ori t, s, low16(<label>-<label>).
Brian Carlstrom7940e442013-07-12 13:46:57 -0700484 kMipsCurrPC, // jal to .+8 to materialize pc.
485 kMipsSync, // sync kind [000000] [0000000000000000] s[10..6] [001111].
486 kMipsUndefined, // undefined [011001xxxxxxxxxxxxxxxx].
487 kMipsLast
488};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700489std::ostream& operator<<(std::ostream& os, const MipsOpCode& rhs);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700490
491// Instruction assembly field_loc kind.
492enum MipsEncodingKind {
493 kFmtUnused,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700494 kFmtBitBlt, // Bit string using end/start.
495 kFmtDfp, // Double FP reg.
496 kFmtSfp, // Single FP reg
497 kFmtBlt5_2, // Same 5-bit field to 2 locations.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700498};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700499std::ostream& operator<<(std::ostream& os, const MipsEncodingKind& rhs);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700500
501// Struct used to define the snippet positions for each MIPS opcode.
502struct MipsEncodingMap {
503 uint32_t skeleton;
504 struct {
505 MipsEncodingKind kind;
506 int end; // end for kFmtBitBlt, 1-bit slice end for FP regs.
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700507 int start; // start for kFmtBitBlt, 4-bit slice end for FP regs.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700508 } field_loc[4];
509 MipsOpCode opcode;
510 uint64_t flags;
511 const char *name;
512 const char* fmt;
513 int size; // Note: size is in bytes.
514};
515
516extern MipsEncodingMap EncodingMap[kMipsLast];
517
518#define IS_UIMM16(v) ((0 <= (v)) && ((v) <= 65535))
519#define IS_SIMM16(v) ((-32768 <= (v)) && ((v) <= 32766))
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700520#define IS_SIMM16_2WORD(v) ((-32764 <= (v)) && ((v) <= 32763)) // 2 offsets must fit.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700521
522} // namespace art
523
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700524#endif // ART_COMPILER_DEX_QUICK_MIPS_MIPS_LIR_H_