Debian Codegraph @

gcc/config/i386/i386-c.cc

raw
1 /* Subroutines used for macro/preprocessor support on the ia-32.
2 Copyright (C) 2008-2025 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
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)
9 any later version.
10
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.
15
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/>. */
19
20 #define IN_TARGET_CODE 1
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "target.h"
26 #include "c-family/c-common.h"
27 #include "memmodel.h"
28 #include "tm_p.h"
29 #include "c-family/c-pragma.h"
30
31 static bool ix86_pragma_target_parse (tree, tree);
32 static void ix86_target_macros_internal
33 (HOST_WIDE_INT, HOST_WIDE_INT, enum processor_type, enum processor_type, enum fpmath_unit,
34 void (*def_or_undef) (cpp_reader *, const char *));
35
36 /* Internal function to either define or undef the appropriate system
37 macros. */
38 static void
39 ix86_target_macros_internal (HOST_WIDE_INT isa_flag,
40 HOST_WIDE_INT isa_flag2,
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 {
47 /* For some of the k6/pentium varients there weren't separate ISA bits to
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;
63 case PROCESSOR_LAKEMONT:
64 /* Intel MCU is based on Intel Pentium CPU. */
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;
107 case PROCESSOR_BDVER1:
108 def_or_undef (parse_in, "__bdver1");
109 def_or_undef (parse_in, "__bdver1__");
110 break;
111 case PROCESSOR_BDVER2:
112 def_or_undef (parse_in, "__bdver2");
113 def_or_undef (parse_in, "__bdver2__");
114 break;
115 case PROCESSOR_BDVER3:
116 def_or_undef (parse_in, "__bdver3");
117 def_or_undef (parse_in, "__bdver3__");
118 break;
119 case PROCESSOR_BDVER4:
120 def_or_undef (parse_in, "__bdver4");
121 def_or_undef (parse_in, "__bdver4__");
122 break;
123 case PROCESSOR_ZNVER1:
124 def_or_undef (parse_in, "__znver1");
125 def_or_undef (parse_in, "__znver1__");
126 break;
127 case PROCESSOR_ZNVER2:
128 def_or_undef (parse_in, "__znver2");
129 def_or_undef (parse_in, "__znver2__");
130 break;
131 case PROCESSOR_ZNVER3:
132 def_or_undef (parse_in, "__znver3");
133 def_or_undef (parse_in, "__znver3__");
134 break;
135 case PROCESSOR_ZNVER4:
136 def_or_undef (parse_in, "__znver4");
137 def_or_undef (parse_in, "__znver4__");
138 break;
139 case PROCESSOR_ZNVER5:
140 def_or_undef (parse_in, "__znver5");
141 def_or_undef (parse_in, "__znver5__");
142 break;
143 case PROCESSOR_BTVER1:
144 def_or_undef (parse_in, "__btver1");
145 def_or_undef (parse_in, "__btver1__");
146 break;
147 case PROCESSOR_BTVER2:
148 def_or_undef (parse_in, "__btver2");
149 def_or_undef (parse_in, "__btver2__");
150 break;
151 case PROCESSOR_LUJIAZUI:
152 def_or_undef (parse_in, "__lujiazui");
153 def_or_undef (parse_in, "__lujiazui__");
154 break;
155 case PROCESSOR_YONGFENG:
156 def_or_undef (parse_in, "__yongfeng");
157 def_or_undef (parse_in, "__yongfeng__");
158 break;
159 case PROCESSOR_SHIJIDADAO:
160 def_or_undef (parse_in, "__shijidadao");
161 def_or_undef (parse_in, "__shijidadao__");
162 break;
163 case PROCESSOR_PENTIUM4:
164 def_or_undef (parse_in, "__pentium4");
165 def_or_undef (parse_in, "__pentium4__");
166 break;
167 case PROCESSOR_NOCONA:
168 def_or_undef (parse_in, "__nocona");
169 def_or_undef (parse_in, "__nocona__");
170 break;
171 case PROCESSOR_CORE2:
172 def_or_undef (parse_in, "__core2");
173 def_or_undef (parse_in, "__core2__");
174 break;
175 case PROCESSOR_NEHALEM:
176 def_or_undef (parse_in, "__corei7");
177 def_or_undef (parse_in, "__corei7__");
178 def_or_undef (parse_in, "__nehalem");
179 def_or_undef (parse_in, "__nehalem__");
180 break;
181 case PROCESSOR_SANDYBRIDGE:
182 def_or_undef (parse_in, "__corei7_avx");
183 def_or_undef (parse_in, "__corei7_avx__");
184 def_or_undef (parse_in, "__sandybridge");
185 def_or_undef (parse_in, "__sandybridge__");
186 break;
187 case PROCESSOR_HASWELL:
188 def_or_undef (parse_in, "__core_avx2");
189 def_or_undef (parse_in, "__core_avx2__");
190 def_or_undef (parse_in, "__haswell");
191 def_or_undef (parse_in, "__haswell__");
192 break;
193 case PROCESSOR_BONNELL:
194 def_or_undef (parse_in, "__atom");
195 def_or_undef (parse_in, "__atom__");
196 def_or_undef (parse_in, "__bonnell");
197 def_or_undef (parse_in, "__bonnell__");
198 break;
199 case PROCESSOR_SILVERMONT:
200 def_or_undef (parse_in, "__slm");
201 def_or_undef (parse_in, "__slm__");
202 def_or_undef (parse_in, "__silvermont");
203 def_or_undef (parse_in, "__silvermont__");
204 break;
205 case PROCESSOR_GOLDMONT:
206 def_or_undef (parse_in, "__goldmont");
207 def_or_undef (parse_in, "__goldmont__");
208 break;
209 case PROCESSOR_GOLDMONT_PLUS:
210 def_or_undef (parse_in, "__goldmont_plus");
211 def_or_undef (parse_in, "__goldmont_plus__");
212 break;
213 case PROCESSOR_TREMONT:
214 def_or_undef (parse_in, "__tremont");
215 def_or_undef (parse_in, "__tremont__");
216 break;
217 case PROCESSOR_SIERRAFOREST:
218 def_or_undef (parse_in, "__sierraforest");
219 def_or_undef (parse_in, "__sierraforest__");
220 break;
221 case PROCESSOR_GRANDRIDGE:
222 def_or_undef (parse_in, "__grandridge");
223 def_or_undef (parse_in, "__grandridge__");
224 break;
225 case PROCESSOR_CLEARWATERFOREST:
226 def_or_undef (parse_in, "__clearwaterforest");
227 def_or_undef (parse_in, "__clearwaterforest__");
228 break;
229 break;
230 case PROCESSOR_SKYLAKE:
231 def_or_undef (parse_in, "__skylake");
232 def_or_undef (parse_in, "__skylake__");
233 break;
234 case PROCESSOR_SKYLAKE_AVX512:
235 def_or_undef (parse_in, "__skylake_avx512");
236 def_or_undef (parse_in, "__skylake_avx512__");
237 break;
238 case PROCESSOR_CANNONLAKE:
239 def_or_undef (parse_in, "__cannonlake");
240 def_or_undef (parse_in, "__cannonlake__");
241 break;
242 case PROCESSOR_ICELAKE_CLIENT:
243 def_or_undef (parse_in, "__icelake_client");
244 def_or_undef (parse_in, "__icelake_client__");
245 break;
246 case PROCESSOR_ICELAKE_SERVER:
247 def_or_undef (parse_in, "__icelake_server");
248 def_or_undef (parse_in, "__icelake_server__");
249 break;
250 case PROCESSOR_CASCADELAKE:
251 def_or_undef (parse_in, "__cascadelake");
252 def_or_undef (parse_in, "__cascadelake__");
253 break;
254 case PROCESSOR_TIGERLAKE:
255 def_or_undef (parse_in, "__tigerlake");
256 def_or_undef (parse_in, "__tigerlake__");
257 break;
258 case PROCESSOR_COOPERLAKE:
259 def_or_undef (parse_in, "__cooperlake");
260 def_or_undef (parse_in, "__cooperlake__");
261 break;
262 case PROCESSOR_SAPPHIRERAPIDS:
263 def_or_undef (parse_in, "__sapphirerapids");
264 def_or_undef (parse_in, "__sapphirerapids__");
265 break;
266 case PROCESSOR_GRANITERAPIDS:
267 def_or_undef (parse_in, "__graniterapids");
268 def_or_undef (parse_in, "__graniterapids__");
269 break;
270 case PROCESSOR_GRANITERAPIDS_D:
271 def_or_undef (parse_in, "__graniterapids_d");
272 def_or_undef (parse_in, "__graniterapids_d__");
273 break;
274 case PROCESSOR_ALDERLAKE:
275 def_or_undef (parse_in, "__alderlake");
276 def_or_undef (parse_in, "__alderlake__");
277 break;
278 case PROCESSOR_ROCKETLAKE:
279 def_or_undef (parse_in, "__rocketlake");
280 def_or_undef (parse_in, "__rocketlake__");
281 break;
282 case PROCESSOR_ARROWLAKE:
283 def_or_undef (parse_in, "__arrowlake");
284 def_or_undef (parse_in, "__arrowlake__");
285 break;
286 case PROCESSOR_ARROWLAKE_S:
287 def_or_undef (parse_in, "__arrowlake_s");
288 def_or_undef (parse_in, "__arrowlake_s__");
289 break;
290 case PROCESSOR_PANTHERLAKE:
291 def_or_undef (parse_in, "__pantherlake");
292 def_or_undef (parse_in, "__pantherlake__");
293 break;
294 case PROCESSOR_DIAMONDRAPIDS:
295 def_or_undef (parse_in, "__diamondrapids");
296 def_or_undef (parse_in, "__diamondrapids__");
297 break;
298 case PROCESSOR_C86_4G_M4:
299 def_or_undef (parse_in, "__c86_4g_m4");
300 def_or_undef (parse_in, "__c86_4g_m4__");
301 break;
302 case PROCESSOR_C86_4G_M6:
303 def_or_undef (parse_in, "__c86_4g_m6");
304 def_or_undef (parse_in, "__c86_4g_m6__");
305 break;
306 case PROCESSOR_C86_4G_M7:
307 def_or_undef (parse_in, "__c86_4g_m7");
308 def_or_undef (parse_in, "__c86_4g_m7__");
309 break;
310 /* use PROCESSOR_max to not set/unset the arch macro. */
311 case PROCESSOR_max:
312 break;
313 case PROCESSOR_INTEL:
314 case PROCESSOR_GENERIC:
315 gcc_unreachable ();
316 }
317
318 /* Built-ins based on -mtune=. */
319 switch (tune)
320 {
321 case PROCESSOR_I386:
322 def_or_undef (parse_in, "__tune_i386__");
323 break;
324 case PROCESSOR_I486:
325 def_or_undef (parse_in, "__tune_i486__");
326 break;
327 case PROCESSOR_PENTIUM:
328 def_or_undef (parse_in, "__tune_i586__");
329 def_or_undef (parse_in, "__tune_pentium__");
330 if (last_tune_char == 'x')
331 def_or_undef (parse_in, "__tune_pentium_mmx__");
332 break;
333 case PROCESSOR_PENTIUMPRO:
334 def_or_undef (parse_in, "__tune_i686__");
335 def_or_undef (parse_in, "__tune_pentiumpro__");
336 switch (last_tune_char)
337 {
338 case '3':
339 def_or_undef (parse_in, "__tune_pentium3__");
340 /* FALLTHRU */
341 case '2':
342 def_or_undef (parse_in, "__tune_pentium2__");
343 break;
344 }
345 break;
346 case PROCESSOR_GEODE:
347 def_or_undef (parse_in, "__tune_geode__");
348 break;
349 case PROCESSOR_K6:
350 def_or_undef (parse_in, "__tune_k6__");
351 if (last_tune_char == '2')
352 def_or_undef (parse_in, "__tune_k6_2__");
353 else if (last_tune_char == '3')
354 def_or_undef (parse_in, "__tune_k6_3__");
355 else if (isa_flag & OPTION_MASK_ISA_3DNOW)
356 def_or_undef (parse_in, "__tune_k6_3__");
357 break;
358 case PROCESSOR_ATHLON:
359 def_or_undef (parse_in, "__tune_athlon__");
360 if (isa_flag & OPTION_MASK_ISA_SSE)
361 def_or_undef (parse_in, "__tune_athlon_sse__");
362 break;
363 case PROCESSOR_K8:
364 def_or_undef (parse_in, "__tune_k8__");
365 break;
366 case PROCESSOR_AMDFAM10:
367 def_or_undef (parse_in, "__tune_amdfam10__");
368 break;
369 case PROCESSOR_BDVER1:
370 def_or_undef (parse_in, "__tune_bdver1__");
371 break;
372 case PROCESSOR_BDVER2:
373 def_or_undef (parse_in, "__tune_bdver2__");
374 break;
375 case PROCESSOR_BDVER3:
376 def_or_undef (parse_in, "__tune_bdver3__");
377 break;
378 case PROCESSOR_BDVER4:
379 def_or_undef (parse_in, "__tune_bdver4__");
380 break;
381 case PROCESSOR_ZNVER1:
382 def_or_undef (parse_in, "__tune_znver1__");
383 break;
384 case PROCESSOR_ZNVER2:
385 def_or_undef (parse_in, "__tune_znver2__");
386 break;
387 case PROCESSOR_ZNVER3:
388 def_or_undef (parse_in, "__tune_znver3__");
389 break;
390 case PROCESSOR_ZNVER4:
391 def_or_undef (parse_in, "__tune_znver4__");
392 break;
393 case PROCESSOR_ZNVER5:
394 def_or_undef (parse_in, "__tune_znver5__");
395 break;
396 case PROCESSOR_BTVER1:
397 def_or_undef (parse_in, "__tune_btver1__");
398 break;
399 case PROCESSOR_BTVER2:
400 def_or_undef (parse_in, "__tune_btver2__");
401 break;
402 case PROCESSOR_LUJIAZUI:
403 def_or_undef (parse_in, "__tune_lujiazui__");
404 break;
405 case PROCESSOR_YONGFENG:
406 def_or_undef (parse_in, "__tune_yongfeng__");
407 break;
408 case PROCESSOR_SHIJIDADAO:
409 def_or_undef (parse_in, "__tune_shijidadao__");
410 break;
411 case PROCESSOR_PENTIUM4:
412 def_or_undef (parse_in, "__tune_pentium4__");
413 break;
414 case PROCESSOR_NOCONA:
415 def_or_undef (parse_in, "__tune_nocona__");
416 break;
417 case PROCESSOR_CORE2:
418 def_or_undef (parse_in, "__tune_core2__");
419 break;
420 case PROCESSOR_NEHALEM:
421 def_or_undef (parse_in, "__tune_corei7__");
422 def_or_undef (parse_in, "__tune_nehalem__");
423 break;
424 case PROCESSOR_SANDYBRIDGE:
425 def_or_undef (parse_in, "__tune_corei7_avx__");
426 def_or_undef (parse_in, "__tune_sandybridge__");
427 break;
428 case PROCESSOR_HASWELL:
429 def_or_undef (parse_in, "__tune_core_avx2__");
430 def_or_undef (parse_in, "__tune_haswell__");
431 break;
432 case PROCESSOR_BONNELL:
433 def_or_undef (parse_in, "__tune_atom__");
434 def_or_undef (parse_in, "__tune_bonnell__");
435 break;
436 case PROCESSOR_SILVERMONT:
437 def_or_undef (parse_in, "__tune_slm__");
438 def_or_undef (parse_in, "__tune_silvermont__");
439 break;
440 case PROCESSOR_GOLDMONT:
441 def_or_undef (parse_in, "__tune_goldmont__");
442 break;
443 case PROCESSOR_GOLDMONT_PLUS:
444 def_or_undef (parse_in, "__tune_goldmont_plus__");
445 break;
446 case PROCESSOR_TREMONT:
447 def_or_undef (parse_in, "__tune_tremont__");
448 break;
449 case PROCESSOR_SIERRAFOREST:
450 def_or_undef (parse_in, "__tune_sierraforest__");
451 break;
452 case PROCESSOR_GRANDRIDGE:
453 def_or_undef (parse_in, "__tune_grandridge__");
454 break;
455 case PROCESSOR_CLEARWATERFOREST:
456 def_or_undef (parse_in, "__tune_clearwaterforest__");
457 break;
458 case PROCESSOR_SKYLAKE:
459 def_or_undef (parse_in, "__tune_skylake__");
460 break;
461 case PROCESSOR_SKYLAKE_AVX512:
462 def_or_undef (parse_in, "__tune_skylake_avx512__");
463 break;
464 case PROCESSOR_CANNONLAKE:
465 def_or_undef (parse_in, "__tune_cannonlake__");
466 break;
467 case PROCESSOR_ICELAKE_CLIENT:
468 def_or_undef (parse_in, "__tune_icelake_client__");
469 break;
470 case PROCESSOR_ICELAKE_SERVER:
471 def_or_undef (parse_in, "__tune_icelake_server__");
472 break;
473 case PROCESSOR_LAKEMONT:
474 def_or_undef (parse_in, "__tune_lakemont__");
475 break;
476 case PROCESSOR_CASCADELAKE:
477 def_or_undef (parse_in, "__tune_cascadelake__");
478 break;
479 case PROCESSOR_TIGERLAKE:
480 def_or_undef (parse_in, "__tune_tigerlake__");
481 break;
482 case PROCESSOR_COOPERLAKE:
483 def_or_undef (parse_in, "__tune_cooperlake__");
484 break;
485 case PROCESSOR_SAPPHIRERAPIDS:
486 def_or_undef (parse_in, "__tune_sapphirerapids__");
487 break;
488 case PROCESSOR_ALDERLAKE:
489 def_or_undef (parse_in, "__tune_alderlake__");
490 break;
491 case PROCESSOR_ROCKETLAKE:
492 def_or_undef (parse_in, "__tune_rocketlake__");
493 break;
494 case PROCESSOR_GRANITERAPIDS:
495 def_or_undef (parse_in, "__tune_graniterapids__");
496 break;
497 case PROCESSOR_GRANITERAPIDS_D:
498 def_or_undef (parse_in, "__tune_graniterapids_d__");
499 break;
500 case PROCESSOR_ARROWLAKE:
501 def_or_undef (parse_in, "__tune_arrowlake__");
502 break;
503 case PROCESSOR_ARROWLAKE_S:
504 def_or_undef (parse_in, "__tune_arrowlake_s__");
505 break;
506 case PROCESSOR_PANTHERLAKE:
507 def_or_undef (parse_in, "__tune_pantherlake__");
508 break;
509 case PROCESSOR_DIAMONDRAPIDS:
510 def_or_undef (parse_in, "__tune_diamondrapids__");
511 break;
512 case PROCESSOR_C86_4G_M4:
513 def_or_undef (parse_in, "__tune_c86_4g_m4__");
514 break;
515 case PROCESSOR_C86_4G_M6:
516 def_or_undef (parse_in, "__tune_c86_4g_m6__");
517 break;
518 case PROCESSOR_C86_4G_M7:
519 def_or_undef (parse_in, "__tune_c86_4g_m7__");
520 break;
521 case PROCESSOR_INTEL:
522 case PROCESSOR_GENERIC:
523 break;
524 /* use PROCESSOR_max to not set/unset the tune macro. */
525 case PROCESSOR_max:
526 break;
527 }
528
529 switch (ix86_cmodel)
530 {
531 case CM_SMALL:
532 case CM_SMALL_PIC:
533 def_or_undef (parse_in, "__code_model_small__");
534 break;
535 case CM_MEDIUM:
536 case CM_MEDIUM_PIC:
537 def_or_undef (parse_in, "__code_model_medium__");
538 break;
539 case CM_LARGE:
540 case CM_LARGE_PIC:
541 def_or_undef (parse_in, "__code_model_large__");
542 break;
543 case CM_32:
544 def_or_undef (parse_in, "__code_model_32__");
545 break;
546 case CM_KERNEL:
547 def_or_undef (parse_in, "__code_model_kernel__");
548 break;
549 default:
550 ;
551 }
552
553 if (isa_flag2 & OPTION_MASK_ISA2_WBNOINVD)
554 def_or_undef (parse_in, "__WBNOINVD__");
555 if (isa_flag2 & OPTION_MASK_ISA2_AVX512VP2INTERSECT)
556 def_or_undef (parse_in, "__AVX512VP2INTERSECT__");
557 if (isa_flag & OPTION_MASK_ISA_MMX)
558 def_or_undef (parse_in, "__MMX__");
559 if (isa_flag & OPTION_MASK_ISA_3DNOW)
560 def_or_undef (parse_in, "__3dNOW__");
561 if (isa_flag & OPTION_MASK_ISA_3DNOW_A)
562 def_or_undef (parse_in, "__3dNOW_A__");
563 if (isa_flag & OPTION_MASK_ISA_SSE)
564 def_or_undef (parse_in, "__SSE__");
565 if (isa_flag & OPTION_MASK_ISA_SSE2)
566 def_or_undef (parse_in, "__SSE2__");
567 if (isa_flag & OPTION_MASK_ISA_SSE3)
568 def_or_undef (parse_in, "__SSE3__");
569 if (isa_flag & OPTION_MASK_ISA_SSSE3)
570 def_or_undef (parse_in, "__SSSE3__");
571 if (isa_flag & OPTION_MASK_ISA_SSE4_1)
572 def_or_undef (parse_in, "__SSE4_1__");
573 if (isa_flag & OPTION_MASK_ISA_SSE4_2)
574 def_or_undef (parse_in, "__SSE4_2__");
575 if (isa_flag & OPTION_MASK_ISA_AES)
576 def_or_undef (parse_in, "__AES__");
577 if (isa_flag & OPTION_MASK_ISA_SHA)
578 def_or_undef (parse_in, "__SHA__");
579 if (isa_flag & OPTION_MASK_ISA_PCLMUL)
580 def_or_undef (parse_in, "__PCLMUL__");
581 if (isa_flag & OPTION_MASK_ISA_AVX)
582 def_or_undef (parse_in, "__AVX__");
583 if (isa_flag & OPTION_MASK_ISA_AVX2)
584 def_or_undef (parse_in, "__AVX2__");
585 if (isa_flag & OPTION_MASK_ISA_AVX512F)
586 def_or_undef (parse_in, "__AVX512F__");
587 if (isa_flag & OPTION_MASK_ISA_AVX512CD)
588 def_or_undef (parse_in, "__AVX512CD__");
589 if (isa_flag & OPTION_MASK_ISA_AVX512DQ)
590 def_or_undef (parse_in, "__AVX512DQ__");
591 if (isa_flag & OPTION_MASK_ISA_AVX512BW)
592 def_or_undef (parse_in, "__AVX512BW__");
593 if (isa_flag & OPTION_MASK_ISA_AVX512VL)
594 {
595 def_or_undef (parse_in, "__AVX512VL__");
596 def_or_undef (parse_in, "__EVEX256__");
597 }
598 if (isa_flag & OPTION_MASK_ISA_AVX512VBMI)
599 def_or_undef (parse_in, "__AVX512VBMI__");
600 if (isa_flag & OPTION_MASK_ISA_AVX512IFMA)
601 def_or_undef (parse_in, "__AVX512IFMA__");
602 if (isa_flag & OPTION_MASK_ISA_AVX512VBMI2)
603 def_or_undef (parse_in, "__AVX512VBMI2__");
604 if (isa_flag & OPTION_MASK_ISA_AVX512VNNI)
605 def_or_undef (parse_in, "__AVX512VNNI__");
606 if (isa_flag2 & OPTION_MASK_ISA2_PCONFIG)
607 def_or_undef (parse_in, "__PCONFIG__");
608 if (isa_flag2 & OPTION_MASK_ISA2_SGX)
609 def_or_undef (parse_in, "__SGX__");
610 if (isa_flag & OPTION_MASK_ISA_AVX512BITALG)
611 def_or_undef (parse_in, "__AVX512BITALG__");
612 if (isa_flag & OPTION_MASK_ISA_AVX512VPOPCNTDQ)
613 def_or_undef (parse_in, "__AVX512VPOPCNTDQ__");
614 if (isa_flag & OPTION_MASK_ISA_FMA)
615 def_or_undef (parse_in, "__FMA__");
616 if (isa_flag & OPTION_MASK_ISA_RTM)
617 def_or_undef (parse_in, "__RTM__");
618 if (isa_flag & OPTION_MASK_ISA_SSE4A)
619 def_or_undef (parse_in, "__SSE4A__");
620 if (isa_flag & OPTION_MASK_ISA_FMA4)
621 def_or_undef (parse_in, "__FMA4__");
622 if (isa_flag & OPTION_MASK_ISA_XOP)
623 def_or_undef (parse_in, "__XOP__");
624 if (isa_flag & OPTION_MASK_ISA_LWP)
625 def_or_undef (parse_in, "__LWP__");
626 if (isa_flag & OPTION_MASK_ISA_ABM)
627 def_or_undef (parse_in, "__ABM__");
628 if (isa_flag & OPTION_MASK_ISA_BMI)
629 def_or_undef (parse_in, "__BMI__");
630 if (isa_flag & OPTION_MASK_ISA_BMI2)
631 def_or_undef (parse_in, "__BMI2__");
632 if (isa_flag & OPTION_MASK_ISA_LZCNT)
633 def_or_undef (parse_in, "__LZCNT__");
634 if (isa_flag & OPTION_MASK_ISA_TBM)
635 def_or_undef (parse_in, "__TBM__");
636 if (isa_flag & OPTION_MASK_ISA_CRC32)
637 def_or_undef (parse_in, "__CRC32__");
638 if (isa_flag & OPTION_MASK_ISA_POPCNT)
639 def_or_undef (parse_in, "__POPCNT__");
640 if (isa_flag & OPTION_MASK_ISA_FSGSBASE)
641 def_or_undef (parse_in, "__FSGSBASE__");
642 if (isa_flag & OPTION_MASK_ISA_RDRND)
643 def_or_undef (parse_in, "__RDRND__");
644 if (isa_flag & OPTION_MASK_ISA_F16C)
645 def_or_undef (parse_in, "__F16C__");
646 if (isa_flag & OPTION_MASK_ISA_RDSEED)
647 def_or_undef (parse_in, "__RDSEED__");
648 if (isa_flag & OPTION_MASK_ISA_PRFCHW)
649 def_or_undef (parse_in, "__PRFCHW__");
650 if (isa_flag & OPTION_MASK_ISA_ADX)
651 def_or_undef (parse_in, "__ADX__");
652 if (isa_flag & OPTION_MASK_ISA_FXSR)
653 def_or_undef (parse_in, "__FXSR__");
654 if (isa_flag & OPTION_MASK_ISA_XSAVE)
655 def_or_undef (parse_in, "__XSAVE__");
656 if (isa_flag & OPTION_MASK_ISA_XSAVEOPT)
657 def_or_undef (parse_in, "__XSAVEOPT__");
658 if ((fpmath & FPMATH_SSE) && (isa_flag & OPTION_MASK_ISA_SSE))
659 def_or_undef (parse_in, "__SSE_MATH__");
660 if ((fpmath & FPMATH_SSE) && (isa_flag & OPTION_MASK_ISA_SSE2))
661 def_or_undef (parse_in, "__SSE2_MATH__");
662 if (isa_flag & OPTION_MASK_ISA_CLFLUSHOPT)
663 def_or_undef (parse_in, "__CLFLUSHOPT__");
664 if (isa_flag2 & OPTION_MASK_ISA2_CLZERO)
665 def_or_undef (parse_in, "__CLZERO__");
666 if (isa_flag & OPTION_MASK_ISA_XSAVEC)
667 def_or_undef (parse_in, "__XSAVEC__");
668 if (isa_flag & OPTION_MASK_ISA_XSAVES)
669 def_or_undef (parse_in, "__XSAVES__");
670 if (isa_flag & OPTION_MASK_ISA_CLWB)
671 def_or_undef (parse_in, "__CLWB__");
672 if (isa_flag2 & OPTION_MASK_ISA2_MWAITX)
673 def_or_undef (parse_in, "__MWAITX__");
674 if (isa_flag & OPTION_MASK_ISA_PKU)
675 def_or_undef (parse_in, "__PKU__");
676 if (isa_flag2 & OPTION_MASK_ISA2_RDPID)
677 def_or_undef (parse_in, "__RDPID__");
678 if (isa_flag & OPTION_MASK_ISA_GFNI)
679 def_or_undef (parse_in, "__GFNI__");
680 if ((isa_flag & OPTION_MASK_ISA_SHSTK))
681 def_or_undef (parse_in, "__SHSTK__");
682 if (isa_flag2 & OPTION_MASK_ISA2_VAES)
683 def_or_undef (parse_in, "__VAES__");
684 if (isa_flag & OPTION_MASK_ISA_VPCLMULQDQ)
685 def_or_undef (parse_in, "__VPCLMULQDQ__");
686 if (isa_flag & OPTION_MASK_ISA_MOVDIRI)
687 def_or_undef (parse_in, "__MOVDIRI__");
688 if (isa_flag2 & OPTION_MASK_ISA2_MOVDIR64B)
689 def_or_undef (parse_in, "__MOVDIR64B__");
690 if (isa_flag2 & OPTION_MASK_ISA2_WAITPKG)
691 def_or_undef (parse_in, "__WAITPKG__");
692 if (isa_flag2 & OPTION_MASK_ISA2_CLDEMOTE)
693 def_or_undef (parse_in, "__CLDEMOTE__");
694 if (isa_flag2 & OPTION_MASK_ISA2_SERIALIZE)
695 def_or_undef (parse_in, "__SERIALIZE__");
696 if (isa_flag2 & OPTION_MASK_ISA2_PTWRITE)
697 def_or_undef (parse_in, "__PTWRITE__");
698 if (isa_flag2 & OPTION_MASK_ISA2_AVX512BF16)
699 def_or_undef (parse_in, "__AVX512BF16__");
700 if (isa_flag2 & OPTION_MASK_ISA2_AVX512FP16)
701 def_or_undef (parse_in, "__AVX512FP16__");
702 if (TARGET_MMX_WITH_SSE)
703 def_or_undef (parse_in, "__MMX_WITH_SSE__");
704 if (isa_flag2 & OPTION_MASK_ISA2_ENQCMD)
705 def_or_undef (parse_in, "__ENQCMD__");
706 if (isa_flag2 & OPTION_MASK_ISA2_TSXLDTRK)
707 def_or_undef (parse_in, "__TSXLDTRK__");
708 if (isa_flag2 & OPTION_MASK_ISA2_AMX_TILE)
709 def_or_undef (parse_in, "__AMX_TILE__");
710 if (isa_flag2 & OPTION_MASK_ISA2_AMX_INT8)
711 def_or_undef (parse_in, "__AMX_INT8__");
712 if (isa_flag2 & OPTION_MASK_ISA2_AMX_BF16)
713 def_or_undef (parse_in, "__AMX_BF16__");
714 if (isa_flag & OPTION_MASK_ISA_SAHF)
715 def_or_undef (parse_in, "__LAHF_SAHF__");
716 if (isa_flag2 & OPTION_MASK_ISA2_MOVBE)
717 def_or_undef (parse_in, "__MOVBE__");
718 if (isa_flag2 & OPTION_MASK_ISA2_UINTR)
719 def_or_undef (parse_in, "__UINTR__");
720 if (isa_flag2 & OPTION_MASK_ISA2_HRESET)
721 def_or_undef (parse_in, "__HRESET__");
722 if (isa_flag2 & OPTION_MASK_ISA2_KL)
723 def_or_undef (parse_in, "__KL__");
724 if (isa_flag2 & OPTION_MASK_ISA2_WIDEKL)
725 def_or_undef (parse_in, "__WIDEKL__");
726 if (isa_flag2 & OPTION_MASK_ISA2_AVXVNNI)
727 def_or_undef (parse_in, "__AVXVNNI__");
728 if (isa_flag2 & OPTION_MASK_ISA2_AVXIFMA)
729 def_or_undef (parse_in, "__AVXIFMA__");
730 if (isa_flag2 & OPTION_MASK_ISA2_AVXVNNIINT8)
731 def_or_undef (parse_in, "__AVXVNNIINT8__");
732 if (isa_flag2 & OPTION_MASK_ISA2_AVXNECONVERT)
733 def_or_undef (parse_in, "__AVXNECONVERT__");
734 if (isa_flag2 & OPTION_MASK_ISA2_CMPCCXADD)
735 def_or_undef (parse_in, "__CMPCCXADD__");
736 if (isa_flag2 & OPTION_MASK_ISA2_AMX_FP16)
737 def_or_undef (parse_in, "__AMX_FP16__");
738 if (isa_flag2 & OPTION_MASK_ISA2_PREFETCHI)
739 def_or_undef (parse_in, "__PREFETCHI__");
740 if (isa_flag2 & OPTION_MASK_ISA2_RAOINT)
741 def_or_undef (parse_in, "__RAOINT__");
742 if (isa_flag2 & OPTION_MASK_ISA2_AMX_COMPLEX)
743 def_or_undef (parse_in, "__AMX_COMPLEX__");
744 if (isa_flag2 & OPTION_MASK_ISA2_AVXVNNIINT16)
745 def_or_undef (parse_in, "__AVXVNNIINT16__");
746 if (isa_flag2 & OPTION_MASK_ISA2_SM3)
747 def_or_undef (parse_in, "__SM3__");
748 if (isa_flag2 & OPTION_MASK_ISA2_SHA512)
749 def_or_undef (parse_in, "__SHA512__");
750 if (isa_flag2 & OPTION_MASK_ISA2_SM4)
751 def_or_undef (parse_in, "__SM4__");
752 if (isa_flag2 & OPTION_MASK_ISA2_EVEX512)
753 def_or_undef (parse_in, "__EVEX512__");
754 if (isa_flag2 & OPTION_MASK_ISA2_USER_MSR)
755 def_or_undef (parse_in, "__USER_MSR__");
756 if (isa_flag2 & OPTION_MASK_ISA2_AVX10_1_256)
757 def_or_undef (parse_in, "__AVX10_1_256__");
758 if (isa_flag2 & OPTION_MASK_ISA2_AVX10_1)
759 def_or_undef (parse_in, "__AVX10_1__");
760 if (isa_flag2 & OPTION_MASK_ISA2_APX_F)
761 def_or_undef (parse_in, "__APX_F__");
762 if (ix86_apx_inline_asm_use_gpr32)
763 def_or_undef (parse_in, "__APX_INLINE_ASM_USE_GPR32__");
764 if (isa_flag2 & OPTION_MASK_ISA2_AVX10_2)
765 def_or_undef (parse_in, "__AVX10_2__");
766 if (isa_flag2 & OPTION_MASK_ISA2_AMX_AVX512)
767 def_or_undef (parse_in, "__AMX_AVX512__");
768 if (isa_flag2 & OPTION_MASK_ISA2_AMX_TF32)
769 def_or_undef (parse_in, "__AMX_TF32__");
770 if (isa_flag2 & OPTION_MASK_ISA2_AMX_TRANSPOSE)
771 def_or_undef (parse_in, "__AMX_TRANSPOSE__");
772 if (isa_flag2 & OPTION_MASK_ISA2_AMX_FP8)
773 def_or_undef (parse_in, "__AMX_FP8__");
774 if (isa_flag2 & OPTION_MASK_ISA2_MOVRS)
775 def_or_undef (parse_in, "__MOVRS__");
776 if (isa_flag2 & OPTION_MASK_ISA2_AMX_MOVRS)
777 def_or_undef (parse_in, "__AMX_MOVRS__");
778 if (TARGET_IAMCU)
779 {
780 def_or_undef (parse_in, "__iamcu");
781 def_or_undef (parse_in, "__iamcu__");
782 }
783 }
784
785
786 /* Hook to validate the current #pragma GCC target and set the state, and
787 update the macros based on what was changed. If ARGS is NULL, then
788 POP_TARGET is used to reset the options. */
789
790 static bool
791 ix86_pragma_target_parse (tree args, tree pop_target)
792 {
793 tree prev_tree
794 = build_target_option_node (&global_options, &global_options_set);
795 tree cur_tree;
796 struct cl_target_option *prev_opt;
797 struct cl_target_option *cur_opt;
798 HOST_WIDE_INT prev_isa;
799 HOST_WIDE_INT cur_isa;
800 HOST_WIDE_INT diff_isa;
801 HOST_WIDE_INT prev_isa2;
802 HOST_WIDE_INT cur_isa2;
803 HOST_WIDE_INT diff_isa2;
804 enum processor_type prev_arch;
805 enum processor_type prev_tune;
806 enum processor_type cur_arch;
807 enum processor_type cur_tune;
808
809 if (! args)
810 {
811 cur_tree = (pop_target ? pop_target : target_option_default_node);
812 cl_target_option_restore (&global_options, &global_options_set,
813 TREE_TARGET_OPTION (cur_tree));
814 }
815 else
816 {
817 cur_tree = ix86_valid_target_attribute_tree (NULL_TREE, args,
818 &global_options,
819 &global_options_set, 0);
820 if (!cur_tree || cur_tree == error_mark_node)
821 {
822 cl_target_option_restore (&global_options, &global_options_set,
823 TREE_TARGET_OPTION (prev_tree));
824 return false;
825 }
826 }
827
828 target_option_current_node = cur_tree;
829 ix86_reset_previous_fndecl ();
830
831 /* Figure out the previous/current isa, arch, tune and the differences. */
832 prev_opt = TREE_TARGET_OPTION (prev_tree);
833 cur_opt = TREE_TARGET_OPTION (cur_tree);
834 prev_isa = prev_opt->x_ix86_isa_flags;
835 cur_isa = cur_opt->x_ix86_isa_flags;
836 diff_isa = (prev_isa ^ cur_isa);
837 prev_isa2 = prev_opt->x_ix86_isa_flags2;
838 cur_isa2 = cur_opt->x_ix86_isa_flags2;
839 diff_isa2 = (prev_isa2 ^ cur_isa2);
840 prev_arch = (enum processor_type) prev_opt->arch;
841 prev_tune = (enum processor_type) prev_opt->tune;
842 cur_arch = (enum processor_type) cur_opt->arch;
843 cur_tune = (enum processor_type) cur_opt->tune;
844
845 /* If the same processor is used for both previous and current options, don't
846 change the macros. */
847 if (cur_arch == prev_arch)
848 cur_arch = prev_arch = PROCESSOR_max;
849
850 if (cur_tune == prev_tune)
851 cur_tune = prev_tune = PROCESSOR_max;
852
853 /* Undef all of the macros for that are no longer current. */
854 cpp_force_token_locations (parse_in, BUILTINS_LOCATION);
855 ix86_target_macros_internal (prev_isa & diff_isa,
856 prev_isa2 & diff_isa2,
857 prev_arch,
858 prev_tune,
859 (enum fpmath_unit) prev_opt->x_ix86_fpmath,
860 cpp_undef);
861 cpp_stop_forcing_token_locations (parse_in);
862
863 /* For the definitions, ensure all newly defined macros are considered
864 as used for -Wunused-macros. There is no point warning about the
865 compiler predefined macros. */
866 cpp_options *cpp_opts = cpp_get_options (parse_in);
867 unsigned char saved_warn_unused_macros = cpp_opts->warn_unused_macros;
868 cpp_opts->warn_unused_macros = 0;
869
870 /* Define all of the macros for new options that were just turned on. */
871 cpp_force_token_locations (parse_in, BUILTINS_LOCATION);
872 ix86_target_macros_internal (cur_isa & diff_isa,
873 cur_isa2 & diff_isa2,
874 cur_arch,
875 cur_tune,
876 (enum fpmath_unit) cur_opt->x_ix86_fpmath,
877 cpp_define);
878 cpp_stop_forcing_token_locations (parse_in);
879
880 cpp_opts->warn_unused_macros = saved_warn_unused_macros;
881
882 return true;
883 }
884
885 /* Function to tell the preprocessor about the defines for the current target. */
886
887 void
888 ix86_target_macros (void)
889 {
890 /* 32/64-bit won't change with target specific options, so do the assert and
891 builtin_define_std calls here. */
892 if (TARGET_64BIT)
893 {
894 cpp_assert (parse_in, "cpu=x86_64");
895 cpp_assert (parse_in, "machine=x86_64");
896 cpp_define (parse_in, "__amd64");
897 cpp_define (parse_in, "__amd64__");
898 cpp_define (parse_in, "__x86_64");
899 cpp_define (parse_in, "__x86_64__");
900 if (TARGET_X32)
901 {
902 cpp_define (parse_in, "_ILP32");
903 cpp_define (parse_in, "__ILP32__");
904 }
905 }
906 else
907 {
908 cpp_assert (parse_in, "cpu=i386");
909 cpp_assert (parse_in, "machine=i386");
910 builtin_define_std ("i386");
911 cpp_define (parse_in, "_ILP32");
912 cpp_define (parse_in, "__ILP32__");
913 }
914
915 if (!TARGET_80387)
916 cpp_define (parse_in, "_SOFT_FLOAT");
917
918 /* HFmode/BFmode is supported without depending any isa
919 in scalar_mode_supported_p and libgcc_floating_mode_supported_p,
920 but according to psABI, they're really supported w/ SSE2 and above.
921 Since libstdc++ uses __STDCPP_FLOAT16_T__ and __STDCPP_BFLOAT16_T__
922 for backend support of the types, undef the macros to avoid
923 build failure, see PR109504. */
924 if (!TARGET_SSE2)
925 {
926 if (c_dialect_cxx () && cxx_dialect > cxx20)
927 {
928 cpp_undef (parse_in, "__STDCPP_FLOAT16_T__");
929 cpp_undef (parse_in, "__STDCPP_BFLOAT16_T__");
930 }
931 }
932
933 if (TARGET_LONG_DOUBLE_64)
934 cpp_define (parse_in, "__LONG_DOUBLE_64__");
935
936 if (TARGET_LONG_DOUBLE_128)
937 cpp_define (parse_in, "__LONG_DOUBLE_128__");
938
939 cpp_define_formatted (parse_in, "__SIZEOF_FLOAT80__=%d",
940 GET_MODE_SIZE (XFmode));
941
942 cpp_define (parse_in, "__SIZEOF_FLOAT128__=16");
943
944 cpp_define_formatted (parse_in, "__ATOMIC_HLE_ACQUIRE=%d", IX86_HLE_ACQUIRE);
945 cpp_define_formatted (parse_in, "__ATOMIC_HLE_RELEASE=%d", IX86_HLE_RELEASE);
946
947 cpp_define (parse_in, "__GCC_ASM_FLAG_OUTPUTS__");
948
949 ix86_target_macros_internal (ix86_isa_flags,
950 ix86_isa_flags2,
951 ix86_arch,
952 ix86_tune,
953 ix86_fpmath,
954 cpp_define);
955
956 cpp_define (parse_in, "__SEG_FS");
957 cpp_define (parse_in, "__SEG_GS");
958
959 if (flag_cf_protection != CF_NONE)
960 cpp_define_formatted (parse_in, "__CET__=%d", flag_cf_protection & ~CF_SET);
961 }
962
963
964 /* Register target pragmas. We need to add the hook for parsing #pragma GCC
965 option here rather than in i386.cc since it will pull in various preprocessor
966 functions, and those are not present in languages like fortran without a
967 preprocessor. */
968
969 void
970 ix86_register_pragmas (void)
971 {
972 /* Update pragma hook to allow parsing #pragma GCC target. */
973 targetm.target_option.pragma_parse = ix86_pragma_target_parse;
974
975 c_register_addr_space ("__seg_fs", ADDR_SPACE_SEG_FS);
976 c_register_addr_space ("__seg_gs", ADDR_SPACE_SEG_GS);
977
978 #ifdef REGISTER_SUBTARGET_PRAGMAS
979 REGISTER_SUBTARGET_PRAGMAS ();
980 #endif
981 }