src/cpuinfo/SDL_cpuinfo.c
branchSDL-1.2
changeset 13219 4f88e197acad
parent 13212 3d6dc20a0974
child 13396 f765d8961a16
     1.1 --- a/src/cpuinfo/SDL_cpuinfo.c	Thu Oct 31 14:00:28 2019 +0300
     1.2 +++ b/src/cpuinfo/SDL_cpuinfo.c	Thu Oct 31 14:00:28 2019 +0300
     1.3 @@ -46,6 +46,7 @@
     1.4  #define CPU_HAS_SSE2	0x00000080
     1.5  #define CPU_HAS_ALTIVEC	0x00000100
     1.6  #define CPU_HAS_ARM_SIMD 0x00000200
     1.7 +#define CPU_HAS_ARM_NEON 0x00000400
     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 @@ -422,6 +423,25 @@
    1.12  	return arm_simd;
    1.13  }
    1.14  
    1.15 +static __inline__ int CPU_haveARMNEON(void)
    1.16 +{
    1.17 +	int arm_neon = 0;
    1.18 +	int fd;
    1.19 +
    1.20 +	fd = open("/proc/self/auxv", O_RDONLY);
    1.21 +	if (fd >= 0)
    1.22 +	{
    1.23 +		Elf32_auxv_t aux;
    1.24 +		while (read(fd, &aux, sizeof aux) == sizeof aux)
    1.25 +		{
    1.26 +			if (aux.a_type == AT_HWCAP)
    1.27 +				arm_neon = (aux.a_un.a_val & 4096) != 0;
    1.28 +		}
    1.29 +		close(fd);
    1.30 +	}
    1.31 +	return arm_neon;
    1.32 +}
    1.33 +
    1.34  #else
    1.35  
    1.36  static __inline__ int CPU_haveARMSIMD(void)
    1.37 @@ -429,6 +449,11 @@
    1.38  	return 0;
    1.39  }
    1.40  
    1.41 +static __inline__ int CPU_haveARMNEON(void)
    1.42 +{
    1.43 +	return 0;
    1.44 +}
    1.45 +
    1.46  #endif
    1.47  
    1.48  static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
    1.49 @@ -464,6 +489,9 @@
    1.50  		if ( CPU_haveARMSIMD() ) {
    1.51  			SDL_CPUFeatures |= CPU_HAS_ARM_SIMD;
    1.52  		}
    1.53 +		if ( CPU_haveARMNEON() ) {
    1.54 +			SDL_CPUFeatures |= CPU_HAS_ARM_NEON;
    1.55 +		}
    1.56  	}
    1.57  	return SDL_CPUFeatures;
    1.58  }
    1.59 @@ -540,6 +568,14 @@
    1.60  	return SDL_FALSE;
    1.61  }
    1.62  
    1.63 +SDL_bool SDL_HasARMNEON(void)
    1.64 +{
    1.65 +	if ( SDL_GetCPUFeatures() & CPU_HAS_ARM_NEON ) {
    1.66 +		return SDL_TRUE;
    1.67 +	}
    1.68 +	return SDL_FALSE;
    1.69 +}
    1.70 +
    1.71  #ifdef TEST_MAIN
    1.72  
    1.73  #include <stdio.h>
    1.74 @@ -555,6 +591,7 @@
    1.75  	printf("SSE2: %d\n", SDL_HasSSE2());
    1.76  	printf("AltiVec: %d\n", SDL_HasAltiVec());
    1.77  	printf("ARM SIMD: %d\n", SDL_HasARMSIMD());
    1.78 +	printf("ARM NEON: %d\n", SDL_HasARMNEON());
    1.79  	return 0;
    1.80  }
    1.81