src/cpuinfo/SDL_cpuinfo.c
changeset 3580 951dd6a5d1a2
parent 3579 3427271a2d75
child 3584 41d01d70659c
     1.1 --- a/src/cpuinfo/SDL_cpuinfo.c	Wed Dec 16 06:53:53 2009 +0000
     1.2 +++ b/src/cpuinfo/SDL_cpuinfo.c	Wed Dec 16 08:17:05 2009 +0000
     1.3 @@ -35,6 +35,10 @@
     1.4  #include <signal.h>
     1.5  #include <setjmp.h>
     1.6  #endif
     1.7 +#ifdef __WIN32__
     1.8 +#define WIN32_LEAN_AND_MEAN
     1.9 +#include <windows.h>
    1.10 +#endif
    1.11  
    1.12  #define CPU_HAS_RDTSC   0x00000001
    1.13  #define CPU_HAS_MMX     0x00000002
    1.14 @@ -151,34 +155,34 @@
    1.15  }
    1.16  
    1.17  #if defined(__GNUC__) && (defined(i386) || defined(__x86_64__))
    1.18 -#define cpuid(func, ax, bx, cx, dx) \
    1.19 +#define cpuid(func, a, b, c, d) \
    1.20      __asm__ __volatile__ ("cpuid": \
    1.21 -    "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (func))
    1.22 +    "=a" (a), "=b" (b), "=c" (c), "=d" (d) : "a" (func))
    1.23  #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
    1.24 -#define cpuid(func, ax, bx, cx, dx) \
    1.25 -    asm { \
    1.26 -        mov eax, func \
    1.27 -        cpuid
    1.28 -        mov ax, eax \
    1.29 -        mov bx, ebx \
    1.30 -        mov cx, ecx \
    1.31 -        mov dx, edx \
    1.32 +#define cpuid(func, a, b, c, d) \
    1.33 +    __asm { \
    1.34 +        __asm mov eax, func \
    1.35 +        __asm cpuid \
    1.36 +        __asm mov a, eax \
    1.37 +        __asm mov b, ebx \
    1.38 +        __asm mov c, ecx \
    1.39 +        __asm mov d, edx \
    1.40      }
    1.41  #else
    1.42 -#define cpuid(func, ax, bx, cx, dx) \
    1.43 -    ax = bx = cx = dx = 0
    1.44 +#define cpuid(func, a, b, c, d) \
    1.45 +    a = b = c = d = 0
    1.46  #endif
    1.47  
    1.48  static __inline__ int
    1.49  CPU_getCPUIDFeatures(void)
    1.50  {
    1.51      int features = 0;
    1.52 -    int ax, bx, cx, dx;
    1.53 +    int a, b, c, d;
    1.54  
    1.55 -    cpuid(0, ax, bx, cx, dx);
    1.56 -    if (ax >= 1) {
    1.57 -        cpuid(1, ax, bx, cx, dx);
    1.58 -        features = dx;
    1.59 +    cpuid(0, a, b, c, d);
    1.60 +    if (a >= 1) {
    1.61 +        cpuid(1, a, b, c, d);
    1.62 +        features = d;
    1.63      }
    1.64      return features;
    1.65  }
    1.66 @@ -187,12 +191,12 @@
    1.67  CPU_getCPUIDFeaturesExt(void)
    1.68  {
    1.69      int features = 0;
    1.70 -    int ax, bx, cx, dx;
    1.71 +    int a, b, c, d;
    1.72  
    1.73 -    cpuid(0x80000000, ax, bx, cx, dx);
    1.74 -    if (ax >= 0x80000001) {
    1.75 -        cpuid(0x80000001, ax, bx, cx, dx);
    1.76 -        features = dx;
    1.77 +    cpuid(0x80000000, a, b, c, d);
    1.78 +    if (a >= 0x80000001) {
    1.79 +        cpuid(0x80000001, a, b, c, d);
    1.80 +        features = d;
    1.81      }
    1.82      return features;
    1.83  }
    1.84 @@ -290,8 +294,17 @@
    1.85  {
    1.86      if (!SDL_CPUCount) {
    1.87  #ifdef HAVE_SYSCTLBYNAME
    1.88 -        size_t size = sizeof(SDL_CPUCount);
    1.89 -        sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0);
    1.90 +        {
    1.91 +            size_t size = sizeof(SDL_CPUCount);
    1.92 +            sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0);
    1.93 +        }
    1.94 +#endif
    1.95 +#ifdef __WIN32__
    1.96 +        {
    1.97 +            SYSTEM_INFO info;
    1.98 +            GetSystemInfo(&info);
    1.99 +            SDL_CPUCount = info.dwNumberOfProcessors;
   1.100 +        }
   1.101  #endif
   1.102          /* There has to be at least 1, right? :) */
   1.103          if (!SDL_CPUCount) {
   1.104 @@ -309,62 +322,62 @@
   1.105  
   1.106      if (!SDL_CPUType[0]) {
   1.107          int i = 0;
   1.108 -        int ax, bx, cx, dx;
   1.109 +        int a, b, c, d;
   1.110  
   1.111          if (CPU_haveCPUID()) {
   1.112 -            cpuid(0x80000000, ax, bx, cx, dx);
   1.113 -            if (ax >= 0x80000004) {
   1.114 -                cpuid(0x80000002, ax, bx, cx, dx);
   1.115 -                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   1.116 -                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   1.117 -                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   1.118 -                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   1.119 -                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   1.120 -                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   1.121 -                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   1.122 -                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   1.123 -                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   1.124 -                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   1.125 -                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   1.126 -                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   1.127 -                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   1.128 -                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   1.129 -                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   1.130 -                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   1.131 -                cpuid(0x80000003, ax, bx, cx, dx);
   1.132 -                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   1.133 -                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   1.134 -                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   1.135 -                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   1.136 -                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   1.137 -                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   1.138 -                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   1.139 -                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   1.140 -                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   1.141 -                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   1.142 -                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   1.143 -                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   1.144 -                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   1.145 -                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   1.146 -                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   1.147 -                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   1.148 -                cpuid(0x80000004, ax, bx, cx, dx);
   1.149 -                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   1.150 -                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   1.151 -                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   1.152 -                SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
   1.153 -                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   1.154 -                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   1.155 -                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   1.156 -                SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
   1.157 -                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   1.158 -                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   1.159 -                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   1.160 -                SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
   1.161 -                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   1.162 -                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   1.163 -                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   1.164 -                SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
   1.165 +            cpuid(0x80000000, a, b, c, d);
   1.166 +            if (a >= 0x80000004) {
   1.167 +                cpuid(0x80000002, a, b, c, d);
   1.168 +                SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
   1.169 +                SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
   1.170 +                SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
   1.171 +                SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
   1.172 +                SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
   1.173 +                SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
   1.174 +                SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
   1.175 +                SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
   1.176 +                SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
   1.177 +                SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
   1.178 +                SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
   1.179 +                SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
   1.180 +                SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
   1.181 +                SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
   1.182 +                SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
   1.183 +                SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
   1.184 +                cpuid(0x80000003, a, b, c, d);
   1.185 +                SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
   1.186 +                SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
   1.187 +                SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
   1.188 +                SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
   1.189 +                SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
   1.190 +                SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
   1.191 +                SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
   1.192 +                SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
   1.193 +                SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
   1.194 +                SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
   1.195 +                SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
   1.196 +                SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
   1.197 +                SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
   1.198 +                SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
   1.199 +                SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
   1.200 +                SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
   1.201 +                cpuid(0x80000004, a, b, c, d);
   1.202 +                SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
   1.203 +                SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
   1.204 +                SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
   1.205 +                SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
   1.206 +                SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
   1.207 +                SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
   1.208 +                SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
   1.209 +                SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
   1.210 +                SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
   1.211 +                SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
   1.212 +                SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
   1.213 +                SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
   1.214 +                SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
   1.215 +                SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
   1.216 +                SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
   1.217 +                SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
   1.218              }
   1.219          }
   1.220          if (!SDL_CPUType[0]) {