SDL  2.0
SDL_cpuinfo.c File Reference
#include "../SDL_internal.h"
#include "SDL_cpuinfo.h"
+ Include dependency graph for SDL_cpuinfo.c:

Go to the source code of this file.

Macros

#define CPU_HAS_RDTSC   0x00000001
 
#define CPU_HAS_ALTIVEC   0x00000002
 
#define CPU_HAS_MMX   0x00000004
 
#define CPU_HAS_3DNOW   0x00000008
 
#define CPU_HAS_SSE   0x00000010
 
#define CPU_HAS_SSE2   0x00000020
 
#define CPU_HAS_SSE3   0x00000040
 
#define CPU_HAS_SSE41   0x00000100
 
#define CPU_HAS_SSE42   0x00000200
 
#define CPU_HAS_AVX   0x00000400
 
#define CPU_HAS_AVX2   0x00000800
 
#define cpuid(func, a, b, c, d)   a = b = c = d = 0
 

Functions

static int CPU_haveCPUID (void)
 
static int CPU_getCPUIDFeatures (void)
 
static SDL_bool CPU_OSSavesYMM (void)
 
static int CPU_haveRDTSC (void)
 
static int CPU_haveAltiVec (void)
 
static int CPU_haveMMX (void)
 
static int CPU_have3DNow (void)
 
static int CPU_haveSSE (void)
 
static int CPU_haveSSE2 (void)
 
static int CPU_haveSSE3 (void)
 
static int CPU_haveSSE41 (void)
 
static int CPU_haveSSE42 (void)
 
static int CPU_haveAVX (void)
 
static int CPU_haveAVX2 (void)
 
int SDL_GetCPUCount (void)
 
static const char * SDL_GetCPUType (void)
 
int SDL_GetCPUCacheLineSize (void)
 
static Uint32 SDL_GetCPUFeatures (void)
 
SDL_bool SDL_HasRDTSC (void)
 
SDL_bool SDL_HasAltiVec (void)
 
SDL_bool SDL_HasMMX (void)
 
SDL_bool SDL_Has3DNow (void)
 
SDL_bool SDL_HasSSE (void)
 
SDL_bool SDL_HasSSE2 (void)
 
SDL_bool SDL_HasSSE3 (void)
 
SDL_bool SDL_HasSSE41 (void)
 
SDL_bool SDL_HasSSE42 (void)
 
SDL_bool SDL_HasAVX (void)
 
SDL_bool SDL_HasAVX2 (void)
 
int SDL_GetSystemRAM (void)
 

Variables

static int SDL_CPUCount = 0
 
static Uint32 SDL_CPUFeatures = 0xFFFFFFFF
 
static int SDL_SystemRAM = 0
 

Macro Definition Documentation

§ CPU_HAS_3DNOW

#define CPU_HAS_3DNOW   0x00000008

Definition at line 56 of file SDL_cpuinfo.c.

Referenced by SDL_GetCPUFeatures(), and SDL_Has3DNow().

§ CPU_HAS_ALTIVEC

#define CPU_HAS_ALTIVEC   0x00000002

Definition at line 54 of file SDL_cpuinfo.c.

Referenced by SDL_GetCPUFeatures(), and SDL_HasAltiVec().

§ CPU_HAS_AVX

#define CPU_HAS_AVX   0x00000400

Definition at line 62 of file SDL_cpuinfo.c.

Referenced by SDL_GetCPUFeatures(), and SDL_HasAVX().

§ CPU_HAS_AVX2

#define CPU_HAS_AVX2   0x00000800

Definition at line 63 of file SDL_cpuinfo.c.

Referenced by SDL_GetCPUFeatures(), and SDL_HasAVX2().

§ CPU_HAS_MMX

#define CPU_HAS_MMX   0x00000004

Definition at line 55 of file SDL_cpuinfo.c.

Referenced by SDL_GetCPUFeatures(), and SDL_HasMMX().

§ CPU_HAS_RDTSC

#define CPU_HAS_RDTSC   0x00000001

Definition at line 53 of file SDL_cpuinfo.c.

Referenced by SDL_GetCPUFeatures(), and SDL_HasRDTSC().

§ CPU_HAS_SSE

#define CPU_HAS_SSE   0x00000010

Definition at line 57 of file SDL_cpuinfo.c.

Referenced by SDL_GetCPUFeatures(), and SDL_HasSSE().

§ CPU_HAS_SSE2

#define CPU_HAS_SSE2   0x00000020

Definition at line 58 of file SDL_cpuinfo.c.

Referenced by SDL_GetCPUFeatures(), and SDL_HasSSE2().

§ CPU_HAS_SSE3

#define CPU_HAS_SSE3   0x00000040

Definition at line 59 of file SDL_cpuinfo.c.

Referenced by SDL_GetCPUFeatures(), and SDL_HasSSE3().

§ CPU_HAS_SSE41

