1 /* Subroutines used for macro/preprocessor support on the ia-32.
2 Copyright (C) 2008-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
27 #include "double-int.h"
37 #include "c-family/c-common.h"
40 #include "target-def.h"
42 #include "c-family/c-pragma.h"
44 static bool ix86_pragma_target_parse (tree, tree);
45 static void ix86_target_macros_internal
46 (HOST_WIDE_INT, enum processor_type, enum processor_type, enum fpmath_unit,
47 void (*def_or_undef) (cpp_reader *, const char *));
50 /* Internal function to either define or undef the appropriate system
53 ix86_target_macros_internal (HOST_WIDE_INT isa_flag,
54 enum processor_type arch,
55 enum processor_type tune,
56 enum fpmath_unit fpmath,
57 void (*def_or_undef) (cpp_reader *,
60 /* For some of the k6/pentium varients there weren't separate ISA bits to
61 identify which tune/arch flag was passed, so figure it out here. */
62 size_t arch_len = strlen (ix86_arch_string);
63 size_t tune_len = strlen (ix86_tune_string);
64 int last_arch_char = ix86_arch_string[arch_len - 1];
65 int last_tune_char = ix86_tune_string[tune_len - 1];
67 /* Built-ins based on -march=. */
73 def_or_undef (parse_in, "__i486");
74 def_or_undef (parse_in, "__i486__");
76 case PROCESSOR_PENTIUM:
77 def_or_undef (parse_in, "__i586");
78 def_or_undef (parse_in, "__i586__");
79 def_or_undef (parse_in, "__pentium");
80 def_or_undef (parse_in, "__pentium__");
81 if (isa_flag & OPTION_MASK_ISA_MMX)
82 def_or_undef (parse_in, "__pentium_mmx__");
84 case PROCESSOR_PENTIUMPRO:
85 def_or_undef (parse_in, "__i686");
86 def_or_undef (parse_in, "__i686__");
87 def_or_undef (parse_in, "__pentiumpro");
88 def_or_undef (parse_in, "__pentiumpro__");
91 def_or_undef (parse_in, "__geode");
92 def_or_undef (parse_in, "__geode__");
95 def_or_undef (parse_in, "__k6");
96 def_or_undef (parse_in, "__k6__");
97 if (last_arch_char == '2')
98 def_or_undef (parse_in, "__k6_2__");
99 else if (last_arch_char == '3')
100 def_or_undef (parse_in, "__k6_3__");
101 else if (isa_flag & OPTION_MASK_ISA_3DNOW)
102 def_or_undef (parse_in, "__k6_3__");
104 case PROCESSOR_ATHLON:
105 def_or_undef (parse_in, "__athlon");
106 def_or_undef (parse_in, "__athlon__");
107 if (isa_flag & OPTION_MASK_ISA_SSE)
108 def_or_undef (parse_in, "__athlon_sse__");
111 def_or_undef (parse_in, "__k8");
112 def_or_undef (parse_in, "__k8__");
114 case PROCESSOR_AMDFAM10:
115 def_or_undef (parse_in, "__amdfam10");
116 def_or_undef (parse_in, "__amdfam10__");
118 case PROCESSOR_BDVER1:
119 def_or_undef (parse_in, "__bdver1");
120 def_or_undef (parse_in, "__bdver1__");
122 case PROCESSOR_BDVER2:
123 def_or_undef (parse_in, "__bdver2");
124 def_or_undef (parse_in, "__bdver2__");
126 case PROCESSOR_BDVER3:
127 def_or_undef (parse_in, "__bdver3");
128 def_or_undef (parse_in, "__bdver3__");
130 case PROCESSOR_BDVER4:
131 def_or_undef (parse_in, "__bdver4");
132 def_or_undef (parse_in, "__bdver4__");
134 case PROCESSOR_BTVER1:
135 def_or_undef (parse_in, "__btver1");
136 def_or_undef (parse_in, "__btver1__");
138 case PROCESSOR_BTVER2:
139 def_or_undef (parse_in, "__btver2");
140 def_or_undef (parse_in, "__btver2__");
142 case PROCESSOR_PENTIUM4:
143 def_or_undef (parse_in, "__pentium4");
144 def_or_undef (parse_in, "__pentium4__");
146 case PROCESSOR_NOCONA:
147 def_or_undef (parse_in, "__nocona");
148 def_or_undef (parse_in, "__nocona__");
150 case PROCESSOR_CORE2:
151 def_or_undef (parse_in, "__core2");
152 def_or_undef (parse_in, "__core2__");
154 case PROCESSOR_NEHALEM:
155 def_or_undef (parse_in, "__corei7");
156 def_or_undef (parse_in, "__corei7__");
157 def_or_undef (parse_in, "__nehalem");
158 def_or_undef (parse_in, "__nehalem__");
160 case PROCESSOR_SANDYBRIDGE:
161 def_or_undef (parse_in, "__corei7_avx");
162 def_or_undef (parse_in, "__corei7_avx__");
163 def_or_undef (parse_in, "__sandybridge");
164 def_or_undef (parse_in, "__sandybridge__");
166 case PROCESSOR_HASWELL:
167 def_or_undef (parse_in, "__core_avx2");
168 def_or_undef (parse_in, "__core_avx2__");
169 def_or_undef (parse_in, "__haswell");
170 def_or_undef (parse_in, "__haswell__");
172 case PROCESSOR_BONNELL:
173 def_or_undef (parse_in, "__atom");
174 def_or_undef (parse_in, "__atom__");
175 def_or_undef (parse_in, "__bonnell");
176 def_or_undef (parse_in, "__bonnell__");
178 case PROCESSOR_SILVERMONT:
179 def_or_undef (parse_in, "__slm");
180 def_or_undef (parse_in, "__slm__");
181 def_or_undef (parse_in, "__silvermont");
182 def_or_undef (parse_in, "__silvermont__");
185 def_or_undef (parse_in, "__knl");
186 def_or_undef (parse_in, "__knl__");
188 /* use PROCESSOR_max to not set/unset the arch macro. */
191 case PROCESSOR_INTEL:
192 case PROCESSOR_GENERIC:
196 /* Built-ins based on -mtune=. */
200 def_or_undef (parse_in, "__tune_i386__");
203 def_or_undef (parse_in, "__tune_i486__");
205 case PROCESSOR_PENTIUM:
206 def_or_undef (parse_in, "__tune_i586__");
207 def_or_undef (parse_in, "__tune_pentium__");
208 if (last_tune_char == 'x')
209 def_or_undef (parse_in, "__tune_pentium_mmx__");
211 case PROCESSOR_PENTIUMPRO:
212 def_or_undef (parse_in, "__tune_i686__");
213 def_or_undef (parse_in, "__tune_pentiumpro__");
214 switch (last_tune_char)
217 def_or_undef (parse_in, "__tune_pentium3__");
220 def_or_undef (parse_in, "__tune_pentium2__");
224 case PROCESSOR_GEODE:
225 def_or_undef (parse_in, "__tune_geode__");
228 def_or_undef (parse_in, "__tune_k6__");
229 if (last_tune_char == '2')
230 def_or_undef (parse_in, "__tune_k6_2__");
231 else if (last_tune_char == '3')
232 def_or_undef (parse_in, "__tune_k6_3__");
233 else if (isa_flag & OPTION_MASK_ISA_3DNOW)
234 def_or_undef (parse_in, "__tune_k6_3__");
236 case PROCESSOR_ATHLON:
237 def_or_undef (parse_in, "__tune_athlon__");
238 if (isa_flag & OPTION_MASK_ISA_SSE)
239 def_or_undef (parse_in, "__tune_athlon_sse__");
242 def_or_undef (parse_in, "__tune_k8__");
244 case PROCESSOR_AMDFAM10:
245 def_or_undef (parse_in, "__tune_amdfam10__");
247 case PROCESSOR_BDVER1:
248 def_or_undef (parse_in, "__tune_bdver1__");
250 case PROCESSOR_BDVER2:
251 def_or_undef (parse_in, "__tune_bdver2__");
253 case PROCESSOR_BDVER3:
254 def_or_undef (parse_in, "__tune_bdver3__");
256 case PROCESSOR_BDVER4:
257 def_or_undef (parse_in, "__tune_bdver4__");
259 case PROCESSOR_BTVER1:
260 def_or_undef (parse_in, "__tune_btver1__");
262 case PROCESSOR_BTVER2:
263 def_or_undef (parse_in, "__tune_btver2__");
265 case PROCESSOR_PENTIUM4:
266 def_or_undef (parse_in, "__tune_pentium4__");
268 case PROCESSOR_NOCONA:
269 def_or_undef (parse_in, "__tune_nocona__");
271 case PROCESSOR_CORE2:
272 def_or_undef (parse_in, "__tune_core2__");
274 case PROCESSOR_NEHALEM:
275 def_or_undef (parse_in, "__tune_corei7__");
276 def_or_undef (parse_in, "__tune_nehalem__");
278 case PROCESSOR_SANDYBRIDGE:
279 def_or_undef (parse_in, "__tune_corei7_avx__");
280 def_or_undef (parse_in, "__tune_sandybridge__");
282 case PROCESSOR_HASWELL:
283 def_or_undef (parse_in, "__tune_core_avx2__");
284 def_or_undef (parse_in, "__tune_haswell__");
286 case PROCESSOR_BONNELL:
287 def_or_undef (parse_in, "__tune_atom__");
288 def_or_undef (parse_in, "__tune_bonnell__");
290 case PROCESSOR_SILVERMONT:
291 def_or_undef (parse_in, "__tune_slm__");
292 def_or_undef (parse_in, "__tune_silvermont__");
295 def_or_undef (parse_in, "__tune_knl__");
297 case PROCESSOR_INTEL:
298 case PROCESSOR_GENERIC:
300 /* use PROCESSOR_max to not set/unset the tune macro. */
309 def_or_undef (parse_in, "__code_model_small__");
313 def_or_undef (parse_in, "__code_model_medium__");
317 def_or_undef (parse_in, "__code_model_large__");
320 def_or_undef (parse_in, "__code_model_32__");
323 def_or_undef (parse_in, "__code_model_kernel__");
329 if (isa_flag & OPTION_MASK_ISA_MMX)
330 def_or_undef (parse_in, "__MMX__");
331 if (isa_flag & OPTION_MASK_ISA_3DNOW)
332 def_or_undef (parse_in, "__3dNOW__");
333 if (isa_flag & OPTION_MASK_ISA_3DNOW_A)
334 def_or_undef (parse_in, "__3dNOW_A__");
335 if (isa_flag & OPTION_MASK_ISA_SSE)
336 def_or_undef (parse_in, "__SSE__");
337 if (isa_flag & OPTION_MASK_ISA_SSE2)
338 def_or_undef (parse_in, "__SSE2__");
339 if (isa_flag & OPTION_MASK_ISA_SSE3)
340 def_or_undef (parse_in, "__SSE3__");
341 if (isa_flag & OPTION_MASK_ISA_SSSE3)
342 def_or_undef (parse_in, "__SSSE3__");
343 if (isa_flag & OPTION_MASK_ISA_SSE4_1)
344 def_or_undef (parse_in, "__SSE4_1__");
345 if (isa_flag & OPTION_MASK_ISA_SSE4_2)
346 def_or_undef (parse_in, "__SSE4_2__");
347 if (isa_flag & OPTION_MASK_ISA_AES)
348 def_or_undef (parse_in, "__AES__");
349 if (isa_flag & OPTION_MASK_ISA_SHA)
350 def_or_undef (parse_in, "__SHA__");
351 if (isa_flag & OPTION_MASK_ISA_PCLMUL)
352 def_or_undef (parse_in, "__PCLMUL__");
353 if (isa_flag & OPTION_MASK_ISA_AVX)
354 def_or_undef (parse_in, "__AVX__");
355 if (isa_flag & OPTION_MASK_ISA_AVX2)
356 def_or_undef (parse_in, "__AVX2__");
357 if (isa_flag & OPTION_MASK_ISA_AVX512F)
358 def_or_undef (parse_in, "__AVX512F__");
359 if (isa_flag & OPTION_MASK_ISA_AVX512ER)
360 def_or_undef (parse_in, "__AVX512ER__");
361 if (isa_flag & OPTION_MASK_ISA_AVX512CD)
362 def_or_undef (parse_in, "__AVX512CD__");
363 if (isa_flag & OPTION_MASK_ISA_AVX512PF)
364 def_or_undef (parse_in, "__AVX512PF__");
365 if (isa_flag & OPTION_MASK_ISA_AVX512DQ)
366 def_or_undef (parse_in, "__AVX512DQ__");
367 if (isa_flag & OPTION_MASK_ISA_AVX512BW)
368 def_or_undef (parse_in, "__AVX512BW__");
369 if (isa_flag & OPTION_MASK_ISA_AVX512VL)
370 def_or_undef (parse_in, "__AVX512VL__");
371 if (isa_flag & OPTION_MASK_ISA_AVX512VBMI)
372 def_or_undef (parse_in, "__AVX512VBMI__");
373 if (isa_flag & OPTION_MASK_ISA_AVX512IFMA)
374 def_or_undef (parse_in, "__AVX512IFMA__");
375 if (isa_flag & OPTION_MASK_ISA_FMA)
376 def_or_undef (parse_in, "__FMA__");
377 if (isa_flag & OPTION_MASK_ISA_RTM)
378 def_or_undef (parse_in, "__RTM__");
379 if (isa_flag & OPTION_MASK_ISA_SSE4A)
380 def_or_undef (parse_in, "__SSE4A__");
381 if (isa_flag & OPTION_MASK_ISA_FMA4)
382 def_or_undef (parse_in, "__FMA4__");
383 if (isa_flag & OPTION_MASK_ISA_XOP)
384 def_or_undef (parse_in, "__XOP__");
385 if (isa_flag & OPTION_MASK_ISA_LWP)
386 def_or_undef (parse_in, "__LWP__");
387 if (isa_flag & OPTION_MASK_ISA_ABM)
388 def_or_undef (parse_in, "__ABM__");
389 if (isa_flag & OPTION_MASK_ISA_BMI)
390 def_or_undef (parse_in, "__BMI__");
391 if (isa_flag & OPTION_MASK_ISA_BMI2)
392 def_or_undef (parse_in, "__BMI2__");
393 if (isa_flag & OPTION_MASK_ISA_LZCNT)
394 def_or_undef (parse_in, "__LZCNT__");
395 if (isa_flag & OPTION_MASK_ISA_TBM)
396 def_or_undef (parse_in, "__TBM__");
397 if (isa_flag & OPTION_MASK_ISA_POPCNT)
398 def_or_undef (parse_in, "__POPCNT__");
399 if (isa_flag & OPTION_MASK_ISA_FSGSBASE)
400 def_or_undef (parse_in, "__FSGSBASE__");
401 if (isa_flag & OPTION_MASK_ISA_RDRND)
402 def_or_undef (parse_in, "__RDRND__");
403 if (isa_flag & OPTION_MASK_ISA_F16C)
404 def_or_undef (parse_in, "__F16C__");
405 if (isa_flag & OPTION_MASK_ISA_RDSEED)
406 def_or_undef (parse_in, "__RDSEED__");
407 if (isa_flag & OPTION_MASK_ISA_PRFCHW)
408 def_or_undef (parse_in, "__PRFCHW__");
409 if (isa_flag & OPTION_MASK_ISA_ADX)
410 def_or_undef (parse_in, "__ADX__");
411 if (isa_flag & OPTION_MASK_ISA_FXSR)
412 def_or_undef (parse_in, "__FXSR__");
413 if (isa_flag & OPTION_MASK_ISA_XSAVE)
414 def_or_undef (parse_in, "__XSAVE__");
415 if (isa_flag & OPTION_MASK_ISA_XSAVEOPT)
416 def_or_undef (parse_in, "__XSAVEOPT__");
417 if (isa_flag & OPTION_MASK_ISA_PREFETCHWT1)
418 def_or_undef (parse_in, "__PREFETCHWT1__");
419 if ((fpmath & FPMATH_SSE) && (isa_flag & OPTION_MASK_ISA_SSE))
420 def_or_undef (parse_in, "__SSE_MATH__");
421 if ((fpmath & FPMATH_SSE) && (isa_flag & OPTION_MASK_ISA_SSE2))
422 def_or_undef (parse_in, "__SSE2_MATH__");
423 if (isa_flag & OPTION_MASK_ISA_CLFLUSHOPT)
424 def_or_undef (parse_in, "__CLFLUSHOPT__");
425 if (isa_flag & OPTION_MASK_ISA_XSAVEC)
426 def_or_undef (parse_in, "__XSAVEC__");
427 if (isa_flag & OPTION_MASK_ISA_XSAVES)
428 def_or_undef (parse_in, "__XSAVES__");
429 if (isa_flag & OPTION_MASK_ISA_MPX)
430 def_or_undef (parse_in, "__MPX__");
431 if (isa_flag & OPTION_MASK_ISA_PCOMMIT)
432 def_or_undef (parse_in, "__PCOMMIT__");
433 if (isa_flag & OPTION_MASK_ISA_CLWB)
434 def_or_undef (parse_in, "__CLWB__");
438 /* Hook to validate the current #pragma GCC target and set the state, and
439 update the macros based on what was changed. If ARGS is NULL, then
440 POP_TARGET is used to reset the options. */
443 ix86_pragma_target_parse (tree args, tree pop_target)
445 tree prev_tree = build_target_option_node (&global_options);
447 struct cl_target_option *prev_opt;
448 struct cl_target_option *cur_opt;
449 HOST_WIDE_INT prev_isa;
450 HOST_WIDE_INT cur_isa;
451 HOST_WIDE_INT diff_isa;
452 enum processor_type prev_arch;
453 enum processor_type prev_tune;
454 enum processor_type cur_arch;
455 enum processor_type cur_tune;
459 cur_tree = (pop_target ? pop_target : target_option_default_node);
460 cl_target_option_restore (&global_options,
461 TREE_TARGET_OPTION (cur_tree));
465 cur_tree = ix86_valid_target_attribute_tree (args, &global_options,
466 &global_options_set);
467 if (!cur_tree || cur_tree == error_mark_node)
469 cl_target_option_restore (&global_options,
470 TREE_TARGET_OPTION (prev_tree));
475 target_option_current_node = cur_tree;
476 ix86_reset_previous_fndecl ();
478 /* Figure out the previous/current isa, arch, tune and the differences. */
479 prev_opt = TREE_TARGET_OPTION (prev_tree);
480 cur_opt = TREE_TARGET_OPTION (cur_tree);
481 prev_isa = prev_opt->x_ix86_isa_flags;
482 cur_isa = cur_opt->x_ix86_isa_flags;
483 diff_isa = (prev_isa ^ cur_isa);
484 prev_arch = (enum processor_type) prev_opt->arch;
485 prev_tune = (enum processor_type) prev_opt->tune;
486 cur_arch = (enum processor_type) cur_opt->arch;
487 cur_tune = (enum processor_type) cur_opt->tune;
489 /* If the same processor is used for both previous and current options, don't
490 change the macros. */
491 if (cur_arch == prev_arch)
492 cur_arch = prev_arch = PROCESSOR_max;
494 if (cur_tune == prev_tune)
495 cur_tune = prev_tune = PROCESSOR_max;
497 /* Undef all of the macros for that are no longer current. */
498 ix86_target_macros_internal (prev_isa & diff_isa,
501 (enum fpmath_unit) prev_opt->x_ix86_fpmath,
504 /* For the definitions, ensure all newly defined macros are considered
505 as used for -Wunused-macros. There is no point warning about the
506 compiler predefined macros. */
507 cpp_options *cpp_opts = cpp_get_options (parse_in);
508 unsigned char saved_warn_unused_macros = cpp_opts->warn_unused_macros;
509 cpp_opts->warn_unused_macros = 0;
511 /* Define all of the macros for new options that were just turned on. */
512 ix86_target_macros_internal (cur_isa & diff_isa,
515 (enum fpmath_unit) cur_opt->x_ix86_fpmath,
518 cpp_opts->warn_unused_macros = saved_warn_unused_macros;
523 /* Function to tell the preprocessor about the defines for the current target. */
526 ix86_target_macros (void)
528 /* 32/64-bit won't change with target specific options, so do the assert and
529 builtin_define_std calls here. */
532 cpp_assert (parse_in, "cpu=x86_64");
533 cpp_assert (parse_in, "machine=x86_64");
534 cpp_define (parse_in, "__amd64");
535 cpp_define (parse_in, "__amd64__");
536 cpp_define (parse_in, "__x86_64");
537 cpp_define (parse_in, "__x86_64__");
540 cpp_define (parse_in, "_ILP32");
541 cpp_define (parse_in, "__ILP32__");
546 cpp_assert (parse_in, "cpu=i386");
547 cpp_assert (parse_in, "machine=i386");
548 builtin_define_std ("i386");
552 cpp_define (parse_in, "_SOFT_FLOAT");
554 if (TARGET_LONG_DOUBLE_64)
555 cpp_define (parse_in, "__LONG_DOUBLE_64__");
557 if (TARGET_LONG_DOUBLE_128)
558 cpp_define (parse_in, "__LONG_DOUBLE_128__");
560 if (TARGET_128BIT_LONG_DOUBLE)
561 cpp_define (parse_in, "__SIZEOF_FLOAT80__=16");
563 cpp_define (parse_in, "__SIZEOF_FLOAT80__=12");
565 cpp_define (parse_in, "__SIZEOF_FLOAT128__=16");
567 cpp_define_formatted (parse_in, "__ATOMIC_HLE_ACQUIRE=%d", IX86_HLE_ACQUIRE);
568 cpp_define_formatted (parse_in, "__ATOMIC_HLE_RELEASE=%d", IX86_HLE_RELEASE);
570 ix86_target_macros_internal (ix86_isa_flags,
578 /* Register target pragmas. We need to add the hook for parsing #pragma GCC
579 option here rather than in i386.c since it will pull in various preprocessor
580 functions, and those are not present in languages like fortran without a
584 ix86_register_pragmas (void)
586 /* Update pragma hook to allow parsing #pragma GCC target. */
587 targetm.target_option.pragma_parse = ix86_pragma_target_parse;
589 #ifdef REGISTER_SUBTARGET_PRAGMAS
590 REGISTER_SUBTARGET_PRAGMAS ();