blob: 2253d1006c2e91753d0df04013e2d7682a30d574 [file] [log] [blame]
Matteo Franchin43ec8732014-03-31 15:00:14 +01001/*
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#ifndef ART_COMPILER_DEX_QUICK_ARM64_ARM64_LIR_H_
18#define ART_COMPILER_DEX_QUICK_ARM64_ARM64_LIR_H_
19
Andreas Gampe0b9203e2015-01-22 20:39:27 -080020#include "dex/compiler_enums.h"
21#include "dex/reg_location.h"
22#include "dex/reg_storage.h"
Matteo Franchin43ec8732014-03-31 15:00:14 +010023
24namespace art {
25
26/*
27 * Runtime register usage conventions.
28 *
Matteo Franchin4163c532014-07-15 15:20:27 +010029 * r0 : As in C/C++ w0 is 32-bit return register and x0 is 64-bit.
30 * r0-r7 : Argument registers in both Dalvik and C/C++ conventions.
31 * However, for Dalvik->Dalvik calls we'll pass the target's Method*
32 * pointer in x0 as a hidden arg0. Otherwise used as codegen scratch
33 * registers.
34 * r8-r15 : Caller save registers (used as temporary registers).
35 * r16-r17: Also known as ip0-ip1, respectively. Used as scratch registers by
36 * the linker, by the trampolines and other stubs (the backend uses
37 * these as temporary registers).
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010038 * r18 : Caller save register (used as temporary register).
39 * r19 : (rxSELF) is reserved (pointer to thread-local storage).
40 * r20-r29: Callee save registers (promotion targets).
Matteo Franchin4163c532014-07-15 15:20:27 +010041 * r30 : (lr) is reserved (the link register).
42 * rsp : (sp) is reserved (the stack pointer).
43 * rzr : (zr) is reserved (the zero register).
Matteo Franchin43ec8732014-03-31 15:00:14 +010044 *
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010045 * 19 core temps that codegen can use (r0-r18).
46 * 9 core registers that can be used for promotion.
Matteo Franchin43ec8732014-03-31 15:00:14 +010047 *
Matteo Franchin4163c532014-07-15 15:20:27 +010048 * Floating-point registers
49 * v0-v31
Matteo Franchin43ec8732014-03-31 15:00:14 +010050 *
Matteo Franchin4163c532014-07-15 15:20:27 +010051 * v0 : s0 is return register for singles (32-bit) and d0 for doubles (64-bit).
52 * This is analogous to the C/C++ (hard-float) calling convention.
53 * v0-v7 : Floating-point argument registers in both Dalvik and C/C++ conventions.
54 * Also used as temporary and codegen scratch registers.
Matteo Franchin43ec8732014-03-31 15:00:14 +010055 *
Matteo Franchin4163c532014-07-15 15:20:27 +010056 * v0-v7 and v16-v31 : trashed across C calls.
57 * v8-v15 : bottom 64-bits preserved across C calls (d8-d15 are preserved).
Matteo Franchin43ec8732014-03-31 15:00:14 +010058 *
Matteo Franchin4163c532014-07-15 15:20:27 +010059 * v16-v31: Used as codegen temp/scratch.
60 * v8-v15 : Can be used for promotion.
61 *
62 * Calling convention (Hard-float)
63 * o On a call to a Dalvik method, pass target's Method* in x0
64 * o r1-r7, v0-v7 will be used for the first 7+8 arguments
65 * o Arguments which cannot be put in registers are placed in appropriate
Matteo Franchin43ec8732014-03-31 15:00:14 +010066 * out slots by the caller.
Matteo Franchin43ec8732014-03-31 15:00:14 +010067 * o Maintain a 16-byte stack alignment
68 *
69 * Stack frame diagram (stack grows down, higher addresses at top):
70 *
Matteo Franchin4163c532014-07-15 15:20:27 +010071 * +--------------------------------------------+
72 * | IN[ins-1] | {Note: resides in caller's frame}
73 * | . |
74 * | IN[0] |
Mathieu Chartiere401d142015-04-22 13:56:20 -070075 * | caller's method ArtMethod* | {Pointer sized reference}
Matteo Franchin4163c532014-07-15 15:20:27 +010076 * +============================================+ {Note: start of callee's frame}
77 * | spill region | {variable sized - will include lr if non-leaf}
78 * +--------------------------------------------+
79 * | ...filler word... | {Note: used as 2nd word of V[locals-1] if long}
80 * +--------------------------------------------+
81 * | V[locals-1] |
82 * | V[locals-2] |
83 * | . |
84 * | . |
85 * | V[1] |
86 * | V[0] |
87 * +--------------------------------------------+
88 * | 0 to 3 words padding |
89 * +--------------------------------------------+
90 * | OUT[outs-1] |
91 * | OUT[outs-2] |
92 * | . |
93 * | OUT[0] |
Mathieu Chartiere401d142015-04-22 13:56:20 -070094 * | current method ArtMethod* | <<== sp w/ 16-byte alignment
Matteo Franchin4163c532014-07-15 15:20:27 +010095 * +============================================+
Matteo Franchin43ec8732014-03-31 15:00:14 +010096 */
97
98// First FP callee save.
buzbee9cdf48e2014-05-20 06:28:55 -070099#define A64_FP_CALLEE_SAVE_BASE 8
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100100
101// Temporary macros, used to mark code which wants to distinguish betweek zr/sp.
102#define A64_REG_IS_SP(reg_num) ((reg_num) == rwsp || (reg_num) == rsp)
103#define A64_REG_IS_ZR(reg_num) ((reg_num) == rwzr || (reg_num) == rxzr)
Andreas Gampe3c12c512014-06-24 18:46:29 +0000104#define A64_REGSTORAGE_IS_SP_OR_ZR(rs) (((rs).GetRegNum() & 0x1f) == 0x1f)
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100105
Matteo Franchin4163c532014-07-15 15:20:27 +0100106enum A64ResourceEncodingPos {
107 kA64GPReg0 = 0,
108 kA64RegLR = 30,
109 kA64RegSP = 31,
110 kA64FPReg0 = 32,
111 kA64RegEnd = 64,
Matteo Franchin43ec8732014-03-31 15:00:14 +0100112};
113
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100114#define IS_SIGNED_IMM(size, value) \
115 ((value) >= -(1 << ((size) - 1)) && (value) < (1 << ((size) - 1)))
116#define IS_SIGNED_IMM7(value) IS_SIGNED_IMM(7, value)
117#define IS_SIGNED_IMM9(value) IS_SIGNED_IMM(9, value)
118#define IS_SIGNED_IMM12(value) IS_SIGNED_IMM(12, value)
Zheng Xu5d7cdec2014-08-18 17:28:22 +0800119#define IS_SIGNED_IMM14(value) IS_SIGNED_IMM(14, value)
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100120#define IS_SIGNED_IMM19(value) IS_SIGNED_IMM(19, value)
121#define IS_SIGNED_IMM21(value) IS_SIGNED_IMM(21, value)
Vladimir Marko7c2ad5a2014-09-24 12:42:55 +0100122#define IS_SIGNED_IMM26(value) IS_SIGNED_IMM(26, value)
Matteo Franchin43ec8732014-03-31 15:00:14 +0100123
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100124// Quick macro used to define the registers.
125#define A64_REGISTER_CODE_LIST(R) \
126 R(0) R(1) R(2) R(3) R(4) R(5) R(6) R(7) \
127 R(8) R(9) R(10) R(11) R(12) R(13) R(14) R(15) \
128 R(16) R(17) R(18) R(19) R(20) R(21) R(22) R(23) \
129 R(24) R(25) R(26) R(27) R(28) R(29) R(30) R(31)
Matteo Franchin43ec8732014-03-31 15:00:14 +0100130
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100131// Registers (integer) values.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700132enum A64NativeRegisterPool { // private marker to avoid generate-operator-out.py from processing.
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100133# define A64_DEFINE_REGISTERS(nr) \
134 rw##nr = RegStorage::k32BitSolo | RegStorage::kCoreRegister | nr, \
buzbeeb01bf152014-05-13 15:59:07 -0700135 rx##nr = RegStorage::k64BitSolo | RegStorage::kCoreRegister | nr, \
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100136 rf##nr = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | nr, \
137 rd##nr = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | nr,
138 A64_REGISTER_CODE_LIST(A64_DEFINE_REGISTERS)
139#undef A64_DEFINE_REGISTERS
140
buzbeeb01bf152014-05-13 15:59:07 -0700141 rxzr = RegStorage::k64BitSolo | RegStorage::kCoreRegister | 0x3f,
Zheng Xubaa7c882014-06-30 14:26:50 +0800142 rwzr = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 0x3f,
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100143 rsp = rx31,
Zheng Xubaa7c882014-06-30 14:26:50 +0800144 rwsp = rw31,
145
146 // Aliases which are not defined in "ARM Architecture Reference, register names".
Zheng Xub551fdc2014-07-25 11:49:42 +0800147 rxIP0 = rx16,
148 rxIP1 = rx17,
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100149 rxSELF = rx19,
Zheng Xubaa7c882014-06-30 14:26:50 +0800150 rxLR = rx30,
buzbeeb01bf152014-05-13 15:59:07 -0700151 /*
152 * FIXME: It's a bit awkward to define both 32 and 64-bit views of these - we'll only ever use
153 * the 64-bit view. However, for now we'll define a 32-bit view to keep these from being
154 * allocated as 32-bit temp registers.
155 */
Zheng Xub551fdc2014-07-25 11:49:42 +0800156 rwIP0 = rw16,
157 rwIP1 = rw17,
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100158 rwSELF = rw19,
Zheng Xubaa7c882014-06-30 14:26:50 +0800159 rwLR = rw30,
Matteo Franchin43ec8732014-03-31 15:00:14 +0100160};
161
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100162#define A64_DEFINE_REGSTORAGES(nr) \
163 constexpr RegStorage rs_w##nr(RegStorage::kValid | rw##nr); \
164 constexpr RegStorage rs_x##nr(RegStorage::kValid | rx##nr); \
165 constexpr RegStorage rs_f##nr(RegStorage::kValid | rf##nr); \
166 constexpr RegStorage rs_d##nr(RegStorage::kValid | rd##nr);
167A64_REGISTER_CODE_LIST(A64_DEFINE_REGSTORAGES)
168#undef A64_DEFINE_REGSTORAGES
Matteo Franchin43ec8732014-03-31 15:00:14 +0100169
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100170constexpr RegStorage rs_xzr(RegStorage::kValid | rxzr);
Zheng Xubaa7c882014-06-30 14:26:50 +0800171constexpr RegStorage rs_wzr(RegStorage::kValid | rwzr);
Zheng Xub551fdc2014-07-25 11:49:42 +0800172constexpr RegStorage rs_xIP0(RegStorage::kValid | rxIP0);
173constexpr RegStorage rs_wIP0(RegStorage::kValid | rwIP0);
174constexpr RegStorage rs_xIP1(RegStorage::kValid | rxIP1);
175constexpr RegStorage rs_wIP1(RegStorage::kValid | rwIP1);
Zheng Xubaa7c882014-06-30 14:26:50 +0800176// Reserved registers.
Zheng Xubaa7c882014-06-30 14:26:50 +0800177constexpr RegStorage rs_xSELF(RegStorage::kValid | rxSELF);
178constexpr RegStorage rs_sp(RegStorage::kValid | rsp);
179constexpr RegStorage rs_xLR(RegStorage::kValid | rxLR);
buzbeeb01bf152014-05-13 15:59:07 -0700180// TODO: eliminate the need for these.
Zheng Xubaa7c882014-06-30 14:26:50 +0800181constexpr RegStorage rs_wSELF(RegStorage::kValid | rwSELF);
182constexpr RegStorage rs_wsp(RegStorage::kValid | rwsp);
183constexpr RegStorage rs_wLR(RegStorage::kValid | rwLR);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100184
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100185// RegisterLocation templates return values (following the hard-float calling convention).
Matteo Franchin4163c532014-07-15 15:20:27 +0100186const RegLocation a64_loc_c_return =
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100187 {kLocPhysReg, 0, 0, 0, 0, 0, 0, 0, 1, rs_w0, INVALID_SREG, INVALID_SREG};
Matteo Franchin4163c532014-07-15 15:20:27 +0100188const RegLocation a64_loc_c_return_ref =
Andreas Gampe4b537a82014-06-30 22:24:53 -0700189 {kLocPhysReg, 0, 0, 0, 0, 0, 1, 0, 1, rs_x0, INVALID_SREG, INVALID_SREG};
Matteo Franchin4163c532014-07-15 15:20:27 +0100190const RegLocation a64_loc_c_return_wide =
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100191 {kLocPhysReg, 1, 0, 0, 0, 0, 0, 0, 1, rs_x0, INVALID_SREG, INVALID_SREG};
Matteo Franchin4163c532014-07-15 15:20:27 +0100192const RegLocation a64_loc_c_return_float =
Andreas Gampec6301bc2014-06-27 08:43:05 -0700193 {kLocPhysReg, 0, 0, 0, 1, 0, 0, 0, 1, rs_f0, INVALID_SREG, INVALID_SREG};
Matteo Franchin4163c532014-07-15 15:20:27 +0100194const RegLocation a64_loc_c_return_double =
Andreas Gampec6301bc2014-06-27 08:43:05 -0700195 {kLocPhysReg, 1, 0, 0, 1, 0, 0, 0, 1, rs_d0, INVALID_SREG, INVALID_SREG};
Matteo Franchin43ec8732014-03-31 15:00:14 +0100196
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100197/**
198 * @brief Shift-type to be applied to a register via EncodeShift().
199 */
200enum A64ShiftEncodings {
201 kA64Lsl = 0x0,
202 kA64Lsr = 0x1,
203 kA64Asr = 0x2,
204 kA64Ror = 0x3
205};
Matteo Franchin43ec8732014-03-31 15:00:14 +0100206
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100207/**
208 * @brief Extend-type to be applied to a register via EncodeExtend().
209 */
210enum A64RegExtEncodings {
211 kA64Uxtb = 0x0,
212 kA64Uxth = 0x1,
213 kA64Uxtw = 0x2,
214 kA64Uxtx = 0x3,
215 kA64Sxtb = 0x4,
216 kA64Sxth = 0x5,
217 kA64Sxtw = 0x6,
218 kA64Sxtx = 0x7
219};
220
221#define ENCODE_NO_SHIFT (EncodeShift(kA64Lsl, 0))
Stuart Monteithf8ec48e2014-06-06 17:05:08 +0100222#define ENCODE_NO_EXTEND (EncodeExtend(kA64Uxtx, 0))
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100223/*
224 * The following enum defines the list of supported A64 instructions by the
225 * assembler. Their corresponding EncodingMap positions will be defined in
226 * assemble_arm64.cc.
227 */
Matteo Franchin4163c532014-07-15 15:20:27 +0100228enum A64Opcode {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100229 kA64First = 0,
230 kA64Adc3rrr = kA64First, // adc [00011010000] rm[20-16] [000000] rn[9-5] rd[4-0].
231 kA64Add4RRdT, // add [s001000100] imm_12[21-10] rn[9-5] rd[4-0].
Andreas Gampe9f975bf2014-06-18 17:45:32 -0700232 kA64Add4rrro, // add [00001011000] rm[20-16] imm_6[15-10] rn[9-5] rd[4-0].
Andreas Gampe47b31aa2014-06-19 01:10:07 -0700233 kA64Add4RRre, // add [00001011001] rm[20-16] option[15-13] imm_3[12-10] rn[9-5] rd[4-0].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100234 kA64Adr2xd, // adr [0] immlo[30-29] [10000] immhi[23-5] rd[4-0].
Vladimir Marko20f85592015-03-19 10:07:02 +0000235 kA64Adrp2xd, // adrp [1] immlo[30-29] [10000] immhi[23-5] rd[4-0].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100236 kA64And3Rrl, // and [00010010] N[22] imm_r[21-16] imm_s[15-10] rn[9-5] rd[4-0].
237 kA64And4rrro, // and [00001010] shift[23-22] [N=0] rm[20-16] imm_6[15-10] rn[9-5] rd[4-0].
238 kA64Asr3rrd, // asr [0001001100] immr[21-16] imms[15-10] rn[9-5] rd[4-0].
239 kA64Asr3rrr, // asr alias of "sbfm arg0, arg1, arg2, {#31/#63}".
240 kA64B2ct, // b.cond [01010100] imm_19[23-5] [0] cond[3-0].
241 kA64Blr1x, // blr [1101011000111111000000] rn[9-5] [00000].
242 kA64Br1x, // br [1101011000011111000000] rn[9-5] [00000].
Vladimir Marko7c2ad5a2014-09-24 12:42:55 +0100243 kA64Bl1t, // bl [100101] imm26[25-0].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100244 kA64Brk1d, // brk [11010100001] imm_16[20-5] [00000].
245 kA64B1t, // b [00010100] offset_26[25-0].
246 kA64Cbnz2rt, // cbnz[00110101] imm_19[23-5] rt[4-0].
247 kA64Cbz2rt, // cbz [00110100] imm_19[23-5] rt[4-0].
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100248 kA64Cmn3rro, // cmn [s0101011] shift[23-22] [0] rm[20-16] imm_6[15-10] rn[9-5] [11111].
249 kA64Cmn3Rre, // cmn [s0101011001] rm[20-16] option[15-13] imm_3[12-10] rn[9-5] [11111].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100250 kA64Cmn3RdT, // cmn [00110001] shift[23-22] imm_12[21-10] rn[9-5] [11111].
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100251 kA64Cmp3rro, // cmp [s1101011] shift[23-22] [0] rm[20-16] imm_6[15-10] rn[9-5] [11111].
252 kA64Cmp3Rre, // cmp [s1101011001] rm[20-16] option[15-13] imm_3[12-10] rn[9-5] [11111].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100253 kA64Cmp3RdT, // cmp [01110001] shift[23-22] imm_12[21-10] rn[9-5] [11111].
254 kA64Csel4rrrc, // csel[s0011010100] rm[20-16] cond[15-12] [00] rn[9-5] rd[4-0].
255 kA64Csinc4rrrc, // csinc [s0011010100] rm[20-16] cond[15-12] [01] rn[9-5] rd[4-0].
Stuart Monteith873c3712014-07-11 16:31:28 +0100256 kA64Csinv4rrrc, // csinv [s1011010100] rm[20-16] cond[15-12] [00] rn[9-5] rd[4-0].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100257 kA64Csneg4rrrc, // csneg [s1011010100] rm[20-16] cond[15-12] [01] rn[9-5] rd[4-0].
258 kA64Dmb1B, // dmb [11010101000000110011] CRm[11-8] [10111111].
259 kA64Eor3Rrl, // eor [s10100100] N[22] imm_r[21-16] imm_s[15-10] rn[9-5] rd[4-0].
260 kA64Eor4rrro, // eor [s1001010] shift[23-22] [0] rm[20-16] imm_6[15-10] rn[9-5] rd[4-0].
261 kA64Extr4rrrd, // extr[s00100111N0] rm[20-16] imm_s[15-10] rn[9-5] rd[4-0].
262 kA64Fabs2ff, // fabs[000111100s100000110000] rn[9-5] rd[4-0].
263 kA64Fadd3fff, // fadd[000111100s1] rm[20-16] [001010] rn[9-5] rd[4-0].
264 kA64Fcmp1f, // fcmp[000111100s100000001000] rn[9-5] [01000].
265 kA64Fcmp2ff, // fcmp[000111100s1] rm[20-16] [001000] rn[9-5] [00000].
266 kA64Fcvtzs2wf, // fcvtzs [000111100s111000000000] rn[9-5] rd[4-0].
267 kA64Fcvtzs2xf, // fcvtzs [100111100s111000000000] rn[9-5] rd[4-0].
268 kA64Fcvt2Ss, // fcvt [0001111000100010110000] rn[9-5] rd[4-0].
269 kA64Fcvt2sS, // fcvt [0001111001100010010000] rn[9-5] rd[4-0].
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100270 kA64Fcvtms2ws, // fcvtms [0001111000110000000000] rn[9-5] rd[4-0].
271 kA64Fcvtms2xS, // fcvtms [1001111001110000000000] rn[9-5] rd[4-0].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100272 kA64Fdiv3fff, // fdiv[000111100s1] rm[20-16] [000110] rn[9-5] rd[4-0].
Serban Constantinescu23abec92014-07-02 16:13:38 +0100273 kA64Fmax3fff, // fmax[000111100s1] rm[20-16] [010010] rn[9-5] rd[4-0].
274 kA64Fmin3fff, // fmin[000111100s1] rm[20-16] [010110] rn[9-5] rd[4-0].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100275 kA64Fmov2ff, // fmov[000111100s100000010000] rn[9-5] rd[4-0].
276 kA64Fmov2fI, // fmov[000111100s1] imm_8[20-13] [10000000] rd[4-0].
277 kA64Fmov2sw, // fmov[0001111000100111000000] rn[9-5] rd[4-0].
278 kA64Fmov2Sx, // fmov[1001111001100111000000] rn[9-5] rd[4-0].
279 kA64Fmov2ws, // fmov[0001111001101110000000] rn[9-5] rd[4-0].
280 kA64Fmov2xS, // fmov[1001111001101111000000] rn[9-5] rd[4-0].
281 kA64Fmul3fff, // fmul[000111100s1] rm[20-16] [000010] rn[9-5] rd[4-0].
282 kA64Fneg2ff, // fneg[000111100s100001010000] rn[9-5] rd[4-0].
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100283 kA64Frintp2ff, // frintp [000111100s100100110000] rn[9-5] rd[4-0].
284 kA64Frintm2ff, // frintm [000111100s100101010000] rn[9-5] rd[4-0].
285 kA64Frintn2ff, // frintn [000111100s100100010000] rn[9-5] rd[4-0].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100286 kA64Frintz2ff, // frintz [000111100s100101110000] rn[9-5] rd[4-0].
287 kA64Fsqrt2ff, // fsqrt[000111100s100001110000] rn[9-5] rd[4-0].
288 kA64Fsub3fff, // fsub[000111100s1] rm[20-16] [001110] rn[9-5] rd[4-0].
289 kA64Ldrb3wXd, // ldrb[0011100101] imm_12[21-10] rn[9-5] rt[4-0].
290 kA64Ldrb3wXx, // ldrb[00111000011] rm[20-16] [011] S[12] [10] rn[9-5] rt[4-0].
291 kA64Ldrsb3rXd, // ldrsb[001110011s] imm_12[21-10] rn[9-5] rt[4-0].
292 kA64Ldrsb3rXx, // ldrsb[0011 1000 1s1] rm[20-16] [011] S[12] [10] rn[9-5] rt[4-0].
293 kA64Ldrh3wXF, // ldrh[0111100101] imm_12[21-10] rn[9-5] rt[4-0].
294 kA64Ldrh4wXxd, // ldrh[01111000011] rm[20-16] [011] S[12] [10] rn[9-5] rt[4-0].
295 kA64Ldrsh3rXF, // ldrsh[011110011s] imm_12[21-10] rn[9-5] rt[4-0].
296 kA64Ldrsh4rXxd, // ldrsh[011110001s1] rm[20-16] [011] S[12] [10] rn[9-5] rt[4-0]
297 kA64Ldr2fp, // ldr [0s011100] imm_19[23-5] rt[4-0].
298 kA64Ldr2rp, // ldr [0s011000] imm_19[23-5] rt[4-0].
299 kA64Ldr3fXD, // ldr [1s11110100] imm_12[21-10] rn[9-5] rt[4-0].
300 kA64Ldr3rXD, // ldr [1s111000010] imm_9[20-12] [01] rn[9-5] rt[4-0].
301 kA64Ldr4fXxG, // ldr [1s111100011] rm[20-16] [011] S[12] [10] rn[9-5] rt[4-0].
302 kA64Ldr4rXxG, // ldr [1s111000011] rm[20-16] [011] S[12] [10] rn[9-5] rt[4-0].
303 kA64LdrPost3rXd, // ldr [1s111000010] imm_9[20-12] [01] rn[9-5] rt[4-0].
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100304 kA64Ldp4ffXD, // ldp [0s10110101] imm_7[21-15] rt2[14-10] rn[9-5] rt[4-0].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100305 kA64Ldp4rrXD, // ldp [s010100101] imm_7[21-15] rt2[14-10] rn[9-5] rt[4-0].
306 kA64LdpPost4rrXD, // ldp [s010100011] imm_7[21-15] rt2[14-10] rn[9-5] rt[4-0].
307 kA64Ldur3fXd, // ldur[1s111100010] imm_9[20-12] [00] rn[9-5] rt[4-0].
308 kA64Ldur3rXd, // ldur[1s111000010] imm_9[20-12] [00] rn[9-5] rt[4-0].
309 kA64Ldxr2rX, // ldxr[1s00100001011111011111] rn[9-5] rt[4-0].
Serban Constantinescu169489b2014-06-11 16:43:35 +0100310 kA64Ldaxr2rX, // ldaxr[1s00100001011111111111] rn[9-5] rt[4-0].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100311 kA64Lsl3rrr, // lsl [s0011010110] rm[20-16] [001000] rn[9-5] rd[4-0].
312 kA64Lsr3rrd, // lsr alias of "ubfm arg0, arg1, arg2, #{31/63}".
313 kA64Lsr3rrr, // lsr [s0011010110] rm[20-16] [001001] rn[9-5] rd[4-0].
Ningsheng Jiana262f772014-11-25 16:48:07 +0800314 kA64Madd4rrrr, // madd[s0011011000] rm[20-16] [0] ra[14-10] rn[9-5] rd[4-0].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100315 kA64Movk3rdM, // mov [010100101] hw[22-21] imm_16[20-5] rd[4-0].
316 kA64Movn3rdM, // mov [000100101] hw[22-21] imm_16[20-5] rd[4-0].
317 kA64Movz3rdM, // mov [011100101] hw[22-21] imm_16[20-5] rd[4-0].
318 kA64Mov2rr, // mov [00101010000] rm[20-16] [000000] [11111] rd[4-0].
319 kA64Mvn2rr, // mov [00101010001] rm[20-16] [000000] [11111] rd[4-0].
320 kA64Mul3rrr, // mul [00011011000] rm[20-16] [011111] rn[9-5] rd[4-0].
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100321 kA64Msub4rrrr, // msub[s0011011000] rm[20-16] [1] ra[14-10] rn[9-5] rd[4-0].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100322 kA64Neg3rro, // neg alias of "sub arg0, rzr, arg1, arg2".
Matteo Franchin65420b22014-10-27 13:29:30 +0000323 kA64Nop0, // nop alias of "hint #0" [11010101000000110010000000011111].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100324 kA64Orr3Rrl, // orr [s01100100] N[22] imm_r[21-16] imm_s[15-10] rn[9-5] rd[4-0].
325 kA64Orr4rrro, // orr [s0101010] shift[23-22] [0] rm[20-16] imm_6[15-10] rn[9-5] rd[4-0].
326 kA64Ret, // ret [11010110010111110000001111000000].
Serban Constantinescu23abec92014-07-02 16:13:38 +0100327 kA64Rbit2rr, // rbit [s101101011000000000000] rn[9-5] rd[4-0].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100328 kA64Rev2rr, // rev [s10110101100000000001x] rn[9-5] rd[4-0].
329 kA64Rev162rr, // rev16[s101101011000000000001] rn[9-5] rd[4-0].
330 kA64Ror3rrr, // ror [s0011010110] rm[20-16] [001011] rn[9-5] rd[4-0].
331 kA64Sbc3rrr, // sbc [s0011010000] rm[20-16] [000000] rn[9-5] rd[4-0].
332 kA64Sbfm4rrdd, // sbfm[0001001100] imm_r[21-16] imm_s[15-10] rn[9-5] rd[4-0].
333 kA64Scvtf2fw, // scvtf [000111100s100010000000] rn[9-5] rd[4-0].
334 kA64Scvtf2fx, // scvtf [100111100s100010000000] rn[9-5] rd[4-0].
335 kA64Sdiv3rrr, // sdiv[s0011010110] rm[20-16] [000011] rn[9-5] rd[4-0].
Matteo Franchin65420b22014-10-27 13:29:30 +0000336 kA64Smull3xww, // smull [10011011001] rm[20-16] [011111] rn[9-5] rd[4-0].
Matteo Franchin7c6c2ac2014-07-01 18:03:08 +0100337 kA64Smulh3xxx, // smulh [10011011010] rm[20-16] [011111] rn[9-5] rd[4-0].
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100338 kA64Stp4ffXD, // stp [0s10110100] imm_7[21-15] rt2[14-10] rn[9-5] rt[4-0].
339 kA64Stp4rrXD, // stp [s010100100] imm_7[21-15] rt2[14-10] rn[9-5] rt[4-0].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100340 kA64StpPost4rrXD, // stp [s010100010] imm_7[21-15] rt2[14-10] rn[9-5] rt[4-0].
Andreas Gampef29ecd62014-07-29 00:35:00 -0700341 kA64StpPre4ffXD, // stp [0s10110110] imm_7[21-15] rt2[14-10] rn[9-5] rt[4-0].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100342 kA64StpPre4rrXD, // stp [s010100110] imm_7[21-15] rt2[14-10] rn[9-5] rt[4-0].
343 kA64Str3fXD, // str [1s11110100] imm_12[21-10] rn[9-5] rt[4-0].
344 kA64Str4fXxG, // str [1s111100001] rm[20-16] [011] S[12] [10] rn[9-5] rt[4-0].
345 kA64Str3rXD, // str [1s11100100] imm_12[21-10] rn[9-5] rt[4-0].
346 kA64Str4rXxG, // str [1s111000001] rm[20-16] option[15-13] S[12-12] [10] rn[9-5] rt[4-0].
347 kA64Strb3wXd, // strb[0011100100] imm_12[21-10] rn[9-5] rt[4-0].
348 kA64Strb3wXx, // strb[00111000001] rm[20-16] [011] S[12] [10] rn[9-5] rt[4-0].
349 kA64Strh3wXF, // strh[0111100100] imm_12[21-10] rn[9-5] rt[4-0].
350 kA64Strh4wXxd, // strh[01111000001] rm[20-16] [011] S[12] [10] rn[9-5] rt[4-0].
351 kA64StrPost3rXd, // str [1s111000000] imm_9[20-12] [01] rn[9-5] rt[4-0].
352 kA64Stur3fXd, // stur[1s111100000] imm_9[20-12] [00] rn[9-5] rt[4-0].
353 kA64Stur3rXd, // stur[1s111000000] imm_9[20-12] [00] rn[9-5] rt[4-0].
354 kA64Stxr3wrX, // stxr[11001000000] rs[20-16] [011111] rn[9-5] rt[4-0].
Serban Constantinescu169489b2014-06-11 16:43:35 +0100355 kA64Stlxr3wrX, // stlxr[11001000000] rs[20-16] [111111] rn[9-5] rt[4-0].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100356 kA64Sub4RRdT, // sub [s101000100] imm_12[21-10] rn[9-5] rd[4-0].
Andreas Gampe9f975bf2014-06-18 17:45:32 -0700357 kA64Sub4rrro, // sub [s1001011000] rm[20-16] imm_6[15-10] rn[9-5] rd[4-0].
Andreas Gampe47b31aa2014-06-19 01:10:07 -0700358 kA64Sub4RRre, // sub [s1001011001] rm[20-16] option[15-13] imm_3[12-10] rn[9-5] rd[4-0].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100359 kA64Subs3rRd, // subs[s111000100] imm_12[21-10] rn[9-5] rd[4-0].
Zheng Xu5d7cdec2014-08-18 17:28:22 +0800360 kA64Tst2rl, // tst alias of "ands rzr, rn, #imm".
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100361 kA64Tst3rro, // tst alias of "ands rzr, arg1, arg2, arg3".
Zheng Xu5d7cdec2014-08-18 17:28:22 +0800362 kA64Tbnz3rht, // tbnz imm_6_b5[31] [0110111] imm_6_b40[23-19] imm_14[18-5] rt[4-0].
363 kA64Tbz3rht, // tbz imm_6_b5[31] [0110110] imm_6_b40[23-19] imm_14[18-5] rt[4-0].
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100364 kA64Ubfm4rrdd, // ubfm[s10100110] N[22] imm_r[21-16] imm_s[15-10] rn[9-5] rd[4-0].
365 kA64Last,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700366 kA64NotWide = kA64First, // 0 - Flag used to select the first instruction variant.
367 kA64Wide = 0x1000 // Flag used to select the second instruction variant.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100368};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700369std::ostream& operator<<(std::ostream& os, const A64Opcode& rhs);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100370
371/*
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100372 * The A64 instruction set provides two variants for many instructions. For example, "mov wN, wM"
373 * and "mov xN, xM" or - for floating point instructions - "mov sN, sM" and "mov dN, dM".
374 * It definitely makes sense to exploit this symmetries of the instruction set. We do this via the
375 * WIDE, UNWIDE macros. For opcodes that allow it, the wide variant can be obtained by applying the
376 * WIDE macro to the non-wide opcode. E.g. WIDE(kA64Sub4RRdT).
Matteo Franchin43ec8732014-03-31 15:00:14 +0100377 */
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100378
379// Return the wide and no-wide variants of the given opcode.
Matteo Franchin4163c532014-07-15 15:20:27 +0100380#define WIDE(op) ((A64Opcode)((op) | kA64Wide))
381#define UNWIDE(op) ((A64Opcode)((op) & ~kA64Wide))
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100382
383// Whether the given opcode is wide.
384#define IS_WIDE(op) (((op) & kA64Wide) != 0)
385
Matteo Franchin4163c532014-07-15 15:20:27 +0100386enum A64OpDmbOptions {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100387 kSY = 0xf,
388 kST = 0xe,
389 kISH = 0xb,
390 kISHST = 0xa,
Hans Boehm48f5c472014-06-27 14:50:10 -0700391 kISHLD = 0x9,
Matteo Franchin43ec8732014-03-31 15:00:14 +0100392 kNSH = 0x7,
393 kNSHST = 0x6
394};
395
396// Instruction assembly field_loc kind.
Matteo Franchin4163c532014-07-15 15:20:27 +0100397enum A64EncodingKind {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100398 // All the formats below are encoded in the same way (as a kFmtBitBlt).
399 // These are grouped together, for fast handling (e.g. "if (LIKELY(fmt <= kFmtBitBlt)) ...").
Zheng Xu5d7cdec2014-08-18 17:28:22 +0800400 kFmtRegW = 0, // Word register (w) or wzr.
401 kFmtRegX, // Extended word register (x) or xzr.
402 kFmtRegR, // Register with same width as the instruction or zr.
403 kFmtRegWOrSp, // Word register (w) or wsp.
404 kFmtRegXOrSp, // Extended word register (x) or sp.
405 kFmtRegROrSp, // Register with same width as the instruction or sp.
406 kFmtRegS, // Single FP reg.
407 kFmtRegD, // Double FP reg.
408 kFmtRegF, // Single/double FP reg depending on the instruction width.
409 kFmtBitBlt, // Bit string using end/start.
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100410
411 // Less likely formats.
Zheng Xu5d7cdec2014-08-18 17:28:22 +0800412 kFmtUnused, // Unused field and marks end of formats.
413 kFmtImm6Shift, // Shift immediate, 6-bit at [31, 23..19].
414 kFmtImm21, // Sign-extended immediate using [23..5,30..29].
415 kFmtShift, // Register shift, 9-bit at [23..21, 15..10]..
416 kFmtExtend, // Register extend, 9-bit at [23..21, 15..10].
417 kFmtSkip, // Unused field, but continue to next.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100418};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700419std::ostream& operator<<(std::ostream& os, const A64EncodingKind & rhs);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100420
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100421// Struct used to define the snippet positions for each A64 opcode.
Matteo Franchin4163c532014-07-15 15:20:27 +0100422struct A64EncodingMap {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100423 uint32_t wskeleton;
424 uint32_t xskeleton;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100425 struct {
Matteo Franchin4163c532014-07-15 15:20:27 +0100426 A64EncodingKind kind;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100427 int end; // end for kFmtBitBlt, 1-bit slice end for FP regs.
428 int start; // start for kFmtBitBlt, 4-bit slice end for FP regs.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100429 } field_loc[4];
Matteo Franchin4163c532014-07-15 15:20:27 +0100430 A64Opcode opcode; // can be WIDE()-ned to indicate it has a wide variant.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100431 uint64_t flags;
432 const char* name;
433 const char* fmt;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100434 int size; // Note: size is in bytes.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100435 FixupKind fixup;
436};
437
Matteo Franchin43ec8732014-03-31 15:00:14 +0100438} // namespace art
439
440#endif // ART_COMPILER_DEX_QUICK_ARM64_ARM64_LIR_H_