1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
|
#!/bin/sh
if test x"$CC" = x; then
CC=gcc
fi
if test $# -ne 1; then
echo "Please give the arch (ppc or x86) as an argument!" 1>&2
exit 1
fi
if test `uname -s` = Darwin; then
IsDarwin=yes
else
IsDarwin=no
fi
target=$1
cc_version=`$CC -dumpversion`
_cc_major=`echo $cc_version | cut -d'.' -f1`
_cc_minor=`echo $cc_version | cut -d'.' -f2`
if test $_cc_major -ge 4; then
_opt_mcpu="-mtune"
elif test $_cc_major -ge 3 -a $_cc_minor -ge 4; then
_opt_mcpu="-mtune"
else
_opt_mcpu="-mcpu"
fi
do_cc()
{
$CC -o conftest conftest.c $@ >/dev/null 2>&1
}
extcheck()
{
cat > conftest.c <<EOF
#include <signal.h>
void catch() { exit(1); }
int main(void){
signal(SIGILL, catch);
__asm__ __volatile__ ("$1":::"memory");
exit(0);
}
EOF
do_cc
if test -x ./conftest; then
./conftest
if test $? -ne 0; then
return 1
fi
return 0
else
return 1
fi
}
do_x86()
{
CFLAGS=-O
if test $IsDarwin = yes; then
CFLAGS="$CFLAGS -fno-pic -Wl,-read_only_relocs -Wl,suppress"
fi
if test -r /proc/cpuinfo; then
_cpuinfo="cat /proc/cpuinfo"
else
$CC $CFLAGS -o cpuinfo utils/cpuinfo.c
_cpuinfo="./cpuinfo"
fi
# Cpu determination logic adapted from the MPlayer configure script.
pname=`$_cpuinfo | grep 'model name' | cut -d ':' -f 2 | head -n 1`
pvendor=`$_cpuinfo | grep 'vendor_id' | cut -d':' -f2 | cut -d' ' -f2 | head -n 1`
pfamily=`$_cpuinfo | grep 'cpu family' | cut -d':' -f2 | cut -d' ' -f2 | head -n 1`
pmodel=`$_cpuinfo | grep -v 'model name' | grep 'model' | cut -d':' -f2 | cut -d' ' -f2 | head -n 1`
pstep=`$_cpuinfo | grep 'stepping' | cut -d':' -f2 | cut -d' ' -f2 | head -n 1`
pparam=`$_cpuinfo | grep 'features' | cut -d':' -f2 | head -n 1`
if test -z "$pparam" ; then
pparam=`$_cpuinfo | grep 'flags' | cut -d ':' -f 2 | head -n 1`
fi
_mmx=no
_3dnow=no
_3dnowex=no
_mmx2=no
_sse=no
_sse2=no
_mtrr=no
for i in $pparam ; do
case "$i" in
3dnow) _3dnow=yes ;;
3dnowext) _3dnow=yes _3dnowex=yes ;;
mmx) _mmx=yes ;;
mmxext) _mmx2=yes ;;
mtrr|k6_mtrr|cyrix_arr) _mtrr=yes ;;
xmm|sse|kni) _sse=yes _mmx2=yes ;;
sse2) _sse2=yes ;;
esac
done
case "$pvendor" in
AuthenticAMD)
case "$pfamily" in
3)proc=i386
;;
4) proc=i486
;;
5) iproc=586
# models are: K5/SSA5 K5 K5 K5 ? ? K6 K6 K6-2 K6-3
# K6 model 13 are the K6-2+ and K6-III+
if test "$pmodel" -eq 9 -o "$pmodel" -eq 13; then
proc=k6-3
elif test "$pmodel" -ge 8; then
proc=k6-2
elif test "$pmodel" -ge 6; then
proc=k6
else
proc=i586
fi
;;
6) iproc=686
if test "$pmodel" -ge 7; then
proc=athlon-4
elif test "$pmodel" -ge 6; then
if test "$_sse" = yes && test "$pstep" -ge 2; then
proc=athlon-xp
else
proc=athlon-4
fi
elif test "$pmodel" -ge 4; then
proc=athlon-tbird
else
proc=athlon
fi
;;
15)
# Despite what the gcc into says 'athlon64' is not accepted as
# synonym for 'k8'
proc=k8
;;
*) proc=athlon-xp
;;
esac
;;
GenuineIntel)
case "$pfamily" in
3) proc=i386
;;
4) proc=i486
;;
5) iproc=586
if test "$pmodel" -eq 4 || test "$pmodel" -eq 8; then
proc=pentium-mmx # 4 is desktop, 8 is mobile
else
proc=i586
fi
;;
6) iproc=686
if test "$pmodel" -ge 15; then
proc=nocona
elif test "$pmodel" -ge 13; then
proc=pentium-m
elif test "$pmodel" -ge 7; then
proc=pentium3
elif test "$pmodel" -ge 3; then
proc=pentium2
else
proc=i686
fi
;;
15) proc=pentium4
;;
*) proc=pentium4
;;
esac
;;
unknown)
case "$pfamily" in
3) proc=i386
;;
4) proc=i486
;;
*) proc=i586
;;
esac
;;
*)
proc=i586
;;
esac
# check that gcc supports our CPU, if not, fall back to earlier ones
cat > conftest.c << EOF
int main(void) { return 0; }
EOF
if test "$proc" = "athlon64" ; then
do_cc -march=$proc $_opt_mcpu=$proc || proc=athlon-xp
fi
if test "$proc" = "athlon-xp" || test "$proc" = "athlon-4" || test "$proc" = "athlon-tbird"; then
do_cc -march=$proc $_opt_mcpu=$proc || proc=athlon
fi
if test "$proc" = "k6-3" || test "$proc" = "k6-2"; then
do_cc -march=$proc $_opt_mcpu=$proc || proc=k6
fi
if test "$proc" = "k6"; then
do_cc -march=$proc $_opt_mcpu=$proc
if test $? -ne 0; then
if do_cc -march=i586 $_opt_mcpu=i686; then
proc=i586-i686
else
proc=i586
fi
fi
fi
if test "$proc" = "pentium4" || test "$proc" = "pentium3" || test "$proc" = "pentium2" || test "$proc" = "athlon"; then
do_cc -march=$proc $_opt_mcpu=$proc || proc=i686
fi
if test "$proc" = "i686" || test "$proc" = "pentium-mmx"; then
do_cc -march=$proc $_opt_mcpu=$proc || proc=i586
fi
if test "$proc" = "i586" ; then
do_cc -march=$proc $_opt_mcpu=$proc || proc=i486
fi
if test "$proc" = "i486" ; then
do_cc -march=$proc $_opt_mcpu=$proc || proc=i386
fi
if test "$proc" = "i386" ; then
do_cc -march=$proc $_opt_mcpu=$proc || proc=error
fi
if test "$proc" = "error" ; then
echo "Your $_cc does not even support \"i386\" for '-march' and $_opt_mcpu."
_mcpu=""
_march=""
elif test "$proc" = "i586-i686"; then
_march="-march=i586"
_mcpu="$_opt_mcpu=i686"
else
_march="-march=$proc"
_mcpu="$_opt_mcpu=$proc"
fi
if test $_cc_major -ge 3; then
extcheck "xorps %%xmm0, %%xmm0" || _gcc3_ext="$_gcc3_ext -mno-sse"
extcheck "xorpd %%xmm0, %%xmm0" || _gcc3_ext="$_gcc3_ext -mno-sse2"
if test x"$_gcc3_ext" != "x"; then
# if we had to disable sse/sse2 because the active kernel does not
# support this instruction set extension, we also have to tell
# gcc3 to not generate sse/sse2 instructions for normal C code
cat > conftest.c << EOF
int main(void) { return 0; }
EOF
do_cc $_march $_gcc3_ext && _march="$_march $_gcc3_ext"
fi
fi
echo $_march $_mcpu
rm -f conftest.c conftest cpuinfo
return 0
}
do_ppc()
{
# Linux on a PPC has /proc/info
# Darwin (OS/X) has the hostinfo command
# If neither of those we have no idea what to do - so do nothing.
if test -r /proc/cpuinfo; then
proc=`grep cpu /proc/cpuinfo | cut -d':' -f2 | cut -d',' -f1 | cut -b 2- | head -n 1`
elif test $IsDarwin = yes; then
proc=`hostinfo | grep "Processor type" | cut -f3 -d' ' | sed 's/ppc//'`
else
return 0
fi
case "$proc" in
601) _march="$_opt_mcpu=601" _mcpu='-mtune=601'
;;
603) _march="$_opt_mcpu=603" _mcpu='-mtune=603'
;;
603e|603ev) _march="$_opt_mcpu=603e" _mcpu='-mtune=603e'
;;
604|604e|604r|604ev) _march="$_opt_mcpu=604" _mcpu='-mtune=604'
;;
740|740/750|745/755) _march="$_opt_mcpu=740" _mcpu='-mtune=740'
;;
750|750CX) _march="$_opt_mcpu=750" _mcpu='-mtune=750'
;;
*) ;;
esac
# gcc 3.1(.1) and up supports 7400 and 7450
if test "$_cc_major" -ge "3" && test "$_cc_minor" -ge "1" || test "$_cc_major" -ge "4"; then
case "$proc" in
7400*|7410*) _march="$_opt_mcpu=7400" _mcpu='-mtune=7400' ;;
7450*|7455*) _march="$_opt_mcpu=7450" _mcpu='-mtune=7450' ;;
*) ;;
esac
fi
# gcc 3.2 and up supports 970
if test "$_cc_major" -ge "3" && test "$_cc_minor" -ge "3" || test "$_cc_major" -ge "4"; then
case "$proc" in
970*) if test $IsDarwin = yes; then
_march="$_opt_mcpu=G5 -mpowerpc64 -mpowerpc-gpopt -falign-loops=16" _mcpu='-mtune=G5'
else
_march="$_opt_mcpu=970" _mcpu='-mtune=970'
fi
;;
*) ;;
esac
fi
echo $_march $_mcpu
return 0
}
#
# The script that runs the various functions above
#
if test $target = x86; then
do_x86
elif test $target = ppc; then
do_ppc
fi
|