]>
Commit | Line | Data |
---|---|---|
fa959ce4 | 1 | /* Subroutines for the gcc driver. |
99dee823 | 2 | Copyright (C) 2006-2021 Free Software Foundation, Inc. |
fa959ce4 MM |
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 | |
2f83c7d6 | 8 | the Free Software Foundation; either version 3, or (at your option) |
fa959ce4 MM |
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 | |
2f83c7d6 NC |
17 | along with GCC; see the file COPYING3. If not see |
18 | <http://www.gnu.org/licenses/>. */ | |
fa959ce4 | 19 | |
8fcc61f8 RS |
20 | #define IN_TARGET_CODE 1 |
21 | ||
fa959ce4 MM |
22 | #include "config.h" |
23 | #include "system.h" | |
edccdcb1 L |
24 | #include "coretypes.h" |
25 | #include "tm.h" | |
fa959ce4 | 26 | |
895016f6 UB |
27 | const char *host_detect_local_cpu (int argc, const char **argv); |
28 | ||
02147868 | 29 | #if defined(__GNUC__) && (__GNUC__ >= 5 || !defined(__PIC__)) |
b3172cab | 30 | #include "cpuid.h" |
6c35d16a L |
31 | #include "common/config/i386/cpuinfo.h" |
32 | #include "common/config/i386/i386-isas.h" | |
fa959ce4 | 33 | |
cb0dee88 UB |
34 | struct cache_desc |
35 | { | |
36 | unsigned sizekb; | |
37 | unsigned assoc; | |
38 | unsigned line; | |
39 | }; | |
40 | ||
41 | /* Returns command line parameters that describe size and | |
42 | cache line size of the processor caches. */ | |
2711355f ZD |
43 | |
44 | static char * | |
cb0dee88 | 45 | describe_cache (struct cache_desc level1, struct cache_desc level2) |
2711355f | 46 | { |
f4a1dd0d | 47 | char size[100], line[100], size2[100]; |
2711355f | 48 | |
cb0dee88 UB |
49 | /* At the moment, gcc does not use the information |
50 | about the associativity of the cache. */ | |
51 | ||
f3afc8a7 UB |
52 | snprintf (size, sizeof (size), |
53 | "--param l1-cache-size=%u ", level1.sizekb); | |
54 | snprintf (line, sizeof (line), | |
55 | "--param l1-cache-line-size=%u ", level1.line); | |
2711355f | 56 | |
f3afc8a7 UB |
57 | snprintf (size2, sizeof (size2), |
58 | "--param l2-cache-size=%u ", level2.sizekb); | |
2711355f | 59 | |
f3afc8a7 | 60 | return concat (size, line, size2, NULL); |
f4a1dd0d ZM |
61 | } |
62 | ||
cb0dee88 UB |
63 | /* Detect L2 cache parameters using CPUID extended function 0x80000006. */ |
64 | ||
f4a1dd0d | 65 | static void |
cb0dee88 | 66 | detect_l2_cache (struct cache_desc *level2) |
f4a1dd0d | 67 | { |
cb0dee88 UB |
68 | unsigned eax, ebx, ecx, edx; |
69 | unsigned assoc; | |
f4a1dd0d ZM |
70 | |
71 | __cpuid (0x80000006, eax, ebx, ecx, edx); | |
72 | ||
cb0dee88 UB |
73 | level2->sizekb = (ecx >> 16) & 0xffff; |
74 | level2->line = ecx & 0xff; | |
75 | ||
f4a1dd0d ZM |
76 | assoc = (ecx >> 12) & 0xf; |
77 | if (assoc == 6) | |
78 | assoc = 8; | |
79 | else if (assoc == 8) | |
80 | assoc = 16; | |
81 | else if (assoc >= 0xa && assoc <= 0xc) | |
82 | assoc = 32 + (assoc - 0xa) * 16; | |
83 | else if (assoc >= 0xd && assoc <= 0xe) | |
84 | assoc = 96 + (assoc - 0xd) * 32; | |
cb0dee88 UB |
85 | |
86 | level2->assoc = assoc; | |
2711355f ZD |
87 | } |
88 | ||
89 | /* Returns the description of caches for an AMD processor. */ | |
90 | ||
d3bfe4de | 91 | static const char * |
2711355f ZD |
92 | detect_caches_amd (unsigned max_ext_level) |
93 | { | |
94 | unsigned eax, ebx, ecx, edx; | |
cb0dee88 UB |
95 | |
96 | struct cache_desc level1, level2 = {0, 0, 0}; | |
2711355f ZD |
97 | |
98 | if (max_ext_level < 0x80000005) | |
d3bfe4de | 99 | return ""; |
2711355f | 100 | |
b3172cab | 101 | __cpuid (0x80000005, eax, ebx, ecx, edx); |
2711355f | 102 | |
cb0dee88 UB |
103 | level1.sizekb = (ecx >> 24) & 0xff; |
104 | level1.assoc = (ecx >> 16) & 0xff; | |
105 | level1.line = ecx & 0xff; | |
2711355f | 106 | |
f4a1dd0d | 107 | if (max_ext_level >= 0x80000006) |
cb0dee88 | 108 | detect_l2_cache (&level2); |
f4a1dd0d | 109 | |
cb0dee88 | 110 | return describe_cache (level1, level2); |
2711355f ZD |
111 | } |
112 | ||
cb0dee88 UB |
113 | /* Decodes the size, the associativity and the cache line size of |
114 | L1/L2 caches of an Intel processor. Values are based on | |
115 | "Intel Processor Identification and the CPUID Instruction" | |
116 | [Application Note 485], revision -032, December 2007. */ | |
2711355f ZD |
117 | |
118 | static void | |
cb0dee88 UB |
119 | decode_caches_intel (unsigned reg, bool xeon_mp, |
120 | struct cache_desc *level1, struct cache_desc *level2) | |
2711355f | 121 | { |
cb0dee88 UB |
122 | int i; |
123 | ||
124 | for (i = 24; i >= 0; i -= 8) | |
125 | switch ((reg >> i) & 0xff) | |
126 | { | |
127 | case 0x0a: | |
128 | level1->sizekb = 8; level1->assoc = 2; level1->line = 32; | |
129 | break; | |
130 | case 0x0c: | |
131 | level1->sizekb = 16; level1->assoc = 4; level1->line = 32; | |
132 | break; | |
f313cce5 UB |
133 | case 0x0d: |
134 | level1->sizekb = 16; level1->assoc = 4; level1->line = 64; | |
135 | break; | |
136 | case 0x0e: | |
137 | level1->sizekb = 24; level1->assoc = 6; level1->line = 64; | |
138 | break; | |
139 | case 0x21: | |
140 | level2->sizekb = 256; level2->assoc = 8; level2->line = 64; | |
141 | break; | |
142 | case 0x24: | |
143 | level2->sizekb = 1024; level2->assoc = 16; level2->line = 64; | |
144 | break; | |
cb0dee88 UB |
145 | case 0x2c: |
146 | level1->sizekb = 32; level1->assoc = 8; level1->line = 64; | |
147 | break; | |
148 | case 0x39: | |
149 | level2->sizekb = 128; level2->assoc = 4; level2->line = 64; | |
150 | break; | |
151 | case 0x3a: | |
152 | level2->sizekb = 192; level2->assoc = 6; level2->line = 64; | |
153 | break; | |
154 | case 0x3b: | |
155 | level2->sizekb = 128; level2->assoc = 2; level2->line = 64; | |
156 | break; | |
157 | case 0x3c: | |
158 | level2->sizekb = 256; level2->assoc = 4; level2->line = 64; | |
159 | break; | |
160 | case 0x3d: | |
161 | level2->sizekb = 384; level2->assoc = 6; level2->line = 64; | |
162 | break; | |
163 | case 0x3e: | |
164 | level2->sizekb = 512; level2->assoc = 4; level2->line = 64; | |
165 | break; | |
166 | case 0x41: | |
167 | level2->sizekb = 128; level2->assoc = 4; level2->line = 32; | |
168 | break; | |
169 | case 0x42: | |
170 | level2->sizekb = 256; level2->assoc = 4; level2->line = 32; | |
171 | break; | |
172 | case 0x43: | |
173 | level2->sizekb = 512; level2->assoc = 4; level2->line = 32; | |
174 | break; | |
175 | case 0x44: | |
176 | level2->sizekb = 1024; level2->assoc = 4; level2->line = 32; | |
177 | break; | |
178 | case 0x45: | |
179 | level2->sizekb = 2048; level2->assoc = 4; level2->line = 32; | |
180 | break; | |
f313cce5 UB |
181 | case 0x48: |
182 | level2->sizekb = 3072; level2->assoc = 12; level2->line = 64; | |
183 | break; | |
cb0dee88 UB |
184 | case 0x49: |
185 | if (xeon_mp) | |
186 | break; | |
187 | level2->sizekb = 4096; level2->assoc = 16; level2->line = 64; | |
188 | break; | |
189 | case 0x4e: | |
190 | level2->sizekb = 6144; level2->assoc = 24; level2->line = 64; | |
191 | break; | |
192 | case 0x60: | |
193 | level1->sizekb = 16; level1->assoc = 8; level1->line = 64; | |
194 | break; | |
195 | case 0x66: | |
196 | level1->sizekb = 8; level1->assoc = 4; level1->line = 64; | |
197 | break; | |
198 | case 0x67: | |
199 | level1->sizekb = 16; level1->assoc = 4; level1->line = 64; | |
200 | break; | |
201 | case 0x68: | |
202 | level1->sizekb = 32; level1->assoc = 4; level1->line = 64; | |
203 | break; | |
204 | case 0x78: | |
205 | level2->sizekb = 1024; level2->assoc = 4; level2->line = 64; | |
206 | break; | |
207 | case 0x79: | |
208 | level2->sizekb = 128; level2->assoc = 8; level2->line = 64; | |
209 | break; | |
210 | case 0x7a: | |
211 | level2->sizekb = 256; level2->assoc = 8; level2->line = 64; | |
212 | break; | |
213 | case 0x7b: | |
214 | level2->sizekb = 512; level2->assoc = 8; level2->line = 64; | |
215 | break; | |
216 | case 0x7c: | |
217 | level2->sizekb = 1024; level2->assoc = 8; level2->line = 64; | |
218 | break; | |
219 | case 0x7d: | |
220 | level2->sizekb = 2048; level2->assoc = 8; level2->line = 64; | |
221 | break; | |
222 | case 0x7f: | |
223 | level2->sizekb = 512; level2->assoc = 2; level2->line = 64; | |
224 | break; | |
f313cce5 UB |
225 | case 0x80: |
226 | level2->sizekb = 512; level2->assoc = 8; level2->line = 64; | |
227 | break; | |
cb0dee88 UB |
228 | case 0x82: |
229 | level2->sizekb = 256; level2->assoc = 8; level2->line = 32; | |
230 | break; | |
231 | case 0x83: | |
232 | level2->sizekb = 512; level2->assoc = 8; level2->line = 32; | |
233 | break; | |
234 | case 0x84: | |
235 | level2->sizekb = 1024; level2->assoc = 8; level2->line = 32; | |
236 | break; | |
237 | case 0x85: | |
238 | level2->sizekb = 2048; level2->assoc = 8; level2->line = 32; | |
239 | break; | |
240 | case 0x86: | |
241 | level2->sizekb = 512; level2->assoc = 4; level2->line = 64; | |
242 | break; | |
243 | case 0x87: | |
244 | level2->sizekb = 1024; level2->assoc = 8; level2->line = 64; | |
245 | ||
246 | default: | |
247 | break; | |
248 | } | |
249 | } | |
2711355f | 250 | |
cb0dee88 | 251 | /* Detect cache parameters using CPUID function 2. */ |
2711355f | 252 | |
cb0dee88 UB |
253 | static void |
254 | detect_caches_cpuid2 (bool xeon_mp, | |
255 | struct cache_desc *level1, struct cache_desc *level2) | |
256 | { | |
dc8bd8d9 UB |
257 | unsigned regs[4]; |
258 | int nreps, i; | |
cb0dee88 | 259 | |
dc8bd8d9 | 260 | __cpuid (2, regs[0], regs[1], regs[2], regs[3]); |
cb0dee88 | 261 | |
dc8bd8d9 UB |
262 | nreps = regs[0] & 0x0f; |
263 | regs[0] &= ~0x0f; | |
cb0dee88 UB |
264 | |
265 | while (--nreps >= 0) | |
2711355f | 266 | { |
dc8bd8d9 UB |
267 | for (i = 0; i < 4; i++) |
268 | if (regs[i] && !((regs[i] >> 31) & 1)) | |
269 | decode_caches_intel (regs[i], xeon_mp, level1, level2); | |
cb0dee88 UB |
270 | |
271 | if (nreps) | |
dc8bd8d9 | 272 | __cpuid (2, regs[0], regs[1], regs[2], regs[3]); |
cb0dee88 UB |
273 | } |
274 | } | |
2711355f | 275 | |
cb0dee88 UB |
276 | /* Detect cache parameters using CPUID function 4. This |
277 | method doesn't require hardcoded tables. */ | |
2711355f | 278 | |
cb0dee88 UB |
279 | enum cache_type |
280 | { | |
281 | CACHE_END = 0, | |
282 | CACHE_DATA = 1, | |
283 | CACHE_INST = 2, | |
284 | CACHE_UNIFIED = 3 | |
285 | }; | |
286 | ||
287 | static void | |
a0463099 AK |
288 | detect_caches_cpuid4 (struct cache_desc *level1, struct cache_desc *level2, |
289 | struct cache_desc *level3) | |
cb0dee88 UB |
290 | { |
291 | struct cache_desc *cache; | |
292 | ||
293 | unsigned eax, ebx, ecx, edx; | |
294 | int count; | |
295 | ||
296 | for (count = 0;; count++) | |
297 | { | |
298 | __cpuid_count(4, count, eax, ebx, ecx, edx); | |
299 | switch (eax & 0x1f) | |
300 | { | |
301 | case CACHE_END: | |
302 | return; | |
303 | case CACHE_DATA: | |
304 | case CACHE_UNIFIED: | |
305 | { | |
306 | switch ((eax >> 5) & 0x07) | |
307 | { | |
308 | case 1: | |
309 | cache = level1; | |
310 | break; | |
311 | case 2: | |
312 | cache = level2; | |
313 | break; | |
a0463099 AK |
314 | case 3: |
315 | cache = level3; | |
316 | break; | |
cb0dee88 UB |
317 | default: |
318 | cache = NULL; | |
319 | } | |
320 | ||
321 | if (cache) | |
322 | { | |
323 | unsigned sets = ecx + 1; | |
dc8bd8d9 | 324 | unsigned part = ((ebx >> 12) & 0x03ff) + 1; |
cb0dee88 | 325 | |
dc8bd8d9 | 326 | cache->assoc = ((ebx >> 22) & 0x03ff) + 1; |
cb0dee88 | 327 | cache->line = (ebx & 0x0fff) + 1; |
cb0dee88 UB |
328 | |
329 | cache->sizekb = (cache->assoc * part | |
330 | * cache->line * sets) / 1024; | |
a0463099 | 331 | } |
cb0dee88 | 332 | } |
2711355f ZD |
333 | default: |
334 | break; | |
335 | } | |
336 | } | |
337 | } | |
338 | ||
cb0dee88 | 339 | /* Returns the description of caches for an Intel processor. */ |
2711355f | 340 | |
d3bfe4de | 341 | static const char * |
a0463099 AK |
342 | detect_caches_intel (bool xeon_mp, unsigned max_level, |
343 | unsigned max_ext_level, unsigned *l2sizekb) | |
2711355f | 344 | { |
a0463099 | 345 | struct cache_desc level1 = {0, 0, 0}, level2 = {0, 0, 0}, level3 = {0, 0, 0}; |
2711355f | 346 | |
cb0dee88 | 347 | if (max_level >= 4) |
a0463099 | 348 | detect_caches_cpuid4 (&level1, &level2, &level3); |
cb0dee88 UB |
349 | else if (max_level >= 2) |
350 | detect_caches_cpuid2 (xeon_mp, &level1, &level2); | |
351 | else | |
d3bfe4de | 352 | return ""; |
2711355f | 353 | |
cb0dee88 | 354 | if (level1.sizekb == 0) |
d3bfe4de | 355 | return ""; |
2711355f | 356 | |
a0463099 AK |
357 | /* Let the L3 replace the L2. This assumes inclusive caches |
358 | and single threaded program for now. */ | |
359 | if (level3.sizekb) | |
360 | level2 = level3; | |
361 | ||
cb0dee88 UB |
362 | /* Intel CPUs are equipped with AMD style L2 cache info. Try this |
363 | method if other methods fail to provide L2 cache parameters. */ | |
364 | if (level2.sizekb == 0 && max_ext_level >= 0x80000006) | |
365 | detect_l2_cache (&level2); | |
f4a1dd0d | 366 | |
a0463099 AK |
367 | *l2sizekb = level2.sizekb; |
368 | ||
cb0dee88 | 369 | return describe_cache (level1, level2); |
2711355f ZD |
370 | } |
371 | ||
fa959ce4 MM |
372 | /* This will be called by the spec parser in gcc.c when it sees |
373 | a %:local_cpu_detect(args) construct. Currently it will be called | |
374 | with either "arch" or "tune" as argument depending on if -march=native | |
375 | or -mtune=native is to be substituted. | |
376 | ||
377 | It returns a string containing new command line parameters to be | |
378 | put at the place of the above two options, depending on what CPU | |
379 | this is executed. E.g. "-march=k8" on an AMD64 machine | |
380 | for -march=native. | |
381 | ||
382 | ARGC and ARGV are set depending on the actual arguments given | |
383 | in the spec. */ | |
b3172cab | 384 | |
fa959ce4 MM |
385 | const char *host_detect_local_cpu (int argc, const char **argv) |
386 | { | |
b3172cab UB |
387 | enum processor_type processor = PROCESSOR_I386; |
388 | const char *cpu = "i386"; | |
389 | ||
2711355f | 390 | const char *cache = ""; |
5be6cb59 | 391 | const char *options = ""; |
b3172cab | 392 | |
6c35d16a | 393 | unsigned int ebx, ecx, edx; |
b3172cab UB |
394 | |
395 | unsigned int max_level, ext_level; | |
cb0dee88 | 396 | |
fa959ce4 | 397 | unsigned int vendor; |
cb0dee88 | 398 | unsigned int model, family; |
b3172cab | 399 | |
edccdcb1 L |
400 | bool arch; |
401 | ||
a0463099 AK |
402 | unsigned int l2sizekb = 0; |
403 | ||
edccdcb1 L |
404 | if (argc < 1) |
405 | return NULL; | |
406 | ||
b3172cab UB |
407 | arch = !strcmp (argv[0], "arch"); |
408 | ||
edccdcb1 | 409 | if (!arch && strcmp (argv[0], "tune")) |
fa959ce4 MM |
410 | return NULL; |
411 | ||
6c35d16a L |
412 | struct __processor_model cpu_model = { }; |
413 | struct __processor_model2 cpu_model2 = { }; | |
414 | unsigned int cpu_features2[SIZE_OF_CPU_FEATURES] = { }; | |
fa959ce4 | 415 | |
6c35d16a L |
416 | if (cpu_indicator_init (&cpu_model, &cpu_model2, cpu_features2) != 0) |
417 | goto done; | |
a91529c4 | 418 | |
6c35d16a L |
419 | vendor = cpu_model.__cpu_vendor; |
420 | family = cpu_model2.__cpu_family; | |
421 | model = cpu_model2.__cpu_model; | |
422 | max_level = cpu_model2.__cpu_max_level; | |
423 | ext_level = cpu_model2.__cpu_ext_level; | |
2c12f2f4 | 424 | |
2711355f ZD |
425 | if (!arch) |
426 | { | |
6c35d16a L |
427 | if (vendor == VENDOR_AMD |
428 | || vendor == VENDOR_CENTAUR | |
429 | || vendor == VENDOR_CYRIX | |
430 | || vendor == VENDOR_NSC) | |
2711355f | 431 | cache = detect_caches_amd (ext_level); |
6c35d16a | 432 | else if (vendor == VENDOR_INTEL) |
cb0dee88 UB |
433 | { |
434 | bool xeon_mp = (family == 15 && model == 6); | |
a0463099 AK |
435 | cache = detect_caches_intel (xeon_mp, max_level, |
436 | ext_level, &l2sizekb); | |
cb0dee88 | 437 | } |
2711355f ZD |
438 | } |
439 | ||
6c35d16a L |
440 | /* Extended features */ |
441 | #define has_feature(f) \ | |
442 | has_cpu_feature (&cpu_model, cpu_features2, f) | |
443 | ||
444 | if (vendor == VENDOR_AMD) | |
fa959ce4 | 445 | { |
fbdf817d | 446 | unsigned int name; |
b3172cab | 447 | |
fbdf817d | 448 | /* Detect geode processor by its processor signature. */ |
0a2d7bc0 | 449 | if (ext_level >= 0x80000002) |
fbdf817d UB |
450 | __cpuid (0x80000002, name, ebx, ecx, edx); |
451 | else | |
452 | name = 0; | |
453 | ||
ef64d158 | 454 | if (name == signature_NSC_ebx) |
fbdf817d | 455 | processor = PROCESSOR_GEODE; |
6c35d16a | 456 | else if (has_feature (FEATURE_MOVBE) && family == 22) |
e32bfc16 | 457 | processor = PROCESSOR_BTVER2; |
3e2ae3ee VK |
458 | else if (has_feature (FEATURE_VAES)) |
459 | processor = PROCESSOR_ZNVER3; | |
6c35d16a | 460 | else if (has_feature (FEATURE_CLWB)) |
2901f42f | 461 | processor = PROCESSOR_ZNVER2; |
6c35d16a | 462 | else if (has_feature (FEATURE_CLZERO)) |
9ce29eb0 | 463 | processor = PROCESSOR_ZNVER1; |
6c35d16a L |
464 | else if (has_feature (FEATURE_AVX2)) |
465 | processor = PROCESSOR_BDVER4; | |
466 | else if (has_feature (FEATURE_XSAVEOPT)) | |
467 | processor = PROCESSOR_BDVER3; | |
468 | else if (has_feature (FEATURE_BMI)) | |
469 | processor = PROCESSOR_BDVER2; | |
470 | else if (has_feature (FEATURE_XOP)) | |
1133125e | 471 | processor = PROCESSOR_BDVER1; |
6c35d16a L |
472 | else if (has_feature (FEATURE_SSE4_A) |
473 | && has_feature (FEATURE_SSSE3)) | |
474 | processor = PROCESSOR_BTVER1; | |
475 | else if (has_feature (FEATURE_SSE4_A)) | |
35a63f21 | 476 | processor = PROCESSOR_AMDFAM10; |
6c35d16a L |
477 | else if (has_feature (FEATURE_SSE2) |
478 | || has_feature (FEATURE_LM)) | |
fbdf817d | 479 | processor = PROCESSOR_K8; |
6c35d16a | 480 | else if (has_feature (FEATURE_3DNOWP) && family == 6) |
fbdf817d | 481 | processor = PROCESSOR_ATHLON; |
6c35d16a | 482 | else if (has_feature (FEATURE_MMX)) |
fbdf817d UB |
483 | processor = PROCESSOR_K6; |
484 | else | |
485 | processor = PROCESSOR_PENTIUM; | |
fa959ce4 | 486 | } |
6c35d16a | 487 | else if (vendor == VENDOR_CENTAUR) |
19db293a | 488 | { |
4bdf739d UB |
489 | processor = PROCESSOR_GENERIC; |
490 | ||
491 | switch (family) | |
19db293a | 492 | { |
4bdf739d UB |
493 | default: |
494 | /* We have no idea. */ | |
495 | break; | |
496 | ||
497 | case 5: | |
6c35d16a L |
498 | if (has_feature (FEATURE_3DNOW) |
499 | || has_feature (FEATURE_MMX)) | |
4bdf739d UB |
500 | processor = PROCESSOR_I486; |
501 | break; | |
502 | ||
503 | case 6: | |
6c35d16a | 504 | if (has_feature (FEATURE_LM)) |
d3606ee3 | 505 | processor = PROCESSOR_K8; |
a239d460 | 506 | else if (model >= 9) |
4bdf739d UB |
507 | processor = PROCESSOR_PENTIUMPRO; |
508 | else if (model >= 6) | |
509 | processor = PROCESSOR_I486; | |
19db293a UB |
510 | } |
511 | } | |
fa959ce4 MM |
512 | else |
513 | { | |
edccdcb1 L |
514 | switch (family) |
515 | { | |
b3172cab UB |
516 | case 4: |
517 | processor = PROCESSOR_I486; | |
518 | break; | |
edccdcb1 | 519 | case 5: |
b3172cab | 520 | processor = PROCESSOR_PENTIUM; |
edccdcb1 L |
521 | break; |
522 | case 6: | |
523 | processor = PROCESSOR_PENTIUMPRO; | |
524 | break; | |
525 | case 15: | |
526 | processor = PROCESSOR_PENTIUM4; | |
527 | break; | |
528 | default: | |
b3172cab | 529 | /* We have no idea. */ |
9d532162 | 530 | processor = PROCESSOR_GENERIC; |
edccdcb1 L |
531 | } |
532 | } | |
533 | ||
534 | switch (processor) | |
535 | { | |
536 | case PROCESSOR_I386: | |
b3172cab | 537 | /* Default. */ |
edccdcb1 L |
538 | break; |
539 | case PROCESSOR_I486: | |
6c35d16a | 540 | if (arch && vendor == VENDOR_CENTAUR) |
4bdf739d UB |
541 | { |
542 | if (model >= 6) | |
543 | cpu = "c3"; | |
6c35d16a | 544 | else if (has_feature (FEATURE_3DNOW)) |
4bdf739d UB |
545 | cpu = "winchip2"; |
546 | else | |
547 | /* Assume WinChip C6. */ | |
548 | cpu = "winchip-c6"; | |
549 | } | |
550 | else | |
551 | cpu = "i486"; | |
edccdcb1 L |
552 | break; |
553 | case PROCESSOR_PENTIUM: | |
6c35d16a | 554 | if (arch && has_feature (FEATURE_MMX)) |
edccdcb1 L |
555 | cpu = "pentium-mmx"; |
556 | else | |
557 | cpu = "pentium"; | |
558 | break; | |
559 | case PROCESSOR_PENTIUMPRO: | |
134f7c94 | 560 | cpu = get_intel_cpu (&cpu_model, &cpu_model2, cpu_features2); |
6c35d16a | 561 | if (cpu == NULL) |
edccdcb1 | 562 | { |
44f276c6 L |
563 | if (arch) |
564 | { | |
4ffae7ff | 565 | /* This is unknown family 0x6 CPU. */ |
6c35d16a L |
566 | if (has_feature (FEATURE_AVX)) |
567 | { | |
6c35d16a | 568 | if (has_feature (FEATURE_AVX512VP2INTERSECT)) |
ba9c87d3 CL |
569 | { |
570 | if (has_feature (FEATURE_TSXLDTRK)) | |
571 | /* Assume Sapphire Rapids. */ | |
572 | cpu = "sapphirerapids"; | |
573 | else | |
574 | /* Assume Tiger Lake */ | |
575 | cpu = "tigerlake"; | |
576 | } | |
6c35d16a L |
577 | /* Assume Cooper Lake */ |
578 | else if (has_feature (FEATURE_AVX512BF16)) | |
579 | cpu = "cooperlake"; | |
580 | /* Assume Ice Lake Server. */ | |
581 | else if (has_feature (FEATURE_WBNOINVD)) | |
582 | cpu = "icelake-server"; | |
a9fcfec3 | 583 | /* Assume Ice Lake. */ |
6c35d16a | 584 | else if (has_feature (FEATURE_AVX512BITALG)) |
a9fcfec3 HL |
585 | cpu = "icelake-client"; |
586 | /* Assume Cannon Lake. */ | |
6c35d16a | 587 | else if (has_feature (FEATURE_AVX512VBMI)) |
a9fcfec3 HL |
588 | cpu = "cannonlake"; |
589 | /* Assume Knights Mill. */ | |
6c35d16a | 590 | else if (has_feature (FEATURE_AVX5124VNNIW)) |
a9fcfec3 HL |
591 | cpu = "knm"; |
592 | /* Assume Knights Landing. */ | |
6c35d16a | 593 | else if (has_feature (FEATURE_AVX512ER)) |
a9fcfec3 HL |
594 | cpu = "knl"; |
595 | /* Assume Skylake with AVX-512. */ | |
6c35d16a | 596 | else if (has_feature (FEATURE_AVX512F)) |
a9fcfec3 | 597 | cpu = "skylake-avx512"; |
ba9c87d3 CL |
598 | /* Assume Alder Lake */ |
599 | else if (has_feature (FEATURE_SERIALIZE)) | |
600 | cpu = "alderlake"; | |
a9fcfec3 | 601 | /* Assume Skylake. */ |
6c35d16a | 602 | else if (has_feature (FEATURE_CLFLUSHOPT)) |
a9fcfec3 HL |
603 | cpu = "skylake"; |
604 | /* Assume Broadwell. */ | |
6c35d16a | 605 | else if (has_feature (FEATURE_ADX)) |
a9fcfec3 | 606 | cpu = "broadwell"; |
6c35d16a | 607 | else if (has_feature (FEATURE_AVX2)) |
992592ec | 608 | /* Assume Haswell. */ |
a9fcfec3 HL |
609 | cpu = "haswell"; |
610 | else | |
4ffae7ff | 611 | /* Assume Sandy Bridge. */ |
a9fcfec3 HL |
612 | cpu = "sandybridge"; |
613 | } | |
6c35d16a | 614 | else if (has_feature (FEATURE_SSE4_2)) |
0b871ccf | 615 | { |
6c35d16a | 616 | if (has_feature (FEATURE_GFNI)) |
a548a5a1 OM |
617 | /* Assume Tremont. */ |
618 | cpu = "tremont"; | |
6c35d16a | 619 | else if (has_feature (FEATURE_SGX)) |
74b2bb19 OM |
620 | /* Assume Goldmont Plus. */ |
621 | cpu = "goldmont-plus"; | |
6c35d16a | 622 | else if (has_feature (FEATURE_XSAVE)) |
50e461df OM |
623 | /* Assume Goldmont. */ |
624 | cpu = "goldmont"; | |
6c35d16a | 625 | else if (has_feature (FEATURE_MOVBE)) |
d3c11974 L |
626 | /* Assume Silvermont. */ |
627 | cpu = "silvermont"; | |
0b871ccf | 628 | else |
d3c11974 L |
629 | /* Assume Nehalem. */ |
630 | cpu = "nehalem"; | |
0b871ccf | 631 | } |
6c35d16a | 632 | else if (has_feature (FEATURE_SSSE3)) |
4ffae7ff | 633 | { |
6c35d16a | 634 | if (has_feature (FEATURE_MOVBE)) |
d3c11974 L |
635 | /* Assume Bonnell. */ |
636 | cpu = "bonnell"; | |
4ffae7ff L |
637 | else |
638 | /* Assume Core 2. */ | |
639 | cpu = "core2"; | |
640 | } | |
6c35d16a | 641 | else if (has_feature (FEATURE_LM)) |
8d37375b JJ |
642 | /* Perhaps some emulator? Assume x86-64, otherwise gcc |
643 | -march=native would be unusable for 64-bit compilations, | |
644 | as all the CPUs below are 32-bit only. */ | |
645 | cpu = "x86-64"; | |
6c35d16a | 646 | else if (has_feature (FEATURE_SSE3)) |
a239d460 | 647 | { |
6c35d16a | 648 | if (vendor == VENDOR_CENTAUR) |
a239d460 JM |
649 | /* C7 / Eden "Esther" */ |
650 | cpu = "c7"; | |
651 | else | |
652 | /* It is Core Duo. */ | |
653 | cpu = "pentium-m"; | |
654 | } | |
6c35d16a | 655 | else if (has_feature (FEATURE_SSE2)) |
fb112177 L |
656 | /* It is Pentium M. */ |
657 | cpu = "pentium-m"; | |
6c35d16a | 658 | else if (has_feature (FEATURE_SSE)) |
4bdf739d | 659 | { |
6c35d16a | 660 | if (vendor == VENDOR_CENTAUR) |
a239d460 JM |
661 | { |
662 | if (model >= 9) | |
663 | /* Eden "Nehemiah" */ | |
664 | cpu = "nehemiah"; | |
665 | else | |
666 | cpu = "c3-2"; | |
667 | } | |
4bdf739d UB |
668 | else |
669 | /* It is Pentium III. */ | |
670 | cpu = "pentium3"; | |
671 | } | |
6c35d16a | 672 | else if (has_feature (FEATURE_MMX)) |
fb112177 L |
673 | /* It is Pentium II. */ |
674 | cpu = "pentium2"; | |
44f276c6 | 675 | else |
fb112177 L |
676 | /* Default to Pentium Pro. */ |
677 | cpu = "pentiumpro"; | |
44f276c6 | 678 | } |
b3172cab | 679 | else |
44f276c6 L |
680 | /* For -mtune, we default to -mtune=generic. */ |
681 | cpu = "generic"; | |
fa959ce4 | 682 | } |
b3172cab UB |
683 | break; |
684 | case PROCESSOR_PENTIUM4: | |
6c35d16a | 685 | if (has_feature (FEATURE_SSE3)) |
fa959ce4 | 686 | { |
6c35d16a | 687 | if (has_feature (FEATURE_LM)) |
b3172cab | 688 | cpu = "nocona"; |
fa959ce4 | 689 | else |
fb112177 | 690 | cpu = "prescott"; |
fa959ce4 | 691 | } |
b3172cab | 692 | else |
fb112177 | 693 | cpu = "pentium4"; |
edccdcb1 L |
694 | break; |
695 | case PROCESSOR_GEODE: | |
696 | cpu = "geode"; | |
697 | break; | |
698 | case PROCESSOR_K6: | |
6c35d16a | 699 | if (arch && has_feature (FEATURE_3DNOW)) |
b3172cab | 700 | cpu = "k6-3"; |
edccdcb1 L |
701 | else |
702 | cpu = "k6"; | |
703 | break; | |
704 | case PROCESSOR_ATHLON: | |
6c35d16a | 705 | if (arch && has_feature (FEATURE_SSE)) |
edccdcb1 L |
706 | cpu = "athlon-4"; |
707 | else | |
708 | cpu = "athlon"; | |
709 | break; | |
edccdcb1 | 710 | case PROCESSOR_K8: |
d3606ee3 JM |
711 | if (arch) |
712 | { | |
6c35d16a | 713 | if (vendor == VENDOR_CENTAUR) |
d3606ee3 | 714 | { |
6c35d16a | 715 | if (has_feature (FEATURE_SSE4_1)) |
d3606ee3 JM |
716 | /* Nano 3000 | Nano dual / quad core | Eden X4 */ |
717 | cpu = "nano-3000"; | |
6c35d16a | 718 | else if (has_feature (FEATURE_SSSE3)) |
d3606ee3 JM |
719 | /* Nano 1000 | Nano 2000 */ |
720 | cpu = "nano"; | |
6c35d16a | 721 | else if (has_feature (FEATURE_SSE3)) |
d3606ee3 JM |
722 | /* Eden X2 */ |
723 | cpu = "eden-x2"; | |
724 | else | |
725 | /* Default to k8 */ | |
726 | cpu = "k8"; | |
727 | } | |
6c35d16a | 728 | else if (has_feature (FEATURE_SSE3)) |
d3606ee3 JM |
729 | cpu = "k8-sse3"; |
730 | else | |
731 | cpu = "k8"; | |
732 | } | |
b3172cab | 733 | else |
d3606ee3 | 734 | /* For -mtune, we default to -mtune=k8 */ |
b3172cab | 735 | cpu = "k8"; |
edccdcb1 | 736 | break; |
35a63f21 DR |
737 | case PROCESSOR_AMDFAM10: |
738 | cpu = "amdfam10"; | |
739 | break; | |
1133125e HJ |
740 | case PROCESSOR_BDVER1: |
741 | cpu = "bdver1"; | |
742 | break; | |
4d652a18 HJ |
743 | case PROCESSOR_BDVER2: |
744 | cpu = "bdver2"; | |
745 | break; | |
eb2f2b44 GG |
746 | case PROCESSOR_BDVER3: |
747 | cpu = "bdver3"; | |
748 | break; | |
ed97ad47 GG |
749 | case PROCESSOR_BDVER4: |
750 | cpu = "bdver4"; | |
751 | break; | |
9ce29eb0 VK |
752 | case PROCESSOR_ZNVER1: |
753 | cpu = "znver1"; | |
754 | break; | |
2901f42f VK |
755 | case PROCESSOR_ZNVER2: |
756 | cpu = "znver2"; | |
757 | break; | |
3e2ae3ee VK |
758 | case PROCESSOR_ZNVER3: |
759 | cpu = "znver3"; | |
760 | break; | |
14b52538 CF |
761 | case PROCESSOR_BTVER1: |
762 | cpu = "btver1"; | |
763 | break; | |
e32bfc16 VK |
764 | case PROCESSOR_BTVER2: |
765 | cpu = "btver2"; | |
766 | break; | |
b3172cab | 767 | |
edccdcb1 | 768 | default: |
b3172cab UB |
769 | /* Use something reasonable. */ |
770 | if (arch) | |
771 | { | |
6c35d16a | 772 | if (has_feature (FEATURE_SSSE3)) |
b3172cab | 773 | cpu = "core2"; |
6c35d16a | 774 | else if (has_feature (FEATURE_SSE3)) |
b3172cab | 775 | { |
6c35d16a | 776 | if (has_feature (FEATURE_LM)) |
b3172cab UB |
777 | cpu = "nocona"; |
778 | else | |
779 | cpu = "prescott"; | |
780 | } | |
6c35d16a | 781 | else if (has_feature (FEATURE_LM)) |
4bdf739d UB |
782 | /* Perhaps some emulator? Assume x86-64, otherwise gcc |
783 | -march=native would be unusable for 64-bit compilations, | |
784 | as all the CPUs below are 32-bit only. */ | |
785 | cpu = "x86-64"; | |
6c35d16a | 786 | else if (has_feature (FEATURE_SSE2)) |
b3172cab | 787 | cpu = "pentium4"; |
6c35d16a | 788 | else if (has_feature (FEATURE_CMOV)) |
b3172cab | 789 | cpu = "pentiumpro"; |
6c35d16a | 790 | else if (has_feature (FEATURE_MMX)) |
b3172cab | 791 | cpu = "pentium-mmx"; |
6c35d16a | 792 | else if (has_feature (FEATURE_CMPXCHG8B)) |
b3172cab UB |
793 | cpu = "pentium"; |
794 | } | |
795 | else | |
796 | cpu = "generic"; | |
fa959ce4 MM |
797 | } |
798 | ||
5be6cb59 UB |
799 | if (arch) |
800 | { | |
6c35d16a L |
801 | unsigned int i; |
802 | const char *const neg_option = " -mno-"; | |
803 | for (i = 0; i < ARRAY_SIZE (isa_names_table); i++) | |
804 | if (isa_names_table[i].option) | |
805 | { | |
806 | if (has_feature (isa_names_table[i].feature)) | |
807 | options = concat (options, " ", | |
808 | isa_names_table[i].option, NULL); | |
809 | else | |
810 | options = concat (options, neg_option, | |
811 | isa_names_table[i].option + 2, NULL); | |
812 | } | |
5be6cb59 UB |
813 | } |
814 | ||
fa959ce4 | 815 | done: |
f3afc8a7 | 816 | return concat (cache, "-m", argv[0], "=", cpu, options, NULL); |
fa959ce4 MM |
817 | } |
818 | #else | |
b3172cab | 819 | |
02147868 UB |
820 | /* If we are compiling with GCC where %EBX register is fixed, then the |
821 | driver will just ignore -march and -mtune "native" target and will leave | |
822 | to the newly built compiler to generate code for its default target. */ | |
b3172cab | 823 | |
997ef9e7 | 824 | const char *host_detect_local_cpu (int, const char **) |
fa959ce4 | 825 | { |
f3afc8a7 | 826 | return NULL; |
fa959ce4 | 827 | } |
a6ecb05c | 828 | #endif /* __GNUC__ */ |