#define CPU_HAS_SSE41   0x00000100

Definition at line 60 of file SDL_cpuinfo.c.

Referenced by SDL_GetCPUFeatures(), and SDL_HasSSE41().

§ CPU_HAS_SSE42

#define CPU_HAS_SSE42   0x00000200

Definition at line 61 of file SDL_cpuinfo.c.

Referenced by SDL_GetCPUFeatures(), and SDL_HasSSE42().

§ cpuid

#define cpuid (   func,
  a,
  b,
  c,
  d 
)    a = b = c = d = 0

Function Documentation

§ CPU_getCPUIDFeatures()

static int CPU_getCPUIDFeatures ( void  )
static

Definition at line 219 of file SDL_cpuinfo.c.

References cpuid, and d.

Referenced by CPU_haveMMX(), CPU_haveRDTSC(), CPU_haveSSE(), and CPU_haveSSE2().

220 {
221  int features = 0;
222  int a, b, c, d;
223 
224  cpuid(0, a, b, c, d);
225  if (a >= 1) {
226  cpuid(1, a, b, c, d);
227  features = d;
228  }
229  return features;
230 }
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 ** d
const GLubyte * c
#define cpuid(func, a, b, c, d)
Definition: SDL_cpuinfo.c:214
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean GLboolean b

§ CPU_have3DNow()

static int CPU_have3DNow ( void  )
static

Definition at line 312 of file SDL_cpuinfo.c.

References CPU_haveCPUID(), cpuid, and d.

Referenced by SDL_GetCPUFeatures().

313 {
314  if (CPU_haveCPUID()) {
315  int a, b, c, d;
316 
317  cpuid(0x80000000, a, b, c, d);
318  if (a >= 0x80000001) {
319  cpuid(0x80000001, a, b, c, d);
320  return (d & 0x80000000);
321  }
322  }
323  return 0;
324 }
static int CPU_haveCPUID(void)
Definition: SDL_cpuinfo.c:78
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 ** d
const GLubyte * c
#define cpuid(func, a, b, c, d)
Definition: SDL_cpuinfo.c:214
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean GLboolean b

§ CPU_haveAltiVec()

static int CPU_haveAltiVec ( void  )
static

Definition at line 274 of file SDL_cpuinfo.c.

References NULL, and void.

Referenced by SDL_GetCPUFeatures().

275 {
276  volatile int altivec = 0;
277 #ifndef SDL_CPUINFO_DISABLED
278 #if (defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))) || (defined(__OpenBSD__) && defined(__powerpc__))
279 #ifdef __OpenBSD__
280  int selectors[2] = { CTL_MACHDEP, CPU_ALTIVEC };
281 #else
282  int selectors[2] = { CTL_HW, HW_VECTORUNIT };
283 #endif
284  int hasVectorUnit = 0;
285  size_t length = sizeof(hasVectorUnit);
286  int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0);
287  if (0 == error)
288  altivec = (hasVectorUnit != 0);
289 #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
290  void (*handler) (int sig);
291  handler = signal(SIGILL, illegal_instruction);
292  if (setjmp(jmpbuf) == 0) {
293  asm volatile ("mtspr 256, %0\n\t" "vand %%v0, %%v0, %%v0"::"r" (-1));
294  altivec = 1;
295  }
296  signal(SIGILL, handler);
297 #endif
298 #endif
299  return altivec;
300 }
#define NULL
Definition: begin_code.h:143
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
GLuint GLsizei GLsizei * length

§ CPU_haveAVX()

static int CPU_haveAVX ( void  )
static

Definition at line 390 of file SDL_cpuinfo.c.

References CPU_haveCPUID(), CPU_OSSavesYMM(), cpuid, and d.

Referenced by SDL_GetCPUFeatures().

391 {
392  if (CPU_haveCPUID() && CPU_OSSavesYMM()) {
393  int a, b, c, d;
394 
395  cpuid(0, a, b, c, d);
396  if (a >= 1) {
397  cpuid(1, a, b, c, d);
398  return (c & 0x10000000);
399  }
400  }
401  return 0;
402 }
static SDL_bool CPU_OSSavesYMM(void)
Definition: SDL_cpuinfo.c:233
static int CPU_haveCPUID(void)
Definition: SDL_cpuinfo.c:78
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 ** d
const GLubyte * c
#define cpuid(func, a, b, c, d)
Definition: SDL_cpuinfo.c:214
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean GLboolean b

§ CPU_haveAVX2()

static int CPU_haveAVX2 ( void  )
static

Definition at line 405 of file SDL_cpuinfo.c.

References CPU_haveCPUID(), CPU_OSSavesYMM(), cpuid, and d.

Referenced by SDL_GetCPUFeatures().

