Blame config.guess

Packit 5c3484
#! /bin/sh
Packit 5c3484
#
Packit 5c3484
# GMP config.guess wrapper.
Packit 5c3484
Packit 5c3484
Packit 5c3484
# Copyright 2000-2006, 2008, 2011-2016 Free Software Foundation, Inc.
Packit 5c3484
#
Packit 5c3484
#  This file is part of the GNU MP Library.
Packit 5c3484
#
Packit 5c3484
#  The GNU MP Library is free software; you can redistribute it and/or modify
Packit 5c3484
#  it under the terms of either:
Packit 5c3484
#
Packit 5c3484
#    * the GNU Lesser General Public License as published by the Free
Packit 5c3484
#      Software Foundation; either version 3 of the License, or (at your
Packit 5c3484
#      option) any later version.
Packit 5c3484
#
Packit 5c3484
#  or
Packit 5c3484
#
Packit 5c3484
#    * the GNU General Public License as published by the Free Software
Packit 5c3484
#      Foundation; either version 2 of the License, or (at your option) any
Packit 5c3484
#      later version.
Packit 5c3484
#
Packit 5c3484
#  or both in parallel, as here.
Packit 5c3484
#
Packit 5c3484
#  The GNU MP Library is distributed in the hope that it will be useful, but
Packit 5c3484
#  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
Packit 5c3484
#  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
Packit 5c3484
#  for more details.
Packit 5c3484
#
Packit 5c3484
#  You should have received copies of the GNU General Public License and the
Packit 5c3484
#  GNU Lesser General Public License along with the GNU MP Library.  If not,
Packit 5c3484
#  see https://www.gnu.org/licenses/.
Packit 5c3484
Packit 5c3484
Packit 5c3484
# Usage: config.guess
Packit 5c3484
#
Packit 5c3484
# Print the host system CPU-VENDOR-OS.
Packit 5c3484
#
Packit 5c3484
# configfsf.guess is run and its guess then sharpened up to take advantage
Packit 5c3484
# of the finer grained CPU types that GMP knows.
Packit 5c3484
Packit 5c3484
Packit 5c3484
# Expect to find configfsf.guess in the same directory as this config.guess
Packit 5c3484
configfsf_guess="`echo \"$0\" | sed 's/config.guess$/configfsf.guess/'`"
Packit 5c3484
if test "$configfsf_guess" = "$0"; then
Packit 5c3484
  echo "Cannot derive configfsf.guess from $0" 1>&2
Packit 5c3484
  exit 1
Packit 5c3484
fi
Packit 5c3484
if test -f "$configfsf_guess"; then
Packit 5c3484
  :
Packit 5c3484
else
Packit 5c3484
  echo "$configfsf_guess not found" 1>&2
Packit 5c3484
  exit 1
Packit 5c3484
fi
Packit 5c3484
Packit 5c3484
# Setup a $SHELL with which to run configfsf.guess, using the same
Packit 5c3484
# $CONFIG_SHELL or /bin/sh as autoconf does when running config.guess
Packit 5c3484
SHELL=${CONFIG_SHELL-/bin/sh}
Packit 5c3484
Packit 5c3484
# Identify ourselves on --version, --help or errors
Packit 5c3484
if test $# != 0; then
Packit 5c3484
  echo "(GNU MP wrapped config.guess)"
Packit 5c3484
  $SHELL $configfsf_guess "$@"
Packit 5c3484
  exit 1
Packit 5c3484
fi
Packit 5c3484
Packit 5c3484
guess_full=`$SHELL $configfsf_guess`
Packit 5c3484
if test $? != 0; then
Packit 5c3484
  exit 1
Packit 5c3484
fi
Packit 5c3484
Packit 5c3484
guess_cpu=`echo "$guess_full" | sed 's/-.*$//'`
Packit 5c3484
guess_rest=`echo "$guess_full" | sed 's/^[^-]*//'`
Packit 5c3484
exact_cpu=
Packit 5c3484
Packit 5c3484
Packit 5c3484
# -------------------------------------------------------------------------
Packit 5c3484
# The following should look at the current guess and probe the system to
Packit 5c3484
# establish a better guess in exact_cpu.  Leave exact_cpu empty if probes
Packit 5c3484
# can't be done, or don't work.
Packit 5c3484
#
Packit 5c3484
# When a number of probes are done, test -z "$exact_cpu" can be used instead
Packit 5c3484
# of putting each probe under an "else" of the preceeding.  That can stop
Packit 5c3484
# the code getting horribly nested and marching off the right side of the
Packit 5c3484
# screen.
Packit 5c3484
Packit 5c3484
# Note that when a compile-and-link is done in one step we need to remove .o
Packit 5c3484
# files, since lame C compilers generate these even when not asked.
Packit 5c3484
#
Packit 5c3484
Packit 5c3484
# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
Packit 5c3484
# compiler to aid in system detection is discouraged as it requires
Packit 5c3484
# temporary files to be created and, as you can see below, it is a
Packit 5c3484
# headache to deal with in a portable fashion.
Packit 5c3484
Packit 5c3484
# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
Packit 5c3484
# use `HOST_CC' if defined, but it is deprecated.
Packit 5c3484
Packit 5c3484
# Portable tmp directory creation inspired by the Autoconf team.
Packit 5c3484
Packit 5c3484
set_cc_for_build='
Packit 5c3484
trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
Packit 5c3484
trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
Packit 5c3484
: ${TMPDIR=/tmp} ;
Packit 5c3484
 { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
Packit 5c3484
 { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
Packit 5c3484
 { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
Packit 5c3484
 { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
Packit 5c3484
dummy=$tmp/dummy ;
Packit 5c3484
tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy $dummy.core ${dummy}0.s" ;
Packit 5c3484
case $CC_FOR_BUILD,$HOST_CC,$CC in
Packit 5c3484
 ,,)    echo "int x;" > $dummy.c ;
Packit 5c3484
	for c in cc gcc c89 c99 ; do
Packit 5c3484
	  if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
Packit 5c3484
	     CC_FOR_BUILD="$c"; break ;
Packit 5c3484
	  fi ;
Packit 5c3484
	done ;
Packit 5c3484
	if test x"$CC_FOR_BUILD" = x ; then
Packit 5c3484
	  CC_FOR_BUILD=no_compiler_found ;
Packit 5c3484
	fi
Packit 5c3484
	;;
Packit 5c3484
 ,,*)   CC_FOR_BUILD=$CC ;;
Packit 5c3484
 ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
Packit 5c3484
esac ; set_cc_for_build= ;'
Packit 5c3484
Packit 5c3484
Packit 5c3484
case "$guess_full" in
Packit 5c3484
Packit 5c3484
alpha-*-*)
Packit 5c3484
  eval $set_cc_for_build
Packit 5c3484
  # configfsf.guess detects exact alpha cpu types for OSF and GNU/Linux, but
Packit 5c3484
  # not for *BSD and other systems.  We try to get an exact type for any
Packit 5c3484
  # plain "alpha" it leaves.
Packit 5c3484
  #
Packit 5c3484
  # configfsf.guess used to have a block of code not unlike this, but these
Packit 5c3484
  # days does its thing with Linux kernel /proc/cpuinfo or OSF psrinfo.
Packit 5c3484
  #
Packit 5c3484
  cat <<EOF >${dummy}0.s
Packit 5c3484
	.data
Packit 5c3484
Lformat:
Packit 5c3484
	.byte 37,100,45,37,120,10,0	# "%d-%x\n"
Packit 5c3484
	.text
Packit 5c3484
	.globl main
Packit 5c3484
	.align 4
Packit 5c3484
	.ent main
Packit 5c3484
main:
Packit 5c3484
	.frame \$30,16,\$26,0
Packit 5c3484
	ldgp \$29,0(\$27)
Packit 5c3484
	.prologue 1
Packit 5c3484
	.long 0x47e03d91 # implver \$17
Packit 5c3484
	lda \$2,-1
Packit 5c3484
	.long 0x47e20c21 # amask \$2,\$1
Packit 5c3484
	lda \$16,Lformat
Packit 5c3484
	not \$1,\$18
Packit 5c3484
	jsr \$26,printf
Packit 5c3484
	ldgp \$29,0(\$26)
Packit 5c3484
	mov 0,\$16
Packit 5c3484
	jsr \$26,exit
Packit 5c3484
	.end main
Packit 5c3484
EOF
Packit 5c3484
  $CC_FOR_BUILD ${dummy}0.s -o $dummy 2>/dev/null
Packit 5c3484
  if test "$?" = 0 ; then
Packit 5c3484
    case `$dummy` in
Packit 5c3484
    0-0)	exact_cpu=alpha      ;;
Packit 5c3484
    1-0)	exact_cpu=alphaev5   ;;
