-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
targetx86.h
353 lines (276 loc) · 16.5 KB
/
targetx86.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#pragma once
#if !defined(TARGET_X86)
#error The file should not be included for this platform.
#endif
// clang-format off
#define CPU_LOAD_STORE_ARCH 0
#define ROUND_FLOAT 1 // round intermed float expression results
#define CPU_HAS_BYTE_REGS 1
#define CPOBJ_NONGC_SLOTS_LIMIT 4 // For CpObj code generation, this is the threshold of the number
// of contiguous non-gc slots that trigger generating rep movsq instead of
// sequences of movsq instructions
#ifdef FEATURE_SIMD
#define ALIGN_SIMD_TYPES 1 // whether SIMD type locals are to be aligned
#endif // FEATURE_SIMD
#define FEATURE_FIXED_OUT_ARGS 0 // X86 uses push instructions to pass args
#define FEATURE_STRUCTPROMOTE 1 // JIT Optimization to promote fields of structs into registers
#define FEATURE_MULTIREG_STRUCT_PROMOTE 0 // True when we want to promote fields of a multireg struct into registers
#define FEATURE_FASTTAILCALL 0 // Tail calls made as epilog+jmp
#define FEATURE_TAILCALL_OPT 0 // opportunistic Tail calls (without ".tail" prefix) made as fast tail calls.
#define FEATURE_SET_FLAGS 0 // Set to true to force the JIT to mark the trees with GTF_SET_FLAGS when
// the flags need to be set
#define FEATURE_IMPLICIT_BYREFS 0 // Support for struct parameters passed via pointers to shadow copies
#define FEATURE_MULTIREG_ARGS_OR_RET 1 // Support for passing and/or returning single values in more than one register
#define FEATURE_MULTIREG_ARGS 0 // Support for passing a single argument in more than one register
#define FEATURE_MULTIREG_RET 1 // Support for returning a single value in more than one register
#define MAX_PASS_SINGLEREG_BYTES 8 // Maximum size of a struct passed in a single register (double).
#define MAX_PASS_MULTIREG_BYTES 0 // No multireg arguments
#define MAX_RET_MULTIREG_BYTES 8 // Maximum size of a struct that could be returned in more than one register
#define MAX_ARG_REG_COUNT 1 // Maximum registers used to pass an argument.
#define MAX_RET_REG_COUNT 2 // Maximum registers used to return a value.
#define MAX_MULTIREG_COUNT 2 // Maximum number of registers defined by a single instruction (including calls).
// This is also the maximum number of registers for a MultiReg node.
#ifdef FEATURE_USE_ASM_GC_WRITE_BARRIERS
#define NOGC_WRITE_BARRIERS 1 // We have specialized WriteBarrier JIT Helpers that DO-NOT trash the
// RBM_CALLEE_TRASH registers
#else
#define NOGC_WRITE_BARRIERS 0 // Do not modify this -- modify the definition above. (If we're not using
// ASM barriers we definitely don't have NOGC barriers).
#endif
#define USER_ARGS_COME_LAST 0
#define EMIT_TRACK_STACK_DEPTH 1
#define TARGET_POINTER_SIZE 4 // equal to sizeof(void*) and the managed pointer size in bytes for this
// target
#define FEATURE_EH 1 // To aid platform bring-up, eliminate exceptional EH clauses (catch, filter,
// filter-handler, fault) and directly execute 'finally' clauses.
#define FEATURE_EH_CALLFINALLY_THUNKS 0 // Generate call-to-finally code in "thunks" in the enclosing EH region,
// protected by "cloned finally" clauses.
#define ETW_EBP_FRAMED 1 // if 1 we cannot use EBP as a scratch register and must create EBP based
// frames for most methods
#define CSE_CONSTS 1 // Enable if we want to CSE constants
// The following defines are useful for iterating a regNumber
#define REG_FIRST REG_EAX
#define REG_INT_FIRST REG_EAX
#define REG_INT_LAST REG_EDI
#define REG_INT_COUNT (REG_INT_LAST - REG_INT_FIRST + 1)
#define REG_NEXT(reg) ((regNumber)((unsigned)(reg) + 1))
#define REG_PREV(reg) ((regNumber)((unsigned)(reg) - 1))
#define REG_FP_FIRST REG_XMM0
#define REG_FP_LAST REG_XMM7
#define REG_MASK_FIRST REG_K0
#define REG_MASK_LAST REG_K7
#define CNT_MASK_REGS 8
#define FIRST_FP_ARGREG REG_XMM0
#define LAST_FP_ARGREG REG_XMM3
#define REG_FLTARG_0 REG_XMM0
#define REG_FLTARG_1 REG_XMM1
#define REG_FLTARG_2 REG_XMM2
#define REG_FLTARG_3 REG_XMM3
#define RBM_FLTARG_0 RBM_XMM0
#define RBM_FLTARG_1 RBM_XMM1
#define RBM_FLTARG_2 RBM_XMM2
#define RBM_FLTARG_3 RBM_XMM3
#define RBM_FLTARG_REGS (RBM_FLTARG_0|RBM_FLTARG_1|RBM_FLTARG_2|RBM_FLTARG_3)
#define RBM_ALLFLOAT (RBM_XMM0 | RBM_XMM1 | RBM_XMM2 | RBM_XMM3 | RBM_XMM4 | RBM_XMM5 | RBM_XMM6 | RBM_XMM7)
#define RBM_ALLDOUBLE RBM_ALLFLOAT
#if !defined(UNIX_X86_ABI)
#define RBM_ALLMASK REG_K1
#else
#define RBM_ALLMASK (0)
#endif
#define CNT_HIGHFLOAT 0
// TODO-CQ: Currently we are following the x86 ABI for SSE2 registers.
// This should be reconsidered.
#define RBM_FLT_CALLEE_SAVED RBM_NONE
#define RBM_FLT_CALLEE_TRASH RBM_ALLFLOAT
#define REG_VAR_ORDER_FLT REG_XMM0, REG_XMM1, REG_XMM2, REG_XMM3, REG_XMM4, REG_XMM5, REG_XMM6, REG_XMM7
#define REG_FLT_CALLEE_SAVED_FIRST REG_XMM6
#define REG_FLT_CALLEE_SAVED_LAST REG_XMM7
#define RBM_MSK_CALLEE_SAVED (0)
#define RBM_MSK_CALLEE_TRASH RBM_ALLMASK
#define XMM_REGSIZE_BYTES 16 // XMM register size in bytes
#define YMM_REGSIZE_BYTES 32 // YMM register size in bytes
#define ZMM_REGSIZE_BYTES 64 // ZMM register size in bytes
#define REGNUM_BITS 6 // number of bits in a REG_*
#define REGSIZE_BYTES 4 // number of bytes in one register
#define MIN_ARG_AREA_FOR_CALL 0 // Minimum required outgoing argument space for a call.
#define CODE_ALIGN 1 // code alignment requirement
#if !defined(UNIX_X86_ABI)
#define STACK_ALIGN 4 // stack alignment requirement
#define STACK_ALIGN_SHIFT 2 // Shift-right amount to convert size in bytes to size in STACK_ALIGN units == log2(STACK_ALIGN)
#else
#define STACK_ALIGN 16 // stack alignment requirement
#define STACK_ALIGN_SHIFT 4 // Shift-right amount to convert size in bytes to size in STACK_ALIGN units == log2(STACK_ALIGN)
#endif // !UNIX_X86_ABI
#define RBM_INT_CALLEE_SAVED (RBM_EBX|RBM_ESI|RBM_EDI)
#define RBM_INT_CALLEE_TRASH (RBM_EAX|RBM_ECX|RBM_EDX)
// TODO-AVX512: Add RBM_MSK_CALLEE_*
#define RBM_CALLEE_SAVED (RBM_INT_CALLEE_SAVED | RBM_FLT_CALLEE_SAVED)
#define RBM_CALLEE_TRASH (RBM_INT_CALLEE_TRASH | RBM_FLT_CALLEE_TRASH)
#define RBM_ALLINT (RBM_INT_CALLEE_SAVED | RBM_INT_CALLEE_TRASH)
#define REG_VAR_ORDER REG_EAX,REG_EDX,REG_ECX,REG_ESI,REG_EDI,REG_EBX
#define MAX_VAR_ORDER_SIZE 6
// The order here is fixed: it must agree with an order assumed in eetwain...
#define REG_CALLEE_SAVED_ORDER REG_EDI,REG_ESI,REG_EBX,REG_EBP
#define RBM_CALLEE_SAVED_ORDER RBM_EDI,RBM_ESI,RBM_EBX,RBM_EBP
#define CNT_CALLEE_SAVED (4)
#define CNT_CALLEE_TRASH (3)
#define CNT_CALLEE_ENREG (CNT_CALLEE_SAVED-1)
#define CNT_CALLEE_SAVED_FLOAT (0)
#define CNT_CALLEE_TRASH_FLOAT (6)
#define CALLEE_SAVED_REG_MAXSZ (CNT_CALLEE_SAVED*REGSIZE_BYTES) // EBX,ESI,EDI,EBP
#define REG_LNGARG_LO REG_EAX
#define RBM_LNGARG_LO RBM_EAX
#define REG_LNGARG_HI REG_EDX
#define RBM_LNGARG_HI RBM_EDX
// register to hold shift amount
#define REG_SHIFT REG_ECX
#define RBM_SHIFT RBM_ECX
// register to hold shift amount when shifting 64-bit values
#define REG_SHIFT_LNG REG_ECX
#define RBM_SHIFT_LNG RBM_ECX
// This is a general scratch register that does not conflict with the argument registers
#define REG_SCRATCH REG_EAX
// Where is the exception object on entry to the handler block?
#define REG_EXCEPTION_OBJECT REG_EAX
#define RBM_EXCEPTION_OBJECT RBM_EAX
// Only used on ARM for GTF_CALL_M_VIRTSTUB_REL_INDIRECT
#define REG_JUMP_THUNK_PARAM REG_EAX
#define RBM_JUMP_THUNK_PARAM RBM_EAX
#define REG_R2R_INDIRECT_PARAM REG_EAX // Indirection cell for R2R fast tailcall, not currently used in x86.
#define RBM_R2R_INDIRECT_PARAM RBM_EAX
// x86 write barrier ABI (see vm\i386\jithelp.asm, vm\i386\jithelp.S):
// CORINFO_HELP_ASSIGN_REF (JIT_WriteBarrier), CORINFO_HELP_CHECKED_ASSIGN_REF (JIT_CheckedWriteBarrier):
// On entry:
// edx: the destination address (object reference written here)
// For optimized write barriers, one of eax, ecx, ebx, esi, or edi contains the source (object to write).
// (There is a separate write barrier for each of these source options.)
// On exit:
// edx: trashed
// CORINFO_HELP_ASSIGN_BYREF (JIT_ByRefWriteBarrier):
// On entry:
// esi: the source address (points to object reference to write)
// edi: the destination address (object reference written here)
// On exit:
// ecx: trashed
// edi: incremented by 8
// esi: incremented by 8
//
#define REG_WRITE_BARRIER_DST REG_ARG_0
#define RBM_WRITE_BARRIER_DST RBM_ARG_0
#define REG_WRITE_BARRIER_SRC REG_ARG_1
#define RBM_WRITE_BARRIER_SRC RBM_ARG_1
#if NOGC_WRITE_BARRIERS
#define REG_OPTIMIZED_WRITE_BARRIER_DST REG_EDX
#define RBM_OPTIMIZED_WRITE_BARRIER_DST RBM_EDX
// We don't allow using ebp as a source register. Maybe we should only prevent this for ETW_EBP_FRAMED
// (but that is always set right now).
#define RBM_OPTIMIZED_WRITE_BARRIER_SRC (RBM_EAX|RBM_ECX|RBM_EBX|RBM_ESI|RBM_EDI)
#endif // NOGC_WRITE_BARRIERS
#define RBM_CALLEE_TRASH_NOGC RBM_EDX
// Registers killed by CORINFO_HELP_ASSIGN_REF and CORINFO_HELP_CHECKED_ASSIGN_REF.
// Note that x86 normally emits an optimized (source-register-specific) write barrier, but can emit
// a call to a "general" write barrier.
CLANG_FORMAT_COMMENT_ANCHOR;
#ifdef FEATURE_USE_ASM_GC_WRITE_BARRIERS
#define RBM_CALLEE_TRASH_WRITEBARRIER (RBM_EAX | RBM_EDX)
#else // !FEATURE_USE_ASM_GC_WRITE_BARRIERS
#define RBM_CALLEE_TRASH_WRITEBARRIER RBM_CALLEE_TRASH
#endif // !FEATURE_USE_ASM_GC_WRITE_BARRIERS
// Registers no longer containing GC pointers after CORINFO_HELP_ASSIGN_REF and CORINFO_HELP_CHECKED_ASSIGN_REF.
#define RBM_CALLEE_GCTRASH_WRITEBARRIER RBM_EDX
// Registers killed by CORINFO_HELP_ASSIGN_BYREF.
#define RBM_CALLEE_TRASH_WRITEBARRIER_BYREF (RBM_ESI | RBM_EDI | RBM_ECX)
// Registers no longer containing GC pointers after CORINFO_HELP_ASSIGN_BYREF.
// Note that RDI and RSI are still valid byref pointers after this helper call, despite their value being changed.
#define RBM_CALLEE_GCTRASH_WRITEBARRIER_BYREF RBM_ECX
// GenericPInvokeCalliHelper unmanaged target parameter
#define REG_PINVOKE_TARGET_PARAM REG_EAX
#define RBM_PINVOKE_TARGET_PARAM RBM_EAX
// GenericPInvokeCalliHelper cookie parameter
#define REG_PINVOKE_COOKIE_PARAM REG_EBX
// IL stub's secret parameter (JitFlags::JIT_FLAG_PUBLISH_SECRET_PARAM)
#define REG_SECRET_STUB_PARAM REG_EAX
#define RBM_SECRET_STUB_PARAM RBM_EAX
// VSD target address register
#define REG_VIRTUAL_STUB_TARGET REG_EAX
#define RBM_VIRTUAL_STUB_TARGET RBM_EAX
// Registers used by PInvoke frame setup
#define REG_PINVOKE_FRAME REG_EDI // EDI is p/invoke "Frame" pointer argument to CORINFO_HELP_INIT_PINVOKE_FRAME helper
#define RBM_PINVOKE_FRAME RBM_EDI
#define REG_PINVOKE_TCB REG_ESI // ESI is set to Thread Control Block (TCB) on return from
// CORINFO_HELP_INIT_PINVOKE_FRAME helper
#define RBM_PINVOKE_TCB RBM_ESI
#define REG_PINVOKE_SCRATCH REG_EAX // EAX is trashed by CORINFO_HELP_INIT_PINVOKE_FRAME helper
#define RBM_PINVOKE_SCRATCH RBM_EAX
// The following defines are useful for iterating a regNumber
#define REG_FIRST REG_EAX
#define REG_INT_FIRST REG_EAX
#define REG_INT_LAST REG_EDI
#define REG_INT_COUNT (REG_INT_LAST - REG_INT_FIRST + 1)
#define REG_NEXT(reg) ((regNumber)((unsigned)(reg) + 1))
#define REG_PREV(reg) ((regNumber)((unsigned)(reg) - 1))
// Which register are int and long values returned in ?
#define REG_INTRET REG_EAX
#define RBM_INTRET RBM_EAX
#define RBM_LNGRET (RBM_EDX|RBM_EAX)
#define REG_LNGRET_LO REG_EAX
#define RBM_LNGRET_LO RBM_EAX
#define REG_LNGRET_HI REG_EDX
#define RBM_LNGRET_HI RBM_EDX
#define REG_FLOATRET REG_NA
#define RBM_FLOATRET RBM_NONE
#define RBM_DOUBLERET RBM_NONE
// The registers trashed by the CORINFO_HELP_STOP_FOR_GC helper
#define RBM_STOP_FOR_GC_TRASH RBM_CALLEE_TRASH
// The registers trashed by the CORINFO_HELP_INIT_PINVOKE_FRAME helper. On x86, this helper has a custom calling
// convention that takes EDI as argument (but doesn't trash it), trashes EAX, and returns ESI.
#define RBM_INIT_PINVOKE_FRAME_TRASH (RBM_PINVOKE_SCRATCH | RBM_PINVOKE_TCB)
#define RBM_VALIDATE_INDIRECT_CALL_TRASH (RBM_INT_CALLEE_TRASH & ~RBM_ECX)
#define REG_VALIDATE_INDIRECT_CALL_ADDR REG_ECX
#define REG_FPBASE REG_EBP
#define RBM_FPBASE RBM_EBP
#define STR_FPBASE "ebp"
#define REG_SPBASE REG_ESP
#define RBM_SPBASE RBM_ESP
#define STR_SPBASE "esp"
#define FIRST_ARG_STACK_OFFS (2*REGSIZE_BYTES) // Caller's saved EBP and return address
#define MAX_REG_ARG 2
#define MAX_FLOAT_REG_ARG 0
#define REG_ARG_FIRST REG_ECX
#define REG_ARG_LAST REG_EDX
#define INIT_ARG_STACK_SLOT 0 // No outgoing reserved stack slots
#define REG_ARG_0 REG_ECX
#define REG_ARG_1 REG_EDX
extern const regNumber intArgRegs [MAX_REG_ARG];
extern const regMaskTP intArgMasks[MAX_REG_ARG];
#define RBM_ARG_0 RBM_ECX
#define RBM_ARG_1 RBM_EDX
#define RBM_ARG_REGS (RBM_ARG_0|RBM_ARG_1)
// The registers trashed by profiler enter/leave/tailcall hook
// See vm\i386\asmhelpers.asm for more details.
#define RBM_PROFILER_ENTER_TRASH RBM_NONE
#define RBM_PROFILER_LEAVE_TRASH RBM_NONE
#define RBM_PROFILER_TAILCALL_TRASH (RBM_CALLEE_TRASH & ~RBM_ARG_REGS)
// What sort of reloc do we use for [disp32] address mode
#define IMAGE_REL_BASED_DISP32 IMAGE_REL_BASED_HIGHLOW
// What sort of reloc to we use for 'moffset' address mode (for 'mov eax, moffset' or 'mov moffset, eax')
#define IMAGE_REL_BASED_MOFFSET IMAGE_REL_BASED_HIGHLOW
// Pointer-sized string move instructions
#define INS_movsp INS_movsd
#define INS_r_movsp INS_r_movsd
#define INS_stosp INS_stosd
#define INS_r_stosp INS_r_stosd
// Any stack pointer adjustments larger than this (in bytes) when setting up outgoing call arguments
// requires a stack probe. Set it large enough so all normal stack arguments don't get a probe.
#define ARG_STACK_PROBE_THRESHOLD_BYTES 1024
// The number of bytes from the end the last probed page that must also be probed, to allow for some
// small SP adjustments without probes. If zero, then the stack pointer can point to the last byte/word
// on the stack guard page, and must be touched before any further "SUB SP".
#define STACK_PROBE_BOUNDARY_THRESHOLD_BYTES ARG_STACK_PROBE_THRESHOLD_BYTES
#define REG_STACK_PROBE_HELPER_ARG REG_EAX
#define RBM_STACK_PROBE_HELPER_ARG RBM_EAX
#define RBM_STACK_PROBE_HELPER_TRASH RBM_NONE
// clang-format on