src/cpuinfo/SDL_cpuinfo.c
changeset 10626 04035f36048e
parent 10625 d40f7ebf34eb
child 10627 35fe16a7960a
     1.1 --- a/src/cpuinfo/SDL_cpuinfo.c	Thu Nov 17 16:01:59 2016 -0500
     1.2 +++ b/src/cpuinfo/SDL_cpuinfo.c	Thu Nov 17 16:04:00 2016 -0500
     1.3 @@ -50,10 +50,11 @@
     1.4  #include <setjmp.h>
     1.5  #endif
     1.6  
     1.7 -#if defined(__LINUX__) || defined(__ANDROID__) && defined(__ARM_ARCH)
     1.8 +#if (defined(__LINUX__) || defined(__ANDROID__)) && defined(__ARM_ARCH)
     1.9 +#include <asm/hwcap.h>
    1.10 +#if defined HAVE_GETAUXVAL
    1.11  #include <sys/auxv.h>
    1.12 -#include <asm/hwcap.h>
    1.13 -#if !defined HAVE_GETAUXVAL
    1.14 +#else
    1.15  #include <fcntl.h>
    1.16  #endif
    1.17  #endif
    1.18 @@ -297,27 +298,22 @@
    1.19      return altivec;
    1.20  }
    1.21  
    1.22 -#if (defined(__LINUX__) || defined(__ANDROID__)) && !defined(HAVE_GETAUXVAL)
    1.23 +#if (defined(__LINUX__) || defined(__ANDROID__)) && defined(__ARM_ARCH) && !defined(HAVE_GETAUXVAL)
    1.24  static int
    1.25  readProcAuxvForNeon(void)
    1.26  {
    1.27      int neon = 0;
    1.28      int kv[2];
    1.29      const int fd = open("/proc/self/auxv", O_RDONLY);
    1.30 -
    1.31 -    if (fd == -1) {
    1.32 -        return 0;
    1.33 +    if (fd != -1) {
    1.34 +        while (read(fd, kv, sizeof (kv)) == sizeof (kv)) {
    1.35 +            if (kv[0] == AT_HWCAP) {
    1.36 +                neon = ((kv[1] & HWCAP_NEON) == HWCAP_NEON);
    1.37 +                break;
    1.38 +            }
    1.39 +        }
    1.40 +        close(fd);
    1.41      }
    1.42 -
    1.43 -    while (read(fd, kv, sizeof (kv)) == sizeof (kv)) {
    1.44 -        if (kv[0] == AT_HWCAP) {
    1.45 -            neon = ((kv[1] & HWCAP_NEON) == HWCAP_NEON);
    1.46 -            break;
    1.47 -        }
    1.48 -    }
    1.49 -
    1.50 -    close(fd);
    1.51 -
    1.52      return neon;
    1.53  }
    1.54  #endif
    1.55 @@ -338,11 +334,10 @@
    1.56      size_t length = sizeof (neon);
    1.57      const int error = sysctlbyname("hw.optional.neon", &neon, &length, NULL, 0);
    1.58      return (!error) && (neon != 0);
    1.59 -/* Android offers a static library for this but all it does is parse /proc/cpuinfo */
    1.60  #elif (defined(__LINUX__) || defined(__ANDROID__)) && defined(HAVE_GETAUXVAL)
    1.61      return ((getauxval(AT_HWCAP) & HWCAP_NEON) == HWCAP_NEON)
    1.62  #elif (defined(__LINUX__) || defined(__ANDROID__))
    1.63 -    return readProcAuxvForNeon();
    1.64 +    return readProcAuxvForNeon();   /* Android offers a static library for this, but it just parses /proc/self/auxv */
    1.65  #elif (defined(__WINDOWS__) || defined(__WINRT__)) && defined(_M_ARM)
    1.66      /* All WinRT ARM devices are required to support NEON, but just in case. */
    1.67      return IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE) != 0;