Packit 5c3484
    1-1)	exact_cpu=alphaev56  ;;
Packit 5c3484
    1-101)	exact_cpu=alphapca56 ;;
Packit 5c3484
    2-303)	exact_cpu=alphaev6   ;;
Packit 5c3484
    2-307)	exact_cpu=alphaev67  ;;
Packit 5c3484
    2-1307)	exact_cpu=alphaev68  ;;
Packit 5c3484
    esac
Packit 5c3484
  fi
Packit 5c3484
  ;;
Packit 5c3484
Packit 5c3484
arm*-*-* | aarch64-*-*)
Packit 5c3484
  cpu_code=`sed -n 's/^CPU part.*\(0x.*\)$/\1/p' /proc/cpuinfo 2>/dev/null | sort -r | head -n 1 2>/dev/null`
Packit 5c3484
  cpu_implementer=`sed -n 's/^CPU implementer.*\(0x.*\)$/\1/p' /proc/cpuinfo 2>/dev/null | head -n 1 2>/dev/null`
Packit 5c3484
  case "${cpu_implementer}_${cpu_code}" in
Packit 5c3484
    0x53_0x001) exact_cpu=armexynosm1  ;;
Packit 5c3484
    0x51_0x800) exact_cpu=armcortexa57 ;;
Packit 5c3484
    0x43_0x0a1) exact_cpu=armthunderx  ;;
Packit 5c3484
    0x50_0x000) exact_cpu=armxgene1    ;;
Packit 5c3484
  esac
Packit 5c3484
  if test -z "$exact_cpu"; then
Packit 5c3484
    case "$cpu_code" in
Packit 5c3484
	0xa10 | 0xa11 | 0xb11)			# v4 strongarm/sa1100
Packit 5c3484
		exact_cpu="armsa1";;
Packit 5c3484
	0x915 | 0x925 | \
Packit 5c3484
	0x920 | 0x922 | 0x940)			# v4
Packit 5c3484
		exact_cpu="arm9tdmi";;
Packit 5c3484
	0x210 | 0x290 | 0x2d0 | \
Packit 5c3484
	0x212 | 0x292 | 0x2d2 | \
Packit 5c3484
	0x411)	exact_cpu="armxscale";;		# v5 pxa2xx
Packit 5c3484
	0x926 | 0x946 | 0x966 | 0x968)		# v5te/v5tej
Packit 5c3484
		exact_cpu="arm9te";;
Packit 5c3484
	0xa20 | 0xa22 | 0xa26)			# v5te
Packit 5c3484
		exact_cpu="arm10";;
Packit 5c3484
	0xb02)	exact_cpu="arm11mpcore";;	# v6
Packit 5c3484
	0xb36)	exact_cpu="arm1136";;		# v6
Packit 5c3484
	0xb56)	exact_cpu="arm1156";;		# v6t2
Packit 5c3484
	0xb76)	exact_cpu="arm1176";;		# v6
Packit 5c3484
	0xc05)	exact_cpu="armcortexa5";;	# v7a
Packit 5c3484
	0xc07)	exact_cpu="armcortexa7";;	# v7a
Packit 5c3484
	0xc08)	exact_cpu="armcortexa8";;	# v7a
Packit 5c3484
	0xc09)	exact_cpu="armcortexa9";;	# v7a
Packit 5c3484
	0xc0f)	exact_cpu="armcortexa15";;	# v7a
Packit 5c3484
	0xc14)	exact_cpu="armcortexr4";;	# v7r
Packit 5c3484
	0xc15)	exact_cpu="armcortexr5";;	# v7r
Packit 5c3484
	0xc23)	exact_cpu="armcortexm3";;	# v7m
Packit 5c3484
Packit 5c3484
	0xd04)	exact_cpu="armcortexa35";;	# v8-32
Packit 5c3484
	0xd03)	exact_cpu="armcortexa53";;	# v8
Packit 5c3484
	0xd07)	exact_cpu="armcortexa57";;	# v8
Packit 5c3484
	0xd08)	exact_cpu="armcortexa72";;	# v8
Packit 5c3484
	*)	exact_cpu=$guess_cpu;;
Packit 5c3484
    esac
Packit 5c3484
  fi
Packit 5c3484
  exact_cpu="${exact_cpu}`sed -n 's;^Features.*\(neon\).*;\1;p' /proc/cpuinfo 2>/dev/null | head -n 1 2>/dev/null`"
Packit 5c3484
  ;;
Packit 5c3484
Packit 5c3484
ia64*-*-*)
Packit 5c3484
  eval $set_cc_for_build
Packit 5c3484
  # CPUID[3] bits 24 to 31 is the processor family.  itanium2 is documented
Packit 5c3484
  # as 0x1f, plain itanium has been seen returning 0x07 on two systems, but
Packit 5c3484
  # haven't found any documentation on it as such.
Packit 5c3484
  #
Packit 5c3484
  # Defining both getcpuid and _getcpuid lets us ignore whether the system
Packit 5c3484
  # expects underscores or not.
Packit 5c3484
  #
Packit 5c3484
  # "unsigned long long" is always 64 bits, in fact on hpux in ilp32 mode
Packit 5c3484
  # (which is the default there), it's the only 64-bit type.
Packit 5c3484
  #
Packit 5c3484
  cat >${dummy}0.s <
Packit 5c3484
	.text
Packit 5c3484
	.global	_getcpuid
Packit 5c3484
	.proc	_getcpuid
Packit 5c3484
_getcpuid:
Packit 5c3484
	mov	r8 = CPUID[r32] ;;
Packit 5c3484
	br.ret.sptk.many rp ;;
Packit 5c3484
	.endp	_getcpuid
Packit 5c3484
	.global	getcpuid
Packit 5c3484
	.proc	getcpuid
Packit 5c3484
getcpuid:
Packit 5c3484
	mov	r8 = CPUID[r32] ;;
Packit 5c3484
	br.ret.sptk.many rp ;;
Packit 5c3484
	.endp	getcpuid
Packit 5c3484
EOF
Packit 5c3484
  cat >$dummy.c <
Packit 5c3484
#include <stdio.h>
Packit 5c3484
unsigned long long getcpuid ();
Packit 5c3484
int
Packit 5c3484
main ()
Packit 5c3484
{
Packit 5c3484
  if (getcpuid(0LL) == 0x49656E69756E6547LL && getcpuid(1LL) == 0x6C65746ELL)
Packit 5c3484
    {
Packit 5c3484
      /* "GenuineIntel" */
Packit 5c3484
      switch ((getcpuid(3LL) >> 24) & 0xFF) {
Packit 5c3484
      case 0x07: puts ("itanium");  break;
Packit 5c3484
      case 0x1F: puts ("itanium2"); break; /* McKinley, Madison */
Packit 5c3484
      case 0x20: puts ("itanium2"); break; /* Montecito, Montvale, Tukwila */
Packit 5c3484
      case 0x21: puts ("itanium2"); break; /* Poulson */
Packit 5c3484
      }
Packit 5c3484
    }
Packit 5c3484
  return 0;
Packit 5c3484
}
Packit 5c3484
EOF
Packit 5c3484
  if $CC_FOR_BUILD ${dummy}0.s $dummy.c -o $dummy >/dev/null 2>&1; then
Packit 5c3484
    exact_cpu=`$dummy`
Packit 5c3484
  fi
Packit 5c3484
  ;;
Packit 5c3484
Packit 5c3484
mips-*-irix[6789]*)
Packit 5c3484
  # IRIX 6 and up always has a 64-bit mips cpu
Packit 5c3484
  exact_cpu=mips64
Packit 5c3484
  ;;
Packit 5c3484
Packit 5c3484
m68k-*-*)
Packit 5c3484
  eval $set_cc_for_build
Packit 5c3484
  # NetBSD (and presumably other *BSD) "sysctl hw.model" gives for example
Packit 5c3484
  #   hw.model = Apple Macintosh Quadra 610  (68040)
Packit 5c3484
  exact_cpu=`(sysctl hw.model) 2>/dev/null | sed -n 's/^.*\(680[012346]0\).*$/m\1/p'`
Packit 5c3484
  if test -z "$exact_cpu"; then
Packit 5c3484
    # Linux kernel 2.2 gives for example "CPU: 68020" (tabs in between).
Packit 5c3484
    exact_cpu=`sed -n 's/^CPU:.*\(680[012346]0\).*$/m\1/p' /proc/cpuinfo 2>/dev/null`
Packit 5c3484
  fi
Packit 5c3484
  if test -z "$exact_cpu"; then
Packit 5c3484
    # Try: movel #0,%d0; rts
Packit 5c3484
    # This is to check the compiler and our asm code works etc, before
Packit 5c3484
    # assuming failures below indicate cpu characteristics.
