src/cpuinfo/SDL_cpuinfo.c
branchSDL-1.2
changeset 13212 3d6dc20a0974
parent 6908 8b9fcdd925d8
child 13219 4f88e197acad
     1.1 --- a/src/cpuinfo/SDL_cpuinfo.c	Mon Oct 21 22:21:56 2019 +0300
     1.2 +++ b/src/cpuinfo/SDL_cpuinfo.c	Thu Oct 31 14:00:28 2019 +0300
     1.3 @@ -45,6 +45,7 @@
     1.4  #define CPU_HAS_SSE	0x00000040
     1.5  #define CPU_HAS_SSE2	0x00000080
     1.6  #define CPU_HAS_ALTIVEC	0x00000100
     1.7 +#define CPU_HAS_ARM_SIMD 0x00000200
     1.8  
     1.9  #if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__ && !__OpenBSD__
    1.10  /* This is the brute force way of detecting instruction sets...
    1.11 @@ -390,6 +391,46 @@
    1.12  	return altivec; 
    1.13  }
    1.14  
    1.15 +#ifdef __linux__
    1.16 +
    1.17 +#include <unistd.h>
    1.18 +#include <sys/types.h>
    1.19 +#include <sys/stat.h>
    1.20 +#include <fcntl.h>
    1.21 +#include <elf.h>
    1.22 +
    1.23 +static __inline__ int CPU_haveARMSIMD(void)
    1.24 +{
    1.25 +	int arm_simd = 0;
    1.26 +	int fd;
    1.27 +
    1.28 +	fd = open("/proc/self/auxv", O_RDONLY);
    1.29 +	if (fd >= 0)
    1.30 +	{
    1.31 +		Elf32_auxv_t aux;
    1.32 +		while (read(fd, &aux, sizeof aux) == sizeof aux)
    1.33 +		{
    1.34 +			if (aux.a_type == AT_PLATFORM)
    1.35 +			{
    1.36 +				const char *plat = (const char *) aux.a_un.a_val;
    1.37 +				arm_simd = strncmp(plat, "v6l", 3) == 0 ||
    1.38 +				           strncmp(plat, "v7l", 3) == 0;
    1.39 +			}
    1.40 +		}
    1.41 +		close(fd);
    1.42 +	}
    1.43 +	return arm_simd;
    1.44 +}
    1.45 +
    1.46 +#else
    1.47 +
    1.48 +static __inline__ int CPU_haveARMSIMD(void)
    1.49 +{
    1.50 +	return 0;
    1.51 +}
    1.52 +
    1.53 +#endif
    1.54 +
    1.55  static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
    1.56  
    1.57  static Uint32 SDL_GetCPUFeatures(void)
    1.58 @@ -420,6 +461,9 @@
    1.59  		if ( CPU_haveAltiVec() ) {
    1.60  			SDL_CPUFeatures |= CPU_HAS_ALTIVEC;
    1.61  		}
    1.62 +		if ( CPU_haveARMSIMD() ) {
    1.63 +			SDL_CPUFeatures |= CPU_HAS_ARM_SIMD;
    1.64 +		}
    1.65  	}
    1.66  	return SDL_CPUFeatures;
    1.67  }
    1.68 @@ -488,6 +532,14 @@
    1.69  	return SDL_FALSE;
    1.70  }
    1.71  
    1.72 +SDL_bool SDL_HasARMSIMD(void)
    1.73 +{
    1.74 +	if ( SDL_GetCPUFeatures() & CPU_HAS_ARM_SIMD ) {
    1.75 +		return SDL_TRUE;
    1.76 +	}
    1.77 +	return SDL_FALSE;
    1.78 +}
    1.79 +
    1.80  #ifdef TEST_MAIN
    1.81  
    1.82  #include <stdio.h>
    1.83 @@ -502,6 +554,7 @@
    1.84  	printf("SSE: %d\n", SDL_HasSSE());
    1.85  	printf("SSE2: %d\n", SDL_HasSSE2());
    1.86  	printf("AltiVec: %d\n", SDL_HasAltiVec());
    1.87 +	printf("ARM SIMD: %d\n", SDL_HasARMSIMD());
    1.88  	return 0;
    1.89  }
    1.90