SDL_cpuinfo.h File Reference
`#include "SDL_stdinc.h"`
`#include "begin_code.h"`
`#include "close_code.h"`
Include dependency graph for SDL_cpuinfo.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Macros

#define | SDL_CACHELINE_SIZE 128

## Functions

int | SDL_GetCPUCount (void)
int | SDL_GetCPUCacheLineSize (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)

## Detailed Description

CPU feature detection for SDL.

Definition in file SDL_cpuinfo.h.

## Macro Definition Documentation

#define SDL_CACHELINE_SIZE 128

Definition at line 77 of file SDL_cpuinfo.h.

Referenced by SDL_GetCPUCacheLineSize().

## Function Documentation

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().

{
const char *cpuType = SDL_GetCPUType();
int a, b, c, d;
(void) a; (void) b; (void) c; (void) d;
if (SDL_strcmp(cpuType, "GenuineIntel") == 0) {
cpuid(0x00000001, a, b, c, d);
return (((b >> 8) & 0xff) * 8);
} else if (SDL_strcmp(cpuType, "AuthenticAMD") == 0) {
cpuid(0x80000005, a, b, c, d);
return (c & 0xff);
} else {
/* Just make a guess here... */
return SDL_CACHELINE_SIZE;
}
}
SDL_GetCPUType
static const char * SDL_GetCPUType(void)
Definition: SDL_cpuinfo.c:455
d
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
Definition: SDL_dynapi_procs.h:121
SDL_CACHELINE_SIZE
#define SDL_CACHELINE_SIZE
Definition: SDL_cpuinfo.h:77
c
const GLubyte * c
Definition: SDL_opengl_glext.h:11093
cpuid
#define cpuid(func, a, b, c, d)
Definition: SDL_cpuinfo.c:214
void
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
Definition: SDL_dynapi_procs.h:93
SDL_strcmp
#define SDL_strcmp
Definition: SDL_dynapi_overrides.h:423
a
GLboolean GLboolean GLboolean GLboolean a
Definition: SDL_opengl_glext.h:1109
b
GLboolean GLboolean GLboolean b
Definition: SDL_opengl_glext.h:1109

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().

{
if (!SDL_CPUCount) {
#ifndef SDL_CPUINFO_DISABLED
#if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
if (SDL_CPUCount <= 0) {
SDL_CPUCount = (int)sysconf(_SC_NPROCESSORS_ONLN);
}
#endif
#ifdef HAVE_SYSCTLBYNAME
if (SDL_CPUCount <= 0) {
size_t size = sizeof(SDL_CPUCount);
sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0);
}
#endif
#ifdef __WIN32__
if (SDL_CPUCount <= 0) {
SYSTEM_INFO info;
GetSystemInfo(&info);
SDL_CPUCount = info.dwNumberOfProcessors;
}
#endif
#endif
/* There has to be at least 1, right? :) */
if (SDL_CPUCount <= 0) {
SDL_CPUCount = 1;
}
}
return SDL_CPUCount;
}
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:537
NULL
#define NULL
Definition: begin_code.h:143
SDL_CPUCount
static int SDL_CPUCount
Definition: SDL_cpuinfo.c:419

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.

{
if (!SDL_SystemRAM) {
#ifndef SDL_CPUINFO_DISABLED
#if defined(HAVE_SYSCONF) && defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE)
if (SDL_SystemRAM <= 0) {
SDL_SystemRAM = (int)((Sint64)sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE) / (1024*1024));
}
#endif
#ifdef HAVE_SYSCTLBYNAME
if (SDL_SystemRAM <= 0) {
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
#ifdef HW_REALMEM
int mib[2] = {CTL_HW, HW_REALMEM};
#else
/* might only report up to 2 GiB */
int mib[2] = {CTL_HW, HW_PHYSMEM};
#endif /* HW_REALMEM */
#else
int mib[2] = {CTL_HW, HW_MEMSIZE};
#endif /* __FreeBSD__ || __FreeBSD_kernel__ */
Uint64 memsize = 0;
size_t len = sizeof(memsize);
if (sysctl(mib, 2, &memsize, &len, NULL, 0) == 0) {
SDL_SystemRAM = (int)(memsize / (1024*1024));
}
}
#endif
#ifdef __WIN32__
if (SDL_SystemRAM <= 0) {
MEMORYSTATUSEX stat;
stat.dwLength = sizeof(stat);
if (GlobalMemoryStatusEx(&stat)) {
SDL_SystemRAM = (int)(stat.ullTotalPhys / (1024 * 1024));
}
}
#endif
#endif
}
return SDL_SystemRAM;
}
SDL_SystemRAM
static int SDL_SystemRAM
Definition: SDL_cpuinfo.c:724
Uint64
uint64_t Uint64
An unsigned 64-bit integer type.
Definition: SDL_stdinc.h:166
len
GLenum GLsizei len
Definition: SDL_opengl_glext.h:2926
NULL
#define NULL
Definition: begin_code.h:143
Sint64
int64_t Sint64
A signed 64-bit integer type.
Definition: SDL_stdinc.h:162

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().