Packit 5c3484
    # .byte is used to avoid problems with assembler syntax variations.
Packit 5c3484
    # For testing, provoke failures by adding "illegal" possibly as
Packit 5c3484
    # ".byte 0x4A, 0xFC"
Packit 5c3484
    cat >${dummy}0.s <
Packit 5c3484
	.text
Packit 5c3484
	.globl main
Packit 5c3484
	.globl _main
Packit 5c3484
main:
Packit 5c3484
_main:
Packit 5c3484
	.byte	0x70, 0x00
Packit 5c3484
	.byte	0x4e, 0x75
Packit 5c3484
EOF
Packit 5c3484
Packit 5c3484
    if ($CC_FOR_BUILD ${dummy}0.s -o $dummy && $dummy) >/dev/null 2>&1; then
Packit 5c3484
Packit 5c3484
      # $SHELL -c is used to execute $dummy below, since ($dummy)
Packit 5c3484
      # 2>/dev/null still prints the SIGILL message on some shells.
Packit 5c3484
      #
Packit 5c3484
        # Try: movel #0,%d0
Packit 5c3484
        #      rtd #0
Packit 5c3484
        cat >${dummy}0.s <
Packit 5c3484
	.text
Packit 5c3484
	.globl main
Packit 5c3484
	.globl _main
Packit 5c3484
main:
Packit 5c3484
_main:
Packit 5c3484
	.byte	0x70, 0x00
Packit 5c3484
	.byte	0x4e, 0x74, 0x00, 0x00
Packit 5c3484
EOF
Packit 5c3484
        if $CC_FOR_BUILD ${dummy}0.s -o $dummy >/dev/null 2>&1; then
Packit 5c3484
          $SHELL -c $dummy >/dev/null 2>&1
Packit 5c3484
	  if test $? != 0; then
Packit 5c3484
            exact_cpu=m68000    # because rtd didn't work
Packit 5c3484
          fi
Packit 5c3484
        fi
Packit 5c3484
      #
Packit 5c3484
Packit 5c3484
      if test -z "$exact_cpu"; then
Packit 5c3484
        # Try: trapf
Packit 5c3484
        #      movel #0,%d0
Packit 5c3484
        #      rts
Packit 5c3484
        # Another possibility for identifying 68000 and 68010 is the
Packit 5c3484
        # different value stored by "movem a0,(a0)+"
Packit 5c3484
        cat >${dummy}0.s <
Packit 5c3484
	.text
Packit 5c3484
	.globl main
Packit 5c3484
	.globl _main
Packit 5c3484
main:
Packit 5c3484
_main:
Packit 5c3484
	.byte	0x51, 0xFC
Packit 5c3484
	.byte	0x70, 0x00
Packit 5c3484
	.byte	0x4e, 0x75
Packit 5c3484
EOF
Packit 5c3484
        if $CC_FOR_BUILD ${dummy}0.s -o $dummy >/dev/null 2>&1; then
Packit 5c3484
          $SHELL -c $dummy >/dev/null 2>&1
Packit 5c3484
	  if test $? != 0; then
Packit 5c3484
            exact_cpu=m68010    # because trapf didn't work
Packit 5c3484
          fi
Packit 5c3484
        fi
Packit 5c3484
      fi
Packit 5c3484
Packit 5c3484
      if test -z "$exact_cpu"; then
Packit 5c3484
        # Try: bfffo %d1{0:31},%d0
Packit 5c3484
        #      movel #0,%d0
Packit 5c3484
        #      rts
Packit 5c3484
        cat >${dummy}0.s <
Packit 5c3484
	.text
Packit 5c3484
	.globl main
Packit 5c3484
	.globl _main
Packit 5c3484
main:
Packit 5c3484
_main:
Packit 5c3484
	.byte	0xED, 0xC1, 0x00, 0x1F
Packit 5c3484
	.byte	0x70, 0x00
Packit 5c3484
	.byte	0x4e, 0x75
Packit 5c3484
EOF
Packit 5c3484
        if $CC_FOR_BUILD ${dummy}0.s -o $dummy >/dev/null 2>&1; then
Packit 5c3484
          $SHELL -c $dummy >/dev/null 2>&1
Packit 5c3484
	  if test $? != 0; then
Packit 5c3484
            exact_cpu=m68360  # cpu32, because bfffo didn't work
Packit 5c3484
          fi
Packit 5c3484
        fi
Packit 5c3484
      fi
Packit 5c3484
Packit 5c3484
      if test -z "$exact_cpu"; then
Packit 5c3484
        # FIXME: Now we know 68020 or up, but how to detect 030, 040 and 060?
Packit 5c3484
        exact_cpu=m68020
Packit 5c3484
      fi
Packit 5c3484
    fi
Packit 5c3484
  fi
Packit 5c3484
  if test -z "$exact_cpu"; then
Packit 5c3484
    case "$guess_full" in
Packit 5c3484
      *-*-next* | *-*-openstep*)  # NeXTs are 68020 or better
Packit 5c3484
        exact_cpu=m68020 ;;
Packit 5c3484
    esac
Packit 5c3484
  fi
Packit 5c3484
  ;;
Packit 5c3484
Packit 5c3484
Packit 5c3484
rs6000-*-* | powerpc*-*-*)
Packit 5c3484
  # Enhancement: On MacOS the "machine" command prints for instance
Packit 5c3484
  # "ppc750".  Interestingly on powerpc970-apple-darwin6.8.5 it prints
Packit 5c3484
  # "ppc970" where there's no actual #define for 970 from NXGetLocalArchInfo
Packit 5c3484
  # (as noted below).  But the man page says the command is still "under
Packit 5c3484
  # development", so it doesn't seem wise to use it just yet, not while
Packit 5c3484
  # there's an alternative.
Packit 5c3484
Packit 5c3484
  # Grep the /proc/cpuinfo pseudo-file.
Packit 5c3484
  # Anything unrecognised is ignored, since of course we mustn't spit out
Packit 5c3484
  # a cpu type config.sub doesn't know.
Packit 5c3484
  if test -z "$exact_cpu" && test -f /proc/cpuinfo; then
Packit 5c3484
    x=`grep "^cpu[ 	]" /proc/cpuinfo | head -n 1`
Packit 5c3484
    x=`echo $x | sed -n 's/^cpu[ 	]*:[ 	]*\([A-Za-z0-9]*\).*/\1/p'`
Packit 5c3484
    x=`echo $x | sed 's/PPC//'`
Packit 5c3484
    case $x in
Packit 5c3484
      601)     exact_cpu="power" ;;
Packit 5c3484
      603ev)   exact_cpu="powerpc603e" ;;
Packit 5c3484
      604ev5)  exact_cpu="powerpc604e" ;;
Packit 5c3484
      970??)   exact_cpu="powerpc970" ;;
Packit 5c3484
      603 | 603e | 604 | 604e | 750 | 821 | 860)
Packit 5c3484
        exact_cpu="powerpc$x" ;;
Packit 5c3484
      POWER[4-9]*)
Packit 5c3484
        exact_cpu=`echo $x | sed -e "s;POWER;power;" -e "s;[a-zA-Z]*$;;"` ;;
Packit 5c3484
    esac
Packit 5c3484
  fi
Packit 5c3484
Packit 5c3484
  # Try to read the PVR.  mfpvr is a protected instruction, NetBSD, MacOS
Packit 5c3484
  # and AIX don't allow it in user mode, but the Linux kernel does.
Packit 5c3484
  #
Packit 5c3484
  # Note this is no good on AIX, since a C function there is the address of
Packit 5c3484
  # a function descriptor, not actual code.  But this doesn't matter since
Packit 5c3484
  # AIX doesn't allow mfpvr anyway.
Packit 5c3484
  #
Packit 5c3484
  if test -z "$exact_cpu"; then
Packit 5c3484
    eval $set_cc_for_build
Packit 5c3484
    cat >$dummy.c <<\EOF
