* cpu.c: CPU detection code
*****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
- * $Id: cpu.c,v 1.1 2002/06/01 12:32:01 sam Exp $
+ * $Id: cpu.c,v 1.9 2002/11/11 14:39:12 sam Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
* Christophe Massiot <massiot@via.ecp.fr>
/*****************************************************************************
* Preamble
*****************************************************************************/
-#include <signal.h> /* SIGHUP, SIGINT, SIGKILL */
-#include <setjmp.h> /* longjmp, setjmp */
-
#include <vlc/vlc.h>
+#ifdef HAVE_SIGNAL_H
+# include <signal.h> /* SIGHUP, SIGINT, SIGKILL */
+# include <setjmp.h> /* longjmp, setjmp */
+#endif
+
#ifdef SYS_DARWIN
# include <mach/mach.h> /* AltiVec detection */
# include <mach/mach_error.h> /* some day the header files||compiler *
/*****************************************************************************
* Local prototypes
*****************************************************************************/
-static void IllegalSignalHandler( int i_signal );
+#ifdef HAVE_SIGNAL_H
+static void SigHandler ( int );
+#endif
/*****************************************************************************
* Global variables - they're needed for signal handling
*****************************************************************************/
+#ifdef HAVE_SIGNAL_H
static jmp_buf env;
static int i_illegal;
+#if defined( __i386__ )
static char *psz_capability;
+#endif
+#endif
/*****************************************************************************
- * CPUCapabilities: list the processors MMX support and other capabilities
+ * CPUCapabilities: get the CPU capabilities
*****************************************************************************
* This function is called to list extensions the CPU may have.
*****************************************************************************/
-u32 CPUCapabilities( vlc_object_t *p_this )
+uint32_t CPUCapabilities( void )
{
- volatile u32 i_capabilities = CPU_CAPABILITY_NONE;
+ volatile uint32_t i_capabilities = CPU_CAPABILITY_NONE;
#if defined( SYS_DARWIN )
struct host_basic_info hi;
if( ret != KERN_SUCCESS )
{
fprintf( stderr, "error: couldn't get CPU information\n" );
- return( i_capabilities );
+ return i_capabilities;
}
slot_name( hi.cpu_type, hi.cpu_subtype, &psz_name, &psz_subname );
i_capabilities |= CPU_CAPABILITY_ALTIVEC;
}
- return( i_capabilities );
+ return i_capabilities;
#elif defined( __i386__ )
volatile unsigned int i_eax, i_ebx, i_ecx, i_edx;
: "a" ( a ) \
: "cc" );
- i_capabilities |= CPU_CAPABILITY_FPU;
-
-# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
- signal( SIGILL, IllegalSignalHandler );
+# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW ) \
+ && defined( HAVE_SIGNAL_H )
+ void (*pf_sigill) (int) = signal( SIGILL, SigHandler );
# endif
+ i_capabilities |= CPU_CAPABILITY_FPU;
+
/* test for a 486 CPU */
asm volatile ( "pushl %%ebx\n\t"
"pushfl\n\t"
if( i_eax == i_ebx )
{
-# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
- signal( SIGILL, NULL );
+# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW ) \
+ && defined( HAVE_SIGNAL_H )
+ signal( SIGILL, pf_sigill );
# endif
- return( i_capabilities );
+ return i_capabilities;
}
i_capabilities |= CPU_CAPABILITY_486;
if( !i_eax )
{
-# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
- signal( SIGILL, NULL );
+# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW ) \
+ && defined( HAVE_SIGNAL_H )
+ signal( SIGILL, pf_sigill );
# endif
- return( i_capabilities );
+ return i_capabilities;
}
/* FIXME: this isn't correct, since some 486s have cpuid */
if( ! (i_edx & 0x00800000) )
{
-# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
- signal( SIGILL, NULL );
+# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW ) \
+ && defined( HAVE_SIGNAL_H )
+ signal( SIGILL, pf_sigill );
# endif
- return( i_capabilities );
+ return i_capabilities;
}
i_capabilities |= CPU_CAPABILITY_MMX;
psz_capability = "SSE";
i_illegal = 0;
- vlc_mutex_lock( p_this->p_vlc->p_global_lock );
if( setjmp( env ) == 0 )
{
/* Test a SSE instruction */
__asm__ __volatile__ ( "xorps %%xmm0,%%xmm0\n" : : );
}
- vlc_mutex_unlock( p_this->p_vlc->p_global_lock );
if( i_illegal == 0 )
{
if( i_eax < 0x80000001 )
{
-# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
- signal( SIGILL, NULL );
+# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW ) \
+ && defined( HAVE_SIGNAL_H )
+ signal( SIGILL, pf_sigill );
# endif
- return( i_capabilities );
+ return i_capabilities;
}
/* list these additional capabilities */
psz_capability = "3D Now!";
i_illegal = 0;
- vlc_mutex_lock( p_this->p_vlc->p_global_lock );
if( setjmp( env ) == 0 )
{
/* Test a 3D Now! instruction */
__asm__ __volatile__ ( "pfadd %%mm0,%%mm0\n" "femms\n" : : );
}
- vlc_mutex_unlock( p_this->p_vlc->p_global_lock );
if( i_illegal == 0 )
{
i_capabilities |= CPU_CAPABILITY_MMXEXT;
}
-# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
- signal( SIGILL, NULL );
+# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW ) \
+ && defined( HAVE_SIGNAL_H )
+ signal( SIGILL, pf_sigill );
# endif
- return( i_capabilities );
+ return i_capabilities;
#elif defined( __powerpc__ )
- i_capabilities |= CPU_CAPABILITY_FPU;
+# ifdef CAN_COMPILE_ALTIVEC && defined( HAVE_SIGNAL_H )
+ void (*pf_sigill) (int) = signal( SIGILL, SigHandler );
-# ifdef CAN_COMPILE_ALTIVEC
- signal( SIGILL, IllegalSignalHandler );
+ i_capabilities |= CPU_CAPABILITY_FPU;
- psz_capability = "AltiVec";
i_illegal = 0;
- vlc_mutex_lock( p_this->p_vlc->p_global_lock );
if( setjmp( env ) == 0 )
{
asm volatile ("mtspr 256, %0\n\t"
:
: "r" (-1));
}
- vlc_mutex_unlock( p_this->p_vlc->p_global_lock );
if( i_illegal == 0 )
{
i_capabilities |= CPU_CAPABILITY_ALTIVEC;
}
- signal( SIGILL, NULL );
+ signal( SIGILL, pf_sigill );
# endif
- return( i_capabilities );
+ return i_capabilities;
#elif defined( __sparc__ )
i_capabilities |= CPU_CAPABILITY_FPU;
- return( i_capabilities );
+ return i_capabilities;
#else
/* default behaviour */
- return( i_capabilities );
+ return i_capabilities;
#endif
}
/*****************************************************************************
- * IllegalSignalHandler: system signal handler
+ * SigHandler: system signal handler
*****************************************************************************
* This function is called when an illegal instruction signal is received by
* the program. We use this function to test OS and CPU capabilities
*****************************************************************************/
-static void IllegalSignalHandler( int i_signal )
+#if defined( HAVE_SIGNAL_H )
+static void SigHandler( int i_signal )
{
/* Acknowledge the signal received */
i_illegal = 1;
longjmp( env, 1 );
}
+#endif