Fixed bug 1434 - Add AltiVec detection for OpenBSD/powerpc SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Wed, 18 Jul 2012 13:08:19 -0700
branchSDL-1.2
changeset 63644a08ade5b4c9
parent 6361 173deb250f75
child 6366 4488c8602961
Fixed bug 1434 - Add AltiVec detection for OpenBSD/powerpc

Brad Smith 2012-02-29 19:31:46 PST

The attached patch adds AltiVec detection for OpenBSD/powerpc. Please apply the
patch to both 2.0 and 1.2.
src/cpuinfo/SDL_cpuinfo.c
     1.1 --- a/src/cpuinfo/SDL_cpuinfo.c	Wed Jul 11 21:55:36 2012 -0400
     1.2 +++ b/src/cpuinfo/SDL_cpuinfo.c	Wed Jul 18 13:08:19 2012 -0700
     1.3 @@ -28,6 +28,10 @@
     1.4  
     1.5  #if defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))
     1.6  #include <sys/sysctl.h> /* For AltiVec check */
     1.7 +#elif defined(__OpenBSD__) && defined(__powerpc__)
     1.8 +#include <sys/param.h>
     1.9 +#include <sys/sysctl.h> /* For AltiVec check */
    1.10 +#include <machine/cpu.h>
    1.11  #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
    1.12  #include <signal.h>
    1.13  #include <setjmp.h>
    1.14 @@ -42,7 +46,7 @@
    1.15  #define CPU_HAS_SSE2	0x00000080
    1.16  #define CPU_HAS_ALTIVEC	0x00000100
    1.17  
    1.18 -#if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__
    1.19 +#if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__ && !__OpenBSD__
    1.20  /* This is the brute force way of detecting instruction sets...
    1.21     the idea is borrowed from the libmpeg2 library - thanks!
    1.22   */
    1.23 @@ -359,8 +363,12 @@
    1.24  static __inline__ int CPU_haveAltiVec(void)
    1.25  {
    1.26  	volatile int altivec = 0;
    1.27 -#if defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))
    1.28 -	int selectors[2] = { CTL_HW, HW_VECTORUNIT }; 
    1.29 +#if (defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))) || (defined(__OpenBSD__) && defined(__powerpc__))
    1.30 +# ifdef __OpenBSD__
    1.31 +	int selectors[2] = { CTL_MACHDEP, CPU_ALTIVEC };
    1.32 +# else
    1.33 +	int selectors[2] = { CTL_HW, HW_VECTORUNIT };
    1.34 +# endif
    1.35  	int hasVectorUnit = 0; 
    1.36  	size_t length = sizeof(hasVectorUnit); 
    1.37  	int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0);