Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
authorSam Lantinga <slouken@libsdl.org>
Fri, 11 Feb 2011 23:02:35 -0800
changeset 5263e1122f31fec5
parent 5262 b530ef003506
child 5264 7ace5f8f432f
Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
include/SDL_cpuinfo.h
src/cpuinfo/SDL_cpuinfo.c
test/testplatform.c
     1.1 --- a/include/SDL_cpuinfo.h	Fri Feb 11 22:37:15 2011 -0800
     1.2 +++ b/include/SDL_cpuinfo.h	Fri Feb 11 23:02:35 2011 -0800
     1.3 @@ -85,9 +85,14 @@
     1.4  extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void);
     1.5  
     1.6  /**
     1.7 - *  This function returns true if the CPU has SSE4 features.
     1.8 + *  This function returns true if the CPU has SSE4.1 features.
     1.9   */
    1.10 -extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE4(void);
    1.11 +extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void);
    1.12 +
    1.13 +/**
    1.14 + *  This function returns true if the CPU has SSE4.2 features.
    1.15 + */
    1.16 +extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void);
    1.17  
    1.18  
    1.19  /* Ends C function definitions when using C++ */
     2.1 --- a/src/cpuinfo/SDL_cpuinfo.c	Fri Feb 11 22:37:15 2011 -0800
     2.2 +++ b/src/cpuinfo/SDL_cpuinfo.c	Fri Feb 11 23:02:35 2011 -0800
     2.3 @@ -41,7 +41,8 @@
     2.4  #define CPU_HAS_SSE     0x00000010
     2.5  #define CPU_HAS_SSE2    0x00000020
     2.6  #define CPU_HAS_SSE3    0x00000040
     2.7 -#define CPU_HAS_SSE4    0x00000080
     2.8 +#define CPU_HAS_SSE41   0x00000080
     2.9 +#define CPU_HAS_SSE42   0x00000100
    2.10  
    2.11  
    2.12  static __inline__ int
    2.13 @@ -234,15 +235,30 @@
    2.14  }
    2.15  
    2.16  static __inline__ int
    2.17 -CPU_haveSSE4(void)
    2.18 +CPU_haveSSE41(void)
    2.19  {
    2.20      if (CPU_haveCPUID()) {
    2.21          int a, b, c, d;
    2.22  
    2.23 -        cpuid(0, a, b, c, d);
    2.24 +        cpuid(1, a, b, c, d);
    2.25          if (a >= 1) {
    2.26              cpuid(1, a, b, c, d);
    2.27 -            return (c & 0x00000100);
    2.28 +            return (c & 0x00080000);
    2.29 +        }
    2.30 +    }
    2.31 +    return 0;
    2.32 +}
    2.33 +
    2.34 +static __inline__ int
    2.35 +CPU_haveSSE42(void)
    2.36 +{
    2.37 +    if (CPU_haveCPUID()) {
    2.38 +        int a, b, c, d;
    2.39 +
    2.40 +        cpuid(1, a, b, c, d);
    2.41 +        if (a >= 1) {
    2.42 +            cpuid(1, a, b, c, d);
    2.43 +            return (c & 0x00100000);
    2.44          }
    2.45      }
    2.46      return 0;
    2.47 @@ -427,8 +443,11 @@
    2.48          if (CPU_haveSSE3()) {
    2.49              SDL_CPUFeatures |= CPU_HAS_SSE3;
    2.50          }
    2.51 -        if (CPU_haveSSE4()) {
    2.52 -            SDL_CPUFeatures |= CPU_HAS_SSE4;
    2.53 +        if (CPU_haveSSE41()) {
    2.54 +            SDL_CPUFeatures |= CPU_HAS_SSE41;
    2.55 +        }
    2.56 +        if (CPU_haveSSE42()) {
    2.57 +            SDL_CPUFeatures |= CPU_HAS_SSE42;
    2.58          }
    2.59      }
    2.60      return SDL_CPUFeatures;
    2.61 @@ -480,9 +499,18 @@
    2.62  }
    2.63  
    2.64  SDL_bool
    2.65 -SDL_HasSSE4(void)
    2.66 +SDL_HasSSE41(void)
    2.67  {
    2.68 -    if (SDL_GetCPUFeatures() & CPU_HAS_SSE4) {
    2.69 +    if (SDL_GetCPUFeatures() & CPU_HAS_SSE41) {
    2.70 +        return SDL_TRUE;
    2.71 +    }
    2.72 +    return SDL_FALSE;
    2.73 +}
    2.74 +
    2.75 +SDL_bool
    2.76 +SDL_HasSSE42(void)
    2.77 +{
    2.78 +    if (SDL_GetCPUFeatures() & CPU_HAS_SSE42) {
    2.79          return SDL_TRUE;
    2.80      }
    2.81      return SDL_FALSE;
    2.82 @@ -504,7 +532,8 @@
    2.83      printf("SSE: %d\n", SDL_HasSSE());
    2.84      printf("SSE2: %d\n", SDL_HasSSE2());
    2.85      printf("SSE3: %d\n", SDL_HasSSE3());
    2.86 -    printf("SSE4: %d\n", SDL_HasSSE4());
    2.87 +    printf("SSE4.1: %d\n", SDL_HasSSE41());
    2.88 +    printf("SSE4.2: %d\n", SDL_HasSSE42());
    2.89      return 0;
    2.90  }
    2.91  
     3.1 --- a/test/testplatform.c	Fri Feb 11 22:37:15 2011 -0800
     3.2 +++ b/test/testplatform.c	Fri Feb 11 23:02:35 2011 -0800
     3.3 @@ -146,7 +146,8 @@
     3.4          printf("SSE %s\n", SDL_HasSSE()? "detected" : "not detected");
     3.5          printf("SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected");
     3.6          printf("SSE3 %s\n", SDL_HasSSE3()? "detected" : "not detected");
     3.7 -        printf("SSE4 %s\n", SDL_HasSSE4()? "detected" : "not detected");
     3.8 +        printf("SSE4.1 %s\n", SDL_HasSSE41()? "detected" : "not detected");
     3.9 +        printf("SSE4.2 %s\n", SDL_HasSSE42()? "detected" : "not detected");
    3.10      }
    3.11      return (0);
    3.12  }