[MPlayer-dev-eng] [PATCH] configure: enhancement for runtime cpu detection and --target support under x86

Zuxy Meng zuxy.meng at gmail.com
Mon Dec 4 15:26:53 CET 2006


Hi,

Currently configure will check for host's cpu type even if
--enable-cpudetection or --target is specified. Moreover, if the user
has also specified --disable-[mmx|3dnow|sse, etc.], link error will
occur.

This patch will chiefly help those who are preparing a binary release by:
1. --enable-cpudetection or --target will inhibit any cpu
identification, so the binary won't be affected by the type of host
CPU.
2. --enable-cpudetection enables all cpu capabilities (except cmov
under x86) even with --disable-mmx, --disable-sse, etc..
3. --target disables all cpu capabilities by default; like
--enable-cpudetection, the use of --target will cause configure to
skip any "kernel support" checking. Proper use of "--target" will
enable a user to generate a binary best suited for another machine.
For example, the user can use "configure --target=athlon-linux
--enable-3dnowext --enable-cmov --enable-mtrr" even on a Pentium 4
which doesn't support 3DNow!.

TODO:
Runtime cpu detection support for ppc is as good as x86's in the
current configure: the resulting CFLAGS still depends on the type of
host CPU, but I don't have a ppc to play around.

Comments!:-)
-- 
Zuxy
Beauty is truth,
While truth is beauty.
PGP KeyID: E8555ED6
-------------- next part --------------
Index: configure
===================================================================
--- configure	???????? 21489??
+++ configure	????????????
@@ -805,6 +805,12 @@
   }
 fi
 
+if [ "$_runtime_cpudetection" = yes ] ; then
+  if ! ( x86 || x86_64 || 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
@@ -831,14 +837,14 @@
 elif aix; then
   # use 'lsattr' on AIX
   _cpuinfo="lsattr -E -l proc0 -a type"
-elif x86 || x86_64; then
+elif x86 || x86_64 && [ "$_runtime_cpudetection" = no -a -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 && [ "$_runtime_cpudetection" = no -a -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`
@@ -872,13 +878,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 [ "$_runtime_cpudetection" = no -a -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
@@ -892,7 +898,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.
@@ -904,27 +910,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
@@ -937,7 +943,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
@@ -945,12 +951,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
@@ -959,7 +965,7 @@
 		proc=i586
 	fi
 	;;
-    6) iproc=686
+      6) iproc=686
 	if test "$pmodel" -ge 9; then
 		proc=c3-2
 	else
@@ -967,19 +973,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
@@ -997,7 +1004,7 @@
 cat > $TMPC << EOF
 int main(void) { return 0; }
 EOF
-  if test "$_runtime_cpudetection" = no ; then
+  if test "$_runtime_cpudetection" = no -a -z "$_target"; then
     if test "$proc" = "k8"; then
       cc_check -march=$proc $cpuopt=$proc || proc=athlon-xp
     fi
@@ -1051,37 +1058,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"
     ;;
@@ -1109,21 +1116,23 @@
     else
 	cpuopt=-mcpu
     fi
-    case "$pvendor" in
-    AuthenticAMD)
-      proc=k8;;
-    GenuineIntel)
-      case "$pmodel" in
-      6) proc=core2;;
+    if [ "$_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
@@ -1163,6 +1172,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
@@ -1461,8 +1471,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
@@ -1476,7 +1490,7 @@
   fi
 fi
 
-if x86 && test "$_runtime_cpudetection" = no ; then
+if x86 &&  test "$_runtime_cpudetection" = no -a -z "$_target" ; then
   extcheck() {
     if test "$1" = yes ; then
       echocheck "kernel support of $2"
@@ -2133,17 +2147,18 @@
     ;;
 
   --enable-sse)	_sse=yes ;;
-  --disable-sse) _sse=no ;;
+  --disable-sse) [ "$_runtime_cpudetection" = "no" ] && _sse=no ;;
   --enable-sse2) _sse2=yes ;;
-  --disable-sse2) _sse2=no ;;
+  --disable-sse2) [ "$_runtime_cpudetection" = "no" ] && _sse2=no ;;
   --enable-mmxext) _mmxext=yes ;;
-  --disable-mmxext) _mmxext=no ;;
+  --disable-mmxext) [ "$_runtime_cpudetection" = "no" ] && _mmxext=no ;;
   --enable-3dnow) _3dnow=yes ;;
-  --disable-3dnow) _3dnow=no _3dnowext=no ;;
+  --disable-3dnow)
+        [ "$_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) [ "$_runtime_cpudetection" = "no" ] && _3dnowext=no ;;
+  --enable-cmov) [ "$_runtime_cpudetection" = "no" ] && _cmov=yes ;;
+  --disable-cmov) [ "$_runtime_cpudetection" = "no" ] && _cmov=no ;;
   --enable-altivec) _altivec=yes ;;
   --disable-altivec) _altivec=no ;;
   --enable-armv5te) _armv5te=yes ;;
@@ -2152,8 +2167,8 @@
   --disable-iwmmxt) _iwmmxt=no ;;
   --enable-mmx)	_mmx=yes ;;
   --disable-mmx) # 3Dnow! and MMX2 require MMX
-        _3dnow=no _3dnowext=no _mmx=no _mmxext=no ;;
-
+        [ "$_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