src/cpuinfo/SDL_cpuinfo.c
changeset 11986 e307b74aa643
parent 11985 36aa0bf7312b
child 12242 df7260f149f2
     1.1 --- a/src/cpuinfo/SDL_cpuinfo.c	Mon May 14 00:03:39 2018 -0400
     1.2 +++ b/src/cpuinfo/SDL_cpuinfo.c	Mon May 21 11:35:42 2018 -0400
     1.3 @@ -89,6 +89,7 @@
     1.4  #define CPU_HAS_AVX     (1 << 9)
     1.5  #define CPU_HAS_AVX2    (1 << 10)
     1.6  #define CPU_HAS_NEON    (1 << 11)
     1.7 +#define CPU_HAS_AVX512F (1 << 12)
     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 @@ -247,6 +248,7 @@
    1.12  static int CPU_CPUIDFeatures[4];
    1.13  static int CPU_CPUIDMaxFunction = 0;
    1.14  static SDL_bool CPU_OSSavesYMM = SDL_FALSE;
    1.15 +static SDL_bool CPU_OSSavesZMM = SDL_FALSE;
    1.16  
    1.17  static void
    1.18  CPU_calcCPUIDFeatures(void)
    1.19 @@ -267,7 +269,7 @@
    1.20  
    1.21                  /* Check to make sure we can call xgetbv */
    1.22                  if (c & 0x08000000) {
    1.23 -                    /* Call xgetbv to see if YMM register state is saved */
    1.24 +                    /* Call xgetbv to see if YMM (etc) register state is saved */
    1.25  #if defined(__GNUC__) && (defined(i386) || defined(__x86_64__))
    1.26                      __asm__(".byte 0x0f, 0x01, 0xd0" : "=a" (a) : "c" (0) : "%edx");
    1.27  #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) && (_MSC_FULL_VER >= 160040219) /* VS2010 SP1 */
    1.28 @@ -281,6 +283,7 @@
    1.29                      }
    1.30  #endif
    1.31                      CPU_OSSavesYMM = ((a & 6) == 6) ? SDL_TRUE : SDL_FALSE;
    1.32 +                    CPU_OSSavesZMM = (CPU_OSSavesYMM && ((a & 0xe0) == 0xe0)) ? SDL_TRUE : SDL_FALSE;
    1.33                  }
    1.34              }
    1.35          }
    1.36 @@ -401,6 +404,18 @@
    1.37      return 0;
    1.38  }
    1.39  
    1.40 +static int
    1.41 +CPU_haveAVX512F(void)
    1.42 +{
    1.43 +    if (CPU_OSSavesZMM && (CPU_CPUIDMaxFunction >= 7)) {
    1.44 +        int a, b, c, d;
    1.45 +        (void) a; (void) b; (void) c; (void) d;  /* compiler warnings... */
    1.46 +        cpuid(7, a, b, c, d);
    1.47 +        return (b & 0x00010000);
    1.48 +    }
    1.49 +    return 0;
    1.50 +}
    1.51 +
    1.52  static int SDL_CPUCount = 0;
    1.53  
    1.54  int
    1.55 @@ -624,6 +639,10 @@
    1.56              SDL_CPUFeatures |= CPU_HAS_AVX2;
    1.57              SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 32);
    1.58          }
    1.59 +        if (CPU_haveAVX512F()) {
    1.60 +            SDL_CPUFeatures |= CPU_HAS_AVX512F;
    1.61 +            SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 64);
    1.62 +        }
    1.63          if (CPU_haveNEON()) {
    1.64              SDL_CPUFeatures |= CPU_HAS_NEON;
    1.65              SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 16);
    1.66 @@ -700,6 +719,12 @@
    1.67  }
    1.68  
    1.69  SDL_bool
    1.70 +SDL_HasAVX512F(void)
    1.71 +{
    1.72 +    return CPU_FEATURE_AVAILABLE(CPU_HAS_AVX512F);
    1.73 +}
    1.74 +
    1.75 +SDL_bool
    1.76  SDL_HasNEON(void)
    1.77  {
    1.78      return CPU_FEATURE_AVAILABLE(CPU_HAS_NEON);
    1.79 @@ -819,6 +844,7 @@
    1.80      printf("SSE4.2: %d\n", SDL_HasSSE42());
    1.81      printf("AVX: %d\n", SDL_HasAVX());
    1.82      printf("AVX2: %d\n", SDL_HasAVX2());
    1.83 +    printf("AVX-512F: %d\n", SDL_HasAVX512F());
    1.84      printf("NEON: %d\n", SDL_HasNEON());
    1.85      printf("RAM: %d MB\n", SDL_GetSystemRAM());
    1.86      return 0;