Packit 5c3484
#include <stdio.h>
Packit 5c3484
int
Packit 5c3484
main ()
Packit 5c3484
{
Packit 5c3484
  unsigned  pvr;
Packit 5c3484
Packit 5c3484
  asm ("mfpvr	%0" : "=r" (pvr));
Packit 5c3484
Packit 5c3484
  switch (pvr >> 16) {
Packit 5c3484
  case 0x0001: puts ("powerpc601");  break;
Packit 5c3484
  case 0x0003: puts ("powerpc603");  break;
Packit 5c3484
  case 0x0004: puts ("powerpc604");  break;
Packit 5c3484
  case 0x0006: puts ("powerpc603e"); break;
Packit 5c3484
  case 0x0007: puts ("powerpc603e"); break;  /* 603ev */
Packit 5c3484
  case 0x0008: puts ("powerpc750");  break;
Packit 5c3484
  case 0x0009: puts ("powerpc604e"); break;
Packit 5c3484
  case 0x000a: puts ("powerpc604e"); break;  /* 604ev5 */
Packit 5c3484
  case 0x000c: puts ("powerpc7400"); break;
Packit 5c3484
  case 0x0041: puts ("powerpc630");  break;
Packit 5c3484
  case 0x003f: puts ("power7");      break;
Packit 5c3484
  case 0x004b: puts ("power8");      break;
Packit 5c3484
  case 0x0050: puts ("powerpc860");  break;
Packit 5c3484
  case 0x8000: puts ("powerpc7450"); break;
Packit 5c3484
  case 0x8001: puts ("powerpc7455"); break;
Packit 5c3484
  case 0x8002: puts ("powerpc7457"); break;
Packit 5c3484
  case 0x8003: puts ("powerpc7447"); break; /* really 7447A */
Packit 5c3484
  case 0x800c: puts ("powerpc7410"); break;
Packit 5c3484
  }
Packit 5c3484
  return 0;
Packit 5c3484
}
Packit 5c3484
EOF
Packit 5c3484
    if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
Packit 5c3484
      # This style construct is needed on AIX 4.3 to suppress the SIGILL error
Packit 5c3484
      # from (*fun)().  Using $SHELL -c $dummy 2>/dev/null doesn't work.
Packit 5c3484
      { x=`$dummy`; } 2>/dev/null
Packit 5c3484
      if test -n "$x"; then
Packit 5c3484
	exact_cpu=$x
Packit 5c3484
      fi
Packit 5c3484
    fi
Packit 5c3484
  fi
Packit 5c3484
Packit 5c3484
  if test -z "$exact_cpu"; then
Packit 5c3484
    # On AIX, try looking at _system_configuration.  This is present in
Packit 5c3484
    # version 4 at least.
Packit 5c3484
    cat >$dummy.c <
Packit 5c3484
#include <stdio.h>
Packit 5c3484
#include <sys/systemcfg.h>
Packit 5c3484
int
Packit 5c3484
main ()
Packit 5c3484
{
Packit 5c3484
  switch (_system_configuration.implementation) {
Packit 5c3484
  /* Old versions of AIX don't have all these constants,
Packit 5c3484
     use ifdef for safety. */
Packit 5c3484
#ifdef POWER_RS2
Packit 5c3484
  case POWER_RS2:    puts ("power2");     break;
Packit 5c3484
#endif
Packit 5c3484
#ifdef POWER_601
Packit 5c3484
  case POWER_601:    puts ("power");      break;
Packit 5c3484
#endif
Packit 5c3484
#ifdef POWER_603
Packit 5c3484
  case POWER_603:    puts ("powerpc603"); break;
Packit 5c3484
#endif
Packit 5c3484
#ifdef POWER_604
Packit 5c3484
  case POWER_604:    puts ("powerpc604"); break;
Packit 5c3484
#endif
Packit 5c3484
#ifdef POWER_620
Packit 5c3484
  case POWER_620:    puts ("powerpc620"); break;
Packit 5c3484
#endif
Packit 5c3484
#ifdef POWER_630
Packit 5c3484
  case POWER_630:    puts ("powerpc630"); break;
Packit 5c3484
#endif
Packit 5c3484
  /* Dunno what this is, leave it out for now.
Packit 5c3484
  case POWER_A35:    puts ("powerpca35"); break;
Packit 5c3484
  */
Packit 5c3484
  /* This is waiting for a bit more info.
Packit 5c3484
  case POWER_RS64II: puts ("powerpcrs64ii"); break;
Packit 5c3484
  */
Packit 5c3484
#ifdef POWER_4
Packit 5c3484
  case POWER_4:    puts ("power4"); break;
Packit 5c3484
#endif
Packit 5c3484
#ifdef POWER_5
Packit 5c3484
  case POWER_5:    puts ("power5"); break;
Packit 5c3484
#endif
Packit 5c3484
#ifdef POWER_6
Packit 5c3484
  case POWER_6:    puts ("power6"); break;
Packit 5c3484
#endif
Packit 5c3484
#ifdef POWER_7
Packit 5c3484
  case POWER_7:    puts ("power7"); break;
Packit 5c3484
#endif
Packit 5c3484
#ifdef POWER_8
Packit 5c3484
  case POWER_8:    puts ("power8"); break;
Packit 5c3484
#endif
Packit 5c3484
  default:
Packit 5c3484
    if (_system_configuration.architecture == POWER_RS)
Packit 5c3484
      puts ("power");
Packit 5c3484
    else if (_system_configuration.width == 64)
Packit 5c3484
      puts ("powerpc64");
Packit 5c3484
  }
Packit 5c3484
  return 0;
Packit 5c3484
}
Packit 5c3484
EOF
Packit 5c3484
    if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
Packit 5c3484
      x=`$dummy`
Packit 5c3484
      if test -n "$x"; then
Packit 5c3484
        exact_cpu=$x
Packit 5c3484
      fi
Packit 5c3484
    fi
Packit 5c3484
  fi
Packit 5c3484
Packit 5c3484
  if test -z "$exact_cpu"; then
Packit 5c3484
    # On MacOS X (or any Mach-O presumably), NXGetLocalArchInfo cpusubtype
Packit 5c3484
    # can tell us the exact cpu.
Packit 5c3484
    cat >$dummy.c <
Packit 5c3484
#include <stdio.h>
Packit 5c3484
#include <mach-o/arch.h>
Packit 5c3484
int
Packit 5c3484
main (void)
Packit 5c3484
{
Packit 5c3484
  const NXArchInfo *a = NXGetLocalArchInfo();
Packit 5c3484
  if (a->cputype == CPU_TYPE_POWERPC)
Packit 5c3484
    {
Packit 5c3484
      switch (a->cpusubtype) {
Packit 5c3484
      /* The following known to Darwin 1.3. */
Packit 5c3484
      case CPU_SUBTYPE_POWERPC_601:   puts ("powerpc601");  break;
Packit 5c3484
      case CPU_SUBTYPE_POWERPC_602:   puts ("powerpc602");  break;
Packit 5c3484
      case CPU_SUBTYPE_POWERPC_603:   puts ("powerpc603");  break;
Packit 5c3484
      case CPU_SUBTYPE_POWERPC_603e:  puts ("powerpc603e"); break;
Packit 5c3484
      case CPU_SUBTYPE_POWERPC_603ev: puts ("powerpc603e"); break;
Packit 5c3484
      case CPU_SUBTYPE_POWERPC_604:   puts ("powerpc604");  break;
Packit 5c3484
      case CPU_SUBTYPE_POWERPC_604e:  puts ("powerpc604e"); break;
Packit 5c3484
      case CPU_SUBTYPE_POWERPC_620:   puts ("powerpc620");  break;
Packit 5c3484
      case CPU_SUBTYPE_POWERPC_750:   puts ("powerpc750");  break;
Packit 5c3484
      case CPU_SUBTYPE_POWERPC_7400:  puts ("powerpc7400"); break;
Packit 5c3484
      case CPU_SUBTYPE_POWERPC_7450:  puts ("powerpc7450"); break;
Packit 5c3484
      /* Darwin 6.8.5 doesn't define the following */
Packit 5c3484
      case 0x8001:                    puts ("powerpc7455"); break;
Packit 5c3484
      case 0x8002:                    puts ("powerpc7457"); break;
Packit 5c3484
      case 0x8003:                    puts ("powerpc7447"); break;
Packit 5c3484
      case 100:                       puts ("powerpc970");  break;
Packit 5c3484
      }
Packit 5c3484
    }
Packit 5c3484
  return 0;
Packit 5c3484
}
Packit 5c3484
EOF
Packit 5c3484
    if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
Packit 5c3484
      x=`$dummy`
Packit 5c3484
      if test -n "$x"; then
Packit 5c3484
        exact_cpu=$x
Packit 5c3484
      fi
Packit 5c3484
    fi
Packit 5c3484
  fi
Packit 5c3484
  ;;
Packit 5c3484
Packit 5c3484
sparc-*-* | sparc64-*-*)
Packit 5c3484
  # If we can recognise an actual v7 then $exact_cpu is set to "sparc" so as
Packit 5c3484
  # to short-circuit subsequent tests.
Packit 5c3484
Packit 5c3484
  # Grep the linux kernel /proc/cpuinfo pseudo-file.
Packit 5c3484
  # A typical line is "cpu\t\t: TI UltraSparc II  (BlackBird)"
Packit 5c3484
  # See arch/sparc/kernel/cpu.c and arch/sparc64/kernel/cpu.c.
Packit 5c3484
  #
Packit 5c3484
  if test -f /proc/cpuinfo; then
Packit 5c3484
    if grep 'cpu.*Cypress' /proc/cpuinfo >/dev/null; then
