* cpu.c: CPU detection code
*****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
- * $Id: cpu.c,v 1.6 2002/08/19 11:37:57 sam Exp $
+ * $Id: cpu.c,v 1.11 2003/05/22 12:00:57 gbazin 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
*****************************************************************************/
+#ifdef HAVE_SIGNAL_H
static void SigHandler ( int );
-static u32 Capabilities ( vlc_object_t * );
+#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: get the CPU capabilities
*****************************************************************************
- * This function is a wrapper around Capabilities().
- *****************************************************************************/
-u32 __CPUCapabilities( vlc_object_t *p_this )
-{
- u32 i_capabilities;
-
- vlc_mutex_lock( p_this->p_vlc->p_global_lock );
- i_capabilities = Capabilities( p_this );
- vlc_mutex_unlock( p_this->p_vlc->p_global_lock );
-
- return i_capabilities;
-}
-
-/*****************************************************************************
- * Capabilities: list the processors MMX support and other capabilities
- *****************************************************************************
* This function is called to list extensions the CPU may have.
*****************************************************************************/
-static u32 Capabilities( 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;
volatile vlc_bool_t b_amd;
/* Needed for x86 CPU capabilities detection */
-# define cpuid( a ) \
+# define cpuid( reg ) \
asm volatile ( "pushl %%ebx\n\t" \
"cpuid\n\t" \
"movl %%ebx,%1\n\t" \
"=r" ( i_ebx ), \
"=c" ( i_ecx ), \
"=d" ( i_edx ) \
- : "a" ( a ) \
+ : "a" ( reg ) \
: "cc" );
-# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
+# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW ) \
+ && defined( HAVE_SIGNAL_H )
void (*pf_sigill) (int) = signal( SIGILL, SigHandler );
# endif
if( i_eax == i_ebx )
{
-# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
+# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW ) \
+ && defined( HAVE_SIGNAL_H )
signal( SIGILL, pf_sigill );
# endif
return i_capabilities;
if( !i_eax )
{
-# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
+# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW ) \
+ && defined( HAVE_SIGNAL_H )
signal( SIGILL, pf_sigill );
# endif
return i_capabilities;
if( ! (i_edx & 0x00800000) )
{
-# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
+# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW ) \
+ && defined( HAVE_SIGNAL_H )
signal( SIGILL, pf_sigill );
# endif
return i_capabilities;
if( i_eax < 0x80000001 )
{
-# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
+# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW ) \
+ && defined( HAVE_SIGNAL_H )
signal( SIGILL, pf_sigill );
# endif
return i_capabilities;
i_capabilities |= CPU_CAPABILITY_MMXEXT;
}
-# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
+# if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW ) \
+ && defined( HAVE_SIGNAL_H )
signal( SIGILL, pf_sigill );
# endif
return i_capabilities;
#elif defined( __powerpc__ )
-# ifdef CAN_COMPILE_ALTIVEC
+# ifdef CAN_COMPILE_ALTIVEC && defined( HAVE_SIGNAL_H )
void (*pf_sigill) (int) = signal( SIGILL, SigHandler );
i_capabilities |= CPU_CAPABILITY_FPU;
i_capabilities |= CPU_CAPABILITY_FPU;
return i_capabilities;
+#elif defined( _MSC_VER )
+ i_capabilities |= CPU_CAPABILITY_FPU;
+ return i_capabilities;
+
#else
/* default behaviour */
return i_capabilities;
* This function is called when an illegal instruction signal is received by
* the program. We use this function to test OS and CPU capabilities
*****************************************************************************/
+#if defined( HAVE_SIGNAL_H )
static void SigHandler( int i_signal )
{
/* Acknowledge the signal received */
longjmp( env, 1 );
}
+#endif