src/cpuinfo/SDL_cpuinfo.c
changeset 778 8ac3f46f9d09
parent 769 b8d311d90021
child 784 a2dde6aff60e
     1.1 --- a/src/cpuinfo/SDL_cpuinfo.c	Tue Jan 06 17:16:02 2004 +0000
     1.2 +++ b/src/cpuinfo/SDL_cpuinfo.c	Tue Jan 06 17:18:38 2004 +0000
     1.3 @@ -30,10 +30,15 @@
     1.4  #include "SDL.h"
     1.5  #include "SDL_cpuinfo.h"
     1.6  
     1.7 +#ifdef MACOSX
     1.8 +#include <sys/sysctl.h> /* For AltiVec check */
     1.9 +#endif
    1.10 +
    1.11  #define CPU_HAS_RDTSC	0x00000001
    1.12  #define CPU_HAS_MMX	0x00000002
    1.13  #define CPU_HAS_3DNOW	0x00000004
    1.14  #define CPU_HAS_SSE	0x00000008
    1.15 +#define CPU_HAS_ALTIVEC	0x00000010
    1.16  
    1.17  static __inline__ int CPU_haveCPUID()
    1.18  {
    1.19 @@ -186,6 +191,23 @@
    1.20  	return 0;
    1.21  }
    1.22  
    1.23 +static __inline__ int CPU_haveAltiVec()
    1.24 +{
    1.25 +#ifdef MACOSX
    1.26 +	/* TODO: This check works on OS X. It would be nice to detect AltiVec
    1.27 +	   properly on for example Linux/PPC, too. But I don't know how that
    1.28 +	   is done in Linux (or FreeBSD, or whatever other OS you run PPC :-)
    1.29 +	 */
    1.30 +	int selectors[2] = { CTL_HW, HW_VECTORUNIT }; 
    1.31 +	int hasVectorUnit = 0; 
    1.32 +	size_t length = sizeof(hasVectorUnit); 
    1.33 +	int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0); 
    1.34 +	if( 0 == error )
    1.35 +		return hasVectorUnit != 0; 
    1.36 +#endif
    1.37 +	return 0; 
    1.38 +}
    1.39 +
    1.40  static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
    1.41  
    1.42  static Uint32 SDL_GetCPUFeatures()
    1.43 @@ -204,6 +226,9 @@
    1.44  		if ( CPU_haveSSE() ) {
    1.45  			SDL_CPUFeatures |= CPU_HAS_SSE;
    1.46  		}
    1.47 +		if ( CPU_haveAltiVec() ) {
    1.48 +			SDL_CPUFeatures |= CPU_HAS_ALTIVEC;
    1.49 +		}
    1.50  	}
    1.51  	return SDL_CPUFeatures;
    1.52  }
    1.53 @@ -240,15 +265,25 @@
    1.54  	return SDL_FALSE;
    1.55  }
    1.56  
    1.57 +SDL_bool SDL_HasAltiVec()
    1.58 +{
    1.59 +	if ( SDL_GetCPUFeatures() & CPU_HAS_ALTIVEC ) {
    1.60 +		return SDL_TRUE;
    1.61 +	}
    1.62 +	return SDL_FALSE;
    1.63 +}
    1.64 +
    1.65  #ifdef TEST_MAIN
    1.66  
    1.67  #include <stdio.h>
    1.68  
    1.69  int main()
    1.70  {
    1.71 +	printf("RDTSC: %d\n", SDL_HasRDTSC());
    1.72  	printf("MMX: %d\n", SDL_HasMMX());
    1.73  	printf("3DNow: %d\n", SDL_Has3DNow());
    1.74  	printf("SSE: %d\n", SDL_HasSSE());
    1.75 +	printf("AltiVec: %d\n", SDL_HasAltiVec());
    1.76  	return 0;
    1.77  }
    1.78