* common/cpu.c: runtime AltiVec autodetection on Linux.
authorSam Hocevar <sam@videolan.org>
Wed, 14 Mar 2007 18:04:06 +0000 (18:04 +0000)
committerSam Hocevar <sam@videolan.org>
Wed, 14 Mar 2007 18:04:06 +0000 (18:04 +0000)
  * configure, Makefile: do not build the whole project with -maltivec because
    it generates AltiVec code in weird places.

git-svn-id: svn://svn.videolan.org/x264/trunk@629 df754926-b1dd-0310-bc7b-ec298dee348c

Makefile
common/cpu.c
configure

index 2b30f8b..61db07e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -43,8 +43,10 @@ endif
 
 # AltiVec optims
 ifeq ($(ARCH),PPC)
-SRCS += common/ppc/mc.c common/ppc/pixel.c common/ppc/dct.c \
-       common/ppc/quant.c
+ALTIVECSRC += common/ppc/mc.c common/ppc/pixel.c common/ppc/dct.c \
+              common/ppc/quant.c
+SRCS += $(ALTIVECSRC)
+$(ALTIVECSRC:%.c=%.o): CFLAGS += $(ALTIVECFLAGS)
 endif
 
 # VIS optims
index b7b1ac8..09e20ea 100644 (file)
@@ -132,9 +132,43 @@ uint32_t x264_cpu_detect( void )
 }
 
 #elif defined( SYS_LINUX )
+#include <signal.h>
+#include <setjmp.h>
+static sigjmp_buf jmpbuf;
+static volatile sig_atomic_t canjump = 0;
+
+static void sigill_handler( int sig )
+{
+    if( !canjump )
+    {
+        signal( sig, SIG_DFL );
+        raise( sig );
+    }
+
+    canjump = 0;
+    siglongjmp( jmpbuf, 1 );
+}
+
 uint32_t x264_cpu_detect( void )
 {
-    /* FIXME (Linux PPC) */
+    static void (* oldsig)( int );
+
+    oldsig = signal( SIGILL, sigill_handler );
+    if( sigsetjmp( jmpbuf, 1 ) )
+    {
+        signal( SIGILL, oldsig );
+        return 0;
+    }
+
+    canjump = 1;
+    asm volatile( "mtspr 256, %0\n\t"
+                  "vand 0, 0, 0\n\t"
+                  :
+                  : "r"(-1) );
+    canjump = 0;
+
+    signal( SIGILL, oldsig );
+
     return X264_CPU_ALTIVEC;
 }
 #endif
index c16a329..6a5fe26 100755 (executable)
--- a/configure
+++ b/configure
@@ -161,9 +161,9 @@ case "${MACHINE%%-*}" in
     ARCH="PPC"
     if [ $SYS = MACOSX ]
     then
-      CFLAGS="$CFLAGS -faltivec -fastf -mcpu=G4"
+      ALTIVECFLAGS="$ALTIVECFLAGS -faltivec -fastf -mcpu=G4"
     else
-      CFLAGS="$CFLAGS -maltivec -mabi=altivec"
+      ALTIVECFLAGS="$ALTIVECFLAGS -maltivec -mabi=altivec"
     fi
     ;;
   sparc)
@@ -385,6 +385,7 @@ ARCH=$ARCH
 SYS=$SYS
 CC=$CC
 CFLAGS=$CFLAGS
+ALTIVECFLAGS=$ALTIVECFLAGS
 LDFLAGS=$LDFLAGS
 AS=$AS
 ASFLAGS=$ASFLAGS