blob: c80533399844c5c166170e0e542b6d150505b1c7 [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.
35 * For these reasons we aim to match native conventions for caller and callee save
36 *
37 * General Purpose Register:
38 * Native: x86 | x86-64 / x32 | ART
39 * r0/eax: caller save | caller save | caller, Method*, scratch, return value
40 * r1/ecx: caller save | caller save, arg4 | caller, arg2, scratch
41 * r2/edx: caller save | caller save, arg3 | caller, arg1, scratch, high half of long return
42 * r3/ebx: callee save | callee save | callee, available for dalvik register promotion
43 * r4/esp: stack pointer
44 * r5/ebp: callee save | callee save | callee, available for dalvik register promotion
45 * r6/esi: callEE save | callER save, arg2 | callee, available for dalvik register promotion
46 * r7/edi: callEE save | callER save, arg1 | callee, available for dalvik register promotion
47 * --- x86-64/x32 registers
48 * Native: x86-64 / x32 | ART
49 * r8: caller save, arg5 | caller, scratch
50 * r9: caller save, arg6 | caller, scratch
51 * r10: caller save | caller, scratch
52 * r11: caller save | caller, scratch
53 * r12: callee save | callee, available for dalvik register promotion
54 * r13: callee save | callee, available for dalvik register promotion
55 * r14: callee save | callee, available for dalvik register promotion
56 * r15: callee save | callee, available for dalvik register promotion
57 *
58 * There is no rSELF, instead on x86 fs: has a base address of Thread::Current, whereas on
59 * x86-64/x32 gs: holds it.
60 *
61 * For floating point we don't support CPUs without SSE2 support (ie newer than PIII):
62 * Native: x86 | x86-64 / x32 | ART
63 * XMM0: caller save |caller save, arg1 | caller, float/double return value (except for native x86 code)
64 * XMM1: caller save |caller save, arg2 | caller, scratch
65 * XMM2: caller save |caller save, arg3 | caller, scratch
66 * XMM3: caller save |caller save, arg4 | caller, scratch
67 * XMM4: caller save |caller save, arg5 | caller, scratch
68 * XMM5: caller save |caller save, arg6 | caller, scratch
69 * XMM6: caller save |caller save, arg7 | caller, scratch
70 * XMM7: caller save |caller save, arg8 | caller, scratch
71 * --- x86-64/x32 registers
72 * XMM8 .. 15: caller save
73 *
74 * X87 is a necessary evil outside of ART code:
75 * ST0: x86 float/double native return value, caller save
76 * ST1 .. ST7: caller save
77 *
78 * Stack frame diagram (stack grows down, higher addresses at top):
79 *
80 * +------------------------+
81 * | IN[ins-1] | {Note: resides in caller's frame}
82 * | . |
83 * | IN[0] |
84 * | caller's Method* |
85 * +========================+ {Note: start of callee's frame}
86 * | return address | {pushed by call}
87 * | spill region | {variable sized}
88 * +------------------------+
89 * | ...filler word... | {Note: used as 2nd word of V[locals-1] if long]
90 * +------------------------+
91 * | V[locals-1] |
92 * | V[locals-2] |
93 * | . |
94 * | . |
95 * | V[1] |
96 * | V[0] |
97 * +------------------------+
98 * | 0 to 3 words padding |
99 * +------------------------+
100 * | OUT[outs-1] |
101 * | OUT[outs-2] |
102 * | . |
103 * | OUT[0] |
104 * | curMethod* | <<== sp w/ 16-byte alignment
105 * +========================+
106 */
107
108/* Offset to distingish FP regs */
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700109#define FP_REG_OFFSET 32
Ian Rogerse32ca232012-03-05 10:20:23 -0800110/* Offset to distinguish DP FP regs */
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700111#define FP_DOUBLE (FP_REG_OFFSET + 16)
Ian Rogerse32ca232012-03-05 10:20:23 -0800112/* Offset to distingish the extra regs */
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700113#define EXTRA_REG_OFFSET (FP_DOUBLE + 16)
Ian Rogerse32ca232012-03-05 10:20:23 -0800114/* Reg types */
115#define REGTYPE(x) (x & (FP_REG_OFFSET | FP_DOUBLE))
116#define FPREG(x) ((x & FP_REG_OFFSET) == FP_REG_OFFSET)
117#define EXTRAREG(x) ((x & EXTRA_REG_OFFSET) == EXTRA_REG_OFFSET)
118#define LOWREG(x) ((x & 0x1f) == x)
119#define DOUBLEREG(x) ((x & FP_DOUBLE) == FP_DOUBLE)
120#define SINGLEREG(x) (FPREG(x) && !DOUBLEREG(x))
Ian Rogersb5d09b22012-03-06 22:14:17 -0800121
Ian Rogerse32ca232012-03-05 10:20:23 -0800122/*
123 * Note: the low register of a floating point pair is sufficient to
124 * create the name of a double, but require both names to be passed to
125 * allow for asserts to verify that the pair is consecutive if significant
126 * rework is done in this area. Also, it is a good reminder in the calling
127 * code that reg locations always describe doubles as a pair of singles.
128 */
129#define S2D(x,y) ((x) | FP_DOUBLE)
130/* Mask to strip off fp flags */
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700131#define FP_REG_MASK 0xF
Ian Rogerse32ca232012-03-05 10:20:23 -0800132/* non-existent Dalvik register */
133#define vNone (-1)
134/* non-existant physical register */
135#define rNone (-1)
136
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700137/* RegisterLocation templates return values (rAX, rAX/rDX or XMM0) */
138// location, wide, defined, fp, core, highWord, home, lowReg, highReg, sRegLow
139#define LOC_C_RETURN {kLocPhysReg, 0, 0, 0, 0, 0, 1, rAX, INVALID_REG, INVALID_SREG}
140#define LOC_C_RETURN_WIDE {kLocPhysReg, 1, 0, 0, 0, 0, 1, rAX, rDX, INVALID_SREG}
141#define LOC_C_RETURN_FLOAT {kLocPhysReg, 0, 0, 1, 0, 0, 1, fr0, INVALID_REG, INVALID_SREG}
142#define LOC_C_RETURN_WIDE_DOUBLE {kLocPhysReg, 1, 0, 1, 0, 0, 1, fr0, fr1, INVALID_SREG}
Ian Rogerse32ca232012-03-05 10:20:23 -0800143
Elliott Hughes719ace42012-03-09 18:06:03 -0800144enum ResourceEncodingPos {
Ian Rogerse32ca232012-03-05 10:20:23 -0800145 kGPReg0 = 0,
146 kRegSP = 4,
147 kRegLR = -1,
148 kFPReg0 = 16, // xmm0 .. xmm7/xmm15
149 kFPRegEnd = 32,
150 kRegEnd = kFPRegEnd,
151 kCCode = kRegEnd,
152 // The following four bits are for memory disambiguation
153 kDalvikReg, // 1 Dalvik Frame (can be fully disambiguated)
154 kLiteral, // 2 Literal pool (can be fully disambiguated)
155 kHeapRef, // 3 Somewhere on the heap (alias with any other heap)
156 kMustNotAlias, // 4 Guaranteed to be non-alias (eg *(r6+x))
Elliott Hughes719ace42012-03-09 18:06:03 -0800157};
Ian Rogerse32ca232012-03-05 10:20:23 -0800158
159#define ENCODE_REG_LIST(N) ((u8) N)
160#define ENCODE_REG_SP (1ULL << kRegSP)
161#define ENCODE_CCODE (1ULL << kCCode)
162#define ENCODE_FP_STATUS (1ULL << kFPStatus)
163
164/* Abstract memory locations */
165#define ENCODE_DALVIK_REG (1ULL << kDalvikReg)
166#define ENCODE_LITERAL (1ULL << kLiteral)
167#define ENCODE_HEAP_REF (1ULL << kHeapRef)
168#define ENCODE_MUST_NOT_ALIAS (1ULL << kMustNotAlias)
169
170#define ENCODE_ALL (~0ULL)
171#define ENCODE_MEM (ENCODE_DALVIK_REG | ENCODE_LITERAL | \
172 ENCODE_HEAP_REF | ENCODE_MUST_NOT_ALIAS)
173
174#define DECODE_ALIAS_INFO_REG(X) (X & 0xffff)
175#define DECODE_ALIAS_INFO_WIDE(X) ((X & 0x80000000) ? 1 : 0)
176
177/*
178 * Annotate special-purpose core registers:
179 */
180
Elliott Hughes719ace42012-03-09 18:06:03 -0800181enum NativeRegisterPool {
Ian Rogerse32ca232012-03-05 10:20:23 -0800182 r0 = 0,
Ian Rogersb5d09b22012-03-06 22:14:17 -0800183 rAX = r0,
Ian Rogerse32ca232012-03-05 10:20:23 -0800184 r1 = 1,
Ian Rogersb5d09b22012-03-06 22:14:17 -0800185 rCX = r1,
Ian Rogerse32ca232012-03-05 10:20:23 -0800186 r2 = 2,
187 rDX = r2,
188 r3 = 3,
189 rBX = r3,
190 r4sp = 4,
Ian Rogersb5d09b22012-03-06 22:14:17 -0800191 rSP = r4sp,
192 r4sib_no_index = r4sp,
Ian Rogerse32ca232012-03-05 10:20:23 -0800193 r5 = 5,
194 rBP = r5,
195 r6 = 6,
196 rSI = r6,
197 r7 = 7,
198 rDI = r7,
199 r8 = 8,
200 r9 = 9,
201 r10 = 10,
202 r11 = 11,
203 r12 = 12,
204 r13 = 13,
205 r14 = 14,
206 r15 = 15,
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700207 rRET = 16, // fake return address register for core spill mask
Ian Rogerse32ca232012-03-05 10:20:23 -0800208 fr0 = 0 + FP_REG_OFFSET,
209 fr1 = 1 + FP_REG_OFFSET,
210 fr2 = 2 + FP_REG_OFFSET,
211 fr3 = 3 + FP_REG_OFFSET,
212 fr4 = 4 + FP_REG_OFFSET,
213 fr5 = 5 + FP_REG_OFFSET,
214 fr6 = 6 + FP_REG_OFFSET,
215 fr7 = 7 + FP_REG_OFFSET,
216 fr8 = 8 + FP_REG_OFFSET,
217 fr9 = 9 + FP_REG_OFFSET,
218 fr10 = 10 + FP_REG_OFFSET,
219 fr11 = 11 + FP_REG_OFFSET,
220 fr12 = 12 + FP_REG_OFFSET,
221 fr13 = 13 + FP_REG_OFFSET,
222 fr14 = 14 + FP_REG_OFFSET,
223 fr15 = 15 + FP_REG_OFFSET,
Elliott Hughes719ace42012-03-09 18:06:03 -0800224};
Ian Rogerse32ca232012-03-05 10:20:23 -0800225
226/*
227 * Target-independent aliases
228 */
229
230#define rARG0 rAX
231#define rARG1 rDX
232#define rARG2 rCX
233#define rRET0 rAX
234#define rRET1 rDX
235
236#define isPseudoOpcode(opCode) ((int)(opCode) < 0)
237
Ian Rogersb5d09b22012-03-06 22:14:17 -0800238/* X86 condition encodings */
239enum X86ConditionCode {
240 kX86CondO = 0x0, // overflow
241 kX86CondNo = 0x1, // not overflow
242
243 kX86CondB = 0x2, // below
244 kX86CondNae = kX86CondB, // not-above-equal
245 kX86CondC = kX86CondB, // carry
246
247 kX86CondNb = 0x3, // not-below
248 kX86CondAe = kX86CondNb, // above-equal
249 kX86CondNc = kX86CondNb, // not-carry
250
251 kX86CondZ = 0x4, // zero
252 kX86CondEq = kX86CondZ, // equal
253
254 kX86CondNz = 0x5, // not-zero
255 kX86CondNe = kX86CondNz, // not-equal
256
257 kX86CondBe = 0x6, // below-equal
258 kX86CondNa = kX86CondBe, // not-above
259
260 kX86CondNbe = 0x7, // not-below-equal
261 kX86CondA = kX86CondNbe,// above
262
263 kX86CondS = 0x8, // sign
264 kX86CondNs = 0x9, // not-sign
265
266 kX86CondP = 0xA, // 8-bit parity even
267 kX86CondPE = kX86CondP,
268
269 kX86CondNp = 0xB, // 8-bit parity odd
270 kX86CondPo = kX86CondNp,
271
272 kX86CondL = 0xC, // less-than
273 kX86CondNge = kX86CondL, // not-greater-equal
274
275 kX86CondNl = 0xD, // not-less-than
276 kX86CondGe = kX86CondL, // not-greater-equal
277
278 kX86CondLe = 0xE, // less-than-equal
279 kX86CondNg = kX86CondLe, // not-greater
280
281 kX86CondNle = 0xF, // not-less-than
282 kX86CondG = kX86CondNle,// greater
283};
284
Ian Rogerse32ca232012-03-05 10:20:23 -0800285/*
Ian Rogersde797832012-03-06 10:18:10 -0800286 * The following enum defines the list of supported X86 instructions by the
287 * assembler. Their corresponding EncodingMap positions will be defined in
288 * Assemble.cc.
Ian Rogerse32ca232012-03-05 10:20:23 -0800289 */
Elliott Hughes719ace42012-03-09 18:06:03 -0800290enum X86OpCode {
Ian Rogerse32ca232012-03-05 10:20:23 -0800291 kPseudoSuspendTarget = -15,
292 kPseudoThrowTarget = -14,
293 kPseudoCaseLabel = -13,
294 kPseudoMethodEntry = -12,
295 kPseudoMethodExit = -11,
296 kPseudoBarrier = -10,
297 kPseudoExtended = -9,
298 kPseudoSSARep = -8,
299 kPseudoEntryBlock = -7,
300 kPseudoExitBlock = -6,
301 kPseudoTargetLabel = -5,
302 kPseudoDalvikByteCodeBoundary = -4,
303 kPseudoPseudoAlign4 = -3,
304 kPseudoEHBlockLabel = -2,
305 kPseudoNormalBlockLabel = -1,
Ian Rogerse32ca232012-03-05 10:20:23 -0800306 kX86First,
Ian Rogers96ab4202012-03-05 19:51:02 -0800307 kX8632BitData = kX86First, /* data [31..0] */
Ian Rogersb5d09b22012-03-06 22:14:17 -0800308 kX86Bkpt,
309 kX86Nop,
Ian Rogersde797832012-03-06 10:18:10 -0800310 // Define groups of binary operations
Ian Rogersb5d09b22012-03-06 22:14:17 -0800311 // MR - Memory Register - opcode [base + disp], reg
312 // - lir operands - 0: base, 1: disp, 2: reg
313 // AR - Array Register - opcode [base + index * scale + disp], reg
314 // - lir operands - 0: base, 1: index, 2: scale, 3: disp, 4: reg
315 // TR - Thread Register - opcode fs:[disp], reg - where fs: is equal to Thread::Current()
316 // - lir operands - 0: disp, 1: reg
Ian Rogersde797832012-03-06 10:18:10 -0800317 // RR - Register Register - opcode reg1, reg2
318 // - lir operands - 0: reg1, 1: reg2
319 // RM - Register Memory - opcode reg, [base + disp]
320 // - lir operands - 0: reg, 1: base, 2: disp
321 // RA - Register Array - opcode reg, [base + index * scale + disp]
322 // - lir operands - 0: reg, 1: base, 2: index, 3: scale, 4: disp
Ian Rogersb5d09b22012-03-06 22:14:17 -0800323 // RT - Register Thread - opcode reg, fs:[disp] - where fs: is equal to Thread::Current()
324 // - lir operands - 0: reg, 1: disp
325 // RI - Register Immediate - opcode reg, #immediate
326 // - lir operands - 0: reg, 1: immediate
327 // MI - Memory Immediate - opcode [base + disp], #immediate
328 // - lir operands - 0: base, 1: disp, 2: immediate
329 // AI - Array Immediate - opcode [base + index * scale + disp], #immediate
330 // - lir operands - 0: base, 1: index, 2: scale, 3: disp 4: immediate
331 // TI - Thread Register - opcode fs:[disp], imm - where fs: is equal to Thread::Current()
332 // - lir operands - 0: disp, 1: imm
Ian Rogers96ab4202012-03-05 19:51:02 -0800333#define BinaryOpCode(opcode) \
Ian Rogersb5d09b22012-03-06 22:14:17 -0800334 opcode ## 8MR, opcode ## 8AR, opcode ## 8TR, \
335 opcode ## 8RR, opcode ## 8RM, opcode ## 8RA, opcode ## 8RT, \
336 opcode ## 8RI, opcode ## 8MI, opcode ## 8AI, opcode ## 8TI, \
337 opcode ## 16MR, opcode ## 16AR, opcode ## 16TR, \
338 opcode ## 16RR, opcode ## 16RM, opcode ## 16RA, opcode ## 16RT, \
339 opcode ## 16RI, opcode ## 16MI, opcode ## 16AI, opcode ## 16TI, \
340 opcode ## 16RI8, opcode ## 16MI8, opcode ## 16AI8, opcode ## 16TI8, \
341 opcode ## 32MR, opcode ## 32AR, opcode ## 32TR, \
342 opcode ## 32RR, opcode ## 32RM, opcode ## 32RA, opcode ## 32RT, \
343 opcode ## 32RI, opcode ## 32MI, opcode ## 32AI, opcode ## 32TI, \
344 opcode ## 32RI8, opcode ## 32MI8, opcode ## 32AI8, opcode ## 32TI8
345 BinaryOpCode(kX86Add),
346 BinaryOpCode(kX86Or),
347 BinaryOpCode(kX86Adc),
348 BinaryOpCode(kX86Sbb),
349 BinaryOpCode(kX86And),
350 BinaryOpCode(kX86Sub),
351 BinaryOpCode(kX86Xor),
352 BinaryOpCode(kX86Cmp),
Ian Rogers96ab4202012-03-05 19:51:02 -0800353#undef BinaryOpCode
Ian Rogersb5d09b22012-03-06 22:14:17 -0800354 kX86Imul16RRI, kX86Imul16RMI, kX86Imul16RAI,
355 kX86Imul32RRI, kX86Imul32RMI, kX86Imul32RAI,
356 kX86Imul32RRI8, kX86Imul32RMI8, kX86Imul32RAI8,
357 kX86Mov8MR, kX86Mov8AR, kX86Mov8TR,
358 kX86Mov8RR, kX86Mov8RM, kX86Mov8RA, kX86Mov8RT,
359 kX86Mov8RI, kX86Mov8MI, kX86Mov8AI, kX86Mov8TI,
360 kX86Mov16MR, kX86Mov16AR, kX86Mov16TR,
361 kX86Mov16RR, kX86Mov16RM, kX86Mov16RA, kX86Mov16RT,
362 kX86Mov16RI, kX86Mov16MI, kX86Mov16AI, kX86Mov16TI,
363 kX86Mov32MR, kX86Mov32AR, kX86Mov32TR,
364 kX86Mov32RR, kX86Mov32RM, kX86Mov32RA, kX86Mov32RT,
365 kX86Mov32RI, kX86Mov32MI, kX86Mov32AI, kX86Mov32TI,
366 kX86Lea32RA,
367 // RC - Register CL - opcode reg, CL
368 // - lir operands - 0: reg, 1: CL
369 // MC - Memory CL - opcode [base + disp], CL
370 // - lir operands - 0: base, 1: disp, 2: CL
371 // AC - Array CL - opcode [base + index * scale + disp], CL
372 // - lir operands - 0: base, 1: index, 2: scale, 3: disp, 4: CL
373#define BinaryShiftOpCode(opcode) \
374 opcode ## 8RI, opcode ## 8MI, opcode ## 8AI, \
375 opcode ## 8RC, opcode ## 8MC, opcode ## 8AC, \
376 opcode ## 16RI, opcode ## 16MI, opcode ## 16AI, \
377 opcode ## 16RC, opcode ## 16MC, opcode ## 16AC, \
378 opcode ## 32RI, opcode ## 32MI, opcode ## 32AI, \
379 opcode ## 32RC, opcode ## 32MC, opcode ## 32AC
380 BinaryShiftOpCode(kX86Rol),
381 BinaryShiftOpCode(kX86Ror),
382 BinaryShiftOpCode(kX86Rcl),
383 BinaryShiftOpCode(kX86Rcr),
384 BinaryShiftOpCode(kX86Sal),
385 BinaryShiftOpCode(kX86Shl),
386 BinaryShiftOpCode(kX86Shr),
387 BinaryShiftOpCode(kX86Sar),
388#undef BinaryShiftOpcode
389#define UnaryOpcode(opcode, reg, mem, array) \
390 opcode ## 8 ## reg, opcode ## 8 ## mem, opcode ## 8 ## array, \
391 opcode ## 16 ## reg, opcode ## 16 ## mem, opcode ## 16 ## array, \
392 opcode ## 32 ## reg, opcode ## 32 ## mem, opcode ## 32 ## array
393 UnaryOpcode(kX86Test, RI, MI, AI),
394 UnaryOpcode(kX86Not, R, M, A),
395 UnaryOpcode(kX86Neg, R, M, A),
396 UnaryOpcode(kX86Mul, DaR, DaM, DaA),
397 UnaryOpcode(kX86Imul, DaR, DaM, DaA),
398 UnaryOpcode(kX86Divmod, DaR, DaM, DaA),
399 UnaryOpcode(kX86Idivmod, DaR, DaM, DaA),
400#undef UnaryOpcode
401#define Binary0fOpCode(opcode) \
402 opcode ## RR, opcode ## RM, opcode ## RA
403 Binary0fOpCode(kX86Movsd),
404 kX86MovsdMR,
405 kX86MovsdAR,
406 Binary0fOpCode(kX86Movss),
407 kX86MovssMR,
408 kX86MovssAR,
409 Binary0fOpCode(kX86Cvtsi2sd), // int to double
410 Binary0fOpCode(kX86Cvtsi2ss), // int to float
411 Binary0fOpCode(kX86Cvttsd2si), // truncating double to int
412 Binary0fOpCode(kX86Cvttss2si), // truncating float to int
413 Binary0fOpCode(kX86Cvtsd2si), // rounding double to int
414 Binary0fOpCode(kX86Cvtss2si), // rounding float to int
415 Binary0fOpCode(kX86Ucomisd), // unordered double compare
416 Binary0fOpCode(kX86Ucomiss), // unordered float compare
417 Binary0fOpCode(kX86Comisd), // double compare
418 Binary0fOpCode(kX86Comiss), // float compare
419 Binary0fOpCode(kX86Addsd), // double add
420 Binary0fOpCode(kX86Addss), // float add
421 Binary0fOpCode(kX86Mulsd), // double multiply
422 Binary0fOpCode(kX86Mulss), // float multiply
423 Binary0fOpCode(kX86Cvtss2sd), // float to double
424 Binary0fOpCode(kX86Cvtsd2ss), // double to float
425 Binary0fOpCode(kX86Subsd), // double subtract
426 Binary0fOpCode(kX86Subss), // float subtract
427 Binary0fOpCode(kX86Divsd), // double subtract
428 Binary0fOpCode(kX86Divss), // float subtract
429 Binary0fOpCode(kX86Movdxr), // move into xmm from gpr
430 Binary0fOpCode(kX86Movdrx), // move into reg from xmm
431 kX86Set8R, kX86Set8M, kX86Set8A,// set byte depending on condition operand
432 Binary0fOpCode(kX86Imul16), // 16bit multiply
433 Binary0fOpCode(kX86Imul32), // 32bit multiply
434 Binary0fOpCode(kX86Movzx8), // zero-extend 8-bit value
435 Binary0fOpCode(kX86Movzx16), // zero-extend 16-bit value
436 Binary0fOpCode(kX86Movsx8), // sign-extend 8-bit value
437 Binary0fOpCode(kX86Movsx16), // sign-extend 16-bit value
438#undef Binary0fOpCode
439 kX86Jcc, // jCC rel; lir operands - 0: rel, 1: CC, target assigned
440 kX86Jmp, // jmp rel; lir operands - 0: rel, target assigned
441 kX86CallR, // call reg; lir operands - 0: reg
442 kX86CallM, // call [base + disp]; lir operands - 0: base, 1: disp
443 kX86CallA, // call [base + index * scale + disp]
444 // lir operands - 0: base, 1: index, 2: scale, 3: disp
445 kX86Ret, // ret; no lir operands
Ian Rogerse32ca232012-03-05 10:20:23 -0800446 kX86Last
Elliott Hughes719ace42012-03-09 18:06:03 -0800447};
Ian Rogerse32ca232012-03-05 10:20:23 -0800448
Ian Rogersde797832012-03-06 10:18:10 -0800449/* Instruction assembly fieldLoc kind */
Elliott Hughes719ace42012-03-09 18:06:03 -0800450enum X86EncodingKind {
Ian Rogersb5d09b22012-03-06 22:14:17 -0800451 kData, // Special case for raw data.
452 kNop, // Special case for variable length nop.
453 kNullary, // Opcode that takes no arguments.
454 kReg, kMem, kArray, // R, M and A instruction kinds.
455 kMemReg, kArrayReg, kThreadReg, // MR, AR and TR instruction kinds.
456 kRegReg, kRegMem, kRegArray, kRegThread, // RR, RM, RA and RT instruction kinds.
457 kRegImm, kMemImm, kArrayImm, kThreadImm, // RI, MI, AI and TI instruction kinds.
458 kRegRegImm, kRegMemImm, kRegArrayImm, // RRI, RMI and RAI instruction kinds.
459 kMovRegImm, // Shorter form move RI.
460 kShiftRegImm, kShiftMemImm, kShiftArrayImm, // Shift opcode with immediate.
461 kShiftRegCl, kShiftMemCl, kShiftArrayCl, // Shift opcode with register CL.
462 kRegRegReg, kRegRegMem, kRegRegArray, // RRR, RRM, RRA instruction kinds.
463 kRegCond, kMemCond, kArrayCond, // R, M, A instruction kinds following by a condition.
464 kJmp, kJcc, kCall, // Branch instruction kinds.
Ian Rogersde797832012-03-06 10:18:10 -0800465 kUnimplemented // Encoding used when an instruction isn't yet implemented.
Elliott Hughes719ace42012-03-09 18:06:03 -0800466};
Ian Rogersde797832012-03-06 10:18:10 -0800467
Ian Rogersde797832012-03-06 10:18:10 -0800468/* Struct used to define the EncodingMap positions for each X86 opcode */
Elliott Hughes719ace42012-03-09 18:06:03 -0800469struct X86EncodingMap {
Ian Rogersde797832012-03-06 10:18:10 -0800470 X86OpCode opcode; // e.g. kOpAddRI
471 X86EncodingKind kind; // Used to discriminate in the union below
472 int flags;
Ian Rogersb5d09b22012-03-06 22:14:17 -0800473 struct {
474 uint8_t prefix1; // non-zero => a prefix byte
475 uint8_t prefix2; // non-zero => a second prefix byte
476 uint8_t opcode; // 1 byte opcode
477 uint8_t extra_opcode1; // possible extra opcode byte
478 uint8_t extra_opcode2; // possible second extra opcode byte
479 // 3bit opcode that gets encoded in the register bits of the modrm byte, use determined by the
480 // encoding kind
481 uint8_t modrm_opcode;
482 uint8_t ax_opcode; // non-zero => shorter encoding for AX as a destination
483 uint8_t immediate_bytes; // number of bytes of immediate
Ian Rogersde797832012-03-06 10:18:10 -0800484 } skeleton;
485 const char *name;
486 const char* fmt;
Elliott Hughes719ace42012-03-09 18:06:03 -0800487};
Ian Rogersde797832012-03-06 10:18:10 -0800488
489extern X86EncodingMap EncodingMap[kX86Last];
490
buzbeea7678db2012-03-05 15:35:46 -0800491// FIXME: mem barrier type - what do we do for x86?
492#define kSY 0
493#define kST 0
494
Ian Rogerse32ca232012-03-05 10:20:23 -0800495/* Bit flags describing the behavior of each native opcode */
Elliott Hughes719ace42012-03-09 18:06:03 -0800496enum X86OpFeatureFlags {
Ian Rogerse32ca232012-03-05 10:20:23 -0800497 kIsBranch = 0,
498 kRegDef0,
499 kRegDef1,
500 kRegDefSP,
501 kRegDefList0,
502 kRegDefList1,
503 kRegUse0,
504 kRegUse1,
505 kRegUse2,
506 kRegUse3,
507 kRegUseSP,
508 kRegUseList0,
509 kRegUseList1,
510 kNoOperand,
511 kIsUnaryOp,
512 kIsBinaryOp,
513 kIsTertiaryOp,
514 kIsQuadOp,
Ian Rogersb5d09b22012-03-06 22:14:17 -0800515 kIsQuinOp,
516 kIsSextupleOp,
Ian Rogerse32ca232012-03-05 10:20:23 -0800517 kIsIT,
518 kSetsCCodes,
519 kUsesCCodes,
520 kMemLoad,
521 kMemStore,
522 kPCRelFixup,
523// FIXME: add NEEDS_FIXUP to instruction attributes
Elliott Hughes719ace42012-03-09 18:06:03 -0800524};
Ian Rogerse32ca232012-03-05 10:20:23 -0800525
526#define IS_LOAD (1 << kMemLoad)
527#define IS_STORE (1 << kMemStore)
528#define IS_BRANCH (1 << kIsBranch)
529#define REG_DEF0 (1 << kRegDef0)
530#define REG_DEF1 (1 << kRegDef1)
531#define REG_DEF_SP (1 << kRegDefSP)
532#define REG_DEF_LR (1 << kRegDefLR)
533#define REG_DEF_LIST0 (1 << kRegDefList0)
534#define REG_DEF_LIST1 (1 << kRegDefList1)
535#define REG_USE0 (1 << kRegUse0)
536#define REG_USE1 (1 << kRegUse1)
537#define REG_USE2 (1 << kRegUse2)
538#define REG_USE3 (1 << kRegUse3)
539#define REG_USE_SP (1 << kRegUseSP)
540#define REG_USE_PC (1 << kRegUsePC)
541#define REG_USE_LIST0 (1 << kRegUseList0)
542#define REG_USE_LIST1 (1 << kRegUseList1)
543#define NO_OPERAND (1 << kNoOperand)
544#define IS_UNARY_OP (1 << kIsUnaryOp)
545#define IS_BINARY_OP (1 << kIsBinaryOp)
546#define IS_TERTIARY_OP (1 << kIsTertiaryOp)
547#define IS_QUAD_OP (1 << kIsQuadOp)
Ian Rogersb5d09b22012-03-06 22:14:17 -0800548#define IS_QUIN_OP (1 << kIsQuinOp)
549#define IS_SEXTUPLE_OP (1 << kIsSextupleOp)
Ian Rogerse32ca232012-03-05 10:20:23 -0800550#define IS_IT (1 << kIsIT)
551#define SETS_CCODES (1 << kSetsCCodes)
552#define USES_CCODES (1 << kUsesCCodes)
Ian Rogersb5d09b22012-03-06 22:14:17 -0800553#define NEEDS_FIXUP (1 << kPCRelFixup)
Ian Rogerse32ca232012-03-05 10:20:23 -0800554
555/* attributes, included for compatibility */
556#define REG_DEF_FPCS_LIST0 (0)
557#define REG_DEF_FPCS_LIST2 (0)
558
559
560/* Common combo register usage patterns */
561#define REG_USE01 (REG_USE0 | REG_USE1)
562#define REG_USE02 (REG_USE0 | REG_USE2)
563#define REG_USE012 (REG_USE01 | REG_USE2)
564#define REG_USE12 (REG_USE1 | REG_USE2)
565#define REG_USE23 (REG_USE2 | REG_USE3)
566#define REG_DEF01 (REG_DEF0 | REG_DEF1)
567#define REG_DEF0_USE0 (REG_DEF0 | REG_USE0)
568#define REG_DEF0_USE1 (REG_DEF0 | REG_USE1)
569#define REG_DEF0_USE2 (REG_DEF0 | REG_USE2)
570#define REG_DEF0_USE01 (REG_DEF0 | REG_USE01)
571#define REG_DEF0_USE12 (REG_DEF0 | REG_USE12)
572#define REG_DEF01_USE2 (REG_DEF0 | REG_DEF1 | REG_USE2)
573
Ian Rogerse32ca232012-03-05 10:20:23 -0800574/* Keys for target-specific scheduling and other optimization hints */
Elliott Hughes719ace42012-03-09 18:06:03 -0800575enum X86TargetOptHints {
Ian Rogerse32ca232012-03-05 10:20:23 -0800576 kMaxHoistDistance,
Elliott Hughes719ace42012-03-09 18:06:03 -0800577};
Ian Rogerse32ca232012-03-05 10:20:23 -0800578
Ian Rogersb5d09b22012-03-06 22:14:17 -0800579/* Offsets of high and low halves of a 64bit value */
580#define LOWORD_OFFSET 0
581#define HIWORD_OFFSET 4
582
583/* Segment override instruction prefix used for quick TLS access to Thread::Current() */
584#define THREAD_PREFIX 0x64
Ian Rogerse32ca232012-03-05 10:20:23 -0800585
Ian Rogersde797832012-03-06 10:18:10 -0800586#define IS_SIMM8(v) ((-128 <= (v)) && ((v) <= 127))
Ian Rogersb5d09b22012-03-06 22:14:17 -0800587#define IS_SIMM16(v) ((-32768 <= (v)) && ((v) <= 32767))
Ian Rogerse32ca232012-03-05 10:20:23 -0800588
589} // namespace art
590
591#endif // ART_COMPILER_COMPILER_CODEGEN_X86_X86LIR_H_