406 {
407  if (CPU_haveCPUID() && CPU_OSSavesYMM()) {
408  int a, b, c, d;
409 
410  cpuid(0, a, b, c, d);
411  if (a >= 7) {
412  cpuid(7, a, b, c, d);
413  return (b & 0x00000020);
414  }
415  }
416  return 0;
417 }
static SDL_bool CPU_OSSavesYMM(void)
Definition: SDL_cpuinfo.c:233
static int CPU_haveCPUID(void)
Definition: SDL_cpuinfo.c:78
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 ** d
const GLubyte * c
#define cpuid(func, a, b, c, d)
Definition: SDL_cpuinfo.c:214
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean GLboolean b

§ CPU_haveCPUID()

static int CPU_haveCPUID ( void  )
static

Definition at line 78 of file SDL_cpuinfo.c.

References done, and pop.

Referenced by CPU_have3DNow(), CPU_haveAVX(), CPU_haveAVX2(), CPU_haveMMX(), CPU_haveRDTSC(), CPU_haveSSE(), CPU_haveSSE2(), CPU_haveSSE3(), CPU_haveSSE41(), CPU_haveSSE42(), and SDL_GetCPUType().

79 {
80  int has_CPUID = 0;
81 /* *INDENT-OFF* */
82 #ifndef SDL_CPUINFO_DISABLED
83 #if defined(__GNUC__) && defined(i386)
84  __asm__ (
85 " pushfl # Get original EFLAGS \n"
86 " popl %%eax \n"
87 " movl %%eax,%%ecx \n"
88 " xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n"
89 " pushl %%eax # Save new EFLAGS value on stack \n"
90 " popfl # Replace current EFLAGS value \n"
91 " pushfl # Get new EFLAGS \n"
92 " popl %%eax # Store new EFLAGS in EAX \n"
93 " xorl %%ecx,%%eax # Can not toggle ID bit, \n"
94 " jz 1f # Processor=80486 \n"
95 " movl $1,%0 # We have CPUID support \n"
96 "1: \n"
97  : "=m" (has_CPUID)
98  :
99  : "%eax", "%ecx"
100  );
101 #elif defined(__GNUC__) && defined(__x86_64__)
102 /* Technically, if this is being compiled under __x86_64__ then it has
103  CPUid by definition. But it's nice to be able to prove it. :) */
104  __asm__ (
105 " pushfq # Get original EFLAGS \n"
106 " popq %%rax \n"
107 " movq %%rax,%%rcx \n"
108 " xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n"
109 " pushq %%rax # Save new EFLAGS value on stack \n"
110 " popfq # Replace current EFLAGS value \n"
111 " pushfq # Get new EFLAGS \n"
112 " popq %%rax # Store new EFLAGS in EAX \n"
113 " xorl %%ecx,%%eax # Can not toggle ID bit, \n"
114 " jz 1f # Processor=80486 \n"
115 " movl $1,%0 # We have CPUID support \n"
116 "1: \n"
117  : "=m" (has_CPUID)
118  :
119  : "%rax", "%rcx"
120  );
121 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
122  __asm {
123  pushfd ; Get original EFLAGS
124  pop eax
125  mov ecx, eax
126  xor eax, 200000h ; Flip ID bit in EFLAGS
127  push eax ; Save new EFLAGS value on stack
128  popfd ; Replace current EFLAGS value
129  pushfd ; Get new EFLAGS
130  pop eax ; Store new EFLAGS in EAX
131  xor eax, ecx ; Can not toggle ID bit,
132  jz done ; Processor=80486
133  mov has_CPUID,1 ; We have CPUID support
134 done:
135  }
136 #elif defined(_MSC_VER) && defined(_M_X64)
137  has_CPUID = 1;
138 #elif defined(__sun) && defined(__i386)
139  __asm (
140 " pushfl \n"
141 " popl %eax \n"
142 " movl %eax,%ecx \n"
143 " xorl $0x200000,%eax \n"
144 " pushl %eax \n"
145 " popfl \n"
146 " pushfl \n"
147 " popl %eax \n"
148 " xorl %ecx,%eax \n"
149 " jz 1f \n"
150 " movl $1,-8(%ebp) \n"
151 "1: \n"
152  );
153 #elif defined(__sun) && defined(__amd64)
154  __asm (
155 " pushfq \n"
156 " popq %rax \n"
157 " movq %rax,%rcx \n"
158 " xorl $0x200000,%eax \n"
159 " pushq %rax \n"
160 " popfq \n"
161 " pushfq \n"
162 " popq %rax \n"
163 " xorl %ecx,%eax \n"
164 " jz 1f \n"
165 " movl $1,-8(%rbp) \n"
166 "1: \n"
167  );
168 #endif
169 #endif
170 /* *INDENT-ON* */
171  return has_CPUID;
172 }
GLsizei const GLfloat * value
#define pop
Definition: SDL_qsort.c:192
int done
Definition: checkkeys.c:28
GLuint in
GLfloat GLfloat GLfloat GLfloat h

