AArch64: Improve costing of ctz
[official-gcc.git] / gcc / config / i386 / darwin.h
blobbf9c45d70bb0249a7e178be2f39510cf77ec2b4d
1 /* Target definitions for x86 running Darwin.
2 Copyright (C) 2001-2024 Free Software Foundation, Inc.
3 Contributed by Apple Computer Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* Enable Mach-O bits in generic x86 code. */
22 #undef TARGET_MACHO
23 #define TARGET_MACHO 1
25 #undef DARWIN_X86
26 #define DARWIN_X86 1
28 /* Size of the Obj-C jump buffer. */
29 #define OBJC_JBLEN ((TARGET_64BIT) ? ((9 * 2) + 3 + 16) : (18))
31 #undef TARGET_FPMATH_DEFAULT
32 #define TARGET_FPMATH_DEFAULT (TARGET_SSE ? FPMATH_SSE : FPMATH_387)
33 #undef TARGET_FPMATH_DEFAULT_P
34 #define TARGET_FPMATH_DEFAULT_P(x) \
35 (TARGET_SSE_P(x) ? FPMATH_SSE : FPMATH_387)
37 #define TARGET_OS_CPP_BUILTINS() \
38 do { \
39 builtin_define ("__LITTLE_ENDIAN__"); \
40 darwin_cpp_builtins (pfile); \
41 } while (0)
43 #undef PTRDIFF_TYPE
44 #define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int")
46 #undef WCHAR_TYPE
47 #define WCHAR_TYPE "int"
49 #undef WCHAR_TYPE_SIZE
50 #define WCHAR_TYPE_SIZE 32
52 /* Generate pic symbol indirection stubs if this is true. */
53 #undef TARGET_MACHO_SYMBOL_STUBS
54 #define TARGET_MACHO_SYMBOL_STUBS (darwin_symbol_stubs)
56 /* For compatibility with OSX system tools, use the new style of pic stub
57 if this is set (default). */
58 #undef MACHOPIC_ATT_STUB
59 #define MACHOPIC_ATT_STUB (darwin_macho_att_stub)
61 #undef MAX_BITS_PER_WORD
62 #define MAX_BITS_PER_WORD 64
64 #undef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
65 #define FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN (0)
67 #undef TARGET_KEEPS_VECTOR_ALIGNED_STACK
68 #define TARGET_KEEPS_VECTOR_ALIGNED_STACK 1
70 /* On Darwin, the stack is 128-bit aligned at the point of every call.
71 Failure to ensure this will lead to a crash in the system libraries
72 or dynamic loader. */
74 #undef MAIN_STACK_BOUNDARY
75 #define MAIN_STACK_BOUNDARY 128
77 /* Since we'll never want a stack boundary less aligned than 128 bits
78 we need the extra work here otherwise bits of gcc get very grumpy
79 when we ask for lower alignment. We could just reject values less
80 than 128 bits for Darwin, but it's easier to up the alignment if
81 it's below the minimum. */
82 #undef PREFERRED_STACK_BOUNDARY
83 #define PREFERRED_STACK_BOUNDARY \
84 MAX (128, ix86_preferred_stack_boundary)
86 /* We want -fPIC by default, unless we're using -static to compile for
87 the kernel or some such. */
89 #undef CC1_SPEC
90 #define CC1_SPEC "%(cc1_cpu) \
91 %{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}} \
92 %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }} \
93 %{mx32:%eDarwin is not an mx32 platform} \
94 %{mfentry*:%eDarwin does not support -mfentry or associated options}" \
95 DARWIN_CC1_SPEC
97 /* This is a workaround for a tool bug: see PR100340. */
99 #ifdef HAVE_AS_MLLVM_X86_PAD_FOR_ALIGN
100 #define EXTRA_ASM_OPTS " -mllvm -x86-pad-for-align=false "
101 #else
102 #define EXTRA_ASM_OPTS ""
103 #endif
105 #undef ASM_SPEC
106 #define ASM_SPEC \
107 "%{static} -arch %(darwin_arch) " \
108 ASM_OPTIONS ASM_MMACOSX_VERSION_MIN_SPEC EXTRA_ASM_OPTS \
109 "%{!force_cpusubtype_ALL:-force_cpusubtype_ALL} "
111 #undef ENDFILE_SPEC
112 #define ENDFILE_SPEC \
113 "%{mdaz-ftz:crtfastmath.o%s;Ofast|ffast-math|funsafe-math-optimizations:%{!shared:%{!mno-daz-ftz:crtfastmath.o%s}}} \
114 %{mpc32:crtprec32.o%s} \
115 %{mpc64:crtprec64.o%s} \
116 %{mpc80:crtprec80.o%s}" TM_DESTRUCTOR
118 #ifndef DARWIN_ARCH_SPEC
119 /* We default to x86_64 for single-arch builds, bi-arch overrides. */
120 #define DARWIN_ARCH_SPEC "x86_64"
121 #define DARWIN_SUBARCH_SPEC DARWIN_ARCH_SPEC
122 #endif
124 #undef DARWIN_HEAP_T_LIB
125 #define DARWIN_HEAP_T_LIB " -lheapt_w "
127 #undef SUBTARGET_EXTRA_SPECS
128 #define SUBTARGET_EXTRA_SPECS \
129 DARWIN_EXTRA_SPECS \
130 { "darwin_arch", DARWIN_ARCH_SPEC }, \
131 { "darwin_crt2", "" }, \
132 { "darwin_subarch", DARWIN_ARCH_SPEC },
134 /* The Darwin assembler mostly follows AT&T syntax. */
135 #undef ASSEMBLER_DIALECT
136 #define ASSEMBLER_DIALECT ASM_ATT
138 /* Define macro used to output shift-double opcodes when the shift
139 count is in %cl. Some assemblers require %cl as an argument;
140 some don't. This macro controls what to do: by default, don't
141 print %cl. */
143 #define SHIFT_DOUBLE_OMITS_COUNT 0
145 #undef TARGET_ASM_FILE_END
146 #define TARGET_ASM_FILE_END darwin_file_end
148 /* Define the syntax of pseudo-ops, labels and comments. */
150 /* String containing the assembler's comment-starter. */
152 #define ASM_COMMENT_START "#"
154 /* By default, target has a 80387, uses IEEE compatible arithmetic,
155 and returns float values in the 387. */
157 #undef TARGET_SUBTARGET_DEFAULT
158 #define TARGET_SUBTARGET_DEFAULT \
159 (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_128BIT_LONG_DOUBLE)
161 /* For darwin we want to target specific processor features as a minimum,
162 but these unfortunately don't correspond to a specific processor. */
163 #undef TARGET_SUBTARGET32_ISA_DEFAULT
164 #define TARGET_SUBTARGET32_ISA_DEFAULT \
165 (OPTION_MASK_ISA_MMX | OPTION_MASK_ISA_SSE \
166 | OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE3)
168 #undef TARGET_SUBTARGET64_ISA_DEFAULT
169 #define TARGET_SUBTARGET64_ISA_DEFAULT TARGET_SUBTARGET32_ISA_DEFAULT
171 #undef GOT_SYMBOL_NAME
172 #define GOT_SYMBOL_NAME MACHOPIC_FUNCTION_BASE_NAME
174 /* Define the syntax of pseudo-ops, labels and comments. */
176 #define LPREFIX "L"
178 /* Assembler pseudos to introduce constants of various size. */
180 #define ASM_BYTE "\t.byte\t"
181 #define ASM_SHORT "\t.word\t"
182 #define ASM_LONG "\t.long\t"
183 #define ASM_QUAD "\t.quad\t"
185 #define SUBTARGET_ENCODE_SECTION_INFO darwin_encode_section_info
187 #undef ASM_OUTPUT_ALIGN
188 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
189 do { \
190 if ((LOG) != 0) \
192 if (in_section == text_section) \
193 fprintf (FILE, "\t%s %d,0x90\n", ALIGN_ASM_OP, (LOG)); \
194 else \
195 fprintf (FILE, "\t%s %d\n", ALIGN_ASM_OP, (LOG)); \
197 } while (0)
199 /* Darwin x86 assemblers support the .ident directive. */
201 #undef TARGET_ASM_OUTPUT_IDENT
202 #define TARGET_ASM_OUTPUT_IDENT default_asm_output_ident_directive
204 /* We always want jump tables in the text section:
205 * for PIC code, we need the subtracted symbol to be defined at
206 assembly-time.
207 * for mdynamic-no-pic, we cannot support jump tables in the .const
208 section for weak functions, this looks to ld64 like direct access
209 to the weak symbol from an anonymous atom. */
211 #undef JUMP_TABLES_IN_TEXT_SECTION
212 #define JUMP_TABLES_IN_TEXT_SECTION 1
214 /* Darwin profiling -- call mcount.
215 If we need a stub, then we unconditionally mark it as used. */
216 #undef FUNCTION_PROFILER
217 #define FUNCTION_PROFILER(FILE, LABELNO) \
218 do { \
219 if (TARGET_MACHO_SYMBOL_STUBS \
220 && MACHOPIC_INDIRECT && !TARGET_64BIT) \
222 const char *name = machopic_mcount_stub_name (); \
223 fprintf (FILE, "\tcall %s\n", name+1); /* skip '&' */ \
225 else fprintf (FILE, "\tcall mcount\n"); \
226 } while (0)
228 #define C_COMMON_OVERRIDE_OPTIONS \
229 do { \
230 SUBTARGET_C_COMMON_OVERRIDE_OPTIONS; \
231 } while (0)
233 #undef SUBTARGET_OVERRIDE_OPTIONS
234 #define SUBTARGET_OVERRIDE_OPTIONS \
235 do { \
236 if (TARGET_64BIT && MACHO_DYNAMIC_NO_PIC_P) \
237 target_flags &= ~MASK_MACHO_DYNAMIC_NO_PIC; \
238 } while (0)
240 /* Darwin uses the standard DWARF register numbers but the default
241 register numbers for STABS. Fortunately for 64-bit code the
242 default and the standard are the same. */
243 #undef DEBUGGER_REGNO
244 #define DEBUGGER_REGNO(n) \
245 (TARGET_64BIT ? debugger64_register_map[n] \
246 : dwarf_debuginfo_p () ? svr4_debugger_register_map[n] \
247 : debugger_register_map[n])
249 /* Unfortunately, the 32-bit EH information also doesn't use the standard
250 DWARF register numbers. */
251 #define DWARF2_FRAME_REG_OUT(n, for_eh) \
252 (! (for_eh) || !dwarf_debuginfo_p () || TARGET_64BIT ? (n) \
253 : (n) == 5 ? 4 \
254 : (n) == 4 ? 5 \
255 : (n) >= 11 && (n) <= 18 ? (n) + 1 \
256 : (n))
258 #undef REGISTER_SUBTARGET_PRAGMAS
259 #define REGISTER_SUBTARGET_PRAGMAS() DARWIN_REGISTER_TARGET_PRAGMAS()
261 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
262 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES darwin_set_default_type_attributes
264 /* For 64-bit, we need to add 4 because @GOTPCREL is relative to the
265 end of the instruction, but without the 4 we'd only have the right
266 address for the start of the instruction. */
267 #undef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
268 #define ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX(FILE, ENCODING, SIZE, ADDR, DONE) \
269 if (TARGET_64BIT) \
271 if ((SIZE) == 4 && ((ENCODING) & 0x70) == DW_EH_PE_pcrel) \
273 fputs (ASM_LONG, FILE); \
274 assemble_name (FILE, XSTR (ADDR, 0)); \
275 fputs ("+4@GOTPCREL", FILE); \
276 goto DONE; \
279 else \
281 if (ENCODING == ASM_PREFERRED_EH_DATA_FORMAT (2, 1)) \
283 darwin_non_lazy_pcrel (FILE, ADDR); \
284 goto DONE; \
288 /* First available SYMBOL flag bit for use by subtargets. */
289 #define SYMBOL_FLAG_SUBT_DEP (SYMBOL_FLAG_MACH_DEP << 5)
291 #undef MACHOPIC_NL_SYMBOL_PTR_SECTION
292 #define MACHOPIC_NL_SYMBOL_PTR_SECTION \
293 ".section __IMPORT,__pointers,non_lazy_symbol_pointers"
295 #define SUBTARGET32_DEFAULT_CPU "i686"
297 #undef SUBTARGET_INIT_BUILTINS
298 #define SUBTARGET_INIT_BUILTINS \
299 do { \
300 ix86_builtins[(int) IX86_BUILTIN_CFSTRING] \
301 = darwin_init_cfstring_builtins ((unsigned) (IX86_BUILTIN_CFSTRING)); \
302 darwin_rename_builtins (); \
303 } while(0)
305 /* Define the shadow offset for asan. */
306 #undef SUBTARGET_SHADOW_OFFSET
307 #define SUBTARGET_SHADOW_OFFSET \
308 (TARGET_LP64 ? HOST_WIDE_INT_1 << 44 : HOST_WIDE_INT_1 << 29)
310 #undef CLEAR_INSN_CACHE
311 #define CLEAR_INSN_CACHE(beg, end) \
312 extern void sys_icache_invalidate(void *start, size_t len); \
313 sys_icache_invalidate ((beg), (size_t)((end)-(beg)))
315 /* Disable custom function descriptors for Darwin when we have off-stack
316 trampolines. */
317 #undef X86_CUSTOM_FUNCTION_TEST
318 #define X86_CUSTOM_FUNCTION_TEST \
319 (flag_trampolines && flag_trampoline_impl == TRAMPOLINE_IMPL_HEAP) ? 0 : 1