Packit 5c3484
      exact_cpu="sparc"   # ie. v7
Packit 5c3484
    elif grep 'cpu.*Power-UP' /proc/cpuinfo >/dev/null; then
Packit 5c3484
      exact_cpu="sparc"   # ie. v7
Packit 5c3484
    elif grep 'cpu.*HyperSparc' /proc/cpuinfo >/dev/null; then
Packit 5c3484
      exact_cpu="sparcv8"
Packit 5c3484
    elif grep 'cpu.*SuperSparc' /proc/cpuinfo >/dev/null; then
Packit 5c3484
      exact_cpu="supersparc"
Packit 5c3484
    elif grep 'cpu.*MicroSparc' /proc/cpuinfo >/dev/null; then
Packit 5c3484
      exact_cpu="microsparc"
Packit 5c3484
    elif grep 'cpu.*MB86904' /proc/cpuinfo >/dev/null; then
Packit 5c3484
      # actually MicroSPARC-II
Packit 5c3484
      exact_cpu=microsparc
Packit 5c3484
    elif grep 'cpu.*UltraSparc T5' /proc/cpuinfo >/dev/null; then
Packit 5c3484
      exact_cpu="ultrasparct5"
Packit 5c3484
    elif grep 'cpu.*UltraSparc T4' /proc/cpuinfo >/dev/null; then
Packit 5c3484
      exact_cpu="ultrasparct4"
Packit 5c3484
    elif grep 'cpu.*UltraSparc T3' /proc/cpuinfo >/dev/null; then
Packit 5c3484
      exact_cpu="ultrasparct3"
Packit 5c3484
    elif grep 'cpu.*UltraSparc T2' /proc/cpuinfo >/dev/null; then
Packit 5c3484
      exact_cpu="ultrasparct2"
Packit 5c3484
    elif grep 'cpu.*UltraSparc T1' /proc/cpuinfo >/dev/null; then
Packit 5c3484
      exact_cpu="ultrasparct1"
Packit 5c3484
    elif grep 'cpu.*UltraSparc III' /proc/cpuinfo >/dev/null; then
Packit 5c3484
      exact_cpu="ultrasparc3"
Packit 5c3484
    elif grep 'cpu.*UltraSparc IIi' /proc/cpuinfo >/dev/null; then
Packit 5c3484
      exact_cpu="ultrasparc2i"
Packit 5c3484
    elif grep 'cpu.*UltraSparc II' /proc/cpuinfo >/dev/null; then
Packit 5c3484
      exact_cpu="ultrasparc2"
Packit 5c3484
    elif grep 'cpu.*UltraSparc' /proc/cpuinfo >/dev/null; then
Packit 5c3484
      exact_cpu="ultrasparc"
Packit 5c3484
    fi
Packit 5c3484
  fi
Packit 5c3484
Packit 5c3484
  # Need to invoke this for setup of $dummy
Packit 5c3484
  eval $set_cc_for_build
Packit 5c3484
Packit 5c3484
  # Grep the output from sysinfo on SunOS.
Packit 5c3484
  # sysinfo has been seen living in /bin or in /usr/kvm
Packit 5c3484
  #	cpu0 is a "SuperSPARC Model 41 SPARCmodule" CPU
Packit 5c3484
  #	cpu0 is a "75 MHz TI,TMS390Z55" CPU
Packit 5c3484
  #
Packit 5c3484
  if test -z "$exact_cpu"; then
Packit 5c3484
    for i in sysinfo /usr/kvm/sysinfo; do
Packit 5c3484
      if $SHELL -c $i 2>/dev/null >$dummy; then
Packit 5c3484
        if grep 'cpu0 is a "SuperSPARC' $dummy >/dev/null; then
Packit 5c3484
          exact_cpu=supersparc
Packit 5c3484
          break
Packit 5c3484
        elif grep 'cpu0 is a .*TMS390Z5.' $dummy >/dev/null; then
Packit 5c3484
          # TMS390Z50 and TMS390Z55
Packit 5c3484
          exact_cpu=supersparc
Packit 5c3484
          break
Packit 5c3484
        fi
Packit 5c3484
      fi
Packit 5c3484
    done
Packit 5c3484
  fi
Packit 5c3484
Packit 5c3484
  # Grep the output from prtconf on Solaris.
Packit 5c3484
  # Use an explicit /usr/sbin, since that directory might not be in a normal
Packit 5c3484
  # user's path.
Packit 5c3484
  #
Packit 5c3484
  #     SUNW,UltraSPARC (driver not attached)
Packit 5c3484
  #     SUNW,UltraSPARC-II (driver not attached)
Packit 5c3484
  #     SUNW,UltraSPARC-IIi (driver not attached)
Packit 5c3484
  #     SUNW,UltraSPARC-III+ (driver not attached)
Packit 5c3484
  #     Ross,RT625 (driver not attached)
Packit 5c3484
  #     TI,TMS390Z50 (driver not attached)
Packit 5c3484
  #
Packit 5c3484
  # /usr/sbin/sysdef prints similar information, but includes all loadable
Packit 5c3484
  # cpu modules, not just the real cpu.
Packit 5c3484
  #
Packit 5c3484
  # We first try a plain prtconf, since that is known to work on older systems.
Packit 5c3484
  # But for newer T1 systems, that doesn't produce any useful output, we need
Packit 5c3484
  # "prtconf -vp" there.
Packit 5c3484
  #
Packit 5c3484
  for prtconfopt in "" "-vp"; do
Packit 5c3484
    if test -z "$exact_cpu"; then
Packit 5c3484
      if $SHELL -c "/usr/sbin/prtconf $prtconfopt" 2>/dev/null >$dummy; then
Packit 5c3484
	if grep 'SUNW,UltraSPARC-T5' $dummy >/dev/null; then
Packit 5c3484
	  exact_cpu=ultrasparct5
Packit 5c3484
	elif grep 'SUNW,UltraSPARC-T4' $dummy >/dev/null; then
Packit 5c3484
	  exact_cpu=ultrasparct4
Packit 5c3484
	elif grep 'SUNW,UltraSPARC-T3' $dummy >/dev/null; then
Packit 5c3484
	  exact_cpu=ultrasparct3
Packit 5c3484
	elif grep 'SUNW,UltraSPARC-T2' $dummy >/dev/null; then
Packit 5c3484
	  exact_cpu=ultrasparct2
Packit 5c3484
	elif grep 'SUNW,UltraSPARC-T1' $dummy >/dev/null; then
Packit 5c3484
	  exact_cpu=ultrasparct1
Packit 5c3484
	elif grep 'SUNW,UltraSPARC-III' $dummy >/dev/null; then
Packit 5c3484
	  exact_cpu=ultrasparc3
Packit 5c3484
	elif grep 'SUNW,UltraSPARC-IIi' $dummy >/dev/null; then
Packit 5c3484
	  exact_cpu=ultrasparc2i
Packit 5c3484
	elif grep 'SUNW,UltraSPARC-II' $dummy >/dev/null; then
Packit 5c3484
	  exact_cpu=ultrasparc2
Packit 5c3484
	elif grep 'SUNW,UltraSPARC' $dummy >/dev/null; then
Packit 5c3484
	  exact_cpu=ultrasparc
Packit 5c3484
	elif grep 'Ross,RT62.' $dummy >/dev/null; then
Packit 5c3484
	  # RT620, RT625, RT626 hypersparcs (v8).
Packit 5c3484
	  exact_cpu=sparcv8
Packit 5c3484
	elif grep 'TI,TMS390Z5.' $dummy >/dev/null; then
Packit 5c3484
	  # TMS390Z50 and TMS390Z55
Packit 5c3484
	  exact_cpu=supersparc
Packit 5c3484
	elif grep 'TI,TMS390S10' $dummy >/dev/null; then
Packit 5c3484
	  exact_cpu=microsparc
Packit 5c3484
	elif grep 'FMI,MB86904' $dummy >/dev/null; then
Packit 5c3484
	  # actually MicroSPARC-II
Packit 5c3484
	  exact_cpu=microsparc
Packit 5c3484
	fi
Packit 5c3484
      fi
Packit 5c3484
    fi
Packit 5c3484
  done
Packit 5c3484
Packit 5c3484
  # Grep the output from sysctl hw.model on sparc or sparc64 *BSD.
Packit 5c3484
  # Use an explicit /sbin, since that directory might not be in a normal
Packit 5c3484
  # user's path.  Example outputs,
Packit 5c3484
  #
Packit 5c3484
  #     hw.model: Sun Microsystems UltraSparc-IIi
Packit 5c3484
  #
Packit 5c3484
  if test -z "$exact_cpu"; then
Packit 5c3484
    if $SHELL -c "/sbin/sysctl hw.model" 2>/dev/null >$dummy; then
