SDL  2.0
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)
 
SDL_bool SDL_HasARMSIMD (void)
 
SDL_bool SDL_HasNEON (void)
 
int SDL_GetSystemRAM (void)
 

Detailed Description

CPU feature detection for SDL.

Definition in file SDL_cpuinfo.h.

Macro Definition Documentation

◆ SDL_CACHELINE_SIZE

#define SDL_CACHELINE_SIZE   128

Definition at line 77 of file SDL_cpuinfo.h.

Referenced by SDL_GetCPUCacheLineSize().

Function Documentation

◆ 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 693 of file SDL_cpuinfo.c.

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

Referenced by SDL_GetSystemRAM().

694 {
695  const char *cpuType = SDL_GetCPUType();
696  int a, b, c, d;
697  (void) a; (void) b; (void) c; (void) d;
698  if (SDL_strcmp(cpuType, "GenuineIntel") == 0) {
699  cpuid(0x00000001, a, b, c, d);
700  return (((b >> 8) & 0xff) * 8);
701  } else if (SDL_strcmp(cpuType, "AuthenticAMD") == 0) {
702  cpuid(0x80000005, a, b, c, d);
703  return (c & 0xff);
704  } else {
705  /* Just make a guess here... */
706  return SDL_CACHELINE_SIZE;
707  }
708 }
static const char * SDL_GetCPUType(void)
Definition: SDL_cpuinfo.c:584
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:231
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 551 of file SDL_cpuinfo.c.

References NULL, and SDL_CPUCount.

Referenced by SDL_GetSystemRAM().

552 {
553  if (!SDL_CPUCount) {
554 #ifndef SDL_CPUINFO_DISABLED
555 #if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
556  if (SDL_CPUCount <= 0) {
557  SDL_CPUCount = (int)sysconf(_SC_NPROCESSORS_ONLN);
558  }
559 #endif
560 #ifdef HAVE_SYSCTLBYNAME
561  if (SDL_CPUCount <= 0) {
562  size_t size = sizeof(SDL_CPUCount);
563  sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0);
564  }
565 #endif
566 #ifdef __WIN32__
567  if (SDL_CPUCount <= 0) {
568  SYSTEM_INFO info;
569  GetSystemInfo(&info);
570  SDL_CPUCount = info.dwNumberOfProcessors;
571  }
572 #endif
573 #endif
574  /* There has to be at least 1, right? :) */
575  if (SDL_CPUCount <= 0) {
576  SDL_CPUCount = 1;
577  }
578  }
579  return SDL_CPUCount;
580 }
GLsizeiptr size
#define NULL
Definition: begin_code.h:143
static int SDL_CPUCount
Definition: SDL_cpuinfo.c:548

◆ SDL_GetSystemRAM()

int SDL_GetSystemRAM ( void  )

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

Definition at line 880 of file SDL_cpuinfo.c.

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

881 {
882  if (!SDL_SystemRAM) {
883 #ifndef SDL_CPUINFO_DISABLED
884 #if defined(HAVE_SYSCONF) && defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE)
885  if (SDL_SystemRAM <= 0) {
886  SDL_SystemRAM = (int)((Sint64)sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE) / (1024*1024));
887  }
888 #endif
889 #ifdef HAVE_SYSCTLBYNAME
890  if (SDL_SystemRAM <= 0) {
891 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
892 #ifdef HW_REALMEM
893  int mib[2] = {CTL_HW, HW_REALMEM};
894 #else
895  /* might only report up to 2 GiB */
896  int mib[2] = {CTL_HW, HW_PHYSMEM};
897 #endif /* HW_REALMEM */
898 #else
899  int mib[2] = {CTL_HW, HW_MEMSIZE};
900 #endif /* __FreeBSD__ || __FreeBSD_kernel__ */
901  Uint64 memsize = 0;
902  size_t len = sizeof(memsize);
903 
904  if (sysctl(mib, 2, &memsize, &len, NULL, 0) == 0) {
905  SDL_SystemRAM = (int)(memsize / (1024*1024));
906  }
907  }
908 #endif
909 #ifdef __WIN32__
910  if (SDL_SystemRAM <= 0) {
911  MEMORYSTATUSEX stat;
912  stat.dwLength = sizeof(stat);
913  if (GlobalMemoryStatusEx(&stat)) {
914  SDL_SystemRAM = (int)(stat.ullTotalPhys / (1024 * 1024));
915  }
916  }
917 #endif
918 #endif
919  }
920  return SDL_SystemRAM;
921 }
static int SDL_SystemRAM
Definition: SDL_cpuinfo.c:877
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 788 of file SDL_cpuinfo.c.

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

Referenced by SDL_GetSystemRAM().

789 {
791  return SDL_TRUE;
792  }
793  return SDL_FALSE;
794 }
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:713
#define CPU_HAS_3DNOW
Definition: SDL_cpuinfo.c:71

◆ SDL_HasAltiVec()

SDL_bool SDL_HasAltiVec ( void  )

This function returns true if the CPU has AltiVec features.

Definition at line 770 of file SDL_cpuinfo.c.

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

Referenced by SDL_GetSystemRAM().

