| 1 |
/* Subroutines for the gcc driver. |
| 2 |
Copyright (C) 2006-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 "tm.h" |
| 26 |
#include "diagnostic.h" |
| 27 |
|
| 28 |
const char *host_detect_local_cpu (int argc, const char **argv); |
| 29 |
|
| 30 |
#if defined(__GNUC__) && (__GNUC__ >= 5 || !defined(__PIC__)) |
| 31 |
#include "cpuid.h" |
| 32 |
#include "common/config/i386/cpuinfo.h" |
| 33 |
#include "common/config/i386/i386-isas.h" |
| 34 |
|
| 35 |
struct cache_desc |
| 36 |
{ |
| 37 |
unsigned sizekb; |
| 38 |
unsigned assoc; |
| 39 |
unsigned line; |
| 40 |
}; |
| 41 |
|
| 42 |
/* Returns command line parameters that describe size and |
| 43 |
cache line size of the processor caches. */ |
| 44 |
|
| 45 |
static char * |
| 46 |
describe_cache (struct cache_desc level1, struct cache_desc level2) |
| 47 |
{ |
| 48 |
char size[100], line[100], size2[100]; |
| 49 |
|
| 50 |
/* At the moment, gcc does not use the information |
| 51 |
about the associativity of the cache. */ |
| 52 |
|
| 53 |
snprintf (size, sizeof (size), |
| 54 |
"--param l1-cache-size=%u ", level1.sizekb); |
| 55 |
snprintf (line, sizeof (line), |
| 56 |
"--param l1-cache-line-size=%u ", level1.line); |
| 57 |
|
| 58 |
snprintf (size2, sizeof (size2), |
| 59 |
"--param l2-cache-size=%u ", level2.sizekb); |
| 60 |
|
| 61 |
return concat (size, line, size2, NULL); |
| 62 |
} |
| 63 |
|
| 64 |
/* Detect L2 cache parameters using CPUID extended function 0x80000006. */ |
| 65 |
|
| 66 |
static void |
| 67 |
detect_l2_cache (struct cache_desc *level2) |
| 68 |
{ |
| 69 |
unsigned eax, ebx, ecx, edx; |
| 70 |
unsigned assoc; |
| 71 |
|
| 72 |
__cpuid (0x80000006, eax, ebx, ecx, edx); |
| 73 |
|
| 74 |
level2->sizekb = (ecx >> 16) & 0xffff; |
| 75 |
level2->line = ecx & 0xff; |
| 76 |
|
| 77 |
assoc = (ecx >> 12) & 0xf; |
| 78 |
if (assoc == 6) |
| 79 |
assoc = 8; |
| 80 |
else if (assoc == 8) |
| 81 |
assoc = 16; |
| 82 |
else if (assoc >= 0xa && assoc <= 0xc) |
| 83 |
assoc = 32 + (assoc - 0xa) * 16; |
| 84 |
else if (assoc >= 0xd && assoc <= 0xe) |
| 85 |
assoc = 96 + (assoc - 0xd) * 32; |
| 86 |
|
| 87 |
level2->assoc = assoc; |
| 88 |
} |
| 89 |
|
| 90 |
/* Returns the description of caches for an AMD processor. */ |
| 91 |
|
| 92 |
static const char * |
| 93 |
detect_caches_amd (unsigned max_ext_level) |
| 94 |
{ |
| 95 |
unsigned eax, ebx, ecx, edx; |
| 96 |
|
| 97 |
struct cache_desc level1, level2 = {0, 0, 0}; |
| 98 |
|
| 99 |
if (max_ext_level < 0x80000005) |
| 100 |
return ""; |
| 101 |
|
| 102 |
__cpuid (0x80000005, eax, ebx, ecx, edx); |
| 103 |
|
| 104 |
level1.sizekb = (ecx >> 24) & 0xff; |
| 105 |
level1.assoc = (ecx >> 16) & 0xff; |
| 106 |
level1.line = ecx & 0xff; |
| 107 |
|
| 108 |
if (max_ext_level >= 0x80000006) |
| 109 |
detect_l2_cache (&level2); |
| 110 |
|
| 111 |
return describe_cache (level1, level2); |
| 112 |
} |
| 113 |
|
| 114 |
/* Decodes the size, the associativity and the cache line size of |
| 115 |
L1/L2 caches of an Intel processor. Values are based on |
| 116 |
"Intel Processor Identification and the CPUID Instruction" |
| 117 |
[Application Note 485], revision -032, December 2007. */ |
| 118 |
|
| 119 |
static void |
| 120 |
decode_caches_intel (unsigned reg, bool xeon_mp, |
| 121 |
struct cache_desc *level1, struct cache_desc *level2) |
| 122 |
{ |
| 123 |
int i; |
| 124 |
|
| 125 |
for (i = 24; i >= 0; i -= 8) |
| 126 |
switch ((reg >> i) & 0xff) |
| 127 |
{ |
| 128 |
case 0x0a: |
| 129 |
level1->sizekb = 8; level1->assoc = 2; level1->line = 32; |
| 130 |
break; |
| 131 |
case 0x0c: |
| 132 |
level1->sizekb = 16; level1->assoc = 4; level1->line = 32; |
| 133 |
break; |
| 134 |
case 0x0d: |
| 135 |
level1->sizekb = 16; level1->assoc = 4; level1->line = 64; |
| 136 |
break; |
| 137 |
case 0x0e: |
| 138 |
level1->sizekb = 24; level1->assoc = 6; level1->line = 64; |
| 139 |
break; |
| 140 |
case 0x21: |
| 141 |
level2->sizekb = 256; level2->assoc = 8; level2->line = 64; |
| 142 |
break; |
| 143 |
case 0x24: |
| 144 |
level2->sizekb = 1024; level2->assoc = 16; level2->line = 64; |
| 145 |
break; |
| 146 |
case 0x2c: |
| 147 |
level1->sizekb = 32; level1->assoc = 8; level1->line = 64; |
| 148 |
break; |
| 149 |
case 0x39: |
| 150 |
level2->sizekb = 128; level2->assoc = 4; level2->line = 64; |
| 151 |
break; |
| 152 |
case 0x3a: |
| 153 |
level2->sizekb = 192; level2->assoc = 6; level2->line = 64; |
| 154 |
break; |
| 155 |
case 0x3b: |
| 156 |
level2->sizekb = 128; level2->assoc = 2; level2->line = 64; |
| 157 |
break; |
| 158 |
case 0x3c: |
| 159 |
level2->sizekb = 256; level2->assoc = 4; level2->line = 64; |
| 160 |
break; |
| 161 |
case 0x3d: |
| 162 |
level2->sizekb = 384; level2->assoc = 6; level2->line = 64; |
| 163 |
break; |
| 164 |
case 0x3e: |
| 165 |
level2->sizekb = 512; level2->assoc = 4; level2->line = 64; |
| 166 |
break; |
| 167 |
case 0x41: |
| 168 |
level2->sizekb = 128; level2->assoc = 4; level2->line = 32; |
| 169 |
break; |
| 170 |
case 0x42: |
| 171 |
level2->sizekb = 256; level2->assoc = 4; level2->line = 32; |
| 172 |
break; |
| 173 |
case 0x43: |
| 174 |
level2->sizekb = 512; level2->assoc = 4; level2->line = 32; |
| 175 |
break; |
| 176 |
case 0x44: |
| 177 |
level2->sizekb = 1024; level2->assoc = 4; level2->line = 32; |
| 178 |
break; |
| 179 |
case 0x45: |
| 180 |
level2->sizekb = 2048; level2->assoc = 4; level2->line = 32; |
| 181 |
break; |
| 182 |
case 0x48: |
| 183 |
level2->sizekb = 3072; level2->assoc = 12; level2->line = 64; |
| 184 |
break; |
| 185 |
case 0x49: |
| 186 |
if (xeon_mp) |
| 187 |
break; |
| 188 |
level2->sizekb = 4096; level2->assoc = 16; level2->line = 64; |
| 189 |
break; |
| 190 |
case 0x4e: |
| 191 |
level2->sizekb = 6144; level2->assoc = 24; level2->line = 64; |
| 192 |
break; |
| 193 |
case 0x60: |
| 194 |
level1->sizekb = 16; level1->assoc = 8; level1->line = 64; |
| 195 |
break; |
| 196 |
case 0x66: |
| 197 |
level1->sizekb = 8; level1->assoc = 4; level1->line = 64; |
| 198 |
break; |
| 199 |
case 0x67: |
| 200 |
level1->sizekb = 16; level1->assoc = 4; level1->line = 64; |
| 201 |
break; |
| 202 |
case 0x68: |
| 203 |
level1->sizekb = 32; level1->assoc = 4; level1->line = 64; |
| 204 |
break; |
| 205 |
case 0x78: |
| 206 |
level2->sizekb = 1024; level2->assoc = 4; level2->line = 64; |
| 207 |
break; |
| 208 |
case 0x79: |
| 209 |
level2->sizekb = 128; level2->assoc = 8; level2->line = 64; |
| 210 |
break; |
| 211 |
case 0x7a: |
| 212 |
level2->sizekb = 256; level2->assoc = 8; level2->line = 64; |
| 213 |
break; |
| 214 |
case 0x7b: |
| 215 |
level2->sizekb = 512; level2->assoc = 8; level2->line = 64; |
| 216 |
break; |
| 217 |
case 0x7c: |
| 218 |
level2->sizekb = 1024; level2->assoc = 8; level2->line = 64; |
| 219 |
break; |
| 220 |
case 0x7d: |
| 221 |
level2->sizekb = 2048; level2->assoc = 8; level2->line = 64; |
| 222 |
break; |
| 223 |
case 0x7f: |
| 224 |
level2->sizekb = 512; level2->assoc = 2; level2->line = 64; |
| 225 |
break; |
| 226 |
case 0x80: |
| 227 |
level2->sizekb = 512; level2->assoc = 8; level2->line = 64; |
| 228 |
break; |
| 229 |
case 0x82: |
| 230 |
level2->sizekb = 256; level2->assoc = 8; level2->line = 32; |
| 231 |
break; |
| 232 |
case 0x83: |
| 233 |
level2->sizekb = 512; level2->assoc = 8; level2->line = 32; |
| 234 |
break; |
| 235 |
case 0x84: |
| 236 |
level2->sizekb = 1024; level2->assoc = 8; level2->line = 32; |
| 237 |
break; |
| 238 |
case 0x85: |
| 239 |
level2->sizekb = 2048; level2->assoc = 8; level2->line = 32; |
| 240 |
break; |
| 241 |
case 0x86: |
| 242 |
level2->sizekb = 512; level2->assoc = 4; level2->line = 64; |
| 243 |
break; |
| 244 |
case 0x87: |
| 245 |
level2->sizekb = 1024; level2->assoc = 8; level2->line = 64; |
| 246 |
|
| 247 |
default: |
| 248 |
break; |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
/* Detect cache parameters using CPUID function 2. */ |
| 253 |
|
| 254 |
static void |
| 255 |
detect_caches_cpuid2 (bool xeon_mp, |
| 256 |
struct cache_desc *level1, struct cache_desc *level2) |
| 257 |
{ |
| 258 |
unsigned regs[4]; |
| 259 |
int nreps, i; |
| 260 |
|
| 261 |
__cpuid (2, regs[0], regs[1], regs[2], regs[3]); |
| 262 |
|
| 263 |
nreps = regs[0] & 0x0f; |
| 264 |
regs[0] &= ~0x0f; |
| 265 |
|
| 266 |
while (--nreps >= 0) |
| 267 |
{ |
| 268 |
for (i = 0; i < 4; i++) |
| 269 |
if (regs[i] && !((regs[i] >> 31) & 1)) |
| 270 |
decode_caches_intel (regs[i], xeon_mp, level1, level2); |
| 271 |
|
| 272 |
if (nreps) |
| 273 |
__cpuid (2, regs[0], regs[1], regs[2], regs[3]); |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
/* Detect cache parameters using CPUID function 4. This |
| 278 |
method doesn't require hardcoded tables. */ |
| 279 |
|
| 280 |
enum cache_type |
| 281 |
{ |
| 282 |
CACHE_END = 0, |
| 283 |
CACHE_DATA = 1, |
| 284 |
CACHE_INST = 2, |
| 285 |
CACHE_UNIFIED = 3 |
| 286 |
}; |
| 287 |
|
| 288 |
static void |
| 289 |
detect_caches_cpuid4 (struct cache_desc *level1, struct cache_desc *level2, |
| 290 |
struct cache_desc *level3) |
| 291 |
{ |
| 292 |
struct cache_desc *cache; |
| 293 |
|
| 294 |
unsigned eax, ebx, ecx, edx; |
| 295 |
int count; |
| 296 |
|
| 297 |
for (count = 0;; count++) |
| 298 |
{ |
| 299 |
__cpuid_count(4, count, eax, ebx, ecx, edx); |
| 300 |
switch (eax & 0x1f) |
| 301 |
{ |
| 302 |
case CACHE_END: |
| 303 |
return; |
| 304 |
case CACHE_DATA: |
| 305 |
case CACHE_UNIFIED: |
| 306 |
{ |
| 307 |
switch ((eax >> 5) & 0x07) |
| 308 |
{ |
| 309 |
case 1: |
| 310 |
cache = level1; |
| 311 |
break; |
| 312 |
case 2: |
| 313 |
cache = level2; |
| 314 |
break; |
| 315 |
case 3: |
| 316 |
cache = level3; |
| 317 |
break; |
| 318 |
default: |
| 319 |
cache = NULL; |
| 320 |
} |
| 321 |
|
| 322 |
if (cache) |
| 323 |
{ |
| 324 |
unsigned sets = ecx + 1; |
| 325 |
unsigned part = ((ebx >> 12) & 0x03ff) + 1; |
| 326 |
|
| 327 |
cache->assoc = ((ebx >> 22) & 0x03ff) + 1; |
| 328 |
cache->line = (ebx & 0x0fff) + 1; |
| 329 |
|
| 330 |
cache->sizekb = (cache->assoc * part |
| 331 |
* cache->line * sets) / 1024; |
| 332 |
} |
| 333 |
} |
| 334 |
default: |
| 335 |
break; |
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
/* Returns the description of caches for an Intel processor. */ |
| 341 |
|
| 342 |
static const char * |
| 343 |
detect_caches_intel (bool xeon_mp, unsigned max_level, |
| 344 |
unsigned max_ext_level, unsigned *l2sizekb) |
| 345 |
{ |
| 346 |
struct cache_desc level1 = {0, 0, 0}, level2 = {0, 0, 0}, level3 = {0, 0, 0}; |
| 347 |
|
| 348 |
if (max_level >= 4) |
| 349 |
detect_caches_cpuid4 (&level1, &level2, &level3); |
| 350 |
else if (max_level >= 2) |
| 351 |
detect_caches_cpuid2 (xeon_mp, &level1, &level2); |
| 352 |
else |
| 353 |
return ""; |
| 354 |
|
| 355 |
if (level1.sizekb == 0) |
| 356 |
return ""; |
| 357 |
|
| 358 |
/* Let the L3 replace the L2. This assumes inclusive caches |
| 359 |
and single threaded program for now. */ |
| 360 |
if (level3.sizekb) |
| 361 |
level2 = level3; |
| 362 |
|
| 363 |
/* Intel CPUs are equipped with AMD style L2 cache info. Try this |
| 364 |
method if other methods fail to provide L2 cache parameters. */ |
| 365 |
if (level2.sizekb == 0 && max_ext_level >= 0x80000006) |
| 366 |
detect_l2_cache (&level2); |
| 367 |
|
| 368 |
*l2sizekb = level2.sizekb; |
| 369 |
|
| 370 |
return describe_cache (level1, level2); |
| 371 |
} |
| 372 |
|
| 373 |
/* Extended features */ |
| 374 |
#define has_feature(f) \ |
| 375 |
has_cpu_feature (&cpu_model, cpu_features2, f) |
| 376 |
|
| 377 |
/* We will emit a warning when using AVX10.1 and AVX512 options with one |
| 378 |
enabled and the other disabled. Add this function to avoid push "-mno-" |
| 379 |
options under this scenario for -march=native. */ |
| 380 |
|
| 381 |
bool check_avx512_features (__processor_model &cpu_model, |
| 382 |
unsigned int (&cpu_features2)[SIZE_OF_CPU_FEATURES], |
| 383 |
const enum processor_features feature) |
| 384 |
{ |
| 385 |
if (has_feature (FEATURE_AVX10_1_256) |
| 386 |
&& ((feature == FEATURE_AVX512F) |
| 387 |
|| (feature == FEATURE_AVX512CD) |
| 388 |
|| (feature == FEATURE_AVX512DQ) |
| 389 |
|| (feature == FEATURE_AVX512BW) |
| 390 |
|| (feature == FEATURE_AVX512VL) |
| 391 |
|| (feature == FEATURE_AVX512IFMA) |
| 392 |
|| (feature == FEATURE_AVX512VBMI) |
| 393 |
|| (feature == FEATURE_AVX512VBMI2) |
| 394 |
|| (feature == FEATURE_AVX512VNNI) |
| 395 |
|| (feature == FEATURE_AVX512VPOPCNTDQ) |
| 396 |
|| (feature == FEATURE_AVX512BITALG) |
| 397 |
|| (feature == FEATURE_AVX512FP16) |
| 398 |
|| (feature == FEATURE_AVX512BF16))) |
| 399 |
return false; |
| 400 |
|
| 401 |
return true; |
| 402 |
} |
| 403 |
|
| 404 |
/* This will be called by the spec parser in gcc.cc when it sees |
| 405 |
a %:local_cpu_detect(args) construct. Currently it will be |
| 406 |
called with either "arch [32|64]" or "tune [32|64]" as argument |
| 407 |
depending on if -march=native or -mtune=native is to be substituted. |
| 408 |
|
| 409 |
It returns a string containing new command line parameters to be |
| 410 |
put at the place of the above two options, depending on what CPU |
| 411 |
this is executed. E.g. "-march=k8" on an AMD64 machine |
| 412 |
for -march=native. |
| 413 |
|
| 414 |
ARGC and ARGV are set depending on the actual arguments given |
| 415 |
in the spec. */ |
| 416 |
|
| 417 |
const char *host_detect_local_cpu (int argc, const char **argv) |
| 418 |
{ |
| 419 |
enum processor_type processor = PROCESSOR_I386; |
| 420 |
const char *cpu = "i386"; |
| 421 |
|
| 422 |
const char *cache = ""; |
| 423 |
const char *options = ""; |
| 424 |
|
| 425 |
unsigned int ebx, ecx, edx; |
| 426 |
|
| 427 |
unsigned int max_level, ext_level; |
| 428 |
|
| 429 |
unsigned int vendor; |
| 430 |
unsigned int model, family; |
| 431 |
|
| 432 |
bool arch; |
| 433 |
|
| 434 |
unsigned int l2sizekb = 0; |
| 435 |
|
| 436 |
if (argc < 2) |
| 437 |
return NULL; |
| 438 |
|
| 439 |
arch = !strcmp (argv[0], "arch"); |
| 440 |
|
| 441 |
if (!arch && strcmp (argv[0], "tune")) |
| 442 |
return NULL; |
| 443 |
|
| 444 |
bool codegen_x86_64; |
| 445 |
|
| 446 |
if (!strcmp (argv[1], "32")) |
| 447 |
codegen_x86_64 = false; |
| 448 |
else if (!strcmp (argv[1], "64")) |
| 449 |
codegen_x86_64 = true; |
| 450 |
else |
| 451 |
return NULL; |
| 452 |
|
| 453 |
struct __processor_model cpu_model = { }; |
| 454 |
struct __processor_model2 cpu_model2 = { }; |
| 455 |
unsigned int cpu_features2[SIZE_OF_CPU_FEATURES] = { }; |
| 456 |
|
| 457 |
if (cpu_indicator_init (&cpu_model, &cpu_model2, cpu_features2) != 0) |
| 458 |
goto done; |
| 459 |
|
| 460 |
vendor = cpu_model.__cpu_vendor; |
| 461 |
family = cpu_model2.__cpu_family; |
| 462 |
model = cpu_model2.__cpu_model; |
| 463 |
max_level = cpu_model2.__cpu_max_level; |
| 464 |
ext_level = cpu_model2.__cpu_ext_level; |
| 465 |
|
| 466 |
if (!arch) |
| 467 |
{ |
| 468 |
if (vendor == VENDOR_AMD |
| 469 |
|| vendor == VENDOR_CENTAUR |
| 470 |
|| vendor == VENDOR_CYRIX |
| 471 |
|| vendor == VENDOR_NSC) |
| 472 |
cache = detect_caches_amd (ext_level); |
| 473 |
else if (vendor == VENDOR_INTEL |
| 474 |
|| vendor == VENDOR_ZHAOXIN) |
| 475 |
{ |
| 476 |
bool xeon_mp = (family == 15 && model == 6); |
| 477 |
cache = detect_caches_intel (xeon_mp, max_level, |
| 478 |
ext_level, &l2sizekb); |
| 479 |
} |
| 480 |
} |
| 481 |
|
| 482 |
if (vendor == VENDOR_AMD) |
| 483 |
{ |
| 484 |
unsigned int name; |
| 485 |
|
| 486 |
/* Detect geode processor by its processor signature. */ |
| 487 |
if (ext_level >= 0x80000002) |
| 488 |
__cpuid (0x80000002, name, ebx, ecx, edx); |
| 489 |
else |
| 490 |
name = 0; |
| 491 |
|
| 492 |
if (name == signature_NSC_ebx) |
| 493 |
processor = PROCESSOR_GEODE; |
| 494 |
else if (has_feature (FEATURE_MOVBE) && family == 22) |
| 495 |
processor = PROCESSOR_BTVER2; |
| 496 |
else if (has_feature (FEATURE_AVX512VP2INTERSECT)) |
| 497 |
processor = PROCESSOR_ZNVER5; |
| 498 |
else if (has_feature (FEATURE_AVX512F)) |
| 499 |
processor = PROCESSOR_ZNVER4; |
| 500 |
else if (has_feature (FEATURE_VAES)) |
| 501 |
processor = PROCESSOR_ZNVER3; |
| 502 |
else if (has_feature (FEATURE_CLWB)) |
| 503 |
processor = PROCESSOR_ZNVER2; |
| 504 |
else if (has_feature (FEATURE_CLZERO)) |
| 505 |
processor = PROCESSOR_ZNVER1; |
| 506 |
else if (has_feature (FEATURE_AVX2)) |
| 507 |
processor = PROCESSOR_BDVER4; |
| 508 |
else if (has_feature (FEATURE_XSAVEOPT)) |
| 509 |
processor = PROCESSOR_BDVER3; |
| 510 |
else if (has_feature (FEATURE_BMI)) |
| 511 |
processor = PROCESSOR_BDVER2; |
| 512 |
else if (has_feature (FEATURE_XOP)) |
| 513 |
processor = PROCESSOR_BDVER1; |
| 514 |
else if (has_feature (FEATURE_SSE4_A) |
| 515 |
&& has_feature (FEATURE_SSSE3)) |
| 516 |
processor = PROCESSOR_BTVER1; |
| 517 |
else if (has_feature (FEATURE_SSE4_A)) |
| 518 |
processor = PROCESSOR_AMDFAM10; |
| 519 |
else if (has_feature (FEATURE_SSE2) |
| 520 |
|| has_feature (FEATURE_LM)) |
| 521 |
processor = PROCESSOR_K8; |
| 522 |
else if (has_feature (FEATURE_3DNOWP) && family == 6) |
| 523 |
processor = PROCESSOR_ATHLON; |
| 524 |
else if (has_feature (FEATURE_MMX)) |
| 525 |
processor = PROCESSOR_K6; |
| 526 |
else |
| 527 |
processor = PROCESSOR_PENTIUM; |
| 528 |
} |
| 529 |
else if (vendor == VENDOR_HYGON) |
| 530 |
{ |
| 531 |
processor = PROCESSOR_GENERIC; |
| 532 |
if (model == 4) |
| 533 |
processor = PROCESSOR_C86_4G_M4; |
| 534 |
else if (model == 6) |
| 535 |
processor = PROCESSOR_C86_4G_M6; |
| 536 |
else if (model >= 7) |
| 537 |
processor = PROCESSOR_C86_4G_M7; |
| 538 |
} |
| 539 |
else if (vendor == VENDOR_CENTAUR) |
| 540 |
{ |
| 541 |
processor = PROCESSOR_GENERIC; |
| 542 |
|
| 543 |
switch (family) |
| 544 |
{ |
| 545 |
default: |
| 546 |
/* We have no idea. */ |
| 547 |
break; |
| 548 |
|
| 549 |
case 5: |
| 550 |
if (has_feature (FEATURE_3DNOW) |
| 551 |
|| has_feature (FEATURE_MMX)) |
| 552 |
processor = PROCESSOR_I486; |
| 553 |
break; |
| 554 |
|
| 555 |
case 6: |
| 556 |
if (has_feature (FEATURE_LM)) |
| 557 |
processor = PROCESSOR_K8; |
| 558 |
else if (model >= 9) |
| 559 |
processor = PROCESSOR_PENTIUMPRO; |
| 560 |
else if (model >= 6) |
| 561 |
processor = PROCESSOR_I486; |
| 562 |
} |
| 563 |
} |
| 564 |
else if (vendor == VENDOR_ZHAOXIN) |
| 565 |
{ |
| 566 |
processor = PROCESSOR_GENERIC; |
| 567 |
|
| 568 |
switch (family) |
| 569 |
{ |
| 570 |
case 7: |
| 571 |
if (model >= 0x6b) |
| 572 |
processor = PROCESSOR_SHIJIDADAO; |
| 573 |
else if (model == 0x5b) |
| 574 |
processor = PROCESSOR_YONGFENG; |
| 575 |
else if (model == 0x3b) |
| 576 |
processor = PROCESSOR_LUJIAZUI; |
| 577 |
break; |
| 578 |
default: |
| 579 |
break; |
| 580 |
} |
| 581 |
} |
| 582 |
else |
| 583 |
{ |
| 584 |
switch (family) |
| 585 |
{ |
| 586 |
case 4: |
| 587 |
processor = PROCESSOR_I486; |
| 588 |
break; |
| 589 |
case 5: |
| 590 |
processor = PROCESSOR_PENTIUM; |
| 591 |
break; |
| 592 |
case 6: |
| 593 |
case 19: |
| 594 |
processor = PROCESSOR_PENTIUMPRO; |
| 595 |
break; |
| 596 |
case 15: |
| 597 |
processor = PROCESSOR_PENTIUM4; |
| 598 |
break; |
| 599 |
default: |
| 600 |
/* We have no idea. */ |
| 601 |
processor = PROCESSOR_GENERIC; |
| 602 |
} |
| 603 |
} |
| 604 |
|
| 605 |
switch (processor) |
| 606 |
{ |
| 607 |
case PROCESSOR_I386: |
| 608 |
/* Default. */ |
| 609 |
break; |
| 610 |
case PROCESSOR_I486: |
| 611 |
if (arch && vendor == VENDOR_CENTAUR) |
| 612 |
{ |
| 613 |
if (model >= 6) |
| 614 |
cpu = "c3"; |
| 615 |
else if (has_feature (FEATURE_3DNOW)) |
| 616 |
cpu = "winchip2"; |
| 617 |
else |
| 618 |
/* Assume WinChip C6. */ |
| 619 |
cpu = "winchip-c6"; |
| 620 |
} |
| 621 |
else |
| 622 |
cpu = "i486"; |
| 623 |
break; |
| 624 |
case PROCESSOR_PENTIUM: |
| 625 |
if (arch && has_feature (FEATURE_MMX)) |
| 626 |
cpu = "pentium-mmx"; |
| 627 |
else |
| 628 |
cpu = "pentium"; |
| 629 |
break; |
| 630 |
case PROCESSOR_PENTIUMPRO: |
| 631 |
cpu = get_intel_cpu (&cpu_model, &cpu_model2, cpu_features2); |
| 632 |
if (cpu == NULL) |
| 633 |
{ |
| 634 |
if (arch) |
| 635 |
{ |
| 636 |
/* This is unknown CPU. */ |
| 637 |
if (has_feature (FEATURE_AVX512F)) |
| 638 |
{ |
| 639 |
/* Assume Diamond Rapids. */ |
| 640 |
if (has_feature (FEATURE_AMX_FP8)) |
| 641 |
cpu = "diamondrapids"; |
| 642 |
/* Assume Granite Rapids D. */ |
| 643 |
else if (has_feature (FEATURE_AMX_COMPLEX)) |
| 644 |
cpu = "graniterapids-d"; |
| 645 |
/* Assume Granite Rapids. */ |
| 646 |
else if (has_feature (FEATURE_AMX_FP16)) |
| 647 |
cpu = "graniterapids"; |
| 648 |
/* Assume Tiger Lake */ |
| 649 |
else if (has_feature (FEATURE_AVX512VP2INTERSECT)) |
| 650 |
cpu = "tigerlake"; |
| 651 |
/* Assume Sapphire Rapids. */ |
| 652 |
else if (has_feature (FEATURE_TSXLDTRK)) |
| 653 |
cpu = "sapphirerapids"; |
| 654 |
/* Assume Cooper Lake */ |
| 655 |
else if (has_feature (FEATURE_AVX512BF16)) |
| 656 |
cpu = "cooperlake"; |
| 657 |
/* Assume Ice Lake Server. */ |
| 658 |
else if (has_feature (FEATURE_WBNOINVD)) |
| 659 |
cpu = "icelake-server"; |
| 660 |
/* Assume Ice Lake. */ |
| 661 |
else if (has_feature (FEATURE_AVX512BITALG)) |
| 662 |
cpu = "icelake-client"; |
| 663 |
/* Assume Cannon Lake. */ |
| 664 |
else if (has_feature (FEATURE_AVX512VBMI)) |
| 665 |
cpu = "cannonlake"; |
| 666 |
/* Assume Xeon Phi Processors. Support has been removed |
| 667 |
since GCC 15. */ |
| 668 |
else if (!has_feature (FEATURE_AVX512VL)) |
| 669 |
error ("Xeon Phi ISA support has been removed since " |
| 670 |
"GCC 15, use GCC 14 for the Xeon Phi ISAs or " |
| 671 |
"%<-march=broadwell%> for all the other ISAs " |
| 672 |
"supported on this machine."); |
| 673 |
/* Assume Skylake with AVX-512. */ |
| 674 |
else |
| 675 |
cpu = "skylake-avx512"; |
| 676 |
} |
| 677 |
else if (has_feature (FEATURE_AVX)) |
| 678 |
{ |
| 679 |
/* Assume Clearwater Forest. */ |
| 680 |
if (has_feature (FEATURE_USER_MSR)) |
| 681 |
cpu = "clearwaterforest"; |
| 682 |
else if (has_feature (FEATURE_SM3)) |
| 683 |
{ |
| 684 |
if (has_feature (FEATURE_KL)) |
| 685 |
/* Assume Arrow Lake S. */ |
| 686 |
cpu = "arrowlake-s"; |
| 687 |
else |
| 688 |
/* Assume Panther Lake. */ |
| 689 |
cpu = "pantherlake"; |
| 690 |
} |
| 691 |
/* Assume Sierra Forest. */ |
| 692 |
else if (has_feature (FEATURE_CLDEMOTE)) |
| 693 |
cpu = "sierraforest"; |
| 694 |
/* Assume Arrow Lake. */ |
| 695 |
else if (has_feature (FEATURE_AVXVNNIINT8)) |
| 696 |
cpu = "arrowlake"; |
| 697 |
/* Assume Alder Lake. */ |
| 698 |
else if (has_feature (FEATURE_SERIALIZE)) |
| 699 |
cpu = "alderlake"; |
| 700 |
/* Assume Skylake. */ |
| 701 |
else if (has_feature (FEATURE_CLFLUSHOPT)) |
| 702 |
cpu = "skylake"; |
| 703 |
/* Assume Broadwell. */ |
| 704 |
else if (has_feature (FEATURE_ADX)) |
| 705 |
cpu = "broadwell"; |
| 706 |
/* Assume Haswell. */ |
| 707 |
else if (has_feature (FEATURE_AVX2)) |
| 708 |
cpu = "haswell"; |
| 709 |
/* Assume Sandy Bridge. */ |
| 710 |
else |
| 711 |
cpu = "sandybridge"; |
| 712 |
} |
| 713 |
else if (has_feature (FEATURE_SSE4_2)) |
| 714 |
{ |
| 715 |
if (has_feature (FEATURE_GFNI)) |
| 716 |
/* Assume Tremont. */ |
| 717 |
cpu = "tremont"; |
| 718 |
else if (has_feature (FEATURE_SGX)) |
| 719 |
/* Assume Goldmont Plus. */ |
| 720 |
cpu = "goldmont-plus"; |
| 721 |
else if (has_feature (FEATURE_XSAVE)) |
| 722 |
/* Assume Goldmont. */ |
| 723 |
cpu = "goldmont"; |
| 724 |
else if (has_feature (FEATURE_MOVBE)) |
| 725 |
/* Assume Silvermont. */ |
| 726 |
cpu = "silvermont"; |
| 727 |
else |
| 728 |
/* Assume Nehalem. */ |
| 729 |
cpu = "nehalem"; |
| 730 |
} |
| 731 |
else if (has_feature (FEATURE_SSSE3)) |
| 732 |
{ |
| 733 |
if (has_feature (FEATURE_MOVBE)) |
| 734 |
/* Assume Bonnell. */ |
| 735 |
cpu = "bonnell"; |
| 736 |
else |
| 737 |
/* Assume Core 2. */ |
| 738 |
cpu = "core2"; |
| 739 |
} |
| 740 |
else if (has_feature (FEATURE_LM)) |
| 741 |
/* Perhaps some emulator? Assume x86-64, otherwise gcc |
| 742 |
-march=native would be unusable for 64-bit compilations, |
| 743 |
as all the CPUs below are 32-bit only. */ |
| 744 |
cpu = "x86-64"; |
| 745 |
else if (has_feature (FEATURE_SSE3)) |
| 746 |
{ |
| 747 |
if (vendor == VENDOR_CENTAUR) |
| 748 |
/* C7 / Eden "Esther" */ |
| 749 |
cpu = "c7"; |
| 750 |
else |
| 751 |
/* It is Core Duo. */ |
| 752 |
cpu = "pentium-m"; |
| 753 |
} |
| 754 |
else if (has_feature (FEATURE_SSE2)) |
| 755 |
/* It is Pentium M. */ |
| 756 |
cpu = "pentium-m"; |
| 757 |
else if (has_feature (FEATURE_SSE)) |
| 758 |
{ |
| 759 |
if (vendor == VENDOR_CENTAUR) |
| 760 |
{ |
| 761 |
if (model >= 9) |
| 762 |
/* Eden "Nehemiah" */ |
| 763 |
cpu = "nehemiah"; |
| 764 |
else |
| 765 |
cpu = "c3-2"; |
| 766 |
} |
| 767 |
else |
| 768 |
/* It is Pentium III. */ |
| 769 |
cpu = "pentium3"; |
| 770 |
} |
| 771 |
else if (has_feature (FEATURE_MMX)) |
| 772 |
/* It is Pentium II. */ |
| 773 |
cpu = "pentium2"; |
| 774 |
else |
| 775 |
/* Default to Pentium Pro. */ |
| 776 |
cpu = "pentiumpro"; |
| 777 |
} |
| 778 |
else |
| 779 |
/* For -mtune, we default to -mtune=generic. */ |
| 780 |
cpu = "generic"; |
| 781 |
} |
| 782 |
break; |
| 783 |
case PROCESSOR_PENTIUM4: |
| 784 |
if (has_feature (FEATURE_SSE3)) |
| 785 |
{ |
| 786 |
if (has_feature (FEATURE_LM)) |
| 787 |
cpu = "nocona"; |
| 788 |
else |
| 789 |
cpu = "prescott"; |
| 790 |
} |
| 791 |
else |
| 792 |
cpu = "pentium4"; |
| 793 |
break; |
| 794 |
case PROCESSOR_GEODE: |
| 795 |
cpu = "geode"; |
| 796 |
break; |
| 797 |
case PROCESSOR_K6: |
| 798 |
if (arch && has_feature (FEATURE_3DNOW)) |
| 799 |
cpu = "k6-3"; |
| 800 |
else |
| 801 |
cpu = "k6"; |
| 802 |
break; |
| 803 |
case PROCESSOR_ATHLON: |
| 804 |
if (arch && has_feature (FEATURE_SSE)) |
| 805 |
cpu = "athlon-4"; |
| 806 |
else |
| 807 |
cpu = "athlon"; |
| 808 |
break; |
| 809 |
case PROCESSOR_K8: |
| 810 |
if (arch) |
| 811 |
{ |
| 812 |
if (vendor == VENDOR_CENTAUR) |
| 813 |
{ |
| 814 |
if (has_feature (FEATURE_SSE4_1)) |
| 815 |
/* Nano 3000 | Nano dual / quad core | Eden X4 */ |
| 816 |
cpu = "nano-3000"; |
| 817 |
else if (has_feature (FEATURE_SSSE3)) |
| 818 |
/* Nano 1000 | Nano 2000 */ |
| 819 |
cpu = "nano"; |
| 820 |
else if (has_feature (FEATURE_SSE3)) |
| 821 |
/* Eden X2 */ |
| 822 |
cpu = "eden-x2"; |
| 823 |
else |
| 824 |
/* Default to k8 */ |
| 825 |
cpu = "k8"; |
| 826 |
} |
| 827 |
else if (has_feature (FEATURE_SSE3)) |
| 828 |
cpu = "k8-sse3"; |
| 829 |
else |
| 830 |
cpu = "k8"; |
| 831 |
} |
| 832 |
else |
| 833 |
/* For -mtune, we default to -mtune=k8 */ |
| 834 |
cpu = "k8"; |
| 835 |
break; |
| 836 |
case PROCESSOR_AMDFAM10: |
| 837 |
cpu = "amdfam10"; |
| 838 |
break; |
| 839 |
case PROCESSOR_BDVER1: |
| 840 |
cpu = "bdver1"; |
| 841 |
break; |
| 842 |
case PROCESSOR_BDVER2: |
| 843 |
cpu = "bdver2"; |
| 844 |
break; |
| 845 |
case PROCESSOR_BDVER3: |
| 846 |
cpu = "bdver3"; |
| 847 |
break; |
| 848 |
case PROCESSOR_BDVER4: |
| 849 |
cpu = "bdver4"; |
| 850 |
break; |
| 851 |
case PROCESSOR_ZNVER1: |
| 852 |
cpu = "znver1"; |
| 853 |
break; |
| 854 |
case PROCESSOR_ZNVER2: |
| 855 |
cpu = "znver2"; |
| 856 |
break; |
| 857 |
case PROCESSOR_ZNVER3: |
| 858 |
cpu = "znver3"; |
| 859 |
break; |
| 860 |
case PROCESSOR_ZNVER4: |
| 861 |
cpu = "znver4"; |
| 862 |
break; |
| 863 |
case PROCESSOR_ZNVER5: |
| 864 |
cpu = "znver5"; |
| 865 |
break; |
| 866 |
case PROCESSOR_BTVER1: |
| 867 |
cpu = "btver1"; |
| 868 |
break; |
| 869 |
case PROCESSOR_BTVER2: |
| 870 |
cpu = "btver2"; |
| 871 |
break; |
| 872 |
case PROCESSOR_LUJIAZUI: |
| 873 |
cpu = "lujiazui"; |
| 874 |
break; |
| 875 |
case PROCESSOR_YONGFENG: |
| 876 |
cpu = "yongfeng"; |
| 877 |
break; |
| 878 |
case PROCESSOR_SHIJIDADAO: |
| 879 |
cpu = "shijidadao"; |
| 880 |
break; |
| 881 |
case PROCESSOR_C86_4G_M4: |
| 882 |
cpu = "c86-4g-m4"; |
| 883 |
break; |
| 884 |
case PROCESSOR_C86_4G_M6: |
| 885 |
cpu = "c86-4g-m6"; |
| 886 |
break; |
| 887 |
case PROCESSOR_C86_4G_M7: |
| 888 |
cpu = "c86-4g-m7"; |
| 889 |
break; |
| 890 |
|
| 891 |
default: |
| 892 |
/* Use something reasonable. */ |
| 893 |
if (arch) |
| 894 |
{ |
| 895 |
if (has_feature (FEATURE_SSSE3)) |
| 896 |
cpu = "core2"; |
| 897 |
else if (has_feature (FEATURE_SSE3)) |
| 898 |
{ |
| 899 |
if (has_feature (FEATURE_LM)) |
| 900 |
cpu = "nocona"; |
| 901 |
else |
| 902 |
cpu = "prescott"; |
| 903 |
} |
| 904 |
else if (has_feature (FEATURE_LM)) |
| 905 |
/* Perhaps some emulator? Assume x86-64, otherwise gcc |
| 906 |
-march=native would be unusable for 64-bit compilations, |
| 907 |
as all the CPUs below are 32-bit only. */ |
| 908 |
cpu = "x86-64"; |
| 909 |
else if (has_feature (FEATURE_SSE2)) |
| 910 |
cpu = "pentium4"; |
| 911 |
else if (has_feature (FEATURE_CMOV)) |
| 912 |
cpu = "pentiumpro"; |
| 913 |
else if (has_feature (FEATURE_MMX)) |
| 914 |
cpu = "pentium-mmx"; |
| 915 |
else if (has_feature (FEATURE_CMPXCHG8B)) |
| 916 |
cpu = "pentium"; |
| 917 |
} |
| 918 |
else |
| 919 |
cpu = "generic"; |
| 920 |
} |
| 921 |
|
| 922 |
if (arch) |
| 923 |
{ |
| 924 |
unsigned int i; |
| 925 |
const char *const neg_option = " -mno-"; |
| 926 |
for (i = 0; i < ARRAY_SIZE (isa_names_table); i++) |
| 927 |
if (isa_names_table[i].option) |
| 928 |
{ |
| 929 |
if (has_feature (isa_names_table[i].feature)) |
| 930 |
{ |
| 931 |
if (codegen_x86_64 |
| 932 |
|| (isa_names_table[i].feature != FEATURE_UINTR |
| 933 |
&& isa_names_table[i].feature != FEATURE_APX_F)) |
| 934 |
options = concat (options, " ", |
| 935 |
isa_names_table[i].option, NULL); |
| 936 |
} |
| 937 |
/* Never push -mno-avx10.1-{256,512} under -march=native to |
| 938 |
avoid unnecessary warnings when building libraries. */ |
| 939 |
else if (isa_names_table[i].feature != FEATURE_AVX10_1_256 |
| 940 |
&& isa_names_table[i].feature != FEATURE_AVX10_1 |
| 941 |
&& check_avx512_features (cpu_model, cpu_features2, |
| 942 |
isa_names_table[i].feature)) |
| 943 |
options = concat (options, neg_option, |
| 944 |
isa_names_table[i].option + 2, NULL); |
| 945 |
} |
| 946 |
} |
| 947 |
|
| 948 |
done: |
| 949 |
return concat (cache, "-m", argv[0], "=", cpu, options, NULL); |
| 950 |
} |
| 951 |
#else |
| 952 |
|
| 953 |
/* If we are compiling with GCC where %EBX register is fixed, then the |
| 954 |
driver will just ignore -march and -mtune "native" target and will leave |
| 955 |
to the newly built compiler to generate code for its default target. */ |
| 956 |
|
| 957 |
const char *host_detect_local_cpu (int, const char **) |
| 958 |
{ |
| 959 |
return NULL; |
| 960 |
} |
| 961 |
#endif /* __GNUC__ */ |