blob: bccd365604c6ea5729cee42c191b3c45ddfbc6b3 [file] [log] [blame]
Ian Rogerse32ca232012-03-05 10:20:23 -08001/*
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
17#ifndef ART_COMPILER_COMPILER_CODEGEN_X86_X86LIR_H_
18#define ART_COMPILER_COMPILER_CODEGEN_X86_X86LIR_H_
19
20#include "../../Dalvik.h"
21#include "../../CompilerInternals.h"
22
23namespace art {
24
Ian Rogerse32ca232012-03-05 10:20:23 -080025/*
26 * Runtime register conventions. We consider both x86, x86-64 and x32 (32bit mode x86-64), although
27 * we currently only target x86. The ABI has different conventions and we hope to have a single
28 * convention to simplify code generation. Changing something that is callee save and making it
29 * caller save places a burden on up-calls to save/restore the callee save register, however, there
30 * are few registers that are callee save in the ABI. Changing something that is caller save and
31 * making it callee save places a burden on down-calls to save/restore the callee save register.
Ian Rogersb41b33b2012-03-20 14:22:54 -070032 * For these reasons we aim to match native conventions for caller and callee save. The first 4
33 * registers can be used for byte operations, for this reason they are preferred for temporary
34 * scratch registers.
Ian Rogerse32ca232012-03-05 10:20:23 -080035 *
36 * General Purpose Register:
37 * Native: x86 | x86-64 / x32 | ART
38 * r0/eax: caller save | caller save | caller, Method*, scratch, return value
Ian Rogersb41b33b2012-03-20 14:22:54 -070039 * r1/ecx: caller save | caller save, arg4 | caller, arg1, scratch
40 * r2/edx: caller save | caller save, arg3 | caller, arg2, scratch, high half of long return
41 * r3/ebx: callEE save | callEE save | callER, arg3, scratch
Ian Rogerse32ca232012-03-05 10:20:23 -080042 * r4/esp: stack pointer
43 * r5/ebp: callee save | callee save | callee, available for dalvik register promotion
44 * r6/esi: callEE save | callER save, arg2 | callee, available for dalvik register promotion
45 * r7/edi: callEE save | callER save, arg1 | callee, available for dalvik register promotion
46 * --- x86-64/x32 registers
47 * Native: x86-64 / x32 | ART
48 * r8: caller save, arg5 | caller, scratch
49 * r9: caller save, arg6 | caller, scratch
50 * r10: caller save | caller, scratch
51 * r11: caller save | caller, scratch
52 * r12: callee save | callee, available for dalvik register promotion
53 * r13: callee save | callee, available for dalvik register promotion
54 * r14: callee save | callee, available for dalvik register promotion
55 * r15: callee save | callee, available for dalvik register promotion
56 *
57 * There is no rSELF, instead on x86 fs: has a base address of Thread::Current, whereas on
58 * x86-64/x32 gs: holds it.
59 *
60 * For floating point we don't support CPUs without SSE2 support (ie newer than PIII):
61 * Native: x86 | x86-64 / x32 | ART
62 * XMM0: caller save |caller save, arg1 | caller, float/double return value (except for native x86 code)
63 * XMM1: caller save |caller save, arg2 | caller, scratch
64 * XMM2: caller save |caller save, arg3 | caller, scratch
65 * XMM3: caller save |caller save, arg4 | caller, scratch
66 * XMM4: caller save |caller save, arg5 | caller, scratch
67 * XMM5: caller save |caller save, arg6 | caller, scratch
68 * XMM6: caller save |caller save, arg7 | caller, scratch
69 * XMM7: caller save |caller save, arg8 | caller, scratch
70 * --- x86-64/x32 registers
71 * XMM8 .. 15: caller save
72 *
73 * X87 is a necessary evil outside of ART code:
74 * ST0: x86 float/double native return value, caller save
75 * ST1 .. ST7: caller save
76 *
77 * Stack frame diagram (stack grows down, higher addresses at top):
78 *
79 * +------------------------+
80 * | IN[ins-1] | {Note: resides in caller's frame}
81 * | . |
82 * | IN[0] |
83 * | caller's Method* |
84 * +========================+ {Note: start of callee's frame}
85 * | return address | {pushed by call}
86 * | spill region | {variable sized}
87 * +------------------------+
88 * | ...filler word... | {Note: used as 2nd word of V[locals-1] if long]
89 * +------------------------+
90 * | V[locals-1] |
91 * | V[locals-2] |
92 * | . |
93 * | . |
94 * | V[1] |
95 * | V[0] |
96 * +------------------------+
97 * | 0 to 3 words padding |
98 * +------------------------+
99 * | OUT[outs-1] |
100 * | OUT[outs-2] |
101 * | . |
102 * | OUT[0] |
103 * | curMethod* | <<== sp w/ 16-byte alignment
104 * +========================+
105 */
106
107/* Offset to distingish FP regs */
buzbeef0504cd2012-11-13 16:31:10 -0800108#define X86_FP_REG_OFFSET 32
Ian Rogerse32ca232012-03-05 10:20:23 -0800109/* Offset to distinguish DP FP regs */
buzbeef0504cd2012-11-13 16:31:10 -0800110#define X86_FP_DOUBLE (X86_FP_REG_OFFSET + 16)
Ian Rogerse32ca232012-03-05 10:20:23 -0800111/* Offset to distingish the extra regs */
buzbeef0504cd2012-11-13 16:31:10 -0800112#define X86_EXTRA_REG_OFFSET (X86_FP_DOUBLE + 16)
Ian Rogerse32ca232012-03-05 10:20:23 -0800113/* Reg types */
buzbeef0504cd2012-11-13 16:31:10 -0800114#define X86_REGTYPE(x) (x & (X86_FP_REG_OFFSET | X86_FP_DOUBLE))
115#define X86_FPREG(x) ((x & X86_FP_REG_OFFSET) == X86_FP_REG_OFFSET)
116#define X86_EXTRAREG(x) ((x & X86_EXTRA_REG_OFFSET) == X86_EXTRA_REG_OFFSET)
117#define X86_DOUBLEREG(x) ((x & X86_FP_DOUBLE) == X86_FP_DOUBLE)
118#define X86_SINGLEREG(x) (X86_FPREG(x) && !X86_DOUBLEREG(x))
Ian Rogersb5d09b22012-03-06 22:14:17 -0800119
Ian Rogerse32ca232012-03-05 10:20:23 -0800120/*
121 * Note: the low register of a floating point pair is sufficient to
122 * create the name of a double, but require both names to be passed to
123 * allow for asserts to verify that the pair is consecutive if significant
124 * rework is done in this area. Also, it is a good reminder in the calling
125 * code that reg locations always describe doubles as a pair of singles.
126 */
buzbeef0504cd2012-11-13 16:31:10 -0800127#define X86_S2D(x,y) ((x) | X86_FP_DOUBLE)
Ian Rogerse32ca232012-03-05 10:20:23 -0800128/* Mask to strip off fp flags */
buzbeef0504cd2012-11-13 16:31:10 -0800129#define X86_FP_REG_MASK 0xF
Ian Rogerse32ca232012-03-05 10:20:23 -0800130
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700131/* RegisterLocation templates return values (rAX, rAX/rDX or XMM0) */
buzbee2cfc6392012-05-07 14:51:40 -0700132// location, wide, defined, const, fp, core, ref, highWord, home, lowReg, highReg, sRegLow
buzbeef0504cd2012-11-13 16:31:10 -0800133#define X86_LOC_C_RETURN {kLocPhysReg, 0, 0, 0, 0, 0, 0, 0, 1, rAX, INVALID_REG, INVALID_SREG, INVALID_SREG}
134#define X86_LOC_C_RETURN_WIDE {kLocPhysReg, 1, 0, 0, 0, 0, 0, 0, 1, rAX, rDX, INVALID_SREG, INVALID_SREG}
135#define X86_LOC_C_RETURN_FLOAT {kLocPhysReg, 0, 0, 0, 1, 0, 0, 0, 1, fr0, INVALID_REG, INVALID_SREG, INVALID_SREG}
136#define X86_LOC_C_RETURN_DOUBLE {kLocPhysReg, 1, 0, 0, 1, 0, 0, 0, 1, fr0, fr1, INVALID_SREG, INVALID_SREG}
Ian Rogerse32ca232012-03-05 10:20:23 -0800137
buzbeeec137432012-11-13 12:13:16 -0800138enum X86ResourceEncodingPos {
139 kX86GPReg0 = 0,
140 kX86RegSP = 4,
141 kX86FPReg0 = 16, // xmm0 .. xmm7/xmm15
142 kX86FPRegEnd = 32,
143 kX86RegEnd = kX86FPRegEnd,
Elliott Hughes719ace42012-03-09 18:06:03 -0800144};
Ian Rogerse32ca232012-03-05 10:20:23 -0800145
buzbeeec137432012-11-13 12:13:16 -0800146#define ENCODE_X86_REG_LIST(N) ((u8) N)
147#define ENCODE_X86_REG_SP (1ULL << kX86RegSP)
Ian Rogerse32ca232012-03-05 10:20:23 -0800148
149/*
150 * Annotate special-purpose core registers:
151 */
152
buzbeef0504cd2012-11-13 16:31:10 -0800153enum X86NativeRegisterPool {
Ian Rogerse32ca232012-03-05 10:20:23 -0800154 r0 = 0,
Ian Rogersb5d09b22012-03-06 22:14:17 -0800155 rAX = r0,
Ian Rogerse32ca232012-03-05 10:20:23 -0800156 r1 = 1,
Ian Rogersb5d09b22012-03-06 22:14:17 -0800157 rCX = r1,
Ian Rogerse32ca232012-03-05 10:20:23 -0800158 r2 = 2,
159 rDX = r2,
160 r3 = 3,
161 rBX = r3,
162 r4sp = 4,
buzbeef0504cd2012-11-13 16:31:10 -0800163 rX86_SP = r4sp,
Ian Rogersb5d09b22012-03-06 22:14:17 -0800164 r4sib_no_index = r4sp,
Ian Rogerse32ca232012-03-05 10:20:23 -0800165 r5 = 5,
166 rBP = r5,
Ian Rogers7caad772012-03-30 01:07:54 -0700167 r5sib_no_base = r5,
Ian Rogerse32ca232012-03-05 10:20:23 -0800168 r6 = 6,
169 rSI = r6,
170 r7 = 7,
171 rDI = r7,
jeffhao703f2cd2012-07-13 17:25:52 -0700172#ifndef TARGET_REX_SUPPORT
173 rRET = 8, // fake return address register for core spill mask
174#else
Ian Rogerse32ca232012-03-05 10:20:23 -0800175 r8 = 8,
176 r9 = 9,
177 r10 = 10,
178 r11 = 11,
179 r12 = 12,
180 r13 = 13,
181 r14 = 14,
182 r15 = 15,
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700183 rRET = 16, // fake return address register for core spill mask
jeffhao703f2cd2012-07-13 17:25:52 -0700184#endif
buzbeef0504cd2012-11-13 16:31:10 -0800185 fr0 = 0 + X86_FP_REG_OFFSET,
186 fr1 = 1 + X86_FP_REG_OFFSET,
187 fr2 = 2 + X86_FP_REG_OFFSET,
188 fr3 = 3 + X86_FP_REG_OFFSET,
189 fr4 = 4 + X86_FP_REG_OFFSET,
190 fr5 = 5 + X86_FP_REG_OFFSET,
191 fr6 = 6 + X86_FP_REG_OFFSET,
192 fr7 = 7 + X86_FP_REG_OFFSET,
193 fr8 = 8 + X86_FP_REG_OFFSET,
194 fr9 = 9 + X86_FP_REG_OFFSET,
195 fr10 = 10 + X86_FP_REG_OFFSET,
196 fr11 = 11 + X86_FP_REG_OFFSET,
197 fr12 = 12 + X86_FP_REG_OFFSET,
198 fr13 = 13 + X86_FP_REG_OFFSET,
199 fr14 = 14 + X86_FP_REG_OFFSET,
200 fr15 = 15 + X86_FP_REG_OFFSET,
Elliott Hughes719ace42012-03-09 18:06:03 -0800201};
Ian Rogerse32ca232012-03-05 10:20:23 -0800202
203/*
204 * Target-independent aliases
205 */
206
buzbeef0504cd2012-11-13 16:31:10 -0800207#define rX86_ARG0 rAX
208#define rX86_ARG1 rCX
209#define rX86_ARG2 rDX
210#define rX86_ARG3 rBX
211#define rX86_FARG0 rAX
212#define rX86_FARG1 rCX
213#define rX86_FARG2 rDX
214#define rX86_FARG3 rBX
215#define rX86_RET0 rAX
216#define rX86_RET1 rDX
217#define rX86_INVOKE_TGT rAX
218#define rX86_LR INVALID_REG
219#define rX86_SUSPEND INVALID_REG
220#define rX86_SELF INVALID_REG
221#define rX86_COUNT rCX
222#define rX86_PC INVALID_REG
Ian Rogerse32ca232012-03-05 10:20:23 -0800223
224#define isPseudoOpcode(opCode) ((int)(opCode) < 0)
225
226/*
Ian Rogersde797832012-03-06 10:18:10 -0800227 * The following enum defines the list of supported X86 instructions by the
228 * assembler. Their corresponding EncodingMap positions will be defined in
229 * Assemble.cc.
Ian Rogerse32ca232012-03-05 10:20:23 -0800230 */
Elliott Hughes719ace42012-03-09 18:06:03 -0800231enum X86OpCode {
buzbeeb046e162012-10-30 15:48:42 -0700232 kX86First = 0,
Bill Buzbeea114add2012-05-03 15:00:40 -0700233 kX8632BitData = kX86First, /* data [31..0] */
234 kX86Bkpt,
235 kX86Nop,
236 // Define groups of binary operations
237 // MR - Memory Register - opcode [base + disp], reg
238 // - lir operands - 0: base, 1: disp, 2: reg
239 // AR - Array Register - opcode [base + index * scale + disp], reg
240 // - lir operands - 0: base, 1: index, 2: scale, 3: disp, 4: reg
241 // TR - Thread Register - opcode fs:[disp], reg - where fs: is equal to Thread::Current()
242 // - lir operands - 0: disp, 1: reg
243 // RR - Register Register - opcode reg1, reg2
244 // - lir operands - 0: reg1, 1: reg2
245 // RM - Register Memory - opcode reg, [base + disp]
246 // - lir operands - 0: reg, 1: base, 2: disp
247 // RA - Register Array - opcode reg, [base + index * scale + disp]
248 // - lir operands - 0: reg, 1: base, 2: index, 3: scale, 4: disp
249 // RT - Register Thread - opcode reg, fs:[disp] - where fs: is equal to Thread::Current()
250 // - lir operands - 0: reg, 1: disp
251 // RI - Register Immediate - opcode reg, #immediate
252 // - lir operands - 0: reg, 1: immediate
253 // MI - Memory Immediate - opcode [base + disp], #immediate
254 // - lir operands - 0: base, 1: disp, 2: immediate
255 // AI - Array Immediate - opcode [base + index * scale + disp], #immediate
256 // - lir operands - 0: base, 1: index, 2: scale, 3: disp 4: immediate
257 // TI - Thread Register - opcode fs:[disp], imm - where fs: is equal to Thread::Current()
258 // - lir operands - 0: disp, 1: imm
Ian Rogers96ab4202012-03-05 19:51:02 -0800259#define BinaryOpCode(opcode) \
Ian Rogersb5d09b22012-03-06 22:14:17 -0800260 opcode ## 8MR, opcode ## 8AR, opcode ## 8TR, \
261 opcode ## 8RR, opcode ## 8RM, opcode ## 8RA, opcode ## 8RT, \
262 opcode ## 8RI, opcode ## 8MI, opcode ## 8AI, opcode ## 8TI, \
263 opcode ## 16MR, opcode ## 16AR, opcode ## 16TR, \
264 opcode ## 16RR, opcode ## 16RM, opcode ## 16RA, opcode ## 16RT, \
265 opcode ## 16RI, opcode ## 16MI, opcode ## 16AI, opcode ## 16TI, \
266 opcode ## 16RI8, opcode ## 16MI8, opcode ## 16AI8, opcode ## 16TI8, \
267 opcode ## 32MR, opcode ## 32AR, opcode ## 32TR, \
268 opcode ## 32RR, opcode ## 32RM, opcode ## 32RA, opcode ## 32RT, \
269 opcode ## 32RI, opcode ## 32MI, opcode ## 32AI, opcode ## 32TI, \
270 opcode ## 32RI8, opcode ## 32MI8, opcode ## 32AI8, opcode ## 32TI8
Bill Buzbeea114add2012-05-03 15:00:40 -0700271 BinaryOpCode(kX86Add),
272 BinaryOpCode(kX86Or),
273 BinaryOpCode(kX86Adc),
274 BinaryOpCode(kX86Sbb),
275 BinaryOpCode(kX86And),
276 BinaryOpCode(kX86Sub),
277 BinaryOpCode(kX86Xor),
278 BinaryOpCode(kX86Cmp),
Ian Rogers96ab4202012-03-05 19:51:02 -0800279#undef BinaryOpCode
Bill Buzbeea114add2012-05-03 15:00:40 -0700280 kX86Imul16RRI, kX86Imul16RMI, kX86Imul16RAI,
281 kX86Imul32RRI, kX86Imul32RMI, kX86Imul32RAI,
282 kX86Imul32RRI8, kX86Imul32RMI8, kX86Imul32RAI8,
283 kX86Mov8MR, kX86Mov8AR, kX86Mov8TR,
284 kX86Mov8RR, kX86Mov8RM, kX86Mov8RA, kX86Mov8RT,
285 kX86Mov8RI, kX86Mov8MI, kX86Mov8AI, kX86Mov8TI,
286 kX86Mov16MR, kX86Mov16AR, kX86Mov16TR,
287 kX86Mov16RR, kX86Mov16RM, kX86Mov16RA, kX86Mov16RT,
288 kX86Mov16RI, kX86Mov16MI, kX86Mov16AI, kX86Mov16TI,
289 kX86Mov32MR, kX86Mov32AR, kX86Mov32TR,
290 kX86Mov32RR, kX86Mov32RM, kX86Mov32RA, kX86Mov32RT,
291 kX86Mov32RI, kX86Mov32MI, kX86Mov32AI, kX86Mov32TI,
292 kX86Lea32RA,
293 // RC - Register CL - opcode reg, CL
294 // - lir operands - 0: reg, 1: CL
295 // MC - Memory CL - opcode [base + disp], CL
296 // - lir operands - 0: base, 1: disp, 2: CL
297 // AC - Array CL - opcode [base + index * scale + disp], CL
298 // - lir operands - 0: base, 1: index, 2: scale, 3: disp, 4: CL
Ian Rogersb5d09b22012-03-06 22:14:17 -0800299#define BinaryShiftOpCode(opcode) \
Bill Buzbeea114add2012-05-03 15:00:40 -0700300 opcode ## 8RI, opcode ## 8MI, opcode ## 8AI, \
301 opcode ## 8RC, opcode ## 8MC, opcode ## 8AC, \
302 opcode ## 16RI, opcode ## 16MI, opcode ## 16AI, \
303 opcode ## 16RC, opcode ## 16MC, opcode ## 16AC, \
304 opcode ## 32RI, opcode ## 32MI, opcode ## 32AI, \
305 opcode ## 32RC, opcode ## 32MC, opcode ## 32AC
306 BinaryShiftOpCode(kX86Rol),
307 BinaryShiftOpCode(kX86Ror),
308 BinaryShiftOpCode(kX86Rcl),
309 BinaryShiftOpCode(kX86Rcr),
310 BinaryShiftOpCode(kX86Sal),
311 BinaryShiftOpCode(kX86Shr),
312 BinaryShiftOpCode(kX86Sar),
Ian Rogersb5d09b22012-03-06 22:14:17 -0800313#undef BinaryShiftOpcode
jeffhao77ae36b2012-08-07 14:18:16 -0700314 kX86Cmc,
Ian Rogersb5d09b22012-03-06 22:14:17 -0800315#define UnaryOpcode(opcode, reg, mem, array) \
Bill Buzbeea114add2012-05-03 15:00:40 -0700316 opcode ## 8 ## reg, opcode ## 8 ## mem, opcode ## 8 ## array, \
317 opcode ## 16 ## reg, opcode ## 16 ## mem, opcode ## 16 ## array, \
318 opcode ## 32 ## reg, opcode ## 32 ## mem, opcode ## 32 ## array
319 UnaryOpcode(kX86Test, RI, MI, AI),
Ian Rogers2e9f7ed2012-09-26 11:30:43 -0700320 kX86Test32RR,
Bill Buzbeea114add2012-05-03 15:00:40 -0700321 UnaryOpcode(kX86Not, R, M, A),
322 UnaryOpcode(kX86Neg, R, M, A),
323 UnaryOpcode(kX86Mul, DaR, DaM, DaA),
324 UnaryOpcode(kX86Imul, DaR, DaM, DaA),
325 UnaryOpcode(kX86Divmod, DaR, DaM, DaA),
326 UnaryOpcode(kX86Idivmod, DaR, DaM, DaA),
Ian Rogersb5d09b22012-03-06 22:14:17 -0800327#undef UnaryOpcode
328#define Binary0fOpCode(opcode) \
329 opcode ## RR, opcode ## RM, opcode ## RA
Bill Buzbeea114add2012-05-03 15:00:40 -0700330 Binary0fOpCode(kX86Movsd),
331 kX86MovsdMR,
332 kX86MovsdAR,
333 Binary0fOpCode(kX86Movss),
334 kX86MovssMR,
335 kX86MovssAR,
336 Binary0fOpCode(kX86Cvtsi2sd), // int to double
337 Binary0fOpCode(kX86Cvtsi2ss), // int to float
338 Binary0fOpCode(kX86Cvttsd2si),// truncating double to int
339 Binary0fOpCode(kX86Cvttss2si),// truncating float to int
340 Binary0fOpCode(kX86Cvtsd2si), // rounding double to int
341 Binary0fOpCode(kX86Cvtss2si), // rounding float to int
342 Binary0fOpCode(kX86Ucomisd), // unordered double compare
343 Binary0fOpCode(kX86Ucomiss), // unordered float compare
344 Binary0fOpCode(kX86Comisd), // double compare
345 Binary0fOpCode(kX86Comiss), // float compare
346 Binary0fOpCode(kX86Orps), // or of floating point registers
347 Binary0fOpCode(kX86Xorps), // xor of floating point registers
348 Binary0fOpCode(kX86Addsd), // double add
349 Binary0fOpCode(kX86Addss), // float add
350 Binary0fOpCode(kX86Mulsd), // double multiply
351 Binary0fOpCode(kX86Mulss), // float multiply
Bill Buzbeea114add2012-05-03 15:00:40 -0700352 Binary0fOpCode(kX86Cvtsd2ss), // double to float
jeffhao292188d2012-05-17 15:45:04 -0700353 Binary0fOpCode(kX86Cvtss2sd), // float to double
Bill Buzbeea114add2012-05-03 15:00:40 -0700354 Binary0fOpCode(kX86Subsd), // double subtract
355 Binary0fOpCode(kX86Subss), // float subtract
356 Binary0fOpCode(kX86Divsd), // double divide
357 Binary0fOpCode(kX86Divss), // float divide
jeffhaofdffdf82012-07-11 16:08:43 -0700358 kX86PsrlqRI, // right shift of floating point registers
359 kX86PsllqRI, // left shift of floating point registers
Bill Buzbeea114add2012-05-03 15:00:40 -0700360 Binary0fOpCode(kX86Movdxr), // move into xmm from gpr
jeffhaofdffdf82012-07-11 16:08:43 -0700361 kX86MovdrxRR, kX86MovdrxMR, kX86MovdrxAR,// move into reg from xmm
Bill Buzbeea114add2012-05-03 15:00:40 -0700362 kX86Set8R, kX86Set8M, kX86Set8A,// set byte depending on condition operand
363 kX86Mfence, // memory barrier
364 Binary0fOpCode(kX86Imul16), // 16bit multiply
365 Binary0fOpCode(kX86Imul32), // 32bit multiply
jeffhao83025762012-08-02 11:08:56 -0700366 kX86CmpxchgRR, kX86CmpxchgMR, kX86CmpxchgAR,// compare and exchange
367 kX86LockCmpxchgRR, kX86LockCmpxchgMR, kX86LockCmpxchgAR,// locked compare and exchange
Bill Buzbeea114add2012-05-03 15:00:40 -0700368 Binary0fOpCode(kX86Movzx8), // zero-extend 8-bit value
369 Binary0fOpCode(kX86Movzx16), // zero-extend 16-bit value
370 Binary0fOpCode(kX86Movsx8), // sign-extend 8-bit value
371 Binary0fOpCode(kX86Movsx16), // sign-extend 16-bit value
Ian Rogersb5d09b22012-03-06 22:14:17 -0800372#undef Binary0fOpCode
Bill Buzbeea114add2012-05-03 15:00:40 -0700373 kX86Jcc8, kX86Jcc32, // jCC rel8/32; lir operands - 0: rel, 1: CC, target assigned
374 kX86Jmp8, kX86Jmp32, // jmp rel8/32; lir operands - 0: rel, target assigned
375 kX86JmpR, // jmp reg; lir operands - 0: reg
376 kX86CallR, // call reg; lir operands - 0: reg
377 kX86CallM, // call [base + disp]; lir operands - 0: base, 1: disp
378 kX86CallA, // call [base + index * scale + disp]
379 // lir operands - 0: base, 1: index, 2: scale, 3: disp
380 kX86CallT, // call fs:[disp]; fs: is equal to Thread::Current(); lir operands - 0: disp
381 kX86Ret, // ret; no lir operands
382 kX86StartOfMethod, // call 0; pop reg; sub reg, # - generate start of method into reg
383 // lir operands - 0: reg
384 kX86PcRelLoadRA, // mov reg, [base + index * scale + PC relative displacement]
385 // lir operands - 0: reg, 1: base, 2: index, 3: scale, 4: table
386 kX86PcRelAdr, // mov reg, PC relative displacement; lir operands - 0: reg, 1: table
387 kX86Last
Elliott Hughes719ace42012-03-09 18:06:03 -0800388};
Ian Rogerse32ca232012-03-05 10:20:23 -0800389
Ian Rogersde797832012-03-06 10:18:10 -0800390/* Instruction assembly fieldLoc kind */
Elliott Hughes719ace42012-03-09 18:06:03 -0800391enum X86EncodingKind {
Ian Rogersb5d09b22012-03-06 22:14:17 -0800392 kData, // Special case for raw data.
393 kNop, // Special case for variable length nop.
394 kNullary, // Opcode that takes no arguments.
395 kReg, kMem, kArray, // R, M and A instruction kinds.
396 kMemReg, kArrayReg, kThreadReg, // MR, AR and TR instruction kinds.
397 kRegReg, kRegMem, kRegArray, kRegThread, // RR, RM, RA and RT instruction kinds.
jeffhaofdffdf82012-07-11 16:08:43 -0700398 kRegRegStore, // RR following the store modrm reg-reg encoding rather than the load.
Ian Rogersb5d09b22012-03-06 22:14:17 -0800399 kRegImm, kMemImm, kArrayImm, kThreadImm, // RI, MI, AI and TI instruction kinds.
400 kRegRegImm, kRegMemImm, kRegArrayImm, // RRI, RMI and RAI instruction kinds.
401 kMovRegImm, // Shorter form move RI.
402 kShiftRegImm, kShiftMemImm, kShiftArrayImm, // Shift opcode with immediate.
403 kShiftRegCl, kShiftMemCl, kShiftArrayCl, // Shift opcode with register CL.
404 kRegRegReg, kRegRegMem, kRegRegArray, // RRR, RRM, RRA instruction kinds.
405 kRegCond, kMemCond, kArrayCond, // R, M, A instruction kinds following by a condition.
Bill Buzbeea114add2012-05-03 15:00:40 -0700406 kJmp, kJcc, kCall, // Branch instruction kinds.
407 kPcRel, // Operation with displacement that is PC relative
408 kMacro, // An instruction composing multiple others
409 kUnimplemented // Encoding used when an instruction isn't yet implemented.
Elliott Hughes719ace42012-03-09 18:06:03 -0800410};
Ian Rogersde797832012-03-06 10:18:10 -0800411
Ian Rogersde797832012-03-06 10:18:10 -0800412/* Struct used to define the EncodingMap positions for each X86 opcode */
Elliott Hughes719ace42012-03-09 18:06:03 -0800413struct X86EncodingMap {
Ian Rogersde797832012-03-06 10:18:10 -0800414 X86OpCode opcode; // e.g. kOpAddRI
415 X86EncodingKind kind; // Used to discriminate in the union below
buzbeeec137432012-11-13 12:13:16 -0800416 uint64_t flags;
Ian Rogersb5d09b22012-03-06 22:14:17 -0800417 struct {
Bill Buzbeea114add2012-05-03 15:00:40 -0700418 uint8_t prefix1; // non-zero => a prefix byte
419 uint8_t prefix2; // non-zero => a second prefix byte
420 uint8_t opcode; // 1 byte opcode
421 uint8_t extra_opcode1; // possible extra opcode byte
422 uint8_t extra_opcode2; // possible second extra opcode byte
423 // 3bit opcode that gets encoded in the register bits of the modrm byte, use determined by the
424 // encoding kind
425 uint8_t modrm_opcode;
426 uint8_t ax_opcode; // non-zero => shorter encoding for AX as a destination
427 uint8_t immediate_bytes; // number of bytes of immediate
Ian Rogersde797832012-03-06 10:18:10 -0800428 } skeleton;
429 const char *name;
430 const char* fmt;
Elliott Hughes719ace42012-03-09 18:06:03 -0800431};
Ian Rogersde797832012-03-06 10:18:10 -0800432
433extern X86EncodingMap EncodingMap[kX86Last];
434
buzbeea7678db2012-03-05 15:35:46 -0800435// FIXME: mem barrier type - what do we do for x86?
436#define kSY 0
437#define kST 0
438
Ian Rogerse32ca232012-03-05 10:20:23 -0800439/* Keys for target-specific scheduling and other optimization hints */
Elliott Hughes719ace42012-03-09 18:06:03 -0800440enum X86TargetOptHints {
Bill Buzbeea114add2012-05-03 15:00:40 -0700441 kMaxHoistDistance,
Elliott Hughes719ace42012-03-09 18:06:03 -0800442};
Ian Rogerse32ca232012-03-05 10:20:23 -0800443
Ian Rogersb5d09b22012-03-06 22:14:17 -0800444/* Offsets of high and low halves of a 64bit value */
445#define LOWORD_OFFSET 0
446#define HIWORD_OFFSET 4
447
448/* Segment override instruction prefix used for quick TLS access to Thread::Current() */
449#define THREAD_PREFIX 0x64
Ian Rogerse32ca232012-03-05 10:20:23 -0800450
Ian Rogersde797832012-03-06 10:18:10 -0800451#define IS_SIMM8(v) ((-128 <= (v)) && ((v) <= 127))
Ian Rogersb5d09b22012-03-06 22:14:17 -0800452#define IS_SIMM16(v) ((-32768 <= (v)) && ((v) <= 32767))
Ian Rogerse32ca232012-03-05 10:20:23 -0800453
454} // namespace art
455
456#endif // ART_COMPILER_COMPILER_CODEGEN_X86_X86LIR_H_