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