Packit 5c3484
      if grep -i 'UltraSparc-T5' $dummy >/dev/null; then
Packit 5c3484
        exact_cpu=ultrasparct5
Packit 5c3484
      elif grep -i 'UltraSparc-T4' $dummy >/dev/null; then
Packit 5c3484
        exact_cpu=ultrasparct4
Packit 5c3484
      elif grep -i 'UltraSparc-T3' $dummy >/dev/null; then
Packit 5c3484
        exact_cpu=ultrasparct3
Packit 5c3484
      elif grep -i 'UltraSparc-T2' $dummy >/dev/null; then
Packit 5c3484
        exact_cpu=ultrasparct2
Packit 5c3484
      elif grep -i 'UltraSparc-T1' $dummy >/dev/null; then
Packit 5c3484
        exact_cpu=ultrasparct1
Packit 5c3484
      elif grep -i 'UltraSparc-III' $dummy >/dev/null; then
Packit 5c3484
        exact_cpu=ultrasparc3
Packit 5c3484
      elif grep -i 'UltraSparc-IIi' $dummy >/dev/null; then
Packit 5c3484
        exact_cpu=ultrasparc2i
Packit 5c3484
      elif grep -i 'UltraSparc-II' $dummy >/dev/null; then
Packit 5c3484
        exact_cpu=ultrasparc2
Packit 5c3484
      elif grep -i 'UltraSparc' $dummy >/dev/null; then
Packit 5c3484
        exact_cpu=ultrasparc
Packit 5c3484
      elif grep 'TMS390Z5.' $dummy >/dev/null; then
Packit 5c3484
        # TMS390Z50 and TMS390Z55
Packit 5c3484
        exact_cpu=supersparc
Packit 5c3484
      elif grep 'TMS390S10' $dummy >/dev/null; then
Packit 5c3484
        exact_cpu=microsparc
Packit 5c3484
      elif grep 'MB86904' $dummy >/dev/null; then
Packit 5c3484
        # actually MicroSPARC-II
Packit 5c3484
        exact_cpu=microsparc
Packit 5c3484
      elif grep 'MB86907' $dummy >/dev/null; then
Packit 5c3484
        exact_cpu=turbosparc
Packit 5c3484
      fi
Packit 5c3484
    fi
Packit 5c3484
  fi
Packit 5c3484
Packit 5c3484
  # sun4m and sun4d are v8s of some sort, sun4u is a v9 of some sort
Packit 5c3484
  #
Packit 5c3484
  if test -z "$exact_cpu"; then
Packit 5c3484
    case `uname -m` in
Packit 5c3484
      sun4[md]) exact_cpu=sparcv8 ;;
Packit 5c3484
      sun4u)    exact_cpu=sparcv9 ;;
Packit 5c3484
    esac
Packit 5c3484
  fi
Packit 5c3484
  ;;
Packit 5c3484
Packit 5c3484
Packit 5c3484
# Recognise x86 processors using a tricky cpuid with 4 arguments, repeating
Packit 5c3484
# arguments; for x86-64 we effectively pass the 1st in rdx and the 2nd in rcx.
Packit 5c3484
# This allows the same asm to work for both standard and Windoze calling
Packit 5c3484
# conventions.
Packit 5c3484
Packit 5c3484
i?86-*-* | amd64-*-* | x86_64-*-*)
Packit 5c3484
  eval $set_cc_for_build
Packit 5c3484
Packit 5c3484
  cat <<EOF >$dummy.c
