Added SDL_GetCPUCount() to see how many cores are available.
authorSam Lantinga <slouken@libsdl.org>
Wed, 16 Dec 2009 06:53:53 +0000
changeset 35793427271a2d75
parent 3578 0d1b16ee0bca
child 3580 951dd6a5d1a2
Added SDL_GetCPUCount() to see how many cores are available.
configure.in
include/SDL_config.h.in
include/SDL_config_iphoneos.h
include/SDL_config_macosx.h
include/SDL_cpuinfo.h
src/cpuinfo/SDL_cpuinfo.c
src/thread/SDL_systhread.h
test/automated/platform/platform.c
test/testplatform.c
     1.1 --- a/configure.in	Wed Dec 16 04:48:11 2009 +0000
     1.2 +++ b/configure.in	Wed Dec 16 06:53:53 2009 +0000
     1.3 @@ -207,7 +207,7 @@
     1.4          AC_DEFINE(HAVE_MPROTECT)
     1.5          ]),
     1.6      )
     1.7 -    AC_CHECK_FUNCS(malloc calloc realloc free getenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp sscanf snprintf vsnprintf sigaction setjmp nanosleep)
     1.8 +    AC_CHECK_FUNCS(malloc calloc realloc free getenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp sscanf snprintf vsnprintf sigaction setjmp nanosleep sysctlbyname)
     1.9  
    1.10      AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"])
    1.11      AC_CHECK_FUNCS(ceil copysign cos cosf fabs floor log pow scalbn sin sinf sqrt)
     2.1 --- a/include/SDL_config.h.in	Wed Dec 16 04:48:11 2009 +0000
     2.2 +++ b/include/SDL_config.h.in	Wed Dec 16 06:53:53 2009 +0000
     2.3 @@ -150,6 +150,7 @@
     2.4  #undef HAVE_SIGACTION
     2.5  #undef HAVE_SETJMP
     2.6  #undef HAVE_NANOSLEEP
     2.7 +#undef HAVE_SYSCTLBYNAME
     2.8  #undef HAVE_CLOCK_GETTIME
     2.9  #undef HAVE_GETPAGESIZE
    2.10  #undef HAVE_MPROTECT
     3.1 --- a/include/SDL_config_iphoneos.h	Wed Dec 16 04:48:11 2009 +0000
     3.2 +++ b/include/SDL_config_iphoneos.h	Wed Dec 16 06:53:53 2009 +0000
     3.3 @@ -106,6 +106,7 @@
     3.4  #define HAVE_SIGACTION	1
     3.5  #define HAVE_SETJMP	1
     3.6  #define HAVE_NANOSLEEP	1
     3.7 +#define HAVE_SYSCTLBYNAME 1
     3.8  
     3.9  /* enable iPhone version of Core Audio driver */
    3.10  #define SDL_AUDIO_DRIVER_COREAUDIOIPHONE 1
     4.1 --- a/include/SDL_config_macosx.h	Wed Dec 16 04:48:11 2009 +0000
     4.2 +++ b/include/SDL_config_macosx.h	Wed Dec 16 06:53:53 2009 +0000
     4.3 @@ -105,6 +105,7 @@
     4.4  #define HAVE_SIGACTION	1
     4.5  #define HAVE_SETJMP	1
     4.6  #define HAVE_NANOSLEEP	1
     4.7 +#define HAVE_SYSCTLBYNAME 1
     4.8  
     4.9  /* Enable various audio drivers */
    4.10  #define SDL_AUDIO_DRIVER_COREAUDIO	1
     5.1 --- a/include/SDL_cpuinfo.h	Wed Dec 16 04:48:11 2009 +0000
     5.2 +++ b/include/SDL_cpuinfo.h	Wed Dec 16 06:53:53 2009 +0000
     5.3 @@ -40,6 +40,11 @@
     5.4  #endif
     5.5  
     5.6  /**
     5.7 + *  This function returns the number of CPU cores available.
     5.8 + */
     5.9 +extern DECLSPEC int SDLCALL SDL_GetCPUCount(void);
    5.10 +
    5.11 +/**
    5.12   *  This function returns true if the CPU has the RDTSC instruction.
    5.13   */
    5.14  extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void);
     6.1 --- a/src/cpuinfo/SDL_cpuinfo.c	Wed Dec 16 04:48:11 2009 +0000
     6.2 +++ b/src/cpuinfo/SDL_cpuinfo.c	Wed Dec 16 06:53:53 2009 +0000
     6.3 @@ -25,6 +25,10 @@
     6.4  
     6.5  #include "SDL_cpuinfo.h"
     6.6  
     6.7 +#ifdef HAVE_SYSCTLBYNAME
     6.8 +#include <sys/types.h>
     6.9 +#include <sys/sysctl.h>
    6.10 +#endif
    6.11  #if defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))
    6.12  #include <sys/sysctl.h>         /* For AltiVec check */
    6.13  #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
    6.14 @@ -32,14 +36,14 @@
    6.15  #include <setjmp.h>
    6.16  #endif
    6.17  
    6.18 -#define CPU_HAS_RDTSC	0x00000001
    6.19 -#define CPU_HAS_MMX	0x00000002
    6.20 -#define CPU_HAS_MMXEXT	0x00000004
    6.21 -#define CPU_HAS_3DNOW	0x00000010
    6.22 +#define CPU_HAS_RDTSC   0x00000001
    6.23 +#define CPU_HAS_MMX     0x00000002
    6.24 +#define CPU_HAS_MMXEXT  0x00000004
    6.25 +#define CPU_HAS_3DNOW   0x00000010
    6.26  #define CPU_HAS_3DNOWEXT 0x00000020
    6.27 -#define CPU_HAS_SSE	0x00000040
    6.28 -#define CPU_HAS_SSE2	0x00000080
    6.29 -#define CPU_HAS_ALTIVEC	0x00000100
    6.30 +#define CPU_HAS_SSE     0x00000040
    6.31 +#define CPU_HAS_SSE2    0x00000080
    6.32 +#define CPU_HAS_ALTIVEC 0x00000100
    6.33  
    6.34  #if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__
    6.35  /* This is the brute force way of detecting instruction sets...
    6.36 @@ -59,7 +63,7 @@
    6.37      int has_CPUID = 0;
    6.38  /* *INDENT-OFF* */
    6.39  #if defined(__GNUC__) && defined(i386)
    6.40 -	__asm__ (
    6.41 +    __asm__ (
    6.42  "        pushfl                      # Get original EFLAGS             \n"
    6.43  "        popl    %%eax                                                 \n"
    6.44  "        movl    %%eax,%%ecx                                           \n"
    6.45 @@ -72,14 +76,14 @@
    6.46  "        jz      1f                  # Processor=80486                 \n"
    6.47  "        movl    $1,%0               # We have CPUID support           \n"
    6.48  "1:                                                                    \n"
    6.49 -	: "=m" (has_CPUID)
    6.50 -	:
    6.51 -	: "%eax", "%ecx"
    6.52 -	);
    6.53 +    : "=m" (has_CPUID)
    6.54 +    :
    6.55 +    : "%eax", "%ecx"
    6.56 +    );
    6.57  #elif defined(__GNUC__) && defined(__x86_64__)
    6.58  /* Technically, if this is being compiled under __x86_64__ then it has 
    6.59  CPUid by definition.  But it's nice to be able to prove it.  :)      */
    6.60 -	__asm__ (
    6.61 +    __asm__ (
    6.62  "        pushfq                      # Get original EFLAGS             \n"
    6.63  "        popq    %%rax                                                 \n"
    6.64  "        movq    %%rax,%%rcx                                           \n"
    6.65 @@ -92,12 +96,12 @@
    6.66  "        jz      1f                  # Processor=80486                 \n"
    6.67  "        movl    $1,%0               # We have CPUID support           \n"
    6.68  "1:                                                                    \n"
    6.69 -	: "=m" (has_CPUID)
    6.70 -	:
    6.71 -	: "%rax", "%rcx"
    6.72 -	);
    6.73 +    : "=m" (has_CPUID)
    6.74 +    :
    6.75 +    : "%rax", "%rcx"
    6.76 +    );
    6.77  #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
    6.78 -	__asm {
    6.79 +    __asm {
    6.80          pushfd                      ; Get original EFLAGS
    6.81          pop     eax
    6.82          mov     ecx, eax
    6.83 @@ -110,24 +114,24 @@
    6.84          jz      done                ; Processor=80486
    6.85          mov     has_CPUID,1         ; We have CPUID support
    6.86  done:
    6.87 -	}
    6.88 +    }
    6.89  #elif defined(__sun) && defined(__i386)
    6.90 -	__asm (
    6.91 +    __asm (
    6.92  "       pushfl                 \n"
    6.93 -"	popl    %eax           \n"
    6.94 -"	movl    %eax,%ecx      \n"
    6.95 -"	xorl    $0x200000,%eax \n"
    6.96 -"	pushl   %eax           \n"
    6.97 -"	popfl                  \n"
    6.98 -"	pushfl                 \n"
    6.99 -"	popl    %eax           \n"
   6.100 -"	xorl    %ecx,%eax      \n"
   6.101 -"	jz      1f             \n"
   6.102 -"	movl    $1,-8(%ebp)    \n"
   6.103 +"   popl    %eax           \n"
   6.104 +"   movl    %eax,%ecx      \n"
   6.105 +"   xorl    $0x200000,%eax \n"
   6.106 +"   pushl   %eax           \n"
   6.107 +"   popfl                  \n"
   6.108 +"   pushfl                 \n"
   6.109 +"   popl    %eax           \n"
   6.110 +"   xorl    %ecx,%eax      \n"
   6.111 +"   jz      1f             \n"
   6.112 +"   movl    $1,-8(%ebp)    \n"
   6.113  "1:                            \n"
   6.114 -	);
   6.115 +    );
   6.116  #elif defined(__sun) && defined(__amd64)
   6.117 -	__asm (
   6.118 +    __asm (
   6.119  "       pushfq                 \n"
   6.120  "       popq    %rax           \n"
   6.121  "       movq    %rax,%rcx      \n"
   6.122 @@ -140,92 +144,42 @@
   6.123  "       jz      1f             \n"
   6.124  "       movl    $1,-8(%rbp)    \n"
   6.125  "1:                            \n"
   6.126 -	);
   6.127 +    );
   6.128  #endif
   6.129  /* *INDENT-ON* */
   6.130      return has_CPUID;
   6.131  }
   6.132  
   6.133 +#if defined(__GNUC__) && (defined(i386) || defined(__x86_64__))
   6.134 +#define cpuid(func, ax, bx, cx, dx) \
   6.135 +    __asm__ __volatile__ ("cpuid": \
   6.136 +    "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (func))
   6.137 +#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
   6.138 +#define cpuid(func, ax, bx, cx, dx) \
   6.139 +    asm { \
   6.140 +        mov eax, func \
   6.141 +        cpuid
   6.142 +        mov ax, eax \
   6.143 +        mov bx, ebx \
   6.144 +        mov cx, ecx \
   6.145 +        mov dx, edx \
   6.146 +    }
   6.147 +#else
   6.148 +#define cpuid(func, ax, bx, cx, dx) \
   6.149 +    ax = bx = cx = dx = 0
   6.150 +#endif
   6.151 +
   6.152  static __inline__ int
   6.153  CPU_getCPUIDFeatures(void)
   6.154  {
   6.155      int features = 0;
   6.156 -/* *INDENT-OFF* */
   6.157 -#if defined(__GNUC__) && defined(i386)
   6.158 -	__asm__ (
   6.159 -"        xorl    %%eax,%%eax         # Set up for CPUID instruction    \n"
   6.160 -"        pushl   %%ebx                                                 \n"
   6.161 -"        cpuid                       # Get and save vendor ID          \n"
   6.162 -"        popl    %%ebx                                                 \n"
   6.163 -"        cmpl    $1,%%eax            # Make sure 1 is valid input for CPUID\n"
   6.164 -"        jl      1f                  # We dont have the CPUID instruction\n"
   6.165 -"        xorl    %%eax,%%eax                                           \n"
   6.166 -"        incl    %%eax                                                 \n"
   6.167 -"        pushl   %%ebx                                                 \n"
   6.168 -"        cpuid                       # Get family/model/stepping/features\n"
   6.169 -"        popl    %%ebx                                                 \n"
   6.170 -"        movl    %%edx,%0                                              \n"
   6.171 -"1:                                                                    \n"
   6.172 -	: "=m" (features)
   6.173 -	:
   6.174 -	: "%eax", "%ecx", "%edx"
   6.175 -	);
   6.176 -#elif defined(__GNUC__) && defined(__x86_64__)
   6.177 -	__asm__ (
   6.178 -"        xorl    %%eax,%%eax         # Set up for CPUID instruction    \n"
   6.179 -"        pushq   %%rbx                                                 \n"
   6.180 -"        cpuid                       # Get and save vendor ID          \n"
   6.181 -"        popq    %%rbx                                                 \n"
   6.182 -"        cmpl    $1,%%eax            # Make sure 1 is valid input for CPUID\n"
   6.183 -"        jl      1f                  # We dont have the CPUID instruction\n"
   6.184 -"        xorl    %%eax,%%eax                                           \n"
   6.185 -"        incl    %%eax                                                 \n"
   6.186 -"        pushq   %%rbx                                                 \n"
   6.187 -"        cpuid                       # Get family/model/stepping/features\n"
   6.188 -"        popq    %%rbx                                                 \n"
   6.189 -"        movl    %%edx,%0                                              \n"
   6.190 -"1:                                                                    \n"
   6.191 -	: "=m" (features)
   6.192 -	:
   6.193 -	: "%rax", "%rcx", "%rdx"
   6.194 -	);
   6.195 -#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
   6.196 -	__asm {
   6.197 -        xor     eax, eax            ; Set up for CPUID instruction
   6.198 -        push    ebx
   6.199 -        cpuid                       ; Get and save vendor ID
   6.200 -        pop     ebx
   6.201 -        cmp     eax, 1              ; Make sure 1 is valid input for CPUID
   6.202 -        jl      done                ; We dont have the CPUID instruction
   6.203 -        xor     eax, eax
   6.204 -        inc     eax
   6.205 -        push    ebx
   6.206 -        cpuid                       ; Get family/model/stepping/features
   6.207 -        pop     ebx
   6.208 -        mov     features, edx
   6.209 -done:
   6.210 -	}
   6.211 -#elif defined(__sun) && (defined(__i386) || defined(__amd64))
   6.212 -	    __asm(
   6.213 -"        xorl    %eax,%eax         \n"
   6.214 -"        pushl   %ebx              \n"
   6.215 -"        cpuid                     \n"
   6.216 -"        popl    %ebx              \n"
   6.217 -"        cmpl    $1,%eax           \n"
   6.218 -"        jl      1f                \n"
   6.219 -"        xorl    %eax,%eax         \n"
   6.220 -"        incl    %eax              \n"
   6.221 -"        pushl   %ebx              \n"
   6.222 -"        cpuid                     \n"
   6.223 -"        popl    %ebx              \n"
   6.224 -#ifdef __i386
   6.225 -"        movl    %edx,-8(%ebp)     \n"
   6.226 -#else
   6.227 -"        movl    %edx,-8(%rbp)     \n"
   6.228 -#endif
   6.229 -"1:                                \n"
   6.230 -#endif
   6.231 -/* *INDENT-ON* */
   6.232 +    int ax, bx, cx, dx;
   6.233 +
   6.234 +    cpuid(0, ax, bx, cx, dx);
   6.235 +    if (ax >= 1) {
   6.236 +        cpuid(1, ax, bx, cx, dx);
   6.237 +        features = dx;
   6.238 +    }
   6.239      return features;
   6.240  }
   6.241  
   6.242 @@ -233,79 +187,13 @@
   6.243  CPU_getCPUIDFeaturesExt(void)
   6.244  {
   6.245      int features = 0;
   6.246 -/* *INDENT-OFF* */
   6.247 -#if defined(__GNUC__) && defined(i386)
   6.248 -	__asm__ (
   6.249 -"        movl    $0x80000000,%%eax   # Query for extended functions    \n"
   6.250 -"        pushl   %%ebx                                                 \n"
   6.251 -"        cpuid                       # Get extended function limit     \n"
   6.252 -"        popl    %%ebx                                                 \n"
   6.253 -"        cmpl    $0x80000001,%%eax                                     \n"
   6.254 -"        jl      1f                  # Nope, we dont have function 800000001h\n"
   6.255 -"        movl    $0x80000001,%%eax   # Setup extended function 800000001h\n"
   6.256 -"        pushl   %%ebx                                                 \n"
   6.257 -"        cpuid                       # and get the information         \n"
   6.258 -"        popl    %%ebx                                                 \n"
   6.259 -"        movl    %%edx,%0                                              \n"
   6.260 -"1:                                                                    \n"
   6.261 -	: "=m" (features)
   6.262 -	:
   6.263 -	: "%eax", "%ecx", "%edx"
   6.264 -	);
   6.265 -#elif defined(__GNUC__) && defined (__x86_64__)
   6.266 -	__asm__ (
   6.267 -"        movl    $0x80000000,%%eax   # Query for extended functions    \n"
   6.268 -"        pushq   %%rbx                                                 \n"
   6.269 -"        cpuid                       # Get extended function limit     \n"
   6.270 -"        popq    %%rbx                                                 \n"
   6.271 -"        cmpl    $0x80000001,%%eax                                     \n"
   6.272 -"        jl      1f                  # Nope, we dont have function 800000001h\n"
   6.273 -"        movl    $0x80000001,%%eax   # Setup extended function 800000001h\n"
   6.274 -"        pushq   %%rbx                                                 \n"
   6.275 -"        cpuid                       # and get the information         \n"
   6.276 -"        popq    %%rbx                                                 \n"
   6.277 -"        movl    %%edx,%0                                              \n"
   6.278 -"1:                                                                    \n"
   6.279 -	: "=m" (features)
   6.280 -	:
   6.281 -	: "%rax", "%rcx", "%rdx"
   6.282 -	);
   6.283 -#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
   6.284 -	__asm {
   6.285 -        mov     eax,80000000h       ; Query for extended functions
   6.286 -        push    ebx
   6.287 -        cpuid                       ; Get extended function limit
   6.288 -        pop     ebx
   6.289 -        cmp     eax,80000001h
   6.290 -        jl      done                ; Nope, we dont have function 800000001h
   6.291 -        mov     eax,80000001h       ; Setup extended function 800000001h
   6.292 -        push    ebx
   6.293 -        cpuid                       ; and get the information
   6.294 -        pop     ebx
   6.295 -        mov     features,edx
   6.296 -done:
   6.297 -	}
   6.298 -#elif defined(__sun) && ( defined(__i386) || defined(__amd64) )
   6.299 -	    __asm (
   6.300 -"        movl    $0x80000000,%eax \n"
   6.301 -"        pushl   %ebx             \n"
   6.302 -"        cpuid                    \n"
   6.303 -"        popl    %ebx             \n"
   6.304 -"        cmpl    $0x80000001,%eax \n"
   6.305 -"        jl      1f               \n"
   6.306 -"        movl    $0x80000001,%eax \n"
   6.307 -"        pushl   %ebx             \n"
   6.308 -"        cpuid                    \n"
   6.309 -"        popl    %ebx             \n"
   6.310 -#ifdef __i386
   6.311 -"        movl    %edx,-8(%ebp)    \n"
   6.312 -#else
   6.313 -"        movl    %edx,-8(%rbp)    \n"
   6.314 -#endif
   6.315 -"1:                               \n"
   6.316 -	    );
   6.317 -#endif
   6.318 -/* *INDENT-ON* */
   6.319 +    int ax, bx, cx, dx;
   6.320 +
   6.321 +    cpuid(0x80000000, ax, bx, cx, dx);
   6.322 +    if (ax >= 0x80000001) {
   6.323 +        cpuid(0x80000001, ax, bx, cx, dx);
   6.324 +        features = dx;
   6.325 +    }
   6.326      return features;
   6.327  }
   6.328  
   6.329 @@ -395,6 +283,97 @@
   6.330      return altivec;
   6.331  }
   6.332  
   6.333 +static int SDL_CPUCount = 0;
   6.334 +
   6.335 +int
   6.336 +SDL_GetCPUCount()
   6.337 +{
   6.338 +    if (!SDL_CPUCount) {
   6.339 +#ifdef HAVE_SYSCTLBYNAME
   6.340 +        size_t size = sizeof(SDL_CPUCount);
   6.341 +        sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0);
   6.342 +#endif
   6.343 +        /* There has to be at least 1, right? :) */
   6.344 +        if (!SDL_CPUCount) {
   6.345 +            SDL_CPUCount = 1;
   6.346 +        }
   6.347 +    }
   6.348 +    return SDL_CPUCount;
   6.349 +}
   6.350 +
   6.351 +/* Oh, such a sweet sweet trick, just not very useful. :) */
   6.352 +const char *
   6.353 +SDL_GetCPUType()
   6.354 +{
   6.355 +    static char SDL_CPUType[48];
   6.356 +
   6.357 +    if (!SDL_CPUType[0]) {
   6.358 +        int i = 0;
   6.359 +        int ax, bx, cx, dx;
   6.360 +
   6.361 +        if (CPU_haveCPUID()) {
   6.362 +            cpuid(0x80000000, ax, bx, cx, dx);
   6.363 +            if (ax >= 0x80000004) {
   6.364 +                cpuid(0x80000002, ax, bx, cx, dx);
   6.365 +                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   6.366 +                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   6.367 +                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   6.368 +                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   6.369 +                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   6.370 +                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   6.371 +                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   6.372 +                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   6.373 +                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   6.374 +                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   6.375 +                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   6.376 +                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   6.377 +                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   6.378 +                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   6.379 +                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   6.380 +                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   6.381 +                cpuid(0x80000003, ax, bx, cx, dx);
   6.382 +                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   6.383 +                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   6.384 +                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   6.385 +                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   6.386 +                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   6.387 +                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   6.388 +                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   6.389 +                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   6.390 +                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   6.391 +                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   6.392 +                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   6.393 +                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   6.394 +                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   6.395 +                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   6.396 +                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   6.397 +                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   6.398 +                cpuid(0x80000004, ax, bx, cx, dx);
   6.399 +                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   6.400 +                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   6.401 +                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   6.402 +                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   6.403 +                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   6.404 +                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   6.405 +                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   6.406 +                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   6.407 +                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   6.408 +                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   6.409 +                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   6.410 +                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   6.411 +                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   6.412 +                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   6.413 +                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   6.414 +                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   6.415 +            }
   6.416 +        }
   6.417 +        if (!SDL_CPUType[0]) {
   6.418 +            SDL_strlcpy(SDL_CPUType, "Unknown", sizeof(SDL_CPUType));
   6.419 +        }
   6.420 +    }
   6.421 +    return SDL_CPUType;
   6.422 +}
   6.423 +
   6.424  static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
   6.425  
   6.426  static Uint32
   6.427 @@ -509,6 +488,8 @@
   6.428  int
   6.429  main()
   6.430  {
   6.431 +    printf("CPU count: %d\n", SDL_GetCPUCount());
   6.432 +    printf("CPU name: %s\n", SDL_GetCPUType());
   6.433      printf("RDTSC: %d\n", SDL_HasRDTSC());
   6.434      printf("MMX: %d\n", SDL_HasMMX());
   6.435      printf("MMXExt: %d\n", SDL_HasMMXExt());
     7.1 --- a/src/thread/SDL_systhread.h	Wed Dec 16 04:48:11 2009 +0000
     7.2 +++ b/src/thread/SDL_systhread.h	Wed Dec 16 06:53:53 2009 +0000
     7.3 @@ -49,4 +49,5 @@
     7.4  extern void SDL_SYS_WaitThread(SDL_Thread * thread);
     7.5  
     7.6  #endif /* _SDL_systhread_h */
     7.7 +
     7.8  /* vi: set ts=4 sw=4 expandtab: */
     8.1 --- a/test/automated/platform/platform.c	Wed Dec 16 04:48:11 2009 +0000
     8.2 +++ b/test/automated/platform/platform.c	Wed Dec 16 06:53:53 2009 +0000
     8.3 @@ -155,6 +155,7 @@
     8.4           "big"
     8.5  #endif
     8.6           );
     8.7 +   SDL_ATprintVerbose( 1, "CPU count: %d\n", SDL_GetCPUCount());
     8.8     SDL_ATprintVerbose( 1, "Available extensions:\n" );
     8.9     SDL_ATprintVerbose( 1, "   RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected" );
    8.10     SDL_ATprintVerbose( 1, "   MMX %s\n", SDL_HasMMX()? "detected" : "not detected" );
     9.1 --- a/test/testplatform.c	Wed Dec 16 04:48:11 2009 +0000
     9.2 +++ b/test/testplatform.c	Wed Dec 16 06:53:53 2009 +0000
     9.3 @@ -134,6 +134,7 @@
     9.4  TestCPUInfo(SDL_bool verbose)
     9.5  {
     9.6      if (verbose) {
     9.7 +        printf("CPU count: %d\n", SDL_GetCPUCount());
     9.8          printf("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected");
     9.9          printf("MMX %s\n", SDL_HasMMX()? "detected" : "not detected");
    9.10          printf("MMX Ext %s\n", SDL_HasMMXExt()? "detected" : "not detected");