771 {
773  return SDL_TRUE;
774  }
775  return SDL_FALSE;
776 }
#define CPU_HAS_ALTIVEC
Definition: SDL_cpuinfo.c:69
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:713

◆ SDL_HasARMSIMD()

SDL_bool SDL_HasARMSIMD ( void  )

This function returns true if the CPU has ARM SIMD (ARMv6) features.

Definition at line 860 of file SDL_cpuinfo.c.

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

Referenced by SDL_CalculateBlitA(), SDL_FillRect(), and SDL_GetSystemRAM().

861 {
863  return SDL_TRUE;
864  }
865  return SDL_FALSE;
866 }
#define CPU_HAS_ARM_SIMD
Definition: SDL_cpuinfo.c:80
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:713

◆ SDL_HasAVX()

SDL_bool SDL_HasAVX ( void  )

This function returns true if the CPU has AVX features.

Definition at line 842 of file SDL_cpuinfo.c.

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

Referenced by SDL_GetSystemRAM().

843 {
845  return SDL_TRUE;
846  }
847  return SDL_FALSE;
848 }
#define CPU_HAS_AVX
Definition: SDL_cpuinfo.c:77
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:713

◆ SDL_HasAVX2()

SDL_bool SDL_HasAVX2 ( void  )

This function returns true if the CPU has AVX2 features.

Definition at line 851 of file SDL_cpuinfo.c.

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

Referenced by SDL_GetSystemRAM().

852 {
854  return SDL_TRUE;
855  }
856  return SDL_FALSE;
857 }
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:713
#define CPU_HAS_AVX2
Definition: SDL_cpuinfo.c:78

◆ SDL_HasMMX()

SDL_bool SDL_HasMMX ( void  )

This function returns true if the CPU has MMX features.

Definition at line 779 of file SDL_cpuinfo.c.

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

Referenced by SDL_GetSystemRAM().

780 {
782  return SDL_TRUE;
783  }
784  return SDL_FALSE;
785 }
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:713
#define CPU_HAS_MMX
Definition: SDL_cpuinfo.c:70

◆ SDL_HasNEON()

SDL_bool SDL_HasNEON ( void  )

This function returns true if the CPU has NEON (ARM SIMD) features.

Definition at line 869 of file SDL_cpuinfo.c.

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

Referenced by SDL_CalculateBlitA(), SDL_FillRect(), and SDL_GetSystemRAM().

870 {
872  return SDL_TRUE;
873  }
874  return SDL_FALSE;
875 }
#define CPU_HAS_NEON
Definition: SDL_cpuinfo.c:79
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:713

◆ SDL_HasRDTSC()

SDL_bool SDL_HasRDTSC ( void  )

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

Definition at line 761 of file SDL_cpuinfo.c.

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

Referenced by SDL_GetSystemRAM().

762 {
764  return SDL_TRUE;
765  }
766  return SDL_FALSE;
767 }
#define CPU_HAS_RDTSC
Definition: SDL_cpuinfo.c:68
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:713

◆ SDL_HasSSE()

SDL_bool SDL_HasSSE ( void  )

This function returns true if the CPU has SSE features.

Definition at line 797 of file SDL_cpuinfo.c.

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

Referenced by SDL_GetSystemRAM().

798 {
800  return SDL_TRUE;
801  }
802  return SDL_FALSE;
803 }
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:713
#define CPU_HAS_SSE
Definition: SDL_cpuinfo.c:72

◆ SDL_HasSSE2()

SDL_bool SDL_HasSSE2 ( void  )

This function returns true if the CPU has SSE2 features.

Definition at line 806 of file SDL_cpuinfo.c.

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

Referenced by SDL_GetSystemRAM().

807 {
809  return SDL_TRUE;
810  }
811  return SDL_FALSE;
812 }
#define CPU_HAS_SSE2
Definition: SDL_cpuinfo.c:73
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:713

◆ SDL_HasSSE3()

SDL_bool SDL_HasSSE3 ( void  )

This function returns true if the CPU has SSE3 features.

Definition at line 815 of file SDL_cpuinfo.c.

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

Referenced by SDL_GetSystemRAM().

816 {
818  return SDL_TRUE;
819  }
820  return SDL_FALSE;
821 }
#define CPU_HAS_SSE3
Definition: SDL_cpuinfo.c:74
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:713

◆ SDL_HasSSE41()

SDL_bool SDL_HasSSE41 ( void  )

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

Definition at line 824 of file SDL_cpuinfo.c.

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

Referenced by SDL_GetSystemRAM().

825 {
827  return SDL_TRUE;
828  }
829  return SDL_FALSE;
830 }
#define CPU_HAS_SSE41
Definition: SDL_cpuinfo.c:75
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:713

◆ SDL_HasSSE42()

SDL_bool SDL_HasSSE42 ( void  )

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

Definition at line 833 of file SDL_cpuinfo.c.

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

Referenced by SDL_GetSystemRAM().

834 {
836  return SDL_TRUE;
837  }
838  return SDL_FALSE;
839 }
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:713
#define CPU_HAS_SSE42
Definition: SDL_cpuinfo.c:76