{
if (SDL_GetCPUFeatures() & CPU_HAS_3DNOW) {
return SDL_TRUE;
}
return SDL_FALSE;
}
SDL_GetCPUFeatures
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584
SDL_TRUE
Definition: SDL_stdinc.h:129
SDL_FALSE
Definition: SDL_stdinc.h:128
CPU_HAS_3DNOW
#define CPU_HAS_3DNOW
Definition: SDL_cpuinfo.c:56

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().

{
if (SDL_GetCPUFeatures() & CPU_HAS_ALTIVEC) {
return SDL_TRUE;
}
return SDL_FALSE;
}
CPU_HAS_ALTIVEC
#define CPU_HAS_ALTIVEC
Definition: SDL_cpuinfo.c:54
SDL_GetCPUFeatures
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584
SDL_TRUE
Definition: SDL_stdinc.h:129
SDL_FALSE
Definition: SDL_stdinc.h:128

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().

{
if (SDL_GetCPUFeatures() & CPU_HAS_AVX) {
return SDL_TRUE;
}
return SDL_FALSE;
}
CPU_HAS_AVX
#define CPU_HAS_AVX
Definition: SDL_cpuinfo.c:62
SDL_GetCPUFeatures
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584
SDL_TRUE
Definition: SDL_stdinc.h:129
SDL_FALSE
Definition: SDL_stdinc.h:128

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().

{
if (SDL_GetCPUFeatures() & CPU_HAS_AVX2) {
return SDL_TRUE;
}
return SDL_FALSE;
}
SDL_GetCPUFeatures
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584
SDL_TRUE
Definition: SDL_stdinc.h:129
CPU_HAS_AVX2
#define CPU_HAS_AVX2
Definition: SDL_cpuinfo.c:63
SDL_FALSE
Definition: SDL_stdinc.h:128

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().

{
if (SDL_GetCPUFeatures() & CPU_HAS_MMX) {
return SDL_TRUE;
}
return SDL_FALSE;
}
SDL_GetCPUFeatures
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584
SDL_TRUE
Definition: SDL_stdinc.h:129
CPU_HAS_MMX
#define CPU_HAS_MMX
Definition: SDL_cpuinfo.c:55
SDL_FALSE
Definition: SDL_stdinc.h:128

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().

{
if (SDL_GetCPUFeatures() & CPU_HAS_RDTSC) {
return SDL_TRUE;
}
return SDL_FALSE;
}
CPU_HAS_RDTSC
#define CPU_HAS_RDTSC
Definition: SDL_cpuinfo.c:53
SDL_GetCPUFeatures
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584
SDL_TRUE
Definition: SDL_stdinc.h:129
SDL_FALSE
Definition: SDL_stdinc.h:128

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().

{
if (SDL_GetCPUFeatures() & CPU_HAS_SSE) {
return SDL_TRUE;
}
return SDL_FALSE;
}
SDL_GetCPUFeatures
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584
CPU_HAS_SSE
#define CPU_HAS_SSE
Definition: SDL_cpuinfo.c:57
SDL_TRUE
Definition: SDL_stdinc.h:129
SDL_FALSE
Definition: SDL_stdinc.h:128

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().

{
if (SDL_GetCPUFeatures() & CPU_HAS_SSE2) {
return SDL_TRUE;
}
return SDL_FALSE;
}
CPU_HAS_SSE2
#define CPU_HAS_SSE2
Definition: SDL_cpuinfo.c:58
SDL_GetCPUFeatures
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584
SDL_TRUE
Definition: SDL_stdinc.h:129
SDL_FALSE
Definition: SDL_stdinc.h:128

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().

{
if (SDL_GetCPUFeatures() & CPU_HAS_SSE3) {
return SDL_TRUE;
}
return SDL_FALSE;
}
CPU_HAS_SSE3
#define CPU_HAS_SSE3
Definition: SDL_cpuinfo.c:59
SDL_GetCPUFeatures
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584
SDL_TRUE
Definition: SDL_stdinc.h:129
SDL_FALSE
Definition: SDL_stdinc.h:128

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().

{
if (SDL_GetCPUFeatures() & CPU_HAS_SSE41) {
return SDL_TRUE;
}
return SDL_FALSE;
}
CPU_HAS_SSE41
#define CPU_HAS_SSE41
Definition: SDL_cpuinfo.c:60
SDL_GetCPUFeatures
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584
SDL_TRUE
Definition: SDL_stdinc.h:129
SDL_FALSE
Definition: SDL_stdinc.h:128

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().

{
if (SDL_GetCPUFeatures() & CPU_HAS_SSE42) {
return SDL_TRUE;
}
return SDL_FALSE;
}
SDL_GetCPUFeatures
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:584
SDL_TRUE
Definition: SDL_stdinc.h:129
SDL_FALSE
Definition: SDL_stdinc.h:128
CPU_HAS_SSE42
#define CPU_HAS_SSE42
Definition: SDL_cpuinfo.c:61