# HG changeset patch # User arpi # Date 1042918186 0 # Node ID c428933c7e54e584827e8925879e4129a53206fe # Parent 60d144a160886ef6cae578216bddb75572d08279 AltiVec detection code ("borrowed" from FFmpeg and libmpeg2) & enough code to enable the AltiVec IMDCT in liba52 and the DCT64 in mp3lib. patch by Romain Dolbeau diff -r 60d144a16088 -r c428933c7e54 Makefile --- a/Makefile Sat Jan 18 19:28:53 2003 +0000 +++ b/Makefile Sat Jan 18 19:29:46 2003 +0000 @@ -40,6 +40,10 @@ CFLAGS = $(OPTFLAGS) -Ilibmpdemux -Iloader -Ilibvo $(FREETYPE_INC) $(EXTRA_INC) $(CDPARANOIA_INC) $(SDL_INC) # -Wall +ifeq ($(TARGET_ALTIVEC),yes) +CFLAGS += -faltivec +endif + PARTS = libmpdemux libmpcodecs mp3lib liba52 libmpeg2 libavcodec libao2 drivers linux postproc input libvo libaf ifeq ($(VIDIX),yes) PARTS += libdha vidix diff -r 60d144a16088 -r c428933c7e54 cpudetect.c --- a/cpudetect.c Sat Jan 18 19:28:53 2003 +0000 +++ b/cpudetect.c Sat Jan 18 19:29:46 2003 +0000 @@ -429,6 +429,27 @@ } #else /* ARCH_X86 */ +#ifdef SYS_DARWIN +#include +#else +#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); +} +#endif + void GetCpuCaps( CpuCaps *caps) { caps->cpuType=0; @@ -440,5 +461,46 @@ caps->hasSSE=0; caps->hasSSE2=0; caps->isX86=0; + caps->hasAltiVec = 0; +#ifdef HAVE_ALTIVEC +#ifdef SYS_DARWIN +/* + rip-off from ffmpeg altivec detection code. + this code also appears on Apple's AltiVec pages. + */ + { + int sels[2] = {CTL_HW, HW_VECTORUNIT}; + int has_vu = 0; + size_t len = sizeof(has_vu); + int err; + + err = sysctl(sels, 2, &has_vu, &len, NULL, 0); + + if (err == 0) + if (has_vu != 0) + caps->hasAltiVec = 1; + mp_msg(MSGT_CPUDETECT,MSGL_INFO,"AltiVec %sfound\n", (caps->hasAltiVec ? "" : "not ")); + } +#else /* SYS_DARWIN */ +/* no Darwin, do it the brute-force way */ +/* this is borrowed from the libmpeg2 library */ + { + signal (SIGILL, sigill_handler); + if (sigsetjmp (jmpbuf, 1)) { + signal (SIGILL, SIG_DFL); + } else { + canjump = 1; + + asm volatile ("mtspr 256, %0\n\t" + "vand v0, v0, v0" + : + : "r" (-1)); + + signal (SIGILL, SIG_DFL); + caps->hasAltiVec = 1; + } + } +#endif /* SYS_DARWIN */ +#endif /* HAVE_ALTIVEC */ } #endif /* !ARCH_X86 */ diff -r 60d144a16088 -r c428933c7e54 cpudetect.h --- a/cpudetect.h Sat Jan 18 19:28:53 2003 +0000 +++ b/cpudetect.h Sat Jan 18 19:29:46 2003 +0000 @@ -17,6 +17,7 @@ int hasSSE2; int isX86; unsigned cl_size; /* size of cache line */ + int hasAltiVec; } CpuCaps; extern CpuCaps gCpuCaps; diff -r 60d144a16088 -r c428933c7e54 libmpcodecs/ad_liba52.c --- a/libmpcodecs/ad_liba52.c Sat Jan 18 19:28:53 2003 +0000 +++ b/libmpcodecs/ad_liba52.c Sat Jan 18 19:29:46 2003 +0000 @@ -112,6 +112,7 @@ if(gCpuCaps.hasMMX2) a52_accel|=MM_ACCEL_X86_MMXEXT; if(gCpuCaps.has3DNow) a52_accel|=MM_ACCEL_X86_3DNOW; if(gCpuCaps.has3DNowExt) a52_accel|=MM_ACCEL_X86_3DNOWEXT; + if(gCpuCaps.hasAltiVec) a52_accel|=MM_ACCEL_PPC_ALTIVEC; a52_samples=a52_init (a52_accel); if (a52_samples == NULL) { mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 init failed\n"); diff -r 60d144a16088 -r c428933c7e54 mencoder.c --- a/mencoder.c Sat Jan 18 19:28:53 2003 +0000 +++ b/mencoder.c Sat Jan 18 19:29:46 2003 +0000 @@ -367,8 +367,8 @@ mp_msg(MSGT_CPLAYER,MSGL_INFO,"%s",banner_text); /* Test for cpu capabilities (and corresponding OS support) for optimizing */ + GetCpuCaps(&gCpuCaps); #ifdef ARCH_X86 - GetCpuCaps(&gCpuCaps); mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: Type: %d MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n", gCpuCaps.cpuType,gCpuCaps.hasMMX,gCpuCaps.hasMMX2, gCpuCaps.has3DNow, gCpuCaps.has3DNowExt, diff -r 60d144a16088 -r c428933c7e54 mplayer.c --- a/mplayer.c Sat Jan 18 19:28:53 2003 +0000 +++ b/mplayer.c Sat Jan 18 19:29:46 2003 +0000 @@ -665,8 +665,8 @@ mp_msg(MSGT_CPLAYER,MSGL_INFO,banner_text); /* Test for cpu capabilities (and corresponding OS support) for optimizing */ + GetCpuCaps(&gCpuCaps); #ifdef ARCH_X86 - GetCpuCaps(&gCpuCaps); mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n", gCpuCaps.hasMMX,gCpuCaps.hasMMX2, gCpuCaps.has3DNow, gCpuCaps.has3DNowExt,