From e1a4ae9ef58f461aa8ca1e0a1f88140a61d03680 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 14 Mar 2007 18:04:06 +0000 Subject: [PATCH] * common/cpu.c: runtime AltiVec autodetection on Linux. * 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 | 6 ++++-- common/cpu.c | 36 +++++++++++++++++++++++++++++++++++- configure | 5 +++-- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 2b30f8be..61db07ea 100644 --- 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 diff --git a/common/cpu.c b/common/cpu.c index b7b1ac84..09e20ea8 100644 --- a/common/cpu.c +++ b/common/cpu.c @@ -132,9 +132,43 @@ uint32_t x264_cpu_detect( void ) } #elif defined( SYS_LINUX ) +#include +#include +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 diff --git a/configure b/configure index c16a3293..6a5fe262 100755 --- 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 -- 2.40.0