§ CPU_haveMMX()

static int CPU_haveMMX ( void  )
static

Definition at line 303 of file SDL_cpuinfo.c.

References CPU_getCPUIDFeatures(), and CPU_haveCPUID().

Referenced by SDL_GetCPUFeatures().

304 {
305  if (CPU_haveCPUID()) {
306  return (CPU_getCPUIDFeatures() & 0x00800000);
307  }
308  return 0;
309 }
static int CPU_haveCPUID(void)
Definition: SDL_cpuinfo.c:78
static int CPU_getCPUIDFeatures(void)
Definition: SDL_cpuinfo.c:219

§ CPU_haveRDTSC()

static int CPU_haveRDTSC ( void  )
static

Definition at line 265 of file SDL_cpuinfo.c.

References CPU_getCPUIDFeatures(), and CPU_haveCPUID().

Referenced by SDL_GetCPUFeatures().

266 {
267  if (CPU_haveCPUID()) {
268  return (CPU_getCPUIDFeatures() & 0x00000010);
269  }
270  return 0;
271 }
static int CPU_haveCPUID(void)
Definition: SDL_cpuinfo.c:78
static int CPU_getCPUIDFeatures(void)
Definition: SDL_cpuinfo.c:219

§ CPU_haveSSE()

static int CPU_haveSSE ( void  )
static

Definition at line 327 of file SDL_cpuinfo.c.

References CPU_getCPUIDFeatures(), and CPU_haveCPUID().

Referenced by SDL_GetCPUFeatures().

328 {
329  if (CPU_haveCPUID()) {
330  return (CPU_getCPUIDFeatures() & 0x02000000);
331  }
332  return 0;
333 }
static int CPU_haveCPUID(void)
Definition: SDL_cpuinfo.c:78
static int CPU_getCPUIDFeatures(void)
Definition: SDL_cpuinfo.c:219

§ CPU_haveSSE2()

static int CPU_haveSSE2 ( void  )
static

Definition at line 336 of file SDL_cpuinfo.c.

References CPU_getCPUIDFeatures(), and CPU_haveCPUID().

Referenced by SDL_GetCPUFeatures().

337 {
338  if (CPU_haveCPUID()) {
339  return (CPU_getCPUIDFeatures() & 0x04000000);
340  }
341  return 0;
342 }
static int CPU_haveCPUID(void)
Definition: SDL_cpuinfo.c:78
static int CPU_getCPUIDFeatures(void)
Definition: SDL_cpuinfo.c:219

§ CPU_haveSSE3()

static int CPU_haveSSE3 ( void  )
static

Definition at line 345 of file SDL_cpuinfo.c.

References CPU_haveCPUID(), cpuid, and d.

Referenced by SDL_GetCPUFeatures().

346 {
347  if (CPU_haveCPUID()) {
348  int a, b, c, d;
349 
350  cpuid(0, a, b, c, d);
351  if (a >= 1) {
352  cpuid(1, a, b, c, d);
353  return (c & 0x00000001);
354  }
355  }
356  return 0;
357 }
static int CPU_haveCPUID(void)
Definition: SDL_cpuinfo.c:78
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 ** d
const GLubyte * c
#define cpuid(func, a, b, c, d)
Definition: SDL_cpuinfo.c:214
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean GLboolean b

§ CPU_haveSSE41()

static int CPU_haveSSE41 ( void  )
static

Definition at line 360 of file SDL_cpuinfo.c.

References CPU_haveCPUID(), cpuid, and d.

Referenced by SDL_GetCPUFeatures().

361 {
362  if (CPU_haveCPUID()) {
363  int a, b, c, d;
364 
365  cpuid(0, a, b, c, d);
366  if (a >= 1) {
367  cpuid(1, a, b, c, d);
368  return (c & 0x00080000);
369  }
370  }
371  return 0;
372 }
static int CPU_haveCPUID(void)
Definition: SDL_cpuinfo.c:78
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 ** d
const GLubyte * c
#define cpuid(func, a, b, c, d)
Definition: SDL_cpuinfo.c:214
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean GLboolean b

§ CPU_haveSSE42()

static int CPU_haveSSE42 ( void  )
static

Definition at line 375 of file SDL_cpuinfo.c.

References CPU_haveCPUID(), cpuid, and d.

Referenced by SDL_GetCPUFeatures().

376 {
377  if (CPU_haveCPUID()) {
378  int a, b, c, d;
379 
380  cpuid(0, a, b, c, d);
381  if (a >= 1) {
382  cpuid(1, a, b, c, d);
383  return (c & 0x00100000);
384  }
385  }
386  return 0;
387 }
static int CPU_haveCPUID(void)
Definition: SDL_cpuinfo.c:78
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 ** d
const GLubyte * c
#define cpuid(func, a, b, c, d)
Definition: SDL_cpuinfo.c:214
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean GLboolean b

