+/*****************************************************************************
+ * CPUCapabilities: list the processors MMX support and other capabilities
+ *****************************************************************************
+ * This function is called to list extensions the CPU may have.
+ *****************************************************************************/
+static int CPUCapabilities( void )
+{
+ int i_capabilities = CPU_CAPABILITY_NONE;
+
+#if defined( SYS_BEOS )
+ i_capabilities |= CPU_CAPABILITY_486
+ | CPU_CAPABILITY_586
+ | CPU_CAPABILITY_MMX;
+
+#elif defined( SYS_DARWIN1_3 )
+
+ struct host_basic_info hi;
+ kern_return_t ret;
+ host_name_port_t host;
+
+ int i_size;
+ char *psz_name, *psz_subname;
+
+ /* Should 'never' fail? */
+ host = mach_host_self();
+
+ i_size = sizeof( hi ) / sizeof( int );
+ ret = host_info( host, HOST_BASIC_INFO, ( host_info_t )&hi, &i_size );
+
+ if( ret != KERN_SUCCESS )
+ {
+ intf_ErrMsg( "error: couldn't get CPU information" );
+ return( i_capabilities );
+ }
+
+ slot_name( hi.cpu_type, hi.cpu_subtype, &psz_name, &psz_subname );
+ /* FIXME: need better way to detect newer proccessors.
+ * could do strncmp(a,b,5), but that's real ugly */
+ if( strcmp(psz_name, "ppc7400") || strcmp(psz_name, "ppc7450") )
+ {
+ i_capabilities |= CPU_CAPABILITY_ALTIVEC;
+ }
+
+#elif defined( __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 486 CPU */
+ asm volatile ( "pushfl\n\t"
+ "popl %%eax\n\t"
+ "movl %%eax, %%ebx\n\t"
+ "xorl $0x200000, %%eax\n\t"
+ "pushl %%eax\n\t"
+ "popfl\n\t"
+ "pushfl\n\t"
+ "popl %%eax"
+ : "=a" ( i_eax ),
+ "=b" ( i_ebx )
+ :
+ : "cc" );
+
+ if( i_eax == i_ebx )
+ {
+ return( i_capabilities );
+ }
+
+ i_capabilities |= CPU_CAPABILITY_486;
+
+ /* the CPU supports the CPUID instruction - get its level */
+ cpuid( 0x00000000 );
+
+ if( !i_eax )
+ {
+ return( i_capabilities );
+ }
+
+ /* 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_edx & 0x00800000) )
+ {
+ return( i_capabilities );
+ }
+
+ i_capabilities |= CPU_CAPABILITY_MMX;
+
+ if( i_edx & 0x02000000 )
+ {
+ i_capabilities |= CPU_CAPABILITY_MMXEXT;
+ i_capabilities |= CPU_CAPABILITY_SSE;
+ }
+
+ /* 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( b_amd && ( i_edx & 0x00400000 ) )
+ {
+ i_capabilities |= CPU_CAPABILITY_MMXEXT;
+ }
+#else
+ /* default behaviour */
+
+#endif
+ return( i_capabilities );
+}
+