Debian Codegraph @

gcc/common/config/i386/cpuinfo.h

raw
1 /* Get CPU type and Features for x86 processors.
2 Copyright (C) 2012-2025 Free Software Foundation, Inc.
3 Contributed by Sriraman Tallam ([email protected])
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
20
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
25
26 struct __processor_model
27 {
28 unsigned int __cpu_vendor;
29 unsigned int __cpu_type;
30 unsigned int __cpu_subtype;
31 /* The first 32 features are stored as bitmasks in __cpu_features.
32 The rest of features are stored as bitmasks in a separate array
33 of unsigned int. */
34 unsigned int __cpu_features[1];
35 };
36
37 struct __processor_model2
38 {
39 unsigned int __cpu_family;
40 unsigned int __cpu_model;
41 unsigned int __cpu_max_level;
42 unsigned int __cpu_ext_level;
43 };
44
45 #ifndef CHECK___builtin_cpu_is
46 # define CHECK___builtin_cpu_is(cpu)
47 #endif
48
49 #ifndef CHECK___builtin_cpu_supports
50 # define CHECK___builtin_cpu_supports(isa)
51 #endif
52
53 /* Return non-zero if the processor has feature F. */
54
55 static inline int
56 has_cpu_feature (struct __processor_model *cpu_model,
57 unsigned int *cpu_features2,
58 enum processor_features feature)
59 {
60 unsigned index, offset;
61 unsigned f = feature;
62
63 if (f < 32)
64 {
65 /* The first 32 features. */
66 return cpu_model->__cpu_features[0] & (1U << f);
67 }
68 else
69 {
70 /* The rest of features. cpu_features2[i] contains features from
71 (32 + i * 32) to (31 + 32 + i * 32), inclusively. */
72 f -= 32;
73 index = f / 32;
74 offset = f % 32;
75 return cpu_features2[index] & (1U << offset);
76 }
77 }
78
79 /* Save FEATURE to either CPU_MODEL or CPU_FEATURES2. */
80
81 static inline void
82 set_cpu_feature (struct __processor_model *cpu_model,
83 unsigned int *cpu_features2,
84 enum processor_features feature)
85 {
86 unsigned index, offset;
87 unsigned f = feature;
88
89 if (f < 32)
90 {
91 /* The first 32 features. */
92 cpu_model->__cpu_features[0] |= (1U << f);
93 }
94 else
95 {
96 /* The rest of features. cpu_features2[i] contains features from
97 (32 + i * 32) to (31 + 32 + i * 32), inclusively. */
98 f -= 32;
99 index = f / 32;
100 offset = f % 32;
101 cpu_features2[index] |= (1U << offset);
102 }
103 }
104
105 /* Drop FEATURE from either CPU_MODEL or CPU_FEATURES2. */
106
107 static inline void
108 reset_cpu_feature (struct __processor_model *cpu_model,
109 unsigned int *cpu_features2,
110 enum processor_features feature)
111 {
112 unsigned index, offset;
113 unsigned f = feature;
114
115 if (f < 32)
116 {
117 /* The first 32 features. */
118 cpu_model->__cpu_features[0] &= ~(1U << f);
119 }
120 else
121 {
122 /* The rest of features. cpu_features2[i] contains features from
123 (32 + i * 32) to (31 + 32 + i * 32), inclusively. */
124 f -= 32;
125 index = f / 32;
126 offset = f % 32;
127 cpu_features2[index] &= ~(1U << offset);
128 }
129 }
130
131 /* Get the specific type of AMD CPU and return AMD CPU name. Return
132 NULL for unknown AMD CPU. */
133
134 static inline const char *
135 get_amd_cpu (struct __processor_model *cpu_model,
136 struct __processor_model2 *cpu_model2,
137 unsigned int *cpu_features2)
138 {
139 const char *cpu = NULL;
140 unsigned int family = cpu_model2->__cpu_family;
141 unsigned int model = cpu_model2->__cpu_model;
142
143 switch (family)
144 {
145 case 0x10:
146 /* AMD Family 10h. */
147 cpu = "amdfam10";
148 cpu_model->__cpu_type = AMDFAM10H;
149 switch (model)
150 {
151 case 0x2:
152 /* Barcelona. */
153 CHECK___builtin_cpu_is ("amdfam10h");
154 CHECK___builtin_cpu_is ("barcelona");
155 cpu_model->__cpu_subtype = AMDFAM10H_BARCELONA;
156 break;
157 case 0x4:
158 /* Shanghai. */
159 CHECK___builtin_cpu_is ("amdfam10h");
160 CHECK___builtin_cpu_is ("shanghai");
161 cpu_model->__cpu_subtype = AMDFAM10H_SHANGHAI;
162 break;
163 case 0x8:
164 /* Istanbul. */
165 CHECK___builtin_cpu_is ("amdfam10h");
166 CHECK___builtin_cpu_is ("istanbul");
167 cpu_model->__cpu_subtype = AMDFAM10H_ISTANBUL;
168 break;
169 default:
170 break;
171 }
172 break;
173 case 0x14:
174 /* AMD Family 14h "btver1". */
175 cpu = "btver1";
176 CHECK___builtin_cpu_is ("btver1");
177 cpu_model->__cpu_type = AMD_BTVER1;
178 break;
179 case 0x15:
180 /* AMD Family 15h "Bulldozer". */
181 cpu_model->__cpu_type = AMDFAM15H;
182 if (model == 0x2)
183 {
184 /* Bulldozer version 2 "Piledriver" */
185 cpu = "bdver2";
186 CHECK___builtin_cpu_is ("bdver2");
187 cpu_model->__cpu_subtype = AMDFAM15H_BDVER2;
188 }
189 else if (model <= 0xf)
190 {
191 /* Bulldozer version 1. */
192 cpu = "bdver1";
193 CHECK___builtin_cpu_is ("bdver1");
194 cpu_model->__cpu_subtype = AMDFAM15H_BDVER1;
195 }
196 else if (model <= 0x2f)
197 {
198 /* Bulldozer version 2 "Piledriver" */
199 cpu = "bdver2";
200 CHECK___builtin_cpu_is ("bdver2");
201 cpu_model->__cpu_subtype = AMDFAM15H_BDVER2;
202 }
203 else if (model <= 0x4f)
204 {
205 /* Bulldozer version 3 "Steamroller" */
206 cpu = "bdver3";
207 CHECK___builtin_cpu_is ("bdver3");
208 cpu_model->__cpu_subtype = AMDFAM15H_BDVER3;
209 }
210 else if (model <= 0x7f)
211 {
212 /* Bulldozer version 4 "Excavator" */
213 cpu = "bdver4";
214 CHECK___builtin_cpu_is ("bdver4");
215 cpu_model->__cpu_subtype = AMDFAM15H_BDVER4;
216 }
217 else if (has_cpu_feature (cpu_model, cpu_features2,
218 FEATURE_AVX2))
219 {
220 cpu = "bdver4";
221 CHECK___builtin_cpu_is ("bdver4");
222 cpu_model->__cpu_subtype = AMDFAM15H_BDVER4;
223 }
224 else if (has_cpu_feature (cpu_model, cpu_features2,
225 FEATURE_XSAVEOPT))
226 {
227 cpu = "bdver3";
228 CHECK___builtin_cpu_is ("bdver3");
229 cpu_model->__cpu_subtype = AMDFAM15H_BDVER3;
230 }
231 else if (has_cpu_feature (cpu_model, cpu_features2,
232 FEATURE_BMI))
233 {
234 cpu = "bdver2";
235 CHECK___builtin_cpu_is ("bdver2");
236 cpu_model->__cpu_subtype = AMDFAM15H_BDVER2;
237 }
238 else if (has_cpu_feature (cpu_model, cpu_features2,
239 FEATURE_XOP))
240 {
241 cpu = "bdver1";
242 CHECK___builtin_cpu_is ("bdver1");
243 cpu_model->__cpu_subtype = AMDFAM15H_BDVER1;
244 }
245 break;
246 case 0x16:
247 /* AMD Family 16h "btver2" */
248 cpu = "btver2";
249 CHECK___builtin_cpu_is ("btver2");
250 cpu_model->__cpu_type = AMD_BTVER2;
251 break;
252 case 0x17:
253 cpu_model->__cpu_type = AMDFAM17H;
254 if (model <= 0x1f)
255 {
256 /* AMD family 17h version 1. */
257 cpu = "znver1";
258 CHECK___builtin_cpu_is ("znver1");
259 cpu_model->__cpu_subtype = AMDFAM17H_ZNVER1;
260 }
261 else if (model >= 0x30)
262 {
263 cpu = "znver2";
264 CHECK___builtin_cpu_is ("znver2");
265 cpu_model->__cpu_subtype = AMDFAM17H_ZNVER2;
266 }
267 else if (has_cpu_feature (cpu_model, cpu_features2,
268 FEATURE_CLWB))
269 {
270 cpu = "znver2";
271 CHECK___builtin_cpu_is ("znver2");
272 cpu_model->__cpu_subtype = AMDFAM17H_ZNVER2;
273 }
274 else if (has_cpu_feature (cpu_model, cpu_features2,
275 FEATURE_CLZERO))
276 {
277 cpu = "znver1";
278 CHECK___builtin_cpu_is ("znver1");
279 cpu_model->__cpu_subtype = AMDFAM17H_ZNVER1;
280 }
281 break;
282 case 0x19:
283 cpu_model->__cpu_type = AMDFAM19H;
284 /* AMD family 19h. */
285 if (model <= 0x0f)
286 {
287 cpu = "znver3";
288 CHECK___builtin_cpu_is ("znver3");
289 cpu_model->__cpu_subtype = AMDFAM19H_ZNVER3;
290 }
291 else if ((model >= 0x10 && model <= 0x1f)
292 || (model >= 0x60 && model <= 0xaf))
293 {
294 cpu = "znver4";
295 CHECK___builtin_cpu_is ("znver4");
296 cpu_model->__cpu_subtype = AMDFAM19H_ZNVER4;
297 }
298 else if (has_cpu_feature (cpu_model, cpu_features2,
299 FEATURE_AVX512F))
300 {
301 cpu = "znver4";
302 CHECK___builtin_cpu_is ("znver4");
303 cpu_model->__cpu_subtype = AMDFAM19H_ZNVER4;
304 }
305 else if (has_cpu_feature (cpu_model, cpu_features2,
306 FEATURE_VAES))
307 {
308 cpu = "znver3";
309 CHECK___builtin_cpu_is ("znver3");
310 cpu_model->__cpu_subtype = AMDFAM19H_ZNVER3;
311 }
312 break;
313 case 0x1a:
314 cpu_model->__cpu_type = AMDFAM1AH;
315 if (model <= 0x77)
316 {
317 cpu = "znver5";
318 CHECK___builtin_cpu_is ("znver5");
319 cpu_model->__cpu_subtype = AMDFAM1AH_ZNVER5;
320 }
321 else if (has_cpu_feature (cpu_model, cpu_features2,
322 FEATURE_AVX512VP2INTERSECT))
323 {
324 cpu = "znver5";
325 CHECK___builtin_cpu_is ("znver5");
326 cpu_model->__cpu_subtype = AMDFAM1AH_ZNVER5;
327 }
328 break;
329 default:
330 break;
331 }
332
333 return cpu;
334 }
335
336 /* Get the specific type of HYGON CPU and return HYGON CPU name. Return
337 NULL for unknown HYGON CPU. */
338
339 static inline const char *
340 get_hygon_cpu (struct __processor_model *cpu_model,
341 struct __processor_model2 *cpu_model2,
342 unsigned int *cpu_features2 __attribute__((unused)))
343 {
344 const char *cpu = NULL;
345 unsigned int family = cpu_model2->__cpu_family;
346 unsigned int model = cpu_model2->__cpu_model;
347
348 switch (family)
349 {
350 case 0x18:
351 cpu_model->__cpu_type = HYGONFAM18H;
352 if (model == 0x4)
353 {
354 cpu = "c86-4g-m4";
355 CHECK___builtin_cpu_is ("c86-4g-m4");
356 cpu_model->__cpu_subtype = HYGONFAM18H_C86_4G_M4;
357 }
358 else if (model == 0x6)
359 {
360 cpu = "c86-4g-m6";
361 CHECK___builtin_cpu_is ("c86-4g-m6");
362 cpu_model->__cpu_subtype = HYGONFAM18H_C86_4G_M6;
363 }
364 else if (model == 0x7)
365 {
366 cpu = "c86-4g-m7";
367 CHECK___builtin_cpu_is ("c86-4g-m7");
368 cpu_model->__cpu_subtype = HYGONFAM18H_C86_4G_M7;
369 }
370 break;
371 default:
372 break;
373 }
374
375 return cpu;
376 }
377
378 /* Get the specific type of Intel CPU and return Intel CPU name. Return
379 NULL for unknown Intel CPU. */
380
381 static inline const char *
382 get_intel_cpu (struct __processor_model *cpu_model,
383 struct __processor_model2 *cpu_model2,
384 unsigned int *cpu_features2)
385 {
386 const char *cpu = NULL;
387
388 /* Parse family and model for family 0x6. */
389 if (cpu_model2->__cpu_family == 0x6)
390 switch (cpu_model2->__cpu_model)
391 {
392 case 0x1c:
393 case 0x26:
394 /* Bonnell. */
395 cpu = "bonnell";
396 CHECK___builtin_cpu_is ("atom");
397 cpu_model->__cpu_type = INTEL_BONNELL;
398 break;
399 case 0x37:
400 case 0x4a:
401 case 0x4d:
402 case 0x5d:
403 /* Silvermont. */
404 case 0x4c:
405 case 0x5a:
406 case 0x75:
407 /* Airmont. */
408 cpu = "silvermont";
409 CHECK___builtin_cpu_is ("silvermont");
410 cpu_model->__cpu_type = INTEL_SILVERMONT;
411 break;
412 case 0x5c:
413 case 0x5f:
414 /* Goldmont. */
415 cpu = "goldmont";
416 CHECK___builtin_cpu_is ("goldmont");
417 cpu_model->__cpu_type = INTEL_GOLDMONT;
418 break;
419 case 0x7a:
420 /* Goldmont Plus. */
421 cpu = "goldmont-plus";
422 CHECK___builtin_cpu_is ("goldmont-plus");
423 cpu_model->__cpu_type = INTEL_GOLDMONT_PLUS;
424 break;
425 case 0x86:
426 case 0x96:
427 case 0x9c:
428 /* Tremont. */
429 cpu = "tremont";
430 CHECK___builtin_cpu_is ("tremont");
431 cpu_model->__cpu_type = INTEL_TREMONT;
432 break;
433 case 0x17:
434 case 0x1d:
435 /* Penryn. */
436 case 0x0f:
437 /* Merom. */
438 cpu = "core2";
439 CHECK___builtin_cpu_is ("core2");
440 cpu_model->__cpu_type = INTEL_CORE2;
441 break;
442 case 0x1a:
443 case 0x1e:
444 case 0x1f:
445 case 0x2e:
446 /* Nehalem. */
447 cpu = "nehalem";
448 CHECK___builtin_cpu_is ("corei7");
449 CHECK___builtin_cpu_is ("nehalem");
450 cpu_model->__cpu_type = INTEL_COREI7;
451 cpu_model->__cpu_subtype = INTEL_COREI7_NEHALEM;
452 break;
453 case 0x25:
454 case 0x2c:
455 case 0x2f:
456 /* Westmere. */
457 cpu = "westmere";
458 CHECK___builtin_cpu_is ("corei7");
459 CHECK___builtin_cpu_is ("westmere");
460 cpu_model->__cpu_type = INTEL_COREI7;
461 cpu_model->__cpu_subtype = INTEL_COREI7_WESTMERE;
462 break;
463 case 0x2a:
464 case 0x2d:
465 /* Sandy Bridge. */
466 cpu = "sandybridge";
467 CHECK___builtin_cpu_is ("corei7");
468 CHECK___builtin_cpu_is ("sandybridge");
469 cpu_model->__cpu_type = INTEL_COREI7;
470 cpu_model->__cpu_subtype = INTEL_COREI7_SANDYBRIDGE;
471 break;
472 case 0x3a:
473 case 0x3e:
474 /* Ivy Bridge. */
475 cpu = "ivybridge";
476 CHECK___builtin_cpu_is ("corei7");
477 CHECK___builtin_cpu_is ("ivybridge");
478 cpu_model->__cpu_type = INTEL_COREI7;
479 cpu_model->__cpu_subtype = INTEL_COREI7_IVYBRIDGE;
480 break;
481 case 0x3c:
482 case 0x3f:
483 case 0x45:
484 case 0x46:
485 /* Haswell. */
486 cpu = "haswell";
487 CHECK___builtin_cpu_is ("corei7");
488 CHECK___builtin_cpu_is ("haswell");
489 cpu_model->__cpu_type = INTEL_COREI7;
490 cpu_model->__cpu_subtype = INTEL_COREI7_HASWELL;
491 break;
492 case 0x3d:
493 case 0x47:
494 case 0x4f:
495 case 0x56:
496 /* Broadwell. */
497 cpu = "broadwell";
498 CHECK___builtin_cpu_is ("corei7");
499 CHECK___builtin_cpu_is ("broadwell");
500 cpu_model->__cpu_type = INTEL_COREI7;
501 cpu_model->__cpu_subtype = INTEL_COREI7_BROADWELL;
502 break;
503 case 0x4e:
504 case 0x5e:
505 /* Skylake. */
506 case 0x8e:
507 case 0x9e:
508 /* Kaby Lake. */
509 case 0xa5:
510 case 0xa6:
511 /* Comet Lake. */
512 cpu = "skylake";
513 CHECK___builtin_cpu_is ("corei7");
514 CHECK___builtin_cpu_is ("skylake");
515 cpu_model->__cpu_type = INTEL_COREI7;
516 cpu_model->__cpu_subtype = INTEL_COREI7_SKYLAKE;
517 break;
518 case 0x55:
519 CHECK___builtin_cpu_is ("corei7");
520 cpu_model->__cpu_type = INTEL_COREI7;
521 if (has_cpu_feature (cpu_model, cpu_features2,
522 FEATURE_AVX512BF16))
523 {
524 /* Cooper Lake. */
525 cpu = "cooperlake";
526 CHECK___builtin_cpu_is ("cooperlake");
527 cpu_model->__cpu_subtype = INTEL_COREI7_COOPERLAKE;
528 }
529 else if (has_cpu_feature (cpu_model, cpu_features2,
530 FEATURE_AVX512VNNI))
531 {
532 /* Cascade Lake. */
533 cpu = "cascadelake";
534 CHECK___builtin_cpu_is ("cascadelake");
535 cpu_model->__cpu_subtype = INTEL_COREI7_CASCADELAKE;
536 }
537 else
538 {
539 /* Skylake with AVX-512 support. */
540 cpu = "skylake-avx512";
541 CHECK___builtin_cpu_is ("skylake-avx512");
542 cpu_model->__cpu_subtype = INTEL_COREI7_SKYLAKE_AVX512;
543 }
544 break;
545 case 0x66:
546 /* Cannon Lake. */
547 cpu = "cannonlake";
548 CHECK___builtin_cpu_is ("corei7");
549 CHECK___builtin_cpu_is ("cannonlake");
550 cpu_model->__cpu_type = INTEL_COREI7;
551 cpu_model->__cpu_subtype = INTEL_COREI7_CANNONLAKE;
552 break;
553 case 0x7e:
554 case 0x7d:
555 case 0x9d:
556 /* Ice Lake client. */
557 cpu = "icelake-client";
558 CHECK___builtin_cpu_is ("corei7");
559 CHECK___builtin_cpu_is ("icelake-client");
560 cpu_model->__cpu_type = INTEL_COREI7;
561 cpu_model->__cpu_subtype = INTEL_COREI7_ICELAKE_CLIENT;
562 break;
563 case 0x6a:
564 case 0x6c:
565 /* Ice Lake server. */
566 cpu = "icelake-server";
567 CHECK___builtin_cpu_is ("corei7");
568 CHECK___builtin_cpu_is ("icelake-server");
569 cpu_model->__cpu_type = INTEL_COREI7;
570 cpu_model->__cpu_subtype = INTEL_COREI7_ICELAKE_SERVER;
571 break;
572 case 0xa7:
573 /* Rocket Lake. */
574 cpu = "rocketlake";
575 CHECK___builtin_cpu_is ("corei7");
576 CHECK___builtin_cpu_is ("rocketlake");
577 cpu_model->__cpu_type = INTEL_COREI7;
578 cpu_model->__cpu_subtype = INTEL_COREI7_ROCKETLAKE;
579 break;
580 case 0x8c:
581 case 0x8d:
582 /* Tiger Lake. */
583 cpu = "tigerlake";
584 CHECK___builtin_cpu_is ("corei7");
585 CHECK___builtin_cpu_is ("tigerlake");
586 cpu_model->__cpu_type = INTEL_COREI7;
587 cpu_model->__cpu_subtype = INTEL_COREI7_TIGERLAKE;
588 break;
589 case 0xbe:
590 /* Alder Lake N, E-core only. */
591 case 0x97:
592 case 0x9a:
593 /* Alder Lake. */
594 case 0xb7:
595 case 0xba:
596 case 0xbf:
597 /* Raptor Lake. */
598 case 0xaa:
599 case 0xac:
600 /* Meteor Lake. */
601 cpu = "alderlake";
602 CHECK___builtin_cpu_is ("corei7");
603 CHECK___builtin_cpu_is ("alderlake");
604 cpu_model->__cpu_type = INTEL_COREI7;
605 cpu_model->__cpu_subtype = INTEL_COREI7_ALDERLAKE;
606 break;
607 case 0x8f:
608 /* Sapphire Rapids. */
609 case 0xcf:
610 /* Emerald Rapids. */
611 cpu = "sapphirerapids";
612 CHECK___builtin_cpu_is ("corei7");
613 CHECK___builtin_cpu_is ("sapphirerapids");
614 cpu_model->__cpu_type = INTEL_COREI7;
615 cpu_model->__cpu_subtype = INTEL_COREI7_SAPPHIRERAPIDS;
616 break;
617 case 0xaf:
618 /* Sierra Forest. */
619 cpu = "sierraforest";
620 CHECK___builtin_cpu_is ("sierraforest");
621 cpu_model->__cpu_type = INTEL_SIERRAFOREST;
622 break;
623 case 0xad:
624 /* Granite Rapids. */
625 cpu = "graniterapids";
626 CHECK___builtin_cpu_is ("corei7");
627 CHECK___builtin_cpu_is ("graniterapids");
628 cpu_model->__cpu_type = INTEL_COREI7;
629 cpu_model->__cpu_subtype = INTEL_COREI7_GRANITERAPIDS;
630 break;
631 case 0xae:
632 /* Granite Rapids D. */
633 cpu = "graniterapids-d";
634 CHECK___builtin_cpu_is ("corei7");
635 CHECK___builtin_cpu_is ("graniterapids-d");
636 cpu_model->__cpu_type = INTEL_COREI7;
637 cpu_model->__cpu_subtype = INTEL_COREI7_GRANITERAPIDS_D;
638 break;
639 case 0xb6:
640 /* Grand Ridge. */
641 cpu = "grandridge";
642 CHECK___builtin_cpu_is ("grandridge");
643 cpu_model->__cpu_type = INTEL_GRANDRIDGE;
644 break;
645 case 0xb5:
646 case 0xc5:
647 /* Arrow Lake. */
648 cpu = "arrowlake";
649 CHECK___builtin_cpu_is ("corei7");
650 CHECK___builtin_cpu_is ("arrowlake");
651 cpu_model->__cpu_type = INTEL_COREI7;
652 cpu_model->__cpu_subtype = INTEL_COREI7_ARROWLAKE;
653 break;
654 case 0xc6:
655 /* Arrow Lake S. */
656 case 0xbd:
657 /* Lunar Lake. */
658 cpu = "arrowlake-s";
659 CHECK___builtin_cpu_is ("corei7");
660 CHECK___builtin_cpu_is ("arrowlake-s");
661 cpu_model->__cpu_type = INTEL_COREI7;
662 cpu_model->__cpu_subtype = INTEL_COREI7_ARROWLAKE_S;
663 break;
664 case 0xdd:
665 /* Clearwater Forest. */
666 cpu = "clearwaterforest";
667 CHECK___builtin_cpu_is ("clearwaterforest");
668 cpu_model->__cpu_type = INTEL_CLEARWATERFOREST;
669 break;
670 case 0xcc:
671 /* Panther Lake. */
672 cpu = "pantherlake";
673 CHECK___builtin_cpu_is ("corei7");
674 CHECK___builtin_cpu_is ("pantherlake");
675 cpu_model->__cpu_type = INTEL_COREI7;
676 cpu_model->__cpu_subtype = INTEL_COREI7_PANTHERLAKE;
677 break;
678 default:
679 break;
680 }
681 /* Parse family and model for family 0x13. */
682 else if (cpu_model2->__cpu_family == 0x13)
683 switch (cpu_model2->__cpu_model)
684 {
685 case 0x01:
686 /* Diamond Rapids. */
687 cpu = "diamondrapids";
688 CHECK___builtin_cpu_is ("corei7");
689 CHECK___builtin_cpu_is ("diamondrapids");
690 cpu_model->__cpu_type = INTEL_COREI7;
691 cpu_model->__cpu_subtype = INTEL_COREI7_DIAMONDRAPIDS;
692 break;
693 default:
694 break;
695 }
696
697 return cpu;
698 }
699
700 /* Get the specific type of ZHAOXIN CPU and return ZHAOXIN CPU name.
701 Return NULL for unknown ZHAOXIN CPU. */
702
703 static inline const char *
704 get_zhaoxin_cpu (struct __processor_model *cpu_model,
705 struct __processor_model2 *cpu_model2,
706 unsigned int *cpu_features2)
707 {
708 const char *cpu = NULL;
709 unsigned int family = cpu_model2->__cpu_family;
710 unsigned int model = cpu_model2->__cpu_model;
711
712 switch (family)
713 {
714 /* ZHAOXIN family 7h. */
715 case 0x07:
716 cpu_model->__cpu_type = ZHAOXIN_FAM7H;
717 if (model == 0x3b)
718 {
719 cpu = "lujiazui";
720 CHECK___builtin_cpu_is ("lujiazui");
721 reset_cpu_feature (cpu_model, cpu_features2, FEATURE_AVX);
722 reset_cpu_feature (cpu_model, cpu_features2, FEATURE_F16C);
723 cpu_model->__cpu_subtype = ZHAOXIN_FAM7H_LUJIAZUI;
724 }
725 else if (model == 0x5b)
726 {
727 cpu = "yongfeng";
728 CHECK___builtin_cpu_is ("yongfeng");
729 cpu_model->__cpu_subtype = ZHAOXIN_FAM7H_YONGFENG;
730 }
731 else if (model >= 0x6b)
732 {
733 cpu = "shijidadao";
734 CHECK___builtin_cpu_is ("shijidadao");
735 cpu_model->__cpu_subtype = ZHAOXIN_FAM7H_SHIJIDADAO;
736 }
737 break;
738 default:
739 break;
740 }
741
742 return cpu;
743 }
744
745 /* ECX and EDX are output of CPUID at level one. */
746 static inline void
747 get_available_features (struct __processor_model *cpu_model,
748 struct __processor_model2 *cpu_model2,
749 unsigned int *cpu_features2,
750 unsigned int ecx, unsigned int edx)
751 {
752 unsigned int max_cpuid_level = cpu_model2->__cpu_max_level;
753 unsigned int eax, ebx;
754 unsigned int ext_level;
755
756 /* Get XCR_XFEATURE_ENABLED_MASK register with xgetbv. */
757 #define XCR_XFEATURE_ENABLED_MASK 0x0
758 #define XSTATE_FP 0x1
759 #define XSTATE_SSE 0x2
760 #define XSTATE_YMM 0x4
761 #define XSTATE_OPMASK 0x20
762 #define XSTATE_ZMM 0x40
763 #define XSTATE_HI_ZMM 0x80
764 #define XSTATE_TILECFG 0x20000
765 #define XSTATE_TILEDATA 0x40000
766 #define XSTATE_APX_F 0x80000
767
768 #define XCR_AVX_ENABLED_MASK \
769 (XSTATE_SSE | XSTATE_YMM)
770 #define XCR_AVX512F_ENABLED_MASK \
771 (XSTATE_SSE | XSTATE_YMM | XSTATE_OPMASK | XSTATE_ZMM | XSTATE_HI_ZMM)
772 #define XCR_AMX_ENABLED_MASK \
773 (XSTATE_TILECFG | XSTATE_TILEDATA)
774 #define XCR_APX_F_ENABLED_MASK XSTATE_APX_F
775
776 /* Check if AVX, AVX512 and APX are usable. */
777 int avx_usable = 0;
778 int avx512_usable = 0;
779 int amx_usable = 0;
780 int apx_usable = 0;
781 /* Check if KL is usable. */
782 int has_kl = 0;
783 /* Record AVX10 version. */
784 int avx10_set = 0;
785 int version = 0;
786 if ((ecx & bit_OSXSAVE))
787 {
788 /* Check if XMM, YMM, OPMASK, upper 256 bits of ZMM0-ZMM15 and
789 ZMM16-ZMM31 states are supported by OSXSAVE. */
790 unsigned int xcrlow;
791 unsigned int xcrhigh;
792 __asm__ (".byte 0x0f, 0x01, 0xd0"
793 : "=a" (xcrlow), "=d" (xcrhigh)
794 : "c" (XCR_XFEATURE_ENABLED_MASK));
795 if ((xcrlow & XCR_AVX_ENABLED_MASK) == XCR_AVX_ENABLED_MASK)
796 {
797 avx_usable = 1;
798 avx512_usable = ((xcrlow & XCR_AVX512F_ENABLED_MASK)
799 == XCR_AVX512F_ENABLED_MASK);
800 }
801 amx_usable = ((xcrlow & XCR_AMX_ENABLED_MASK)
802 == XCR_AMX_ENABLED_MASK);
803 apx_usable = ((xcrlow & XCR_APX_F_ENABLED_MASK)
804 == XCR_APX_F_ENABLED_MASK);
805 }
806
807 #define set_feature(f) \
808 set_cpu_feature (cpu_model, cpu_features2, f)
809
810 if (edx & bit_CMOV)
811 set_feature (FEATURE_CMOV);
812 if (edx & bit_MMX)
813 set_feature (FEATURE_MMX);
814 if (edx & bit_SSE)
815 set_feature (FEATURE_SSE);
816 if (edx & bit_SSE2)
817 set_feature (FEATURE_SSE2);
818 if (edx & bit_CMPXCHG8B)
819 set_feature (FEATURE_CMPXCHG8B);
820 if (edx & bit_FXSAVE)
821 set_feature (FEATURE_FXSAVE);
822
823 if (ecx & bit_POPCNT)
824 set_feature (FEATURE_POPCNT);
825 if (ecx & bit_AES)
826 set_feature (FEATURE_AES);
827 if (ecx & bit_PCLMUL)
828 set_feature (FEATURE_PCLMUL);
829 if (ecx & bit_SSE3)
830 set_feature (FEATURE_SSE3);
831 if (ecx & bit_SSSE3)
832 set_feature (FEATURE_SSSE3);
833 if (ecx & bit_SSE4_1)
834 set_feature (FEATURE_SSE4_1);
835 if (ecx & bit_SSE4_2)
836 set_feature (FEATURE_SSE4_2);
837 if (ecx & bit_OSXSAVE)
838 set_feature (FEATURE_OSXSAVE);
839 if (ecx & bit_CMPXCHG16B)
840 set_feature (FEATURE_CMPXCHG16B);
841 if (ecx & bit_MOVBE)
842 set_feature (FEATURE_MOVBE);
843 if (ecx & bit_AES)
844 set_feature (FEATURE_AES);
845 if (ecx & bit_RDRND)
846 set_feature (FEATURE_RDRND);
847 if (ecx & bit_XSAVE)
848 set_feature (FEATURE_XSAVE);
849 if (avx_usable)
850 {
851 if (ecx & bit_AVX)
852 set_feature (FEATURE_AVX);
853 if (ecx & bit_FMA)
854 set_feature (FEATURE_FMA);
855 if (ecx & bit_F16C)
856 set_feature (FEATURE_F16C);
857 }
858
859 /* Get Advanced Features at level 7 (eax = 7, ecx = 0/1). */
860 if (max_cpuid_level >= 7)
861 {
862 unsigned int max_subleaf_level;
863
864 __cpuid_count (7, 0, max_subleaf_level, ebx, ecx, edx);
865 if (ebx & bit_BMI)
866 set_feature (FEATURE_BMI);
867 if (ebx & bit_SGX)
868 set_feature (FEATURE_SGX);
869 if (ebx & bit_HLE)
870 set_feature (FEATURE_HLE);
871 if (ebx & bit_RTM)
872 set_feature (FEATURE_RTM);
873 if (avx_usable)
874 {
875 if (ebx & bit_AVX2)
876 set_feature (FEATURE_AVX2);
877 if (ecx & bit_VPCLMULQDQ)
878 set_feature (FEATURE_VPCLMULQDQ);
879 if (ecx & bit_VAES)
880 set_feature (FEATURE_VAES);
881 }
882 if (ebx & bit_BMI2)
883 set_feature (FEATURE_BMI2);
884 if (ebx & bit_FSGSBASE)
885 set_feature (FEATURE_FSGSBASE);
886 if (ebx & bit_RDSEED)
887 set_feature (FEATURE_RDSEED);
888 if (ebx & bit_ADX)
889 set_feature (FEATURE_ADX);
890 if (ebx & bit_SHA)
891 set_feature (FEATURE_SHA);
892 if (ebx & bit_CLFLUSHOPT)
893 set_feature (FEATURE_CLFLUSHOPT);
894 if (ebx & bit_CLWB)
895 set_feature (FEATURE_CLWB);
896 /* NB: bit_OSPKE indicates that OS supports PKU. */
897 if (ecx & bit_OSPKE)
898 set_feature (FEATURE_PKU);
899 if (ecx & bit_RDPID)
900 set_feature (FEATURE_RDPID);
901 if (ecx & bit_GFNI)
902 set_feature (FEATURE_GFNI);
903 if (ecx & bit_MOVDIRI)
904 set_feature (FEATURE_MOVDIRI);
905 if (ecx & bit_MOVDIR64B)
906 set_feature (FEATURE_MOVDIR64B);
907 if (ecx & bit_ENQCMD)
908 set_feature (FEATURE_ENQCMD);
909 if (ecx & bit_CLDEMOTE)
910 set_feature (FEATURE_CLDEMOTE);
911 if (ecx & bit_WAITPKG)
912 set_feature (FEATURE_WAITPKG);
913 if (ecx & bit_SHSTK)
914 set_feature (FEATURE_SHSTK);
915 if (ecx & bit_KL)
916 has_kl = 1;
917 if (edx & bit_SERIALIZE)
918 set_feature (FEATURE_SERIALIZE);
919 if (edx & bit_TSXLDTRK)
920 set_feature (FEATURE_TSXLDTRK);
921 if (edx & bit_PCONFIG)
922 set_feature (FEATURE_PCONFIG);
923 if (edx & bit_IBT)
924 set_feature (FEATURE_IBT);
925 if (edx & bit_UINTR)
926 set_feature (FEATURE_UINTR);
927 if (amx_usable)
928 {
929 if (edx & bit_AMX_TILE)
930 set_feature (FEATURE_AMX_TILE);
931 if (edx & bit_AMX_INT8)
932 set_feature (FEATURE_AMX_INT8);
933 if (edx & bit_AMX_BF16)
934 set_feature (FEATURE_AMX_BF16);
935 }
936 if (avx512_usable)
937 {
938 if (ebx & bit_AVX512F)
939 set_feature (FEATURE_AVX512F);
940 if (ebx & bit_AVX512VL)
941 set_feature (FEATURE_AVX512VL);
942 if (ebx & bit_AVX512BW)
943 set_feature (FEATURE_AVX512BW);
944 if (ebx & bit_AVX512DQ)
945 set_feature (FEATURE_AVX512DQ);
946 if (ebx & bit_AVX512CD)
947 set_feature (FEATURE_AVX512CD);
948 if (ebx & bit_AVX512IFMA)
949 set_feature (FEATURE_AVX512IFMA);
950 if (ecx & bit_AVX512VBMI)
951 set_feature (FEATURE_AVX512VBMI);
952 if (ecx & bit_AVX512VBMI2)
953 set_feature (FEATURE_AVX512VBMI2);
954 if (ecx & bit_AVX512VNNI)
955 set_feature (FEATURE_AVX512VNNI);
956 if (ecx & bit_AVX512BITALG)
957 set_feature (FEATURE_AVX512BITALG);
958 if (ecx & bit_AVX512VPOPCNTDQ)
959 set_feature (FEATURE_AVX512VPOPCNTDQ);
960 if (edx & bit_AVX512VP2INTERSECT)
961 set_feature (FEATURE_AVX512VP2INTERSECT);
962 if (edx & bit_AVX512FP16)
963 set_feature (FEATURE_AVX512FP16);
964 }
965
966 if (max_subleaf_level >= 1)
967 {
968 __cpuid_count (7, 1, eax, ebx, ecx, edx);
969 if (eax & bit_HRESET)
970 set_feature (FEATURE_HRESET);
971 if (eax & bit_CMPCCXADD)
972 set_feature(FEATURE_CMPCCXADD);
973 if (edx & bit_PREFETCHI)
974 set_feature (FEATURE_PREFETCHI);
975 if (eax & bit_RAOINT)
976 set_feature (FEATURE_RAOINT);
977 if (edx & bit_USER_MSR)
978 set_feature (FEATURE_USER_MSR);
979 if (eax & bit_MOVRS)
980 set_feature (FEATURE_MOVRS);
981 if (avx_usable)
982 {
983 if (eax & bit_AVXVNNI)
984 set_feature (FEATURE_AVXVNNI);
985 if (eax & bit_AVXIFMA)
986 set_feature (FEATURE_AVXIFMA);
987 if (edx & bit_AVXVNNIINT8)
988 set_feature (FEATURE_AVXVNNIINT8);
989 if (edx & bit_AVXNECONVERT)
990 set_feature (FEATURE_AVXNECONVERT);
991 if (edx & bit_AVXVNNIINT16)
992 set_feature (FEATURE_AVXVNNIINT16);
993 if (eax & bit_SM3)
994 set_feature (FEATURE_SM3);
995 if (eax & bit_SHA512)
996 set_feature (FEATURE_SHA512);
997 if (eax & bit_SM4)
998 set_feature (FEATURE_SM4);
999 }
1000 if (avx512_usable)
1001 {
1002 if (eax & bit_AVX512BF16)
1003 set_feature (FEATURE_AVX512BF16);
1004 /* AVX10 has the same XSTATE with AVX512. */
1005 if (edx & bit_AVX10)
1006 avx10_set = 1;
1007 }
1008 if (amx_usable)
1009 {
1010 if (eax & bit_AMX_FP16)
1011 set_feature (FEATURE_AMX_FP16);
1012 if (edx & bit_AMX_COMPLEX)
1013 set_feature (FEATURE_AMX_COMPLEX);
1014 }
1015 if (apx_usable)
1016 {
1017 if (edx & bit_APX_F)
1018 set_feature (FEATURE_APX_F);
1019 }
1020 }
1021 }
1022
1023 /* Get Advanced Features at level 0xd (eax = 0xd, ecx = 1). */
1024 if (max_cpuid_level >= 0xd)
1025 {
1026 __cpuid_count (0xd, 1, eax, ebx, ecx, edx);
1027 if (eax & bit_XSAVEOPT)
1028 set_feature (FEATURE_XSAVEOPT);
1029 if (eax & bit_XSAVEC)
1030 set_feature (FEATURE_XSAVEC);
1031 if (eax & bit_XSAVES)
1032 set_feature (FEATURE_XSAVES);
1033 }
1034
1035 /* Get Advanced Features at level 0x14 (eax = 0x14, ecx = 0). */
1036 if (max_cpuid_level >= 0x14)
1037 {
1038 __cpuid_count (0x14, 0, eax, ebx, ecx, edx);
1039 if (ebx & bit_PTWRITE)
1040 set_feature (FEATURE_PTWRITE);
1041 }
1042
1043 /* Get Advanced Features at level 0x19 (eax = 0x19). */
1044 if (max_cpuid_level >= 0x19)
1045 {
1046 __cpuid (0x19, eax, ebx, ecx, edx);
1047 /* Check if OS support keylocker. */
1048 if (ebx & bit_AESKLE)
1049 {
1050 set_feature (FEATURE_AESKLE);
1051 if (ebx & bit_WIDEKL)
1052 set_feature (FEATURE_WIDEKL);
1053 if (has_kl)
1054 set_feature (FEATURE_KL);
1055 }
1056 }
1057
1058 /* Get Advanced Features at level 0x1e (eax = 0x1e, ecx = 1). */
1059 if (max_cpuid_level >= 0x1e)
1060 {
1061 __cpuid_count (0x1e, 1, eax, ebx, ecx, edx);
1062 if (amx_usable)
1063 {
1064 if (eax & bit_AMX_AVX512)
1065 set_feature (FEATURE_AMX_AVX512);
1066 if (eax & bit_AMX_TF32)
1067 set_feature (FEATURE_AMX_TF32);
1068 if (eax & bit_AMX_TRANSPOSE)
1069 set_feature (FEATURE_AMX_TRANSPOSE);
1070 if (eax & bit_AMX_FP8)
1071 set_feature (FEATURE_AMX_FP8);
1072 if (eax & bit_AMX_MOVRS)
1073 set_feature (FEATURE_AMX_MOVRS);
1074 }
1075 }
1076
1077 /* Get Advanced Features at level 0x24 (eax = 0x24, ecx = 0). */
1078 if (avx10_set && max_cpuid_level >= 0x24)
1079 {
1080 __cpuid_count (0x24, 0, eax, ebx, ecx, edx);
1081 version = ebx & 0xff;
1082 switch (version)
1083 {
1084 case 2:
1085 set_feature (FEATURE_AVX10_2);
1086 /* Fall through. */
1087 case 1:
1088 set_feature (FEATURE_AVX10_1);
1089 set_feature (FEATURE_AVX10_1_256);
1090 break;
1091 default:
1092 set_feature (FEATURE_AVX10_1);
1093 set_feature (FEATURE_AVX10_1_256);
1094 break;
1095 }
1096 }
1097
1098 /* Check cpuid level of extended features. */
1099 __cpuid (0x80000000, ext_level, ebx, ecx, edx);
1100
1101 cpu_model2->__cpu_ext_level = ext_level;
1102
1103 if (ext_level >= 0x80000001)
1104 {
1105 __cpuid (0x80000001, eax, ebx, ecx, edx);
1106
1107 if (ecx & bit_SSE4a)
1108 set_feature (FEATURE_SSE4_A);
1109 if (ecx & bit_LAHF_LM)
1110 set_feature (FEATURE_LAHF_LM);
1111 if (ecx & bit_ABM)
1112 set_feature (FEATURE_ABM);
1113 if (ecx & bit_LWP)
1114 set_feature (FEATURE_LWP);
1115 if (ecx & bit_TBM)
1116 set_feature (FEATURE_TBM);
1117 if (ecx & bit_LZCNT)
1118 set_feature (FEATURE_LZCNT);
1119 if (ecx & bit_PRFCHW)
1120 set_feature (FEATURE_PRFCHW);
1121 if (ecx & bit_MWAITX)
1122 set_feature (FEATURE_MWAITX);
1123
1124 if (edx & bit_LM)
1125 set_feature (FEATURE_LM);
1126 if (edx & bit_3DNOWP)
1127 set_feature (FEATURE_3DNOWP);
1128 if (edx & bit_3DNOW)
1129 set_feature (FEATURE_3DNOW);
1130
1131 if (avx_usable)
1132 {
1133 if (ecx & bit_FMA4)
1134 set_feature (FEATURE_FMA4);
1135 if (ecx & bit_XOP)
1136 set_feature (FEATURE_XOP);
1137 }
1138 }
1139
1140 if (ext_level >= 0x80000008)
1141 {
1142 __cpuid (0x80000008, eax, ebx, ecx, edx);
1143 if (ebx & bit_CLZERO)
1144 set_feature (FEATURE_CLZERO);
1145 if (ebx & bit_WBNOINVD)
1146 set_feature (FEATURE_WBNOINVD);
1147 }
1148
1149 #undef set_feature
1150 }
1151
1152 static inline int
1153 cpu_indicator_init (struct __processor_model *cpu_model,
1154 struct __processor_model2 *cpu_model2,
1155 unsigned int *cpu_features2)
1156 {
1157 unsigned int eax, ebx, ecx, edx;
1158
1159 int max_level;
1160 unsigned int vendor;
1161 unsigned int model, family;
1162 unsigned int extended_model, extended_family;
1163
1164 /* This function needs to run just once. */
1165 if (cpu_model->__cpu_vendor)
1166 return 0;
1167
1168 /* Assume cpuid insn present. Run in level 0 to get vendor id. */
1169 if (!__get_cpuid (0, &eax, &ebx, &ecx, &edx))
1170 {
1171 cpu_model->__cpu_vendor = VENDOR_OTHER;
1172 return -1;
1173 }
1174
1175 vendor = ebx;
1176 max_level = eax;
1177
1178 if (max_level < 1)
1179 {
1180 cpu_model->__cpu_vendor = VENDOR_OTHER;
1181 return -1;
1182 }
1183
1184 if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
1185 {
1186 cpu_model->__cpu_vendor = VENDOR_OTHER;
1187 return -1;
1188 }
1189
1190 cpu_model2->__cpu_max_level = max_level;
1191
1192 model = (eax >> 4) & 0x0f;
1193 family = (eax >> 8) & 0x0f;
1194 extended_model = (eax >> 12) & 0xf0;
1195 extended_family = (eax >> 20) & 0xff;
1196
1197 /* Find available features. */
1198 get_available_features (cpu_model, cpu_model2, cpu_features2,
1199 ecx, edx);
1200
1201 if (vendor == signature_INTEL_ebx)
1202 {
1203 /* Adjust model and family for Intel CPUS. */
1204 if (family == 0x0f)
1205 {
1206 family += extended_family;
1207 model += extended_model;
1208 }
1209 else if (family == 0x06)
1210 model += extended_model;
1211
1212 cpu_model2->__cpu_family = family;
1213 cpu_model2->__cpu_model = model;
1214
1215 /* Get CPU type. */
1216 get_intel_cpu (cpu_model, cpu_model2, cpu_features2);
1217 cpu_model->__cpu_vendor = VENDOR_INTEL;
1218 }
1219 else if (vendor == signature_AMD_ebx)
1220 {
1221 /* Adjust model and family for AMD CPUS. */
1222 if (family == 0x0f)
1223 {
1224 family += extended_family;
1225 model += extended_model;
1226 }
1227
1228 cpu_model2->__cpu_family = family;
1229 cpu_model2->__cpu_model = model;
1230
1231 /* Get CPU type. */
1232 get_amd_cpu (cpu_model, cpu_model2, cpu_features2);
1233 cpu_model->__cpu_vendor = VENDOR_AMD;
1234 }
1235 else if (vendor == signature_CENTAUR_ebx && family < 0x07)
1236 cpu_model->__cpu_vendor = VENDOR_CENTAUR;
1237 else if (vendor == signature_SHANGHAI_ebx
1238 || vendor == signature_CENTAUR_ebx)
1239 {
1240 /* Adjust model and family for ZHAOXIN CPUS. */
1241 if (family == 0x07)
1242 model += extended_model;
1243
1244 cpu_model2->__cpu_family = family;
1245 cpu_model2->__cpu_model = model;
1246
1247 /* Get CPU type. */
1248 get_zhaoxin_cpu (cpu_model, cpu_model2, cpu_features2);
1249 cpu_model->__cpu_vendor = VENDOR_ZHAOXIN;
1250 }
1251 else if (vendor == signature_CYRIX_ebx)
1252 cpu_model->__cpu_vendor = VENDOR_CYRIX;
1253 else if (vendor == signature_NSC_ebx)
1254 cpu_model->__cpu_vendor = VENDOR_NSC;
1255 else if (vendor == signature_HYGON_ebx)
1256 {
1257 /* Adjust model and family for HYGON CPUS. */
1258 if (family == 0x0f)
1259 {
1260 family += extended_family;
1261 model += extended_model;
1262 }
1263 cpu_model2->__cpu_family = family;
1264 cpu_model2->__cpu_model = model;
1265
1266 /* Get CPU type. */
1267 get_hygon_cpu (cpu_model, cpu_model2, cpu_features2);
1268 cpu_model->__cpu_vendor = VENDOR_HYGON;
1269 }
1270 else
1271 cpu_model->__cpu_vendor = VENDOR_OTHER;
1272
1273 if (has_cpu_feature (cpu_model, cpu_features2, FEATURE_LM)
1274 && has_cpu_feature (cpu_model, cpu_features2, FEATURE_SSE2))
1275 {
1276 CHECK___builtin_cpu_supports ("x86-64");
1277 set_cpu_feature (cpu_model, cpu_features2,
1278 FEATURE_X86_64_BASELINE);
1279 if (has_cpu_feature (cpu_model, cpu_features2, FEATURE_CMPXCHG16B)
1280 && has_cpu_feature (cpu_model, cpu_features2, FEATURE_POPCNT)
1281 && has_cpu_feature (cpu_model, cpu_features2, FEATURE_LAHF_LM)
1282 && has_cpu_feature (cpu_model, cpu_features2, FEATURE_SSE4_2))
1283 {
1284 CHECK___builtin_cpu_supports ("x86-64-v2");
1285 set_cpu_feature (cpu_model, cpu_features2,
1286 FEATURE_X86_64_V2);
1287 if (has_cpu_feature (cpu_model, cpu_features2, FEATURE_AVX2)
1288 && has_cpu_feature (cpu_model, cpu_features2, FEATURE_BMI)
1289 && has_cpu_feature (cpu_model, cpu_features2, FEATURE_BMI2)
1290 && has_cpu_feature (cpu_model, cpu_features2, FEATURE_F16C)
1291 && has_cpu_feature (cpu_model, cpu_features2, FEATURE_FMA)
1292 && has_cpu_feature (cpu_model, cpu_features2,
1293 FEATURE_LZCNT)
1294 && has_cpu_feature (cpu_model, cpu_features2,
1295 FEATURE_MOVBE))
1296 {
1297 CHECK___builtin_cpu_supports ("x86-64-v3");
1298 set_cpu_feature (cpu_model, cpu_features2,
1299 FEATURE_X86_64_V3);
1300 if (has_cpu_feature (cpu_model, cpu_features2,
1301 FEATURE_AVX512BW)
1302 && has_cpu_feature (cpu_model, cpu_features2,
1303 FEATURE_AVX512CD)
1304 && has_cpu_feature (cpu_model, cpu_features2,
1305 FEATURE_AVX512DQ)
1306 && has_cpu_feature (cpu_model, cpu_features2,
1307 FEATURE_AVX512VL))
1308 {
1309 CHECK___builtin_cpu_supports ("x86-64-v4");
1310 set_cpu_feature (cpu_model, cpu_features2,
1311 FEATURE_X86_64_V4);
1312 }
1313 }
1314 }
1315 }
1316
1317 gcc_assert (cpu_model->__cpu_vendor < VENDOR_MAX);
1318 gcc_assert (cpu_model->__cpu_type < CPU_TYPE_MAX);
1319 gcc_assert (cpu_model->__cpu_subtype < CPU_SUBTYPE_MAX);
1320
1321 return 0;
1322 }