§ CPU_OSSavesYMM()

static SDL_bool CPU_OSSavesYMM ( void  )
static

Definition at line 233 of file SDL_cpuinfo.c.

References cpuid, d, SDL_FALSE, and SDL_TRUE.

Referenced by CPU_haveAVX(), and CPU_haveAVX2().

234 {
235  int a, b, c, d;
236 
237  /* Check to make sure we can call xgetbv */
238  cpuid(0, a, b, c, d);
239  if (a < 1) {
240  return SDL_FALSE;
241  }
242  cpuid(1, a, b, c, d);
243  if (!(c & 0x08000000)) {
244  return SDL_FALSE;
245  }
246 
247  /* Call xgetbv to see if YMM register state is saved */
248  a = 0;
249 #if defined(__GNUC__) && (defined(i386) || defined(__x86_64__))
250  asm(".byte 0x0f, 0x01, 0xd0" : "=a" (a) : "c" (0) : "%edx");
251 #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) && (_MSC_FULL_VER >= 160040219) /* VS2010 SP1 */
252  a = (int)_xgetbv(0);
253 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
254  __asm
255  {
256  xor ecx, ecx
257  _asm _emit 0x0f _asm _emit 0x01 _asm _emit 0xd0
258  mov a, eax
259  }
260 #endif
261  return ((a & 6) == 6) ? SDL_TRUE : SDL_FALSE;
262 }
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 ** d
const GLubyte * c
#define cpuid(func, a, b, c, d)
Definition: SDL_cpuinfo.c:214
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean GLboolean b

§ SDL_GetCPUCacheLineSize()

int SDL_GetCPUCacheLineSize ( void  )

This function returns the L1 cache line size of the CPU

This is useful for determining multi-threaded structure padding or SIMD prefetch sizes.

Definition at line 564 of file SDL_cpuinfo.c.

References cpuid, d, SDL_CACHELINE_SIZE, SDL_GetCPUType(), SDL_strcmp, and void.

Referenced by SDL_GetSystemRAM().

565 {
566  const char *cpuType = SDL_GetCPUType();
567  int a, b, c, d;
568  (void) a; (void) b; (void) c; (void) d;
569  if (SDL_strcmp(cpuType, "GenuineIntel") == 0) {
570  cpuid(0x00000001, a, b, c, d);
571  return (((b >> 8) & 0xff) * 8);
572  } else if (SDL_strcmp(cpuType, "AuthenticAMD") == 0) {
573  cpuid(0x80000005, a, b, c, d);
574  return (c & 0xff);
575  } else {
576  /* Just make a guess here... */
577  return SDL_CACHELINE_SIZE;
578  }
579 }
static const char * SDL_GetCPUType(void)
Definition: SDL_cpuinfo.c:455
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 ** d
#define SDL_CACHELINE_SIZE
Definition: SDL_cpuinfo.h:77
const GLubyte * c
#define cpuid(func, a, b, c, d)
Definition: SDL_cpuinfo.c:214
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
#define SDL_strcmp
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean GLboolean b

§ SDL_GetCPUCount()

int SDL_GetCPUCount ( void  )

This function returns the number of CPU cores available.

Definition at line 422 of file SDL_cpuinfo.c.

References NULL, and SDL_CPUCount.

Referenced by SDL_GetSystemRAM().

423 {
424  if (!SDL_CPUCount) {
425 #ifndef SDL_CPUINFO_DISABLED
426 #if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
427  if (SDL_CPUCount <= 0) {
428  SDL_CPUCount = (int)sysconf(_SC_NPROCESSORS_ONLN);
429  }
430 #endif
431 #ifdef HAVE_SYSCTLBYNAME
432  if (SDL_CPUCount <= 0) {
433  size_t size = sizeof(SDL_CPUCount);
434  sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0);
435  }
436 #endif
437 #ifdef __WIN32__
438  if (SDL_CPUCount <= 0) {
439  SYSTEM_INFO info;
440  GetSystemInfo(&info);
441  SDL_CPUCount = info.dwNumberOfProcessors;
442  }
443 #endif
444 #endif
445  /* There has to be at least 1, right? :) */
446  if (SDL_CPUCount <= 0) {
447  SDL_CPUCount = 1;
448  }
449  }
450  return SDL_CPUCount;
451 }
GLsizeiptr size
#define NULL
Definition: begin_code.h:143
static int SDL_CPUCount
Definition: SDL_cpuinfo.c:419

§ SDL_GetCPUFeatures()

static Uint32 SDL_GetCPUFeatures ( void  )
static

Definition at line 584 of file SDL_cpuinfo.c.