Packit 5c3484
#include <string.h>
Packit 5c3484
#include <stdio.h>
Packit 5c3484
#define CPUID(a,b) cpuid(b,a,a,b)
Packit 5c3484
#if __cplusplus
Packit 5c3484
extern "C"
Packit 5c3484
#endif
Packit 5c3484
unsigned int cpuid (int, char *, char *, int);
Packit 5c3484
Packit 5c3484
int
Packit 5c3484
gmp_workaround_skylake_cpuid_bug ()
Packit 5c3484
{
Packit 5c3484
  char feature_string[49];
Packit 5c3484
  char processor_name_string[49];
Packit 5c3484
  static const char *bad_cpus[] = {" G44", " G45", " G39" /* , "6600" */ };
Packit 5c3484
  int i;
Packit 5c3484
Packit 5c3484
  /* Example strings:                                   */
Packit 5c3484
  /* "Intel(R) Pentium(R) CPU G4400 @ 3.30GHz"          */
Packit 5c3484
  /* "Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz"         */
Packit 5c3484
  /*                  ^               ^               ^ */
Packit 5c3484
  /*     0x80000002       0x80000003      0x80000004    */
Packit 5c3484
  /* We match out just the 0x80000003 part here. */
Packit 5c3484
Packit 5c3484
  /* In their infinitive wisdom, Intel decided to use one register order for
Packit 5c3484
     the vendor string, and another for the processor name string.  We shuffle
Packit 5c3484
     things about here, rather than write a new variant of our assembly cpuid.
Packit 5c3484
  */
Packit 5c3484
Packit 5c3484
  unsigned int eax, ebx, ecx, edx;
Packit 5c3484
  eax = CPUID (feature_string, 0x80000003);
Packit 5c3484
  ebx = ((unsigned int *)feature_string)[0];
Packit 5c3484
  edx = ((unsigned int *)feature_string)[1];
Packit 5c3484
  ecx = ((unsigned int *)feature_string)[2];
Packit 5c3484
Packit 5c3484
  ((unsigned int *) (processor_name_string))[0] = eax;
Packit 5c3484
  ((unsigned int *) (processor_name_string))[1] = ebx;
Packit 5c3484
  ((unsigned int *) (processor_name_string))[2] = ecx;
Packit 5c3484
  ((unsigned int *) (processor_name_string))[3] = edx;
Packit 5c3484
Packit 5c3484
  processor_name_string[16] = 0;
Packit 5c3484
Packit 5c3484
  for (i = 0; i < sizeof (bad_cpus) / sizeof (char *); i++)
Packit 5c3484
    {
Packit 5c3484
      if (strstr (processor_name_string, bad_cpus[i]) != 0)
Packit 5c3484
	return 1;
Packit 5c3484
    }
Packit 5c3484
  return 0;
Packit 5c3484
}
Packit 5c3484
Packit 5c3484
int
Packit 5c3484
main ()
Packit 5c3484
{
Packit 5c3484
  char vendor_string[13];
Packit 5c3484
  char feature_string[12];
Packit 5c3484
  long fms;
Packit 5c3484
  int family, model;
Packit 5c3484
  const char *modelstr, *suffix;
Packit 5c3484
  int cpu_64bit = 0, cpu_avx = 0;
Packit 5c3484
  int cpuid_64bit, cpuid_avx, cpuid_osxsave;
Packit 5c3484
Packit 5c3484
  CPUID (vendor_string, 0);
Packit 5c3484
  vendor_string[12] = 0;
Packit 5c3484
Packit 5c3484
  fms = CPUID (feature_string, 1);
Packit 5c3484
Packit 5c3484
  family = ((fms >> 8) & 0xf) + ((fms >> 20) & 0xff);
Packit 5c3484
  model = ((fms >> 4) & 0xf) + ((fms >> 12) & 0xf0);
Packit 5c3484
Packit 5c3484
  cpuid_avx     = (feature_string[11] >> 4) & 1;
Packit 5c3484
  cpuid_osxsave = (feature_string[11] >> 3) & 1;
Packit 5c3484
Packit 5c3484
  modelstr = "$guess_cpu";
Packit 5c3484
Packit 5c3484
  /**************************************************/
Packit 5c3484
  /*** WARNING: keep this list in sync with fat.c ***/
Packit 5c3484
  /**************************************************/
Packit 5c3484
  if (strcmp (vendor_string, "GenuineIntel") == 0)
Packit 5c3484
    {
Packit 5c3484
      switch (family)
Packit 5c3484
	{
Packit 5c3484
	case 5:
Packit 5c3484
	  if (model <= 2)	modelstr = "pentium";
Packit 5c3484
	  else if (model >= 4)	modelstr = "pentiummmx";
Packit 5c3484
	  break;
Packit 5c3484
	case 6:
Packit 5c3484
          if (model <= 1)                                   modelstr = "pentiumpro";
Packit 5c3484
          else if (model <= 6)                              modelstr = "pentium2";
Packit 5c3484
          else if (model <= 8)                              modelstr = "pentium3";
Packit 5c3484
          else if (model <= 9)                              modelstr = "pentiumm";
Packit 5c3484
          else if (model <= 0x0c)                           modelstr = "pentium3";
Packit 5c3484
          else if (model <= 0x0e)                           modelstr = "pentiumm";
Packit 5c3484
          else if (model <= 0x19) cpu_64bit = 1,            modelstr = "core2";
Packit 5c3484
          else if (model == 0x1a) cpu_64bit = 1,            modelstr = "nehalem";    /* NHM Gainestown */
Packit 5c3484
          else if (model == 0x1c) cpu_64bit = 1,            modelstr = "atom";       /* Silverthorne */
Packit 5c3484
          else if (model == 0x1d) cpu_64bit = 1,            modelstr = "core2";      /* PNR Dunnington */
Packit 5c3484
          else if (model == 0x1e) cpu_64bit = 1,            modelstr = "nehalem";    /* NHM Lynnfield/Jasper */
Packit 5c3484
          else if (model == 0x25) cpu_64bit = 1,            modelstr = "westmere";   /* WSM Clarkdale/Arrandale */
Packit 5c3484
          else if (model == 0x26) cpu_64bit = 1,            modelstr = "atom";       /* Lincroft */
Packit 5c3484
          else if (model == 0x27) cpu_64bit = 1,            modelstr = "atom";       /* Saltwell */
Packit 5c3484
          else if (model == 0x2a) cpu_64bit = 1, cpu_avx=1, modelstr = "sandybridge";/* SB */
Packit 5c3484
          else if (model == 0x2c) cpu_64bit = 1,            modelstr = "westmere";   /* WSM Gulftown */
Packit 5c3484
          else if (model == 0x2d) cpu_64bit = 1, cpu_avx=1, modelstr = "sandybridge";/* SBC-EP */
Packit 5c3484
          else if (model == 0x2e) cpu_64bit = 1,            modelstr = "nehalem";    /* NHM Beckton */
Packit 5c3484
          else if (model == 0x2f) cpu_64bit = 1,            modelstr = "westmere";   /* WSM Eagleton */
Packit 5c3484
          else if (model == 0x36) cpu_64bit = 1,            modelstr = "atom";       /* Cedarview/Saltwell */
Packit 5c3484
          else if (model == 0x37) cpu_64bit = 1,            modelstr = "silvermont"; /* Silvermont */
Packit 5c3484
          else if (model == 0x3a) cpu_64bit = 1, cpu_avx=1, modelstr = "ivybridge";  /* IBR */
Packit 5c3484
          else if (model == 0x3c) cpu_64bit = 1, cpu_avx=1, modelstr = "haswell";    /* Haswell client */
Packit 5c3484
          else if (model == 0x3d) cpu_64bit = 1, cpu_avx=1, modelstr = "broadwell";  /* Broadwell */
Packit 5c3484
          else if (model == 0x3e) cpu_64bit = 1, cpu_avx=1, modelstr = "ivybridge";  /* Ivytown */
Packit 5c3484
          else if (model == 0x3f) cpu_64bit = 1, cpu_avx=1, modelstr = "haswell";    /* Haswell server */
Packit 5c3484
          else if (model == 0x45) cpu_64bit = 1, cpu_avx=1, modelstr = "haswell";    /* Haswell ULT */
Packit 5c3484
          else if (model == 0x46) cpu_64bit = 1, cpu_avx=1, modelstr = "haswell";    /* Crystal Well */
Packit 5c3484
          else if (model == 0x47) cpu_64bit = 1, cpu_avx=1, modelstr = "broadwell";  /* Broadwell */
Packit 5c3484
          else if (model == 0x4a) cpu_64bit = 1,            modelstr = "silvermont"; /* Silvermont */
Packit 5c3484
          else if (model == 0x4c) cpu_64bit = 1,            modelstr = "silvermont"; /* Airmont */
Packit 5c3484
          else if (model == 0x4d) cpu_64bit = 1,            modelstr = "silvermont"; /* Silvermont/Avoton */
Packit 5c3484
          else if (model == 0x4e) cpu_64bit = 1, cpu_avx=1, modelstr = "skylake";    /* Skylake client */
Packit 5c3484
          else if (model == 0x4f) cpu_64bit = 1, cpu_avx=1, modelstr = "broadwell";  /* Broadwell server */
Packit 5c3484
          else if (model == 0x55) cpu_64bit = 1, cpu_avx=1, modelstr = "skylake";    /* Skylake server */
Packit 5c3484
          else if (model == 0x56) cpu_64bit = 1, cpu_avx=1, modelstr = "broadwell";  /* Broadwell microserver */
Packit 5c3484
          else if (model == 0x57) cpu_64bit = 1,            modelstr = "knightslanding"; /* aka Xeon Phi */
Packit 5c3484
          else if (model == 0x5a) cpu_64bit = 1,            modelstr = "silvermont"; /* Silvermont */
Packit 5c3484
          else if (model == 0x5c) cpu_64bit = 1,            modelstr = "goldmont";   /* Goldmont */
Packit 5c3484
          else if (model == 0x5e) cpu_64bit = 1, cpu_avx=1, modelstr = "skylake";    /* Skylake */
Packit 5c3484
          else if (model == 0x5f) cpu_64bit = 1,            modelstr = "goldmont";   /* Goldmont */
Packit 5c3484
          else if (model == 0x8e) cpu_64bit = 1, cpu_avx=1, modelstr = "kabylake";   /* Kabylake Y/U */
Packit 5c3484
          else if (model == 0x9e) cpu_64bit = 1, cpu_avx=1, modelstr = "kabylake";   /* Kabylake desktop */
Packit 5c3484
          else                    cpu_64bit = 1,            modelstr = "nehalem";    /* default */
Packit 5c3484
Packit 5c3484
	  if (strcmp (modelstr, "haswell") == 0 ||
Packit 5c3484
	      strcmp (modelstr, "broadwell") == 0 ||
Packit 5c3484
	      strcmp (modelstr, "skylake") == 0)
Packit 5c3484
	    {
Packit 5c3484
	      /* Some haswell, broadwell, skylake lack BMI2.  Let them appear
Packit 5c3484
		 as sandybridge for now.  */
Packit 5c3484
	      CPUID (feature_string, 7);
Packit 5c3484
	      if ((feature_string[0 + 8 / 8] & (1 << (8 % 8))) == 0
Packit 5c3484
		  || gmp_workaround_skylake_cpuid_bug ())
Packit 5c3484
		modelstr = "sandybridge";
Packit 5c3484
	    }
Packit 5c3484
Packit 5c3484
	  break;
Packit 5c3484
	case 15:
Packit 5c3484
	  cpu_64bit = 1, modelstr = "pentium4";
Packit 5c3484
	  break;
Packit 5c3484
	}
Packit 5c3484
    }
Packit 5c3484
  else if (strcmp (vendor_string, "AuthenticAMD") == 0)
Packit 5c3484
    {
Packit 5c3484
      switch (family)
Packit 5c3484
	{
Packit 5c3484
	case 5:
Packit 5c3484
	  if (model <= 3)	modelstr = "k5";
Packit 5c3484
	  else if (model <= 7)	modelstr = "k6";
Packit 5c3484
	  else if (model == 8)	modelstr = "k62";
Packit 5c3484
	  else if (model == 9)	modelstr = "k63";
Packit 5c3484
	  else if (model == 10) modelstr = "geode";
Packit 5c3484
	  else if (model == 13) modelstr = "k63";
Packit 5c3484
	  break;
Packit 5c3484
	case 6:
Packit 5c3484
	  modelstr = "athlon";
Packit 5c3484
	  break;
Packit 5c3484
	case 15:		/* K8, K9 */
Packit 5c3484
	  cpu_64bit = 1, modelstr = "k8";
Packit 5c3484
	  break;
Packit 5c3484
	case 16:		/* K10 */
Packit 5c3484
	  cpu_64bit = 1, modelstr = "k10";
Packit 5c3484
	  break;
Packit 5c3484
	case 17:		/* Hybrid k8/k10, claim k8 */
Packit 5c3484
	  cpu_64bit = 1, modelstr = "k8";
Packit 5c3484
	  break;
Packit 5c3484
	case 18:		/* Llano, uses K10 core */
Packit 5c3484
	  cpu_64bit = 1, modelstr = "k10";
Packit 5c3484
	  break;
Packit 5c3484
	case 19:		/* AMD Internal, assume future K10 */
Packit 5c3484
	  cpu_64bit = 1, modelstr = "k10";
Packit 5c3484
	  break;
Packit 5c3484
	case 20:		/* Bobcat */
Packit 5c3484
	  cpu_64bit = 1, modelstr = "bobcat";
Packit 5c3484
	  break;
Packit 5c3484
	case 21:		/* Bulldozer */
Packit 5c3484
	  cpu_64bit = 1, cpu_avx = 1;
Packit 5c3484
	  if (model <= 1)
Packit 5c3484
	    modelstr = "bulldozer";
Packit 5c3484
	  else if (model < 0x20)	/* really 2, [0x10-0x20) */
Packit 5c3484
	    modelstr = "piledriver";
Packit 5c3484
	  else if (model < 0x40)	/* really [0x30-0x40) */
Packit 5c3484
	    modelstr = "steamroller";
Packit 5c3484
	  else				/* really [0x60-0x70) */
Packit 5c3484
	    modelstr = "excavator";
Packit 5c3484
	  break;
Packit 5c3484
	case 22:		/* Jaguar, an improved bobcat */
Packit 5c3484
	  cpu_64bit = 1, cpu_avx = 1, modelstr = "jaguar";
Packit 5c3484
	  break;
Packit 5c3484
	}
Packit 5c3484
    }
Packit 5c3484
  else if (strcmp (vendor_string, "CyrixInstead") == 0)
Packit 5c3484
    {
Packit 5c3484
      /* Should recognize Cyrix' processors too.  */
Packit 5c3484
    }
Packit 5c3484
  else if (strcmp (vendor_string, "CentaurHauls") == 0)
Packit 5c3484
    {
Packit 5c3484
      switch (family)
Packit 5c3484
	{
Packit 5c3484
	case 6:
Packit 5c3484
	  if (model < 9)	modelstr = "viac3";
Packit 5c3484
	  else if (model < 15)	modelstr = "viac32";
Packit 5c3484
	  else			cpu_64bit = 1, modelstr = "nano";
Packit 5c3484
	  break;
Packit 5c3484
	}
Packit 5c3484
    }
Packit 5c3484
Packit 5c3484
  CPUID (feature_string, 0x80000001);
Packit 5c3484
  cpuid_64bit = (feature_string[7] >> 5) & 1;
Packit 5c3484
Packit 5c3484
  suffix = "";
Packit 5c3484
Packit 5c3484
  if (cpuid_64bit && ! cpu_64bit)
Packit 5c3484
    /* If our cpuid-based CPU identification thinks this is a 32-bit CPU but
Packit 5c3484
       cpuid claims AMD64 capabilities, then revert to the generic "x86_64".
Packit 5c3484
       This is of course wrong, but it can happen in some virtualisers and
Packit 5c3484
       emulators, and this workaround allows for successful 64-bit builds.  */
Packit 5c3484
    modelstr = "x86_64";
Packit 5c3484
  else if (cpu_avx && ! (cpuid_avx && cpuid_osxsave))
Packit 5c3484
    /* For CPUs nominally capable of executing AVX, append "noavx" when not
Packit 5c3484
       both the AVX and OSXSAVE cpuid bits are set.  We tolerate weirdness
Packit 5c3484
       here, as some virtualisers set a broken cpuid state here, while other
Packit 5c3484
       virtualisers allow users to set a broken state.  */
Packit 5c3484
    suffix = "noavx";
Packit 5c3484
Packit 5c3484
  printf ("%s%s", modelstr, suffix);
Packit 5c3484
  return 0;
Packit 5c3484
}
Packit 5c3484
EOF
Packit 5c3484
Packit 5c3484
# The rcx/ecx zeroing here and in the variant below is needed for the BMI2
Packit 5c3484
# check.
Packit 5c3484
Packit 5c3484
  cat <<EOF >${dummy}0.s
