]>
Commit | Line | Data |
---|---|---|
fa959ce4 | 1 | /* Subroutines for the gcc driver. |
8d9254fc | 2 | Copyright (C) 2006-2020 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" |
fa959ce4 | 31 | |
cb0dee88 UB |
32 | struct cache_desc |
33 | { | |
34 | unsigned sizekb; | |
35 | unsigned assoc; | |
36 | unsigned line; | |
37 | }; | |
38 | ||
39 | /* Returns command line parameters that describe size and | |
40 | cache line size of the processor caches. */ | |
2711355f ZD |
41 | |
42 | static char * | |
cb0dee88 | 43 | describe_cache (struct cache_desc level1, struct cache_desc level2) |
2711355f | 44 | { |
f4a1dd0d | 45 | char size[100], line[100], size2[100]; |
2711355f | 46 | |
cb0dee88 UB |
47 | /* At the moment, gcc does not use the information |
48 | about the associativity of the cache. */ | |
49 | ||
f3afc8a7 UB |
50 | snprintf (size, sizeof (size), |
51 | "--param l1-cache-size=%u ", level1.sizekb); | |
52 | snprintf (line, sizeof (line), | |
53 | "--param l1-cache-line-size=%u ", level1.line); | |
2711355f | 54 | |
f3afc8a7 UB |
55 | snprintf (size2, sizeof (size2), |
56 | "--param l2-cache-size=%u ", level2.sizekb); | |
2711355f | 57 | |
f3afc8a7 | 58 | return concat (size, line, size2, NULL); |
f4a1dd0d ZM |
59 | } |
60 | ||
cb0dee88 UB |
61 | /* Detect L2 cache parameters using CPUID extended function 0x80000006. */ |
62 | ||
f4a1dd0d | 63 | static void |
cb0dee88 | 64 | detect_l2_cache (struct cache_desc *level2) |
f4a1dd0d | 65 | { |
cb0dee88 UB |
66 | unsigned eax, ebx, ecx, edx; |
67 | unsigned assoc; | |
f4a1dd0d ZM |
68 | |
69 | __cpuid (0x80000006, eax, ebx, ecx, edx); | |
70 | ||
cb0dee88 UB |
71 | level2->sizekb = (ecx >> 16) & 0xffff; |
72 | level2->line = ecx & 0xff; | |
73 | ||
f4a1dd0d ZM |
74 | assoc = (ecx >> 12) & 0xf; |
75 | if (assoc == 6) | |
76 | assoc = 8; | |
77 | else if (assoc == 8) | |
78 | assoc = 16; | |
79 | else if (assoc >= 0xa && assoc <= 0xc) | |
80 | assoc = 32 + (assoc - 0xa) * 16; | |
81 | else if (assoc >= 0xd && assoc <= 0xe) | |
82 | assoc = 96 + (assoc - 0xd) * 32; | |
cb0dee88 UB |
83 | |
84 | level2->assoc = assoc; | |
2711355f ZD |
85 | } |
86 | ||
87 | /* Returns the description of caches for an AMD processor. */ | |
88 | ||
d3bfe4de | 89 | static const char * |
2711355f ZD |
90 | detect_caches_amd (unsigned max_ext_level) |
91 | { | |
92 | unsigned eax, ebx, ecx, edx; | |
cb0dee88 UB |
93 | |
94 | struct cache_desc level1, level2 = {0, 0, 0}; | |
2711355f ZD |
95 | |
96 | if (max_ext_level < 0x80000005) | |
d3bfe4de | 97 | return ""; |
2711355f | 98 | |
b3172cab | 99 | __cpuid (0x80000005, eax, ebx, ecx, edx); |
2711355f | 100 | |
cb0dee88 UB |
101 | level1.sizekb = (ecx >> 24) & 0xff; |
102 | level1.assoc = (ecx >> 16) & 0xff; | |
103 | level1.line = ecx & 0xff; | |
2711355f | 104 | |
f4a1dd0d | 105 | if (max_ext_level >= 0x80000006) |
cb0dee88 | 106 | detect_l2_cache (&level2); |
f4a1dd0d | 107 | |
cb0dee88 | 108 | return describe_cache (level1, level2); |
2711355f ZD |
109 | } |
110 | ||
cb0dee88 UB |
111 | /* Decodes the size, the associativity and the cache line size of |
112 | L1/L2 caches of an Intel processor. Values are based on | |
113 | "Intel Processor Identification and the CPUID Instruction" | |
114 | [Application Note 485], revision -032, December 2007. */ | |
2711355f ZD |
115 | |
116 | static void | |
cb0dee88 UB |
117 | decode_caches_intel (unsigned reg, bool xeon_mp, |
118 | struct cache_desc *level1, struct cache_desc *level2) | |
2711355f | 119 | { |
cb0dee88 UB |
120 | int i; |
121 | ||
122 | for (i = 24; i >= 0; i -= 8) | |
123 | switch ((reg >> i) & 0xff) | |
124 | { | |
125 | case 0x0a: | |
126 | level1->sizekb = 8; level1->assoc = 2; level1->line = 32; | |
127 | break; | |
128 | case 0x0c: | |
129 | level1->sizekb = 16; level1->assoc = 4; level1->line = 32; | |
130 | break; | |
f313cce5 UB |
131 | case 0x0d: |
132 | level1->sizekb = 16; level1->assoc = 4; level1->line = 64; | |
133 | break; | |
134 | case 0x0e: | |
135 | level1->sizekb = 24; level1->assoc = 6; level1->line = 64; | |
136 | break; | |
137 | case 0x21: | |
138 | level2->sizekb = 256; level2->assoc = 8; level2->line = 64; | |
139 | break; | |
140 | case 0x24: | |
141 | level2->sizekb = 1024; level2->assoc = 16; level2->line = 64; | |
142 | break; | |
cb0dee88 UB |
143 | case 0x2c: |
144 | level1->sizekb = 32; level1->assoc = 8; level1->line = 64; | |
145 | break; | |
146 | case 0x39: | |
147 | level2->sizekb = 128; level2->assoc = 4; level2->line = 64; | |
148 | break; | |
149 | case 0x3a: | |
150 | level2->sizekb = 192; level2->assoc = 6; level2->line = 64; | |
151 | break; | |
152 | case 0x3b: | |
153 | level2->sizekb = 128; level2->assoc = 2; level2->line = 64; | |
154 | break; | |
155 | case 0x3c: | |
156 | level2->sizekb = 256; level2->assoc = 4; level2->line = 64; | |
157 | break; | |
158 | case 0x3d: | |
159 | level2->sizekb = 384; level2->assoc = 6; level2->line = 64; | |
160 | break; | |
161 | case 0x3e: | |
162 | level2->sizekb = 512; level2->assoc = 4; level2->line = 64; | |
163 | break; | |
164 | case 0x41: | |
165 | level2->sizekb = 128; level2->assoc = 4; level2->line = 32; | |
166 | break; | |
167 | case 0x42: | |
168 | level2->sizekb = 256; level2->assoc = 4; level2->line = 32; | |
169 | break; | |
170 | case 0x43: | |
171 | level2->sizekb = 512; level2->assoc = 4; level2->line = 32; | |
172 | break; | |
173 | case 0x44: | |
174 | level2->sizekb = 1024; level2->assoc = 4; level2->line = 32; | |
175 | break; | |
176 | case 0x45: | |
177 | level2->sizekb = 2048; level2->assoc = 4; level2->line = 32; | |
178 | break; | |
f313cce5 UB |
179 | case 0x48: |
180 | level2->sizekb = 3072; level2->assoc = 12; level2->line = 64; | |
181 | break; | |
cb0dee88 UB |
182 | case 0x49: |
183 | if (xeon_mp) | |
184 | break; | |
185 | level2->sizekb = 4096; level2->assoc = 16; level2->line = 64; | |
186 | break; | |
187 | case 0x4e: | |
188 | level2->sizekb = 6144; level2->assoc = 24; level2->line = 64; | |
189 | break; | |
190 | case 0x60: | |
191 | level1->sizekb = 16; level1->assoc = 8; level1->line = 64; | |
192 | break; | |
193 | case 0x66: | |
194 | level1->sizekb = 8; level1->assoc = 4; level1->line = 64; | |
195 | break; | |
196 | case 0x67: | |
197 | level1->sizekb = 16; level1->assoc = 4; level1->line = 64; | |
198 | break; | |
199 | case 0x68: | |
200 | level1->sizekb = 32; level1->assoc = 4; level1->line = 64; | |
201 | break; | |
202 | case 0x78: | |
203 | level2->sizekb = 1024; level2->assoc = 4; level2->line = 64; | |
204 | break; | |
205 | case 0x79: | |
206 | level2->sizekb = 128; level2->assoc = 8; level2->line = 64; | |
207 | break; | |
208 | case 0x7a: | |
209 | level2->sizekb = 256; level2->assoc = 8; level2->line = 64; | |
210 | break; | |
211 | case 0x7b: | |
212 | level2->sizekb = 512; level2->assoc = 8; level2->line = 64; | |
213 | break; | |
214 | case 0x7c: | |
215 | level2->sizekb = 1024; level2->assoc = 8; level2->line = 64; | |
216 | break; | |
217 | case 0x7d: | |
218 | level2->sizekb = 2048; level2->assoc = 8; level2->line = 64; | |
219 | break; | |
220 | case 0x7f: | |
221 | level2->sizekb = 512; level2->assoc = 2; level2->line = 64; | |
222 | break; | |
f313cce5 UB |
223 | case 0x80: |
224 | level2->sizekb = 512; level2->assoc = 8; level2->line = 64; | |
225 | break; | |
cb0dee88 UB |
226 | case 0x82: |
227 | level2->sizekb = 256; level2->assoc = 8; level2->line = 32; | |
228 | break; | |
229 | case 0x83: | |
230 | level2->sizekb = 512; level2->assoc = 8; level2->line = 32; | |
231 | break; | |
232 | case 0x84: | |
233 | level2->sizekb = 1024; level2->assoc = 8; level2->line = 32; | |
234 | break; | |
235 | case 0x85: | |
236 | level2->sizekb = 2048; level2->assoc = 8; level2->line = 32; | |
237 | break; | |
238 | case 0x86: | |
239 | level2->sizekb = 512; level2->assoc = 4; level2->line = 64; | |
240 | break; | |
241 | case 0x87: | |
242 | level2->sizekb = 1024; level2->assoc = 8; level2->line = 64; | |
243 | ||
244 | default: | |
245 | break; | |
246 | } | |
247 | } | |
2711355f | 248 | |
cb0dee88 | 249 | /* Detect cache parameters using CPUID function 2. */ |
2711355f | 250 | |
cb0dee88 UB |
251 | static void |
252 | detect_caches_cpuid2 (bool xeon_mp, | |
253 | struct cache_desc *level1, struct cache_desc *level2) | |
254 | { | |
dc8bd8d9 UB |
255 | unsigned regs[4]; |
256 | int nreps, i; | |
cb0dee88 | 257 | |
dc8bd8d9 | 258 | __cpuid (2, regs[0], regs[1], regs[2], regs[3]); |
cb0dee88 | 259 | |
dc8bd8d9 UB |
260 | nreps = regs[0] & 0x0f; |
261 | regs[0] &= ~0x0f; | |
cb0dee88 UB |
262 | |
263 | while (--nreps >= 0) | |
2711355f | 264 | { |
dc8bd8d9 UB |
265 | for (i = 0; i < 4; i++) |
266 | if (regs[i] && !((regs[i] >> 31) & 1)) | |
267 | decode_caches_intel (regs[i], xeon_mp, level1, level2); | |
cb0dee88 UB |
268 | |
269 | if (nreps) | |
dc8bd8d9 | 270 | __cpuid (2, regs[0], regs[1], regs[2], regs[3]); |
cb0dee88 UB |
271 | } |
272 | } | |
2711355f | 273 | |
cb0dee88 UB |
274 | /* Detect cache parameters using CPUID function 4. This |
275 | method doesn't require hardcoded tables. */ | |
2711355f | 276 | |
cb0dee88 UB |
277 | enum cache_type |
278 | { | |
279 | CACHE_END = 0, | |
280 | CACHE_DATA = 1, | |
281 | CACHE_INST = 2, | |
282 | CACHE_UNIFIED = 3 | |
283 | }; | |
284 | ||
285 | static void | |
a0463099 AK |
286 | detect_caches_cpuid4 (struct cache_desc *level1, struct cache_desc *level2, |
287 | struct cache_desc *level3) | |
cb0dee88 UB |
288 | { |
289 | struct cache_desc *cache; | |
290 | ||
291 | unsigned eax, ebx, ecx, edx; | |
292 | int count; | |
293 | ||
294 | for (count = 0;; count++) | |
295 | { | |
296 | __cpuid_count(4, count, eax, ebx, ecx, edx); | |
297 | switch (eax & 0x1f) | |
298 | { | |
299 | case CACHE_END: | |
300 | return; | |
301 | case CACHE_DATA: | |
302 | case CACHE_UNIFIED: | |
303 | { | |
304 | switch ((eax >> 5) & 0x07) | |
305 | { | |
306 | case 1: | |
307 | cache = level1; | |
308 | break; | |
309 | case 2: | |
310 | cache = level2; | |
311 | break; | |
a0463099 AK |
312 | case 3: |
313 | cache = level3; | |
314 | break; | |
cb0dee88 UB |
315 | default: |
316 | cache = NULL; | |
317 | } | |
318 | ||
319 | if (cache) | |
320 | { | |
321 | unsigned sets = ecx + 1; | |
dc8bd8d9 | 322 | unsigned part = ((ebx >> 12) & 0x03ff) + 1; |
cb0dee88 | 323 | |
dc8bd8d9 | 324 | cache->assoc = ((ebx >> 22) & 0x03ff) + 1; |
cb0dee88 | 325 | cache->line = (ebx & 0x0fff) + 1; |
cb0dee88 UB |
326 | |
327 | cache->sizekb = (cache->assoc * part | |
328 | * cache->line * sets) / 1024; | |
a0463099 | 329 | } |
cb0dee88 | 330 | } |
2711355f ZD |
331 | default: |
332 | break; | |
333 | } | |
334 | } | |
335 | } | |
336 | ||
cb0dee88 | 337 | /* Returns the description of caches for an Intel processor. */ |
2711355f | 338 | |
d3bfe4de | 339 | static const char * |
a0463099 AK |
340 | detect_caches_intel (bool xeon_mp, unsigned max_level, |
341 | unsigned max_ext_level, unsigned *l2sizekb) | |
2711355f | 342 | { |
a0463099 | 343 | struct cache_desc level1 = {0, 0, 0}, level2 = {0, 0, 0}, level3 = {0, 0, 0}; |
2711355f | 344 | |
cb0dee88 | 345 | if (max_level >= 4) |
a0463099 | 346 | detect_caches_cpuid4 (&level1, &level2, &level3); |
cb0dee88 UB |
347 | else if (max_level >= 2) |
348 | detect_caches_cpuid2 (xeon_mp, &level1, &level2); | |
349 | else | |
d3bfe4de | 350 | return ""; |
2711355f | 351 | |
cb0dee88 | 352 | if (level1.sizekb == 0) |
d3bfe4de | 353 | return ""; |
2711355f | 354 | |
a0463099 AK |
355 | /* Let the L3 replace the L2. This assumes inclusive caches |
356 | and single threaded program for now. */ | |
357 | if (level3.sizekb) | |
358 | level2 = level3; | |
359 | ||
cb0dee88 UB |
360 | /* Intel CPUs are equipped with AMD style L2 cache info. Try this |
361 | method if other methods fail to provide L2 cache parameters. */ | |
362 | if (level2.sizekb == 0 && max_ext_level >= 0x80000006) | |
363 | detect_l2_cache (&level2); | |
f4a1dd0d | 364 | |
a0463099 AK |
365 | *l2sizekb = level2.sizekb; |
366 | ||
cb0dee88 | 367 | return describe_cache (level1, level2); |
2711355f ZD |
368 | } |
369 | ||
fa959ce4 MM |
370 | /* This will be called by the spec parser in gcc.c when it sees |
371 | a %:local_cpu_detect(args) construct. Currently it will be called | |
372 | with either "arch" or "tune" as argument depending on if -march=native | |
373 | or -mtune=native is to be substituted. | |
374 | ||
375 | It returns a string containing new command line parameters to be | |
376 | put at the place of the above two options, depending on what CPU | |
377 | this is executed. E.g. "-march=k8" on an AMD64 machine | |
378 | for -march=native. | |
379 | ||
380 | ARGC and ARGV are set depending on the actual arguments given | |
381 | in the spec. */ | |
b3172cab | 382 | |
fa959ce4 MM |
383 | const char *host_detect_local_cpu (int argc, const char **argv) |
384 | { | |
b3172cab UB |
385 | enum processor_type processor = PROCESSOR_I386; |
386 | const char *cpu = "i386"; | |
387 | ||
2711355f | 388 | const char *cache = ""; |
5be6cb59 | 389 | const char *options = ""; |
b3172cab | 390 | |
cb0dee88 | 391 | unsigned int eax, ebx, ecx, edx; |
b3172cab UB |
392 | |
393 | unsigned int max_level, ext_level; | |
cb0dee88 | 394 | |
fa959ce4 | 395 | unsigned int vendor; |
cb0dee88 | 396 | unsigned int model, family; |
b3172cab UB |
397 | |
398 | unsigned int has_sse3, has_ssse3, has_cmpxchg16b; | |
399 | unsigned int has_cmpxchg8b, has_cmov, has_mmx, has_sse, has_sse2; | |
400 | ||
401 | /* Extended features */ | |
402 | unsigned int has_lahf_lm = 0, has_sse4a = 0; | |
403 | unsigned int has_longmode = 0, has_3dnowp = 0, has_3dnow = 0; | |
634fa334 | 404 | unsigned int has_movbe = 0, has_sse4_1 = 0, has_sse4_2 = 0; |
7afac110 | 405 | unsigned int has_popcnt = 0, has_aes = 0, has_avx = 0, has_avx2 = 0; |
8ad9d49e | 406 | unsigned int has_pclmul = 0, has_abm = 0, has_lwp = 0; |
5eed4f27 | 407 | unsigned int has_fma = 0, has_fma4 = 0, has_xop = 0; |
82feeb8d | 408 | unsigned int has_bmi = 0, has_bmi2 = 0, has_tbm = 0, has_lzcnt = 0; |
73e32c47 | 409 | unsigned int has_hle = 0, has_rtm = 0, has_sgx = 0; |
13b93d4b | 410 | unsigned int has_pconfig = 0, has_wbnoinvd = 0; |
d1925759 | 411 | unsigned int has_rdrnd = 0, has_f16c = 0, has_fsgsbase = 0; |
d05e383b | 412 | unsigned int has_rdseed = 0, has_prfchw = 0, has_adx = 0; |
3a0d99bb | 413 | unsigned int has_osxsave = 0, has_fxsr = 0, has_xsave = 0, has_xsaveopt = 0; |
3f97cb0b | 414 | unsigned int has_avx512er = 0, has_avx512pf = 0, has_avx512cd = 0; |
43b3f52f | 415 | unsigned int has_avx512f = 0, has_sha = 0, has_prefetchwt1 = 0; |
9cdea277 | 416 | unsigned int has_clflushopt = 0, has_xsavec = 0, has_xsaves = 0; |
f4af595f | 417 | unsigned int has_avx512dq = 0, has_avx512bw = 0, has_avx512vl = 0; |
9c3bca11 | 418 | unsigned int has_avx512vbmi = 0, has_avx512ifma = 0, has_clwb = 0; |
1d516992 | 419 | unsigned int has_mwaitx = 0, has_clzero = 0, has_pku = 0, has_rdpid = 0; |
5fbb13a7 | 420 | unsigned int has_avx5124fmaps = 0, has_avx5124vnniw = 0; |
fca51879 | 421 | unsigned int has_gfni = 0, has_avx512vbmi2 = 0; |
e2a29465 | 422 | unsigned int has_avx512bitalg = 0; |
e95dda95 | 423 | unsigned int has_shstk = 0; |
b7b0a4fa | 424 | unsigned int has_avx512vnni = 0, has_vaes = 0; |
6557be99 | 425 | unsigned int has_vpclmulqdq = 0; |
e21b52af | 426 | unsigned int has_avx512vp2intersect = 0; |
37d51c75 | 427 | unsigned int has_movdiri = 0, has_movdir64b = 0; |
6a10feda | 428 | unsigned int has_enqcmd = 0; |
55f31ed1 | 429 | unsigned int has_waitpkg = 0; |
f8d9957e | 430 | unsigned int has_cldemote = 0; |
4f0e90fa | 431 | unsigned int has_avx512bf16 = 0; |
b3172cab | 432 | |
41f8d1fc AK |
433 | unsigned int has_ptwrite = 0; |
434 | ||
edccdcb1 L |
435 | bool arch; |
436 | ||
a0463099 AK |
437 | unsigned int l2sizekb = 0; |
438 | ||
edccdcb1 L |
439 | if (argc < 1) |
440 | return NULL; | |
441 | ||
b3172cab UB |
442 | arch = !strcmp (argv[0], "arch"); |
443 | ||
edccdcb1 | 444 | if (!arch && strcmp (argv[0], "tune")) |
fa959ce4 MM |
445 | return NULL; |
446 | ||
b3172cab UB |
447 | max_level = __get_cpuid_max (0, &vendor); |
448 | if (max_level < 1) | |
fa959ce4 | 449 | goto done; |
fa959ce4 | 450 | |
b3172cab | 451 | __cpuid (1, eax, ebx, ecx, edx); |
fa959ce4 | 452 | |
cb0dee88 | 453 | model = (eax >> 4) & 0x0f; |
b3172cab | 454 | family = (eax >> 8) & 0x0f; |
d478ac59 GG |
455 | if (vendor == signature_INTEL_ebx |
456 | || vendor == signature_AMD_ebx) | |
37c50435 L |
457 | { |
458 | unsigned int extended_model, extended_family; | |
459 | ||
460 | extended_model = (eax >> 12) & 0xf0; | |
461 | extended_family = (eax >> 20) & 0xff; | |
462 | if (family == 0x0f) | |
463 | { | |
464 | family += extended_family; | |
465 | model += extended_model; | |
466 | } | |
467 | else if (family == 0x06) | |
468 | model += extended_model; | |
469 | } | |
b3172cab UB |
470 | |
471 | has_sse3 = ecx & bit_SSE3; | |
472 | has_ssse3 = ecx & bit_SSSE3; | |
634fa334 L |
473 | has_sse4_1 = ecx & bit_SSE4_1; |
474 | has_sse4_2 = ecx & bit_SSE4_2; | |
475 | has_avx = ecx & bit_AVX; | |
a91529c4 | 476 | has_osxsave = ecx & bit_OSXSAVE; |
b3172cab | 477 | has_cmpxchg16b = ecx & bit_CMPXCHG16B; |
cabf85c3 | 478 | has_movbe = ecx & bit_MOVBE; |
634fa334 L |
479 | has_popcnt = ecx & bit_POPCNT; |
480 | has_aes = ecx & bit_AES; | |
481 | has_pclmul = ecx & bit_PCLMUL; | |
5eed4f27 | 482 | has_fma = ecx & bit_FMA; |
d1925759 L |
483 | has_f16c = ecx & bit_F16C; |
484 | has_rdrnd = ecx & bit_RDRND; | |
3a0d99bb | 485 | has_xsave = ecx & bit_XSAVE; |
fa959ce4 | 486 | |
b3172cab UB |
487 | has_cmpxchg8b = edx & bit_CMPXCHG8B; |
488 | has_cmov = edx & bit_CMOV; | |
489 | has_mmx = edx & bit_MMX; | |
3a0d99bb | 490 | has_fxsr = edx & bit_FXSAVE; |
b3172cab UB |
491 | has_sse = edx & bit_SSE; |
492 | has_sse2 = edx & bit_SSE2; | |
493 | ||
2c9b39ef L |
494 | if (max_level >= 7) |
495 | { | |
496 | __cpuid_count (7, 0, eax, ebx, ecx, edx); | |
497 | ||
498 | has_bmi = ebx & bit_BMI; | |
73e32c47 | 499 | has_sgx = ebx & bit_SGX; |
5dcfdccd | 500 | has_hle = ebx & bit_HLE; |
76a02e42 | 501 | has_rtm = ebx & bit_RTM; |
2c9b39ef L |
502 | has_avx2 = ebx & bit_AVX2; |
503 | has_bmi2 = ebx & bit_BMI2; | |
d1925759 | 504 | has_fsgsbase = ebx & bit_FSGSBASE; |
4c340b5d | 505 | has_rdseed = ebx & bit_RDSEED; |
d05e383b | 506 | has_adx = ebx & bit_ADX; |
3f97cb0b AI |
507 | has_avx512f = ebx & bit_AVX512F; |
508 | has_avx512er = ebx & bit_AVX512ER; | |
509 | has_avx512pf = ebx & bit_AVX512PF; | |
510 | has_avx512cd = ebx & bit_AVX512CD; | |
c1618f82 | 511 | has_sha = ebx & bit_SHA; |
9cdea277 | 512 | has_clflushopt = ebx & bit_CLFLUSHOPT; |
9c3bca11 | 513 | has_clwb = ebx & bit_CLWB; |
07165dd7 | 514 | has_avx512dq = ebx & bit_AVX512DQ; |
b525d943 | 515 | has_avx512bw = ebx & bit_AVX512BW; |
f4af595f | 516 | has_avx512vl = ebx & bit_AVX512VL; |
21272090 | 517 | has_avx512ifma = ebx & bit_AVX512IFMA; |
43b3f52f IT |
518 | |
519 | has_prefetchwt1 = ecx & bit_PREFETCHWT1; | |
41a4ef22 KY |
520 | has_avx512vbmi = ecx & bit_AVX512VBMI; |
521 | has_pku = ecx & bit_OSPKE; | |
fca51879 | 522 | has_avx512vbmi2 = ecx & bit_AVX512VBMI2; |
98966963 | 523 | has_avx512vnni = ecx & bit_AVX512VNNI; |
1d516992 | 524 | has_rdpid = ecx & bit_RDPID; |
b8cca31c | 525 | has_gfni = ecx & bit_GFNI; |
b7b0a4fa | 526 | has_vaes = ecx & bit_VAES; |
6557be99 | 527 | has_vpclmulqdq = ecx & bit_VPCLMULQDQ; |
e2a29465 | 528 | has_avx512bitalg = ecx & bit_AVX512BITALG; |
37d51c75 SP |
529 | has_movdiri = ecx & bit_MOVDIRI; |
530 | has_movdir64b = ecx & bit_MOVDIR64B; | |
6a10feda | 531 | has_enqcmd = ecx & bit_ENQCMD; |
f8d9957e | 532 | has_cldemote = ecx & bit_CLDEMOTE; |
1d516992 | 533 | |
5fbb13a7 KY |
534 | has_avx5124vnniw = edx & bit_AVX5124VNNIW; |
535 | has_avx5124fmaps = edx & bit_AVX5124FMAPS; | |
e21b52af | 536 | has_avx512vp2intersect = edx & bit_AVX512VP2INTERSECT; |
2a25448c IT |
537 | |
538 | has_shstk = ecx & bit_SHSTK; | |
13b93d4b | 539 | has_pconfig = edx & bit_PCONFIG; |
55f31ed1 | 540 | has_waitpkg = ecx & bit_WAITPKG; |
4f0e90fa HL |
541 | |
542 | __cpuid_count (7, 1, eax, ebx, ecx, edx); | |
543 | has_avx512bf16 = eax & bit_AVX512BF16; | |
2c9b39ef L |
544 | } |
545 | ||
3a0d99bb AI |
546 | if (max_level >= 13) |
547 | { | |
548 | __cpuid_count (13, 1, eax, ebx, ecx, edx); | |
549 | ||
550 | has_xsaveopt = eax & bit_XSAVEOPT; | |
9cdea277 IT |
551 | has_xsavec = eax & bit_XSAVEC; |
552 | has_xsaves = eax & bit_XSAVES; | |
3a0d99bb AI |
553 | } |
554 | ||
41f8d1fc AK |
555 | if (max_level >= 0x14) |
556 | { | |
557 | __cpuid_count (0x14, 0, eax, ebx, ecx, edx); | |
558 | ||
559 | has_ptwrite = ebx & bit_PTWRITE; | |
560 | } | |
561 | ||
d0b50387 JJ |
562 | /* Check cpuid level of extended features. */ |
563 | __cpuid (0x80000000, ext_level, ebx, ecx, edx); | |
564 | ||
0a2d7bc0 | 565 | if (ext_level >= 0x80000001) |
d0b50387 JJ |
566 | { |
567 | __cpuid (0x80000001, eax, ebx, ecx, edx); | |
568 | ||
569 | has_lahf_lm = ecx & bit_LAHF_LM; | |
570 | has_sse4a = ecx & bit_SSE4a; | |
571 | has_abm = ecx & bit_ABM; | |
572 | has_lwp = ecx & bit_LWP; | |
573 | has_fma4 = ecx & bit_FMA4; | |
574 | has_xop = ecx & bit_XOP; | |
575 | has_tbm = ecx & bit_TBM; | |
576 | has_lzcnt = ecx & bit_LZCNT; | |
577 | has_prfchw = ecx & bit_PRFCHW; | |
578 | ||
579 | has_longmode = edx & bit_LM; | |
580 | has_3dnowp = edx & bit_3DNOWP; | |
581 | has_3dnow = edx & bit_3DNOW; | |
500a08b2 | 582 | has_mwaitx = ecx & bit_MWAITX; |
0a2d7bc0 | 583 | } |
9ce29eb0 | 584 | |
0a2d7bc0 UB |
585 | if (ext_level >= 0x80000008) |
586 | { | |
9ce29eb0 VK |
587 | __cpuid (0x80000008, eax, ebx, ecx, edx); |
588 | has_clzero = ebx & bit_CLZERO; | |
13b93d4b | 589 | has_wbnoinvd = ebx & bit_WBNOINVD; |
d0b50387 JJ |
590 | } |
591 | ||
a91529c4 L |
592 | /* Get XCR_XFEATURE_ENABLED_MASK register with xgetbv. */ |
593 | #define XCR_XFEATURE_ENABLED_MASK 0x0 | |
594 | #define XSTATE_FP 0x1 | |
595 | #define XSTATE_SSE 0x2 | |
596 | #define XSTATE_YMM 0x4 | |
2c12f2f4 IT |
597 | #define XSTATE_OPMASK 0x20 |
598 | #define XSTATE_ZMM 0x40 | |
599 | #define XSTATE_HI_ZMM 0x80 | |
0a2d7bc0 UB |
600 | |
601 | #define XCR_AVX_ENABLED_MASK \ | |
602 | (XSTATE_SSE | XSTATE_YMM) | |
603 | #define XCR_AVX512F_ENABLED_MASK \ | |
604 | (XSTATE_SSE | XSTATE_YMM | XSTATE_OPMASK | XSTATE_ZMM | XSTATE_HI_ZMM) | |
605 | ||
a91529c4 L |
606 | if (has_osxsave) |
607 | asm (".byte 0x0f; .byte 0x01; .byte 0xd0" | |
608 | : "=a" (eax), "=d" (edx) | |
609 | : "c" (XCR_XFEATURE_ENABLED_MASK)); | |
0a2d7bc0 UB |
610 | else |
611 | eax = 0; | |
a91529c4 | 612 | |
0a2d7bc0 UB |
613 | /* Check if AVX registers are supported. */ |
614 | if ((eax & XCR_AVX_ENABLED_MASK) != XCR_AVX_ENABLED_MASK) | |
a91529c4 L |
615 | { |
616 | has_avx = 0; | |
617 | has_avx2 = 0; | |
618 | has_fma = 0; | |
619 | has_fma4 = 0; | |
d0b50387 | 620 | has_f16c = 0; |
a91529c4 | 621 | has_xop = 0; |
3a0d99bb AI |
622 | has_xsave = 0; |
623 | has_xsaveopt = 0; | |
9cdea277 IT |
624 | has_xsaves = 0; |
625 | has_xsavec = 0; | |
a91529c4 L |
626 | } |
627 | ||
0a2d7bc0 UB |
628 | /* Check if AVX512F registers are supported. */ |
629 | if ((eax & XCR_AVX512F_ENABLED_MASK) != XCR_AVX512F_ENABLED_MASK) | |
2c12f2f4 IT |
630 | { |
631 | has_avx512f = 0; | |
632 | has_avx512er = 0; | |
633 | has_avx512pf = 0; | |
634 | has_avx512cd = 0; | |
635 | has_avx512dq = 0; | |
636 | has_avx512bw = 0; | |
637 | has_avx512vl = 0; | |
638 | } | |
639 | ||
2711355f ZD |
640 | if (!arch) |
641 | { | |
19db293a | 642 | if (vendor == signature_AMD_ebx |
af0e415b UB |
643 | || vendor == signature_CENTAUR_ebx |
644 | || vendor == signature_CYRIX_ebx | |
7b9d1bd8 | 645 | || vendor == signature_NSC_ebx) |
2711355f | 646 | cache = detect_caches_amd (ext_level); |
ef64d158 | 647 | else if (vendor == signature_INTEL_ebx) |
cb0dee88 UB |
648 | { |
649 | bool xeon_mp = (family == 15 && model == 6); | |
a0463099 AK |
650 | cache = detect_caches_intel (xeon_mp, max_level, |
651 | ext_level, &l2sizekb); | |
cb0dee88 | 652 | } |
2711355f ZD |
653 | } |
654 | ||
ef64d158 | 655 | if (vendor == signature_AMD_ebx) |
fa959ce4 | 656 | { |
fbdf817d | 657 | unsigned int name; |
b3172cab | 658 | |
fbdf817d | 659 | /* Detect geode processor by its processor signature. */ |
0a2d7bc0 | 660 | if (ext_level >= 0x80000002) |
fbdf817d UB |
661 | __cpuid (0x80000002, name, ebx, ecx, edx); |
662 | else | |
663 | name = 0; | |
664 | ||
ef64d158 | 665 | if (name == signature_NSC_ebx) |
fbdf817d | 666 | processor = PROCESSOR_GEODE; |
d478ac59 | 667 | else if (has_movbe && family == 22) |
e32bfc16 | 668 | processor = PROCESSOR_BTVER2; |
2901f42f VK |
669 | else if (has_clwb) |
670 | processor = PROCESSOR_ZNVER2; | |
9ce29eb0 VK |
671 | else if (has_clzero) |
672 | processor = PROCESSOR_ZNVER1; | |
ed97ad47 GG |
673 | else if (has_avx2) |
674 | processor = PROCESSOR_BDVER4; | |
eb2f2b44 GG |
675 | else if (has_xsaveopt) |
676 | processor = PROCESSOR_BDVER3; | |
4d652a18 HJ |
677 | else if (has_bmi) |
678 | processor = PROCESSOR_BDVER2; | |
1133125e HJ |
679 | else if (has_xop) |
680 | processor = PROCESSOR_BDVER1; | |
14b52538 CF |
681 | else if (has_sse4a && has_ssse3) |
682 | processor = PROCESSOR_BTVER1; | |
fbdf817d | 683 | else if (has_sse4a) |
35a63f21 | 684 | processor = PROCESSOR_AMDFAM10; |
fbdf817d UB |
685 | else if (has_sse2 || has_longmode) |
686 | processor = PROCESSOR_K8; | |
f7593cb4 | 687 | else if (has_3dnowp && family == 6) |
fbdf817d UB |
688 | processor = PROCESSOR_ATHLON; |
689 | else if (has_mmx) | |
690 | processor = PROCESSOR_K6; | |
691 | else | |
692 | processor = PROCESSOR_PENTIUM; | |
fa959ce4 | 693 | } |
19db293a UB |
694 | else if (vendor == signature_CENTAUR_ebx) |
695 | { | |
4bdf739d UB |
696 | processor = PROCESSOR_GENERIC; |
697 | ||
698 | switch (family) | |
19db293a | 699 | { |
4bdf739d UB |
700 | default: |
701 | /* We have no idea. */ | |
702 | break; | |
703 | ||
704 | case 5: | |
705 | if (has_3dnow || has_mmx) | |
706 | processor = PROCESSOR_I486; | |
707 | break; | |
708 | ||
709 | case 6: | |
d3606ee3 JM |
710 | if (has_longmode) |
711 | processor = PROCESSOR_K8; | |
a239d460 | 712 | else if (model >= 9) |
4bdf739d UB |
713 | processor = PROCESSOR_PENTIUMPRO; |
714 | else if (model >= 6) | |
715 | processor = PROCESSOR_I486; | |
19db293a UB |
716 | } |
717 | } | |
fa959ce4 MM |
718 | else |
719 | { | |
edccdcb1 L |
720 | switch (family) |
721 | { | |
b3172cab UB |
722 | case 4: |
723 | processor = PROCESSOR_I486; | |
724 | break; | |
edccdcb1 | 725 | case 5: |
b3172cab | 726 | processor = PROCESSOR_PENTIUM; |
edccdcb1 L |
727 | break; |
728 | case 6: | |
729 | processor = PROCESSOR_PENTIUMPRO; | |
730 | break; | |
731 | case 15: | |
732 | processor = PROCESSOR_PENTIUM4; | |
733 | break; | |
734 | default: | |
b3172cab | 735 | /* We have no idea. */ |
9d532162 | 736 | processor = PROCESSOR_GENERIC; |
edccdcb1 L |
737 | } |
738 | } | |
739 | ||
740 | switch (processor) | |
741 | { | |
742 | case PROCESSOR_I386: | |
b3172cab | 743 | /* Default. */ |
edccdcb1 L |
744 | break; |
745 | case PROCESSOR_I486: | |
4bdf739d UB |
746 | if (arch && vendor == signature_CENTAUR_ebx) |
747 | { | |
748 | if (model >= 6) | |
749 | cpu = "c3"; | |
750 | else if (has_3dnow) | |
751 | cpu = "winchip2"; | |
752 | else | |
753 | /* Assume WinChip C6. */ | |
754 | cpu = "winchip-c6"; | |
755 | } | |
756 | else | |
757 | cpu = "i486"; | |
edccdcb1 L |
758 | break; |
759 | case PROCESSOR_PENTIUM: | |
b3172cab | 760 | if (arch && has_mmx) |
edccdcb1 L |
761 | cpu = "pentium-mmx"; |
762 | else | |
763 | cpu = "pentium"; | |
764 | break; | |
765 | case PROCESSOR_PENTIUMPRO: | |
44f276c6 | 766 | switch (model) |
edccdcb1 | 767 | { |
44f276c6 L |
768 | case 0x1c: |
769 | case 0x26: | |
d3c11974 L |
770 | /* Bonnell. */ |
771 | cpu = "bonnell"; | |
44f276c6 | 772 | break; |
e5287671 | 773 | case 0x37: |
c8f2dff2 | 774 | case 0x4a: |
e5287671 | 775 | case 0x4d: |
c8f2dff2 L |
776 | case 0x5a: |
777 | case 0x5d: | |
e5287671 | 778 | /* Silvermont. */ |
d3c11974 | 779 | cpu = "silvermont"; |
e5287671 | 780 | break; |
50e461df OM |
781 | case 0x5c: |
782 | case 0x5f: | |
783 | /* Goldmont. */ | |
784 | cpu = "goldmont"; | |
785 | break; | |
74b2bb19 OM |
786 | case 0x7a: |
787 | /* Goldmont Plus. */ | |
788 | cpu = "goldmont-plus"; | |
789 | break; | |
992592ec CW |
790 | case 0x0f: |
791 | /* Merom. */ | |
792 | case 0x17: | |
793 | case 0x1d: | |
794 | /* Penryn. */ | |
795 | cpu = "core2"; | |
796 | break; | |
44f276c6 L |
797 | case 0x1a: |
798 | case 0x1e: | |
799 | case 0x1f: | |
800 | case 0x2e: | |
eefe143b | 801 | /* Nehalem. */ |
d3c11974 L |
802 | cpu = "nehalem"; |
803 | break; | |
44f276c6 | 804 | case 0x25: |
12bbb78f | 805 | case 0x2c: |
44f276c6 | 806 | case 0x2f: |
eefe143b | 807 | /* Westmere. */ |
d3c11974 | 808 | cpu = "westmere"; |
44f276c6 | 809 | break; |
35758e5b | 810 | case 0x2a: |
815cecbe | 811 | case 0x2d: |
35758e5b | 812 | /* Sandy Bridge. */ |
d3c11974 | 813 | cpu = "sandybridge"; |
35758e5b | 814 | break; |
992592ec CW |
815 | case 0x3a: |
816 | case 0x3e: | |
817 | /* Ivy Bridge. */ | |
d3c11974 | 818 | cpu = "ivybridge"; |
44f276c6 | 819 | break; |
992592ec | 820 | case 0x3c: |
c8f2dff2 | 821 | case 0x3f: |
d0cf4e84 L |
822 | case 0x45: |
823 | case 0x46: | |
992592ec | 824 | /* Haswell. */ |
d3c11974 | 825 | cpu = "haswell"; |
44f276c6 | 826 | break; |
c8f2dff2 | 827 | case 0x3d: |
dc04bc84 | 828 | case 0x47: |
c8f2dff2 L |
829 | case 0x4f: |
830 | case 0x56: | |
831 | /* Broadwell. */ | |
832 | cpu = "broadwell"; | |
833 | break; | |
3e0f3349 YR |
834 | case 0x4e: |
835 | case 0x5e: | |
836 | /* Skylake. */ | |
60edf8bb MT |
837 | case 0x8e: |
838 | case 0x9e: | |
839 | /* Kaby Lake. */ | |
3e0f3349 YR |
840 | cpu = "skylake"; |
841 | break; | |
c234d831 | 842 | case 0x55: |
5d54c798 WX |
843 | if (has_avx512vnni) |
844 | /* Cascade Lake. */ | |
845 | cpu = "cascadelake"; | |
846 | else | |
847 | /* Skylake with AVX-512. */ | |
848 | cpu = "skylake-avx512"; | |
c234d831 | 849 | break; |
c8f2dff2 L |
850 | case 0x57: |
851 | /* Knights Landing. */ | |
852 | cpu = "knl"; | |
853 | break; | |
c234d831 UB |
854 | case 0x66: |
855 | /* Cannon Lake. */ | |
856 | cpu = "cannonlake"; | |
857 | break; | |
cace2309 | 858 | case 0x85: |
c234d831 | 859 | /* Knights Mill. */ |
cace2309 SP |
860 | cpu = "knm"; |
861 | break; | |
44f276c6 L |
862 | default: |
863 | if (arch) | |
864 | { | |
4ffae7ff | 865 | /* This is unknown family 0x6 CPU. */ |
a9fcfec3 HL |
866 | if (has_avx) |
867 | { | |
868 | /* Assume Tiger Lake */ | |
869 | if (has_avx512vp2intersect) | |
870 | cpu = "tigerlake"; | |
871 | /* Assume Cooper Lake */ | |
872 | else if (has_avx512bf16) | |
873 | cpu = "cooperlake"; | |
874 | /* Assume Ice Lake Server. */ | |
875 | else if (has_wbnoinvd) | |
876 | cpu = "icelake-server"; | |
877 | /* Assume Ice Lake. */ | |
878 | else if (has_avx512bitalg) | |
879 | cpu = "icelake-client"; | |
880 | /* Assume Cannon Lake. */ | |
881 | else if (has_avx512vbmi) | |
882 | cpu = "cannonlake"; | |
883 | /* Assume Knights Mill. */ | |
884 | else if (has_avx5124vnniw) | |
885 | cpu = "knm"; | |
886 | /* Assume Knights Landing. */ | |
887 | else if (has_avx512er) | |
888 | cpu = "knl"; | |
889 | /* Assume Skylake with AVX-512. */ | |
890 | else if (has_avx512f) | |
891 | cpu = "skylake-avx512"; | |
892 | /* Assume Skylake. */ | |
893 | else if (has_clflushopt) | |
894 | cpu = "skylake"; | |
895 | /* Assume Broadwell. */ | |
896 | else if (has_adx) | |
897 | cpu = "broadwell"; | |
898 | else if (has_avx2) | |
992592ec | 899 | /* Assume Haswell. */ |
a9fcfec3 HL |
900 | cpu = "haswell"; |
901 | else | |
4ffae7ff | 902 | /* Assume Sandy Bridge. */ |
a9fcfec3 HL |
903 | cpu = "sandybridge"; |
904 | } | |
4ffae7ff | 905 | else if (has_sse4_2) |
0b871ccf | 906 | { |
a548a5a1 OM |
907 | if (has_gfni) |
908 | /* Assume Tremont. */ | |
909 | cpu = "tremont"; | |
910 | else if (has_sgx) | |
74b2bb19 OM |
911 | /* Assume Goldmont Plus. */ |
912 | cpu = "goldmont-plus"; | |
913 | else if (has_xsave) | |
50e461df OM |
914 | /* Assume Goldmont. */ |
915 | cpu = "goldmont"; | |
916 | else if (has_movbe) | |
d3c11974 L |
917 | /* Assume Silvermont. */ |
918 | cpu = "silvermont"; | |
0b871ccf | 919 | else |
d3c11974 L |
920 | /* Assume Nehalem. */ |
921 | cpu = "nehalem"; | |
0b871ccf | 922 | } |
4ffae7ff L |
923 | else if (has_ssse3) |
924 | { | |
925 | if (has_movbe) | |
d3c11974 L |
926 | /* Assume Bonnell. */ |
927 | cpu = "bonnell"; | |
4ffae7ff L |
928 | else |
929 | /* Assume Core 2. */ | |
930 | cpu = "core2"; | |
931 | } | |
8d37375b JJ |
932 | else if (has_longmode) |
933 | /* Perhaps some emulator? Assume x86-64, otherwise gcc | |
934 | -march=native would be unusable for 64-bit compilations, | |
935 | as all the CPUs below are 32-bit only. */ | |
936 | cpu = "x86-64"; | |
fb112177 | 937 | else if (has_sse3) |
a239d460 JM |
938 | { |
939 | if (vendor == signature_CENTAUR_ebx) | |
940 | /* C7 / Eden "Esther" */ | |
941 | cpu = "c7"; | |
942 | else | |
943 | /* It is Core Duo. */ | |
944 | cpu = "pentium-m"; | |
945 | } | |
fb112177 L |
946 | else if (has_sse2) |
947 | /* It is Pentium M. */ | |
948 | cpu = "pentium-m"; | |
949 | else if (has_sse) | |
4bdf739d UB |
950 | { |
951 | if (vendor == signature_CENTAUR_ebx) | |
a239d460 JM |
952 | { |
953 | if (model >= 9) | |
954 | /* Eden "Nehemiah" */ | |
955 | cpu = "nehemiah"; | |
956 | else | |
957 | cpu = "c3-2"; | |
958 | } | |
4bdf739d UB |
959 | else |
960 | /* It is Pentium III. */ | |
961 | cpu = "pentium3"; | |
962 | } | |
fb112177 L |
963 | else if (has_mmx) |
964 | /* It is Pentium II. */ | |
965 | cpu = "pentium2"; | |
44f276c6 | 966 | else |
fb112177 L |
967 | /* Default to Pentium Pro. */ |
968 | cpu = "pentiumpro"; | |
44f276c6 | 969 | } |
b3172cab | 970 | else |
44f276c6 L |
971 | /* For -mtune, we default to -mtune=generic. */ |
972 | cpu = "generic"; | |
973 | break; | |
fa959ce4 | 974 | } |
b3172cab UB |
975 | break; |
976 | case PROCESSOR_PENTIUM4: | |
977 | if (has_sse3) | |
fa959ce4 | 978 | { |
b3172cab UB |
979 | if (has_longmode) |
980 | cpu = "nocona"; | |
fa959ce4 | 981 | else |
fb112177 | 982 | cpu = "prescott"; |
fa959ce4 | 983 | } |
b3172cab | 984 | else |
fb112177 | 985 | cpu = "pentium4"; |
edccdcb1 L |
986 | break; |
987 | case PROCESSOR_GEODE: | |
988 | cpu = "geode"; | |
989 | break; | |
990 | case PROCESSOR_K6: | |
b3172cab UB |
991 | if (arch && has_3dnow) |
992 | cpu = "k6-3"; | |
edccdcb1 L |
993 | else |
994 | cpu = "k6"; | |
995 | break; | |
996 | case PROCESSOR_ATHLON: | |
b3172cab | 997 | if (arch && has_sse) |
edccdcb1 L |
998 | cpu = "athlon-4"; |
999 | else | |
1000 | cpu = "athlon"; | |
1001 | break; | |
edccdcb1 | 1002 | case PROCESSOR_K8: |
d3606ee3 JM |
1003 | if (arch) |
1004 | { | |
1005 | if (vendor == signature_CENTAUR_ebx) | |
1006 | { | |
1007 | if (has_sse4_1) | |
1008 | /* Nano 3000 | Nano dual / quad core | Eden X4 */ | |
1009 | cpu = "nano-3000"; | |
1010 | else if (has_ssse3) | |
1011 | /* Nano 1000 | Nano 2000 */ | |
1012 | cpu = "nano"; | |
1013 | else if (has_sse3) | |
1014 | /* Eden X2 */ | |
1015 | cpu = "eden-x2"; | |
1016 | else | |
1017 | /* Default to k8 */ | |
1018 | cpu = "k8"; | |
1019 | } | |
1020 | else if (has_sse3) | |
1021 | cpu = "k8-sse3"; | |
1022 | else | |
1023 | cpu = "k8"; | |
1024 | } | |
b3172cab | 1025 | else |
d3606ee3 | 1026 | /* For -mtune, we default to -mtune=k8 */ |
b3172cab | 1027 | cpu = "k8"; |
edccdcb1 | 1028 | break; |
35a63f21 DR |
1029 | case PROCESSOR_AMDFAM10: |
1030 | cpu = "amdfam10"; | |
1031 | break; | |
1133125e HJ |
1032 | case PROCESSOR_BDVER1: |
1033 | cpu = "bdver1"; | |
1034 | break; | |
4d652a18 HJ |
1035 | case PROCESSOR_BDVER2: |
1036 | cpu = "bdver2"; | |
1037 | break; | |
eb2f2b44 GG |
1038 | case PROCESSOR_BDVER3: |
1039 | cpu = "bdver3"; | |
1040 | break; | |
ed97ad47 GG |
1041 | case PROCESSOR_BDVER4: |
1042 | cpu = "bdver4"; | |
1043 | break; | |
9ce29eb0 VK |
1044 | case PROCESSOR_ZNVER1: |
1045 | cpu = "znver1"; | |
1046 | break; | |
2901f42f VK |
1047 | case PROCESSOR_ZNVER2: |
1048 | cpu = "znver2"; | |
1049 | break; | |
14b52538 CF |
1050 | case PROCESSOR_BTVER1: |
1051 | cpu = "btver1"; | |
1052 | break; | |
e32bfc16 VK |
1053 | case PROCESSOR_BTVER2: |
1054 | cpu = "btver2"; | |
1055 | break; | |
b3172cab | 1056 | |
edccdcb1 | 1057 | default: |
b3172cab UB |
1058 | /* Use something reasonable. */ |
1059 | if (arch) | |
1060 | { | |
1061 | if (has_ssse3) | |
1062 | cpu = "core2"; | |
1063 | else if (has_sse3) | |
1064 | { | |
1065 | if (has_longmode) | |
1066 | cpu = "nocona"; | |
1067 | else | |
1068 | cpu = "prescott"; | |
1069 | } | |
4bdf739d UB |
1070 | else if (has_longmode) |
1071 | /* Perhaps some emulator? Assume x86-64, otherwise gcc | |
1072 | -march=native would be unusable for 64-bit compilations, | |
1073 | as all the CPUs below are 32-bit only. */ | |
1074 | cpu = "x86-64"; | |
b3172cab UB |
1075 | else if (has_sse2) |
1076 | cpu = "pentium4"; | |
1077 | else if (has_cmov) | |
1078 | cpu = "pentiumpro"; | |
1079 | else if (has_mmx) | |
1080 | cpu = "pentium-mmx"; | |
1081 | else if (has_cmpxchg8b) | |
1082 | cpu = "pentium"; | |
1083 | } | |
1084 | else | |
1085 | cpu = "generic"; | |
fa959ce4 MM |
1086 | } |
1087 | ||
5be6cb59 UB |
1088 | if (arch) |
1089 | { | |
11c2aa39 UB |
1090 | const char *mmx = has_mmx ? " -mmmx" : " -mno-mmx"; |
1091 | const char *mmx3dnow = has_3dnow ? " -m3dnow" : " -mno-3dnow"; | |
1092 | const char *sse = has_sse ? " -msse" : " -mno-sse"; | |
1093 | const char *sse2 = has_sse2 ? " -msse2" : " -mno-sse2"; | |
1094 | const char *sse3 = has_sse3 ? " -msse3" : " -mno-sse3"; | |
1095 | const char *ssse3 = has_ssse3 ? " -mssse3" : " -mno-ssse3"; | |
1096 | const char *sse4a = has_sse4a ? " -msse4a" : " -mno-sse4a"; | |
5eed4f27 L |
1097 | const char *cx16 = has_cmpxchg16b ? " -mcx16" : " -mno-cx16"; |
1098 | const char *sahf = has_lahf_lm ? " -msahf" : " -mno-sahf"; | |
1099 | const char *movbe = has_movbe ? " -mmovbe" : " -mno-movbe"; | |
11c2aa39 | 1100 | const char *aes = has_aes ? " -maes" : " -mno-aes"; |
c1618f82 | 1101 | const char *sha = has_sha ? " -msha" : " -mno-sha"; |
5eed4f27 L |
1102 | const char *pclmul = has_pclmul ? " -mpclmul" : " -mno-pclmul"; |
1103 | const char *popcnt = has_popcnt ? " -mpopcnt" : " -mno-popcnt"; | |
1104 | const char *abm = has_abm ? " -mabm" : " -mno-abm"; | |
1105 | const char *lwp = has_lwp ? " -mlwp" : " -mno-lwp"; | |
1106 | const char *fma = has_fma ? " -mfma" : " -mno-fma"; | |
1107 | const char *fma4 = has_fma4 ? " -mfma4" : " -mno-fma4"; | |
1108 | const char *xop = has_xop ? " -mxop" : " -mno-xop"; | |
1109 | const char *bmi = has_bmi ? " -mbmi" : " -mno-bmi"; | |
13b93d4b OM |
1110 | const char *pconfig = has_pconfig ? " -mpconfig" : " -mno-pconfig"; |
1111 | const char *wbnoinvd = has_wbnoinvd ? " -mwbnoinvd" : " -mno-wbnoinvd"; | |
73e32c47 | 1112 | const char *sgx = has_sgx ? " -msgx" : " -mno-sgx"; |
82feeb8d | 1113 | const char *bmi2 = has_bmi2 ? " -mbmi2" : " -mno-bmi2"; |
5eed4f27 L |
1114 | const char *tbm = has_tbm ? " -mtbm" : " -mno-tbm"; |
1115 | const char *avx = has_avx ? " -mavx" : " -mno-avx"; | |
7afac110 | 1116 | const char *avx2 = has_avx2 ? " -mavx2" : " -mno-avx2"; |
642a011d | 1117 | const char *sse4_2 = has_sse4_2 ? " -msse4.2" : " -mno-sse4.2"; |
5eed4f27 | 1118 | const char *sse4_1 = has_sse4_1 ? " -msse4.1" : " -mno-sse4.1"; |
3ed2c643 | 1119 | const char *lzcnt = has_lzcnt ? " -mlzcnt" : " -mno-lzcnt"; |
38d7f26e | 1120 | const char *hle = has_hle ? " -mhle" : " -mno-hle"; |
76a02e42 | 1121 | const char *rtm = has_rtm ? " -mrtm" : " -mno-rtm"; |
d1925759 L |
1122 | const char *rdrnd = has_rdrnd ? " -mrdrnd" : " -mno-rdrnd"; |
1123 | const char *f16c = has_f16c ? " -mf16c" : " -mno-f16c"; | |
1124 | const char *fsgsbase = has_fsgsbase ? " -mfsgsbase" : " -mno-fsgsbase"; | |
4c340b5d | 1125 | const char *rdseed = has_rdseed ? " -mrdseed" : " -mno-rdseed"; |
e61c94dd | 1126 | const char *prfchw = has_prfchw ? " -mprfchw" : " -mno-prfchw"; |
d05e383b | 1127 | const char *adx = has_adx ? " -madx" : " -mno-adx"; |
3a0d99bb AI |
1128 | const char *fxsr = has_fxsr ? " -mfxsr" : " -mno-fxsr"; |
1129 | const char *xsave = has_xsave ? " -mxsave" : " -mno-xsave"; | |
1130 | const char *xsaveopt = has_xsaveopt ? " -mxsaveopt" : " -mno-xsaveopt"; | |
3f97cb0b AI |
1131 | const char *avx512f = has_avx512f ? " -mavx512f" : " -mno-avx512f"; |
1132 | const char *avx512er = has_avx512er ? " -mavx512er" : " -mno-avx512er"; | |
1133 | const char *avx512cd = has_avx512cd ? " -mavx512cd" : " -mno-avx512cd"; | |
1134 | const char *avx512pf = has_avx512pf ? " -mavx512pf" : " -mno-avx512pf"; | |
43b3f52f | 1135 | const char *prefetchwt1 = has_prefetchwt1 ? " -mprefetchwt1" : " -mno-prefetchwt1"; |
9cdea277 IT |
1136 | const char *clflushopt = has_clflushopt ? " -mclflushopt" : " -mno-clflushopt"; |
1137 | const char *xsavec = has_xsavec ? " -mxsavec" : " -mno-xsavec"; | |
1138 | const char *xsaves = has_xsaves ? " -mxsaves" : " -mno-xsaves"; | |
07165dd7 | 1139 | const char *avx512dq = has_avx512dq ? " -mavx512dq" : " -mno-avx512dq"; |
b525d943 | 1140 | const char *avx512bw = has_avx512bw ? " -mavx512bw" : " -mno-avx512bw"; |
f4af595f | 1141 | const char *avx512vl = has_avx512vl ? " -mavx512vl" : " -mno-avx512vl"; |
4190ea38 | 1142 | const char *avx512ifma = has_avx512ifma ? " -mavx512ifma" : " -mno-avx512ifma"; |
3dcc8af5 | 1143 | const char *avx512vbmi = has_avx512vbmi ? " -mavx512vbmi" : " -mno-avx512vbmi"; |
5fbb13a7 | 1144 | const char *avx5124vnniw = has_avx5124vnniw ? " -mavx5124vnniw" : " -mno-avx5124vnniw"; |
fca51879 | 1145 | const char *avx512vbmi2 = has_avx512vbmi2 ? " -mavx512vbmi2" : " -mno-avx512vbmi2"; |
98966963 | 1146 | const char *avx512vnni = has_avx512vnni ? " -mavx512vnni" : " -mno-avx512vnni"; |
5fbb13a7 | 1147 | const char *avx5124fmaps = has_avx5124fmaps ? " -mavx5124fmaps" : " -mno-avx5124fmaps"; |
9c3bca11 | 1148 | const char *clwb = has_clwb ? " -mclwb" : " -mno-clwb"; |
500a08b2 | 1149 | const char *mwaitx = has_mwaitx ? " -mmwaitx" : " -mno-mwaitx"; |
9ce29eb0 | 1150 | const char *clzero = has_clzero ? " -mclzero" : " -mno-clzero"; |
41a4ef22 | 1151 | const char *pku = has_pku ? " -mpku" : " -mno-pku"; |
1d516992 | 1152 | const char *rdpid = has_rdpid ? " -mrdpid" : " -mno-rdpid"; |
b8cca31c | 1153 | const char *gfni = has_gfni ? " -mgfni" : " -mno-gfni"; |
2a25448c | 1154 | const char *shstk = has_shstk ? " -mshstk" : " -mno-shstk"; |
b7b0a4fa | 1155 | const char *vaes = has_vaes ? " -mvaes" : " -mno-vaes"; |
6557be99 | 1156 | const char *vpclmulqdq = has_vpclmulqdq ? " -mvpclmulqdq" : " -mno-vpclmulqdq"; |
e21b52af | 1157 | const char *avx512vp2intersect = has_avx512vp2intersect ? " -mavx512vp2intersect" : " -mno-avx512vp2intersect"; |
e2a29465 | 1158 | const char *avx512bitalg = has_avx512bitalg ? " -mavx512bitalg" : " -mno-avx512bitalg"; |
37d51c75 SP |
1159 | const char *movdiri = has_movdiri ? " -mmovdiri" : " -mno-movdiri"; |
1160 | const char *movdir64b = has_movdir64b ? " -mmovdir64b" : " -mno-movdir64b"; | |
6a10feda | 1161 | const char *enqcmd = has_enqcmd ? " -menqcmd" : " -mno-enqcmd"; |
55f31ed1 | 1162 | const char *waitpkg = has_waitpkg ? " -mwaitpkg" : " -mno-waitpkg"; |
f8d9957e | 1163 | const char *cldemote = has_cldemote ? " -mcldemote" : " -mno-cldemote"; |
41f8d1fc | 1164 | const char *ptwrite = has_ptwrite ? " -mptwrite" : " -mno-ptwrite"; |
4f0e90fa | 1165 | const char *avx512bf16 = has_avx512bf16 ? " -mavx512bf16" : " -mno-avx512bf16"; |
41f8d1fc | 1166 | |
11c2aa39 | 1167 | options = concat (options, mmx, mmx3dnow, sse, sse2, sse3, ssse3, |
c1618f82 | 1168 | sse4a, cx16, sahf, movbe, aes, sha, pclmul, |
73e32c47 | 1169 | popcnt, abm, lwp, fma, fma4, xop, bmi, sgx, bmi2, |
13b93d4b | 1170 | pconfig, wbnoinvd, |
76a02e42 | 1171 | tbm, avx, avx2, sse4_2, sse4_1, lzcnt, rtm, |
3a0d99bb | 1172 | hle, rdrnd, f16c, fsgsbase, rdseed, prfchw, adx, |
3f97cb0b | 1173 | fxsr, xsave, xsaveopt, avx512f, avx512er, |
9cdea277 | 1174 | avx512cd, avx512pf, prefetchwt1, clflushopt, |
f4af595f | 1175 | xsavec, xsaves, avx512dq, avx512bw, avx512vl, |
5fbb13a7 | 1176 | avx512ifma, avx512vbmi, avx5124fmaps, avx5124vnniw, |
e95dda95 | 1177 | clwb, mwaitx, clzero, pku, rdpid, gfni, shstk, |
e2a29465 | 1178 | avx512vbmi2, avx512vnni, vaes, vpclmulqdq, |
f8d9957e | 1179 | avx512bitalg, movdiri, movdir64b, waitpkg, cldemote, |
e21b52af | 1180 | ptwrite, avx512bf16, enqcmd, avx512vp2intersect, |
f8d9957e | 1181 | NULL); |
5be6cb59 UB |
1182 | } |
1183 | ||
fa959ce4 | 1184 | done: |
f3afc8a7 | 1185 | return concat (cache, "-m", argv[0], "=", cpu, options, NULL); |
fa959ce4 MM |
1186 | } |
1187 | #else | |
b3172cab | 1188 | |
02147868 UB |
1189 | /* If we are compiling with GCC where %EBX register is fixed, then the |
1190 | driver will just ignore -march and -mtune "native" target and will leave | |
1191 | to the newly built compiler to generate code for its default target. */ | |
b3172cab | 1192 | |
997ef9e7 | 1193 | const char *host_detect_local_cpu (int, const char **) |
fa959ce4 | 1194 | { |
f3afc8a7 | 1195 | return NULL; |
fa959ce4 | 1196 | } |
a6ecb05c | 1197 | #endif /* __GNUC__ */ |