References CPU_HAS_3DNOW, CPU_HAS_ALTIVEC, CPU_HAS_AVX, CPU_HAS_AVX2, CPU_HAS_MMX, CPU_HAS_RDTSC, CPU_HAS_SSE, CPU_HAS_SSE2, CPU_HAS_SSE3, CPU_HAS_SSE41, CPU_HAS_SSE42, CPU_have3DNow(), CPU_haveAltiVec(), CPU_haveAVX(), CPU_haveAVX2(), CPU_haveMMX(), CPU_haveRDTSC(), CPU_haveSSE(), CPU_haveSSE2(), CPU_haveSSE3(), CPU_haveSSE41(), CPU_haveSSE42(), and SDL_CPUFeatures.

Referenced by SDL_Has3DNow(), SDL_HasAltiVec(), SDL_HasAVX(), SDL_HasAVX2(), SDL_HasMMX(), SDL_HasRDTSC(), SDL_HasSSE(), SDL_HasSSE2(), SDL_HasSSE3(), SDL_HasSSE41(), and SDL_HasSSE42().

585 {
586  if (SDL_CPUFeatures == 0xFFFFFFFF) {
587  SDL_CPUFeatures = 0;
588  if (CPU_haveRDTSC()) {
590  }
591  if (CPU_haveAltiVec()) {
593  }
594  if (CPU_haveMMX()) {
596  }
597  if (CPU_have3DNow()) {
599  }
600  if (CPU_haveSSE()) {
602  }
603  if (CPU_haveSSE2()) {
605  }
606  if (CPU_haveSSE3()) {
608  }
609  if (CPU_haveSSE41()) {
611  }
612  if (CPU_haveSSE42()) {
614  }
615  if (CPU_haveAVX()) {
617  }
618  if (CPU_haveAVX2()) {
620  }
621  }
622  return SDL_CPUFeatures;
623 }
#define CPU_HAS_SSE41
Definition: SDL_cpuinfo.c:60
#define CPU_HAS_RDTSC
Definition: SDL_cpuinfo.c:53
#define CPU_HAS_SSE3
Definition: SDL_cpuinfo.c:59
static int CPU_haveSSE42(void)
Definition: SDL_cpuinfo.c:375
static int CPU_haveAVX(void)
Definition: SDL_cpuinfo.c:390
static int CPU_haveRDTSC(void)
Definition: SDL_cpuinfo.c:265
#define CPU_HAS_SSE2
Definition: SDL_cpuinfo.c:58
static int CPU_have3DNow(void)
Definition: SDL_cpuinfo.c:312
#define CPU_HAS_ALTIVEC
Definition: SDL_cpuinfo.c:54
static int CPU_haveAltiVec(void)
Definition: SDL_cpuinfo.c:274
#define CPU_HAS_AVX
Definition: SDL_cpuinfo.c:62
static int CPU_haveSSE3(void)
Definition: SDL_cpuinfo.c:345
static Uint32 SDL_CPUFeatures
Definition: SDL_cpuinfo.c:581
static int CPU_haveSSE(void)
Definition: SDL_cpuinfo.c:327
#define CPU_HAS_SSE
Definition: SDL_cpuinfo.c:57
static int CPU_haveAVX2(void)
Definition: SDL_cpuinfo.c:405
#define CPU_HAS_AVX2
Definition: SDL_cpuinfo.c:63
#define CPU_HAS_MMX
Definition: SDL_cpuinfo.c:55
#define CPU_HAS_SSE42
Definition: SDL_cpuinfo.c:61
#define CPU_HAS_3DNOW
Definition: SDL_cpuinfo.c:56
static int CPU_haveSSE41(void)
Definition: SDL_cpuinfo.c:360
static int CPU_haveMMX(void)
Definition: SDL_cpuinfo.c:303
static int CPU_haveSSE2(void)
Definition: SDL_cpuinfo.c:336

§ SDL_GetCPUType()

static const char* SDL_GetCPUType ( void  )
static

Definition at line 455 of file SDL_cpuinfo.c.

References CPU_haveCPUID(), cpuid, d, i, SDL_strlcpy, and void.

Referenced by SDL_GetCPUCacheLineSize(), and SDL_GetSystemRAM().

456 {
457  static char SDL_CPUType[13];
458 
459  if (!SDL_CPUType[0]) {
460  int i = 0;
461 
462  if (CPU_haveCPUID()) {
463  int a, b, c, d;
464  cpuid(0x00000000, a, b, c, d);
465  (void) a;
466  SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
467  SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
468  SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
469  SDL_CPUType[i++] = (char)(b & 0xff);
470 
471  SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
472  SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
473  SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
474  SDL_CPUType[i++] = (char)(d & 0xff);
475 
476  SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
477  SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
478  SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
479  SDL_CPUType[i++] = (char)(c & 0xff);
480  }
481  if (!SDL_CPUType[0]) {
482  SDL_strlcpy(SDL_CPUType, "Unknown", sizeof(SDL_CPUType));
483  }
484  }
485  return SDL_CPUType;
486 }
#define SDL_strlcpy
static int CPU_haveCPUID(void)
Definition: SDL_cpuinfo.c:78
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 ** d
const GLubyte * c
#define cpuid(func, a, b, c, d)
Definition: SDL_cpuinfo.c:214
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean GLboolean b

