arm64_lir.h revision bc6d197cdb02eeac0c98ec4ed37f530b003a4e7a
1/*
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
20#include "dex/compiler_internals.h"
21
22namespace art {
23
24/*
25 * TODO(Arm64): the comments below are outdated.
26 *
27 * Runtime register usage conventions.
28 *
29 * r0-r3: Argument registers in both Dalvik and C/C++ conventions.
30 *        However, for Dalvik->Dalvik calls we'll pass the target's Method*
31 *        pointer in r0 as a hidden arg0. Otherwise used as codegen scratch
32 *        registers.
33 * r0-r1: As in C/C++ r0 is 32-bit return register and r0/r1 is 64-bit
34 * r4   : (rA64_SUSPEND) is reserved (suspend check/debugger assist)
35 * r5   : Callee save (promotion target)
36 * r6   : Callee save (promotion target)
37 * r7   : Callee save (promotion target)
38 * r8   : Callee save (promotion target)
39 * r9   : (rA64_SELF) is reserved (pointer to thread-local storage)
40 * r10  : Callee save (promotion target)
41 * r11  : Callee save (promotion target)
42 * r12  : Scratch, may be trashed by linkage stubs
43 * r13  : (sp) is reserved
44 * r14  : (lr) is reserved
45 * r15  : (pc) is reserved
46 *
47 * 5 core temps that codegen can use (r0, r1, r2, r3, r12)
48 * 7 core registers that can be used for promotion
49 *
50 * Floating pointer registers
51 * s0-s31
52 * d0-d15, where d0={s0,s1}, d1={s2,s3}, ... , d15={s30,s31}
53 *
54 * s16-s31 (d8-d15) preserved across C calls
55 * s0-s15 (d0-d7) trashed across C calls
56 *
57 * s0-s15/d0-d7 used as codegen temp/scratch
58 * s16-s31/d8-d31 can be used for promotion.
59 *
60 * Calling convention
61 *     o On a call to a Dalvik method, pass target's Method* in r0
62 *     o r1-r3 will be used for up to the first 3 words of arguments
63 *     o Arguments past the first 3 words will be placed in appropriate
64 *       out slots by the caller.
65 *     o If a 64-bit argument would span the register/memory argument
66 *       boundary, it will instead be fully passed in the frame.
67 *     o Maintain a 16-byte stack alignment
68 *
69 *  Stack frame diagram (stack grows down, higher addresses at top):
70 *
71 * +------------------------+
72 * | IN[ins-1]              |  {Note: resides in caller's frame}
73 * |       .                |
74 * | IN[0]                  |
75 * | caller's Method*       |
76 * +========================+  {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]                 |
94 * | cur_method*            | <<== sp w/ 16-byte alignment
95 * +========================+
96 */
97
98// First FP callee save.
99#define A64_FP_CALLEE_SAVE_BASE 16
100
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)
104
105enum ArmResourceEncodingPos {
106  kArmGPReg0   = 0,
107  kArmRegLR    = 30,
108  kArmRegSP    = 31,
109  kArmFPReg0   = 32,
110  kArmRegEnd   = 64,
111};
112
113#define ENCODE_ARM_REG_SP           (1ULL << kArmRegSP)
114#define ENCODE_ARM_REG_LR           (1ULL << kArmRegLR)
115
116#define IS_SIGNED_IMM(size, value) \
117  ((value) >= -(1 << ((size) - 1)) && (value) < (1 << ((size) - 1)))
118#define IS_SIGNED_IMM7(value) IS_SIGNED_IMM(7, value)
119#define IS_SIGNED_IMM9(value) IS_SIGNED_IMM(9, value)
120#define IS_SIGNED_IMM12(value) IS_SIGNED_IMM(12, value)
121#define IS_SIGNED_IMM19(value) IS_SIGNED_IMM(19, value)
122#define IS_SIGNED_IMM21(value) IS_SIGNED_IMM(21, value)
123
124// 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)
130
131// Registers (integer) values.
132// TODO(Arm64): for now we define rx##nr identically to rw##nr. We should rather define rx##nr as
133// a k64BitSolo. We should do this once the register allocator is ready.
134enum A64NativeRegisterPool {
135#  define A64_DEFINE_REGISTERS(nr) \
136    rw##nr = RegStorage::k32BitSolo | RegStorage::kCoreRegister | nr, \
137    rx##nr = RegStorage::k32BitSolo | RegStorage::kCoreRegister | nr, \
138    rf##nr = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | nr, \
139    rd##nr = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | nr,
140  A64_REGISTER_CODE_LIST(A64_DEFINE_REGISTERS)
141#undef A64_DEFINE_REGISTERS
142
143  // TODO(Arm64): can we change the lines below such that rwzr != rwsp && rxzr != rsp?
144  //   This would be desirable to allow detecting usage-errors in the assembler.
145  rwzr = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 0x3f,
146  rxzr = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 0x3f,
147  rwsp = rw31,
148  rsp = rx31,
149  rA64_SUSPEND = rx19,
150  rA64_SELF = rx18,
151  rA64_SP = rx31,
152  rA64_LR = rx30
153};
154
155#define A64_DEFINE_REGSTORAGES(nr) \
156  constexpr RegStorage rs_w##nr(RegStorage::kValid | rw##nr); \
157  constexpr RegStorage rs_x##nr(RegStorage::kValid | rx##nr); \
158  constexpr RegStorage rs_f##nr(RegStorage::kValid | rf##nr); \
159  constexpr RegStorage rs_d##nr(RegStorage::kValid | rd##nr);
160A64_REGISTER_CODE_LIST(A64_DEFINE_REGSTORAGES)
161#undef A64_DEFINE_REGSTORAGES
162
163constexpr RegStorage rs_wzr(RegStorage::kValid | rwzr);
164constexpr RegStorage rs_xzr(RegStorage::kValid | rxzr);
165constexpr RegStorage rs_rA64_SUSPEND(RegStorage::kValid | rA64_SUSPEND);
166constexpr RegStorage rs_rA64_SELF(RegStorage::kValid | rA64_SELF);
167constexpr RegStorage rs_rA64_SP(RegStorage::kValid | rA64_SP);
168constexpr RegStorage rs_rA64_LR(RegStorage::kValid | rA64_LR);
169
170// RegisterLocation templates return values (following the hard-float calling convention).
171const RegLocation arm_loc_c_return =
172    {kLocPhysReg, 0, 0, 0, 0, 0, 0, 0, 1, rs_w0, INVALID_SREG, INVALID_SREG};
173const RegLocation arm_loc_c_return_wide =
174    {kLocPhysReg, 1, 0, 0, 0, 0, 0, 0, 1, rs_x0, INVALID_SREG, INVALID_SREG};
175const RegLocation arm_loc_c_return_float =
176    {kLocPhysReg, 0, 0, 0, 0, 0, 0, 0, 1, rs_f0, INVALID_SREG, INVALID_SREG};
177const RegLocation arm_loc_c_return_double =
178    {kLocPhysReg, 1, 0, 0, 0, 0, 0, 0, 1, rs_d0, INVALID_SREG, INVALID_SREG};
179
180/**
181 * @brief Shift-type to be applied to a register via EncodeShift().
182 */
183enum A64ShiftEncodings {
184  kA64Lsl = 0x0,
185  kA64Lsr = 0x1,
186  kA64Asr = 0x2,
187  kA64Ror = 0x3
188};
189
190/**
191 * @brief Extend-type to be applied to a register via EncodeExtend().
192 */
193enum A64RegExtEncodings {
194  kA64Uxtb = 0x0,
195  kA64Uxth = 0x1,
196  kA64Uxtw = 0x2,
197  kA64Uxtx = 0x3,
198  kA64Sxtb = 0x4,
199  kA64Sxth = 0x5,
200  kA64Sxtw = 0x6,
201  kA64Sxtx = 0x7
202};
203
204#define ENCODE_NO_SHIFT (EncodeShift(kA64Lsl, 0))
205
206/*
207 * The following enum defines the list of supported A64 instructions by the
208 * assembler. Their corresponding EncodingMap positions will be defined in
209 * assemble_arm64.cc.
210 */
211enum ArmOpcode {
212  kA64First = 0,
213  kA64Adc3rrr = kA64First,  // adc [00011010000] rm[20-16] [000000] rn[9-5] rd[4-0].
214  kA64Add4RRdT,      // add [s001000100] imm_12[21-10] rn[9-5] rd[4-0].
215  kA64Add4rrro,      // add [00001011000] rm[20-16] option[15-13] imm_3[12-10] rn[9-5] rd[4-0].
216  kA64Adr2xd,        // adr [0] immlo[30-29] [10000] immhi[23-5] rd[4-0].
217  kA64And3Rrl,       // and [00010010] N[22] imm_r[21-16] imm_s[15-10] rn[9-5] rd[4-0].
218  kA64And4rrro,      // and [00001010] shift[23-22] [N=0] rm[20-16] imm_6[15-10] rn[9-5] rd[4-0].
219  kA64Asr3rrd,       // asr [0001001100] immr[21-16] imms[15-10] rn[9-5] rd[4-0].
220  kA64Asr3rrr,       // asr alias of "sbfm arg0, arg1, arg2, {#31/#63}".
221  kA64B2ct,          // b.cond [01010100] imm_19[23-5] [0] cond[3-0].
222  kA64Blr1x,         // blr [1101011000111111000000] rn[9-5] [00000].
223  kA64Br1x,          // br  [1101011000011111000000] rn[9-5] [00000].
224  kA64Brk1d,         // brk [11010100001] imm_16[20-5] [00000].
225  kA64B1t,           // b   [00010100] offset_26[25-0].
226  kA64Cbnz2rt,       // cbnz[00110101] imm_19[23-5] rt[4-0].
227  kA64Cbz2rt,        // cbz [00110100] imm_19[23-5] rt[4-0].
228  kA64Cmn3rro,       // cmn [s0101011] shift[23-22] [0] rm[20-16] imm_6[15-10] rn[9-5] [11111].
229  kA64Cmn3Rre,       // cmn [s0101011001] rm[20-16] option[15-13] imm_3[12-10] rn[9-5] [11111].
230  kA64Cmn3RdT,       // cmn [00110001] shift[23-22] imm_12[21-10] rn[9-5] [11111].
231  kA64Cmp3rro,       // cmp [s1101011] shift[23-22] [0] rm[20-16] imm_6[15-10] rn[9-5] [11111].
232  kA64Cmp3Rre,       // cmp [s1101011001] rm[20-16] option[15-13] imm_3[12-10] rn[9-5] [11111].
233  kA64Cmp3RdT,       // cmp [01110001] shift[23-22] imm_12[21-10] rn[9-5] [11111].
234  kA64Csel4rrrc,     // csel[s0011010100] rm[20-16] cond[15-12] [00] rn[9-5] rd[4-0].
235  kA64Csinc4rrrc,    // csinc [s0011010100] rm[20-16] cond[15-12] [01] rn[9-5] rd[4-0].
236  kA64Csneg4rrrc,    // csneg [s1011010100] rm[20-16] cond[15-12] [01] rn[9-5] rd[4-0].
237  kA64Dmb1B,         // dmb [11010101000000110011] CRm[11-8] [10111111].
238  kA64Eor3Rrl,       // eor [s10100100] N[22] imm_r[21-16] imm_s[15-10] rn[9-5] rd[4-0].
239  kA64Eor4rrro,      // eor [s1001010] shift[23-22] [0] rm[20-16] imm_6[15-10] rn[9-5] rd[4-0].
240  kA64Extr4rrrd,     // extr[s00100111N0] rm[20-16] imm_s[15-10] rn[9-5] rd[4-0].
241  kA64Fabs2ff,       // fabs[000111100s100000110000] rn[9-5] rd[4-0].
242  kA64Fadd3fff,      // fadd[000111100s1] rm[20-16] [001010] rn[9-5] rd[4-0].
243  kA64Fcmp1f,        // fcmp[000111100s100000001000] rn[9-5] [01000].
244  kA64Fcmp2ff,       // fcmp[000111100s1] rm[20-16] [001000] rn[9-5] [00000].
245  kA64Fcvtzs2wf,     // fcvtzs [000111100s111000000000] rn[9-5] rd[4-0].
246  kA64Fcvtzs2xf,     // fcvtzs [100111100s111000000000] rn[9-5] rd[4-0].
247  kA64Fcvt2Ss,       // fcvt   [0001111000100010110000] rn[9-5] rd[4-0].
248  kA64Fcvt2sS,       // fcvt   [0001111001100010010000] rn[9-5] rd[4-0].
249  kA64Fdiv3fff,      // fdiv[000111100s1] rm[20-16] [000110] rn[9-5] rd[4-0].
250  kA64Fmov2ff,       // fmov[000111100s100000010000] rn[9-5] rd[4-0].
251  kA64Fmov2fI,       // fmov[000111100s1] imm_8[20-13] [10000000] rd[4-0].
252  kA64Fmov2sw,       // fmov[0001111000100111000000] rn[9-5] rd[4-0].
253  kA64Fmov2Sx,       // fmov[1001111001100111000000] rn[9-5] rd[4-0].
254  kA64Fmov2ws,       // fmov[0001111001101110000000] rn[9-5] rd[4-0].
255  kA64Fmov2xS,       // fmov[1001111001101111000000] rn[9-5] rd[4-0].
256  kA64Fmul3fff,      // fmul[000111100s1] rm[20-16] [000010] rn[9-5] rd[4-0].
257  kA64Fneg2ff,       // fneg[000111100s100001010000] rn[9-5] rd[4-0].
258  kA64Frintz2ff,     // frintz [000111100s100101110000] rn[9-5] rd[4-0].
259  kA64Fsqrt2ff,      // fsqrt[000111100s100001110000] rn[9-5] rd[4-0].
260  kA64Fsub3fff,      // fsub[000111100s1] rm[20-16] [001110] rn[9-5] rd[4-0].
261  kA64Ldrb3wXd,      // ldrb[0011100101] imm_12[21-10] rn[9-5] rt[4-0].
262  kA64Ldrb3wXx,      // ldrb[00111000011] rm[20-16] [011] S[12] [10] rn[9-5] rt[4-0].
263  kA64Ldrsb3rXd,     // ldrsb[001110011s] imm_12[21-10] rn[9-5] rt[4-0].
264  kA64Ldrsb3rXx,     // ldrsb[0011 1000 1s1] rm[20-16] [011] S[12] [10] rn[9-5] rt[4-0].
265  kA64Ldrh3wXF,      // ldrh[0111100101] imm_12[21-10] rn[9-5] rt[4-0].
266  kA64Ldrh4wXxd,     // ldrh[01111000011] rm[20-16] [011] S[12] [10] rn[9-5] rt[4-0].
267  kA64Ldrsh3rXF,     // ldrsh[011110011s] imm_12[21-10] rn[9-5] rt[4-0].
268  kA64Ldrsh4rXxd,    // ldrsh[011110001s1] rm[20-16] [011] S[12] [10] rn[9-5] rt[4-0]
269  kA64Ldr2fp,        // ldr [0s011100] imm_19[23-5] rt[4-0].
270  kA64Ldr2rp,        // ldr [0s011000] imm_19[23-5] rt[4-0].
271  kA64Ldr3fXD,       // ldr [1s11110100] imm_12[21-10] rn[9-5] rt[4-0].
272  kA64Ldr3rXD,       // ldr [1s111000010] imm_9[20-12] [01] rn[9-5] rt[4-0].
273  kA64Ldr4fXxG,      // ldr [1s111100011] rm[20-16] [011] S[12] [10] rn[9-5] rt[4-0].
274  kA64Ldr4rXxG,      // ldr [1s111000011] rm[20-16] [011] S[12] [10] rn[9-5] rt[4-0].
275  kA64LdrPost3rXd,   // ldr [1s111000010] imm_9[20-12] [01] rn[9-5] rt[4-0].
276  kA64Ldp4ffXD,      // ldp [0s10110101] imm_7[21-15] rt2[14-10] rn[9-5] rt[4-0].
277  kA64Ldp4rrXD,      // ldp [s010100101] imm_7[21-15] rt2[14-10] rn[9-5] rt[4-0].
278  kA64LdpPost4rrXD,  // ldp [s010100011] imm_7[21-15] rt2[14-10] rn[9-5] rt[4-0].
279  kA64Ldur3fXd,      // ldur[1s111100010] imm_9[20-12] [00] rn[9-5] rt[4-0].
280  kA64Ldur3rXd,      // ldur[1s111000010] imm_9[20-12] [00] rn[9-5] rt[4-0].
281  kA64Ldxr2rX,       // ldxr[1s00100001011111011111] rn[9-5] rt[4-0].
282  kA64Lsl3rrr,       // lsl [s0011010110] rm[20-16] [001000] rn[9-5] rd[4-0].
283  kA64Lsr3rrd,       // lsr alias of "ubfm arg0, arg1, arg2, #{31/63}".
284  kA64Lsr3rrr,       // lsr [s0011010110] rm[20-16] [001001] rn[9-5] rd[4-0].
285  kA64Movk3rdM,      // mov [010100101] hw[22-21] imm_16[20-5] rd[4-0].
286  kA64Movn3rdM,      // mov [000100101] hw[22-21] imm_16[20-5] rd[4-0].
287  kA64Movz3rdM,      // mov [011100101] hw[22-21] imm_16[20-5] rd[4-0].
288  kA64Mov2rr,        // mov [00101010000] rm[20-16] [000000] [11111] rd[4-0].
289  kA64Mvn2rr,        // mov [00101010001] rm[20-16] [000000] [11111] rd[4-0].
290  kA64Mul3rrr,       // mul [00011011000] rm[20-16] [011111] rn[9-5] rd[4-0].
291  kA64Neg3rro,       // neg alias of "sub arg0, rzr, arg1, arg2".
292  kA64Orr3Rrl,       // orr [s01100100] N[22] imm_r[21-16] imm_s[15-10] rn[9-5] rd[4-0].
293  kA64Orr4rrro,      // orr [s0101010] shift[23-22] [0] rm[20-16] imm_6[15-10] rn[9-5] rd[4-0].
294  kA64Ret,           // ret [11010110010111110000001111000000].
295  kA64Rev2rr,        // rev [s10110101100000000001x] rn[9-5] rd[4-0].
296  kA64Rev162rr,      // rev16[s101101011000000000001] rn[9-5] rd[4-0].
297  kA64Ror3rrr,       // ror [s0011010110] rm[20-16] [001011] rn[9-5] rd[4-0].
298  kA64Sbc3rrr,       // sbc [s0011010000] rm[20-16] [000000] rn[9-5] rd[4-0].
299  kA64Sbfm4rrdd,     // sbfm[0001001100] imm_r[21-16] imm_s[15-10] rn[9-5] rd[4-0].
300  kA64Scvtf2fw,      // scvtf  [000111100s100010000000] rn[9-5] rd[4-0].
301  kA64Scvtf2fx,      // scvtf  [100111100s100010000000] rn[9-5] rd[4-0].
302  kA64Sdiv3rrr,      // sdiv[s0011010110] rm[20-16] [000011] rn[9-5] rd[4-0].
303  kA64Smaddl4xwwx,   // smaddl [10011011001] rm[20-16] [0] ra[14-10] rn[9-5] rd[4-0].
304  kA64Stp4ffXD,      // stp [0s10110100] imm_7[21-15] rt2[14-10] rn[9-5] rt[4-0].
305  kA64Stp4rrXD,      // stp [s010100100] imm_7[21-15] rt2[14-10] rn[9-5] rt[4-0].
306  kA64StpPost4rrXD,  // stp [s010100010] imm_7[21-15] rt2[14-10] rn[9-5] rt[4-0].
307  kA64StpPre4rrXD,   // stp [s010100110] imm_7[21-15] rt2[14-10] rn[9-5] rt[4-0].
308  kA64Str3fXD,       // str [1s11110100] imm_12[21-10] rn[9-5] rt[4-0].
309  kA64Str4fXxG,      // str [1s111100001] rm[20-16] [011] S[12] [10] rn[9-5] rt[4-0].
310  kA64Str3rXD,       // str [1s11100100] imm_12[21-10] rn[9-5] rt[4-0].
311  kA64Str4rXxG,      // str [1s111000001] rm[20-16] option[15-13] S[12-12] [10] rn[9-5] rt[4-0].
312  kA64Strb3wXd,      // strb[0011100100] imm_12[21-10] rn[9-5] rt[4-0].
313  kA64Strb3wXx,      // strb[00111000001] rm[20-16] [011] S[12] [10] rn[9-5] rt[4-0].
314  kA64Strh3wXF,      // strh[0111100100] imm_12[21-10] rn[9-5] rt[4-0].
315  kA64Strh4wXxd,     // strh[01111000001] rm[20-16] [011] S[12] [10] rn[9-5] rt[4-0].
316  kA64StrPost3rXd,   // str [1s111000000] imm_9[20-12] [01] rn[9-5] rt[4-0].
317  kA64Stur3fXd,      // stur[1s111100000] imm_9[20-12] [00] rn[9-5] rt[4-0].
318  kA64Stur3rXd,      // stur[1s111000000] imm_9[20-12] [00] rn[9-5] rt[4-0].
319  kA64Stxr3wrX,      // stxr[11001000000] rs[20-16] [011111] rn[9-5] rt[4-0].
320  kA64Sub4RRdT,      // sub [s101000100] imm_12[21-10] rn[9-5] rd[4-0].
321  kA64Sub4rrro,      // sub [s1001011001] rm[20-16] option[15-13] imm_3[12-10] rn[9-5] rd[4-0].
322  kA64Subs3rRd,      // subs[s111000100] imm_12[21-10] rn[9-5] rd[4-0].
323  kA64Tst3rro,       // tst alias of "ands rzr, arg1, arg2, arg3".
324  kA64Ubfm4rrdd,     // ubfm[s10100110] N[22] imm_r[21-16] imm_s[15-10] rn[9-5] rd[4-0].
325  kA64Last,
326  kA64NotWide = 0,   // Flag used to select the first instruction variant.
327  kA64Wide = 0x1000  // Flag used to select the second instruction variant.
328};
329
330/*
331 * The A64 instruction set provides two variants for many instructions. For example, "mov wN, wM"
332 * and "mov xN, xM" or - for floating point instructions - "mov sN, sM" and "mov dN, dM".
333 * It definitely makes sense to exploit this symmetries of the instruction set. We do this via the
334 * WIDE, UNWIDE macros. For opcodes that allow it, the wide variant can be obtained by applying the
335 * WIDE macro to the non-wide opcode. E.g. WIDE(kA64Sub4RRdT).
336 */
337
338// Return the wide and no-wide variants of the given opcode.
339#define WIDE(op) ((ArmOpcode)((op) | kA64Wide))
340#define UNWIDE(op) ((ArmOpcode)((op) & ~kA64Wide))
341
342// Whether the given opcode is wide.
343#define IS_WIDE(op) (((op) & kA64Wide) != 0)
344
345/*
346 * Floating point variants. These are just aliases of the macros above which we use for floating
347 * point instructions, just for readibility reasons.
348 * TODO(Arm64): should we remove these and use the original macros?
349 */
350#define FWIDE WIDE
351#define FUNWIDE UNWIDE
352#define IS_FWIDE IS_WIDE
353
354enum ArmOpDmbOptions {
355  kSY = 0xf,
356  kST = 0xe,
357  kISH = 0xb,
358  kISHST = 0xa,
359  kNSH = 0x7,
360  kNSHST = 0x6
361};
362
363// Instruction assembly field_loc kind.
364enum ArmEncodingKind {
365  // All the formats below are encoded in the same way (as a kFmtBitBlt).
366  // These are grouped together, for fast handling (e.g. "if (LIKELY(fmt <= kFmtBitBlt)) ...").
367  kFmtRegW = 0,  // Word register (w) or wzr.
368  kFmtRegX,      // Extended word register (x) or xzr.
369  kFmtRegR,      // Register with same width as the instruction or zr.
370  kFmtRegWOrSp,  // Word register (w) or wsp.
371  kFmtRegXOrSp,  // Extended word register (x) or sp.
372  kFmtRegROrSp,  // Register with same width as the instruction or sp.
373  kFmtRegS,      // Single FP reg.
374  kFmtRegD,      // Double FP reg.
375  kFmtRegF,      // Single/double FP reg depending on the instruction width.
376  kFmtBitBlt,    // Bit string using end/start.
377
378  // Less likely formats.
379  kFmtUnused,    // Unused field and marks end of formats.
380  kFmtImm21,     // Sign-extended immediate using [23..5,30..29].
381  kFmtShift,     // Register shift, 9-bit at [23..21, 15..10]..
382  kFmtExtend,    // Register extend, 9-bit at [23..21, 15..10].
383  kFmtSkip,      // Unused field, but continue to next.
384};
385
386// TODO(Arm64): should we get rid of kFmtExtend?
387//   Note: the only instructions that use it (cmp, cmn) are not used themselves.
388
389// Struct used to define the snippet positions for each A64 opcode.
390struct ArmEncodingMap {
391  uint32_t wskeleton;
392  uint32_t xskeleton;
393  struct {
394    ArmEncodingKind kind;
395    int end;         // end for kFmtBitBlt, 1-bit slice end for FP regs.
396    int start;       // start for kFmtBitBlt, 4-bit slice end for FP regs.
397  } field_loc[4];
398  ArmOpcode opcode;  // can be WIDE()-ned to indicate it has a wide variant.
399  uint64_t flags;
400  const char* name;
401  const char* fmt;
402  int size;          // Note: size is in bytes.
403  FixupKind fixup;
404};
405
406#if 0
407// TODO(Arm64): try the following alternative, which fits exactly in one cache line (64 bytes).
408struct ArmEncodingMap {
409  uint32_t wskeleton;
410  uint32_t xskeleton;
411  uint64_t flags;
412  const char* name;
413  const char* fmt;
414  struct {
415    uint8_t kind;
416    int8_t end;         // end for kFmtBitBlt, 1-bit slice end for FP regs.
417    int8_t start;       // start for kFmtBitBlt, 4-bit slice end for FP regs.
418  } field_loc[4];
419  uint32_t fixup;
420  uint32_t opcode;         // can be WIDE()-ned to indicate it has a wide variant.
421  uint32_t padding[3];
422};
423#endif
424
425}  // namespace art
426
427#endif  // ART_COMPILER_DEX_QUICK_ARM64_ARM64_LIR_H_
428