xref: /netbsd-src/external/lgpl3/gmp/dist/config.guess (revision 142fb292a4446268e0f280204e2a6e01a77ae6e6)
1#! /bin/sh
2#
3# GMP config.guess wrapper.
4
5
6# Copyright 2000-2019 Free Software Foundation, Inc.
7#
8#  This file is part of the GNU MP Library.
9#
10#  The GNU MP Library is free software; you can redistribute it and/or modify
11#  it under the terms of either:
12#
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.
16#
17#  or
18#
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.
22#
23#  or both in parallel, as here.
24#
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.
29#
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/.
33
34
35# Usage: config.guess
36#
37# Print the host system CPU-VENDOR-OS.
38#
39# configfsf.guess is run and its guess then sharpened up to take advantage
40# of the finer grained CPU types that GMP knows.
41
42
43# Expect to find configfsf.guess in the same directory as this config.guess
44configfsf_guess="`echo \"$0\" | sed 's/config.guess$/configfsf.guess/'`"
45if test "$configfsf_guess" = "$0"; then
46  echo "Cannot derive configfsf.guess from $0" 1>&2
47  exit 1
48fi
49if test -f "$configfsf_guess"; then
50  :
51else
52  echo "$configfsf_guess not found" 1>&2
53  exit 1
54fi
55
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
58SHELL=${CONFIG_SHELL-/bin/sh}
59
60# Identify ourselves on --version, --help or errors
61if test $# != 0; then
62  echo "(GNU MP wrapped config.guess)"
63  $SHELL $configfsf_guess "$@"
64  exit 1
65fi
66
67guess_full=`$SHELL $configfsf_guess`
68if test $? != 0; then
69  exit 1
70fi
71
72guess_cpu=`echo "$guess_full" | sed 's/-.*$//'`
73guess_rest=`echo "$guess_full" | sed 's/^[^-]*//'`
74exact_cpu=
75
76
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.
81#
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.
86
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.
89#
90
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.
95
96# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
97# use `HOST_CC' if defined, but it is deprecated.
98
99# Portable tmp directory creation inspired by the Autoconf team.
100
101set_cc_for_build='
102trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
103trap "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 ; } ;
109dummy=$tmp/dummy ;
110tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy $dummy.core ${dummy}0.s" ;
111case $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 ;
120	fi
121	;;
122 ,,*)   CC_FOR_BUILD=$CC ;;
123 ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
124esac ; set_cc_for_build= ;'
125
126
127case "$guess_full" in
128
129alpha-*-*)
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.
134  #
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.
137  #
138  cat <<EOF >${dummy}0.s
139	.data
140Lformat:
141	.byte 37,100,45,37,120,10,0	# "%d-%x\n"
142	.text
143	.globl main
144	.align 4
145	.ent main
146main:
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
160EOF
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
172  fi
173  ;;
174
175arm*-*-* | aarch64*-*-*)
176  cpu_code=`sed -n 's/^CPU part.*\(0x.*\)$/\1/p' /proc/cpuinfo 2>/dev/null | sort -r | head -n 1 2>/dev/null`
177  cpu_implementer=`sed -n 's/^CPU implementer.*\(0x.*\)$/\1/p' /proc/cpuinfo 2>/dev/null | head -n 1 2>/dev/null`
178  case "${cpu_implementer}_${cpu_code}" in
179    0x53_0x001) exact_cpu=armexynosm1  ;;
180    0x51_0x800) exact_cpu=armcortexa57 ;;
181    0x43_0x0a1) exact_cpu=armthunderx  ;;
182    0x50_0x000) exact_cpu=armxgene1    ;;
183  esac
184  if test -z "$exact_cpu"; then
185    case "$cpu_code" in
186	0xa10 | 0xa11 | 0xb11)			# v4 strongarm/sa1100
187		exact_cpu="armsa1";;
188	0x915 | 0x925 | \
189	0x920 | 0x922 | 0x940)			# v4
190		exact_cpu="arm9tdmi";;
191	0x210 | 0x290 | 0x2d0 | \
192	0x212 | 0x292 | 0x2d2 | \
193	0x411)	exact_cpu="armxscale";;		# v5 pxa2xx
194	0x926 | 0x946 | 0x966 | 0x968)		# v5te/v5tej
195		exact_cpu="arm9te";;
196	0xa20 | 0xa22 | 0xa26)			# v5te
197		exact_cpu="arm10";;
198	0xb02)	exact_cpu="arm11mpcore";;	# v6
199	0xb36)	exact_cpu="arm1136";;		# v6
200	0xb56)	exact_cpu="arm1156";;		# v6t2
201	0xb76)	exact_cpu="arm1176";;		# v6
202	0xc05)	exact_cpu="armcortexa5";;	# v7a
203	0xc07)	exact_cpu="armcortexa7";;	# v7a
204	0xc08)	exact_cpu="armcortexa8";;	# v7a
205	0xc09)	exact_cpu="armcortexa9";;	# v7a
206	0xc0f)	exact_cpu="armcortexa15";;	# v7a
207	0xc0d)	exact_cpu="armcortexa12";;	# v7a
208	0xc0e)	exact_cpu="armcortexa17";;	# v7a
209	0xc14)	exact_cpu="armcortexr4";;	# v7r
210	0xc15)	exact_cpu="armcortexr5";;	# v7r
211	0xc23)	exact_cpu="armcortexm3";;	# v7m
212
213	0xd04)	exact_cpu="armcortexa35";;	# v8
214	0xd03)	exact_cpu="armcortexa53";;	# v8
215	0xd05)	exact_cpu="armcortexa55";;	# v8.2
216	0xd07)	exact_cpu="armcortexa57";;	# v8
217	0xd08)	exact_cpu="armcortexa72";;	# v8
218	0xd09)	exact_cpu="armcortexa73";;	# v8
219	0xd0a)	exact_cpu="armcortexa75";;	# v8.2
220	0xd0b)	exact_cpu="armcortexa76";;	# v8.3
221	*)	exact_cpu=$guess_cpu;;
222    esac
223  fi
224  exact_cpu="${exact_cpu}`sed -n 's;^Features.*\(neon\).*;\1;p' /proc/cpuinfo 2>/dev/null | head -n 1 2>/dev/null`"
225  ;;
226
227ia64*-*-*)
228  eval $set_cc_for_build
229  # CPUID[3] bits 24 to 31 is the processor family.  itanium2 is documented
230  # as 0x1f, plain itanium has been seen returning 0x07 on two systems, but
231  # haven't found any documentation on it as such.
232  #
233  # Defining both getcpuid and _getcpuid lets us ignore whether the system
234  # expects underscores or not.
235  #
236  # "unsigned long long" is always 64 bits, in fact on hpux in ilp32 mode
237  # (which is the default there), it's the only 64-bit type.
238  #
239  cat >${dummy}0.s <<EOF
240	.text
241	.global	_getcpuid
242	.proc	_getcpuid
243_getcpuid:
244	mov	r8 = CPUID[r32] ;;
245	br.ret.sptk.many rp ;;
246	.endp	_getcpuid
247	.global	getcpuid
248	.proc	getcpuid
249getcpuid:
250	mov	r8 = CPUID[r32] ;;
251	br.ret.sptk.many rp ;;
252	.endp	getcpuid
253EOF
254  cat >$dummy.c <<EOF
255#include <stdio.h>
256unsigned long long getcpuid ();
257int
258main ()
259{
260  if (getcpuid(0LL) == 0x49656E69756E6547LL && getcpuid(1LL) == 0x6C65746ELL)
261    {
262      /* "GenuineIntel" */
263      switch ((getcpuid(3LL) >> 24) & 0xFF) {
264      case 0x07: puts ("itanium");  break;
265      case 0x1F: puts ("itanium2"); break; /* McKinley, Madison */
266      case 0x20: puts ("itanium2"); break; /* Montecito, Montvale, Tukwila */
267      case 0x21: puts ("itanium2"); break; /* Poulson */
268      }
269    }
270  return 0;
271}
272EOF
273  if $CC_FOR_BUILD ${dummy}0.s $dummy.c -o $dummy >/dev/null 2>&1; then
274    exact_cpu=`$dummy`
275  fi
276  ;;
277
278mips-*-irix[6789]*)
279  # IRIX 6 and up always has a 64-bit mips cpu
280  exact_cpu=mips64
281  ;;
282
283mips-*-*)
284  case $(uname -m) in
285    mips64)	exact_cpu=mips64;;
286  esac
287  ;;
288
289mipsel-*-*)
290  case $(uname -m) in
291    mips64)	exact_cpu=mips64el;;
292  esac
293  ;;
294
295m68k-*-*)
296  eval $set_cc_for_build
297  # NetBSD (and presumably other *BSD) "sysctl hw.model" gives for example
298  #   hw.model = Apple Macintosh Quadra 610  (68040)
299  exact_cpu=`(sysctl hw.model) 2>/dev/null | sed -n 's/^.*\(680[012346]0\).*$/m\1/p'`
300  if test -z "$exact_cpu"; then
301    # Linux kernel 2.2 gives for example "CPU: 68020" (tabs in between).
302    exact_cpu=`sed -n 's/^CPU:.*\(680[012346]0\).*$/m\1/p' /proc/cpuinfo 2>/dev/null`
303  fi
304  if test -z "$exact_cpu"; then
305    # Try: movel #0,%d0; rts
306    # This is to check the compiler and our asm code works etc, before
307    # assuming failures below indicate cpu characteristics.
308    # .byte is used to avoid problems with assembler syntax variations.
309    # For testing, provoke failures by adding "illegal" possibly as
310    # ".byte 0x4A, 0xFC"
311    cat >${dummy}0.s <<EOF
312	.text
313	.globl main
314	.globl _main
315main:
316_main:
317	.byte	0x70, 0x00
318	.byte	0x4e, 0x75
319EOF
320
321    if ($CC_FOR_BUILD ${dummy}0.s -o $dummy && $dummy) >/dev/null 2>&1; then
322
323      # $SHELL -c is used to execute $dummy below, since ($dummy)
324      # 2>/dev/null still prints the SIGILL message on some shells.
325      #
326        # Try: movel #0,%d0
327        #      rtd #0
328        cat >${dummy}0.s <<EOF
329	.text
330	.globl main
331	.globl _main
332main:
333_main:
334	.byte	0x70, 0x00
335	.byte	0x4e, 0x74, 0x00, 0x00
336EOF
337        if $CC_FOR_BUILD ${dummy}0.s -o $dummy >/dev/null 2>&1; then
338          $SHELL -c $dummy >/dev/null 2>&1
339	  if test $? != 0; then
340            exact_cpu=m68000    # because rtd didn't work
341          fi
342        fi
343      #
344
345      if test -z "$exact_cpu"; then
346        # Try: trapf
347        #      movel #0,%d0
348        #      rts
349        # Another possibility for identifying 68000 and 68010 is the
350        # different value stored by "movem a0,(a0)+"
351        cat >${dummy}0.s <<EOF
352	.text
353	.globl main
354	.globl _main
355main:
356_main:
357	.byte	0x51, 0xFC
358	.byte	0x70, 0x00
359	.byte	0x4e, 0x75
360EOF
361        if $CC_FOR_BUILD ${dummy}0.s -o $dummy >/dev/null 2>&1; then
362          $SHELL -c $dummy >/dev/null 2>&1
363	  if test $? != 0; then
364            exact_cpu=m68010    # because trapf didn't work
365          fi
366        fi
367      fi
368
369      if test -z "$exact_cpu"; then
370        # Try: bfffo %d1{0:31},%d0
371        #      movel #0,%d0
372        #      rts
373        cat >${dummy}0.s <<EOF
374	.text
375	.globl main
376	.globl _main
377main:
378_main:
379	.byte	0xED, 0xC1, 0x00, 0x1F
380	.byte	0x70, 0x00
381	.byte	0x4e, 0x75
382EOF
383        if $CC_FOR_BUILD ${dummy}0.s -o $dummy >/dev/null 2>&1; then
384          $SHELL -c $dummy >/dev/null 2>&1
385	  if test $? != 0; then
386            exact_cpu=m68360  # cpu32, because bfffo didn't work
387          fi
388        fi
389      fi
390
391      if test -z "$exact_cpu"; then
392        # FIXME: Now we know 68020 or up, but how to detect 030, 040 and 060?
393        exact_cpu=m68020
394      fi
395    fi
396  fi
397  if test -z "$exact_cpu"; then
398    case "$guess_full" in
399      *-*-next* | *-*-openstep*)  # NeXTs are 68020 or better
400        exact_cpu=m68020 ;;
401    esac
402  fi
403  ;;
404
405
406rs6000-*-* | powerpc*-*-*)
407  # Enhancement: On MacOS the "machine" command prints for instance
408  # "ppc750".  Interestingly on powerpc970-apple-darwin6.8.5 it prints
409  # "ppc970" where there's no actual #define for 970 from NXGetLocalArchInfo
410  # (as noted below).  But the man page says the command is still "under
411  # development", so it doesn't seem wise to use it just yet, not while
412  # there's an alternative.
413
414  # Try to read the PVR.  mfpvr is a protected instruction, NetBSD, MacOS and
415  # AIX don't allow it in user mode, but the Linux kernel does.  We prefer this
416  # to /proc/cpuinfo since the latter lags for newer CPUs.
417  #
418  # Note this is no good on AIX, since a C function there is the address of
419  # a function descriptor, not actual code.  But this doesn't matter since
420  # AIX doesn't allow mfpvr anyway.
421  #
422  if test -z "$exact_cpu"; then
423    eval $set_cc_for_build
424    cat >$dummy.c <<\EOF
425#include <stdio.h>
426int
427main ()
428{
429  unsigned  pvr;
430
431  asm ("mfpvr	%0" : "=r" (pvr));
432
433  switch (pvr >> 16) {
434  case 0x0001: puts ("powerpc601");  break;
435  case 0x0003: puts ("powerpc603");  break;
436  case 0x0004: puts ("powerpc604");  break;
437  case 0x0006: puts ("powerpc603e"); break;
438  case 0x0007: puts ("powerpc603e"); break;  /* 603ev */
439  case 0x0008: puts ("powerpc750");  break;
440  case 0x0009: puts ("powerpc604e"); break;
441  case 0x000a: puts ("powerpc604e"); break;  /* 604ev5 */
442  case 0x000c: puts ("powerpc7400"); break;
443  case 0x0041: puts ("powerpc630");  break;
444  case 0x003f: puts ("power7");      break;
445  case 0x004b:
446  case 0x004c:
447  case 0x004d: puts ("power8");      break;
448  case 0x004e: puts ("power9");      break;
449  case 0x0050: puts ("powerpc860");  break;
450  case 0x8000: puts ("powerpc7450"); break;
451  case 0x8001: puts ("powerpc7455"); break;
452  case 0x8002: puts ("powerpc7457"); break;
453  case 0x8003: puts ("powerpc7447"); break; /* really 7447A */
454  case 0x800c: puts ("powerpc7410"); break;
455  }
456  return 0;
457}
458EOF
459    if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
460      # This style construct is needed on AIX 4.3 to suppress the SIGILL error
461      # from (*fun)().  Using $SHELL -c $dummy 2>/dev/null doesn't work.
462      { x=`$dummy`; } 2>/dev/null
463      if test -n "$x"; then
464	exact_cpu=$x
465      fi
466    fi
467  fi
468
469
470  # Grep the /proc/cpuinfo pseudo-file.
471  # Anything unrecognised is ignored, since of course we mustn't spit out
472  # a cpu type config.sub doesn't know.
473  if test -z "$exact_cpu" && test -f /proc/cpuinfo; then
474    x=`grep "^cpu[ 	]" /proc/cpuinfo | head -n 1`
475    x=`echo $x | sed -n 's/^cpu[ 	]*:[ 	]*\([A-Za-z0-9]*\).*/\1/p'`
476    x=`echo $x | sed 's/PPC//'`
477    case $x in
478      601)     exact_cpu="power" ;;
479      603ev)   exact_cpu="powerpc603e" ;;
480      604ev5)  exact_cpu="powerpc604e" ;;
481      970??)   exact_cpu="powerpc970" ;;
482      603 | 603e | 604 | 604e | 750 | 821 | 860)
483        exact_cpu="powerpc$x" ;;
484      POWER[4-9]*)
485        exact_cpu=`echo $x | sed -e "s;POWER;power;" -e "s;[a-zA-Z]*$;;"` ;;
486    esac
487  fi
488
489
490  if test -z "$exact_cpu"; then
491    # On AIX, try looking at _system_configuration.  This is present in
492    # version 4 at least.
493    cat >$dummy.c <<EOF
494#include <stdio.h>
495#include <sys/systemcfg.h>
496int
497main ()
498{
499  switch (_system_configuration.implementation) {
500  /* Old versions of AIX don't have all these constants,
501     use ifdef for safety. */
502#ifdef POWER_RS2
503  case POWER_RS2:    puts ("power2");     break;
504#endif
505#ifdef POWER_601
506  case POWER_601:    puts ("power");      break;
507#endif
508#ifdef POWER_603
509  case POWER_603:    puts ("powerpc603"); break;
510#endif
511#ifdef POWER_604
512  case POWER_604:    puts ("powerpc604"); break;
513#endif
514#ifdef POWER_620
515  case POWER_620:    puts ("powerpc620"); break;
516#endif
517#ifdef POWER_630
518  case POWER_630:    puts ("powerpc630"); break;
519#endif
520  /* Dunno what this is, leave it out for now.
521  case POWER_A35:    puts ("powerpca35"); break;
522  */
523  /* This is waiting for a bit more info.
524  case POWER_RS64II: puts ("powerpcrs64ii"); break;
525  */
526#ifdef POWER_4
527  case POWER_4:    puts ("power4"); break;
528#endif
529#ifdef POWER_5
530  case POWER_5:    puts ("power5"); break;
531#endif
532#ifdef POWER_6
533  case POWER_6:    puts ("power6"); break;
534#endif
535#ifdef POWER_7
536  case POWER_7:    puts ("power7"); break;
537#endif
538#ifdef POWER_8
539  case POWER_8:    puts ("power8"); break;
540#endif
541#ifdef POWER_9
542  case POWER_9:    puts ("power9"); break;
543#endif
544  default:
545    if (_system_configuration.architecture == POWER_RS)
546      puts ("power");
547    else if (_system_configuration.width == 64)
548      puts ("powerpc64");
549  }
550  return 0;
551}
552EOF
553    if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
554      x=`$dummy`
555      if test -n "$x"; then
556        exact_cpu=$x
557      fi
558    fi
559  fi
560
561  if test -z "$exact_cpu"; then
562    # On MacOS X (or any Mach-O presumably), NXGetLocalArchInfo cpusubtype
563    # can tell us the exact cpu.
564    cat >$dummy.c <<EOF
565#include <stdio.h>
566#include <mach-o/arch.h>
567int
568main (void)
569{
570  const NXArchInfo *a = NXGetLocalArchInfo();
571  if (a->cputype == CPU_TYPE_POWERPC)
572    {
573      switch (a->cpusubtype) {
574      /* The following known to Darwin 1.3. */
575      case CPU_SUBTYPE_POWERPC_601:   puts ("powerpc601");  break;
576      case CPU_SUBTYPE_POWERPC_602:   puts ("powerpc602");  break;
577      case CPU_SUBTYPE_POWERPC_603:   puts ("powerpc603");  break;
578      case CPU_SUBTYPE_POWERPC_603e:  puts ("powerpc603e"); break;
579      case CPU_SUBTYPE_POWERPC_603ev: puts ("powerpc603e"); break;
580      case CPU_SUBTYPE_POWERPC_604:   puts ("powerpc604");  break;
581      case CPU_SUBTYPE_POWERPC_604e:  puts ("powerpc604e"); break;
582      case CPU_SUBTYPE_POWERPC_620:   puts ("powerpc620");  break;
583      case CPU_SUBTYPE_POWERPC_750:   puts ("powerpc750");  break;
584      case CPU_SUBTYPE_POWERPC_7400:  puts ("powerpc7400"); break;
585      case CPU_SUBTYPE_POWERPC_7450:  puts ("powerpc7450"); break;
586      /* Darwin 6.8.5 doesn't define the following */
587      case 0x8001:                    puts ("powerpc7455"); break;
588      case 0x8002:                    puts ("powerpc7457"); break;
589      case 0x8003:                    puts ("powerpc7447"); break;
590      case 100:                       puts ("powerpc970");  break;
591      }
592    }
593  return 0;
594}
595EOF
596    if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
597      x=`$dummy`
598      if test -n "$x"; then
599        exact_cpu=$x
600      fi
601    fi
602  fi
603  ;;
604
605sparc-*-* | sparc64-*-*)
606  # If we can recognise an actual v7 then $exact_cpu is set to "sparc" so as
607  # to short-circuit subsequent tests.
608
609  # Grep the linux kernel /proc/cpuinfo pseudo-file.
610  # A typical line is "cpu\t\t: TI UltraSparc II  (BlackBird)"
611  # See arch/sparc/kernel/cpu.c and arch/sparc64/kernel/cpu.c.
612  #
613  if test -f /proc/cpuinfo; then
614    if grep 'cpu.*Cypress' /proc/cpuinfo >/dev/null; then
615      exact_cpu="sparc"   # ie. v7
616    elif grep 'cpu.*Power-UP' /proc/cpuinfo >/dev/null; then
617      exact_cpu="sparc"   # ie. v7
618    elif grep 'cpu.*HyperSparc' /proc/cpuinfo >/dev/null; then
619      exact_cpu="sparcv8"
620    elif grep 'cpu.*SuperSparc' /proc/cpuinfo >/dev/null; then
621      exact_cpu="supersparc"
622    elif grep 'cpu.*MicroSparc' /proc/cpuinfo >/dev/null; then
623      exact_cpu="microsparc"
624    elif grep 'cpu.*MB86904' /proc/cpuinfo >/dev/null; then
625      # actually MicroSPARC-II
626      exact_cpu=microsparc
627    elif grep 'cpu.*UltraSparc T5' /proc/cpuinfo >/dev/null; then
628      exact_cpu="ultrasparct5"
629    elif grep 'cpu.*UltraSparc T4' /proc/cpuinfo >/dev/null; then
630      exact_cpu="ultrasparct4"
631    elif grep 'cpu.*UltraSparc T3' /proc/cpuinfo >/dev/null; then
632      exact_cpu="ultrasparct3"
633    elif grep 'cpu.*UltraSparc T2' /proc/cpuinfo >/dev/null; then
634      exact_cpu="ultrasparct2"
635    elif grep 'cpu.*UltraSparc T1' /proc/cpuinfo >/dev/null; then
636      exact_cpu="ultrasparct1"
637    elif grep 'cpu.*UltraSparc III' /proc/cpuinfo >/dev/null; then
638      exact_cpu="ultrasparc3"
639    elif grep 'cpu.*UltraSparc IIi' /proc/cpuinfo >/dev/null; then
640      exact_cpu="ultrasparc2i"
641    elif grep 'cpu.*UltraSparc II' /proc/cpuinfo >/dev/null; then
642      exact_cpu="ultrasparc2"
643    elif grep 'cpu.*UltraSparc' /proc/cpuinfo >/dev/null; then
644      exact_cpu="ultrasparc"
645    fi
646  fi
647
648  # Need to invoke this for setup of $dummy
649  eval $set_cc_for_build
650
651  # Grep the output from sysinfo on SunOS.
652  # sysinfo has been seen living in /bin or in /usr/kvm
653  #	cpu0 is a "SuperSPARC Model 41 SPARCmodule" CPU
654  #	cpu0 is a "75 MHz TI,TMS390Z55" CPU
655  #
656  if test -z "$exact_cpu"; then
657    for i in sysinfo /usr/kvm/sysinfo; do
658      if $SHELL -c $i 2>/dev/null >$dummy; then
659        if grep 'cpu0 is a "SuperSPARC' $dummy >/dev/null; then
660          exact_cpu=supersparc
661          break
662        elif grep 'cpu0 is a .*TMS390Z5.' $dummy >/dev/null; then
663          # TMS390Z50 and TMS390Z55
664          exact_cpu=supersparc
665          break
666        fi
667      fi
668    done
669  fi
670
671  # Grep the output from prtconf on Solaris.
672  # Use an explicit /usr/sbin, since that directory might not be in a normal
673  # user's path.
674  #
675  #     SUNW,UltraSPARC (driver not attached)
676  #     SUNW,UltraSPARC-II (driver not attached)
677  #     SUNW,UltraSPARC-IIi (driver not attached)
678  #     SUNW,UltraSPARC-III+ (driver not attached)
679  #     Ross,RT625 (driver not attached)
680  #     TI,TMS390Z50 (driver not attached)
681  #
682  # /usr/sbin/sysdef prints similar information, but includes all loadable
683  # cpu modules, not just the real cpu.
684  #
685  # We first try a plain prtconf, since that is known to work on older systems.
686  # But for newer T1 systems, that doesn't produce any useful output, we need
687  # "prtconf -vp" there.
688  #
689  for prtconfopt in "" "-vp"; do
690    if test -z "$exact_cpu"; then
691      if $SHELL -c "/usr/sbin/prtconf $prtconfopt" 2>/dev/null >$dummy; then
692	if grep 'SUNW,UltraSPARC-T5' $dummy >/dev/null; then
693	  exact_cpu=ultrasparct5
694	elif grep 'SUNW,UltraSPARC-T4' $dummy >/dev/null; then
695	  exact_cpu=ultrasparct4
696	elif grep 'SUNW,UltraSPARC-T3' $dummy >/dev/null; then
697	  exact_cpu=ultrasparct3
698	elif grep 'SUNW,UltraSPARC-T2' $dummy >/dev/null; then
699	  exact_cpu=ultrasparct2
700	elif grep 'SUNW,UltraSPARC-T1' $dummy >/dev/null; then
701	  exact_cpu=ultrasparct1
702	elif grep 'SUNW,UltraSPARC-III' $dummy >/dev/null; then
703	  exact_cpu=ultrasparc3
704	elif grep 'SUNW,UltraSPARC-IIi' $dummy >/dev/null; then
705	  exact_cpu=ultrasparc2i
706	elif grep 'SUNW,UltraSPARC-II' $dummy >/dev/null; then
707	  exact_cpu=ultrasparc2
708	elif egrep '(SUNW|ORCL),(Ultra)?SPARC' $dummy >/dev/null; then
709	  exact_cpu=ultrasparc
710	elif grep 'Ross,RT62.' $dummy >/dev/null; then
711	  # RT620, RT625, RT626 hypersparcs (v8).
712	  exact_cpu=sparcv8
713	elif grep 'TI,TMS390Z5.' $dummy >/dev/null; then
714	  # TMS390Z50 and TMS390Z55
715	  exact_cpu=supersparc
716	elif grep 'TI,TMS390S10' $dummy >/dev/null; then
717	  exact_cpu=microsparc
718	elif grep 'FMI,MB86904' $dummy >/dev/null; then
719	  # actually MicroSPARC-II
720	  exact_cpu=microsparc
721	fi
722      fi
723    fi
724  done
725
726  # Grep the output from sysctl hw.model on sparc or sparc64 *BSD.
727  # Use an explicit /sbin, since that directory might not be in a normal
728  # user's path.  Example outputs,
729  #
730  #     hw.model: Sun Microsystems UltraSparc-IIi
731  #
732  if test -z "$exact_cpu"; then
733    if $SHELL -c "/sbin/sysctl hw.model" 2>/dev/null >$dummy; then
734      if grep -i 'UltraSparc-T5' $dummy >/dev/null; then
735        exact_cpu=ultrasparct5
736      elif grep -i 'UltraSparc-T4' $dummy >/dev/null; then
737        exact_cpu=ultrasparct4
738      elif grep -i 'UltraSparc-T3' $dummy >/dev/null; then
739        exact_cpu=ultrasparct3
740      elif grep -i 'UltraSparc-T2' $dummy >/dev/null; then
741        exact_cpu=ultrasparct2
742      elif grep -i 'UltraSparc-T1' $dummy >/dev/null; then
743        exact_cpu=ultrasparct1
744      elif grep -i 'UltraSparc-III' $dummy >/dev/null; then
745        exact_cpu=ultrasparc3
746      elif grep -i 'UltraSparc-IIi' $dummy >/dev/null; then
747        exact_cpu=ultrasparc2i
748      elif grep -i 'UltraSparc-II' $dummy >/dev/null; then
749        exact_cpu=ultrasparc2
750      elif grep -i 'UltraSparc' $dummy >/dev/null; then
751        exact_cpu=ultrasparc
752      elif grep 'TMS390Z5.' $dummy >/dev/null; then
753        # TMS390Z50 and TMS390Z55
754        exact_cpu=supersparc
755      elif grep 'TMS390S10' $dummy >/dev/null; then
756        exact_cpu=microsparc
757      elif grep 'MB86904' $dummy >/dev/null; then
758        # actually MicroSPARC-II
759        exact_cpu=microsparc
760      elif grep 'MB86907' $dummy >/dev/null; then
761        exact_cpu=turbosparc
762      fi
763    fi
764  fi
765
766  # sun4m and sun4d are v8s of some sort, sun4u is a v9 of some sort
767  #
768  if test -z "$exact_cpu"; then
769    case `uname -m` in
770      sun4[md]) exact_cpu=sparcv8 ;;
771      sun4u)    exact_cpu=sparcv9 ;;
772    esac
773  fi
774  ;;
775
776
777# Recognise x86 processors using a tricky cpuid with 4 arguments, repeating
778# arguments; for x86-64 we effectively pass the 1st in rdx and the 2nd in rcx.
779# This allows the same asm to work for both standard and Windoze calling
780# conventions.
781
782i?86-*-* | amd64-*-* | x86_64-*-*)
783  eval $set_cc_for_build
784
785  cat <<EOF >$dummy.c
786#include <string.h>
787#include <stdio.h>
788#define CPUID(a,b) cpuid(b,a,a,b)
789#if __cplusplus
790extern "C"
791#endif
792unsigned int cpuid (int, char *, char *, int);
793
794int
795gmp_workaround_skylake_cpuid_bug ()
796{
797  char feature_string[49];
798  char processor_name_string[49];
799  static const char *bad_cpus[] = {" G44", " G45", " G39" /* , "6600" */ };
800  int i;
801
802  /* Example strings:                                   */
803  /* "Intel(R) Pentium(R) CPU G4400 @ 3.30GHz"          */
804  /* "Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz"         */
805  /*                  ^               ^               ^ */
806  /*     0x80000002       0x80000003      0x80000004    */
807  /* We match out just the 0x80000003 part here. */
808
809  /* In their infinitive wisdom, Intel decided to use one register order for
810     the vendor string, and another for the processor name string.  We shuffle
811     things about here, rather than write a new variant of our assembly cpuid.
812  */
813
814  unsigned int eax, ebx, ecx, edx;
815  eax = CPUID (feature_string, 0x80000003);
816  ebx = ((unsigned int *)feature_string)[0];
817  edx = ((unsigned int *)feature_string)[1];
818  ecx = ((unsigned int *)feature_string)[2];
819
820  ((unsigned int *) (processor_name_string))[0] = eax;
821  ((unsigned int *) (processor_name_string))[1] = ebx;
822  ((unsigned int *) (processor_name_string))[2] = ecx;
823  ((unsigned int *) (processor_name_string))[3] = edx;
824
825  processor_name_string[16] = 0;
826
827  for (i = 0; i < sizeof (bad_cpus) / sizeof (char *); i++)
828    {
829      if (strstr (processor_name_string, bad_cpus[i]) != 0)
830	return 1;
831    }
832  return 0;
833}
834
835int
836main ()
837{
838  char vendor_string[13];
839  char feature_string[12];
840  long fms;
841  int family, model;
842  const char *modelstr, *suffix;
843  int cpu_64bit = 0, cpu_avx = 0;
844  int cpuid_64bit, cpuid_avx, cpuid_osxsave;
845
846  CPUID (vendor_string, 0);
847  vendor_string[12] = 0;
848
849  fms = CPUID (feature_string, 1);
850
851  family = ((fms >> 8) & 0xf) + ((fms >> 20) & 0xff);
852  model = ((fms >> 4) & 0xf) + ((fms >> 12) & 0xf0);
853
854  cpuid_avx     = (feature_string[11] >> 4) & 1;
855  cpuid_osxsave = (feature_string[11] >> 3) & 1;
856
857  modelstr = "$guess_cpu";
858
859  /**************************************************/
860  /*** WARNING: keep this list in sync with fat.c ***/
861  /**************************************************/
862  if (strcmp (vendor_string, "GenuineIntel") == 0)
863    {
864      switch (family)
865	{
866	case 5:
867          if (model == 4 || model == 8)               modelstr = "pentiummmx";
868	  else                                        modelstr = "pentium";
869	  break;
870	case 6:
871          if (model <= 1)                                   modelstr = "pentiumpro";
872          else if (model <= 6)                              modelstr = "pentium2";
873          else if (model <= 8)                              modelstr = "pentium3";
874          else if (model <= 9)                              modelstr = "pentiumm";
875          else if (model <= 0x0c)                           modelstr = "pentium3";
876          else if (model <= 0x0e)                           modelstr = "pentiumm";
877          else if (model <= 0x19) cpu_64bit = 1,            modelstr = "core2";
878          else if (model == 0x1a) cpu_64bit = 1,            modelstr = "nehalem";    /* NHM Gainestown */
879          else if (model == 0x1c) cpu_64bit = 1,            modelstr = "atom";       /* Silverthorne */
880          else if (model == 0x1d) cpu_64bit = 1,            modelstr = "core2";      /* PNR Dunnington */
881          else if (model == 0x1e) cpu_64bit = 1,            modelstr = "nehalem";    /* NHM Lynnfield/Jasper */
882          else if (model == 0x25) cpu_64bit = 1,            modelstr = "westmere";   /* WSM Clarkdale/Arrandale */
883          else if (model == 0x26) cpu_64bit = 1,            modelstr = "atom";       /* Lincroft */
884          else if (model == 0x27) cpu_64bit = 1,            modelstr = "atom";       /* Saltwell */
885          else if (model == 0x2a) cpu_64bit = 1, cpu_avx=1, modelstr = "sandybridge";/* SB */
886          else if (model == 0x2c) cpu_64bit = 1,            modelstr = "westmere";   /* WSM Gulftown */
887          else if (model == 0x2d) cpu_64bit = 1, cpu_avx=1, modelstr = "sandybridge";/* SBC-EP */
888          else if (model == 0x2e) cpu_64bit = 1,            modelstr = "nehalem";    /* NHM Beckton */
889          else if (model == 0x2f) cpu_64bit = 1,            modelstr = "westmere";   /* WSM Eagleton */
890          else if (model == 0x36) cpu_64bit = 1,            modelstr = "atom";       /* Cedarview/Saltwell */
891          else if (model == 0x37) cpu_64bit = 1,            modelstr = "silvermont"; /* Silvermont */
892          else if (model == 0x3a) cpu_64bit = 1, cpu_avx=1, modelstr = "ivybridge";  /* IBR */
893          else if (model == 0x3c) cpu_64bit = 1, cpu_avx=1, modelstr = "haswell";    /* Haswell client */
894          else if (model == 0x3d) cpu_64bit = 1, cpu_avx=1, modelstr = "broadwell";  /* Broadwell */
895          else if (model == 0x3e) cpu_64bit = 1, cpu_avx=1, modelstr = "ivybridge";  /* Ivytown */
896          else if (model == 0x3f) cpu_64bit = 1, cpu_avx=1, modelstr = "haswell";    /* Haswell server */
897          else if (model == 0x45) cpu_64bit = 1, cpu_avx=1, modelstr = "haswell";    /* Haswell ULT */
898          else if (model == 0x46) cpu_64bit = 1, cpu_avx=1, modelstr = "haswell";    /* Crystal Well */
899          else if (model == 0x47) cpu_64bit = 1, cpu_avx=1, modelstr = "broadwell";  /* Broadwell */
900          else if (model == 0x4a) cpu_64bit = 1,            modelstr = "silvermont"; /* Silvermont */
901          else if (model == 0x4c) cpu_64bit = 1,            modelstr = "silvermont"; /* Airmont */
902          else if (model == 0x4d) cpu_64bit = 1,            modelstr = "silvermont"; /* Silvermont/Avoton */
903          else if (model == 0x4e) cpu_64bit = 1, cpu_avx=1, modelstr = "skylake";    /* Skylake client */
904          else if (model == 0x4f) cpu_64bit = 1, cpu_avx=1, modelstr = "broadwell";  /* Broadwell server */
905          else if (model == 0x55) cpu_64bit = 1, cpu_avx=1, modelstr = "skylake";    /* Skylake server */
906          else if (model == 0x56) cpu_64bit = 1, cpu_avx=1, modelstr = "broadwell";  /* Broadwell microserver */
907          else if (model == 0x57) cpu_64bit = 1,            modelstr = "knightslanding"; /* aka Xeon Phi */
908          else if (model == 0x5a) cpu_64bit = 1,            modelstr = "silvermont"; /* Silvermont */
909          else if (model == 0x5c) cpu_64bit = 1,            modelstr = "goldmont";   /* Goldmont */
910          else if (model == 0x5e) cpu_64bit = 1, cpu_avx=1, modelstr = "skylake";    /* Skylake */
911          else if (model == 0x5f) cpu_64bit = 1,            modelstr = "goldmont";   /* Goldmont */
912          else if (model == 0x7a) cpu_64bit = 1,            modelstr = "goldmont";   /* Goldmont Plus */
913          else if (model == 0x8e) cpu_64bit = 1, cpu_avx=1, modelstr = "kabylake";   /* Kabylake Y/U */
914          else if (model == 0x9e) cpu_64bit = 1, cpu_avx=1, modelstr = "kabylake";   /* Kabylake desktop */
915          else                    cpu_64bit = 1,            modelstr = "nehalem";    /* default */
916
917	  if (strcmp (modelstr, "haswell") == 0 ||
918	      strcmp (modelstr, "broadwell") == 0 ||
919	      strcmp (modelstr, "skylake") == 0)
920	    {
921	      /* Some haswell, broadwell, skylake lack BMI2.  Let them appear
922		 as sandybridge for now.  */
923	      CPUID (feature_string, 7);
924	      if ((feature_string[0 + 8 / 8] & (1 << (8 % 8))) == 0
925		  || gmp_workaround_skylake_cpuid_bug ())
926		modelstr = "sandybridge";
927	    }
928
929	  break;
930	case 15:
931	  cpu_64bit = 1, modelstr = "pentium4";
932	  break;
933	}
934    }
935  else if (strcmp (vendor_string, "AuthenticAMD") == 0)
936    {
937      switch (family)
938	{
939	case 5:
940	  if (model <= 3)	modelstr = "k5";
941	  else if (model <= 7)	modelstr = "k6";
942	  else if (model == 8)	modelstr = "k62";
943	  else if (model == 9)	modelstr = "k63";
944	  else if (model == 10) modelstr = "geode";
945	  else if (model == 13) modelstr = "k63";
946	  break;
947	case 6:
948	  modelstr = "athlon";
949	  break;
950	case 15:		/* K8, K9 */
951	  cpu_64bit = 1, modelstr = "k8";
952	  break;
953	case 16:		/* K10 */
954	  cpu_64bit = 1, modelstr = "k10";
955	  break;
956	case 17:		/* Hybrid k8/k10, claim k8 */
957	  cpu_64bit = 1, modelstr = "k8";
958	  break;
959	case 18:		/* Llano, uses K10 core */
960	  cpu_64bit = 1, modelstr = "k10";
961	  break;
962	case 19:		/* AMD Internal, assume future K10 */
963	  cpu_64bit = 1, modelstr = "k10";
964	  break;
965	case 20:		/* Bobcat */
966	  cpu_64bit = 1, modelstr = "bobcat";
967	  break;
968	case 21:		/* Bulldozer */
969	  cpu_64bit = 1, cpu_avx = 1;
970	  if (model <= 1)
971	    modelstr = "bulldozer";
972	  else if (model < 0x20)	/* really 2, [0x10-0x20) */
973	    modelstr = "piledriver";
974	  else if (model < 0x40)	/* really [0x30-0x40) */
975	    modelstr = "steamroller";
976	  else				/* really [0x60-0x70) */
977	    modelstr = "excavator";
978	  break;
979	case 22:		/* Jaguar, an improved bobcat */
980	  cpu_64bit = 1, cpu_avx = 1, modelstr = "jaguar";
981	  break;
982	case 23:		/* Zen */
983	  cpu_64bit = 1, cpu_avx = 1;
984	  switch (model)
985	    {
986	    case 1:
987	    case 8:
988	    case 17:
989	    case 24:
990	      modelstr = "zen";
991	      break;
992	    default:
993	      modelstr = "zen2";
994	      break;
995	    }
996	  break;
997	case 25:		/* Zen 3 */
998	  cpu_64bit = 1, cpu_avx = 1;
999	  modelstr = "zen3";
1000	  break;
1001	}
1002    }
1003  else if (strcmp (vendor_string, "HygonGenuine") == 0)
1004    {
1005      cpu_64bit = 1, cpu_avx = 1;
1006      modelstr = "zen";
1007    }
1008  else if (strcmp (vendor_string, "CyrixInstead") == 0)
1009    {
1010      /* Should recognize Cyrix' processors too.  */
1011    }
1012  else if (strcmp (vendor_string, "CentaurHauls") == 0)
1013    {
1014      switch (family)
1015	{
1016	case 6:
1017	  if (model < 9)	modelstr = "viac3";
1018	  else if (model < 15)	modelstr = "viac32";
1019	  else			cpu_64bit = 1, modelstr = "nano";
1020	  break;
1021	}
1022    }
1023
1024  CPUID (feature_string, 0x80000001);
1025  cpuid_64bit = (feature_string[7] >> 5) & 1;
1026
1027  suffix = "";
1028
1029  if (cpuid_64bit && ! cpu_64bit)
1030    /* If our cpuid-based CPU identification thinks this is a 32-bit CPU but
1031       cpuid claims AMD64 capabilities, then revert to the generic "x86_64".
1032       This is of course wrong, but it can happen in some virtualisers and
1033       emulators, and this workaround allows for successful 64-bit builds.  */
1034    modelstr = "x86_64";
1035  else if (cpu_avx && ! (cpuid_avx && cpuid_osxsave))
1036    /* For CPUs nominally capable of executing AVX, append "noavx" when not
1037       both the AVX and OSXSAVE cpuid bits are set.  We tolerate weirdness
1038       here, as some virtualisers set a broken cpuid state, while other
1039       virtualisers allow guests to set a broken state.  */
1040    suffix = "noavx";
1041
1042  printf ("%s%s", modelstr, suffix);
1043  return 0;
1044}
1045EOF
1046
1047# The rcx/ecx zeroing here and in the variant below is needed for the BMI2
1048# check.
1049
1050  cat <<EOF >${dummy}0.s
1051	.globl cpuid
1052	.globl _cpuid
1053cpuid:
1054_cpuid:
1055	push	%rbx
1056	mov	%rdx, %r8
1057	mov	%ecx, %eax
1058	xor	%ecx, %ecx
1059	.byte	0x0f
1060	.byte	0xa2
1061	mov	%ebx, (%r8)
1062	mov	%edx, 4(%r8)
1063	mov	%ecx, 8(%r8)
1064	pop	%rbx
1065	ret
1066EOF
1067
1068  if ($CC_FOR_BUILD ${dummy}0.s $dummy.c -o $dummy) >/dev/null 2>&1; then
1069    # On 80386 and early 80486 cpuid is not available and will result in a
1070    # SIGILL message, hence 2>/dev/null.
1071    #
1072    # On i386-unknown-freebsd4.9, "/bin/sh -c ./dummy" seems to send an
1073    # "Illegal instruction (core dumped)" message to stdout, so we test $?
1074    # to check if the program run was successful.
1075    #
1076    x=`$SHELL -c $dummy 2>/dev/null`
1077    if test $? = 0 && test -n "$x"; then
1078      exact_cpu=$x
1079    fi
1080  fi
1081
1082  cat <<EOF >${dummy}0.s
1083	.globl cpuid
1084	.globl _cpuid
1085cpuid:
1086_cpuid:
1087	pushl %esi
1088	pushl %ebx
1089	movl 24(%esp),%eax
1090	xor	%ecx, %ecx
1091	.byte 0x0f
1092	.byte 0xa2
1093	movl 20(%esp),%esi
1094	movl %ebx,(%esi)
1095	movl %edx,4(%esi)
1096	movl %ecx,8(%esi)
1097	popl %ebx
1098	popl %esi
1099	ret
1100EOF
1101
1102  if test -z "$exact_cpu"; then
1103  if ($CC_FOR_BUILD ${dummy}0.s $dummy.c -o $dummy) >/dev/null 2>&1; then
1104    # On 80386 and early 80486 cpuid is not available and will result in a
1105    # SIGILL message, hence 2>/dev/null.
1106    #
1107    # On i386-unknown-freebsd4.9, "/bin/sh -c ./dummy" seems to send an
1108    # "Illegal instruction (core dumped)" message to stdout, so we test $?
1109    # to check if the program run was successful.
1110    #
1111    x=`$SHELL -c $dummy 2>/dev/null`
1112    if test $? = 0 && test -n "$x"; then
1113      exact_cpu=$x
1114    fi
1115  fi
1116  fi
1117
1118  # We need to remove some .o files here since lame C compilers
1119  # generate these even when not asked.
1120  ;;
1121
1122s390*-*-*)
1123  if test -f /proc/cpuinfo; then
1124    model=`grep "^processor 0: version =" /proc/cpuinfo | sed -e 's/.*machine = //'`
1125    case $model in
1126      2064 | 2066) zcpu="z900" ;;
1127      2084 | 2086) zcpu="z990" ;;
1128      2094 | 2096) zcpu="z9"   ;;
1129      2097 | 2098) zcpu="z10"  ;;
1130      2817 | 2818 | *) zcpu="z196" ;;
1131    esac
1132    case "$guess_full" in
1133      s390x-*-*) exact_cpu=${zcpu}    ;;
1134      s390-*-*)  exact_cpu=${zcpu}esa ;;
1135    esac
1136  fi
1137  ;;
1138
1139esac
1140
1141
1142
1143# -------------------------------------------------------------------------
1144# Use an exact cpu, if possible
1145
1146if test -n "$exact_cpu"; then
1147  echo "$exact_cpu$guess_rest"
1148else
1149  echo "$guess_full"
1150fi
1151exit 0
1152
1153
1154
1155# Local variables:
1156# fill-column: 76
1157# End:
1158