aboutsummaryrefslogtreecommitdiff
path: root/src/lj_target_arm64.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lj_target_arm64.h')
-rw-r--r--src/lj_target_arm64.h221
1 files changed, 216 insertions, 5 deletions
diff --git a/src/lj_target_arm64.h b/src/lj_target_arm64.h
index 57ab134f..0cef06d5 100644
--- a/src/lj_target_arm64.h
+++ b/src/lj_target_arm64.h
@@ -55,7 +55,8 @@ enum {
55 55
56/* Make use of all registers, except for x18, fp, lr and sp. */ 56/* Make use of all registers, except for x18, fp, lr and sp. */
57#define RSET_FIXED \ 57#define RSET_FIXED \
58 (RID2RSET(RID_X18)|RID2RSET(RID_FP)|RID2RSET(RID_LR)|RID2RSET(RID_SP)) 58 (RID2RSET(RID_X18)|RID2RSET(RID_FP)|RID2RSET(RID_LR)|RID2RSET(RID_SP)|\
59 RID2RSET(RID_GL))
59#define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) - RSET_FIXED) 60#define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) - RSET_FIXED)
60#define RSET_FPR RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR) 61#define RSET_FPR RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR)
61#define RSET_ALL (RSET_GPR|RSET_FPR) 62#define RSET_ALL (RSET_GPR|RSET_FPR)
@@ -73,25 +74,235 @@ enum {
73#define REGARG_LASTFPR RID_D7 74#define REGARG_LASTFPR RID_D7
74#define REGARG_NUMFPR 8 75#define REGARG_NUMFPR 8
75 76
77/* -- Spill slots --------------------------------------------------------- */
78
79/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.
80**
81** SPS_FIXED: Available fixed spill slots in interpreter frame.
82** This definition must match with the vm_arm64.dasc file.
83** Pre-allocate some slots to avoid sp adjust in every root trace.
84**
85** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots.
86*/
87#define SPS_FIXED 4
88#define SPS_FIRST 2
89
90#define SPOFS_TMP 0
91
92#define sps_scale(slot) (4 * (int32_t)(slot))
93#define sps_align(slot) (((slot) - SPS_FIXED + 3) & ~3)
94
95/* -- Exit state ---------------------------------------------------------- */
96
97/* This definition must match with the *.dasc file(s). */
98typedef struct {
99 lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */
100 intptr_t gpr[RID_NUM_GPR]; /* General-purpose registers. */
101 int32_t spill[256]; /* Spill slots. */
102} ExitState;
103
104/* PC after instruction that caused an exit. Used to find the trace number. */
105#define EXITSTATE_PCREG RID_LR
106/* Highest exit + 1 indicates stack check. */
107#define EXITSTATE_CHECKEXIT 1
108
109#define EXITSTUB_SPACING 4
110#define EXITSTUBS_PER_GROUP 32
111
112
76/* -- Instructions -------------------------------------------------------- */ 113/* -- Instructions -------------------------------------------------------- */
77 114
78/* Instruction fields. */ 115/* Instruction fields. */
79#define A64F_D(r) (r) 116#define A64F_D(r) (r)
80#define A64F_N(r) ((r) << 5) 117#define A64F_N(r) ((r) << 5)
81#define A64F_A(r) ((r) << 10) 118#define A64F_A(r) ((r) << 10)
82#define A64F_M(r) ((r) << 16) 119#define A64F_M(r) ((r) << 16)
120#define A64F_IMMS(x) ((x) << 10)
121#define A64F_IMMR(x) ((x) << 16)
83#define A64F_U16(x) ((x) << 5) 122#define A64F_U16(x) ((x) << 5)
123#define A64F_U12(x) ((x) << 10)
84#define A64F_S26(x) (x) 124#define A64F_S26(x) (x)
85#define A64F_S19(x) ((x) << 5) 125#define A64F_S19(x) ((x) << 5)
126#define A64F_S9(x) ((x) << 12)
127#define A64F_SH(sh, x) (((sh) << 22) | ((x) << 10))
128#define A64F_EX(ex) (A64I_EX | ((ex) << 13))
129#define A64F_EXSH(ex,x) (A64I_EX | ((ex) << 13) | ((x) << 10))
130#define A64F_FP8(x) ((x) << 13)
131#define A64F_CC(cc) ((cc) << 12)
132#define A64F_LSL16(x) (((x) / 16) << 21)
133#define A64F_BSH(sh) ((sh) << 10)
86 134
87typedef enum A64Ins { 135typedef enum A64Ins {
136 A64I_S = 0x20000000,
137 A64I_X = 0x80000000,
138 A64I_EX = 0x00200000,
139 A64I_K12 = 0x1a000000,
140 A64I_K13 = 0x18000000,
141 A64I_LS_U = 0x01000000,
142 A64I_LS_S = 0x00800000,
143 A64I_LS_R = 0x01200800,
144 A64I_LS_UXTWx = 0x00005000,
145 A64I_LS_LSLx = 0x00007000,
146
147 A64I_ADDw = 0x0b000000,
148 A64I_ADDx = 0x8b000000,
149 A64I_ADDSw = 0x2b000000,
150 A64I_ADDSx = 0xab000000,
151 A64I_NEGw = 0x4b0003e0,
152 A64I_NEGx = 0xcb0003e0,
153 A64I_SUBw = 0x4b000000,
154 A64I_SUBx = 0xcb000000,
155 A64I_SUBSw = 0x6b000000,
156 A64I_SUBSx = 0xeb000000,
157
158 A64I_MULw = 0x1b007c00,
159 A64I_MULx = 0x9b007c00,
160 A64I_SMULL = 0x9b207c00,
161
162 A64I_ANDw = 0x0a000000,
163 A64I_ANDx = 0x8a000000,
164 A64I_ANDSw = 0x6a000000,
165 A64I_ANDSx = 0xea000000,
166 A64I_EORw = 0x4a000000,
167 A64I_EORx = 0xca000000,
168 A64I_ORRw = 0x2a000000,
169 A64I_ORRx = 0xaa000000,
170 A64I_TSTw = 0x6a00001f,
171 A64I_TSTx = 0xea00001f,
172
173 A64I_CMPw = 0x6b00001f,
174 A64I_CMPx = 0xeb00001f,
175 A64I_CMNw = 0x2b00001f,
176 A64I_CMNx = 0xab00001f,
177 A64I_CCMPw = 0x7a400000,
178 A64I_CCMPx = 0xfa400000,
179 A64I_CSELw = 0x1a800000,
180 A64I_CSELx = 0x9a800000,
181
182 A64I_ASRw = 0x13007c00,
183 A64I_ASRx = 0x9340fc00,
184 A64I_LSLx = 0xd3400000,
185 A64I_LSRx = 0xd340fc00,
186 A64I_SHRw = 0x1ac02000,
187 A64I_SHRx = 0x9ac02000, /* lsl/lsr/asr/ror x0, x0, x0 */
188 A64I_REVw = 0x5ac00800,
189 A64I_REVx = 0xdac00c00,
190
191 A64I_EXTRw = 0x13800000,
192 A64I_EXTRx = 0x93c00000,
193 A64I_SBFMw = 0x13000000,
194 A64I_SBFMx = 0x93400000,
195 A64I_SXTBw = 0x13001c00,
196 A64I_SXTHw = 0x13003c00,
197 A64I_SXTW = 0x93407c00,
198 A64I_UBFMw = 0x53000000,
199 A64I_UBFMx = 0xd3400000,
200 A64I_UXTBw = 0x53001c00,
201 A64I_UXTHw = 0x53003c00,
202
203 A64I_MOVw = 0x2a0003e0,
204 A64I_MOVx = 0xaa0003e0,
205 A64I_MVNw = 0x2a2003e0,
206 A64I_MVNx = 0xaa2003e0,
207 A64I_MOVKw = 0x72800000,
208 A64I_MOVKx = 0xf2800000,
88 A64I_MOVZw = 0x52800000, 209 A64I_MOVZw = 0x52800000,
89 A64I_MOVZx = 0xd2800000, 210 A64I_MOVZx = 0xd2800000,
211 A64I_MOVNw = 0x12800000,
212 A64I_MOVNx = 0x92800000,
213
214 A64I_LDRB = 0x39400000,
215 A64I_LDRH = 0x79400000,
216 A64I_LDRw = 0xb9400000,
217 A64I_LDRx = 0xf9400000,
90 A64I_LDRLw = 0x18000000, 218 A64I_LDRLw = 0x18000000,
91 A64I_LDRLx = 0x58000000, 219 A64I_LDRLx = 0x58000000,
92 A64I_NOP = 0xd503201f, 220 A64I_STRB = 0x39000000,
221 A64I_STRH = 0x79000000,
222 A64I_STRw = 0xb9000000,
223 A64I_STRx = 0xf9000000,
224 A64I_STPw = 0x29000000,
225 A64I_STPx = 0xa9000000,
226 A64I_LDPw = 0x29400000,
227 A64I_LDPx = 0xa9400000,
228
93 A64I_B = 0x14000000, 229 A64I_B = 0x14000000,
230 A64I_BCC = 0x54000000,
231 A64I_BL = 0x94000000,
94 A64I_BR = 0xd61f0000, 232 A64I_BR = 0xd61f0000,
233 A64I_BLR = 0xd63f0000,
234
235 A64I_NOP = 0xd503201f,
236
237 /* FP */
238 A64I_FADDd = 0x1e602800,
239 A64I_FSUBd = 0x1e603800,
240 A64I_FMADDd = 0x1f400000,
241 A64I_FMSUBd = 0x1f408000,
242 A64I_FNMADDd = 0x1f600000,
243 A64I_FNMSUBd = 0x1f608000,
244 A64I_FMULd = 0x1e600800,
245 A64I_FDIVd = 0x1e601800,
246 A64I_FNEGd = 0x1e614000,
247 A64I_FABS = 0x1e60c000,
248 A64I_FSQRTd = 0x1e61c000,
249 A64I_LDRs = 0xbd400000,
250 A64I_LDRd = 0xfd400000,
251 A64I_STRs = 0xbd000000,
252 A64I_STRd = 0xfd000000,
253 A64I_LDPs = 0x2d400000,
254 A64I_LDPd = 0x6d400000,
255 A64I_STPs = 0x2d000000,
256 A64I_STPd = 0x6d000000,
257 A64I_FCMPd = 0x1e602000,
258 A64I_FCMPZd = 0x1e602008,
259 A64I_FCSELd = 0x1e600c00,
260 A64I_FRINTMd = 0x1e654000,
261 A64I_FRINTPd = 0x1e64c000,
262 A64I_FRINTZd = 0x1e65c000,
263
264 A64I_FCVT_F32_F64 = 0x1e624000,
265 A64I_FCVT_F64_F32 = 0x1e22c000,
266 A64I_FCVT_F32_S32 = 0x1e220000,
267 A64I_FCVT_F64_S32 = 0x1e620000,
268 A64I_FCVT_F32_U32 = 0x1e230000,
269 A64I_FCVT_F64_U32 = 0x1e630000,
270 A64I_FCVT_F32_S64 = 0x9e220000,
271 A64I_FCVT_F64_S64 = 0x9e620000,
272 A64I_FCVT_F32_U64 = 0x9e230000,
273 A64I_FCVT_F64_U64 = 0x9e630000,
274 A64I_FCVT_S32_F64 = 0x1e780000,
275 A64I_FCVT_S32_F32 = 0x1e380000,
276 A64I_FCVT_U32_F64 = 0x1e790000,
277 A64I_FCVT_U32_F32 = 0x1e390000,
278 A64I_FCVT_S64_F64 = 0x9e780000,
279 A64I_FCVT_S64_F32 = 0x9e380000,
280 A64I_FCVT_U64_F64 = 0x9e790000,
281 A64I_FCVT_U64_F32 = 0x9e390000,
282
283 A64I_FMOV_S = 0x1e204000,
284 A64I_FMOV_D = 0x1e604000,
285 A64I_FMOV_R_S = 0x1e260000,
286 A64I_FMOV_S_R = 0x1e270000,
287 A64I_FMOV_R_D = 0x9e660000,
288 A64I_FMOV_D_R = 0x9e670000,
289 A64I_FMOV_DI = 0x1e601000,
95} A64Ins; 290} A64Ins;
96 291
292typedef enum A64Shift {
293 A64SH_LSL, A64SH_LSR, A64SH_ASR, A64SH_ROR
294} A64Shift;
295
296typedef enum A64Extend {
297 A64EX_UXTB, A64EX_UXTH, A64EX_UXTW, A64EX_UXTX,
298 A64EX_SXTB, A64EX_SXTH, A64EX_SXTW, A64EX_SXTX,
299} A64Extend;
300
301/* ARM condition codes. */
302typedef enum A64CC {
303 CC_EQ, CC_NE, CC_CS, CC_CC, CC_MI, CC_PL, CC_VS, CC_VC,
304 CC_HI, CC_LS, CC_GE, CC_LT, CC_GT, CC_LE, CC_AL,
305 CC_HS = CC_CS, CC_LO = CC_CC
306} A64CC;
307
97#endif 308#endif