]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/i386/i386-c.cc
Update copyright years.
[thirdparty/gcc.git] / gcc / config / i386 / i386-c.cc
CommitLineData
ab442df7 1/* Subroutines used for macro/preprocessor support on the ia-32.
83ffe9cd 2 Copyright (C) 2008-2023 Free Software Foundation, Inc.
ab442df7
MM
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 3, or (at your option)
9any later version.
10
11GCC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
8fcc61f8
RS
20#define IN_TARGET_CODE 1
21
ab442df7
MM
22#include "config.h"
23#include "system.h"
24#include "coretypes.h"
ab442df7 25#include "target.h"
e11c4407 26#include "c-family/c-common.h"
4d0cdd0c 27#include "memmodel.h"
e11c4407 28#include "tm_p.h"
39dabefd 29#include "c-family/c-pragma.h"
ab442df7 30
5779e713 31static bool ix86_pragma_target_parse (tree, tree);
ab442df7 32static void ix86_target_macros_internal
5fbb13a7 33 (HOST_WIDE_INT, HOST_WIDE_INT, enum processor_type, enum processor_type, enum fpmath_unit,
ab442df7
MM
34 void (*def_or_undef) (cpp_reader *, const char *));
35
ab442df7
MM
36/* Internal function to either define or undef the appropriate system
37 macros. */
38static void
df385b9c 39ix86_target_macros_internal (HOST_WIDE_INT isa_flag,
5fbb13a7 40 HOST_WIDE_INT isa_flag2,
ab442df7
MM
41 enum processor_type arch,
42 enum processor_type tune,
43 enum fpmath_unit fpmath,
44 void (*def_or_undef) (cpp_reader *,
45 const char *))
46{
073a8998 47 /* For some of the k6/pentium varients there weren't separate ISA bits to
ab442df7
MM
48 identify which tune/arch flag was passed, so figure it out here. */
49 size_t arch_len = strlen (ix86_arch_string);
50 size_t tune_len = strlen (ix86_tune_string);
51 int last_arch_char = ix86_arch_string[arch_len - 1];
52 int last_tune_char = ix86_tune_string[tune_len - 1];
53
54 /* Built-ins based on -march=. */
55 switch (arch)
56 {
57 case PROCESSOR_I386:
58 break;
59 case PROCESSOR_I486:
60 def_or_undef (parse_in, "__i486");
61 def_or_undef (parse_in, "__i486__");
62 break;
2d6b2e28 63 case PROCESSOR_LAKEMONT:
45cef0e9 64 /* Intel MCU is based on Intel Pentium CPU. */
ab442df7
MM
65 case PROCESSOR_PENTIUM:
66 def_or_undef (parse_in, "__i586");
67 def_or_undef (parse_in, "__i586__");
68 def_or_undef (parse_in, "__pentium");
69 def_or_undef (parse_in, "__pentium__");
70 if (isa_flag & OPTION_MASK_ISA_MMX)
71 def_or_undef (parse_in, "__pentium_mmx__");
72 break;
73 case PROCESSOR_PENTIUMPRO:
74 def_or_undef (parse_in, "__i686");
75 def_or_undef (parse_in, "__i686__");
76 def_or_undef (parse_in, "__pentiumpro");
77 def_or_undef (parse_in, "__pentiumpro__");
78 break;
79 case PROCESSOR_GEODE:
80 def_or_undef (parse_in, "__geode");
81 def_or_undef (parse_in, "__geode__");
82 break;
83 case PROCESSOR_K6:
84 def_or_undef (parse_in, "__k6");
85 def_or_undef (parse_in, "__k6__");
86 if (last_arch_char == '2')
87 def_or_undef (parse_in, "__k6_2__");
88 else if (last_arch_char == '3')
89 def_or_undef (parse_in, "__k6_3__");
90 else if (isa_flag & OPTION_MASK_ISA_3DNOW)
91 def_or_undef (parse_in, "__k6_3__");
92 break;
93 case PROCESSOR_ATHLON:
94 def_or_undef (parse_in, "__athlon");
95 def_or_undef (parse_in, "__athlon__");
96 if (isa_flag & OPTION_MASK_ISA_SSE)
97 def_or_undef (parse_in, "__athlon_sse__");
98 break;
99 case PROCESSOR_K8:
100 def_or_undef (parse_in, "__k8");
101 def_or_undef (parse_in, "__k8__");
102 break;
103 case PROCESSOR_AMDFAM10:
104 def_or_undef (parse_in, "__amdfam10");
105 def_or_undef (parse_in, "__amdfam10__");
106 break;
1133125e
HJ
107 case PROCESSOR_BDVER1:
108 def_or_undef (parse_in, "__bdver1");
109 def_or_undef (parse_in, "__bdver1__");
110 break;
4d652a18
HJ
111 case PROCESSOR_BDVER2:
112 def_or_undef (parse_in, "__bdver2");
113 def_or_undef (parse_in, "__bdver2__");
114 break;
eb2f2b44
GG
115 case PROCESSOR_BDVER3:
116 def_or_undef (parse_in, "__bdver3");
117 def_or_undef (parse_in, "__bdver3__");
118 break;
ed97ad47
GG
119 case PROCESSOR_BDVER4:
120 def_or_undef (parse_in, "__bdver4");
121 def_or_undef (parse_in, "__bdver4__");
122 break;
9ce29eb0
VK
123 case PROCESSOR_ZNVER1:
124 def_or_undef (parse_in, "__znver1");
125 def_or_undef (parse_in, "__znver1__");
126 break;
2901f42f
VK
127 case PROCESSOR_ZNVER2:
128 def_or_undef (parse_in, "__znver2");
129 def_or_undef (parse_in, "__znver2__");
130 break;
3e2ae3ee
VK
131 case PROCESSOR_ZNVER3:
132 def_or_undef (parse_in, "__znver3");
133 def_or_undef (parse_in, "__znver3__");
134 break;
bf3b532b
TJ
135 case PROCESSOR_ZNVER4:
136 def_or_undef (parse_in, "__znver4");
137 def_or_undef (parse_in, "__znver4__");
138 break;
14b52538
CF
139 case PROCESSOR_BTVER1:
140 def_or_undef (parse_in, "__btver1");
141 def_or_undef (parse_in, "__btver1__");
142 break;
e32bfc16
VK
143 case PROCESSOR_BTVER2:
144 def_or_undef (parse_in, "__btver2");
145 def_or_undef (parse_in, "__btver2__");
146 break;
a239aff8
M
147 case PROCESSOR_LUJIAZUI:
148 def_or_undef (parse_in, "__lujiazui");
149 def_or_undef (parse_in, "__lujiazui__");
150 break;
ab442df7
MM
151 case PROCESSOR_PENTIUM4:
152 def_or_undef (parse_in, "__pentium4");
153 def_or_undef (parse_in, "__pentium4__");
154 break;
155 case PROCESSOR_NOCONA:
156 def_or_undef (parse_in, "__nocona");
157 def_or_undef (parse_in, "__nocona__");
158 break;
340ef734 159 case PROCESSOR_CORE2:
ab442df7
MM
160 def_or_undef (parse_in, "__core2");
161 def_or_undef (parse_in, "__core2__");
162 break;
d3c11974 163 case PROCESSOR_NEHALEM:
b2b01543
BS
164 def_or_undef (parse_in, "__corei7");
165 def_or_undef (parse_in, "__corei7__");
d3c11974
L
166 def_or_undef (parse_in, "__nehalem");
167 def_or_undef (parse_in, "__nehalem__");
b2b01543 168 break;
d3c11974 169 case PROCESSOR_SANDYBRIDGE:
fd5564d3
WM
170 def_or_undef (parse_in, "__corei7_avx");
171 def_or_undef (parse_in, "__corei7_avx__");
d3c11974
L
172 def_or_undef (parse_in, "__sandybridge");
173 def_or_undef (parse_in, "__sandybridge__");
fd5564d3 174 break;
3a579e09
VY
175 case PROCESSOR_HASWELL:
176 def_or_undef (parse_in, "__core_avx2");
177 def_or_undef (parse_in, "__core_avx2__");
d3c11974
L
178 def_or_undef (parse_in, "__haswell");
179 def_or_undef (parse_in, "__haswell__");
3a579e09 180 break;
d3c11974 181 case PROCESSOR_BONNELL:
b6837b94
JY
182 def_or_undef (parse_in, "__atom");
183 def_or_undef (parse_in, "__atom__");
d3c11974
L
184 def_or_undef (parse_in, "__bonnell");
185 def_or_undef (parse_in, "__bonnell__");
b6837b94 186 break;
d3c11974 187 case PROCESSOR_SILVERMONT:
0b871ccf
YR
188 def_or_undef (parse_in, "__slm");
189 def_or_undef (parse_in, "__slm__");
d3c11974
L
190 def_or_undef (parse_in, "__silvermont");
191 def_or_undef (parse_in, "__silvermont__");
0b871ccf 192 break;
50e461df
OM
193 case PROCESSOR_GOLDMONT:
194 def_or_undef (parse_in, "__goldmont");
195 def_or_undef (parse_in, "__goldmont__");
196 break;
74b2bb19
OM
197 case PROCESSOR_GOLDMONT_PLUS:
198 def_or_undef (parse_in, "__goldmont_plus");
199 def_or_undef (parse_in, "__goldmont_plus__");
200 break;
a548a5a1
OM
201 case PROCESSOR_TREMONT:
202 def_or_undef (parse_in, "__tremont");
203 def_or_undef (parse_in, "__tremont__");
204 break;
fabe470b
HJ
205 case PROCESSOR_SIERRAFOREST:
206 def_or_undef (parse_in, "__sierraforest");
207 def_or_undef (parse_in, "__sierraforest__");
208 break;
c4f8f8af
HL
209 case PROCESSOR_GRANDRIDGE:
210 def_or_undef (parse_in, "__grandridge");
211 def_or_undef (parse_in, "__grandridge__");
212 break;
52747219
IT
213 case PROCESSOR_KNL:
214 def_or_undef (parse_in, "__knl");
215 def_or_undef (parse_in, "__knl__");
216 break;
cace2309
SP
217 case PROCESSOR_KNM:
218 def_or_undef (parse_in, "__knm");
219 def_or_undef (parse_in, "__knm__");
220 break;
176a3386
OM
221 case PROCESSOR_SKYLAKE:
222 def_or_undef (parse_in, "__skylake");
223 def_or_undef (parse_in, "__skylake__");
224 break;
06caf59d
KY
225 case PROCESSOR_SKYLAKE_AVX512:
226 def_or_undef (parse_in, "__skylake_avx512");
227 def_or_undef (parse_in, "__skylake_avx512__");
228 break;
c234d831
UB
229 case PROCESSOR_CANNONLAKE:
230 def_or_undef (parse_in, "__cannonlake");
231 def_or_undef (parse_in, "__cannonlake__");
232 break;
79ab5364
JK
233 case PROCESSOR_ICELAKE_CLIENT:
234 def_or_undef (parse_in, "__icelake_client");
235 def_or_undef (parse_in, "__icelake_client__");
236 break;
237 case PROCESSOR_ICELAKE_SERVER:
238 def_or_undef (parse_in, "__icelake_server");
239 def_or_undef (parse_in, "__icelake_server__");
02da1e9c 240 break;
7cab07f0
WX
241 case PROCESSOR_CASCADELAKE:
242 def_or_undef (parse_in, "__cascadelake");
243 def_or_undef (parse_in, "__cascadelake__");
244 break;
a9fcfec3
HL
245 case PROCESSOR_TIGERLAKE:
246 def_or_undef (parse_in, "__tigerlake");
247 def_or_undef (parse_in, "__tigerlake__");
248 break;
249 case PROCESSOR_COOPERLAKE:
250 def_or_undef (parse_in, "__cooperlake");
251 def_or_undef (parse_in, "__cooperlake__");
ba9c87d3
CL
252 break;
253 case PROCESSOR_SAPPHIRERAPIDS:
254 def_or_undef (parse_in, "__sapphirerapids");
255 def_or_undef (parse_in, "__sapphirerapids__");
256 break;
339ffc5a
HJ
257 case PROCESSOR_GRANITERAPIDS:
258 def_or_undef (parse_in, "__graniterapids");
259 def_or_undef (parse_in, "__graniterapids__");
260 break;
ba9c87d3
CL
261 case PROCESSOR_ALDERLAKE:
262 def_or_undef (parse_in, "__alderlake");
263 def_or_undef (parse_in, "__alderlake__");
264 break;
c02c39fa
CL
265 case PROCESSOR_ROCKETLAKE:
266 def_or_undef (parse_in, "__rocketlake");
267 def_or_undef (parse_in, "__rocketlake__");
268 break;
ab442df7
MM
269 /* use PROCESSOR_max to not set/unset the arch macro. */
270 case PROCESSOR_max:
271 break;
9a7f94d7 272 case PROCESSOR_INTEL:
9d532162 273 case PROCESSOR_GENERIC:
ab442df7
MM
274 gcc_unreachable ();
275 }
276
277 /* Built-ins based on -mtune=. */
278 switch (tune)
279 {
280 case PROCESSOR_I386:
281 def_or_undef (parse_in, "__tune_i386__");
282 break;
283 case PROCESSOR_I486:
284 def_or_undef (parse_in, "__tune_i486__");
285 break;
286 case PROCESSOR_PENTIUM:
287 def_or_undef (parse_in, "__tune_i586__");
288 def_or_undef (parse_in, "__tune_pentium__");
289 if (last_tune_char == 'x')
290 def_or_undef (parse_in, "__tune_pentium_mmx__");
291 break;
292 case PROCESSOR_PENTIUMPRO:
293 def_or_undef (parse_in, "__tune_i686__");
294 def_or_undef (parse_in, "__tune_pentiumpro__");
295 switch (last_tune_char)
296 {
297 case '3':
298 def_or_undef (parse_in, "__tune_pentium3__");
299 /* FALLTHRU */
300 case '2':
301 def_or_undef (parse_in, "__tune_pentium2__");
302 break;
303 }
304 break;
305 case PROCESSOR_GEODE:
306 def_or_undef (parse_in, "__tune_geode__");
307 break;
308 case PROCESSOR_K6:
309 def_or_undef (parse_in, "__tune_k6__");
310 if (last_tune_char == '2')
311 def_or_undef (parse_in, "__tune_k6_2__");
312 else if (last_tune_char == '3')
313 def_or_undef (parse_in, "__tune_k6_3__");
314 else if (isa_flag & OPTION_MASK_ISA_3DNOW)
315 def_or_undef (parse_in, "__tune_k6_3__");
316 break;
317 case PROCESSOR_ATHLON:
318 def_or_undef (parse_in, "__tune_athlon__");
319 if (isa_flag & OPTION_MASK_ISA_SSE)
320 def_or_undef (parse_in, "__tune_athlon_sse__");
321 break;
322 case PROCESSOR_K8:
323 def_or_undef (parse_in, "__tune_k8__");
324 break;
325 case PROCESSOR_AMDFAM10:
326 def_or_undef (parse_in, "__tune_amdfam10__");
327 break;
1133125e
HJ
328 case PROCESSOR_BDVER1:
329 def_or_undef (parse_in, "__tune_bdver1__");
330 break;
4d652a18
HJ
331 case PROCESSOR_BDVER2:
332 def_or_undef (parse_in, "__tune_bdver2__");
333 break;
eb2f2b44
GG
334 case PROCESSOR_BDVER3:
335 def_or_undef (parse_in, "__tune_bdver3__");
ed97ad47
GG
336 break;
337 case PROCESSOR_BDVER4:
338 def_or_undef (parse_in, "__tune_bdver4__");
eb2f2b44 339 break;
9ce29eb0
VK
340 case PROCESSOR_ZNVER1:
341 def_or_undef (parse_in, "__tune_znver1__");
342 break;
2901f42f
VK
343 case PROCESSOR_ZNVER2:
344 def_or_undef (parse_in, "__tune_znver2__");
345 break;
3e2ae3ee
VK
346 case PROCESSOR_ZNVER3:
347 def_or_undef (parse_in, "__tune_znver3__");
348 break;
bf3b532b
TJ
349 case PROCESSOR_ZNVER4:
350 def_or_undef (parse_in, "__tune_znver4__");
351 break;
eb2f2b44 352 case PROCESSOR_BTVER1:
14b52538
CF
353 def_or_undef (parse_in, "__tune_btver1__");
354 break;
e32bfc16
VK
355 case PROCESSOR_BTVER2:
356 def_or_undef (parse_in, "__tune_btver2__");
357 break;
a239aff8
M
358 case PROCESSOR_LUJIAZUI:
359 def_or_undef (parse_in, "__tune_lujiazui__");
360 break;
ab442df7
MM
361 case PROCESSOR_PENTIUM4:
362 def_or_undef (parse_in, "__tune_pentium4__");
363 break;
364 case PROCESSOR_NOCONA:
365 def_or_undef (parse_in, "__tune_nocona__");
366 break;
340ef734 367 case PROCESSOR_CORE2:
ab442df7
MM
368 def_or_undef (parse_in, "__tune_core2__");
369 break;
d3c11974 370 case PROCESSOR_NEHALEM:
b2b01543 371 def_or_undef (parse_in, "__tune_corei7__");
d3c11974 372 def_or_undef (parse_in, "__tune_nehalem__");
b2b01543 373 break;
d3c11974 374 case PROCESSOR_SANDYBRIDGE:
fd5564d3 375 def_or_undef (parse_in, "__tune_corei7_avx__");
d3c11974 376 def_or_undef (parse_in, "__tune_sandybridge__");
fd5564d3 377 break;
3a579e09
VY
378 case PROCESSOR_HASWELL:
379 def_or_undef (parse_in, "__tune_core_avx2__");
d3c11974 380 def_or_undef (parse_in, "__tune_haswell__");
3a579e09 381 break;
d3c11974 382 case PROCESSOR_BONNELL:
b6837b94 383 def_or_undef (parse_in, "__tune_atom__");
d3c11974 384 def_or_undef (parse_in, "__tune_bonnell__");
b6837b94 385 break;
d3c11974 386 case PROCESSOR_SILVERMONT:
0b871ccf 387 def_or_undef (parse_in, "__tune_slm__");
d3c11974 388 def_or_undef (parse_in, "__tune_silvermont__");
0b871ccf 389 break;
50e461df
OM
390 case PROCESSOR_GOLDMONT:
391 def_or_undef (parse_in, "__tune_goldmont__");
392 break;
74b2bb19
OM
393 case PROCESSOR_GOLDMONT_PLUS:
394 def_or_undef (parse_in, "__tune_goldmont_plus__");
395 break;
a548a5a1
OM
396 case PROCESSOR_TREMONT:
397 def_or_undef (parse_in, "__tune_tremont__");
398 break;
fabe470b
HJ
399 case PROCESSOR_SIERRAFOREST:
400 def_or_undef (parse_in, "__tune_sierraforest__");
401 break;
c4f8f8af
HL
402 case PROCESSOR_GRANDRIDGE:
403 def_or_undef (parse_in, "__tune_grandridge__");
404 break;
52747219
IT
405 case PROCESSOR_KNL:
406 def_or_undef (parse_in, "__tune_knl__");
407 break;
cace2309
SP
408 case PROCESSOR_KNM:
409 def_or_undef (parse_in, "__tune_knm__");
410 break;
176a3386
OM
411 case PROCESSOR_SKYLAKE:
412 def_or_undef (parse_in, "__tune_skylake__");
413 break;
06caf59d
KY
414 case PROCESSOR_SKYLAKE_AVX512:
415 def_or_undef (parse_in, "__tune_skylake_avx512__");
416 break;
c234d831
UB
417 case PROCESSOR_CANNONLAKE:
418 def_or_undef (parse_in, "__tune_cannonlake__");
419 break;
79ab5364
JK
420 case PROCESSOR_ICELAKE_CLIENT:
421 def_or_undef (parse_in, "__tune_icelake_client__");
422 break;
423 case PROCESSOR_ICELAKE_SERVER:
424 def_or_undef (parse_in, "__tune_icelake_server__");
02da1e9c 425 break;
2d6b2e28
L
426 case PROCESSOR_LAKEMONT:
427 def_or_undef (parse_in, "__tune_lakemont__");
45cef0e9 428 break;
7cab07f0
WX
429 case PROCESSOR_CASCADELAKE:
430 def_or_undef (parse_in, "__tune_cascadelake__");
431 break;
a9fcfec3
HL
432 case PROCESSOR_TIGERLAKE:
433 def_or_undef (parse_in, "__tune_tigerlake__");
434 break;
435 case PROCESSOR_COOPERLAKE:
436 def_or_undef (parse_in, "__tune_cooperlake__");
437 break;
ba9c87d3
CL
438 case PROCESSOR_SAPPHIRERAPIDS:
439 def_or_undef (parse_in, "__tune_sapphirerapids__");
440 break;
441 case PROCESSOR_ALDERLAKE:
442 def_or_undef (parse_in, "__tune_alderlake__");
443 break;
c02c39fa
CL
444 case PROCESSOR_ROCKETLAKE:
445 def_or_undef (parse_in, "__tune_rocketlake__");
446 break;
339ffc5a
HJ
447 case PROCESSOR_GRANITERAPIDS:
448 def_or_undef (parse_in, "__tune_graniterapids__");
449 break;
9a7f94d7 450 case PROCESSOR_INTEL:
9d532162 451 case PROCESSOR_GENERIC:
ab442df7
MM
452 break;
453 /* use PROCESSOR_max to not set/unset the tune macro. */
454 case PROCESSOR_max:
455 break;
456 }
457
bb664f09
UB
458 switch (ix86_cmodel)
459 {
460 case CM_SMALL:
461 case CM_SMALL_PIC:
462 def_or_undef (parse_in, "__code_model_small__");
463 break;
464 case CM_MEDIUM:
465 case CM_MEDIUM_PIC:
466 def_or_undef (parse_in, "__code_model_medium__");
467 break;
468 case CM_LARGE:
469 case CM_LARGE_PIC:
470 def_or_undef (parse_in, "__code_model_large__");
471 break;
472 case CM_32:
473 def_or_undef (parse_in, "__code_model_32__");
474 break;
475 case CM_KERNEL:
476 def_or_undef (parse_in, "__code_model_kernel__");
477 break;
478 default:
479 ;
480 }
481
8cf86e14 482 if (isa_flag2 & OPTION_MASK_ISA2_WBNOINVD)
13b93d4b 483 def_or_undef (parse_in, "__WBNOINVD__");
8cf86e14 484 if (isa_flag2 & OPTION_MASK_ISA2_AVX512VP2INTERSECT)
e21b52af 485 def_or_undef (parse_in, "__AVX512VP2INTERSECT__");
ab442df7
MM
486 if (isa_flag & OPTION_MASK_ISA_MMX)
487 def_or_undef (parse_in, "__MMX__");
488 if (isa_flag & OPTION_MASK_ISA_3DNOW)
489 def_or_undef (parse_in, "__3dNOW__");
490 if (isa_flag & OPTION_MASK_ISA_3DNOW_A)
491 def_or_undef (parse_in, "__3dNOW_A__");
492 if (isa_flag & OPTION_MASK_ISA_SSE)
493 def_or_undef (parse_in, "__SSE__");
494 if (isa_flag & OPTION_MASK_ISA_SSE2)
495 def_or_undef (parse_in, "__SSE2__");
496 if (isa_flag & OPTION_MASK_ISA_SSE3)
497 def_or_undef (parse_in, "__SSE3__");
498 if (isa_flag & OPTION_MASK_ISA_SSSE3)
499 def_or_undef (parse_in, "__SSSE3__");
500 if (isa_flag & OPTION_MASK_ISA_SSE4_1)
501 def_or_undef (parse_in, "__SSE4_1__");
502 if (isa_flag & OPTION_MASK_ISA_SSE4_2)
503 def_or_undef (parse_in, "__SSE4_2__");
504 if (isa_flag & OPTION_MASK_ISA_AES)
505 def_or_undef (parse_in, "__AES__");
c1618f82
AI
506 if (isa_flag & OPTION_MASK_ISA_SHA)
507 def_or_undef (parse_in, "__SHA__");
ab442df7
MM
508 if (isa_flag & OPTION_MASK_ISA_PCLMUL)
509 def_or_undef (parse_in, "__PCLMUL__");
95879c72
L
510 if (isa_flag & OPTION_MASK_ISA_AVX)
511 def_or_undef (parse_in, "__AVX__");
7afac110
KY
512 if (isa_flag & OPTION_MASK_ISA_AVX2)
513 def_or_undef (parse_in, "__AVX2__");
3f97cb0b
AI
514 if (isa_flag & OPTION_MASK_ISA_AVX512F)
515 def_or_undef (parse_in, "__AVX512F__");
516 if (isa_flag & OPTION_MASK_ISA_AVX512ER)
517 def_or_undef (parse_in, "__AVX512ER__");
518 if (isa_flag & OPTION_MASK_ISA_AVX512CD)
519 def_or_undef (parse_in, "__AVX512CD__");
520 if (isa_flag & OPTION_MASK_ISA_AVX512PF)
521 def_or_undef (parse_in, "__AVX512PF__");
07165dd7
AI
522 if (isa_flag & OPTION_MASK_ISA_AVX512DQ)
523 def_or_undef (parse_in, "__AVX512DQ__");
b525d943
AI
524 if (isa_flag & OPTION_MASK_ISA_AVX512BW)
525 def_or_undef (parse_in, "__AVX512BW__");
f4af595f
AI
526 if (isa_flag & OPTION_MASK_ISA_AVX512VL)
527 def_or_undef (parse_in, "__AVX512VL__");
3dcc8af5
IT
528 if (isa_flag & OPTION_MASK_ISA_AVX512VBMI)
529 def_or_undef (parse_in, "__AVX512VBMI__");
4190ea38
IT
530 if (isa_flag & OPTION_MASK_ISA_AVX512IFMA)
531 def_or_undef (parse_in, "__AVX512IFMA__");
8cf86e14 532 if (isa_flag2 & OPTION_MASK_ISA2_AVX5124VNNIW)
5fbb13a7 533 def_or_undef (parse_in, "__AVX5124VNNIW__");
b1ccd09a 534 if (isa_flag & OPTION_MASK_ISA_AVX512VBMI2)
fca51879 535 def_or_undef (parse_in, "__AVX512VBMI2__");
fefab953 536 if (isa_flag & OPTION_MASK_ISA_AVX512VNNI)
98966963 537 def_or_undef (parse_in, "__AVX512VNNI__");
8cf86e14 538 if (isa_flag2 & OPTION_MASK_ISA2_PCONFIG)
13b93d4b 539 def_or_undef (parse_in, "__PCONFIG__");
8cf86e14 540 if (isa_flag2 & OPTION_MASK_ISA2_SGX)
73e32c47 541 def_or_undef (parse_in, "__SGX__");
8cf86e14 542 if (isa_flag2 & OPTION_MASK_ISA2_AVX5124FMAPS)
5fbb13a7 543 def_or_undef (parse_in, "__AVX5124FMAPS__");
2e34b5bc 544 if (isa_flag & OPTION_MASK_ISA_AVX512BITALG)
e2a29465 545 def_or_undef (parse_in, "__AVX512BITALG__");
2e34b5bc 546 if (isa_flag & OPTION_MASK_ISA_AVX512VPOPCNTDQ)
79fc8ffe 547 def_or_undef (parse_in, "__AVX512VPOPCNTDQ__");
95879c72
L
548 if (isa_flag & OPTION_MASK_ISA_FMA)
549 def_or_undef (parse_in, "__FMA__");
bf2eaa3f
KY
550 if (isa_flag & OPTION_MASK_ISA_RTM)
551 def_or_undef (parse_in, "__RTM__");
ab442df7
MM
552 if (isa_flag & OPTION_MASK_ISA_SSE4A)
553 def_or_undef (parse_in, "__SSE4A__");
cbf2e4d4
HJ
554 if (isa_flag & OPTION_MASK_ISA_FMA4)
555 def_or_undef (parse_in, "__FMA4__");
43a8b705
HJ
556 if (isa_flag & OPTION_MASK_ISA_XOP)
557 def_or_undef (parse_in, "__XOP__");
3e901069
HJ
558 if (isa_flag & OPTION_MASK_ISA_LWP)
559 def_or_undef (parse_in, "__LWP__");
13c0eb43
SP
560 if (isa_flag & OPTION_MASK_ISA_ABM)
561 def_or_undef (parse_in, "__ABM__");
91afcfa3
QN
562 if (isa_flag & OPTION_MASK_ISA_BMI)
563 def_or_undef (parse_in, "__BMI__");
82feeb8d
L
564 if (isa_flag & OPTION_MASK_ISA_BMI2)
565 def_or_undef (parse_in, "__BMI2__");
5fcafa60
KY
566 if (isa_flag & OPTION_MASK_ISA_LZCNT)
567 def_or_undef (parse_in, "__LZCNT__");
94d13ad1
QN
568 if (isa_flag & OPTION_MASK_ISA_TBM)
569 def_or_undef (parse_in, "__TBM__");
39671f87
L
570 if (isa_flag & OPTION_MASK_ISA_CRC32)
571 def_or_undef (parse_in, "__CRC32__");
3bccee03
SP
572 if (isa_flag & OPTION_MASK_ISA_POPCNT)
573 def_or_undef (parse_in, "__POPCNT__");
4ee89d5f
L
574 if (isa_flag & OPTION_MASK_ISA_FSGSBASE)
575 def_or_undef (parse_in, "__FSGSBASE__");
576 if (isa_flag & OPTION_MASK_ISA_RDRND)
577 def_or_undef (parse_in, "__RDRND__");
578 if (isa_flag & OPTION_MASK_ISA_F16C)
579 def_or_undef (parse_in, "__F16C__");
4c340b5d
KY
580 if (isa_flag & OPTION_MASK_ISA_RDSEED)
581 def_or_undef (parse_in, "__RDSEED__");
e61c94dd
KY
582 if (isa_flag & OPTION_MASK_ISA_PRFCHW)
583 def_or_undef (parse_in, "__PRFCHW__");
d05e383b
MZ
584 if (isa_flag & OPTION_MASK_ISA_ADX)
585 def_or_undef (parse_in, "__ADX__");
3a0d99bb
AI
586 if (isa_flag & OPTION_MASK_ISA_FXSR)
587 def_or_undef (parse_in, "__FXSR__");
588 if (isa_flag & OPTION_MASK_ISA_XSAVE)
589 def_or_undef (parse_in, "__XSAVE__");
590 if (isa_flag & OPTION_MASK_ISA_XSAVEOPT)
591 def_or_undef (parse_in, "__XSAVEOPT__");
43b3f52f
IT
592 if (isa_flag & OPTION_MASK_ISA_PREFETCHWT1)
593 def_or_undef (parse_in, "__PREFETCHWT1__");
ab442df7
MM
594 if ((fpmath & FPMATH_SSE) && (isa_flag & OPTION_MASK_ISA_SSE))
595 def_or_undef (parse_in, "__SSE_MATH__");
596 if ((fpmath & FPMATH_SSE) && (isa_flag & OPTION_MASK_ISA_SSE2))
597 def_or_undef (parse_in, "__SSE2_MATH__");
9cdea277
IT
598 if (isa_flag & OPTION_MASK_ISA_CLFLUSHOPT)
599 def_or_undef (parse_in, "__CLFLUSHOPT__");
8cf86e14 600 if (isa_flag2 & OPTION_MASK_ISA2_CLZERO)
9ce29eb0 601 def_or_undef (parse_in, "__CLZERO__");
9cdea277
IT
602 if (isa_flag & OPTION_MASK_ISA_XSAVEC)
603 def_or_undef (parse_in, "__XSAVEC__");
604 if (isa_flag & OPTION_MASK_ISA_XSAVES)
605 def_or_undef (parse_in, "__XSAVES__");
9c3bca11
IT
606 if (isa_flag & OPTION_MASK_ISA_CLWB)
607 def_or_undef (parse_in, "__CLWB__");
8cf86e14 608 if (isa_flag2 & OPTION_MASK_ISA2_MWAITX)
500a08b2 609 def_or_undef (parse_in, "__MWAITX__");
41a4ef22
KY
610 if (isa_flag & OPTION_MASK_ISA_PKU)
611 def_or_undef (parse_in, "__PKU__");
8cf86e14 612 if (isa_flag2 & OPTION_MASK_ISA2_RDPID)
1d516992 613 def_or_undef (parse_in, "__RDPID__");
d4bc3829 614 if (isa_flag & OPTION_MASK_ISA_GFNI)
b8cca31c 615 def_or_undef (parse_in, "__GFNI__");
e95dda95
L
616 if ((isa_flag & OPTION_MASK_ISA_SHSTK))
617 def_or_undef (parse_in, "__SHSTK__");
8cf86e14 618 if (isa_flag2 & OPTION_MASK_ISA2_VAES)
b7b0a4fa 619 def_or_undef (parse_in, "__VAES__");
6557be99
JK
620 if (isa_flag & OPTION_MASK_ISA_VPCLMULQDQ)
621 def_or_undef (parse_in, "__VPCLMULQDQ__");
37d51c75
SP
622 if (isa_flag & OPTION_MASK_ISA_MOVDIRI)
623 def_or_undef (parse_in, "__MOVDIRI__");
8cf86e14 624 if (isa_flag2 & OPTION_MASK_ISA2_MOVDIR64B)
37d51c75 625 def_or_undef (parse_in, "__MOVDIR64B__");
8cf86e14 626 if (isa_flag2 & OPTION_MASK_ISA2_WAITPKG)
55f31ed1 627 def_or_undef (parse_in, "__WAITPKG__");
8cf86e14 628 if (isa_flag2 & OPTION_MASK_ISA2_CLDEMOTE)
f8d9957e 629 def_or_undef (parse_in, "__CLDEMOTE__");
366386c7 630 if (isa_flag2 & OPTION_MASK_ISA2_SERIALIZE)
631 def_or_undef (parse_in, "__SERIALIZE__");
8cf86e14 632 if (isa_flag2 & OPTION_MASK_ISA2_PTWRITE)
41f8d1fc 633 def_or_undef (parse_in, "__PTWRITE__");
8cf86e14 634 if (isa_flag2 & OPTION_MASK_ISA2_AVX512BF16)
4f0e90fa 635 def_or_undef (parse_in, "__AVX512BF16__");
a6841211
GX
636 if (isa_flag2 & OPTION_MASK_ISA2_AVX512FP16)
637 def_or_undef (parse_in, "__AVX512FP16__");
dfa61b9e
L
638 if (TARGET_MMX_WITH_SSE)
639 def_or_undef (parse_in, "__MMX_WITH_SSE__");
8cf86e14 640 if (isa_flag2 & OPTION_MASK_ISA2_ENQCMD)
6a10feda 641 def_or_undef (parse_in, "__ENQCMD__");
1e47cb35 642 if (isa_flag2 & OPTION_MASK_ISA2_TSXLDTRK)
643 def_or_undef (parse_in, "__TSXLDTRK__");
5c609842 644 if (isa_flag2 & OPTION_MASK_ISA2_AMX_TILE)
645 def_or_undef (parse_in, "__AMX_TILE__");
646 if (isa_flag2 & OPTION_MASK_ISA2_AMX_INT8)
647 def_or_undef (parse_in, "__AMX_INT8__");
648 if (isa_flag2 & OPTION_MASK_ISA2_AMX_BF16)
649 def_or_undef (parse_in, "__AMX_BF16__");
92e652d8
FW
650 if (isa_flag & OPTION_MASK_ISA_SAHF)
651 def_or_undef (parse_in, "__LAHF_SAHF__");
652 if (isa_flag2 & OPTION_MASK_ISA2_MOVBE)
653 def_or_undef (parse_in, "__MOVBE__");
299a53d7 654 if (isa_flag2 & OPTION_MASK_ISA2_UINTR)
655 def_or_undef (parse_in, "__UINTR__");
83927c63
HW
656 if (isa_flag2 & OPTION_MASK_ISA2_HRESET)
657 def_or_undef (parse_in, "__HRESET__");
632a2f50 658 if (isa_flag2 & OPTION_MASK_ISA2_KL)
659 def_or_undef (parse_in, "__KL__");
660 if (isa_flag2 & OPTION_MASK_ISA2_WIDEKL)
661 def_or_undef (parse_in, "__WIDEKL__");
ca813880 662 if (isa_flag2 & OPTION_MASK_ISA2_AVXVNNI)
663 def_or_undef (parse_in, "__AVXVNNI__");
825d0041
HW
664 if (isa_flag2 & OPTION_MASK_ISA2_AVXIFMA)
665 def_or_undef (parse_in, "__AVXIFMA__");
40667594
KL
666 if (isa_flag2 & OPTION_MASK_ISA2_AVXVNNIINT8)
667 def_or_undef (parse_in, "__AVXVNNIINT8__");
58685b93 668 if (isa_flag2 & OPTION_MASK_ISA2_AVXNECONVERT)
669 def_or_undef (parse_in, "__AVXNECONVERT__");
152834fe
HJ
670 if (isa_flag2 & OPTION_MASK_ISA2_CMPCCXADD)
671 def_or_undef (parse_in, "__CMPCCXADD__");
2b4a0396
HW
672 if (isa_flag2 & OPTION_MASK_ISA2_AMX_FP16)
673 def_or_undef (parse_in, "__AMX_FP16__");
b384d9a0
HJ
674 if (isa_flag2 & OPTION_MASK_ISA2_PREFETCHI)
675 def_or_undef (parse_in, "__PREFETCHI__");
4cf1c619 676 if (isa_flag2 & OPTION_MASK_ISA2_RAOINT)
677 def_or_undef (parse_in, "__RAOINT__");
d9063947
L
678 if (TARGET_IAMCU)
679 {
680 def_or_undef (parse_in, "__iamcu");
681 def_or_undef (parse_in, "__iamcu__");
682 }
ab442df7
MM
683}
684
685\f
5779e713
MM
686/* Hook to validate the current #pragma GCC target and set the state, and
687 update the macros based on what was changed. If ARGS is NULL, then
688 POP_TARGET is used to reset the options. */
ab442df7
MM
689
690static bool
5779e713 691ix86_pragma_target_parse (tree args, tree pop_target)
ab442df7 692{
ba948b37
JJ
693 tree prev_tree
694 = build_target_option_node (&global_options, &global_options_set);
ab442df7
MM
695 tree cur_tree;
696 struct cl_target_option *prev_opt;
697 struct cl_target_option *cur_opt;
df385b9c
L
698 HOST_WIDE_INT prev_isa;
699 HOST_WIDE_INT cur_isa;
700 HOST_WIDE_INT diff_isa;
5fbb13a7
KY
701 HOST_WIDE_INT prev_isa2;
702 HOST_WIDE_INT cur_isa2;
703 HOST_WIDE_INT diff_isa2;
ab442df7
MM
704 enum processor_type prev_arch;
705 enum processor_type prev_tune;
706 enum processor_type cur_arch;
707 enum processor_type cur_tune;
708
709 if (! args)
710 {
97db2bf7 711 cur_tree = (pop_target ? pop_target : target_option_default_node);
ba948b37 712 cl_target_option_restore (&global_options, &global_options_set,
46625112 713 TREE_TARGET_OPTION (cur_tree));
ab442df7
MM
714 }
715 else
716 {
cc2a672a
ML
717 cur_tree = ix86_valid_target_attribute_tree (NULL_TREE, args,
718 &global_options,
719 &global_options_set, 0);
97db2bf7
ST
720 if (!cur_tree || cur_tree == error_mark_node)
721 {
ba948b37 722 cl_target_option_restore (&global_options, &global_options_set,
97db2bf7
ST
723 TREE_TARGET_OPTION (prev_tree));
724 return false;
725 }
ab442df7
MM
726 }
727
728 target_option_current_node = cur_tree;
97db2bf7 729 ix86_reset_previous_fndecl ();
ab442df7
MM
730
731 /* Figure out the previous/current isa, arch, tune and the differences. */
732 prev_opt = TREE_TARGET_OPTION (prev_tree);
733 cur_opt = TREE_TARGET_OPTION (cur_tree);
e3339d0f
JM
734 prev_isa = prev_opt->x_ix86_isa_flags;
735 cur_isa = cur_opt->x_ix86_isa_flags;
ab442df7 736 diff_isa = (prev_isa ^ cur_isa);
5fbb13a7
KY
737 prev_isa2 = prev_opt->x_ix86_isa_flags2;
738 cur_isa2 = cur_opt->x_ix86_isa_flags2;
739 diff_isa2 = (prev_isa2 ^ cur_isa2);
32e8bb8e
ILT
740 prev_arch = (enum processor_type) prev_opt->arch;
741 prev_tune = (enum processor_type) prev_opt->tune;
742 cur_arch = (enum processor_type) cur_opt->arch;
743 cur_tune = (enum processor_type) cur_opt->tune;
ab442df7
MM
744
745 /* If the same processor is used for both previous and current options, don't
746 change the macros. */
747 if (cur_arch == prev_arch)
748 cur_arch = prev_arch = PROCESSOR_max;
749
750 if (cur_tune == prev_tune)
751 cur_tune = prev_tune = PROCESSOR_max;
752
753 /* Undef all of the macros for that are no longer current. */
1dbe26b9 754 cpp_force_token_locations (parse_in, BUILTINS_LOCATION);
ab442df7 755 ix86_target_macros_internal (prev_isa & diff_isa,
5fbb13a7 756 prev_isa2 & diff_isa2,
ab442df7
MM
757 prev_arch,
758 prev_tune,
8023568e 759 (enum fpmath_unit) prev_opt->x_ix86_fpmath,
ab442df7 760 cpp_undef);
1dbe26b9 761 cpp_stop_forcing_token_locations (parse_in);
ab442df7 762
fa5d6c75
JJ
763 /* For the definitions, ensure all newly defined macros are considered
764 as used for -Wunused-macros. There is no point warning about the
765 compiler predefined macros. */
766 cpp_options *cpp_opts = cpp_get_options (parse_in);
767 unsigned char saved_warn_unused_macros = cpp_opts->warn_unused_macros;
768 cpp_opts->warn_unused_macros = 0;
769
ab442df7 770 /* Define all of the macros for new options that were just turned on. */
1dbe26b9 771 cpp_force_token_locations (parse_in, BUILTINS_LOCATION);
ab442df7 772 ix86_target_macros_internal (cur_isa & diff_isa,
5fbb13a7 773 cur_isa2 & diff_isa2,
ab442df7
MM
774 cur_arch,
775 cur_tune,
8023568e 776 (enum fpmath_unit) cur_opt->x_ix86_fpmath,
ab442df7 777 cpp_define);
1dbe26b9 778 cpp_stop_forcing_token_locations (parse_in);
ab442df7 779
fa5d6c75
JJ
780 cpp_opts->warn_unused_macros = saved_warn_unused_macros;
781
ab442df7
MM
782 return true;
783}
784\f
785/* Function to tell the preprocessor about the defines for the current target. */
786
787void
788ix86_target_macros (void)
789{
790 /* 32/64-bit won't change with target specific options, so do the assert and
791 builtin_define_std calls here. */
792 if (TARGET_64BIT)
793 {
794 cpp_assert (parse_in, "cpu=x86_64");
795 cpp_assert (parse_in, "machine=x86_64");
796 cpp_define (parse_in, "__amd64");
797 cpp_define (parse_in, "__amd64__");
798 cpp_define (parse_in, "__x86_64");
799 cpp_define (parse_in, "__x86_64__");
6573c644
L
800 if (TARGET_X32)
801 {
802 cpp_define (parse_in, "_ILP32");
803 cpp_define (parse_in, "__ILP32__");
804 }
ab442df7
MM
805 }
806 else
807 {
808 cpp_assert (parse_in, "cpu=i386");
809 cpp_assert (parse_in, "machine=i386");
810 builtin_define_std ("i386");
13a46321
GP
811 cpp_define (parse_in, "_ILP32");
812 cpp_define (parse_in, "__ILP32__");
ab442df7
MM
813 }
814
02ac9503
UB
815 if (!TARGET_80387)
816 cpp_define (parse_in, "_SOFT_FLOAT");
817
c637141a
L
818 if (TARGET_LONG_DOUBLE_64)
819 cpp_define (parse_in, "__LONG_DOUBLE_64__");
820
a2a1ddb5
L
821 if (TARGET_LONG_DOUBLE_128)
822 cpp_define (parse_in, "__LONG_DOUBLE_128__");
823
7d0df0ae
UB
824 cpp_define_formatted (parse_in, "__SIZEOF_FLOAT80__=%d",
825 GET_MODE_SIZE (XFmode));
30c0a59a
MG
826
827 cpp_define (parse_in, "__SIZEOF_FLOAT128__=16");
828
d5becc11
JJ
829 cpp_define_formatted (parse_in, "__ATOMIC_HLE_ACQUIRE=%d", IX86_HLE_ACQUIRE);
830 cpp_define_formatted (parse_in, "__ATOMIC_HLE_RELEASE=%d", IX86_HLE_RELEASE);
831
f767f583
RH
832 cpp_define (parse_in, "__GCC_ASM_FLAG_OUTPUTS__");
833
ab442df7 834 ix86_target_macros_internal (ix86_isa_flags,
5fbb13a7 835 ix86_isa_flags2,
ab442df7
MM
836 ix86_arch,
837 ix86_tune,
838 ix86_fpmath,
839 cpp_define);
00402c94
RH
840
841 cpp_define (parse_in, "__SEG_FS");
842 cpp_define (parse_in, "__SEG_GS");
e95dda95
L
843
844 if (flag_cf_protection != CF_NONE)
7d0df0ae 845 cpp_define_formatted (parse_in, "__CET__=%d", flag_cf_protection & ~CF_SET);
ab442df7
MM
846}
847
848\f
849/* Register target pragmas. We need to add the hook for parsing #pragma GCC
e53b6e56 850 option here rather than in i386.cc since it will pull in various preprocessor
ab442df7
MM
851 functions, and those are not present in languages like fortran without a
852 preprocessor. */
853
854void
855ix86_register_pragmas (void)
856{
5779e713
MM
857 /* Update pragma hook to allow parsing #pragma GCC target. */
858 targetm.target_option.pragma_parse = ix86_pragma_target_parse;
ab442df7 859
00402c94
RH
860 c_register_addr_space ("__seg_fs", ADDR_SPACE_SEG_FS);
861 c_register_addr_space ("__seg_gs", ADDR_SPACE_SEG_GS);
00402c94 862
ab442df7
MM
863#ifdef REGISTER_SUBTARGET_PRAGMAS
864 REGISTER_SUBTARGET_PRAGMAS ();
865#endif
866}