[MPlayer-dev-eng] [PATCH] configure: enhancement for runtime cpu detection and --target support under x86
Zuxy Meng
zuxy.meng at gmail.com
Wed Dec 13 02:58:38 CET 2006
Hi,
2006/12/13, Reimar Döffinger <Reimar.Doeffinger at stud.uni-karlsruhe.de>:
> Hello,
> On Tue, Dec 12, 2006 at 10:59:25PM +0800, Zuxy Meng wrote:
> > 2006/12/12, Reimar Doeffinger <Reimar.Doeffinger at stud.uni-karlsruhe.de>:
> > >Build system is not my area, but some random comments:
> > >
> > >On Mon, Dec 04, 2006 at 10:26:53PM +0800, Zuxy Meng wrote:
> > >> +if [ "$_runtime_cpudetection" = yes ] ; then
> > >
> > >This applies to many, many places in the patch. I think for
> > >compatibility reasons you're supposed to use the 'test' command instead
> > >of []
> > >
> > >> + if ! ( x86 || x86_64 || ppc ) ; then
> > >
> > >and "not" instead of !, there are shells that do not support '!'
> > >
> > >> -elif x86 || x86_64; then
> > >> +elif x86 || x86_64 && [ "$_runtime_cpudetection" = no -a -z "$_target"
> > >] ; then
> > >
> > >And do not use -a, use two checks and combine them with && (many more
> > >cases of that)
> >
> >
> > Hmm...[], ! and -a/-o are used elsewhere in the configure. Forgive me
> > I really didn't have any idea which alternative provides better
> > compatibility.
>
> the decision against [ and -a/-o is actually not due to compatibility I
> admit, nevertheless it was once decided to do it with test and &&/||.
> '!' on the other hand is not used anywhere, there is even this comment:
> > # not boolean test: implement the posix shell "!" operator for a
> > # non-posix /bin/sh.
> > # usage: not {command}
> > # returns exit status "success" when the execution of "command"
> > # fails.
I see. See if this one looks better:-)
>
> > >> ;;
> > >> - 6) iproc=686
> > >> + 6) iproc=686
> > >
> > >cosmetics (also in some more places)
> >
> > No. It's intended to accommodate a new surrounding 'case..esac' pair.
>
> Well, that's exactly the definition of cosmetics?!?
Well, I don't guess so. If u add a pair of brackets around some old
statements in C you're expected to reindent those statements. Similar
in this case.
--
Zuxy
Beauty is truth,
While truth is beauty.
PGP KeyID: E8555ED6
-------------- next part --------------
Index: configure
===================================================================
--- configure ???????? 21598??
+++ configure ????????????
@@ -806,6 +806,12 @@
}
fi
+if test "$_runtime_cpudetection" = yes ; then
+ if not x86 && not x86_64 && not ppc ; then
+ echo "Runtime CPU detection only works for x86, x86-64 and ppc!"
+ $_runtime_cpudetection=no
+ fi
+fi
# ---
# now that we know what compiler should be used for compilation, try to find
@@ -832,14 +838,16 @@
elif aix; then
# use 'lsattr' on AIX
_cpuinfo="lsattr -E -l proc0 -a type"
-elif x86 || x86_64; then
+elif (x86 || x86_64) && test "$_runtime_cpudetection" = no &&
+ test -z "$_target" ; then
# all other OSes try to extract CPU information from a small helper
# program TOOLS/cpuinfo instead
$_cc -o TOOLS/cpuinfo TOOLS/cpuinfo.c
_cpuinfo="TOOLS/cpuinfo"
fi
-if x86 || x86_64 ; then
+if (x86 || x86_64) && test "$_runtime_cpudetection" = no &&
+ test -z "$_target" ; then
# gather more CPU information
pname=`$_cpuinfo | grep 'model name' | cut -d ':' -f 2 | _head 1`
pvendor=`$_cpuinfo | grep 'vendor_id' | cut -d ':' -f 2 | cut -d ' ' -f 2 | _head 1`
@@ -873,13 +881,13 @@
_def_arch="#define ARCH_X86_32 1"
_target_arch="TARGET_ARCH_X86_32 = yes"
-
- case "$pvendor" in
- AuthenticAMD)
- case "$pfamily" in
- 3) proc=i386 iproc=386 ;;
- 4) proc=i486 iproc=486 ;;
- 5) iproc=586 # LGB: models are: K5/SSA5 K5 K5 K5 ? ? K6 K6 K6-2 K6-3
+ if test "$_runtime_cpudetection" = no && test -z "$_target" ; then
+ case "$pvendor" in
+ AuthenticAMD)
+ case "$pfamily" in
+ 3) proc=i386 iproc=386 ;;
+ 4) proc=i486 iproc=486 ;;
+ 5) iproc=586 # LGB: models are: K5/SSA5 K5 K5 K5 ? ? K6 K6 K6-2 K6-3
# K6 model 13 are the K6-2+ and K6-III+, only differing in cache size.
if test "$pmodel" -eq 9 -o "$pmodel" -eq 13; then
proc=k6-3
@@ -893,7 +901,7 @@
proc=i586
fi
;;
- 6) iproc=686
+ 6) iproc=686
# It's a bit difficult to determine the correct type of Family 6
# AMD CPUs just from their signature. Instead, we check directly
# whether it supports SSE.
@@ -905,27 +913,27 @@
proc=athlon
fi
;;
- 15) iproc=686
+ 15) iproc=686
# k8 cpu-type only supported in gcc >= 3.4.0, but that will be
# caught and remedied in the optimization tests below.
proc=k8
;;
- *) proc=k8 iproc=686 ;;
- esac
- ;;
- GenuineIntel)
- case "$pfamily" in
- 3) proc=i386 iproc=386 ;;
- 4) proc=i486 iproc=486 ;;
- 5) iproc=586
+ *) proc=k8 iproc=686 ;;
+ esac
+ ;;
+ GenuineIntel)
+ case "$pfamily" in
+ 3) proc=i386 iproc=386 ;;
+ 4) proc=i486 iproc=486 ;;
+ 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
+ 6) iproc=686
if test "$pmodel" -eq 15; then
proc=core2
elif test "$pmodel" -eq 9 -o "$pmodel" -ge 13; then
@@ -938,7 +946,7 @@
proc=i686
fi
;;
- 15) iproc=686
+ 15) iproc=686
# A nocona in 32-bit mode has no more capabilities than a prescott.
if test "$pmodel" -ge 3; then
proc=prescott
@@ -946,12 +954,12 @@
proc=pentium4
fi
;;
- *) proc=prescott iproc=686 ;;
- esac
- ;;
- CentaurHauls)
- case "$pfamily" in
- 5) iproc=586
+ *) proc=prescott iproc=686 ;;
+ esac
+ ;;
+ CentaurHauls)
+ case "$pfamily" in
+ 5) iproc=586
if test "$pmodel" -ge 8; then
proc=winchip2
elif test "$pmodel" -ge 4; then
@@ -960,7 +968,7 @@
proc=i586
fi
;;
- 6) iproc=686
+ 6) iproc=686
if test "$pmodel" -ge 9; then
proc=c3-2
else
@@ -968,19 +976,20 @@
iproc=586
fi
;;
- *) proc=i686 iproc=i686 ;;
+ *) proc=i686 iproc=i686 ;;
+ esac
+ ;;
+ unknown)
+ case "$pfamily" in
+ 3) proc=i386 iproc=386 ;;
+ 4) proc=i486 iproc=486 ;;
+ *) proc=i586 iproc=586 ;;
+ esac
+ ;;
+ *)
+ proc=i586 iproc=586 ;;
esac
- ;;
- unknown)
- case "$pfamily" in
- 3) proc=i386 iproc=386 ;;
- 4) proc=i486 iproc=486 ;;
- *) proc=i586 iproc=586 ;;
- esac
- ;;
- *)
- proc=i586 iproc=586 ;;
- esac
+ fi
# check that gcc supports our CPU, if not, fall back to earlier ones
# LGB: check -mcpu and -march swithing step by step with enabling
@@ -998,7 +1007,7 @@
cat > $TMPC << EOF
int main(void) { return 0; }
EOF
- if test "$_runtime_cpudetection" = no ; then
+ if test "$_runtime_cpudetection" = no && test -z "$_target" ; then
if test "$proc" = "k8"; then
cc_check -march=$proc $cpuopt=$proc || proc=athlon-xp
fi
@@ -1052,37 +1061,37 @@
_mcpu="$cpuopt=$proc"
_optimizing="$proc"
fi
- else # if test "$_runtime_cpudetection" = no
+ elif test -z "$_target" ; then # runtime cpu detection
+ proc="generic"
# i686 is probably the most common CPU - optimize for it
_mcpu="$cpuopt=i686"
# at least i486 required, for bswap instruction
_march="-march=i486"
+ iproc=486
cc_check $_mcpu || _mcpu=""
cc_check $_march $_mcpu || _march=""
- fi
-
+ else # --target used
## Gabucino : --target takes effect here (hopefully...) by overwriting
## autodetected mcpu/march parameters
- if test "$_target" ; then
- # TODO: it may be a good idea to check GCC and fall back in all cases
- if test "$host_arch" = "i586-i686"; then
- _march="-march=i586"
- _mcpu="$cpuopt=i686"
- else
- _march="-march=$host_arch"
- _mcpu="$cpuopt=$host_arch"
- fi
+ # TODO: it may be a good idea to check GCC and fall back in all cases
+ if test "$host_arch" = "i586-i686"; then
+ _march="-march=i586"
+ _mcpu="$cpuopt=i686"
+ else
+ _march="-march=$host_arch"
+ _mcpu="$cpuopt=$host_arch"
+ fi
- proc="$host_arch"
+ proc="$host_arch"
- case "$proc" in
- i386) iproc=386 ;;
- i486) iproc=486 ;;
- i586|k5|k6|k6-2|k6-3|pentium|pentium-mmx) iproc=586 ;;
- i686|athlon*|pentium*) iproc=686 ;;
- *) iproc=586 ;;
- esac
- fi
+ case "$proc" in
+ i386) iproc=386 ;;
+ i486) iproc=486 ;;
+ i586|k5|k6|k6-2|k6-3|pentium|pentium-mmx) iproc=586 ;;
+ i686|athlon*|pentium*) iproc=686 ;;
+ *) iproc=586 ;;
+ esac
+ fi
echores "$proc"
;;
@@ -1110,21 +1119,23 @@
else
cpuopt=-mcpu
fi
- case "$pvendor" in
- AuthenticAMD)
- proc=k8;;
- GenuineIntel)
- case "$pmodel" in
- 6) proc=core2;;
+ if test "$_runtime_cpudetection" = no ; then
+ case "$pvendor" in
+ AuthenticAMD)
+ proc=k8;;
+ GenuineIntel)
+ case "$pmodel" in
+ 6) proc=core2;;
+ *)
+ # 64-bit prescotts exist, but as far as GCC is concerned they have the
+ # same capabilities as a nocona.
+ proc=nocona;;
+ esac
+ ;;
*)
- # 64-bit prescotts exist, but as far as GCC is concerned they have the
- # same capabilities as a nocona.
- proc=nocona;;
+ proc=error;;
esac
- ;;
- *)
- proc=error;;
- esac
+ fi
echocheck "GCC & CPU optimization abilities"
cat > $TMPC << EOF
@@ -1164,6 +1175,7 @@
# x86-64 is an undocumented option, an intersection of k8 and nocona.
_march="-march=x86-64"
_mcpu="$cpuopt=x86-64"
+ proc="generic"
cc_check $_mcpu || _mcpu=""
cc_check $_march $_mcpu || _march=""
fi
@@ -1462,8 +1474,12 @@
esac # case "$host_arch" in
if test "$_runtime_cpudetection" = yes ; then
- if x86; then
+ if x86 ; then
_cmov=no
+ elif x86_64 ; then
+ _cmov=yes
+ fi
+ if x86 || x86_64 ; then
_mmx=yes
_3dnow=yes
_3dnowext=yes
@@ -1477,7 +1493,7 @@
fi
fi
-if x86 && test "$_runtime_cpudetection" = no ; then
+if x86 && test "$_runtime_cpudetection" = no && test -z "$_target" ; then
extcheck() {
if test "$1" = yes ; then
echocheck "kernel support of $2"
@@ -2141,17 +2157,18 @@
;;
--enable-sse) _sse=yes ;;
- --disable-sse) _sse=no ;;
+ --disable-sse) test "$_runtime_cpudetection" = "no" && _sse=no ;;
--enable-sse2) _sse2=yes ;;
- --disable-sse2) _sse2=no ;;
+ --disable-sse2) test "$_runtime_cpudetection" = "no" && _sse2=no ;;
--enable-mmxext) _mmxext=yes ;;
- --disable-mmxext) _mmxext=no ;;
+ --disable-mmxext) test "$_runtime_cpudetection" = "no" && _mmxext=no ;;
--enable-3dnow) _3dnow=yes ;;
- --disable-3dnow) _3dnow=no _3dnowext=no ;;
+ --disable-3dnow)
+ test "$_runtime_cpudetection" = "no" && _3dnow=no _3dnowext=no ;;
--enable-3dnowext) _3dnow=yes _3dnowext=yes ;;
- --disable-3dnowext) _3dnowext=no ;;
- --enable-cmov) _cmov=yes ;;
- --disable-cmov) _cmov=no ;;
+ --disable-3dnowext) test "$_runtime_cpudetection" = "no" && _3dnowext=no ;;
+ --enable-cmov) test "$_runtime_cpudetection" = "no" && _cmov=yes ;;
+ --disable-cmov) test "$_runtime_cpudetection" = "no" && _cmov=no ;;
--enable-altivec) _altivec=yes ;;
--disable-altivec) _altivec=no ;;
--enable-armv5te) _armv5te=yes ;;
@@ -2160,8 +2177,8 @@
--disable-iwmmxt) _iwmmxt=no ;;
--enable-mmx) _mmx=yes ;;
--disable-mmx) # 3Dnow! and MMX2 require MMX
- _3dnow=no _3dnowext=no _mmx=no _mmxext=no ;;
-
+ test "$_runtime_cpudetection" = "no" &&
+ _3dnow=no _3dnowext=no _mmx=no _mmxext=no ;;
--enable-win32) _win32=yes ;;
--disable-win32) _win32=no ;;
More information about the MPlayer-dev-eng
mailing list