1 /* Subroutines used for macro/preprocessor support on the ia-32.
2 Copyright (C) 2008, 2009, 2010
3 Free Software Foundation, 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)
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/>. */
23 #include "coretypes.h"
28 #include "c-family/c-common.h"
31 #include "target-def.h"
33 #include "c-family/c-pragma.h"
35 static bool ix86_pragma_target_parse (tree, tree);
36 static void ix86_target_macros_internal
37 (int, enum processor_type, enum processor_type, enum fpmath_unit,
38 void (*def_or_undef) (cpp_reader *, const char *));
41 /* Internal function to either define or undef the appropriate system
44 ix86_target_macros_internal (int isa_flag,
45 enum processor_type arch,
46 enum processor_type tune,
47 enum fpmath_unit fpmath,
48 void (*def_or_undef) (cpp_reader *,
51 /* For some of the k6/pentium varients there weren't seperate ISA bits to
52 identify which tune/arch flag was passed, so figure it out here. */
53 size_t arch_len = strlen (ix86_arch_string);
54 size_t tune_len = strlen (ix86_tune_string);
55 int last_arch_char = ix86_arch_string[arch_len - 1];
56 int last_tune_char = ix86_tune_string[tune_len - 1];
58 /* Built-ins based on -march=. */
64 def_or_undef (parse_in, "__i486");
65 def_or_undef (parse_in, "__i486__");
67 case PROCESSOR_PENTIUM:
68 def_or_undef (parse_in, "__i586");
69 def_or_undef (parse_in, "__i586__");
70 def_or_undef (parse_in, "__pentium");
71 def_or_undef (parse_in, "__pentium__");
72 if (isa_flag & OPTION_MASK_ISA_MMX)
73 def_or_undef (parse_in, "__pentium_mmx__");
75 case PROCESSOR_PENTIUMPRO:
76 def_or_undef (parse_in, "__i686");
77 def_or_undef (parse_in, "__i686__");
78 def_or_undef (parse_in, "__pentiumpro");
79 def_or_undef (parse_in, "__pentiumpro__");
82 def_or_undef (parse_in, "__geode");
83 def_or_undef (parse_in, "__geode__");
86 def_or_undef (parse_in, "__k6");
87 def_or_undef (parse_in, "__k6__");
88 if (last_arch_char == '2')
89 def_or_undef (parse_in, "__k6_2__");
90 else if (last_arch_char == '3')
91 def_or_undef (parse_in, "__k6_3__");
92 else if (isa_flag & OPTION_MASK_ISA_3DNOW)
93 def_or_undef (parse_in, "__k6_3__");
95 case PROCESSOR_ATHLON:
96 def_or_undef (parse_in, "__athlon");
97 def_or_undef (parse_in, "__athlon__");
98 if (isa_flag & OPTION_MASK_ISA_SSE)
99 def_or_undef (parse_in, "__athlon_sse__");
102 def_or_undef (parse_in, "__k8");
103 def_or_undef (parse_in, "__k8__");
105 case PROCESSOR_AMDFAM10:
106 def_or_undef (parse_in, "__amdfam10");
107 def_or_undef (parse_in, "__amdfam10__");
109 case PROCESSOR_BDVER1:
110 def_or_undef (parse_in, "__bdver1");
111 def_or_undef (parse_in, "__bdver1__");
113 case PROCESSOR_PENTIUM4:
114 def_or_undef (parse_in, "__pentium4");
115 def_or_undef (parse_in, "__pentium4__");
117 case PROCESSOR_NOCONA:
118 def_or_undef (parse_in, "__nocona");
119 def_or_undef (parse_in, "__nocona__");
121 case PROCESSOR_CORE2:
122 def_or_undef (parse_in, "__core2");
123 def_or_undef (parse_in, "__core2__");
125 case PROCESSOR_COREI7_32:
126 case PROCESSOR_COREI7_64:
127 def_or_undef (parse_in, "__corei7");
128 def_or_undef (parse_in, "__corei7__");
131 def_or_undef (parse_in, "__atom");
132 def_or_undef (parse_in, "__atom__");
134 /* use PROCESSOR_max to not set/unset the arch macro. */
137 case PROCESSOR_GENERIC32:
138 case PROCESSOR_GENERIC64:
142 /* Built-ins based on -mtune=. */
146 def_or_undef (parse_in, "__tune_i386__");
149 def_or_undef (parse_in, "__tune_i486__");
151 case PROCESSOR_PENTIUM:
152 def_or_undef (parse_in, "__tune_i586__");
153 def_or_undef (parse_in, "__tune_pentium__");
154 if (last_tune_char == 'x')
155 def_or_undef (parse_in, "__tune_pentium_mmx__");
157 case PROCESSOR_PENTIUMPRO:
158 def_or_undef (parse_in, "__tune_i686__");
159 def_or_undef (parse_in, "__tune_pentiumpro__");
160 switch (last_tune_char)
163 def_or_undef (parse_in, "__tune_pentium3__");
166 def_or_undef (parse_in, "__tune_pentium2__");
170 case PROCESSOR_GEODE:
171 def_or_undef (parse_in, "__tune_geode__");
174 def_or_undef (parse_in, "__tune_k6__");
175 if (last_tune_char == '2')
176 def_or_undef (parse_in, "__tune_k6_2__");
177 else if (last_tune_char == '3')
178 def_or_undef (parse_in, "__tune_k6_3__");
179 else if (isa_flag & OPTION_MASK_ISA_3DNOW)
180 def_or_undef (parse_in, "__tune_k6_3__");
182 case PROCESSOR_ATHLON:
183 def_or_undef (parse_in, "__tune_athlon__");
184 if (isa_flag & OPTION_MASK_ISA_SSE)
185 def_or_undef (parse_in, "__tune_athlon_sse__");
188 def_or_undef (parse_in, "__tune_k8__");
190 case PROCESSOR_AMDFAM10:
191 def_or_undef (parse_in, "__tune_amdfam10__");
193 case PROCESSOR_BDVER1:
194 def_or_undef (parse_in, "__tune_bdver1__");
196 case PROCESSOR_PENTIUM4:
197 def_or_undef (parse_in, "__tune_pentium4__");
199 case PROCESSOR_NOCONA:
200 def_or_undef (parse_in, "__tune_nocona__");
202 case PROCESSOR_CORE2:
203 def_or_undef (parse_in, "__tune_core2__");
205 case PROCESSOR_COREI7_32:
206 case PROCESSOR_COREI7_64:
207 def_or_undef (parse_in, "__tune_corei7__");
210 def_or_undef (parse_in, "__tune_atom__");
212 case PROCESSOR_GENERIC32:
213 case PROCESSOR_GENERIC64:
215 /* use PROCESSOR_max to not set/unset the tune macro. */
220 if (isa_flag & OPTION_MASK_ISA_MMX)
221 def_or_undef (parse_in, "__MMX__");
222 if (isa_flag & OPTION_MASK_ISA_3DNOW)
223 def_or_undef (parse_in, "__3dNOW__");
224 if (isa_flag & OPTION_MASK_ISA_3DNOW_A)
225 def_or_undef (parse_in, "__3dNOW_A__");
226 if (isa_flag & OPTION_MASK_ISA_SSE)
227 def_or_undef (parse_in, "__SSE__");
228 if (isa_flag & OPTION_MASK_ISA_SSE2)
229 def_or_undef (parse_in, "__SSE2__");
230 if (isa_flag & OPTION_MASK_ISA_SSE3)
231 def_or_undef (parse_in, "__SSE3__");
232 if (isa_flag & OPTION_MASK_ISA_SSSE3)
233 def_or_undef (parse_in, "__SSSE3__");
234 if (isa_flag & OPTION_MASK_ISA_SSE4_1)
235 def_or_undef (parse_in, "__SSE4_1__");
236 if (isa_flag & OPTION_MASK_ISA_SSE4_2)
237 def_or_undef (parse_in, "__SSE4_2__");
238 if (isa_flag & OPTION_MASK_ISA_AES)
239 def_or_undef (parse_in, "__AES__");
240 if (isa_flag & OPTION_MASK_ISA_PCLMUL)
241 def_or_undef (parse_in, "__PCLMUL__");
242 if (isa_flag & OPTION_MASK_ISA_AVX)
243 def_or_undef (parse_in, "__AVX__");
244 if (isa_flag & OPTION_MASK_ISA_FMA)
245 def_or_undef (parse_in, "__FMA__");
246 if (isa_flag & OPTION_MASK_ISA_SSE4A)
247 def_or_undef (parse_in, "__SSE4A__");
248 if (isa_flag & OPTION_MASK_ISA_FMA4)
249 def_or_undef (parse_in, "__FMA4__");
250 if (isa_flag & OPTION_MASK_ISA_XOP)
251 def_or_undef (parse_in, "__XOP__");
252 if (isa_flag & OPTION_MASK_ISA_LWP)
253 def_or_undef (parse_in, "__LWP__");
254 if (isa_flag & OPTION_MASK_ISA_ABM)
255 def_or_undef (parse_in, "__ABM__");
256 if (isa_flag & OPTION_MASK_ISA_BMI)
257 def_or_undef (parse_in, "__BMI__");
258 if (isa_flag & OPTION_MASK_ISA_TBM)
259 def_or_undef (parse_in, "__TBM__");
260 if (isa_flag & OPTION_MASK_ISA_POPCNT)
261 def_or_undef (parse_in, "__POPCNT__");
262 if (isa_flag & OPTION_MASK_ISA_FSGSBASE)
263 def_or_undef (parse_in, "__FSGSBASE__");
264 if (isa_flag & OPTION_MASK_ISA_RDRND)
265 def_or_undef (parse_in, "__RDRND__");
266 if (isa_flag & OPTION_MASK_ISA_F16C)
267 def_or_undef (parse_in, "__F16C__");
268 if ((fpmath & FPMATH_SSE) && (isa_flag & OPTION_MASK_ISA_SSE))
269 def_or_undef (parse_in, "__SSE_MATH__");
270 if ((fpmath & FPMATH_SSE) && (isa_flag & OPTION_MASK_ISA_SSE2))
271 def_or_undef (parse_in, "__SSE2_MATH__");
275 /* Hook to validate the current #pragma GCC target and set the state, and
276 update the macros based on what was changed. If ARGS is NULL, then
277 POP_TARGET is used to reset the options. */
280 ix86_pragma_target_parse (tree args, tree pop_target)
282 tree prev_tree = build_target_option_node ();
284 struct cl_target_option *prev_opt;
285 struct cl_target_option *cur_opt;
289 enum processor_type prev_arch;
290 enum processor_type prev_tune;
291 enum processor_type cur_arch;
292 enum processor_type cur_tune;
296 cur_tree = ((pop_target)
298 : target_option_default_node);
299 cl_target_option_restore (&global_options,
300 TREE_TARGET_OPTION (cur_tree));
304 cur_tree = ix86_valid_target_attribute_tree (args);
309 target_option_current_node = cur_tree;
311 /* Figure out the previous/current isa, arch, tune and the differences. */
312 prev_opt = TREE_TARGET_OPTION (prev_tree);
313 cur_opt = TREE_TARGET_OPTION (cur_tree);
314 prev_isa = prev_opt->x_ix86_isa_flags;
315 cur_isa = cur_opt->x_ix86_isa_flags;
316 diff_isa = (prev_isa ^ cur_isa);
317 prev_arch = (enum processor_type) prev_opt->arch;
318 prev_tune = (enum processor_type) prev_opt->tune;
319 cur_arch = (enum processor_type) cur_opt->arch;
320 cur_tune = (enum processor_type) cur_opt->tune;
322 /* If the same processor is used for both previous and current options, don't
323 change the macros. */
324 if (cur_arch == prev_arch)
325 cur_arch = prev_arch = PROCESSOR_max;
327 if (cur_tune == prev_tune)
328 cur_tune = prev_tune = PROCESSOR_max;
330 /* Undef all of the macros for that are no longer current. */
331 ix86_target_macros_internal (prev_isa & diff_isa,
334 (enum fpmath_unit) prev_opt->fpmath,
337 /* Define all of the macros for new options that were just turned on. */
338 ix86_target_macros_internal (cur_isa & diff_isa,
341 (enum fpmath_unit) cur_opt->fpmath,
347 /* Function to tell the preprocessor about the defines for the current target. */
350 ix86_target_macros (void)
352 /* 32/64-bit won't change with target specific options, so do the assert and
353 builtin_define_std calls here. */
356 cpp_assert (parse_in, "cpu=x86_64");
357 cpp_assert (parse_in, "machine=x86_64");
358 cpp_define (parse_in, "__amd64");
359 cpp_define (parse_in, "__amd64__");
360 cpp_define (parse_in, "__x86_64");
361 cpp_define (parse_in, "__x86_64__");
365 cpp_assert (parse_in, "cpu=i386");
366 cpp_assert (parse_in, "machine=i386");
367 builtin_define_std ("i386");
370 ix86_target_macros_internal (ix86_isa_flags,
378 /* Register target pragmas. We need to add the hook for parsing #pragma GCC
379 option here rather than in i386.c since it will pull in various preprocessor
380 functions, and those are not present in languages like fortran without a
384 ix86_register_pragmas (void)
386 /* Update pragma hook to allow parsing #pragma GCC target. */
387 targetm.target_option.pragma_parse = ix86_pragma_target_parse;
389 #ifdef REGISTER_SUBTARGET_PRAGMAS
390 REGISTER_SUBTARGET_PRAGMAS ();