1 /* Subroutines used for macro/preprocessor support on the ia-32.
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"
32 #include "target-def.h"
36 static bool ix86_pragma_target_parse (tree
, tree
);
37 static void ix86_target_macros_internal
38 (int, enum processor_type
, enum processor_type
, enum fpmath_unit
,
39 void (*def_or_undef
) (cpp_reader
*, const char *));
42 /* Internal function to either define or undef the appropriate system
45 ix86_target_macros_internal (int isa_flag
,
46 enum processor_type arch
,
47 enum processor_type tune
,
48 enum fpmath_unit fpmath
,
49 void (*def_or_undef
) (cpp_reader
*,
52 /* For some of the k6/pentium varients there weren't seperate ISA bits to
53 identify which tune/arch flag was passed, so figure it out here. */
54 size_t arch_len
= strlen (ix86_arch_string
);
55 size_t tune_len
= strlen (ix86_tune_string
);
56 int last_arch_char
= ix86_arch_string
[arch_len
- 1];
57 int last_tune_char
= ix86_tune_string
[tune_len
- 1];
59 /* Built-ins based on -march=. */
65 def_or_undef (parse_in
, "__i486");
66 def_or_undef (parse_in
, "__i486__");
68 case PROCESSOR_PENTIUM
:
69 def_or_undef (parse_in
, "__i586");
70 def_or_undef (parse_in
, "__i586__");
71 def_or_undef (parse_in
, "__pentium");
72 def_or_undef (parse_in
, "__pentium__");
73 if (isa_flag
& OPTION_MASK_ISA_MMX
)
74 def_or_undef (parse_in
, "__pentium_mmx__");
76 case PROCESSOR_PENTIUMPRO
:
77 def_or_undef (parse_in
, "__i686");
78 def_or_undef (parse_in
, "__i686__");
79 def_or_undef (parse_in
, "__pentiumpro");
80 def_or_undef (parse_in
, "__pentiumpro__");
83 def_or_undef (parse_in
, "__geode");
84 def_or_undef (parse_in
, "__geode__");
87 def_or_undef (parse_in
, "__k6");
88 def_or_undef (parse_in
, "__k6__");
89 if (last_arch_char
== '2')
90 def_or_undef (parse_in
, "__k6_2__");
91 else if (last_arch_char
== '3')
92 def_or_undef (parse_in
, "__k6_3__");
93 else if (isa_flag
& OPTION_MASK_ISA_3DNOW
)
94 def_or_undef (parse_in
, "__k6_3__");
96 case PROCESSOR_ATHLON
:
97 def_or_undef (parse_in
, "__athlon");
98 def_or_undef (parse_in
, "__athlon__");
99 if (isa_flag
& OPTION_MASK_ISA_SSE
)
100 def_or_undef (parse_in
, "__athlon_sse__");
103 def_or_undef (parse_in
, "__k8");
104 def_or_undef (parse_in
, "__k8__");
106 case PROCESSOR_AMDFAM10
:
107 def_or_undef (parse_in
, "__amdfam10");
108 def_or_undef (parse_in
, "__amdfam10__");
110 case PROCESSOR_PENTIUM4
:
111 def_or_undef (parse_in
, "__pentium4");
112 def_or_undef (parse_in
, "__pentium4__");
114 case PROCESSOR_NOCONA
:
115 def_or_undef (parse_in
, "__nocona");
116 def_or_undef (parse_in
, "__nocona__");
118 case PROCESSOR_CORE2
:
119 def_or_undef (parse_in
, "__core2");
120 def_or_undef (parse_in
, "__core2__");
122 /* use PROCESSOR_max to not set/unset the arch macro. */
125 case PROCESSOR_GENERIC32
:
126 case PROCESSOR_GENERIC64
:
130 /* Built-ins based on -mtune=. */
134 def_or_undef (parse_in
, "__tune_i386__");
137 def_or_undef (parse_in
, "__tune_i486__");
139 case PROCESSOR_PENTIUM
:
140 def_or_undef (parse_in
, "__tune_i586__");
141 def_or_undef (parse_in
, "__tune_pentium__");
142 if (last_tune_char
== 'x')
143 def_or_undef (parse_in
, "__tune_pentium_mmx__");
145 case PROCESSOR_PENTIUMPRO
:
146 def_or_undef (parse_in
, "__tune_i686__");
147 def_or_undef (parse_in
, "__tune_pentiumpro__");
148 switch (last_tune_char
)
151 def_or_undef (parse_in
, "__tune_pentium3__");
154 def_or_undef (parse_in
, "__tune_pentium2__");
158 case PROCESSOR_GEODE
:
159 def_or_undef (parse_in
, "__tune_geode__");
162 def_or_undef (parse_in
, "__tune_k6__");
163 if (last_tune_char
== '2')
164 def_or_undef (parse_in
, "__tune_k6_2__");
165 else if (last_tune_char
== '3')
166 def_or_undef (parse_in
, "__tune_k6_3__");
167 else if (isa_flag
& OPTION_MASK_ISA_3DNOW
)
168 def_or_undef (parse_in
, "__tune_k6_3__");
170 case PROCESSOR_ATHLON
:
171 def_or_undef (parse_in
, "__tune_athlon__");
172 if (isa_flag
& OPTION_MASK_ISA_SSE
)
173 def_or_undef (parse_in
, "__tune_athlon_sse__");
176 def_or_undef (parse_in
, "__tune_k8__");
178 case PROCESSOR_AMDFAM10
:
179 def_or_undef (parse_in
, "__tune_amdfam10__");
181 case PROCESSOR_PENTIUM4
:
182 def_or_undef (parse_in
, "__tune_pentium4__");
184 case PROCESSOR_NOCONA
:
185 def_or_undef (parse_in
, "__tune_nocona__");
187 case PROCESSOR_CORE2
:
188 def_or_undef (parse_in
, "__tune_core2__");
190 case PROCESSOR_GENERIC32
:
191 case PROCESSOR_GENERIC64
:
193 /* use PROCESSOR_max to not set/unset the tune macro. */
198 if (isa_flag
& OPTION_MASK_ISA_MMX
)
199 def_or_undef (parse_in
, "__MMX__");
200 if (isa_flag
& OPTION_MASK_ISA_3DNOW
)
201 def_or_undef (parse_in
, "__3dNOW__");
202 if (isa_flag
& OPTION_MASK_ISA_3DNOW_A
)
203 def_or_undef (parse_in
, "__3dNOW_A__");
204 if (isa_flag
& OPTION_MASK_ISA_SSE
)
205 def_or_undef (parse_in
, "__SSE__");
206 if (isa_flag
& OPTION_MASK_ISA_SSE2
)
207 def_or_undef (parse_in
, "__SSE2__");
208 if (isa_flag
& OPTION_MASK_ISA_SSE3
)
209 def_or_undef (parse_in
, "__SSE3__");
210 if (isa_flag
& OPTION_MASK_ISA_SSSE3
)
211 def_or_undef (parse_in
, "__SSSE3__");
212 if (isa_flag
& OPTION_MASK_ISA_SSE4_1
)
213 def_or_undef (parse_in
, "__SSE4_1__");
214 if (isa_flag
& OPTION_MASK_ISA_SSE4_2
)
215 def_or_undef (parse_in
, "__SSE4_2__");
216 if (isa_flag
& OPTION_MASK_ISA_AES
)
217 def_or_undef (parse_in
, "__AES__");
218 if (isa_flag
& OPTION_MASK_ISA_PCLMUL
)
219 def_or_undef (parse_in
, "__PCLMUL__");
220 if (isa_flag
& OPTION_MASK_ISA_AVX
)
221 def_or_undef (parse_in
, "__AVX__");
222 if (isa_flag
& OPTION_MASK_ISA_FMA
)
223 def_or_undef (parse_in
, "__FMA__");
224 if (isa_flag
& OPTION_MASK_ISA_SSE4A
)
225 def_or_undef (parse_in
, "__SSE4A__");
226 if (isa_flag
& OPTION_MASK_ISA_SSE5
)
227 def_or_undef (parse_in
, "__SSE5__");
228 if ((fpmath
& FPMATH_SSE
) && (isa_flag
& OPTION_MASK_ISA_SSE
))
229 def_or_undef (parse_in
, "__SSE_MATH__");
230 if ((fpmath
& FPMATH_SSE
) && (isa_flag
& OPTION_MASK_ISA_SSE2
))
231 def_or_undef (parse_in
, "__SSE2_MATH__");
235 /* Hook to validate the current #pragma GCC target and set the state, and
236 update the macros based on what was changed. If ARGS is NULL, then
237 POP_TARGET is used to reset the options. */
240 ix86_pragma_target_parse (tree args
, tree pop_target
)
242 tree prev_tree
= build_target_option_node ();
244 struct cl_target_option
*prev_opt
;
245 struct cl_target_option
*cur_opt
;
249 enum processor_type prev_arch
;
250 enum processor_type prev_tune
;
251 enum processor_type cur_arch
;
252 enum processor_type cur_tune
;
256 cur_tree
= ((pop_target
)
258 : target_option_default_node
);
259 cl_target_option_restore (TREE_TARGET_OPTION (cur_tree
));
263 cur_tree
= ix86_valid_target_attribute_tree (args
);
268 target_option_current_node
= cur_tree
;
270 /* Figure out the previous/current isa, arch, tune and the differences. */
271 prev_opt
= TREE_TARGET_OPTION (prev_tree
);
272 cur_opt
= TREE_TARGET_OPTION (cur_tree
);
273 prev_isa
= prev_opt
->ix86_isa_flags
;
274 cur_isa
= cur_opt
->ix86_isa_flags
;
275 diff_isa
= (prev_isa
^ cur_isa
);
276 prev_arch
= prev_opt
->arch
;
277 prev_tune
= prev_opt
->tune
;
278 cur_arch
= cur_opt
->arch
;
279 cur_tune
= cur_opt
->tune
;
281 /* If the same processor is used for both previous and current options, don't
282 change the macros. */
283 if (cur_arch
== prev_arch
)
284 cur_arch
= prev_arch
= PROCESSOR_max
;
286 if (cur_tune
== prev_tune
)
287 cur_tune
= prev_tune
= PROCESSOR_max
;
289 /* Undef all of the macros for that are no longer current. */
290 ix86_target_macros_internal (prev_isa
& diff_isa
,
296 /* Define all of the macros for new options that were just turned on. */
297 ix86_target_macros_internal (cur_isa
& diff_isa
,
306 /* Function to tell the preprocessor about the defines for the current target. */
309 ix86_target_macros (void)
311 /* 32/64-bit won't change with target specific options, so do the assert and
312 builtin_define_std calls here. */
315 cpp_assert (parse_in
, "cpu=x86_64");
316 cpp_assert (parse_in
, "machine=x86_64");
317 cpp_define (parse_in
, "__amd64");
318 cpp_define (parse_in
, "__amd64__");
319 cpp_define (parse_in
, "__x86_64");
320 cpp_define (parse_in
, "__x86_64__");
324 cpp_assert (parse_in
, "cpu=i386");
325 cpp_assert (parse_in
, "machine=i386");
326 builtin_define_std ("i386");
329 ix86_target_macros_internal (ix86_isa_flags
,
337 /* Register target pragmas. We need to add the hook for parsing #pragma GCC
338 option here rather than in i386.c since it will pull in various preprocessor
339 functions, and those are not present in languages like fortran without a
343 ix86_register_pragmas (void)
345 /* Update pragma hook to allow parsing #pragma GCC target. */
346 targetm
.target_option
.pragma_parse
= ix86_pragma_target_parse
;
348 #ifdef REGISTER_SUBTARGET_PRAGMAS
349 REGISTER_SUBTARGET_PRAGMAS ();