blob: 5b2cb9d85e048e2f0ea89ba49f43792bc7df91f8 [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
20#include "dex/compiler_internals.h"
21
22namespace art {
23
24/*
25 * Runtime register conventions.
26 *
27 * zero is always the value 0
28 * at is scratch (normally used as temp reg by assembler)
29 * v0, v1 are scratch (normally hold subroutine return values)
30 * a0-a3 are scratch (normally hold subroutine arguments)
31 * t0-t8 are scratch
32 * t9 is scratch (normally used for function calls)
33 * s0 (rMIPS_SUSPEND) is reserved [holds suspend-check counter]
34 * s1 (rMIPS_SELF) is reserved [holds current &Thread]
35 * s2-s7 are callee save (promotion target)
36 * k0, k1 are reserved for use by interrupt handlers
37 * gp is reserved for global pointer
38 * sp is reserved
39 * s8 is callee save (promotion target)
40 * ra is scratch (normally holds the return addr)
41 *
42 * Preserved across C calls: s0-s8
43 * Trashed across C calls: at, v0-v1, a0-a3, t0-t9, gp, ra
44 *
45 * Floating pointer registers
46 * NOTE: there are 32 fp registers (16 df pairs), but currently
47 * only support 16 fp registers (8 df pairs).
48 * f0-f15
49 * df0-df7, where df0={f0,f1}, df1={f2,f3}, ... , df7={f14,f15}
50 *
51 * f0-f15 (df0-df7) trashed across C calls
52 *
53 * For mips32 code use:
54 * a0-a3 to hold operands
55 * v0-v1 to hold results
56 * t0-t9 for temps
57 *
58 * All jump/branch instructions have a delay slot after it.
59 *
60 * Stack frame diagram (stack grows down, higher addresses at top):
61 *
62 * +------------------------+
63 * | IN[ins-1] | {Note: resides in caller's frame}
64 * | . |
65 * | IN[0] |
66 * | caller's Method* |
67 * +========================+ {Note: start of callee's frame}
68 * | spill region | {variable sized - will include lr if non-leaf.}
69 * +------------------------+
70 * | ...filler word... | {Note: used as 2nd word of V[locals-1] if long]
71 * +------------------------+
72 * | V[locals-1] |
73 * | V[locals-2] |
74 * | . |
75 * | . |
76 * | V[1] |
77 * | V[0] |
78 * +------------------------+
79 * | 0 to 3 words padding |
80 * +------------------------+
81 * | OUT[outs-1] |
82 * | OUT[outs-2] |
83 * | . |
84 * | OUT[0] |
85 * | cur_method* | <<== sp w/ 16-byte alignment
86 * +========================+
87 */
88
Brian Carlstrom7940e442013-07-12 13:46:57 -070089
Brian Carlstrom7940e442013-07-12 13:46:57 -070090#define LOWORD_OFFSET 0
91#define HIWORD_OFFSET 4
buzbee2700f7e2014-03-07 09:46:20 -080092#define rARG0 rA0
93#define rs_rARG0 rs_rA0
94#define rARG1 rA1
95#define rs_rARG1 rs_rA1
96#define rARG2 rA2
97#define rs_rARG2 rs_rA2
98#define rARG3 rA3
99#define rs_rARG3 rs_rA3
100#define rRESULT0 rV0
101#define rs_rRESULT0 rs_rV0
102#define rRESULT1 rV1
103#define rs_rRESULT1 rs_rV1
Brian Carlstrom7940e442013-07-12 13:46:57 -0700104
buzbee2700f7e2014-03-07 09:46:20 -0800105#define rFARG0 rF12
106#define rs_rFARG0 rs_rF12
107#define rFARG1 rF13
108#define rs_rFARG1 rs_rF13
109#define rFARG2 rF14
110#define rs_rFARG2 rs_rF14
111#define rFARG3 rF15
112#define rs_rFARG3 rs_rF15
113#define rFRESULT0 rF0
114#define rs_rFRESULT0 rs_rF0
115#define rFRESULT1 rF1
116#define rs_rFRESULT1 rs_rF1
Brian Carlstrom7940e442013-07-12 13:46:57 -0700117
118// Regs not used for Mips.
buzbee2700f7e2014-03-07 09:46:20 -0800119#define rMIPS_LR RegStorage::kInvalidRegVal
120#define rMIPS_PC RegStorage::kInvalidRegVal
Brian Carlstrom7940e442013-07-12 13:46:57 -0700121
Brian Carlstrom7940e442013-07-12 13:46:57 -0700122enum MipsResourceEncodingPos {
123 kMipsGPReg0 = 0,
124 kMipsRegSP = 29,
125 kMipsRegLR = 31,
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700126 kMipsFPReg0 = 32, // only 16 fp regs supported currently.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700127 kMipsFPRegEnd = 48,
128 kMipsRegHI = kMipsFPRegEnd,
129 kMipsRegLO,
130 kMipsRegPC,
131 kMipsRegEnd = 51,
132};
133
134#define ENCODE_MIPS_REG_LIST(N) (static_cast<uint64_t>(N))
135#define ENCODE_MIPS_REG_SP (1ULL << kMipsRegSP)
136#define ENCODE_MIPS_REG_LR (1ULL << kMipsRegLR)
137#define ENCODE_MIPS_REG_PC (1ULL << kMipsRegPC)
buzbee9da5c102014-03-28 12:59:18 -0700138#define ENCODE_MIPS_REG_HI (1ULL << kMipsRegHI)
139#define ENCODE_MIPS_REG_LO (1ULL << kMipsRegLO)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700140
141enum MipsNativeRegisterPool {
buzbee091cc402014-03-31 10:14:40 -0700142 rZERO = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 0,
143 rAT = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 1,
144 rV0 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 2,
145 rV1 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 3,
146 rA0 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 4,
147 rA1 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 5,
148 rA2 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 6,
149 rA3 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 7,
150 rT0 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 8,
151 rT1 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 9,
152 rT2 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 10,
153 rT3 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 11,
154 rT4 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 12,
155 rT5 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 13,
156 rT6 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 14,
157 rT7 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 15,
158 rS0 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 16,
159 rS1 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 17,
160 rS2 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 18,
161 rS3 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 19,
162 rS4 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 20,
163 rS5 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 21,
164 rS6 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 22,
165 rS7 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 23,
166 rT8 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 24,
167 rT9 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 25,
168 rK0 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 26,
169 rK1 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 27,
170 rGP = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 28,
171 rSP = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 29,
172 rFP = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 30,
173 rRA = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 31,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700174
buzbee091cc402014-03-31 10:14:40 -0700175 rF0 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 0,
176 rF1 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 1,
177 rF2 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 2,
178 rF3 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 3,
179 rF4 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 4,
180 rF5 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 5,
181 rF6 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 6,
182 rF7 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 7,
183 rF8 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 8,
184 rF9 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 9,
185 rF10 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 10,
186 rF11 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 11,
187 rF12 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 12,
188 rF13 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 13,
189 rF14 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 14,
190 rF15 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 15,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700191#if 0
192 /*
193 * TODO: The shared resource mask doesn't have enough bit positions to describe all
194 * MIPS registers. Expand it and enable use of fp registers 16 through 31.
195 */
buzbee091cc402014-03-31 10:14:40 -0700196 rF16 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 16,
197 rF17 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 17,
198 rF18 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 18,
199 rF19 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 19,
200 rF20 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 20,
201 rF21 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 21,
202 rF22 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 22,
203 rF23 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 23,
204 rF24 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 24,
205 rF25 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 25,
206 rF26 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 26,
207 rF27 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 27,
208 rF28 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 28,
209 rF29 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 29,
210 rF30 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 30,
211 rF31 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 31,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700212#endif
buzbee091cc402014-03-31 10:14:40 -0700213 rD0 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 0,
214 rD1 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 1,
215 rD2 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 2,
216 rD3 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 3,
217 rD4 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 4,
218 rD5 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 5,
219 rD6 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 6,
220 rD7 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 7,
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700221#if 0 // TODO: expand resource mask to enable use of all MIPS fp registers.
buzbee091cc402014-03-31 10:14:40 -0700222 rD8 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 8,
223 rD9 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 9,
224 rD10 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 10,
225 rD11 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 11,
226 rD12 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 12,
227 rD13 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 13,
228 rD14 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 14,
229 rD15 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 15,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700230#endif
Brian Carlstrom7940e442013-07-12 13:46:57 -0700231};
232
buzbee091cc402014-03-31 10:14:40 -0700233constexpr RegStorage rs_rZERO(RegStorage::kValid | rZERO);
234constexpr RegStorage rs_rAT(RegStorage::kValid | rAT);
235constexpr RegStorage rs_rV0(RegStorage::kValid | rV0);
236constexpr RegStorage rs_rV1(RegStorage::kValid | rV1);
237constexpr RegStorage rs_rA0(RegStorage::kValid | rA0);
238constexpr RegStorage rs_rA1(RegStorage::kValid | rA1);
239constexpr RegStorage rs_rA2(RegStorage::kValid | rA2);
240constexpr RegStorage rs_rA3(RegStorage::kValid | rA3);
241constexpr RegStorage rs_rT0(RegStorage::kValid | rT0);
242constexpr RegStorage rs_rT1(RegStorage::kValid | rT1);
243constexpr RegStorage rs_rT2(RegStorage::kValid | rT2);
244constexpr RegStorage rs_rT3(RegStorage::kValid | rT3);
245constexpr RegStorage rs_rT4(RegStorage::kValid | rT4);
246constexpr RegStorage rs_rT5(RegStorage::kValid | rT5);
247constexpr RegStorage rs_rT6(RegStorage::kValid | rT6);
248constexpr RegStorage rs_rT7(RegStorage::kValid | rT7);
249constexpr RegStorage rs_rS0(RegStorage::kValid | rS0);
250constexpr RegStorage rs_rS1(RegStorage::kValid | rS1);
251constexpr RegStorage rs_rS2(RegStorage::kValid | rS2);
252constexpr RegStorage rs_rS3(RegStorage::kValid | rS3);
253constexpr RegStorage rs_rS4(RegStorage::kValid | rS4);
254constexpr RegStorage rs_rS5(RegStorage::kValid | rS5);
255constexpr RegStorage rs_rS6(RegStorage::kValid | rS6);
256constexpr RegStorage rs_rS7(RegStorage::kValid | rS7);
257constexpr RegStorage rs_rT8(RegStorage::kValid | rT8);
258constexpr RegStorage rs_rT9(RegStorage::kValid | rT9);
259constexpr RegStorage rs_rK0(RegStorage::kValid | rK0);
260constexpr RegStorage rs_rK1(RegStorage::kValid | rK1);
261constexpr RegStorage rs_rGP(RegStorage::kValid | rGP);
262constexpr RegStorage rs_rSP(RegStorage::kValid | rSP);
263constexpr RegStorage rs_rFP(RegStorage::kValid | rFP);
264constexpr RegStorage rs_rRA(RegStorage::kValid | rRA);
265
266constexpr RegStorage rs_rMIPS_LR(RegStorage::kInvalid); // Not used for MIPS.
267constexpr RegStorage rs_rMIPS_PC(RegStorage::kInvalid); // Not used for MIPS.
268constexpr RegStorage rs_rMIPS_COUNT(RegStorage::kInvalid); // Not used for MIPS.
269
270constexpr RegStorage rs_rF0(RegStorage::kValid | rF0);
271constexpr RegStorage rs_rF1(RegStorage::kValid | rF1);
272constexpr RegStorage rs_rF2(RegStorage::kValid | rF2);
273constexpr RegStorage rs_rF3(RegStorage::kValid | rF3);
274constexpr RegStorage rs_rF4(RegStorage::kValid | rF4);
275constexpr RegStorage rs_rF5(RegStorage::kValid | rF5);
276constexpr RegStorage rs_rF6(RegStorage::kValid | rF6);
277constexpr RegStorage rs_rF7(RegStorage::kValid | rF7);
278constexpr RegStorage rs_rF8(RegStorage::kValid | rF8);
279constexpr RegStorage rs_rF9(RegStorage::kValid | rF9);
280constexpr RegStorage rs_rF10(RegStorage::kValid | rF10);
281constexpr RegStorage rs_rF11(RegStorage::kValid | rF11);
282constexpr RegStorage rs_rF12(RegStorage::kValid | rF12);
283constexpr RegStorage rs_rF13(RegStorage::kValid | rF13);
284constexpr RegStorage rs_rF14(RegStorage::kValid | rF14);
285constexpr RegStorage rs_rF15(RegStorage::kValid | rF15);
286
287constexpr RegStorage rs_rD0(RegStorage::kValid | rD0);
288constexpr RegStorage rs_rD1(RegStorage::kValid | rD1);
289constexpr RegStorage rs_rD2(RegStorage::kValid | rD2);
290constexpr RegStorage rs_rD3(RegStorage::kValid | rD3);
291constexpr RegStorage rs_rD4(RegStorage::kValid | rD4);
292constexpr RegStorage rs_rD5(RegStorage::kValid | rD5);
293constexpr RegStorage rs_rD6(RegStorage::kValid | rD6);
294constexpr RegStorage rs_rD7(RegStorage::kValid | rD7);
buzbee2700f7e2014-03-07 09:46:20 -0800295
296// TODO: reduce/eliminate use of these.
297#define rMIPS_SUSPEND rS0
298#define rs_rMIPS_SUSPEND rs_rS0
299#define rMIPS_SELF rS1
300#define rs_rMIPS_SELF rs_rS1
301#define rMIPS_SP rSP
302#define rs_rMIPS_SP rs_rSP
303#define rMIPS_ARG0 rARG0
304#define rs_rMIPS_ARG0 rs_rARG0
305#define rMIPS_ARG1 rARG1
306#define rs_rMIPS_ARG1 rs_rARG1
307#define rMIPS_ARG2 rARG2
308#define rs_rMIPS_ARG2 rs_rARG2
309#define rMIPS_ARG3 rARG3
310#define rs_rMIPS_ARG3 rs_rARG3
311#define rMIPS_FARG0 rFARG0
312#define rs_rMIPS_FARG0 rs_rFARG0
313#define rMIPS_FARG1 rFARG1
314#define rs_rMIPS_FARG1 rs_rFARG1
315#define rMIPS_FARG2 rFARG2
316#define rs_rMIPS_FARG2 rs_rFARG2
317#define rMIPS_FARG3 rFARG3
buzbee091cc402014-03-31 10:14:40 -0700318#define rs_rMIPS_FARG3 rs_rFARG3
buzbee2700f7e2014-03-07 09:46:20 -0800319#define rMIPS_RET0 rRESULT0
buzbee091cc402014-03-31 10:14:40 -0700320#define rs_rMIPS_RET0 rs_rRESULT0
buzbee2700f7e2014-03-07 09:46:20 -0800321#define rMIPS_RET1 rRESULT1
322#define rs_rMIPS_RET1 rs_rRESULT1
323#define rMIPS_INVOKE_TGT rT9
324#define rs_rMIPS_INVOKE_TGT rs_rT9
325#define rMIPS_COUNT RegStorage::kInvalidRegVal
Brian Carlstrom7940e442013-07-12 13:46:57 -0700326
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000327// RegisterLocation templates return values (r_V0, or r_V0/r_V1).
328const RegLocation mips_loc_c_return
buzbee091cc402014-03-31 10:14:40 -0700329 {kLocPhysReg, 0, 0, 0, 0, 0, 0, 0, 1,
buzbee2700f7e2014-03-07 09:46:20 -0800330 RegStorage(RegStorage::k32BitSolo, rV0), INVALID_SREG, INVALID_SREG};
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000331const RegLocation mips_loc_c_return_wide
buzbee091cc402014-03-31 10:14:40 -0700332 {kLocPhysReg, 1, 0, 0, 0, 0, 0, 0, 1,
buzbee2700f7e2014-03-07 09:46:20 -0800333 RegStorage(RegStorage::k64BitPair, rV0, rV1), INVALID_SREG, INVALID_SREG};
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000334const RegLocation mips_loc_c_return_float
buzbee091cc402014-03-31 10:14:40 -0700335 {kLocPhysReg, 0, 0, 0, 1, 0, 0, 0, 1,
buzbee2700f7e2014-03-07 09:46:20 -0800336 RegStorage(RegStorage::k32BitSolo, rF0), INVALID_SREG, INVALID_SREG};
buzbee091cc402014-03-31 10:14:40 -0700337// FIXME: move MIPS to k64Bitsolo for doubles
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000338const RegLocation mips_loc_c_return_double
buzbee091cc402014-03-31 10:14:40 -0700339 {kLocPhysReg, 1, 0, 0, 1, 0, 0, 0, 1,
buzbee2700f7e2014-03-07 09:46:20 -0800340 RegStorage(RegStorage::k64BitPair, rF0, rF1), INVALID_SREG, INVALID_SREG};
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000341
Brian Carlstrom7940e442013-07-12 13:46:57 -0700342enum MipsShiftEncodings {
343 kMipsLsl = 0x0,
344 kMipsLsr = 0x1,
345 kMipsAsr = 0x2,
346 kMipsRor = 0x3
347};
348
349// MIPS sync kinds (Note: support for kinds other than kSYNC0 may not exist).
350#define kSYNC0 0x00
351#define kSYNC_WMB 0x04
352#define kSYNC_MB 0x01
353#define kSYNC_ACQUIRE 0x11
354#define kSYNC_RELEASE 0x12
355#define kSYNC_RMB 0x13
356
357// TODO: Use smaller hammer when appropriate for target CPU.
358#define kST kSYNC0
359#define kSY kSYNC0
360
361/*
362 * The following enum defines the list of supported Thumb instructions by the
363 * assembler. Their corresponding EncodingMap positions will be defined in
364 * Assemble.cc.
365 */
366enum MipsOpCode {
367 kMipsFirst = 0,
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700368 kMips32BitData = kMipsFirst, // data [31..0].
369 kMipsAddiu, // addiu t,s,imm16 [001001] s[25..21] t[20..16] imm16[15..0].
Brian Carlstrom7940e442013-07-12 13:46:57 -0700370 kMipsAddu, // add d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000100001].
371 kMipsAnd, // and d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000100100].
372 kMipsAndi, // andi t,s,imm16 [001100] s[25..21] t[20..16] imm16[15..0].
373 kMipsB, // b o [0001000000000000] o[15..0].
374 kMipsBal, // bal o [0000010000010001] o[15..0].
375 // NOTE: the code tests the range kMipsBeq thru kMipsBne, so adding an instruction in this
376 // range may require updates.
377 kMipsBeq, // beq s,t,o [000100] s[25..21] t[20..16] o[15..0].
378 kMipsBeqz, // beqz s,o [000100] s[25..21] [00000] o[15..0].
379 kMipsBgez, // bgez s,o [000001] s[25..21] [00001] o[15..0].
380 kMipsBgtz, // bgtz s,o [000111] s[25..21] [00000] o[15..0].
381 kMipsBlez, // blez s,o [000110] s[25..21] [00000] o[15..0].
382 kMipsBltz, // bltz s,o [000001] s[25..21] [00000] o[15..0].
383 kMipsBnez, // bnez s,o [000101] s[25..21] [00000] o[15..0].
384 kMipsBne, // bne s,t,o [000101] s[25..21] t[20..16] o[15..0].
385 kMipsDiv, // div s,t [000000] s[25..21] t[20..16] [0000000000011010].
Brian Carlstrom38f85e42013-07-18 14:45:22 -0700386#if __mips_isa_rev >= 2
Brian Carlstrom7940e442013-07-12 13:46:57 -0700387 kMipsExt, // ext t,s,p,z [011111] s[25..21] t[20..16] z[15..11] p[10..6] [000000].
388#endif
389 kMipsJal, // jal t [000011] t[25..0].
390 kMipsJalr, // jalr d,s [000000] s[25..21] [00000] d[15..11] hint[10..6] [001001].
391 kMipsJr, // jr s [000000] s[25..21] [0000000000] hint[10..6] [001000].
392 kMipsLahi, // lui t,imm16 [00111100000] t[20..16] imm16[15..0] load addr hi.
393 kMipsLalo, // ori t,s,imm16 [001001] s[25..21] t[20..16] imm16[15..0] load addr lo.
394 kMipsLui, // lui t,imm16 [00111100000] t[20..16] imm16[15..0].
395 kMipsLb, // lb t,o(b) [100000] b[25..21] t[20..16] o[15..0].
396 kMipsLbu, // lbu t,o(b) [100100] b[25..21] t[20..16] o[15..0].
397 kMipsLh, // lh t,o(b) [100001] b[25..21] t[20..16] o[15..0].
398 kMipsLhu, // lhu t,o(b) [100101] b[25..21] t[20..16] o[15..0].
399 kMipsLw, // lw t,o(b) [100011] b[25..21] t[20..16] o[15..0].
400 kMipsMfhi, // mfhi d [0000000000000000] d[15..11] [00000010000].
401 kMipsMflo, // mflo d [0000000000000000] d[15..11] [00000010010].
402 kMipsMove, // move d,s [000000] s[25..21] [00000] d[15..11] [00000100101].
403 kMipsMovz, // movz d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000001010].
404 kMipsMul, // mul d,s,t [011100] s[25..21] t[20..16] d[15..11] [00000000010].
405 kMipsNop, // nop [00000000000000000000000000000000].
406 kMipsNor, // nor d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000100111].
407 kMipsOr, // or d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000100101].
408 kMipsOri, // ori t,s,imm16 [001001] s[25..21] t[20..16] imm16[15..0].
409 kMipsPref, // pref h,o(b) [101011] b[25..21] h[20..16] o[15..0].
410 kMipsSb, // sb t,o(b) [101000] b[25..21] t[20..16] o[15..0].
Brian Carlstrom38f85e42013-07-18 14:45:22 -0700411#if __mips_isa_rev >= 2
Brian Carlstrom7940e442013-07-12 13:46:57 -0700412 kMipsSeb, // seb d,t [01111100000] t[20..16] d[15..11] [10000100000].
413 kMipsSeh, // seh d,t [01111100000] t[20..16] d[15..11] [11000100000].
414#endif
415 kMipsSh, // sh t,o(b) [101001] b[25..21] t[20..16] o[15..0].
416 kMipsSll, // sll d,t,a [00000000000] t[20..16] d[15..11] a[10..6] [000000].
417 kMipsSllv, // sllv d,t,s [000000] s[25..21] t[20..16] d[15..11] [00000000100].
418 kMipsSlt, // slt d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000101010].
419 kMipsSlti, // slti t,s,imm16 [001010] s[25..21] t[20..16] imm16[15..0].
420 kMipsSltu, // sltu d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000101011].
421 kMipsSra, // sra d,s,imm5 [00000000000] t[20..16] d[15..11] imm5[10..6] [000011].
422 kMipsSrav, // srav d,t,s [000000] s[25..21] t[20..16] d[15..11] [00000000111].
423 kMipsSrl, // srl d,t,a [00000000000] t[20..16] d[20..16] a[10..6] [000010].
424 kMipsSrlv, // srlv d,t,s [000000] s[25..21] t[20..16] d[15..11] [00000000110].
425 kMipsSubu, // subu d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000100011].
426 kMipsSw, // sw t,o(b) [101011] b[25..21] t[20..16] o[15..0].
427 kMipsXor, // xor d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000100110].
428 kMipsXori, // xori t,s,imm16 [001110] s[25..21] t[20..16] imm16[15..0].
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700429 kMipsFadds, // add.s d,s,t [01000110000] t[20..16] s[15..11] d[10..6] [000000].
430 kMipsFsubs, // sub.s d,s,t [01000110000] t[20..16] s[15..11] d[10..6] [000001].
431 kMipsFmuls, // mul.s d,s,t [01000110000] t[20..16] s[15..11] d[10..6] [000010].
432 kMipsFdivs, // div.s d,s,t [01000110000] t[20..16] s[15..11] d[10..6] [000011].
433 kMipsFaddd, // add.d d,s,t [01000110001] t[20..16] s[15..11] d[10..6] [000000].
434 kMipsFsubd, // sub.d d,s,t [01000110001] t[20..16] s[15..11] d[10..6] [000001].
435 kMipsFmuld, // mul.d d,s,t [01000110001] t[20..16] s[15..11] d[10..6] [000010].
436 kMipsFdivd, // div.d d,s,t [01000110001] t[20..16] s[15..11] d[10..6] [000011].
437 kMipsFcvtsd, // cvt.s.d d,s [01000110001] [00000] s[15..11] d[10..6] [100000].
438 kMipsFcvtsw, // cvt.s.w d,s [01000110100] [00000] s[15..11] d[10..6] [100000].
439 kMipsFcvtds, // cvt.d.s d,s [01000110000] [00000] s[15..11] d[10..6] [100001].
440 kMipsFcvtdw, // cvt.d.w d,s [01000110100] [00000] s[15..11] d[10..6] [100001].
441 kMipsFcvtws, // cvt.w.d d,s [01000110000] [00000] s[15..11] d[10..6] [100100].
442 kMipsFcvtwd, // cvt.w.d d,s [01000110001] [00000] s[15..11] d[10..6] [100100].
443 kMipsFmovs, // mov.s d,s [01000110000] [00000] s[15..11] d[10..6] [000110].
444 kMipsFmovd, // mov.d d,s [01000110001] [00000] s[15..11] d[10..6] [000110].
445 kMipsFlwc1, // lwc1 t,o(b) [110001] b[25..21] t[20..16] o[15..0].
446 kMipsFldc1, // ldc1 t,o(b) [110101] b[25..21] t[20..16] o[15..0].
447 kMipsFswc1, // swc1 t,o(b) [111001] b[25..21] t[20..16] o[15..0].
448 kMipsFsdc1, // sdc1 t,o(b) [111101] b[25..21] t[20..16] o[15..0].
Brian Carlstrom7940e442013-07-12 13:46:57 -0700449 kMipsMfc1, // mfc1 t,s [01000100000] t[20..16] s[15..11] [00000000000].
450 kMipsMtc1, // mtc1 t,s [01000100100] t[20..16] s[15..11] [00000000000].
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700451 kMipsDelta, // Psuedo for ori t, s, <label>-<label>.
452 kMipsDeltaHi, // Pseudo for lui t, high16(<label>-<label>).
453 kMipsDeltaLo, // Pseudo for ori t, s, low16(<label>-<label>).
Brian Carlstrom7940e442013-07-12 13:46:57 -0700454 kMipsCurrPC, // jal to .+8 to materialize pc.
455 kMipsSync, // sync kind [000000] [0000000000000000] s[10..6] [001111].
456 kMipsUndefined, // undefined [011001xxxxxxxxxxxxxxxx].
457 kMipsLast
458};
459
460// Instruction assembly field_loc kind.
461enum MipsEncodingKind {
462 kFmtUnused,
463 kFmtBitBlt, /* Bit string using end/start */
464 kFmtDfp, /* Double FP reg */
465 kFmtSfp, /* Single FP reg */
466 kFmtBlt5_2, /* Same 5-bit field to 2 locations */
467};
468
469// Struct used to define the snippet positions for each MIPS opcode.
470struct MipsEncodingMap {
471 uint32_t skeleton;
472 struct {
473 MipsEncodingKind kind;
474 int end; // end for kFmtBitBlt, 1-bit slice end for FP regs.
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700475 int start; // start for kFmtBitBlt, 4-bit slice end for FP regs.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700476 } field_loc[4];
477 MipsOpCode opcode;
478 uint64_t flags;
479 const char *name;
480 const char* fmt;
481 int size; // Note: size is in bytes.
482};
483
484extern MipsEncodingMap EncodingMap[kMipsLast];
485
486#define IS_UIMM16(v) ((0 <= (v)) && ((v) <= 65535))
487#define IS_SIMM16(v) ((-32768 <= (v)) && ((v) <= 32766))
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700488#define IS_SIMM16_2WORD(v) ((-32764 <= (v)) && ((v) <= 32763)) // 2 offsets must fit.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700489
490} // namespace art
491
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700492#endif // ART_COMPILER_DEX_QUICK_MIPS_MIPS_LIR_H_