beta-0.89.2
[luatex.git] / source / libs / gmp / gmp-src / configgmp.guess
blobb9d0c5894d53877e79ee434e5e3742770041c98e
1 #! /bin/sh
3 # GMP config.guess wrapper.
6 # Copyright 2000-2006, 2008, 2011-2015 Free Software Foundation, Inc.
8 # This file is part of the GNU MP Library.
10 # The GNU MP Library is free software; you can redistribute it and/or modify
11 # it under the terms of either:
13 # * the GNU Lesser General Public License as published by the Free
14 # Software Foundation; either version 3 of the License, or (at your
15 # option) any later version.
17 # or
19 # * the GNU General Public License as published by the Free Software
20 # Foundation; either version 2 of the License, or (at your option) any
21 # later version.
23 # or both in parallel, as here.
25 # The GNU MP Library is distributed in the hope that it will be useful, but
26 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
27 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28 # for more details.
30 # You should have received copies of the GNU General Public License and the
31 # GNU Lesser General Public License along with the GNU MP Library. If not,
32 # see https://www.gnu.org/licenses/.
35 # Usage: config.guess
37 # Print the host system CPU-VENDOR-OS.
39 # configfsf.guess is run and its guess then sharpened up to take advantage
40 # of the finer grained CPU types that GMP knows.
43 # Expect to find configfsf.guess in the same directory as this config.guess
44 configfsf_guess="`echo \"$0\" | sed 's/config.guess$/configfsf.guess/'`"
45 if test "$configfsf_guess" = "$0"; then
46 echo "Cannot derive configfsf.guess from $0" 1>&2
47 exit 1
49 if test -f "$configfsf_guess"; then
51 else
52 echo "$configfsf_guess not found" 1>&2
53 exit 1
56 # Setup a $SHELL with which to run configfsf.guess, using the same
57 # $CONFIG_SHELL or /bin/sh as autoconf does when running config.guess
58 SHELL=${CONFIG_SHELL-/bin/sh}
60 # Identify ourselves on --version, --help or errors
61 if test $# != 0; then
62 echo "(GNU MP wrapped config.guess)"
63 $SHELL $configfsf_guess "$@"
64 exit 1
67 guess_full=`$SHELL $configfsf_guess`
68 if test $? != 0; then
69 exit 1
72 guess_cpu=`echo "$guess_full" | sed 's/-.*$//'`
73 guess_rest=`echo "$guess_full" | sed 's/^[^-]*//'`
74 exact_cpu=
77 # -------------------------------------------------------------------------
78 # The following should look at the current guess and probe the system to
79 # establish a better guess in exact_cpu. Leave exact_cpu empty if probes
80 # can't be done, or don't work.
82 # When a number of probes are done, test -z "$exact_cpu" can be used instead
83 # of putting each probe under an "else" of the preceeding. That can stop
84 # the code getting horribly nested and marching off the right side of the
85 # screen.
87 # Note that when a compile-and-link is done in one step we need to remove .o
88 # files, since lame C compilers generate these even when not asked.
91 # CC_FOR_BUILD -- compiler used by this script. Note that the use of a
92 # compiler to aid in system detection is discouraged as it requires
93 # temporary files to be created and, as you can see below, it is a
94 # headache to deal with in a portable fashion.
96 # Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
97 # use `HOST_CC' if defined, but it is deprecated.
99 # Portable tmp directory creation inspired by the Autoconf team.
101 set_cc_for_build='
102 trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
103 trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
104 : ${TMPDIR=/tmp} ;
105 { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
106 { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
107 { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
108 { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
109 dummy=$tmp/dummy ;
110 tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy $dummy.core ${dummy}0.s" ;
111 case $CC_FOR_BUILD,$HOST_CC,$CC in
112 ,,) echo "int x;" > $dummy.c ;
113 for c in cc gcc c89 c99 ; do
114 if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
115 CC_FOR_BUILD="$c"; break ;
116 fi ;
117 done ;
118 if test x"$CC_FOR_BUILD" = x ; then
119 CC_FOR_BUILD=no_compiler_found ;
122 ,,*) CC_FOR_BUILD=$CC ;;
123 ,*,*) CC_FOR_BUILD=$HOST_CC ;;
124 esac ; set_cc_for_build= ;'
127 case "$guess_full" in
129 alpha-*-*)
130 eval $set_cc_for_build
131 # configfsf.guess detects exact alpha cpu types for OSF and GNU/Linux, but
132 # not for *BSD and other systems. We try to get an exact type for any
133 # plain "alpha" it leaves.
135 # configfsf.guess used to have a block of code not unlike this, but these
136 # days does its thing with Linux kernel /proc/cpuinfo or OSF psrinfo.
138 cat <<EOF >${dummy}0.s
139 .data
140 Lformat:
141 .byte 37,100,45,37,120,10,0 # "%d-%x\n"
142 .text
143 .globl main
144 .align 4
145 .ent main
146 main:
147 .frame \$30,16,\$26,0
148 ldgp \$29,0(\$27)
149 .prologue 1
150 .long 0x47e03d91 # implver \$17
151 lda \$2,-1
152 .long 0x47e20c21 # amask \$2,\$1
153 lda \$16,Lformat
154 not \$1,\$18
155 jsr \$26,printf
156 ldgp \$29,0(\$26)
157 mov 0,\$16
158 jsr \$26,exit
159 .end main
161 $CC_FOR_BUILD ${dummy}0.s -o $dummy 2>/dev/null
162 if test "$?" = 0 ; then
163 case `$dummy` in
164 0-0) exact_cpu=alpha ;;
165 1-0) exact_cpu=alphaev5 ;;
166 1-1) exact_cpu=alphaev56 ;;
167 1-101) exact_cpu=alphapca56 ;;
168 2-303) exact_cpu=alphaev6 ;;
169 2-307) exact_cpu=alphaev67 ;;
170 2-1307) exact_cpu=alphaev68 ;;
171 esac
175 arm*-*-*)
176 cpu_code=`sed -n 's/^CPU part.*\(0x.*\)$/\1/p' /proc/cpuinfo 2>/dev/null | head -n 1 2>/dev/null`
177 case "$cpu_code" in
178 0xa10 | 0xa11 | 0xb11) # v4 strongarm/sa1100
179 exact_cpu="armsa1";;
180 0x915 | 0x925 | \
181 0x920 | 0x922 | 0x940) # v4
182 exact_cpu="arm9tdmi";;
183 0x210 | 0x290 | 0x2d0 | \
184 0x212 | 0x292 | 0x2d2 | \
185 0x411) exact_cpu="armxscale";; # v5 pxa2xx
186 0x926 | 0x946 | 0x966 | 0x968) # v5te/v5tej
187 exact_cpu="arm9te";;
188 0xa20 | 0xa22 | 0xa26) # v5te
189 exact_cpu="arm10";;
190 0xb02) exact_cpu="arm11mpcore";; # v6
191 0xb36) exact_cpu="arm1136";; # v6
192 0xb56) exact_cpu="arm1156";; # v6t2
193 0xb76) exact_cpu="arm1176";; # v6
194 0xc05) exact_cpu="armcortexa5";; # v7a
195 0xc07) exact_cpu="armcortexa7";; # v7a
196 0xc08) exact_cpu="armcortexa8";; # v7a
197 0xc09) exact_cpu="armcortexa9";; # v7a
198 0xc0f) exact_cpu="armcortexa15";; # v7a
199 0xc14) exact_cpu="armcortexr4";; # v7r
200 0xc15) exact_cpu="armcortexr5";; # v7r
201 0xc23) exact_cpu="armcortexm3";; # v7m
202 *) exact_cpu=$guess_cpu;;
203 esac
204 exact_cpu="${exact_cpu}`sed -n 's;^Features.*\(neon\).*;\1;p' /proc/cpuinfo 2>/dev/null | head -n 1 2>/dev/null`"
207 ia64*-*-*)
208 eval $set_cc_for_build
209 # CPUID[3] bits 24 to 31 is the processor family. itanium2 is documented
210 # as 0x1f, plain itanium has been seen returning 0x07 on two systems, but
211 # haven't found any documentation on it as such.
213 # Defining both getcpuid and _getcpuid lets us ignore whether the system
214 # expects underscores or not.
216 # "unsigned long long" is always 64 bits, in fact on hpux in ilp32 mode
217 # (which is the default there), it's the only 64-bit type.
219 cat >${dummy}0.s <<EOF
220 .text
221 .global _getcpuid
222 .proc _getcpuid
223 _getcpuid:
224 mov r8 = CPUID[r32] ;;
225 br.ret.sptk.many rp ;;
226 .endp _getcpuid
227 .global getcpuid
228 .proc getcpuid
229 getcpuid:
230 mov r8 = CPUID[r32] ;;
231 br.ret.sptk.many rp ;;
232 .endp getcpuid
234 cat >$dummy.c <<EOF
235 #include <stdio.h>
236 unsigned long long getcpuid ();
238 main ()
240 if (getcpuid(0LL) == 0x49656E69756E6547LL && getcpuid(1LL) == 0x6C65746ELL)
242 /* "GenuineIntel" */
243 switch ((getcpuid(3LL) >> 24) & 0xFF) {
244 case 0x07: puts ("itanium"); break;
245 case 0x1F: puts ("itanium2"); break; /* McKinley, Madison */
246 case 0x20: puts ("itanium2"); break; /* Montecito */
249 return 0;
252 if $CC_FOR_BUILD ${dummy}0.s $dummy.c -o $dummy >/dev/null 2>&1; then
253 exact_cpu=`$dummy`
257 mips-*-irix[6789]*)
258 # IRIX 6 and up always has a 64-bit mips cpu
259 exact_cpu=mips64
262 m68k-*-*)
263 eval $set_cc_for_build
264 # NetBSD (and presumably other *BSD) "sysctl hw.model" gives for example
265 # hw.model = Apple Macintosh Quadra 610 (68040)
266 exact_cpu=`(sysctl hw.model) 2>/dev/null | sed -n 's/^.*\(680[012346]0\).*$/m\1/p'`
267 if test -z "$exact_cpu"; then
268 # Linux kernel 2.2 gives for example "CPU: 68020" (tabs in between).
269 exact_cpu=`sed -n 's/^CPU:.*\(680[012346]0\).*$/m\1/p' /proc/cpuinfo 2>/dev/null`
271 if test -z "$exact_cpu"; then
272 # Try: movel #0,%d0; rts
273 # This is to check the compiler and our asm code works etc, before
274 # assuming failures below indicate cpu characteristics.
275 # .byte is used to avoid problems with assembler syntax variations.
276 # For testing, provoke failures by adding "illegal" possibly as
277 # ".byte 0x4A, 0xFC"
278 cat >${dummy}0.s <<EOF
279 .text
280 .globl main
281 .globl _main
282 main:
283 _main:
284 .byte 0x70, 0x00
285 .byte 0x4e, 0x75
288 if ($CC_FOR_BUILD ${dummy}0.s -o $dummy && $dummy) >/dev/null 2>&1; then
290 # $SHELL -c is used to execute $dummy below, since ($dummy)
291 # 2>/dev/null still prints the SIGILL message on some shells.
293 # Try: movel #0,%d0
294 # rtd #0
295 cat >${dummy}0.s <<EOF
296 .text
297 .globl main
298 .globl _main
299 main:
300 _main:
301 .byte 0x70, 0x00
302 .byte 0x4e, 0x74, 0x00, 0x00
304 if $CC_FOR_BUILD ${dummy}0.s -o $dummy >/dev/null 2>&1; then
305 $SHELL -c $dummy >/dev/null 2>&1
306 if test $? != 0; then
307 exact_cpu=m68000 # because rtd didn't work
312 if test -z "$exact_cpu"; then
313 # Try: trapf
314 # movel #0,%d0
315 # rts
316 # Another possibility for identifying 68000 and 68010 is the
317 # different value stored by "movem a0,(a0)+"
318 cat >${dummy}0.s <<EOF
319 .text
320 .globl main
321 .globl _main
322 main:
323 _main:
324 .byte 0x51, 0xFC
325 .byte 0x70, 0x00
326 .byte 0x4e, 0x75
328 if $CC_FOR_BUILD ${dummy}0.s -o $dummy >/dev/null 2>&1; then
329 $SHELL -c $dummy >/dev/null 2>&1
330 if test $? != 0; then
331 exact_cpu=m68010 # because trapf didn't work
336 if test -z "$exact_cpu"; then
337 # Try: bfffo %d1{0:31},%d0
338 # movel #0,%d0
339 # rts
340 cat >${dummy}0.s <<EOF
341 .text
342 .globl main
343 .globl _main
344 main:
345 _main:
346 .byte 0xED, 0xC1, 0x00, 0x1F
347 .byte 0x70, 0x00
348 .byte 0x4e, 0x75
350 if $CC_FOR_BUILD ${dummy}0.s -o $dummy >/dev/null 2>&1; then
351 $SHELL -c $dummy >/dev/null 2>&1
352 if test $? != 0; then
353 exact_cpu=m68360 # cpu32, because bfffo didn't work
358 if test -z "$exact_cpu"; then
359 # FIXME: Now we know 68020 or up, but how to detect 030, 040 and 060?
360 exact_cpu=m68020
364 if test -z "$exact_cpu"; then
365 case "$guess_full" in
366 *-*-next* | *-*-openstep*) # NeXTs are 68020 or better
367 exact_cpu=m68020 ;;
368 esac
373 rs6000-*-* | powerpc*-*-*)
374 # Enhancement: On MacOS the "machine" command prints for instance
375 # "ppc750". Interestingly on powerpc970-apple-darwin6.8.5 it prints
376 # "ppc970" where there's no actual #define for 970 from NXGetLocalArchInfo
377 # (as noted below). But the man page says the command is still "under
378 # development", so it doesn't seem wise to use it just yet, not while
379 # there's an alternative.
381 # Try to read the PVR. mfpvr is a protected instruction, NetBSD, MacOS
382 # and AIX don't allow it in user mode, but the Linux kernel does.
384 # Using explicit bytes for mfpvr avoids worrying about assembler syntax
385 # and underscores. "char"s are used instead of "int"s to avoid worrying
386 # whether sizeof(int)==4 or if it's the right endianness.
388 # Note this is no good on AIX, since a C function there is the address of
389 # a function descriptor, not actual code. But this doesn't matter since
390 # AIX doesn't allow mfpvr anyway.
392 eval $set_cc_for_build
393 cat >$dummy.c <<\EOF
394 #include <stdio.h>
395 struct {
396 int n; /* force 4-byte alignment */
397 char a[8];
398 } getpvr = {
401 0x7c, 0x7f, 0x42, 0xa6, /* mfpvr r3 */
402 0x4e, 0x80, 0x00, 0x20, /* blr */
406 main ()
408 unsigned (*fun)();
409 unsigned pvr;
411 /* a separate "fun" variable is necessary for gcc 2.95.2 on MacOS,
412 it gets a compiler error on a combined cast and call */
413 fun = (unsigned (*)()) getpvr.a;
414 pvr = (*fun) ();
416 switch (pvr >> 16) {
417 case 0x0001: puts ("powerpc601"); break;
418 case 0x0003: puts ("powerpc603"); break;
419 case 0x0004: puts ("powerpc604"); break;
420 case 0x0006: puts ("powerpc603e"); break;
421 case 0x0007: puts ("powerpc603e"); break; /* 603ev */
422 case 0x0008: puts ("powerpc750"); break;
423 case 0x0009: puts ("powerpc604e"); break;
424 case 0x000a: puts ("powerpc604e"); break; /* 604ev5 */
425 case 0x000c: puts ("powerpc7400"); break;
426 case 0x0041: puts ("powerpc630"); break;
427 case 0x0050: puts ("powerpc860"); break;
428 case 0x8000: puts ("powerpc7450"); break;
429 case 0x8001: puts ("powerpc7455"); break;
430 case 0x8002: puts ("powerpc7457"); break;
431 case 0x8003: puts ("powerpc7447"); break; /* really 7447A */
432 case 0x800c: puts ("powerpc7410"); break;
434 return 0;
437 if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
438 # This style construct is needed on AIX 4.3 to suppress the SIGILL error
439 # from (*fun)(). Using $SHELL -c $dummy 2>/dev/null doesn't work.
440 { x=`$dummy`; } 2>/dev/null
441 if test -n "$x"; then
442 exact_cpu=$x
446 # Grep the linux kernel /proc/cpuinfo pseudo-file.
447 # Anything unrecognised is ignored, since of course we mustn't spit out
448 # a cpu type config.sub doesn't know.
449 if test -z "$exact_cpu" && test -f /proc/cpuinfo; then
450 x=`grep "^cpu[ ]" /proc/cpuinfo | head -n 1`
451 x=`echo $x | sed -n 's/^cpu[ ]*:[ ]*\([A-Za-z0-9]*\).*/\1/p'`
452 x=`echo $x | sed 's/PPC//'`
453 case $x in
454 601) exact_cpu="power" ;;
455 603ev) exact_cpu="powerpc603e" ;;
456 604ev5) exact_cpu="powerpc604e" ;;
457 970??) exact_cpu="powerpc970" ;;
458 603 | 603e | 604 | 604e | 750 | 821 | 860)
459 exact_cpu="powerpc$x" ;;
460 POWER[4-9]*)
461 exact_cpu=`echo $x | sed -e "s;POWER;power;" -e "s;[a-zA-Z]*$;;"` ;;
462 esac
465 if test -z "$exact_cpu"; then
466 # On AIX, try looking at _system_configuration. This is present in
467 # version 4 at least.
468 cat >$dummy.c <<EOF
469 #include <stdio.h>
470 #include <sys/systemcfg.h>
472 main ()
474 switch (_system_configuration.implementation) {
475 /* Old versions of AIX don't have all these constants,
476 use ifdef for safety. */
477 #ifdef POWER_RS2
478 case POWER_RS2: puts ("power2"); break;
479 #endif
480 #ifdef POWER_601
481 case POWER_601: puts ("power"); break;
482 #endif
483 #ifdef POWER_603
484 case POWER_603: puts ("powerpc603"); break;
485 #endif
486 #ifdef POWER_604
487 case POWER_604: puts ("powerpc604"); break;
488 #endif
489 #ifdef POWER_620
490 case POWER_620: puts ("powerpc620"); break;
491 #endif
492 #ifdef POWER_630
493 case POWER_630: puts ("powerpc630"); break;
494 #endif
495 /* Dunno what this is, leave it out for now.
496 case POWER_A35: puts ("powerpca35"); break;
498 /* This is waiting for a bit more info.
499 case POWER_RS64II: puts ("powerpcrs64ii"); break;
501 #ifdef POWER_4
502 case POWER_4: puts ("power4"); break;
503 #endif
504 #ifdef POWER_5
505 case POWER_5: puts ("power5"); break;
506 #endif
507 #ifdef POWER_6
508 case POWER_6: puts ("power6"); break;
509 #endif
510 #ifdef POWER_7
511 case POWER_7: puts ("power7"); break;
512 #endif
513 #ifdef POWER_8
514 case POWER_8: puts ("power8"); break;
515 #endif
516 default:
517 if (_system_configuration.architecture == POWER_RS)
518 puts ("power");
519 else if (_system_configuration.width == 64)
520 puts ("powerpc64");
522 return 0;
525 if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
526 x=`$dummy`
527 if test -n "$x"; then
528 exact_cpu=$x
533 if test -z "$exact_cpu"; then
534 # On MacOS X (or any Mach-O presumably), NXGetLocalArchInfo cpusubtype
535 # can tell us the exact cpu.
536 cat >$dummy.c <<EOF
537 #include <stdio.h>
538 #include <mach-o/arch.h>
540 main (void)
542 const NXArchInfo *a = NXGetLocalArchInfo();
543 if (a->cputype == CPU_TYPE_POWERPC)
545 switch (a->cpusubtype) {
546 /* The following known to Darwin 1.3. */
547 case CPU_SUBTYPE_POWERPC_601: puts ("powerpc601"); break;
548 case CPU_SUBTYPE_POWERPC_602: puts ("powerpc602"); break;
549 case CPU_SUBTYPE_POWERPC_603: puts ("powerpc603"); break;
550 case CPU_SUBTYPE_POWERPC_603e: puts ("powerpc603e"); break;
551 case CPU_SUBTYPE_POWERPC_603ev: puts ("powerpc603e"); break;
552 case CPU_SUBTYPE_POWERPC_604: puts ("powerpc604"); break;
553 case CPU_SUBTYPE_POWERPC_604e: puts ("powerpc604e"); break;
554 case CPU_SUBTYPE_POWERPC_620: puts ("powerpc620"); break;
555 case CPU_SUBTYPE_POWERPC_750: puts ("powerpc750"); break;
556 case CPU_SUBTYPE_POWERPC_7400: puts ("powerpc7400"); break;
557 case CPU_SUBTYPE_POWERPC_7450: puts ("powerpc7450"); break;
558 /* Darwin 6.8.5 doesn't define the following */
559 case 0x8001: puts ("powerpc7455"); break;
560 case 0x8002: puts ("powerpc7457"); break;
561 case 0x8003: puts ("powerpc7447"); break;
562 case 100: puts ("powerpc970"); break;
565 return 0;
568 if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
569 x=`$dummy`
570 if test -n "$x"; then
571 exact_cpu=$x
577 sparc-*-* | sparc64-*-*)
578 # If we can recognise an actual v7 then $exact_cpu is set to "sparc" so as
579 # to short-circuit subsequent tests.
581 # Grep the linux kernel /proc/cpuinfo pseudo-file.
582 # A typical line is "cpu\t\t: TI UltraSparc II (BlackBird)"
583 # See arch/sparc/kernel/cpu.c and arch/sparc64/kernel/cpu.c.
585 if test -f /proc/cpuinfo; then
586 if grep 'cpu.*Cypress' /proc/cpuinfo >/dev/null; then
587 exact_cpu="sparc" # ie. v7
588 elif grep 'cpu.*Power-UP' /proc/cpuinfo >/dev/null; then
589 exact_cpu="sparc" # ie. v7
590 elif grep 'cpu.*HyperSparc' /proc/cpuinfo >/dev/null; then
591 exact_cpu="sparcv8"
592 elif grep 'cpu.*SuperSparc' /proc/cpuinfo >/dev/null; then
593 exact_cpu="supersparc"
594 elif grep 'cpu.*MicroSparc' /proc/cpuinfo >/dev/null; then
595 exact_cpu="microsparc"
596 elif grep 'cpu.*MB86904' /proc/cpuinfo >/dev/null; then
597 # actually MicroSPARC-II
598 exact_cpu=microsparc
599 elif grep 'cpu.*UltraSparc T5' /proc/cpuinfo >/dev/null; then
600 exact_cpu="ultrasparct5"
601 elif grep 'cpu.*UltraSparc T4' /proc/cpuinfo >/dev/null; then
602 exact_cpu="ultrasparct4"
603 elif grep 'cpu.*UltraSparc T3' /proc/cpuinfo >/dev/null; then
604 exact_cpu="ultrasparct3"
605 elif grep 'cpu.*UltraSparc T2' /proc/cpuinfo >/dev/null; then
606 exact_cpu="ultrasparct2"
607 elif grep 'cpu.*UltraSparc T1' /proc/cpuinfo >/dev/null; then
608 exact_cpu="ultrasparct1"
609 elif grep 'cpu.*UltraSparc III' /proc/cpuinfo >/dev/null; then
610 exact_cpu="ultrasparc3"
611 elif grep 'cpu.*UltraSparc IIi' /proc/cpuinfo >/dev/null; then
612 exact_cpu="ultrasparc2i"
613 elif grep 'cpu.*UltraSparc II' /proc/cpuinfo >/dev/null; then
614 exact_cpu="ultrasparc2"
615 elif grep 'cpu.*UltraSparc' /proc/cpuinfo >/dev/null; then
616 exact_cpu="ultrasparc"
620 # Need to invoke this for setup of $dummy
621 eval $set_cc_for_build
623 # Grep the output from sysinfo on SunOS.
624 # sysinfo has been seen living in /bin or in /usr/kvm
625 # cpu0 is a "SuperSPARC Model 41 SPARCmodule" CPU
626 # cpu0 is a "75 MHz TI,TMS390Z55" CPU
628 if test -z "$exact_cpu"; then
629 for i in sysinfo /usr/kvm/sysinfo; do
630 if $SHELL -c $i 2>/dev/null >$dummy; then
631 if grep 'cpu0 is a "SuperSPARC' $dummy >/dev/null; then
632 exact_cpu=supersparc
633 break
634 elif grep 'cpu0 is a .*TMS390Z5.' $dummy >/dev/null; then
635 # TMS390Z50 and TMS390Z55
636 exact_cpu=supersparc
637 break
640 done
643 # Grep the output from prtconf on Solaris.
644 # Use an explicit /usr/sbin, since that directory might not be in a normal
645 # user's path.
647 # SUNW,UltraSPARC (driver not attached)
648 # SUNW,UltraSPARC-II (driver not attached)
649 # SUNW,UltraSPARC-IIi (driver not attached)
650 # SUNW,UltraSPARC-III+ (driver not attached)
651 # Ross,RT625 (driver not attached)
652 # TI,TMS390Z50 (driver not attached)
654 # /usr/sbin/sysdef prints similar information, but includes all loadable
655 # cpu modules, not just the real cpu.
657 # We first try a plain prtconf, since that is known to work on older systems.
658 # But for newer T1 systems, that doesn't produce any useful output, we need
659 # "prtconf -vp" there.
661 for prtconfopt in "" "-vp"; do
662 if test -z "$exact_cpu"; then
663 if $SHELL -c "/usr/sbin/prtconf $prtconfopt" 2>/dev/null >$dummy; then
664 if grep 'SUNW,UltraSPARC-T5' $dummy >/dev/null; then
665 exact_cpu=ultrasparct5
666 elif grep 'SUNW,UltraSPARC-T4' $dummy >/dev/null; then
667 exact_cpu=ultrasparct4
668 elif grep 'SUNW,UltraSPARC-T3' $dummy >/dev/null; then
669 exact_cpu=ultrasparct3
670 elif grep 'SUNW,UltraSPARC-T2' $dummy >/dev/null; then
671 exact_cpu=ultrasparct2
672 elif grep 'SUNW,UltraSPARC-T1' $dummy >/dev/null; then
673 exact_cpu=ultrasparct1
674 elif grep 'SUNW,UltraSPARC-III' $dummy >/dev/null; then
675 exact_cpu=ultrasparc3
676 elif grep 'SUNW,UltraSPARC-IIi' $dummy >/dev/null; then
677 exact_cpu=ultrasparc2i
678 elif grep 'SUNW,UltraSPARC-II' $dummy >/dev/null; then
679 exact_cpu=ultrasparc2
680 elif grep 'SUNW,UltraSPARC' $dummy >/dev/null; then
681 exact_cpu=ultrasparc
682 elif grep 'Ross,RT62.' $dummy >/dev/null; then
683 # RT620, RT625, RT626 hypersparcs (v8).
684 exact_cpu=sparcv8
685 elif grep 'TI,TMS390Z5.' $dummy >/dev/null; then
686 # TMS390Z50 and TMS390Z55
687 exact_cpu=supersparc
688 elif grep 'TI,TMS390S10' $dummy >/dev/null; then
689 exact_cpu=microsparc
690 elif grep 'FMI,MB86904' $dummy >/dev/null; then
691 # actually MicroSPARC-II
692 exact_cpu=microsparc
696 done
698 # Grep the output from sysctl hw.model on sparc or sparc64 *BSD.
699 # Use an explicit /sbin, since that directory might not be in a normal
700 # user's path. Example outputs,
702 # hw.model: Sun Microsystems UltraSparc-IIi
704 if test -z "$exact_cpu"; then
705 if $SHELL -c "/sbin/sysctl hw.model" 2>/dev/null >$dummy; then
706 if grep -i 'UltraSparc-T5' $dummy >/dev/null; then
707 exact_cpu=ultrasparct5
708 elif grep -i 'UltraSparc-T4' $dummy >/dev/null; then
709 exact_cpu=ultrasparct4
710 elif grep -i 'UltraSparc-T3' $dummy >/dev/null; then
711 exact_cpu=ultrasparct3
712 elif grep -i 'UltraSparc-T2' $dummy >/dev/null; then
713 exact_cpu=ultrasparct2
714 elif grep -i 'UltraSparc-T1' $dummy >/dev/null; then
715 exact_cpu=ultrasparct1
716 elif grep -i 'UltraSparc-III' $dummy >/dev/null; then
717 exact_cpu=ultrasparc3
718 elif grep -i 'UltraSparc-IIi' $dummy >/dev/null; then
719 exact_cpu=ultrasparc2i
720 elif grep -i 'UltraSparc-II' $dummy >/dev/null; then
721 exact_cpu=ultrasparc2
722 elif grep -i 'UltraSparc' $dummy >/dev/null; then
723 exact_cpu=ultrasparc
724 elif grep 'TMS390Z5.' $dummy >/dev/null; then
725 # TMS390Z50 and TMS390Z55
726 exact_cpu=supersparc
727 elif grep 'TMS390S10' $dummy >/dev/null; then
728 exact_cpu=microsparc
729 elif grep 'MB86904' $dummy >/dev/null; then
730 # actually MicroSPARC-II
731 exact_cpu=microsparc
732 elif grep 'MB86907' $dummy >/dev/null; then
733 exact_cpu=turbosparc
738 # sun4m and sun4d are v8s of some sort, sun4u is a v9 of some sort
740 if test -z "$exact_cpu"; then
741 case `uname -m` in
742 sun4[md]) exact_cpu=sparcv8 ;;
743 sun4u) exact_cpu=sparcv9 ;;
744 esac
749 # Recognise x86 processors using a tricky cpuid with 4 arguments, repeating
750 # arguments; for x86-64 we effectively pass the 1st in rdx and the 2nd in rcx.
751 # This allows the same asm to work for both standard and Windoze calling
752 # conventions.
754 i?86-*-* | amd64-*-* | x86_64-*-*)
755 eval $set_cc_for_build
757 cat <<EOF >$dummy.c
758 #include <string.h>
759 #include <stdio.h>
760 #define CPUID(a,b) cpuid(b,a,a,b)
761 #if __cplusplus
762 extern "C"
763 #endif
764 unsigned int cpuid (int, char *, char *, int);
766 main ()
768 char vendor_string[13];
769 char feature_string[12];
770 long fms;
771 int family, model;
772 const char *modelstr, *suffix;
773 int cpu_64bit = 0, cpu_avx = 0;
774 int cpuid_64bit, cpuid_avx, cpuid_osxsave;
776 CPUID (vendor_string, 0);
777 vendor_string[12] = 0;
779 fms = CPUID (feature_string, 1);
781 family = ((fms >> 8) & 0xf) + ((fms >> 20) & 0xff);
782 model = ((fms >> 4) & 0xf) + ((fms >> 12) & 0xf0);
784 cpuid_avx = (feature_string[11] >> 4) & 1;
785 cpuid_osxsave = (feature_string[11] >> 3) & 1;
787 modelstr = "$guess_cpu";
789 /**************************************************/
790 /*** WARNING: keep this list in sync with fat.c ***/
791 /**************************************************/
792 if (strcmp (vendor_string, "GenuineIntel") == 0)
794 switch (family)
796 case 5:
797 if (model <= 2) modelstr = "pentium";
798 else if (model >= 4) modelstr = "pentiummmx";
799 break;
800 case 6:
801 if (model <= 1) modelstr = "pentiumpro";
802 else if (model <= 6) modelstr = "pentium2";
803 else if (model <= 8) modelstr = "pentium3";
804 else if (model <= 9) modelstr = "pentiumm";
805 else if (model <= 0x0c) modelstr = "pentium3";
806 else if (model <= 0x0e) modelstr = "pentiumm";
807 else if (model <= 0x19) cpu_64bit = 1, modelstr = "core2";
808 else if (model == 0x1a) cpu_64bit = 1, modelstr = "nehalem"; /* NHM Gainestown */
809 else if (model == 0x1c) cpu_64bit = 1, modelstr = "atom"; /* Silverthorne */
810 else if (model == 0x1d) cpu_64bit = 1, modelstr = "core2"; /* PNR Dunnington */
811 else if (model == 0x1e) cpu_64bit = 1, modelstr = "nehalem"; /* NHM Lynnfield/Jasper */
812 else if (model == 0x25) cpu_64bit = 1, modelstr = "westmere"; /* WSM Clarkdale/Arrandale */
813 else if (model == 0x26) cpu_64bit = 1, modelstr = "atom"; /* Lincroft */
814 else if (model == 0x27) cpu_64bit = 1, modelstr = "atom"; /* Saltwell */
815 else if (model == 0x2a) cpu_64bit = 1, cpu_avx=1, modelstr = "sandybridge";/* SB */
816 else if (model == 0x2c) cpu_64bit = 1, modelstr = "westmere"; /* WSM Gulftown */
817 else if (model == 0x2d) cpu_64bit = 1, cpu_avx=1, modelstr = "sandybridge";/* SBC-EP */
818 else if (model == 0x2e) cpu_64bit = 1, modelstr = "nehalem"; /* NHM Beckton */
819 else if (model == 0x2f) cpu_64bit = 1, modelstr = "westmere"; /* WSM Eagleton */
820 else if (model == 0x36) cpu_64bit = 1, modelstr = "atom"; /* Cedarview/Saltwell */
821 else if (model == 0x37) cpu_64bit = 1, modelstr = "silvermont"; /* Silvermont */
822 else if (model == 0x3a) cpu_64bit = 1, cpu_avx=1, modelstr = "ivybridge"; /* IBR */
823 else if (model == 0x3c) cpu_64bit = 1, cpu_avx=1, modelstr = "haswell"; /* Haswell client */
824 else if (model == 0x3d) cpu_64bit = 1, cpu_avx=1, modelstr = "broadwell"; /* Broadwell */
825 else if (model == 0x3e) cpu_64bit = 1, cpu_avx=1, modelstr = "ivybridge"; /* Ivytown */
826 else if (model == 0x3f) cpu_64bit = 1, cpu_avx=1, modelstr = "haswell"; /* Haswell server */
827 else if (model == 0x45) cpu_64bit = 1, cpu_avx=1, modelstr = "haswell"; /* Haswell ULT */
828 else if (model == 0x46) cpu_64bit = 1, cpu_avx=1, modelstr = "haswell"; /* Crystal Well */
829 else if (model == 0x47) cpu_64bit = 1, cpu_avx=1, modelstr = "broadwell"; /* Broadwell */
830 else if (model == 0x4a) cpu_64bit = 1, modelstr = "silvermont"; /* Silvermont */
831 else if (model == 0x4c) cpu_64bit = 1, modelstr = "silvermont"; /* Airmont */
832 else if (model == 0x4d) cpu_64bit = 1, modelstr = "silvermont"; /* Silvermont/Avoton */
833 else if (model == 0x4e) cpu_64bit = 1, cpu_avx=1, modelstr = "skylake"; /* Skylake client */
834 else if (model == 0x4f) cpu_64bit = 1, cpu_avx=1, modelstr = "broadwell"; /* Broadwell server */
835 else if (model == 0x55) cpu_64bit = 1, cpu_avx=1, modelstr = "skylake"; /* Skylake server */
836 else if (model == 0x56) cpu_64bit = 1, cpu_avx=1, modelstr = "broadwell"; /* Broadwell microserver */
837 else if (model == 0x57) cpu_64bit = 1, modelstr = "knightslanding"; /* aka Xeon Phi */
838 else if (model == 0x5a) cpu_64bit = 1, modelstr = "silvermont"; /* Silvermont */
839 else if (model == 0x5c) cpu_64bit = 1, modelstr = "goldmont"; /* Goldmont */
840 else if (model == 0x5e) cpu_64bit = 1, cpu_avx=1, modelstr = "skylake"; /* Skylake */
841 else if (model == 0x5f) cpu_64bit = 1, modelstr = "goldmont"; /* Goldmont */
842 else if (model == 0x8e) cpu_64bit = 1, cpu_avx=1, modelstr = "cabylake"; /* Capylake Y/U */
843 else if (model == 0x9e) cpu_64bit = 1, cpu_avx=1, modelstr = "cabylake"; /* Capylake desktop */
844 else cpu_64bit = 1, modelstr = "nehalem"; /* default */
846 if (strcmp (modelstr, "haswell") == 0)
848 /* Some Haswells lack BMI2. Let them appear as Sandybridges for
849 now. */
850 CPUID (feature_string, 7);
851 if ((feature_string[0 + 8 / 8] & (1 << (8 % 8))) == 0)
852 modelstr = "sandybridge";
855 break;
856 case 15:
857 cpu_64bit = 1, modelstr = "pentium4";
858 break;
861 else if (strcmp (vendor_string, "AuthenticAMD") == 0)
863 switch (family)
865 case 5:
866 if (model <= 3) modelstr = "k5";
867 else if (model <= 7) modelstr = "k6";
868 else if (model == 8) modelstr = "k62";
869 else if (model == 9) modelstr = "k63";
870 else if (model == 10) modelstr = "geode";
871 else if (model == 13) modelstr = "k63";
872 break;
873 case 6:
874 modelstr = "athlon";
875 break;
876 case 15: /* K8, K9 */
877 cpu_64bit = 1, modelstr = "k8";
878 break;
879 case 16: /* K10 */
880 cpu_64bit = 1, modelstr = "k10";
881 break;
882 case 17: /* Hybrid k8/k10, claim k8 */
883 cpu_64bit = 1, modelstr = "k8";
884 break;
885 case 18: /* Llano, uses K10 core */
886 cpu_64bit = 1, modelstr = "k10";
887 break;
888 case 19: /* AMD Internal, assume future K10 */
889 cpu_64bit = 1, modelstr = "k10";
890 break;
891 case 20: /* Bobcat */
892 cpu_64bit = 1, modelstr = "bobcat";
893 break;
894 case 21: /* Bulldozer */
895 cpu_64bit = 1, cpu_avx = 1;
896 if (model <= 1)
897 modelstr = "bulldozer";
898 else if (model < 0x20) /* really 2, [0x10-0x20) */
899 modelstr = "piledriver";
900 else if (model < 0x40) /* really [0x30-0x40) */
901 modelstr = "steamroller";
902 else /* really [0x60-0x70) */
903 modelstr = "excavator";
904 break;
905 case 22: /* Jaguar, an improved bobcat */
906 cpu_64bit = 1, cpu_avx = 1, modelstr = "jaguar";
907 break;
910 else if (strcmp (vendor_string, "CyrixInstead") == 0)
912 /* Should recognize Cyrix' processors too. */
914 else if (strcmp (vendor_string, "CentaurHauls") == 0)
916 switch (family)
918 case 6:
919 if (model < 9) modelstr = "viac3";
920 else if (model < 15) modelstr = "viac32";
921 else cpu_64bit = 1, modelstr = "nano";
922 break;
926 CPUID (feature_string, 0x80000001);
927 cpuid_64bit = (feature_string[7] >> 5) & 1;
929 suffix = "";
931 if (cpuid_64bit && ! cpu_64bit)
932 /* If our cpuid-based CPU identification thinks this is a 32-bit CPU but
933 cpuid claims AMD64 capabilities, then revert to the generic "x86_64".
934 This is of course wrong, but it can happen in some virtualisers and
935 emulators, and this workaround allows for successful 64-bit builds. */
936 modelstr = "x86_64";
937 else if (cpu_avx && ! (cpuid_avx && cpuid_osxsave))
938 /* For CPUs nominally capable of executing AVX, append "noavx" when not
939 both the AVX and OSXSAVE cpuid bits are set. We tolerate weirdness
940 here, as some virtualisers set a broken cpuid state here, while other
941 virtualisers allow users to set a broken state. */
942 suffix = "noavx";
944 printf ("%s%s", modelstr, suffix);
945 return 0;
949 # The rcx/ecx zeroing here and in the variant below is needed for the BMI2
950 # check.
952 cat <<EOF >${dummy}0.s
953 .globl cpuid
954 .globl _cpuid
955 cpuid:
956 _cpuid:
957 push %rbx
958 mov %rdx, %r8
959 mov %ecx, %eax
960 xor %ecx, %ecx
961 .byte 0x0f
962 .byte 0xa2
963 mov %ebx, (%r8)
964 mov %edx, 4(%r8)
965 mov %ecx, 8(%r8)
966 pop %rbx
970 if ($CC_FOR_BUILD ${dummy}0.s $dummy.c -o $dummy) >/dev/null 2>&1; then
971 # On 80386 and early 80486 cpuid is not available and will result in a
972 # SIGILL message, hence 2>/dev/null.
974 # On i386-unknown-freebsd4.9, "/bin/sh -c ./dummy" seems to send an
975 # "Illegal instruction (core dumped)" message to stdout, so we test $?
976 # to check if the program run was successful.
978 x=`$SHELL -c $dummy 2>/dev/null`
979 if test $? = 0 && test -n "$x"; then
980 exact_cpu=$x
984 cat <<EOF >${dummy}0.s
985 .globl cpuid
986 .globl _cpuid
987 cpuid:
988 _cpuid:
989 pushl %esi
990 pushl %ebx
991 movl 24(%esp),%eax
992 xor %ecx, %ecx
993 .byte 0x0f
994 .byte 0xa2
995 movl 20(%esp),%esi
996 movl %ebx,(%esi)
997 movl %edx,4(%esi)
998 movl %ecx,8(%esi)
999 popl %ebx
1000 popl %esi
1004 if test -z "$exact_cpu"; then
1005 if ($CC_FOR_BUILD ${dummy}0.s $dummy.c -o $dummy) >/dev/null 2>&1; then
1006 # On 80386 and early 80486 cpuid is not available and will result in a
1007 # SIGILL message, hence 2>/dev/null.
1009 # On i386-unknown-freebsd4.9, "/bin/sh -c ./dummy" seems to send an
1010 # "Illegal instruction (core dumped)" message to stdout, so we test $?
1011 # to check if the program run was successful.
1013 x=`$SHELL -c $dummy 2>/dev/null`
1014 if test $? = 0 && test -n "$x"; then
1015 exact_cpu=$x
1020 # We need to remove some .o files here since lame C compilers
1021 # generate these even when not asked.
1024 s390*-*-*)
1025 model=`grep "^processor 0: version =" /proc/cpuinfo | sed -e 's/.*machine = //'`
1026 case $model in
1027 2064 | 2066) zcpu="z900" ;;
1028 2084 | 2086) zcpu="z990" ;;
1029 2094 | 2096) zcpu="z9" ;;
1030 2097 | 2098) zcpu="z10" ;;
1031 2817 | 2818 | *) zcpu="z196" ;;
1032 esac
1033 case "$guess_full" in
1034 s390x-*-*) exact_cpu=${zcpu} ;;
1035 s390-*-*) exact_cpu=${zcpu}esa ;;
1036 esac
1039 esac
1043 # -------------------------------------------------------------------------
1044 # Use an exact cpu, if possible
1046 if test -n "$exact_cpu"; then
1047 echo "$exact_cpu$guess_rest"
1048 else
1049 echo "$guess_full"
1051 exit 0
1055 # Local variables:
1056 # fill-column: 76
1057 # End: