]> git.sesse.net Git - vlc/blobdiff - include/tests.h
* Bug fixes and enhancements in the Gtk+/Gnome interfaces.
[vlc] / include / tests.h
index 047bffd23790023319d6efc9933e9e1094b07ca5..c6bd76183bd3252b6f70c785771ee274fd13a030 100644 (file)
@@ -3,7 +3,7 @@
  *****************************************************************************
  * Copyright (C) 1996, 1997, 1998, 1999, 2000 VideoLAN
  *
- * Authors:
+ * Authors: Samuel Hocevar <sam@zoy.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *****************************************************************************/
 
 #define CPU_CAPABILITY_NONE    0
-#define CPU_CAPABILITY_MMX     1<<0
-#define CPU_CAPABILITY_3DNOW   1<<1
-#define CPU_CAPABILITY_MMXEXT  1<<2
-
-#define cpuid( a, eax, ebx, ecx, edx ) \
-    asm volatile ( "pushl %%ebx      \n\
-                    cpuid            \n\
-                    popl %%ebx"        \
-                 : "=a" ( eax ),       \
-                   "=c" ( ecx ),       \
-                   "=d" ( edx )        \
-                 : "a"  ( a )          \
-                 : "cc" );
+#define CPU_CAPABILITY_486     1<<0
+#define CPU_CAPABILITY_586     1<<1
+#define CPU_CAPABILITY_PPRO    1<<2
+#define CPU_CAPABILITY_MMX     1<<3
+#define CPU_CAPABILITY_3DNOW   1<<4
+#define CPU_CAPABILITY_MMXEXT  1<<5
 
 /*****************************************************************************
  * TestVersion: tests if the given string equals the current version
 int TestVersion( char * psz_version );
 int TestProgram( char * psz_program );
 int TestMethod( char * psz_var, char * psz_method );
+int TestCPU( int i_capabilities );
 
 /*****************************************************************************
- * TestCPU: tests if the processor has MMX support and other capabilities
+ * CPUCapabilities: list the processors MMX support and other capabilities
  *****************************************************************************
- * This function is called to check extensions the CPU may have.
+ * This function is called to list extensions the CPU may have.
  *****************************************************************************/
-static __inline__ int TestCPU( void )
+static __inline__ int CPUCapabilities( void )
 {
-#ifndef __i386__
-    return( CPU_CAPABILITY_NONE );
+#ifdef SYS_BEOS
+    return( CPU_CAPABILITY_NONE
+            | CPU_CAPABILITY_486
+            | CPU_CAPABILITY_586
+            | CPU_CAPABILITY_MMX );
 #else
-    int i_reg, i_dummy = 0;
+    int           i_capabilities = CPU_CAPABILITY_NONE;
+#ifdef __i386__
+    unsigned int  i_eax, i_ebx, i_ecx, i_edx;
+    boolean_t     b_amd;
+
+#define cpuid( a )                 \
+    asm volatile ( "cpuid"         \
+                 : "=a" ( i_eax ), \
+                   "=b" ( i_ebx ), \
+                   "=c" ( i_ecx ), \
+                   "=d" ( i_edx )  \
+                 : "a"  ( a )      \
+                 : "cc" );         \
 
-    /* test for a 386 CPU */
+    /* test for a 486 CPU */
     asm volatile ( "pushfl
                     popl %%eax
-                    movl %%eax, %%ecx
-                    xorl $0x40000, %%eax
+                    movl %%eax, %%ebx
+                    xorl $0x200000, %%eax
                     pushl %%eax
                     popfl
                     pushfl
-                    popl %%eax
-                    xorl %%ecx, %%eax
-                    andl $0x40000, %%eax"
-                 : "=a" ( i_reg ) );
+                    popl %%eax"
+                 : "=a" ( i_eax ),
+                   "=b" ( i_ebx )
+                 :
+                 : "cc" );
 
-    if( !i_reg )
+    if( i_eax == i_ebx )
     {
-        return( CPU_CAPABILITY_NONE );
+        return( i_capabilities );
     }
 
-    /* test for a 486 CPU */
-    asm volatile ( "movl %%ecx, %%eax
-                    xorl $0x200000, %%eax
-                    pushl %%eax
-                    popfl
-                    pushfl
-                    popl %%eax
-                    xorl %%ecx, %%eax
-                    pushl %%ecx
-                    popfl
-                    andl $0x200000, %%eax"
-                 : "=a" ( i_reg ) );
+    i_capabilities |= CPU_CAPABILITY_486;
+
+    /* the CPU supports the CPUID instruction - get its level */
+    cpuid( 0x00000000 );
 
-    if( !i_reg )
+    if( !i_eax )
     {
-        return( CPU_CAPABILITY_NONE );
+        return( i_capabilities );
     }
 
-    /* the CPU supports the CPUID instruction - get its level */
-    cpuid( 0, i_reg, i_dummy, i_dummy, i_dummy );
+    /* FIXME: this isn't correct, since some 486s have cpuid */
+    i_capabilities |= CPU_CAPABILITY_586;
+
+    /* borrowed from mpeg2dec */
+    b_amd = ( i_ebx == 0x68747541 ) && ( i_ecx == 0x444d4163 )
+                    && ( i_edx == 0x69746e65 );
+
+    /* test for the MMX flag */
+    cpuid( 0x00000001 );
 
-    if( !i_reg )
+    if( ! (i_edx & 0x00800000) )
     {
-        return( CPU_CAPABILITY_NONE );
+        return( i_capabilities );
     }
 
-    /* test for the MMX flag */
-    cpuid( 1, i_dummy, i_dummy, i_dummy, i_reg );
+    i_capabilities |= CPU_CAPABILITY_MMX;
+
+    if( i_edx & 0x02000000 )
+    {
+        i_capabilities |= CPU_CAPABILITY_MMXEXT;
+    }
+    
+    /* test for additional capabilities */
+    cpuid( 0x80000000 );
+
+    if( i_eax < 0x80000001 )
+    {
+        return( i_capabilities );
+    }
+
+    /* list these additional capabilities */
+    cpuid( 0x80000001 );
+
+    if( i_edx & 0x80000000 )
+    {
+        i_capabilities |= CPU_CAPABILITY_3DNOW;
+    }
 
-    if( ! (i_reg & 0x00800000) )
+    if( b_amd && ( i_edx & 0x00400000 ) )
     {
-        return( CPU_CAPABILITY_NONE );
+        i_capabilities |= CPU_CAPABILITY_MMXEXT;
     }
+#endif /* __i386__ */
 
-    return( CPU_CAPABILITY_MMX );
-#endif
+    return( i_capabilities );
+#endif /* SYS_BEOS */
 }