§ SDL_GetSystemRAM()

int SDL_GetSystemRAM ( void  )

This function returns the amount of RAM configured in the system, in MB.

Definition at line 727 of file SDL_cpuinfo.c.

References main, NULL, SDL_GetCPUCacheLineSize(), SDL_GetCPUCount(), SDL_GetCPUType(), SDL_Has3DNow(), SDL_HasAltiVec(), SDL_HasAVX(), SDL_HasAVX2(), SDL_HasMMX(), SDL_HasRDTSC(), SDL_HasSSE(), SDL_HasSSE2(), SDL_HasSSE3(), SDL_HasSSE41(), SDL_HasSSE42(), and SDL_SystemRAM.

728 {
729  if (!SDL_SystemRAM) {
730 #ifndef SDL_CPUINFO_DISABLED
731 #if defined(HAVE_SYSCONF) && defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE)
732  if (SDL_SystemRAM <= 0) {
733  SDL_SystemRAM = (int)((Sint64)sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE) / (1024*1024));
734  }
735 #endif
736 #ifdef HAVE_SYSCTLBYNAME
737  if (SDL_SystemRAM <= 0) {
738 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
739 #ifdef HW_REALMEM
740  int mib[2] = {CTL_HW, HW_REALMEM};
741 #else
742  /* might only report up to 2 GiB */
743  int mib[2] = {CTL_HW, HW_PHYSMEM};
744 #endif /* HW_REALMEM */
745 #else
746  int mib[2] = {CTL_HW, HW_MEMSIZE};
747 #endif /* __FreeBSD__ || __FreeBSD_kernel__ */
748  Uint64 memsize = 0;
749  size_t len = sizeof(memsize);
750 
751  if (sysctl(mib, 2, &memsize, &len, NULL, 0) == 0) {
752  SDL_SystemRAM = (int)(memsize / (1024*1024));
753  }
754  }
755 #endif
756 #ifdef __WIN32__
757  if (SDL_SystemRAM <= 0) {
758  MEMORYSTATUSEX stat;
759  stat.dwLength = sizeof(stat);
760  if (GlobalMemoryStatusEx(&stat)) {
761  SDL_SystemRAM = (int)(stat.ullTotalPhys / (1024 * 1024));
762  }
763  }
764 #endif
765 #endif
766  }
767  return SDL_SystemRAM;
768 }
static int SDL_SystemRAM
Definition: SDL_cpuinfo.c:724
uint64_t Uint64
An unsigned 64-bit integer type.
Definition: SDL_stdinc.h:168
GLenum GLsizei len
#define NULL
Definition: begin_code.h:143
int64_t Sint64
A signed 64-bit integer type.
Definition: SDL_stdinc.h:164

§ SDL_Has3DNow()

SDL_bool SDL_Has3DNow ( void  )

This function returns true if the CPU has 3DNow! features.

Definition at line 653 of file SDL_cpuinfo.c.

References CPU_HAS_3DNOW, SDL_FALSE, SDL_GetCPUFeatures(), and SDL_TRUE.

Referenced by SDL_GetSystemRAM().

654 {
656  return SDL_TRUE;
657  }
658  return SDL_FALSE;
659 }
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584
#define CPU_HAS_3DNOW
Definition: SDL_cpuinfo.c:56

§ SDL_HasAltiVec()

SDL_bool SDL_HasAltiVec ( void  )

This function returns true if the CPU has AltiVec features.

Definition at line 635 of file SDL_cpuinfo.c.

References CPU_HAS_ALTIVEC, SDL_FALSE, SDL_GetCPUFeatures(), and SDL_TRUE.

Referenced by SDL_GetSystemRAM().

636 {
638  return SDL_TRUE;
639  }
640  return SDL_FALSE;
641 }
#define CPU_HAS_ALTIVEC
Definition: SDL_cpuinfo.c:54
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584

§ SDL_HasAVX()

SDL_bool SDL_HasAVX ( void  )

This function returns true if the CPU has AVX features.

Definition at line 707 of file SDL_cpuinfo.c.

References CPU_HAS_AVX, SDL_FALSE, SDL_GetCPUFeatures(), and SDL_TRUE.

Referenced by SDL_GetSystemRAM().

708 {
710  return SDL_TRUE;
711  }
712  return SDL_FALSE;
713 }
#define CPU_HAS_AVX
Definition: SDL_cpuinfo.c:62
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584

§ SDL_HasAVX2()

SDL_bool SDL_HasAVX2 ( void  )

This function returns true if the CPU has AVX2 features.

Definition at line 716 of file SDL_cpuinfo.c.

