Update cpuflags to 1.10:

Refactor cpuflags into a common part (cpuflags.sh), which calls the
appropriate per OS (subr_NetBSD, subr_SunOS or subr_Linux) and per
compiler (subr_gcc) portions
This commit is contained in:
abs 2007-08-20 11:21:19 +00:00
parent 80b8a5c96a
commit 140b25e6c8
10 changed files with 481 additions and 557 deletions

View file

@ -1,7 +1,7 @@
# $NetBSD: Makefile,v 1.112 2007/08/13 10:31:06 abs Exp $
# $NetBSD: Makefile,v 1.113 2007/08/20 11:21:19 abs Exp $
#
DISTNAME= cpuflags-1.09
DISTNAME= cpuflags-1.10
CATEGORIES= sysutils
MASTER_SITES= # empty
DISTFILES= # empty
@ -17,6 +17,6 @@ NO_CONFIGURE= yes
do-extract:
${MKDIR} ${WRKSRC}
${CP} ${FILESDIR}/Makefile ${FILESDIR}/*.* ${WRKSRC}
${CP} ${FILESDIR}/Makefile ${FILESDIR}/[a-z]* ${WRKSRC}
.include "../../mk/bsd.pkg.mk"

View file

@ -1,5 +1,10 @@
@comment $NetBSD: PLIST,v 1.2 2003/05/29 11:45:50 abs Exp $
@comment $NetBSD: PLIST,v 1.3 2007/08/20 11:21:20 abs Exp $
bin/cpuflags
man/man1/cpuflags.1
share/cpuflags/subr_Linux
share/cpuflags/subr_NetBSD
share/cpuflags/subr_SunOS
share/cpuflags/subr_gcc
share/mk/cpuflags.mk
share/mk/optimize_gcc.mk
@dirrm share/cpuflags

View file

@ -1,12 +1,13 @@
# $Id: Makefile,v 1.7 2006/02/09 13:45:04 abs Exp $
# $Id: Makefile,v 1.8 2007/08/20 11:21:20 abs Exp $
VERSION=0.98
VERSION=1.10
PREFIX?=/usr/local
OPSYS?=`uname`
MANDIR?=${PREFIX}/man/man1
MKDIR?=${PREFIX}/share/mk
SUBRDIR?=${PREFIX}/share/cpuflags
SHAREMKDIR?=${PREFIX}/share/mk
BINDIR?=${PREFIX}/bin
INSTALL?=install
SED?=sed
@ -14,19 +15,21 @@ SED?=sed
all:
${SED} -e 's|@PREFIX@|${PREFIX}|g' cpuflags.1 > cpuflags.1.out
${SED} -e 's|@PREFIX@|${PREFIX}|g' cpuflags.mk > cpuflags.mk.out
${SED} -e 's|@PREFIX@|${PREFIX}|g' cpuflags.sh > cpuflags.sh.out
clean:
rm -rf *.out out
rm -rf *.out DIST
install:
mkdir -p ${BINDIR} ${MANDIR} ${MKDIR}
${INSTALL} cpuflags.${OPSYS} ${BINDIR}/cpuflags
mkdir -p ${BINDIR} ${MANDIR} ${SHAREMKDIR} ${SUBRDIR}
${INSTALL} cpuflags.sh.out ${BINDIR}/cpuflags
${INSTALL} cpuflags.1.out ${MANDIR}/cpuflags.1
${INSTALL} optimize_gcc.mk ${MKDIR}/optimize_gcc.mk
${INSTALL} cpuflags.mk.out ${MKDIR}/cpuflags.mk
${INSTALL} optimize_gcc.mk ${SHAREMKDIR}/optimize_gcc.mk
${INSTALL} cpuflags.mk.out ${SHAREMKDIR}/cpuflags.mk
${INSTALL} subr_* ${SUBRDIR}
dist:
mkdir -p out/cpuflags-${VERSION}
cp Makefile *.* out/cpuflags-${VERSION}
(cd out;pax -w cpuflags-${VERSION} | bzip2 -9 > cpuflags-${VERSION}.tbz)
rm -rf out/cpuflags-${VERSION}
mkdir -p DIST/cpuflags-${VERSION}
cp Makefile [a-z]* DIST/cpuflags-${VERSION}
(cd DIST;pax -w cpuflags-${VERSION}|bzip2 -9 > cpuflags-${VERSION}.tbz)
rm -rf DIST/cpuflags-${VERSION}

View file

@ -1,169 +0,0 @@
#!/bin/sh
# $NetBSD: cpuflags.Linux,v 1.22 2007/03/21 15:05:08 abs Exp $
PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
AWK=awk
display_hw_details()
{
echo " OS : '$(uname)'"
echo " proc model : '$hw_model'"
echo " machine_arch : '$hw_machine_arch'"
echo " proc flags : '$hw_flags'"
}
hw_machine_arch=$(uname -m)
if [ ! -f /proc/cpuinfo ] ; then
echo "Unable to open /proc/cpuinfo"
hw_model=Unknown
else
hw_model=$($AWK -F: '/^model name/{sub(" ","",$2);print $2;exit}' /proc/cpuinfo)
hw_flags=$($AWK -F: '/^flags/{sub(" ","",$2);print $2;exit}' /proc/cpuinfo)
fi
case $hw_machine_arch in
parisc) case $hw_model in
"Mirage 100+") FLAGS='-march=1.1' ;;
esac ;;
i386) FLAGS='-march=i386' ;;
i486) FLAGS='-march=i486' ;;
i686) case $hw_model in
"AMD Athlon(TM) XP "*) FLAGS='-march=athlon-xp' ;;
"AMD Athlon(tm) XP "*) FLAGS='-march=athlon-xp' ;;
"AMD Duron(TM)") FLAGS='-march=athlon' ;;
"AMD Duron(tm) ") FLAGS='-march=athlon' ;;
"Pentium II (Deschutes)") FLAGS='-march=pentium2' ;;
"Celeron (Coppermine)") FLAGS='-march=pentium3' ;;
"Intel(R) Pentium(R) 4 CPU "*) FLAGS='-march=pentium4' ;;
"Intel(R) Pentium(R) III Mobile CPU"*) FLAGS='-march=pentium3m' ;;
"Intel(R) Pentium(R) M processor"*) FLAGS='-march=pentium3m' ;;
"Mobile Intel(R) Pentium(R) 4 - M "*) FLAGS='-march=pentium4m' ;;
"Pentium III (Coppermine)") FLAGS='-march=pentium3' ;;
"Pentium III (Katmai)") FLAGS='-march=pentium3' ;;
"AMD Athlon(tm) 64"*) FLAGS='-march=athlon-xp' ;;
"AMD Opteron(tm) Processor "*) FLAGS='-march=opteron' ;;
"Intel(R) Celeron(R) CPU "* | "Intel(R) Xeon(TM) CPU "*)
case "$hw_flags" in
*" sse2 "*)
FLAGS='-march=pentium4' ;;
esac
esac ;;
esac
############
# Everything from this point common between all cpuflags variants.
if [ "$1" = -v ] ; then
shift
opt_v=1
fi
if [ -n "$1" ]; then
CC=$1
else
CC=gcc
fi
if [ -n "$opt_v" ] ; then
if [ -n "$FLAGS" ]; then
echo "CPUFLAGS=$FLAGS"
elif [ -z "$NONE" ] ; then
echo "CPUFLAGS=Unknown"
else
echo "CPUFLAGS=None"
fi
display_hw_details
exit
fi
if [ -z "$FLAGS" -a -z "$NONE" ] ; then
echo 'Unknown machine - please send details to abs@absd.org' >&2
display_hw_details >&2
fi
# Fixup options for older gccs.
# Entries can be recursive - eg:
# -march=k6-3 -> -march=k6 -> -march=pentium -> -march=i486
#
# The format of table is
# gcc_version_in_which_option_was_introduced new_option old_option
if [ -n "$FLAGS" ]; then
gcc_ver=`${CC} -dumpversion | sed 's/^egcs-//'`
FLAGS=`$AWK -F: -v "flags=$FLAGS" -v "gcc_ver=$gcc_ver" '
{ if (gcc_ver < $1){map[$2] = ""$3} }
END { while (flags in map) {flags = map[flags]} print flags }
' <<EOD
2.90:-march=i386:-mno-486
2.90:-march=i486:-m486
2.90:-march=pentium:-m486
2.90:-march=pentiumpro:-m486
2.90:-mcpu=21164a:
2.90:-mcpu=arm610:-m6
2.90:-mcpu=arm710:-m6
2.90:-mcpu=cypress:-mcypress
2.90:-mcpu=sparclite:-msparclite
2.90:-mcpu=strongarm110:-m6
2.90:-mcpu=supersparc:-msupersparc
2.90:-mcpu=v9:-mv8
2.95:-march=k6:-march=pentium
3.0:-march=athlon:-march=pentiumpro
3.1:-march=athlon-4:-march=athlon
3.1:-march=athlon-mp:-march=athlon
3.1:-march=athlon-tbird:-march=athlon
3.1:-march=athlon-xp:-march=athlon
3.1:-march=k6-2:-march=k6
3.1:-march=k6-3:-march=k6
3.1:-march=pentium-mmx:-march=pentium
3.1:-march=pentium2:-march=pentiumpro
3.1:-march=pentium3 -mno-sse:-march=pentiumpro
3.1:-march=pentium3:-march=pentiumpro
3.1:-march=pentium4:-march=pentiumpro
3.1:-march=r2000:-cpu=r2000
3.1:-march=r3000:-cpu=r3000
3.1:-march=r3900:-cpu=r3900
3.1:-march=r4000:-cpu=r4000
3.1:-march=r4100:-cpu=r4100
3.1:-march=r4300:-cpu=r4300
3.1:-march=r4400:-cpu=r4400
3.1:-march=r4600:-cpu=r4600
3.1:-march=r5000:-cpu=r5000
3.1:-march=r6000:-cpu=r6000
3.1:-march=r8000:-cpu=r8000
3.1:-mcpu=21264a:-mcpu=21264
3.1:-mcpu=7400:-mcpu=750
3.1:-mcpu=7450:-mcpu=750
3.1:-mfpmath=sse:
3.1:-msse2:
3.1:-msse:
3.1:-mtune=r2000:-cpu=r2000
3.1:-mtune=r3000:-cpu=r3000
3.1:-mtune=r3900:-cpu=r3900
3.1:-mtune=r4000:-cpu=r4000
3.1:-mtune=r4100:-cpu=r4100
3.1:-mtune=r4300:-cpu=r4300
3.1:-mtune=r4400:-cpu=r4400
3.1:-mtune=r4600:-cpu=r4600
3.1:-mtune=r5000:-cpu=r5000
3.1:-mtune=r6000:-cpu=r6000
3.1:-mtune=r8000:-cpu=r8000
3.3:-march=c3:-march=i586
3.3:-march=winchip-c6:-march=i586
3.3:-march=winchip2:-march=i586
3.4:-march=athlon-fx:-march=athlon-xp
3.4:-march=athlon64:-march=athlon-xp
3.4:-march=c3-2:-march=c3
3.4:-march=k8:-march=athlon-xp
3.4:-march=nocona:-march=pentium4
3.4:-march=opteron:-march=athlon-xp
3.4:-march=pentium-m:-march=pentium3
3.4:-march=pentium3m:-march=pentium3
3.4:-march=pentium4m:-march=pentium4
3.4:-march=prescott:-march=pentium4
EOD
`
fi
echo $FLAGS
exit 0

View file

@ -1,307 +0,0 @@
#!/bin/sh
# $NetBSD: cpuflags.NetBSD,v 1.69 2007/04/24 22:44:20 abs Exp $
PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
AWK=awk
display_hw_details()
{
echo " OS : '$(uname)'"
echo " hw.model : '$hw_model'"
echo " hw.machine : '$hw_machine'"
echo " hw.machine_arch : '$hw_machine_arch'"
echo " cpu details :"
sed -n -e 's/^/ /' -e '/^ cpu/p' /var/run/dmesg.boot
}
hw_model=$(sysctl -n hw.model)
hw_machine=$(sysctl -n hw.machine)
hw_machine_arch=$(sysctl -n hw.machine_arch)
# We're almost certainly crosscompiling
if [ -n "$MACHINE" -a $hw_machine != "$MACHINE" ]; then
echo
exit
fi
# When adding $hw_model tests use maximum context (such as trailing space)
case $hw_machine_arch in
alpha)
# cpu0 at mainbus0: ID 0 (primary), 21164A-0 (unknown ...
case "$(egrep '^cpu0 ' /var/run/dmesg.boot)" in
*[\(\ ]2106[46][-A\ \)]*) FLAGS="-mcpu=21064" ;;
*[\(\ ]21164[-\ \)]*) FLAGS="-mcpu=21164" ;;
*[\(\ ]21164A[-\ \)]*) FLAGS="-mcpu=21164a" ;;
*[\(\ ]21264[-\ \)]*) FLAGS="-mcpu=21264" ;;
*[\(\ ]21264[AB][-\ \)]*) FLAGS="-mcpu=21264a" ;;
*\ PCA56-2) FLAGS="-mcpu=21164pc" ;;
esac
;;
arm | arm32) case $hw_model in
ARM610*) FLAGS="-mcpu=arm610" ;; # risc pc
ARM710*) FLAGS="-mcpu=arm710" ;; # risc pc
i80321\ *) FLAGS="-mcpu=xscale" ;; # iyonix
SA-110*)
case $hw_machine in # arm32 split post 1.5
cats|shark|hpcarm|netwinder)
FLAGS="-mcpu=strongarm110" ;;
acorn32)
FLAGS="-march=armv3m -mtune=strongarm" ;;
*)
# memorybus in strongarm risc pc machines cannot support
# certain strongarm instructions, but in 1.5 and earlier
# all strongarm machines are 'arm32', so uname and sysctl
# no use
if egrep -q 'ofbus0|footbridge0' /var/run/dmesg.boot \
2>/dev/null ; then
FLAGS="-mcpu=strongarm110" # shark/cats
else
FLAGS="-march=armv3m -mtune=strongarm" # risc pc
fi
esac ;;
esac ;;
hppa)
case "$(egrep '^cpu0 ' /var/run/dmesg.boot)" in
*\ PA7100\ *) FLAGS="-march=1.1 -mschedule=7100" ;; # untested
*\ PA7150\ *) FLAGS="-march=1.1 -mschedule=7100" ;; # untested
*\ PA7100LC\ *) FLAGS="-march=1.1 -mschedule=7100LC" ;; # untested
*\ PA7200\ *) FLAGS="-march=1.1 -mschedule=7200" ;; # untested
*\ PA7300LC\ *) FLAGS="-march=1.1 -mschedule=7300" ;; # B180L
*\ PA8*) FLAGS="-march=2.0 -mschedule=8000" ;; # untested
esac
;;
i386 | x86_64)
case $hw_model in
*Intel\ Pentium/MMX\ *) FLAGS='-march=pentium-mmx' ;;
*Intel\ Pentium\ II\ *) FLAGS='-march=pentium2' ;;
*Intel\ Pentium\ III\ *) FLAGS='-march=pentium3' ;;
*Intel\ Mobile\ Pentium\ III\ *) FLAGS='-march=pentium3' ;;
*Intel\ Celeron\ \(Mendocino\)\ *) FLAGS='-march=pentium3 -mno-sse' ;;
*Intel\ Pentium\ M\ \(\Dothan\)\ *) FLAGS='-march=pentium-m' ;;
*Intel\ Pentium\ M\ *) FLAGS='-march=pentium-m' ;;
*Intel\ Mobile\ Pentium\ 4\ *) FLAGS='-march=pentium4m' ;;
*Intel\ Pentium\ 4\ *) FLAGS='-march=pentium4' ;;
*Intel\(R\)\ Pentium\(R\)\ D*) FLAGS='-march=nocona' ;;
*VIA\ C3*\ *) FLAGS='-march=c3' ;;
*AMD\ K6-III*) FLAGS='-march=k6-3' ;;
*AMD\ K6-2*) FLAGS='-march=k6-2' ;;
*AMD\ K6*) FLAGS='-march=k6' ;;
*AMD\ Duron*) FLAGS='-march=athlon' ;;
*AMD\ Athlon\ 4*) FLAGS='-march=athlon-4' ;;
*AMD\ Athlon\ Model\ 4\ \(Thunderbird\)*) FLAGS='-march=athlon-tbird';;
*AMD\ Athlon\ MP*) FLAGS='-march=athlon-mp' ;;
*AMD\ K7\ \(Athlon\)\ XP\ *) FLAGS='-march=athlon-xp' ;;
*AMD\ Athlon\ XP\ *) FLAGS='-march=athlon-xp' ;;
*AMD\ K7*|*AMD\ Athlon*) FLAGS='-march=athlon' ;;
*AMD\ Unknown\ K7\ \(Athlon\)*) FLAGS='-march=athlon' ;;
*AMD\ Opteron\(tm\)\ Processor*) FLAGS='-march=opteron' ;;
*AMD\ Turion\(tm\)\ 64\ Mobile*) FLAGS='-march=athlon64' ;;
*386-class*) FLAGS='-march=i386' ;;
*486-class*) FLAGS='-march=i486' ;;
*586-class*) FLAGS='-march=pentium' ;;
*686-class*) FLAGS='-march=pentiumpro' ;;
esac
if [ -n "$FLAGS" -a "$hw_machine_arch" = i386 ] ; then
if [ "$(sysctl -n machdep.sse2)" = 1 ] ; then
FLAGS="$FLAGS -mfpmath=sse -msse2"
elif [ "$(sysctl -n machdep.sse)" = 1 ] ; then
FLAGS="$FLAGS -mfpmath=sse -msse"
fi
fi
;;
m68k) case $hw_model in # Examples
*\(68020*|*\ MC68020\ *) FLAGS='-m68020' ;; # Untested
*\(68030*|*\ MC68030\ *) FLAGS='-m68030' ;; # Mac LC III
*\(68040*|*\ MC68040\ *) FLAGS='-m68040' ;; # Untested
*\(68060*|*\ MC68060\ *) FLAGS='-m68060' ;; # Upgr amiga 3000
esac
case "$(egrep '^fpu0 ' /var/run/dmesg.boot)" in
*\(emulator\)*) FLAGS="$FLAGS -msoft-float" ;;
*\(no\ math\ support\)*) FLAGS="$FLAGS -msoft-float" ;;
esac
;;
mipseb|mipsel)
# cpu0 at mainbus0: QED R4600 Orion CPU (0x2020) Rev. 2.0 with ...
case $hw_model in
Infineon\ ADM5120) FLAGS='-march=4kc' ;;
*)
case "$(egrep '^cpu0 ' /var/run/dmesg.boot)" in
*\ MIPS\ R2000\ *) FLAGS="-march=r2000" ;;
*\ MIPS\ R3000\ *) FLAGS="-march=r3000" ;;
*\ MIPS\ R3000A\ *) FLAGS="-march=r3000" ;;
*\ Toshiba\ TX3912\ *) FLAGS="-march=r3900" ;;
*\ Toshiba\ TX392[27]\ *) FLAGS="-march=r3900" ;;
*\ MIPS\ R4000\ *) FLAGS="-mtune=r4000 -mips2" ;; # mips3
*\ MIPS\ R4400\ *) FLAGS="-mtune=r4400 -mips2" ;; # mips3
*\ NEC\ VR4100\ *) FLAGS="-mtune=r4100 -mips2" ;; # mips3
*\ NEC\ VR4300\ *) FLAGS="-mtune=r4300 -mips2" ;; # mips3
*\ QED\ R4600\ *) FLAGS="-mtune=r4600 -mips2" ;; # mips3
*\ MIPS\ R5000\ *) FLAGS="-mtune=r5000 -mips2" ;; # mips4
*\ QED\ RM5200\ *) FLAGS="-mtune=r5000 -mips2" ;; # mips4
*\ MIPS\ R6000\ *) FLAGS="-mtune=r6000 -mips2" ;;
*\ MIPS\ R8000\ *) FLAGS="-mtune=r8000 -mips2" ;; # mips4
esac ;;
esac
;;
powerpc) case $hw_model in # Examples
601\ *) FLAGS='-mcpu=601' ;; # Untested
602\ *) FLAGS='-mcpu=602' ;; # Untested
603\ *) FLAGS='-mcpu=603' ;; # Untested
603e\ *|603ev\ *) FLAGS='-mcpu=603e' ;; # Umax C500 / PM4400
604\ *) FLAGS='-mcpu=604' ;; # Mac 8500
604e\ *) FLAGS='-mcpu=604e' ;; # upgr B&W G3
604ev\ *) FLAGS='-mcpu=604e' ;; # usually 604e
620\ *) FLAGS='-mcpu=620' ;; # Untested
7400\ *) FLAGS='-mcpu=7400' ;; # AGP G4/400 Mac
740\ *) FLAGS='-mcpu=740' ;; # Untested
7410\ *) FLAGS='-mcpu=7400' ;; # powerbook g4
7447A\ *) FLAGS='-mcpu=7450' ;; #
7450\ *) FLAGS='-mcpu=7450' ;; # tibook 550
750\ *) FLAGS='-mcpu=750' ;; # orig. iBook
esac ;;
sparc | sparc64) case " $hw_model" in # Examples
*[\ \(]MB86900/1A*) FLAGS='-mcpu=cypress' ;; # ss1+
*[\ \(]L64811*) FLAGS='-mcpu=cypress' ;; # sun4/sun4c
*[\ \(]CY7C601*) FLAGS='-mcpu=cypress' ;; # ss2
*[\ \(]W8601/8701*) FLAGS='-mcpu=cypress' ;; # elc
*[\ \(]MB86904*) FLAGS='-mcpu=supersparc' ;; # ss5 usparc
*[\ \(]MB86907*) FLAGS='-mcpu=supersparc' ;; # ss5 usparc
*[\ \(]TMS390S10*) FLAGS='-mcpu=supersparc' ;; # classic "
*[\ \(]TMS390Z50*) FLAGS='-mcpu=supersparc' ;; # ss10/ss20
*[\ \(]RT620/625*) FLAGS='-mcpu=hypersparc' ;; # ss20 ross
*[\ \(]MB86930*) FLAGS='-mcpu=sparclite' ;; # from gcc
*[\ \(]MB86934*) FLAGS='-mcpu=sparclite' ;; # from gcc
# under 1.5.1 -mcpu=ultrasparc chokes egcs-2.91.66 compiling perl
*[\ \(]SUNW,UltraSPARC*) FLAGS='-mcpu=v9' ;; # Ultra
esac ;;
vax) # No VAX specific gcc optimisations available
NONE=1
;;
esac
############
# Everything from this point common between all cpuflags variants.
if [ "$1" = -v ] ; then
shift
opt_v=1
fi
if [ -n "$1" ]; then
CC=$1
else
CC=gcc
fi
if [ -n "$opt_v" ] ; then
if [ -n "$FLAGS" ]; then
echo "CPUFLAGS=$FLAGS"
elif [ -z "$NONE" ] ; then
echo "CPUFLAGS=Unknown"
else
echo "CPUFLAGS=None"
fi
display_hw_details
exit
fi
if [ -z "$FLAGS" -a -z "$NONE" ] ; then
echo 'Unknown machine - please send details to abs@absd.org' >&2
display_hw_details >&2
fi
# Fixup options for older gccs.
# Entries can be recursive - eg:
# -march=k6-3 -> -march=k6 -> -march=pentium -> -march=i486
#
# The format of table is
# gcc_version_in_which_option_was_introduced new_option old_option
if [ -n "$FLAGS" ]; then
gcc_ver=`${CC} -dumpversion | sed 's/^egcs-//'`
FLAGS=`$AWK -F: -v "flags=$FLAGS" -v "gcc_ver=$gcc_ver" '
{ if (gcc_ver < $1){map[$2] = ""$3} }
END { while (flags in map) {flags = map[flags]} print flags }
' <<EOD
2.90:-march=i386:-mno-486
2.90:-march=i486:-m486
2.90:-march=pentium:-m486
2.90:-march=pentiumpro:-m486
2.90:-mcpu=21164a:
2.90:-mcpu=arm610:-m6
2.90:-mcpu=arm710:-m6
2.90:-mcpu=cypress:-mcypress
2.90:-mcpu=sparclite:-msparclite
2.90:-mcpu=strongarm110:-m6
2.90:-mcpu=supersparc:-msupersparc
2.90:-mcpu=v9:-mv8
2.95:-march=k6:-march=pentium
3.0:-march=athlon:-march=pentiumpro
3.1:-march=athlon-4:-march=athlon
3.1:-march=athlon-mp:-march=athlon
3.1:-march=athlon-tbird:-march=athlon
3.1:-march=athlon-xp:-march=athlon
3.1:-march=k6-2:-march=k6
3.1:-march=k6-3:-march=k6
3.1:-march=pentium-mmx:-march=pentium
3.1:-march=pentium2:-march=pentiumpro
3.1:-march=pentium3 -mno-sse:-march=pentiumpro
3.1:-march=pentium3:-march=pentiumpro
3.1:-march=pentium4:-march=pentiumpro
3.1:-march=r2000:-cpu=r2000
3.1:-march=r3000:-cpu=r3000
3.1:-march=r3900:-cpu=r3900
3.1:-march=r4000:-cpu=r4000
3.1:-march=r4100:-cpu=r4100
3.1:-march=r4300:-cpu=r4300
3.1:-march=r4400:-cpu=r4400
3.1:-march=r4600:-cpu=r4600
3.1:-march=r5000:-cpu=r5000
3.1:-march=r6000:-cpu=r6000
3.1:-march=r8000:-cpu=r8000
3.1:-mcpu=21264a:-mcpu=21264
3.1:-mcpu=7400:-mcpu=750
3.1:-mcpu=7450:-mcpu=750
3.1:-mfpmath=sse:
3.1:-msse2:
3.1:-msse:
3.1:-mtune=r2000:-cpu=r2000
3.1:-mtune=r3000:-cpu=r3000
3.1:-mtune=r3900:-cpu=r3900
3.1:-mtune=r4000:-cpu=r4000
3.1:-mtune=r4100:-cpu=r4100
3.1:-mtune=r4300:-cpu=r4300
3.1:-mtune=r4400:-cpu=r4400
3.1:-mtune=r4600:-cpu=r4600
3.1:-mtune=r5000:-cpu=r5000
3.1:-mtune=r6000:-cpu=r6000
3.1:-mtune=r8000:-cpu=r8000
3.3:-march=c3:-march=i586
3.3:-march=winchip-c6:-march=i586
3.3:-march=winchip2:-march=i586
3.4:-march=athlon-fx:-march=athlon-xp
3.4:-march=athlon64:-march=athlon-xp
3.4:-march=c3-2:-march=c3
3.4:-march=k8:-march=athlon-xp
3.4:-march=nocona:-march=pentium4
3.4:-march=opteron:-march=athlon-xp
3.4:-march=pentium-m:-march=pentium3
3.4:-march=pentium3m:-march=pentium3
3.4:-march=pentium4m:-march=pentium4
3.4:-march=prescott:-march=pentium4
EOD
`
fi
echo $FLAGS
exit 0

View file

@ -0,0 +1,85 @@
#!/bin/sh
# $NetBSD: cpuflags.sh,v 1.1 2007/08/20 11:21:21 abs Exp $
PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
include()
{
file=$1
if [ -f ./$file ] ; then
file=./$file
else
file=@PREFIX@/share/cpuflags/$file
fi
verbose . $file
. $file
}
verbose()
{
[ -n "$opt_v" ] && echo $* >&2
}
UNAME=$(uname)
if [ "$1" = -v ] ; then
shift
opt_v=1
fi
if [ -n "$1" ]; then
CC=$1
else
CC=gcc
fi
# Each UNAME subr_ file is expected to set AWK & SED, and to provide the
# following methods:
# extract_hw_details: Must be called before determine_arch/determine_features
# determine_arch: Returns cpu arch
# determine_features: Returns cpu features
# display_hw_details: Human readable output for current machine
#
include subr_${UNAME}
# This provides gcc_ser(), gcc_ver() and gcc_fixup_arch_flags()
#
include subr_gcc
# Determine the flags for this OS/machine
extract_hw_details
if [ $(gcc_ser $CC) -gt 4002 ] ; then
ARCH='-march=native'
else
ARCH=$(determine_arch)
fi
FEATURES=$(determine_features)
# Fixup any flags which are too new for our gcc version
#
CPUFLAGS="$(gcc_fixup_arch_flags $CC $ARCH $FEATURES)"
CPUFLAGS="$(echo $CPUFLAGS)"
if [ -n "$opt_v" ] ; then
if [ -n "$NOARCH" ] ; then
ARCH="No flags for this architecture"
fi
if [ -z "$ARCH" ]; then
ARCH=Unknown
fi
cat <<END
ARCH : $ARCH
FEATURES : $FEATURES
CPUFLAGS : $CPUFLAGS
GCC version : $(gcc_ver $CC)
END
display_hw_details
exit;
fi
if [ -z "$ARCH" -a -z "$NOARCH" ] ; then
echo 'Unknown machine - please send details to abs@absd.org' >&2
display_hw_details >&2
fi
echo $CPUFLAGS
exit 0

83
devel/cpuflags/files/subr_Linux Executable file
View file

@ -0,0 +1,83 @@
# $NetBSD: subr_Linux,v 1.1 2007/08/20 11:21:21 abs Exp $
AWK=awk
SED=sed
display_hw_details()
{
cat <<END
OS : '$(uname)'
proc model : '$hw_model'
machine_arch : '$hw_machine_arch'
proc flag : '$feat_flags'
END
}
extract_hw_details()
{
hw_machine_arch=$(uname -m)
if [ ! -f /proc/cpuinfo ] ; then
echo "Unable to open /proc/cpuinfo"
hw_model=Unknown
else
hw_model=$($AWK -F: '/^model name/{sub(" ","",$2);print $2;exit}' /proc/cpuinfo)
feat_flags=$($AWK -F: '/^flags/{sub(" ","",$2);print $2;exit}' /proc/cpuinfo)
fi
}
determine_arch()
{
ARCH=
case $hw_machine_arch in
parisc) case $hw_model in
"Mirage 100+") ARCH='-march=1.1' ;;
esac ;;
i386) ARCH='-march=i386' ;;
i486) ARCH='-march=i486' ;;
i586) ARCH='-march=pentium' ;;
i686) case $hw_model in
"AMD Athlon(TM) XP "*) ARCH='-march=athlon-xp' ;;
"AMD Athlon(tm) XP"*) ARCH='-march=athlon-xp' ;;
"AMD Duron(TM)") ARCH='-march=athlon' ;;
"AMD Duron(tm) ") ARCH='-march=athlon' ;;
"Pentium II (Deschutes)") ARCH='-march=pentium2' ;;
"Celeron (Coppermine)") ARCH='-march=pentium3' ;;
"Intel(R) Pentium(R) 4 CPU "*) ARCH='-march=pentium4' ;;
"Intel(R) Pentium(R) III Mobile CPU"*) ARCH='-march=pentium3m' ;;
"Intel(R) Pentium(R) M processor"*) ARCH='-march=pentium3m' ;;
"Mobile Intel(R) Pentium(R) 4 - M "*) ARCH='-march=pentium4m' ;;
"Pentium III (Coppermine)") ARCH='-march=pentium3' ;;
"Pentium III (Katmai)") ARCH='-march=pentium3' ;;
"AMD Athlon(tm) 64"*) ARCH='-march=athlon-xp' ;;
"AMD Opteron(tm) Processor "*) ARCH='-march=opteron' ;;
"Intel(R) Celeron(R) CPU "* | "Intel(R) Xeon(TM) CPU "*)
case "$feat_flags" in
*" sse2 "*)
ARCH='-march=pentium4' ;;
esac;;
"AMD Sempron(tm) Processor "*) ARCH='-march=athlon-xp' ;;
"Intel(R) Core(TM)2 CPU "*) ARCH='-march=prescott' ;;
esac ;;
x86_64) case $hw_model in
"AMD Sempron(tm) Processor "*) ARCH='-march=athlon64' ;;
"AMD Athlon(tm) 64"*) ARCH='-march=athlon64' ;;
"Intel(R) Core(TM)2 CPU "*) ARCH='-march=nocona' ;;
esac ;;
esac
echo $ARCH
}
determine_features()
{
FEATURES=
case $hw_machine_arch in
i586|i686|x86_64)
case " $feat_flags " in
*" ssse3 "*) FEATURES='-mfpmath=sse -msse3' ;;
*" sse2 "*) FEATURES='-mfpmath=sse -msse2' ;;
*" sse "*) FEATURES='-mfpmath=sse -msse' ;;
*" mmx "*) FEATURES='-mmmx' ;;
esac ;;
esac
echo $FEATURES
}

222
devel/cpuflags/files/subr_NetBSD Executable file
View file

@ -0,0 +1,222 @@
# $NetBSD: subr_NetBSD,v 1.1 2007/08/20 11:21:21 abs Exp $
AWK=awk
SED=sed
display_hw_details()
{
cat <<END
OS : '$(uname)'
hw.model : '$hw_model'
hw.machine : '$hw_machine'
hw.machine_arch : '$hw_machine_arch'
cpu details :
END
sed -n -e 's/^/ /' -e '/^ cpu/p' /var/run/dmesg.boot
}
extract_hw_details()
{
hw_model=$(sysctl -n hw.model)
hw_machine=$(sysctl -n hw.machine)
hw_machine_arch=$(sysctl -n hw.machine_arch)
# We're almost certainly crosscompiling
if [ -n "$MACHINE" -a $hw_machine != "$MACHINE" ]; then
echo
exit
fi
}
determine_arch()
{
ARCH=
# When adding $hw_model tests use maximum context (such as trailing space)
case $hw_machine_arch in
alpha)
# cpu0 at mainbus0: ID 0 (primary), 21164A-0 (unknown ...
case "$(egrep '^cpu0 ' /var/run/dmesg.boot)" in
*[\(\ ]2106[46][-A\ \)]*) ARCH="-mcpu=21064" ;;
*[\(\ ]21164[-\ \)]*) ARCH="-mcpu=21164" ;;
*[\(\ ]21164A[-\ \)]*) ARCH="-mcpu=21164a" ;;
*[\(\ ]21264[-\ \)]*) ARCH="-mcpu=21264" ;;
*[\(\ ]21264[AB][-\ \)]*) ARCH="-mcpu=21264a" ;;
*\ PCA56-2) ARCH="-mcpu=21164pc" ;;
esac
;;
arm | arm32) case $hw_model in
ARM610*) ARCH="-mcpu=arm610" ;; # risc pc
ARM710*) ARCH="-mcpu=arm710" ;; # risc pc
i80321\ *) ARCH="-mcpu=xscale" ;; # iyonix
SA-110*)
case $hw_machine in # arm32 split post 1.5
cats|shark|hpcarm|netwinder)
ARCH="-mcpu=strongarm110" ;;
acorn32)
ARCH="-march=armv3m -mtune=strongarm" ;;
*)
# memorybus in strongarm risc pc machines cannot support
# certain strongarm instructions, but in 1.5 and earlier
# all strongarm machines are 'arm32', so uname and sysctl
# no use
if egrep -q 'ofbus0|footbridge0' /var/run/dmesg.boot \
2>/dev/null ; then
ARCH="-mcpu=strongarm110" # shark/cats
else
ARCH="-march=armv3m -mtune=strongarm" # risc pc
fi
esac ;;
esac ;;
hppa)
case "$(egrep '^cpu0 ' /var/run/dmesg.boot)" in
*\ PA7100\ *) ARCH="-march=1.1 -mschedule=7100" ;; # untested
*\ PA7150\ *) ARCH="-march=1.1 -mschedule=7100" ;; # untested
*\ PA7100LC\ *) ARCH="-march=1.1 -mschedule=7100LC" ;; # untested
*\ PA7200\ *) ARCH="-march=1.1 -mschedule=7200" ;; # untested
*\ PA7300LC\ *) ARCH="-march=1.1 -mschedule=7300" ;; # B180L
*\ PA8*) ARCH="-march=2.0 -mschedule=8000" ;; # untested
esac
;;
i386 | x86_64)
case $hw_model in
*Intel\ Pentium/MMX\ *) ARCH='-march=pentium-mmx' ;;
*Intel\ Pentium\ II\ *) ARCH='-march=pentium2' ;;
*Intel\ Pentium\ III\ *) ARCH='-march=pentium3' ;;
*Intel\ Mobile\ Pentium\ III\ *) ARCH='-march=pentium3' ;;
*Intel\ Celeron\ \(Mendocino\)\ *) ARCH='-march=pentium3 -mno-sse' ;;
*Intel\ Pentium\ M\ \(\Dothan\)\ *) ARCH='-march=pentium-m' ;;
*Intel\ Pentium\ M\ *) ARCH='-march=pentium-m' ;;
*Intel\ Mobile\ Pentium\ 4\ *) ARCH='-march=pentium4m' ;;
*Intel\ Pentium\ 4\ *) ARCH='-march=pentium4' ;;
*Intel\(R\)\ Pentium\(R\)\ D*) ARCH='-march=nocona' ;;
*VIA\ C3*\ *) ARCH='-march=c3' ;;
*AMD\ K6-III*) ARCH='-march=k6-3' ;;
*AMD\ K6-2*) ARCH='-march=k6-2' ;;
*AMD\ K6*) ARCH='-march=k6' ;;
*AMD\ Duron*) ARCH='-march=athlon' ;;
*AMD\ Athlon\ 4*) ARCH='-march=athlon-4' ;;
*AMD\ Athlon\ Model\ 4\ \(Thunderbird\)*) ARCH='-march=athlon-tbird';;
*AMD\ Athlon\ MP*) ARCH='-march=athlon-mp' ;;
*AMD\ K7\ \(Athlon\)\ XP\ *) ARCH='-march=athlon-xp' ;;
*AMD\ Athlon\ XP\ *) ARCH='-march=athlon-xp' ;;
*AMD\ K7*|*AMD\ Athlon*) ARCH='-march=athlon' ;;
*AMD\ Unknown\ K7\ \(Athlon\)*) ARCH='-march=athlon' ;;
*AMD\ Opteron\(tm\)\ Processor*) ARCH='-march=opteron' ;;
*AMD\ Turion\(tm\)\ 64\ Mobile*) ARCH='-march=athlon64' ;;
*386-class*) ARCH='-march=i386' ;;
*486-class*) ARCH='-march=i486' ;;
*586-class*) ARCH='-march=pentium' ;;
*686-class*) ARCH='-march=pentiumpro' ;;
esac
if [ -n "$ARCH" -a "$hw_machine_arch" = i386 ] ; then
if [ "$(sysctl -n machdep.sse2)" = 1 ] ; then
case $hw_model in
*Intel\ Celeron\ *)
ARCH='-march=pentium4' ;;
esac
fi
fi
;;
m68k) case $hw_model in # Examples
*\(68020*|*\ MC68020\ *) ARCH='-m68020' ;; # Untested
*\(68030*|*\ MC68030\ *) ARCH='-m68030' ;; # Mac LC III
*\(68040*|*\ MC68040\ *) ARCH='-m68040' ;; # Untested
*\(68060*|*\ MC68060\ *) ARCH='-m68060' ;; # Upgr amiga 3000
esac
case "$(egrep '^fpu0 ' /var/run/dmesg.boot)" in
*\(emulator\)*) FEATURES="-msoft-float" ;;
*\(no\ math\ support\)*) FEATURES="-msoft-float" ;;
esac
;;
mipseb|mipsel)
# cpu0 at mainbus0: QED R4600 Orion CPU (0x2020) Rev. 2.0 with ...
case $hw_model in
Infineon\ ADM5120) ARCH='-march=4kc' ;;
*)
case "$(egrep '^cpu0 ' /var/run/dmesg.boot)" in
*\ MIPS\ R2000\ *) ARCH="-march=r2000" ;;
*\ MIPS\ R3000\ *) ARCH="-march=r3000" ;;
*\ MIPS\ R3000A\ *) ARCH="-march=r3000" ;;
*\ Toshiba\ TX3912\ *) ARCH="-march=r3900" ;;
*\ Toshiba\ TX392[27]\ *) ARCH="-march=r3900" ;;
*\ MIPS\ R4000\ *) ARCH="-mtune=r4000 -mips2" ;; # mips3
*\ MIPS\ R4400\ *) ARCH="-mtune=r4400 -mips2" ;; # mips3
*\ NEC\ VR4100\ *) ARCH="-mtune=r4100 -mips2" ;; # mips3
*\ NEC\ VR4300\ *) ARCH="-mtune=r4300 -mips2" ;; # mips3
*\ QED\ R4600\ *) ARCH="-mtune=r4600 -mips2" ;; # mips3
*\ MIPS\ R5000\ *) ARCH="-mtune=r5000 -mips2" ;; # mips4
*\ QED\ RM5200\ *) ARCH="-mtune=r5000 -mips2" ;; # mips4
*\ MIPS\ R6000\ *) ARCH="-mtune=r6000 -mips2" ;;
*\ MIPS\ R8000\ *) ARCH="-mtune=r8000 -mips2" ;; # mips4
esac ;;
esac
;;
powerpc) case $hw_model in # Examples
601\ *) ARCH='-mcpu=601' ;; # Untested
602\ *) ARCH='-mcpu=602' ;; # Untested
603\ *) ARCH='-mcpu=603' ;; # Untested
603e\ *|603ev\ *) ARCH='-mcpu=603e' ;; # Umax C500 / PM4400
604\ *) ARCH='-mcpu=604' ;; # Mac 8500
604e\ *) ARCH='-mcpu=604e' ;; # upgr B&W G3
604ev\ *) ARCH='-mcpu=604e' ;; # usually 604e
620\ *) ARCH='-mcpu=620' ;; # Untested
7400\ *) ARCH='-mcpu=7400' ;; # AGP G4/400 Mac
740\ *) ARCH='-mcpu=740' ;; # Untested
7410\ *) ARCH='-mcpu=7400' ;; # powerbook g4
7447A\ *) ARCH='-mcpu=7450' ;; #
7450\ *) ARCH='-mcpu=7450' ;; # tibook 550
750\ *) ARCH='-mcpu=750' ;; # orig. iBook
esac ;;
sparc | sparc64) case " $hw_model" in # Examples
*[\ \(]MB86900/1A*) ARCH='-mcpu=cypress' ;; # ss1+
*[\ \(]L64811*) ARCH='-mcpu=cypress' ;; # sun4/sun4c
*[\ \(]CY7C601*) ARCH='-mcpu=cypress' ;; # ss2
*[\ \(]W8601/8701*) ARCH='-mcpu=cypress' ;; # elc
*[\ \(]MB86904*) ARCH='-mcpu=supersparc' ;; # ss5 usparc
*[\ \(]MB86907*) ARCH='-mcpu=supersparc' ;; # ss5 usparc
*[\ \(]TMS390S10*) ARCH='-mcpu=supersparc' ;; # classic "
*[\ \(]TMS390Z50*) ARCH='-mcpu=supersparc' ;; # ss10/ss20
*[\ \(]RT620/625*) ARCH='-mcpu=hypersparc' ;; # ss20 ross
*[\ \(]MB86930*) ARCH='-mcpu=sparclite' ;; # from gcc
*[\ \(]MB86934*) ARCH='-mcpu=sparclite' ;; # from gcc
# under 1.5.1 -mcpu=ultrasparc chokes egcs-2.91.66 compiling perl
*[\ \(]SUNW,UltraSPARC*) ARCH='-mcpu=v9' ;; # Ultra
esac ;;
vax) # No VAX specific gcc optimisations available
NOARCH=1
;;
esac
echo $ARCH
}
determine_features()
{
FEATURES=
case $hw_machine_arch in
i386 | x86_64)
if [ "$(sysctl -n machdep.sse2)" = 1 ] ; then
FEATURES="-mfpmath=sse -msse2"
elif [ "$(sysctl -n machdep.sse)" = 1 ] ; then
FEATURES="-mfpmath=sse -msse"
fi
;;
m68k)
case "$(egrep '^fpu0 ' /var/run/dmesg.boot)" in
*\(emulator\)*) FEATURES="-msoft-float" ;;
*\(no\ math\ support\)*) FEATURES="-msoft-float" ;;
esac
;;
esac
echo $FEATURES
}

40
devel/cpuflags/files/subr_SunOS Executable file
View file

@ -0,0 +1,40 @@
# $NetBSD: subr_SunOS,v 1.1 2007/08/20 11:21:21 abs Exp $
AWK=nawk
SED=sed
display_hw_details()
{
cat <<END
OS : '`uname`'
arch : '$hw_arch'
psrinfo : '$hw_psrinfo'
END
}
extract_hw_details()
{
hw_arch=`/usr/bin/uname -m`
hw_psrinfo=`psrinfo -v | $AWK 'NR==3{print}'` # Just gets the first CPU
}
determine_arch()
{
ARCH=
case $hw_arch in
sun4c | sun4 ) ARCH='-mcpu=cypress' ;;
sun4m ) ARCH='-mcpu=supersparc' ;;
sun4u ) ARCH='-mcpu=v9' ;;
i86pc )
case "$hw_psrinfo" in
*AMD\ Opteron\(tm\)*) ARCH="-mcpu=opteron" ;;
esac
;;
esac
echo $ARCH
}
determine_features()
{
echo
}

View file

@ -1,71 +1,34 @@
#!/bin/sh
# $NetBSD: cpuflags.SunOS,v 1.11 2007/03/21 15:05:08 abs Exp $
PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
AWK=nawk
display_hw_details()
# Return gcc version string
gcc_ver()
{
echo " OS : '`uname`'"
echo " arch : '$hw_arch'"
echo " psrinfo : '$hw_psrinfo'"
gcc=$1
${gcc} -dumpversion | $SED -e 's/^[^0-9\.]\{1,\}//' -e 's/[^0-9\.]\{1,\}$//'
}
hw_arch=`/usr/bin/uname -m`
hw_psrinfo=`psrinfo -v | $AWK 'NR==3{print}'` # Just gets the first CPU
gcc_ser()
{
gcc=$1
gcc_ver $gcc | $AWK -F. '{ print ($1*1000+$2)}'
}
case $hw_arch in
sun4c | sun4 ) FLAGS='-mcpu=cypress' ;;
sun4m ) FLAGS='-mcpu=supersparc' ;;
sun4u ) FLAGS='-mcpu=v9' ;;
i86pc )
case "$hw_psrinfo" in
*AMD\ Opteron\(tm\)*) FLAGS="-mcpu=opteron" ;;
esac
;;
esac
############
# Everything from this point common between all cpuflags variants.
if [ "$1" = -v ] ; then
gcc_fixup_arch_flags()
{
gcc=$1
shift
opt_v=1
fi
if [ -n "$1" ]; then
CC=$1
else
CC=gcc
fi
gcc_arch_flags="$*"
if [ -n "$opt_v" ] ; then
if [ -n "$FLAGS" ]; then
echo "CPUFLAGS=$FLAGS"
elif [ -z "$NONE" ] ; then
echo "CPUFLAGS=Unknown"
else
echo "CPUFLAGS=None"
fi
display_hw_details
exit
fi
if [ -z "$FLAGS" -a -z "$NONE" ] ; then
echo 'Unknown machine - please send details to abs@absd.org' >&2
display_hw_details >&2
fi
# Fixup options for older gccs.
# Entries can be recursive - eg:
# -march=k6-3 -> -march=k6 -> -march=pentium -> -march=i486
#
# The format of table is
# gcc_version_in_which_option_was_introduced new_option old_option
# Fixup options for older gccs.
# Entries can be recursive - eg:
# -march=k6-3 -> -march=k6 -> -march=pentium -> -march=i486
#
# The format of table is
# gcc_version_in_which_option_was_introduced new_option old_option
if [ -n "$FLAGS" ]; then
gcc_ver=`${CC} -dumpversion | sed 's/^egcs-//'`
FLAGS=`$AWK -F: -v "flags=$FLAGS" -v "gcc_ver=$gcc_ver" '
$AWK -F: -v "flags=$gcc_arch_flags" -v "gcc_ver=$(gcc_ver $gcc)" '
{ if (gcc_ver < $1){map[$2] = ""$3} }
END { while (flags in map) {flags = map[flags]} print flags }
END { FS=" "; split(flags,ar); for (af in ar) { flag=ar[af];
while (flag in map) {flag = map[flag]} print flag }}
' <<EOD
2.90:-march=i386:-mno-486
2.90:-march=i486:-m486
@ -107,6 +70,7 @@ if [ -n "$FLAGS" ]; then
3.1:-mcpu=7400:-mcpu=750
3.1:-mcpu=7450:-mcpu=750
3.1:-mfpmath=sse:
3.1:-mmmx:
3.1:-msse2:
3.1:-msse:
3.1:-mtune=r2000:-cpu=r2000
@ -133,10 +97,8 @@ if [ -n "$FLAGS" ]; then
3.4:-march=pentium3m:-march=pentium3
3.4:-march=pentium4m:-march=pentium4
3.4:-march=prescott:-march=pentium4
3.4:-msse3:
4.2:-m3dnow:
4.2:-march=native:
EOD
`
fi
echo $FLAGS
exit 0
}