From 79a84232d992892d62e12b33397d833e59f6b8d9 Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Sun, 18 Nov 2001 23:00:34 +0000 Subject: test OS support for SSE instructions CVS patchset: 1073 CVS date: 2001/11/18 23:00:34 --- src/xine-utils/cpu_accel.c | 27 ++++++++++++++++++++++++++- src/xine-utils/memcpy.c | 27 +++++---------------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/xine-utils/cpu_accel.c b/src/xine-utils/cpu_accel.c index 838366c77..a5c7749cd 100644 --- a/src/xine-utils/cpu_accel.c +++ b/src/xine-utils/cpu_accel.c @@ -21,7 +21,10 @@ #include "config.h" +#include #include +#include +#include #include "attributes.h" #include "xineutils.h" @@ -86,8 +89,11 @@ static uint32_t x86_accel (void) caps = MM_ACCEL_X86_MMX; if (edx & 0x02000000) /* SSE - identical to AMD MMX extensions */ - caps = MM_ACCEL_X86_MMX | MM_ACCEL_X86_MMXEXT; + caps = MM_ACCEL_X86_SSE | MM_ACCEL_X86_MMXEXT; + if (edx & 0x04000000) /* SSE2 */ + caps |= MM_ACCEL_X86_SSE2; + cpuid (0x80000000, eax, ebx, ecx, edx); if (eax < 0x80000001) /* no extended capabilities */ return caps; @@ -105,6 +111,13 @@ static uint32_t x86_accel (void) #endif +static jmp_buf sigill_return; + +static void sigill_handler (int n) { + printf ("cpu_accel: OS doesn't support SSE instructions.\n"); + longjmp(sigill_return, 1); +} + uint32_t xine_mm_accel (void) { #ifdef ARCH_X86 @@ -113,7 +126,19 @@ uint32_t xine_mm_accel (void) if (!got_accel) { got_accel = 1; + accel = x86_accel (); + + /* test OS support for SSE */ + if( accel & MM_ACCEL_X86_SSE ) { + if (setjmp(sigill_return)) { + accel &= ~(MM_ACCEL_X86_SSE|MM_ACCEL_X86_SSE2); + } else { + signal (SIGILL, sigill_handler); + __asm __volatile ("xorps %xmm0, %xmm0"); + signal (SIGILL, SIG_DFL); + } + } } return accel; diff --git a/src/xine-utils/memcpy.c b/src/xine-utils/memcpy.c index 3e1de857d..fe548c987 100644 --- a/src/xine-utils/memcpy.c +++ b/src/xine-utils/memcpy.c @@ -35,8 +35,6 @@ #include #include -#include -#include #include "xine_internal.h" #include "xineutils.h" @@ -368,9 +366,7 @@ static struct { { "linux kernel memcpy()", linux_kernel_memcpy, 0, 0 }, { "MMX optimized memcpy()", mmx_memcpy, 0, MM_MMX }, { "MMXEXT optimized memcpy()", mmx2_memcpy, 0, MM_MMXEXT }, -# ifndef __FreeBSD__ { "SSE optimized memcpy()", sse_memcpy, 0, MM_MMXEXT|MM_SSE }, -# endif #endif /* ARCH_X86 */ { NULL, NULL, 0, 0 } }; @@ -391,15 +387,6 @@ static unsigned long long int rdtsc() } #endif -static jmp_buf sigill_return; - -static void sigill_handler (int n) { - - printf ("memcpy: SIGILL catched\n"); - - longjmp(sigill_return, 1); -} - #define BUFSIZE 1024*1024 void xine_probe_fast_memcpy(config_values_t *config) @@ -408,8 +395,11 @@ void xine_probe_fast_memcpy(config_values_t *config) char *buf1, *buf2; int i, j, best; static int config_flags = -1; - static char *memcpy_methods[] = {"probe", "glibc", "kernel", - "mmx", "mmxext", "sse", NULL}; + static char *memcpy_methods[] = {"probe", "glibc", +#ifdef ARCH_X86 + "kernel", "mmx", "mmxext", "sse", +#endif + NULL}; #ifdef ARCH_X86 config_flags = xine_mm_accel(); @@ -453,19 +443,12 @@ void xine_probe_fast_memcpy(config_values_t *config) memcpy_method[i].cpu_require ) continue; - if (setjmp(sigill_return)) - continue; - - signal (SIGILL, sigill_handler); - t = rdtsc(); for(j=0;j<50;j++) { memcpy_method[i].function(buf2,buf1,BUFSIZE); memcpy_method[i].function(buf1,buf2,BUFSIZE); } - signal (SIGILL, SIG_DFL); - t = rdtsc() - t; memcpy_method[i].time = t; -- cgit v1.2.3