References CPU_HAS_AVX2, SDL_FALSE, SDL_GetCPUFeatures(), and SDL_TRUE.

Referenced by SDL_GetSystemRAM().

717 {
719  return SDL_TRUE;
720  }
721  return SDL_FALSE;
722 }
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584
#define CPU_HAS_AVX2
Definition: SDL_cpuinfo.c:63

§ SDL_HasMMX()

SDL_bool SDL_HasMMX ( void  )

This function returns true if the CPU has MMX features.

Definition at line 644 of file SDL_cpuinfo.c.

References CPU_HAS_MMX, SDL_FALSE, SDL_GetCPUFeatures(), and SDL_TRUE.

Referenced by SDL_GetSystemRAM().

645 {
647  return SDL_TRUE;
648  }
649  return SDL_FALSE;
650 }
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584
#define CPU_HAS_MMX
Definition: SDL_cpuinfo.c:55

§ SDL_HasRDTSC()

SDL_bool SDL_HasRDTSC ( void  )

This function returns true if the CPU has the RDTSC instruction.

Definition at line 626 of file SDL_cpuinfo.c.

References CPU_HAS_RDTSC, SDL_FALSE, SDL_GetCPUFeatures(), and SDL_TRUE.

Referenced by SDL_GetSystemRAM().

627 {
629  return SDL_TRUE;
630  }
631  return SDL_FALSE;
632 }
#define CPU_HAS_RDTSC
Definition: SDL_cpuinfo.c:53
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584

§ SDL_HasSSE()

SDL_bool SDL_HasSSE ( void  )

This function returns true if the CPU has SSE features.

Definition at line 662 of file SDL_cpuinfo.c.

References CPU_HAS_SSE, SDL_FALSE, SDL_GetCPUFeatures(), and SDL_TRUE.

Referenced by SDL_GetSystemRAM().

663 {
665  return SDL_TRUE;
666  }
667  return SDL_FALSE;
668 }
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584
#define CPU_HAS_SSE
Definition: SDL_cpuinfo.c:57

§ SDL_HasSSE2()

SDL_bool SDL_HasSSE2 ( void  )

This function returns true if the CPU has SSE2 features.

Definition at line 671 of file SDL_cpuinfo.c.

References CPU_HAS_SSE2, SDL_FALSE, SDL_GetCPUFeatures(), and SDL_TRUE.

Referenced by SDL_GetSystemRAM().

672 {
674  return SDL_TRUE;
675  }
676  return SDL_FALSE;
677 }
#define CPU_HAS_SSE2
Definition: SDL_cpuinfo.c:58
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584

§ SDL_HasSSE3()

SDL_bool SDL_HasSSE3 ( void  )

This function returns true if the CPU has SSE3 features.

Definition at line 680 of file SDL_cpuinfo.c.

References CPU_HAS_SSE3, SDL_FALSE, SDL_GetCPUFeatures(), and SDL_TRUE.

Referenced by SDL_GetSystemRAM().

681 {
683  return SDL_TRUE;
684  }
685  return SDL_FALSE;
686 }
#define CPU_HAS_SSE3
Definition: SDL_cpuinfo.c:59
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584

§ SDL_HasSSE41()

SDL_bool SDL_HasSSE41 ( void  )

This function returns true if the CPU has SSE4.1 features.

Definition at line 689 of file SDL_cpuinfo.c.

References CPU_HAS_SSE41, SDL_FALSE, SDL_GetCPUFeatures(), and SDL_TRUE.

Referenced by SDL_GetSystemRAM().

690 {
692  return SDL_TRUE;
693  }
694  return SDL_FALSE;
695 }
#define CPU_HAS_SSE41
Definition: SDL_cpuinfo.c:60
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584

§ SDL_HasSSE42()

SDL_bool SDL_HasSSE42 ( void  )

This function returns true if the CPU has SSE4.2 features.

Definition at line 698 of file SDL_cpuinfo.c.

References CPU_HAS_SSE42, SDL_FALSE, SDL_GetCPUFeatures(), and SDL_TRUE.

Referenced by SDL_GetSystemRAM().

699 {
701  return SDL_TRUE;
702  }
703  return SDL_FALSE;
704 }
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584
#define CPU_HAS_SSE42
Definition: SDL_cpuinfo.c:61

Variable Documentation

§ SDL_CPUCount

int SDL_CPUCount = 0
static

Definition at line 419 of file SDL_cpuinfo.c.

Referenced by SDL_GetCPUCount().

§ SDL_CPUFeatures

Uint32 SDL_CPUFeatures = 0xFFFFFFFF
static

Definition at line 581 of file SDL_cpuinfo.c.

Referenced by SDL_GetCPUFeatures().

§ SDL_SystemRAM

int SDL_SystemRAM = 0
static

Definition at line 724 of file SDL_cpuinfo.c.

Referenced by SDL_GetSystemRAM().