Packit 5c3484
	.globl cpuid
Packit 5c3484
	.globl _cpuid
Packit 5c3484
cpuid:
Packit 5c3484
_cpuid:
Packit 5c3484
	push	%rbx
Packit 5c3484
	mov	%rdx, %r8
Packit 5c3484
	mov	%ecx, %eax
Packit 5c3484
	xor	%ecx, %ecx
Packit 5c3484
	.byte	0x0f
Packit 5c3484
	.byte	0xa2
Packit 5c3484
	mov	%ebx, (%r8)
Packit 5c3484
	mov	%edx, 4(%r8)
Packit 5c3484
	mov	%ecx, 8(%r8)
Packit 5c3484
	pop	%rbx
Packit 5c3484
	ret
Packit 5c3484
EOF
Packit 5c3484
Packit 5c3484
  if ($CC_FOR_BUILD ${dummy}0.s $dummy.c -o $dummy) >/dev/null 2>&1; then
Packit 5c3484
    # On 80386 and early 80486 cpuid is not available and will result in a
Packit 5c3484
    # SIGILL message, hence 2>/dev/null.
Packit 5c3484
    #
Packit 5c3484
    # On i386-unknown-freebsd4.9, "/bin/sh -c ./dummy" seems to send an
Packit 5c3484
    # "Illegal instruction (core dumped)" message to stdout, so we test $?
Packit 5c3484
    # to check if the program run was successful.
Packit 5c3484
    #
Packit 5c3484
    x=`$SHELL -c $dummy 2>/dev/null`
Packit 5c3484
    if test $? = 0 && test -n "$x"; then
Packit 5c3484
      exact_cpu=$x
Packit 5c3484
    fi
Packit 5c3484
  fi
Packit 5c3484
Packit 5c3484
  cat <<EOF >${dummy}0.s
Packit 5c3484
	.globl cpuid
Packit 5c3484
	.globl _cpuid
Packit 5c3484
cpuid:
Packit 5c3484
_cpuid:
Packit 5c3484
	pushl %esi
Packit 5c3484
	pushl %ebx
Packit 5c3484
	movl 24(%esp),%eax
Packit 5c3484
	xor	%ecx, %ecx
Packit 5c3484
	.byte 0x0f
Packit 5c3484
	.byte 0xa2
Packit 5c3484
	movl 20(%esp),%esi
Packit 5c3484
	movl %ebx,(%esi)
Packit 5c3484
	movl %edx,4(%esi)
Packit 5c3484
	movl %ecx,8(%esi)
Packit 5c3484
	popl %ebx
Packit 5c3484
	popl %esi
Packit 5c3484
	ret
Packit 5c3484
EOF
Packit 5c3484
Packit 5c3484
  if test -z "$exact_cpu"; then
Packit 5c3484
  if ($CC_FOR_BUILD ${dummy}0.s $dummy.c -o $dummy) >/dev/null 2>&1; then
Packit 5c3484
    # On 80386 and early 80486 cpuid is not available and will result in a
Packit 5c3484
    # SIGILL message, hence 2>/dev/null.
Packit 5c3484
    #
Packit 5c3484
    # On i386-unknown-freebsd4.9, "/bin/sh -c ./dummy" seems to send an
Packit 5c3484
    # "Illegal instruction (core dumped)" message to stdout, so we test $?
Packit 5c3484
    # to check if the program run was successful.
Packit 5c3484
    #
Packit 5c3484
    x=`$SHELL -c $dummy 2>/dev/null`
Packit 5c3484
    if test $? = 0 && test -n "$x"; then
Packit 5c3484
      exact_cpu=$x
Packit 5c3484
    fi
Packit 5c3484
  fi
Packit 5c3484
  fi
Packit 5c3484
Packit 5c3484
  # We need to remove some .o files here since lame C compilers
Packit 5c3484
  # generate these even when not asked.
Packit 5c3484
  ;;
Packit 5c3484
Packit 5c3484
s390*-*-*)
Packit 5c3484
  if test -f /proc/cpuinfo; then
Packit 5c3484
    model=`grep "^processor 0: version =" /proc/cpuinfo | sed -e 's/.*machine = //'`
Packit 5c3484
    case $model in
Packit 5c3484
      2064 | 2066) zcpu="z900" ;;
Packit 5c3484
      2084 | 2086) zcpu="z990" ;;
Packit 5c3484
      2094 | 2096) zcpu="z9"   ;;
Packit 5c3484
      2097 | 2098) zcpu="z10"  ;;
Packit 5c3484
      2817 | 2818 | *) zcpu="z196" ;;
Packit 5c3484
    esac
Packit 5c3484
    case "$guess_full" in
Packit 5c3484
      s390x-*-*) exact_cpu=${zcpu}    ;;
Packit 5c3484
      s390-*-*)  exact_cpu=${zcpu}esa ;;
Packit 5c3484
    esac
Packit 5c3484
  fi
Packit 5c3484
  ;;
Packit 5c3484
Packit 5c3484
esac
Packit 5c3484
Packit 5c3484
Packit 5c3484
Packit 5c3484
# -------------------------------------------------------------------------
Packit 5c3484
# Use an exact cpu, if possible
Packit 5c3484
Packit 5c3484
if test -n "$exact_cpu"; then
Packit 5c3484
  echo "$exact_cpu$guess_rest"
Packit 5c3484
else
Packit 5c3484
  echo "$guess_full"
Packit 5c3484
fi
Packit 5c3484
exit 0
Packit 5c3484
Packit 5c3484
Packit 5c3484
Packit 5c3484
# Local variables:
Packit 5c3484
# fill-column: 76
Packit 5c3484
# End: