blob: 378c24de68d871f5673f2dd514069ebd5d828048 [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
25// Set to 1 to measure cost of suspend check
26#define NO_SUSPEND 0
27
28/*
29 * Runtime register conventions. We consider both x86, x86-64 and x32 (32bit mode x86-64), although
30 * we currently only target x86. The ABI has different conventions and we hope to have a single
31 * convention to simplify code generation. Changing something that is callee save and making it
32 * caller save places a burden on up-calls to save/restore the callee save register, however, there
33 * are few registers that are callee save in the ABI. Changing something that is caller save and
34 * making it callee save places a burden on down-calls to save/restore the callee save register.
Ian Rogersb41b33b2012-03-20 14:22:54 -070035 * For these reasons we aim to match native conventions for caller and callee save. The first 4
36 * registers can be used for byte operations, for this reason they are preferred for temporary
37 * scratch registers.
Ian Rogerse32ca232012-03-05 10:20:23 -080038 *
39 * General Purpose Register:
40 * Native: x86 | x86-64 / x32 | ART
41 * r0/eax: caller save | caller save | caller, Method*, scratch, return value
Ian Rogersb41b33b2012-03-20 14:22:54 -070042 * r1/ecx: caller save | caller save, arg4 | caller, arg1, scratch
43 * r2/edx: caller save | caller save, arg3 | caller, arg2, scratch, high half of long return
44 * r3/ebx: callEE save | callEE save | callER, arg3, scratch
Ian Rogerse32ca232012-03-05 10:20:23 -080045 * r4/esp: stack pointer
46 * r5/ebp: callee save | callee save | callee, available for dalvik register promotion
47 * r6/esi: callEE save | callER save, arg2 | callee, available for dalvik register promotion
48 * r7/edi: callEE save | callER save, arg1 | callee, available for dalvik register promotion
49 * --- x86-64/x32 registers
50 * Native: x86-64 / x32 | ART
51 * r8: caller save, arg5 | caller, scratch
52 * r9: caller save, arg6 | caller, scratch
53 * r10: caller save | caller, scratch
54 * r11: caller save | caller, scratch
55 * r12: callee save | callee, available for dalvik register promotion
56 * r13: callee save | callee, available for dalvik register promotion
57 * r14: callee save | callee, available for dalvik register promotion
58 * r15: callee save | callee, available for dalvik register promotion
59 *
60 * There is no rSELF, instead on x86 fs: has a base address of Thread::Current, whereas on
61 * x86-64/x32 gs: holds it.
62 *
63 * For floating point we don't support CPUs without SSE2 support (ie newer than PIII):
64 * Native: x86 | x86-64 / x32 | ART
65 * XMM0: caller save |caller save, arg1 | caller, float/double return value (except for native x86 code)
66 * XMM1: caller save |caller save, arg2 | caller, scratch
67 * XMM2: caller save |caller save, arg3 | caller, scratch
68 * XMM3: caller save |caller save, arg4 | caller, scratch
69 * XMM4: caller save |caller save, arg5 | caller, scratch
70 * XMM5: caller save |caller save, arg6 | caller, scratch
71 * XMM6: caller save |caller save, arg7 | caller, scratch
72 * XMM7: caller save |caller save, arg8 | caller, scratch
73 * --- x86-64/x32 registers
74 * XMM8 .. 15: caller save
75 *
76 * X87 is a necessary evil outside of ART code:
77 * ST0: x86 float/double native return value, caller save
78 * ST1 .. ST7: caller save
79 *
80 * Stack frame diagram (stack grows down, higher addresses at top):
81 *
82 * +------------------------+
83 * | IN[ins-1] | {Note: resides in caller's frame}
84 * | . |
85 * | IN[0] |
86 * | caller's Method* |
87 * +========================+ {Note: start of callee's frame}
88 * | return address | {pushed by call}
89 * | spill region | {variable sized}
90 * +------------------------+
91 * | ...filler word... | {Note: used as 2nd word of V[locals-1] if long]
92 * +------------------------+
93 * | V[locals-1] |
94 * | V[locals-2] |
95 * | . |
96 * | . |
97 * | V[1] |
98 * | V[0] |
99 * +------------------------+
100 * | 0 to 3 words padding |
101 * +------------------------+
102 * | OUT[outs-1] |
103 * | OUT[outs-2] |
104 * | . |
105 * | OUT[0] |
106 * | curMethod* | <<== sp w/ 16-byte alignment
107 * +========================+
108 */
109
110/* Offset to distingish FP regs */
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700111#define FP_REG_OFFSET 32
Ian Rogerse32ca232012-03-05 10:20:23 -0800112/* Offset to distinguish DP FP regs */
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700113#define FP_DOUBLE (FP_REG_OFFSET + 16)
Ian Rogerse32ca232012-03-05 10:20:23 -0800114/* Offset to distingish the extra regs */
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700115#define EXTRA_REG_OFFSET (FP_DOUBLE + 16)
Ian Rogerse32ca232012-03-05 10:20:23 -0800116/* Reg types */
117#define REGTYPE(x) (x & (FP_REG_OFFSET | FP_DOUBLE))
118#define FPREG(x) ((x & FP_REG_OFFSET) == FP_REG_OFFSET)
119#define EXTRAREG(x) ((x & EXTRA_REG_OFFSET) == EXTRA_REG_OFFSET)
120#define LOWREG(x) ((x & 0x1f) == x)
121#define DOUBLEREG(x) ((x & FP_DOUBLE) == FP_DOUBLE)
122#define SINGLEREG(x) (FPREG(x) && !DOUBLEREG(x))
Ian Rogersb5d09b22012-03-06 22:14:17 -0800123
Ian Rogerse32ca232012-03-05 10:20:23 -0800124/*
125 * Note: the low register of a floating point pair is sufficient to
126 * create the name of a double, but require both names to be passed to
127 * allow for asserts to verify that the pair is consecutive if significant
128 * rework is done in this area. Also, it is a good reminder in the calling
129 * code that reg locations always describe doubles as a pair of singles.
130 */
131#define S2D(x,y) ((x) | FP_DOUBLE)
132/* Mask to strip off fp flags */
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700133#define FP_REG_MASK 0xF
Ian Rogerse32ca232012-03-05 10:20:23 -0800134/* non-existent Dalvik register */
135#define vNone (-1)
136/* non-existant physical register */
137#define rNone (-1)
138
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700139/* RegisterLocation templates return values (rAX, rAX/rDX or XMM0) */
140// location, wide, defined, fp, core, highWord, home, lowReg, highReg, sRegLow
141#define LOC_C_RETURN {kLocPhysReg, 0, 0, 0, 0, 0, 1, rAX, INVALID_REG, INVALID_SREG}
142#define LOC_C_RETURN_WIDE {kLocPhysReg, 1, 0, 0, 0, 0, 1, rAX, rDX, INVALID_SREG}
143#define LOC_C_RETURN_FLOAT {kLocPhysReg, 0, 0, 1, 0, 0, 1, fr0, INVALID_REG, INVALID_SREG}
144#define LOC_C_RETURN_WIDE_DOUBLE {kLocPhysReg, 1, 0, 1, 0, 0, 1, fr0, fr1, INVALID_SREG}
Ian Rogerse32ca232012-03-05 10:20:23 -0800145
Elliott Hughes719ace42012-03-09 18:06:03 -0800146enum ResourceEncodingPos {
Ian Rogerse32ca232012-03-05 10:20:23 -0800147 kGPReg0 = 0,
148 kRegSP = 4,
149 kRegLR = -1,
150 kFPReg0 = 16, // xmm0 .. xmm7/xmm15
151 kFPRegEnd = 32,
152 kRegEnd = kFPRegEnd,
153 kCCode = kRegEnd,
154 // The following four bits are for memory disambiguation
155 kDalvikReg, // 1 Dalvik Frame (can be fully disambiguated)
156 kLiteral, // 2 Literal pool (can be fully disambiguated)
157 kHeapRef, // 3 Somewhere on the heap (alias with any other heap)
158 kMustNotAlias, // 4 Guaranteed to be non-alias (eg *(r6+x))
Elliott Hughes719ace42012-03-09 18:06:03 -0800159};
Ian Rogerse32ca232012-03-05 10:20:23 -0800160
161#define ENCODE_REG_LIST(N) ((u8) N)
162#define ENCODE_REG_SP (1ULL << kRegSP)
163#define ENCODE_CCODE (1ULL << kCCode)
164#define ENCODE_FP_STATUS (1ULL << kFPStatus)
165
166/* Abstract memory locations */
167#define ENCODE_DALVIK_REG (1ULL << kDalvikReg)
168#define ENCODE_LITERAL (1ULL << kLiteral)
169#define ENCODE_HEAP_REF (1ULL << kHeapRef)
170#define ENCODE_MUST_NOT_ALIAS (1ULL << kMustNotAlias)
171
172#define ENCODE_ALL (~0ULL)
173#define ENCODE_MEM (ENCODE_DALVIK_REG | ENCODE_LITERAL | \
174 ENCODE_HEAP_REF | ENCODE_MUST_NOT_ALIAS)
175
176#define DECODE_ALIAS_INFO_REG(X) (X & 0xffff)
177#define DECODE_ALIAS_INFO_WIDE(X) ((X & 0x80000000) ? 1 : 0)
178
179/*
180 * Annotate special-purpose core registers:
181 */
182
Elliott Hughes719ace42012-03-09 18:06:03 -0800183enum NativeRegisterPool {
Ian Rogerse32ca232012-03-05 10:20:23 -0800184 r0 = 0,
Ian Rogersb5d09b22012-03-06 22:14:17 -0800185 rAX = r0,
Ian Rogerse32ca232012-03-05 10:20:23 -0800186 r1 = 1,
Ian Rogersb5d09b22012-03-06 22:14:17 -0800187 rCX = r1,
Ian Rogerse32ca232012-03-05 10:20:23 -0800188 r2 = 2,
189 rDX = r2,
190 r3 = 3,
191 rBX = r3,
192 r4sp = 4,
Ian Rogersb5d09b22012-03-06 22:14:17 -0800193 rSP = r4sp,
194 r4sib_no_index = r4sp,
Ian Rogerse32ca232012-03-05 10:20:23 -0800195 r5 = 5,
196 rBP = r5,
197 r6 = 6,
198 rSI = r6,
199 r7 = 7,
200 rDI = r7,
201 r8 = 8,
202 r9 = 9,
203 r10 = 10,
204 r11 = 11,
205 r12 = 12,
206 r13 = 13,
207 r14 = 14,
208 r15 = 15,
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700209 rRET = 16, // fake return address register for core spill mask
Ian Rogerse32ca232012-03-05 10:20:23 -0800210 fr0 = 0 + FP_REG_OFFSET,
211 fr1 = 1 + FP_REG_OFFSET,
212 fr2 = 2 + FP_REG_OFFSET,
213 fr3 = 3 + FP_REG_OFFSET,
214 fr4 = 4 + FP_REG_OFFSET,
215 fr5 = 5 + FP_REG_OFFSET,
216 fr6 = 6 + FP_REG_OFFSET,
217 fr7 = 7 + FP_REG_OFFSET,
218 fr8 = 8 + FP_REG_OFFSET,
219 fr9 = 9 + FP_REG_OFFSET,
220 fr10 = 10 + FP_REG_OFFSET,
221 fr11 = 11 + FP_REG_OFFSET,
222 fr12 = 12 + FP_REG_OFFSET,
223 fr13 = 13 + FP_REG_OFFSET,
224 fr14 = 14 + FP_REG_OFFSET,
225 fr15 = 15 + FP_REG_OFFSET,
Elliott Hughes719ace42012-03-09 18:06:03 -0800226};
Ian Rogerse32ca232012-03-05 10:20:23 -0800227
228/*
229 * Target-independent aliases
230 */
231
232#define rARG0 rAX
Ian Rogersb41b33b2012-03-20 14:22:54 -0700233#define rARG1 rCX
234#define rARG2 rDX
235#define rARG3 rBX
Ian Rogerse32ca232012-03-05 10:20:23 -0800236#define rRET0 rAX
237#define rRET1 rDX
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700238#define rINVOKE_TGT rAX
Ian Rogerse32ca232012-03-05 10:20:23 -0800239
240#define isPseudoOpcode(opCode) ((int)(opCode) < 0)
241
Ian Rogersb5d09b22012-03-06 22:14:17 -0800242/* X86 condition encodings */
243enum X86ConditionCode {
244 kX86CondO = 0x0, // overflow
245 kX86CondNo = 0x1, // not overflow
246
247 kX86CondB = 0x2, // below
248 kX86CondNae = kX86CondB, // not-above-equal
249 kX86CondC = kX86CondB, // carry
250
251 kX86CondNb = 0x3, // not-below
252 kX86CondAe = kX86CondNb, // above-equal
253 kX86CondNc = kX86CondNb, // not-carry
254
255 kX86CondZ = 0x4, // zero
256 kX86CondEq = kX86CondZ, // equal
257
258 kX86CondNz = 0x5, // not-zero
259 kX86CondNe = kX86CondNz, // not-equal
260
261 kX86CondBe = 0x6, // below-equal
262 kX86CondNa = kX86CondBe, // not-above
263
264 kX86CondNbe = 0x7, // not-below-equal
265 kX86CondA = kX86CondNbe,// above
266
267 kX86CondS = 0x8, // sign
268 kX86CondNs = 0x9, // not-sign
269
270 kX86CondP = 0xA, // 8-bit parity even
271 kX86CondPE = kX86CondP,
272
273 kX86CondNp = 0xB, // 8-bit parity odd
274 kX86CondPo = kX86CondNp,
275
276 kX86CondL = 0xC, // less-than
277 kX86CondNge = kX86CondL, // not-greater-equal
278
279 kX86CondNl = 0xD, // not-less-than
280 kX86CondGe = kX86CondL, // not-greater-equal
281
282 kX86CondLe = 0xE, // less-than-equal
283 kX86CondNg = kX86CondLe, // not-greater
284
285 kX86CondNle = 0xF, // not-less-than
286 kX86CondG = kX86CondNle,// greater
287};
288
Ian Rogerse32ca232012-03-05 10:20:23 -0800289/*
Ian Rogersde797832012-03-06 10:18:10 -0800290 * The following enum defines the list of supported X86 instructions by the
291 * assembler. Their corresponding EncodingMap positions will be defined in
292 * Assemble.cc.
Ian Rogerse32ca232012-03-05 10:20:23 -0800293 */
Elliott Hughes719ace42012-03-09 18:06:03 -0800294enum X86OpCode {
Ian Rogerse32ca232012-03-05 10:20:23 -0800295 kPseudoSuspendTarget = -15,
296 kPseudoThrowTarget = -14,
297 kPseudoCaseLabel = -13,
298 kPseudoMethodEntry = -12,
299 kPseudoMethodExit = -11,
300 kPseudoBarrier = -10,
301 kPseudoExtended = -9,
302 kPseudoSSARep = -8,
303 kPseudoEntryBlock = -7,
304 kPseudoExitBlock = -6,
305 kPseudoTargetLabel = -5,
306 kPseudoDalvikByteCodeBoundary = -4,
307 kPseudoPseudoAlign4 = -3,
308 kPseudoEHBlockLabel = -2,
309 kPseudoNormalBlockLabel = -1,
Ian Rogerse32ca232012-03-05 10:20:23 -0800310 kX86First,
Ian Rogers96ab4202012-03-05 19:51:02 -0800311 kX8632BitData = kX86First, /* data [31..0] */
Ian Rogersb5d09b22012-03-06 22:14:17 -0800312 kX86Bkpt,
313 kX86Nop,
Ian Rogersde797832012-03-06 10:18:10 -0800314 // Define groups of binary operations
Ian Rogersb5d09b22012-03-06 22:14:17 -0800315 // MR - Memory Register - opcode [base + disp], reg
316 // - lir operands - 0: base, 1: disp, 2: reg
317 // AR - Array Register - opcode [base + index * scale + disp], reg
318 // - lir operands - 0: base, 1: index, 2: scale, 3: disp, 4: reg
319 // TR - Thread Register - opcode fs:[disp], reg - where fs: is equal to Thread::Current()
320 // - lir operands - 0: disp, 1: reg
Ian Rogersde797832012-03-06 10:18:10 -0800321 // RR - Register Register - opcode reg1, reg2
322 // - lir operands - 0: reg1, 1: reg2
323 // RM - Register Memory - opcode reg, [base + disp]
324 // - lir operands - 0: reg, 1: base, 2: disp
325 // RA - Register Array - opcode reg, [base + index * scale + disp]
326 // - lir operands - 0: reg, 1: base, 2: index, 3: scale, 4: disp
Ian Rogersb5d09b22012-03-06 22:14:17 -0800327 // RT - Register Thread - opcode reg, fs:[disp] - where fs: is equal to Thread::Current()
328 // - lir operands - 0: reg, 1: disp
329 // RI - Register Immediate - opcode reg, #immediate
330 // - lir operands - 0: reg, 1: immediate
331 // MI - Memory Immediate - opcode [base + disp], #immediate
332 // - lir operands - 0: base, 1: disp, 2: immediate
333 // AI - Array Immediate - opcode [base + index * scale + disp], #immediate
334 // - lir operands - 0: base, 1: index, 2: scale, 3: disp 4: immediate
335 // TI - Thread Register - opcode fs:[disp], imm - where fs: is equal to Thread::Current()
336 // - lir operands - 0: disp, 1: imm
Ian Rogers96ab4202012-03-05 19:51:02 -0800337#define BinaryOpCode(opcode) \
Ian Rogersb5d09b22012-03-06 22:14:17 -0800338 opcode ## 8MR, opcode ## 8AR, opcode ## 8TR, \
339 opcode ## 8RR, opcode ## 8RM, opcode ## 8RA, opcode ## 8RT, \
340 opcode ## 8RI, opcode ## 8MI, opcode ## 8AI, opcode ## 8TI, \
341 opcode ## 16MR, opcode ## 16AR, opcode ## 16TR, \
342 opcode ## 16RR, opcode ## 16RM, opcode ## 16RA, opcode ## 16RT, \
343 opcode ## 16RI, opcode ## 16MI, opcode ## 16AI, opcode ## 16TI, \
344 opcode ## 16RI8, opcode ## 16MI8, opcode ## 16AI8, opcode ## 16TI8, \
345 opcode ## 32MR, opcode ## 32AR, opcode ## 32TR, \
346 opcode ## 32RR, opcode ## 32RM, opcode ## 32RA, opcode ## 32RT, \
347 opcode ## 32RI, opcode ## 32MI, opcode ## 32AI, opcode ## 32TI, \
348 opcode ## 32RI8, opcode ## 32MI8, opcode ## 32AI8, opcode ## 32TI8
349 BinaryOpCode(kX86Add),
350 BinaryOpCode(kX86Or),
351 BinaryOpCode(kX86Adc),
352 BinaryOpCode(kX86Sbb),
353 BinaryOpCode(kX86And),
354 BinaryOpCode(kX86Sub),
355 BinaryOpCode(kX86Xor),
356 BinaryOpCode(kX86Cmp),
Ian Rogers96ab4202012-03-05 19:51:02 -0800357#undef BinaryOpCode
Ian Rogersb5d09b22012-03-06 22:14:17 -0800358 kX86Imul16RRI, kX86Imul16RMI, kX86Imul16RAI,
359 kX86Imul32RRI, kX86Imul32RMI, kX86Imul32RAI,
360 kX86Imul32RRI8, kX86Imul32RMI8, kX86Imul32RAI8,
361 kX86Mov8MR, kX86Mov8AR, kX86Mov8TR,
362 kX86Mov8RR, kX86Mov8RM, kX86Mov8RA, kX86Mov8RT,
363 kX86Mov8RI, kX86Mov8MI, kX86Mov8AI, kX86Mov8TI,
364 kX86Mov16MR, kX86Mov16AR, kX86Mov16TR,
365 kX86Mov16RR, kX86Mov16RM, kX86Mov16RA, kX86Mov16RT,
366 kX86Mov16RI, kX86Mov16MI, kX86Mov16AI, kX86Mov16TI,
367 kX86Mov32MR, kX86Mov32AR, kX86Mov32TR,
368 kX86Mov32RR, kX86Mov32RM, kX86Mov32RA, kX86Mov32RT,
369 kX86Mov32RI, kX86Mov32MI, kX86Mov32AI, kX86Mov32TI,
370 kX86Lea32RA,
371 // RC - Register CL - opcode reg, CL
372 // - lir operands - 0: reg, 1: CL
373 // MC - Memory CL - opcode [base + disp], CL
374 // - lir operands - 0: base, 1: disp, 2: CL
375 // AC - Array CL - opcode [base + index * scale + disp], CL
376 // - lir operands - 0: base, 1: index, 2: scale, 3: disp, 4: CL
377#define BinaryShiftOpCode(opcode) \
378 opcode ## 8RI, opcode ## 8MI, opcode ## 8AI, \
379 opcode ## 8RC, opcode ## 8MC, opcode ## 8AC, \
380 opcode ## 16RI, opcode ## 16MI, opcode ## 16AI, \
381 opcode ## 16RC, opcode ## 16MC, opcode ## 16AC, \
382 opcode ## 32RI, opcode ## 32MI, opcode ## 32AI, \
383 opcode ## 32RC, opcode ## 32MC, opcode ## 32AC
384 BinaryShiftOpCode(kX86Rol),
385 BinaryShiftOpCode(kX86Ror),
386 BinaryShiftOpCode(kX86Rcl),
387 BinaryShiftOpCode(kX86Rcr),
388 BinaryShiftOpCode(kX86Sal),
389 BinaryShiftOpCode(kX86Shl),
390 BinaryShiftOpCode(kX86Shr),
391 BinaryShiftOpCode(kX86Sar),
392#undef BinaryShiftOpcode
393#define UnaryOpcode(opcode, reg, mem, array) \
394 opcode ## 8 ## reg, opcode ## 8 ## mem, opcode ## 8 ## array, \
395 opcode ## 16 ## reg, opcode ## 16 ## mem, opcode ## 16 ## array, \
396 opcode ## 32 ## reg, opcode ## 32 ## mem, opcode ## 32 ## array
397 UnaryOpcode(kX86Test, RI, MI, AI),
398 UnaryOpcode(kX86Not, R, M, A),
399 UnaryOpcode(kX86Neg, R, M, A),
400 UnaryOpcode(kX86Mul, DaR, DaM, DaA),
401 UnaryOpcode(kX86Imul, DaR, DaM, DaA),
402 UnaryOpcode(kX86Divmod, DaR, DaM, DaA),
403 UnaryOpcode(kX86Idivmod, DaR, DaM, DaA),
404#undef UnaryOpcode
405#define Binary0fOpCode(opcode) \
406 opcode ## RR, opcode ## RM, opcode ## RA
407 Binary0fOpCode(kX86Movsd),
408 kX86MovsdMR,
409 kX86MovsdAR,
410 Binary0fOpCode(kX86Movss),
411 kX86MovssMR,
412 kX86MovssAR,
413 Binary0fOpCode(kX86Cvtsi2sd), // int to double
414 Binary0fOpCode(kX86Cvtsi2ss), // int to float
415 Binary0fOpCode(kX86Cvttsd2si), // truncating double to int
416 Binary0fOpCode(kX86Cvttss2si), // truncating float to int
417 Binary0fOpCode(kX86Cvtsd2si), // rounding double to int
418 Binary0fOpCode(kX86Cvtss2si), // rounding float to int
419 Binary0fOpCode(kX86Ucomisd), // unordered double compare
420 Binary0fOpCode(kX86Ucomiss), // unordered float compare
421 Binary0fOpCode(kX86Comisd), // double compare
422 Binary0fOpCode(kX86Comiss), // float compare
Ian Rogersb41b33b2012-03-20 14:22:54 -0700423 Binary0fOpCode(kX86Orps), // or of floating point registers
424 Binary0fOpCode(kX86Xorps), // xor of floating point registers
Ian Rogersb5d09b22012-03-06 22:14:17 -0800425 Binary0fOpCode(kX86Addsd), // double add
426 Binary0fOpCode(kX86Addss), // float add
427 Binary0fOpCode(kX86Mulsd), // double multiply
428 Binary0fOpCode(kX86Mulss), // float multiply
429 Binary0fOpCode(kX86Cvtss2sd), // float to double
430 Binary0fOpCode(kX86Cvtsd2ss), // double to float
431 Binary0fOpCode(kX86Subsd), // double subtract
432 Binary0fOpCode(kX86Subss), // float subtract
Ian Rogersb41b33b2012-03-20 14:22:54 -0700433 Binary0fOpCode(kX86Divsd), // double divide
434 Binary0fOpCode(kX86Divss), // float divide
435 kX86PsllqRI, // shift of floating point registers
Ian Rogersb5d09b22012-03-06 22:14:17 -0800436 Binary0fOpCode(kX86Movdxr), // move into xmm from gpr
437 Binary0fOpCode(kX86Movdrx), // move into reg from xmm
438 kX86Set8R, kX86Set8M, kX86Set8A,// set byte depending on condition operand
Ian Rogersc6f3bb82012-03-21 20:40:33 -0700439 kX86Mfence, // memory barrier
Ian Rogersb5d09b22012-03-06 22:14:17 -0800440 Binary0fOpCode(kX86Imul16), // 16bit multiply
441 Binary0fOpCode(kX86Imul32), // 32bit multiply
442 Binary0fOpCode(kX86Movzx8), // zero-extend 8-bit value
443 Binary0fOpCode(kX86Movzx16), // zero-extend 16-bit value
444 Binary0fOpCode(kX86Movsx8), // sign-extend 8-bit value
445 Binary0fOpCode(kX86Movsx16), // sign-extend 16-bit value
446#undef Binary0fOpCode
Ian Rogersb41b33b2012-03-20 14:22:54 -0700447 kX86Jcc8, kX86Jcc32, // jCC rel8/32; lir operands - 0: rel, 1: CC, target assigned
448 kX86Jmp8, kX86Jmp32, // jmp rel8/32; lir operands - 0: rel, target assigned
Ian Rogersb5d09b22012-03-06 22:14:17 -0800449 kX86CallR, // call reg; lir operands - 0: reg
450 kX86CallM, // call [base + disp]; lir operands - 0: base, 1: disp
451 kX86CallA, // call [base + index * scale + disp]
452 // lir operands - 0: base, 1: index, 2: scale, 3: disp
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700453 kX86CallT, // call fs:[disp]; fs: is equal to Thread::Current(); lir operands - 0: disp
Ian Rogersb5d09b22012-03-06 22:14:17 -0800454 kX86Ret, // ret; no lir operands
Ian Rogerse32ca232012-03-05 10:20:23 -0800455 kX86Last
Elliott Hughes719ace42012-03-09 18:06:03 -0800456};
Ian Rogerse32ca232012-03-05 10:20:23 -0800457
Ian Rogersde797832012-03-06 10:18:10 -0800458/* Instruction assembly fieldLoc kind */
Elliott Hughes719ace42012-03-09 18:06:03 -0800459enum X86EncodingKind {
Ian Rogersb5d09b22012-03-06 22:14:17 -0800460 kData, // Special case for raw data.
461 kNop, // Special case for variable length nop.
462 kNullary, // Opcode that takes no arguments.
463 kReg, kMem, kArray, // R, M and A instruction kinds.
464 kMemReg, kArrayReg, kThreadReg, // MR, AR and TR instruction kinds.
465 kRegReg, kRegMem, kRegArray, kRegThread, // RR, RM, RA and RT instruction kinds.
466 kRegImm, kMemImm, kArrayImm, kThreadImm, // RI, MI, AI and TI instruction kinds.
467 kRegRegImm, kRegMemImm, kRegArrayImm, // RRI, RMI and RAI instruction kinds.
468 kMovRegImm, // Shorter form move RI.
469 kShiftRegImm, kShiftMemImm, kShiftArrayImm, // Shift opcode with immediate.
470 kShiftRegCl, kShiftMemCl, kShiftArrayCl, // Shift opcode with register CL.
471 kRegRegReg, kRegRegMem, kRegRegArray, // RRR, RRM, RRA instruction kinds.
472 kRegCond, kMemCond, kArrayCond, // R, M, A instruction kinds following by a condition.
473 kJmp, kJcc, kCall, // Branch instruction kinds.
Ian Rogersde797832012-03-06 10:18:10 -0800474 kUnimplemented // Encoding used when an instruction isn't yet implemented.
Elliott Hughes719ace42012-03-09 18:06:03 -0800475};
Ian Rogersde797832012-03-06 10:18:10 -0800476
Ian Rogersde797832012-03-06 10:18:10 -0800477/* Struct used to define the EncodingMap positions for each X86 opcode */
Elliott Hughes719ace42012-03-09 18:06:03 -0800478struct X86EncodingMap {
Ian Rogersde797832012-03-06 10:18:10 -0800479 X86OpCode opcode; // e.g. kOpAddRI
480 X86EncodingKind kind; // Used to discriminate in the union below
481 int flags;
Ian Rogersb5d09b22012-03-06 22:14:17 -0800482 struct {
483 uint8_t prefix1; // non-zero => a prefix byte
484 uint8_t prefix2; // non-zero => a second prefix byte
485 uint8_t opcode; // 1 byte opcode
486 uint8_t extra_opcode1; // possible extra opcode byte
487 uint8_t extra_opcode2; // possible second extra opcode byte
488 // 3bit opcode that gets encoded in the register bits of the modrm byte, use determined by the
489 // encoding kind
490 uint8_t modrm_opcode;
491 uint8_t ax_opcode; // non-zero => shorter encoding for AX as a destination
492 uint8_t immediate_bytes; // number of bytes of immediate
Ian Rogersde797832012-03-06 10:18:10 -0800493 } skeleton;
494 const char *name;
495 const char* fmt;
Elliott Hughes719ace42012-03-09 18:06:03 -0800496};
Ian Rogersde797832012-03-06 10:18:10 -0800497
498extern X86EncodingMap EncodingMap[kX86Last];
499
buzbeea7678db2012-03-05 15:35:46 -0800500// FIXME: mem barrier type - what do we do for x86?
501#define kSY 0
502#define kST 0
503
Ian Rogerse32ca232012-03-05 10:20:23 -0800504/* Bit flags describing the behavior of each native opcode */
Elliott Hughes719ace42012-03-09 18:06:03 -0800505enum X86OpFeatureFlags {
Ian Rogerse32ca232012-03-05 10:20:23 -0800506 kIsBranch = 0,
507 kRegDef0,
508 kRegDef1,
509 kRegDefSP,
510 kRegDefList0,
511 kRegDefList1,
512 kRegUse0,
513 kRegUse1,
514 kRegUse2,
515 kRegUse3,
516 kRegUseSP,
517 kRegUseList0,
518 kRegUseList1,
519 kNoOperand,
520 kIsUnaryOp,
521 kIsBinaryOp,
522 kIsTertiaryOp,
523 kIsQuadOp,
Ian Rogersb5d09b22012-03-06 22:14:17 -0800524 kIsQuinOp,
525 kIsSextupleOp,
Ian Rogerse32ca232012-03-05 10:20:23 -0800526 kIsIT,
527 kSetsCCodes,
528 kUsesCCodes,
529 kMemLoad,
530 kMemStore,
531 kPCRelFixup,
532// FIXME: add NEEDS_FIXUP to instruction attributes
Elliott Hughes719ace42012-03-09 18:06:03 -0800533};
Ian Rogerse32ca232012-03-05 10:20:23 -0800534
535#define IS_LOAD (1 << kMemLoad)
536#define IS_STORE (1 << kMemStore)
537#define IS_BRANCH (1 << kIsBranch)
538#define REG_DEF0 (1 << kRegDef0)
539#define REG_DEF1 (1 << kRegDef1)
540#define REG_DEF_SP (1 << kRegDefSP)
541#define REG_DEF_LR (1 << kRegDefLR)
542#define REG_DEF_LIST0 (1 << kRegDefList0)
543#define REG_DEF_LIST1 (1 << kRegDefList1)
544#define REG_USE0 (1 << kRegUse0)
545#define REG_USE1 (1 << kRegUse1)
546#define REG_USE2 (1 << kRegUse2)
547#define REG_USE3 (1 << kRegUse3)
548#define REG_USE_SP (1 << kRegUseSP)
549#define REG_USE_PC (1 << kRegUsePC)
550#define REG_USE_LIST0 (1 << kRegUseList0)
551#define REG_USE_LIST1 (1 << kRegUseList1)
552#define NO_OPERAND (1 << kNoOperand)
553#define IS_UNARY_OP (1 << kIsUnaryOp)
554#define IS_BINARY_OP (1 << kIsBinaryOp)
555#define IS_TERTIARY_OP (1 << kIsTertiaryOp)
556#define IS_QUAD_OP (1 << kIsQuadOp)
Ian Rogersb5d09b22012-03-06 22:14:17 -0800557#define IS_QUIN_OP (1 << kIsQuinOp)
558#define IS_SEXTUPLE_OP (1 << kIsSextupleOp)
Ian Rogerse32ca232012-03-05 10:20:23 -0800559#define IS_IT (1 << kIsIT)
560#define SETS_CCODES (1 << kSetsCCodes)
561#define USES_CCODES (1 << kUsesCCodes)
Ian Rogersb5d09b22012-03-06 22:14:17 -0800562#define NEEDS_FIXUP (1 << kPCRelFixup)
Ian Rogerse32ca232012-03-05 10:20:23 -0800563
564/* attributes, included for compatibility */
565#define REG_DEF_FPCS_LIST0 (0)
566#define REG_DEF_FPCS_LIST2 (0)
567
568
569/* Common combo register usage patterns */
570#define REG_USE01 (REG_USE0 | REG_USE1)
571#define REG_USE02 (REG_USE0 | REG_USE2)
572#define REG_USE012 (REG_USE01 | REG_USE2)
573#define REG_USE12 (REG_USE1 | REG_USE2)
574#define REG_USE23 (REG_USE2 | REG_USE3)
575#define REG_DEF01 (REG_DEF0 | REG_DEF1)
576#define REG_DEF0_USE0 (REG_DEF0 | REG_USE0)
577#define REG_DEF0_USE1 (REG_DEF0 | REG_USE1)
578#define REG_DEF0_USE2 (REG_DEF0 | REG_USE2)
579#define REG_DEF0_USE01 (REG_DEF0 | REG_USE01)
580#define REG_DEF0_USE12 (REG_DEF0 | REG_USE12)
581#define REG_DEF01_USE2 (REG_DEF0 | REG_DEF1 | REG_USE2)
582
Ian Rogerse32ca232012-03-05 10:20:23 -0800583/* Keys for target-specific scheduling and other optimization hints */
Elliott Hughes719ace42012-03-09 18:06:03 -0800584enum X86TargetOptHints {
Ian Rogerse32ca232012-03-05 10:20:23 -0800585 kMaxHoistDistance,
Elliott Hughes719ace42012-03-09 18:06:03 -0800586};
Ian Rogerse32ca232012-03-05 10:20:23 -0800587
Ian Rogersb5d09b22012-03-06 22:14:17 -0800588/* Offsets of high and low halves of a 64bit value */
589#define LOWORD_OFFSET 0
590#define HIWORD_OFFSET 4
591
592/* Segment override instruction prefix used for quick TLS access to Thread::Current() */
593#define THREAD_PREFIX 0x64
Ian Rogerse32ca232012-03-05 10:20:23 -0800594
Ian Rogersde797832012-03-06 10:18:10 -0800595#define IS_SIMM8(v) ((-128 <= (v)) && ((v) <= 127))
Ian Rogersb5d09b22012-03-06 22:14:17 -0800596#define IS_SIMM16(v) ((-32768 <= (v)) && ((v) <= 32767))
Ian Rogerse32ca232012-03-05 10:20:23 -0800597
598} // namespace art
599
600#endif // ART_COMPILER_COMPILER_CODEGEN_X86_X86LIR_H_