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_HasAVX512F (void)
 
SDL_bool SDL_HasNEON (void)
 
SDL_bool SDL_HasMSA (void)
 
SDL_bool SDL_HasLSX (void)
 
SDL_bool SDL_HasLASX (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 103 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 633 of file SDL_cpuinfo.c.

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

Referenced by SDL_SIMDFree().

634 {
635  const char *cpuType = SDL_GetCPUType();
636  int a, b, c, d;
637  (void) a; (void) b; (void) c; (void) d;
638  if (SDL_strcmp(cpuType, "GenuineIntel") == 0) {
639  cpuid(0x00000001, a, b, c, d);
640  return (((b >> 8) & 0xff) * 8);
641  } else if (SDL_strcmp(cpuType, "AuthenticAMD") == 0) {
642  cpuid(0x80000005, a, b, c, d);
643  return (c & 0xff);
644  } else {
645  /* Just make a guess here... */
646  return SDL_CACHELINE_SIZE;
647  }
648 }
static const char * SDL_GetCPUType(void)
Definition: SDL_cpuinfo.c:522
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:103
const GLubyte * c
#define cpuid(func, a, b, c, d)
Definition: SDL_cpuinfo.c:252
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 483 of file SDL_cpuinfo.c.

References NULL, and SDL_CPUCount.

Referenced by SDL_SIMDFree().

484 {
485  if (!SDL_CPUCount) {
486 #ifndef SDL_CPUINFO_DISABLED
487 #if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
488  if (SDL_CPUCount <= 0) {
489  SDL_CPUCount = (int)sysconf(_SC_NPROCESSORS_ONLN);
490  }
491 #endif
492 #ifdef HAVE_SYSCTLBYNAME
493  if (SDL_CPUCount <= 0) {
494  size_t size = sizeof(SDL_CPUCount);
495  sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0);
496  }
497 #endif
498 #ifdef __WIN32__
499  if (SDL_CPUCount <= 0) {
500  SYSTEM_INFO info;
501  GetSystemInfo(&info);
502  SDL_CPUCount = info.dwNumberOfProcessors;
503  }
504 #endif
505 #ifdef __OS2__
506  if (SDL_CPUCount <= 0) {
507  DosQuerySysInfo(QSV_NUMPROCESSORS, QSV_NUMPROCESSORS,
508  &SDL_CPUCount, sizeof(SDL_CPUCount) );
509  }
510 #endif
511 #endif
512  /* There has to be at least 1, right? :) */
513  if (SDL_CPUCount <= 0) {
514  SDL_CPUCount = 1;
515  }
516  }
517  return SDL_CPUCount;
518 }
GLsizeiptr size
#define NULL
Definition: begin_code.h:164
static int SDL_CPUCount
Definition: SDL_cpuinfo.c:480

◆ SDL_GetSystemRAM()

int SDL_GetSystemRAM ( void  )

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

Definition at line 827 of file SDL_cpuinfo.c.

References NULL, and SDL_SystemRAM.

Referenced by SDL_SIMDFree().

828 {
829  if (!SDL_SystemRAM) {
830 #ifndef SDL_CPUINFO_DISABLED
831 #if defined(HAVE_SYSCONF) && defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE)
832  if (SDL_SystemRAM <= 0) {
833  SDL_SystemRAM = (int)((Sint64)sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE) / (1024*1024));
834  }
835 #endif
836 #ifdef HAVE_SYSCTLBYNAME
837  if (SDL_SystemRAM <= 0) {
838 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
839 #ifdef HW_REALMEM
840  int mib[2] = {CTL_HW, HW_REALMEM};
841 #else
842  /* might only report up to 2 GiB */
843  int mib[2] = {CTL_HW, HW_PHYSMEM};
844 #endif /* HW_REALMEM */
845 #else
846  int mib[2] = {CTL_HW, HW_MEMSIZE};
847 #endif /* __FreeBSD__ || __FreeBSD_kernel__ */
848  Uint64 memsize = 0;
849  size_t len = sizeof(memsize);
850 
851  if (sysctl(mib, 2, &memsize, &len, NULL, 0) == 0) {
852  SDL_SystemRAM = (int)(memsize / (1024*1024));
853  }
854  }
855 #endif
856 #ifdef __WIN32__
857  if (SDL_SystemRAM <= 0) {
858  MEMORYSTATUSEX stat;
859  stat.dwLength = sizeof(stat);
860  if (GlobalMemoryStatusEx(&stat)) {
861  SDL_SystemRAM = (int)(stat.ullTotalPhys / (1024 * 1024));
862  }
863  }
864 #endif
865 #ifdef __OS2__
866  if (SDL_SystemRAM <= 0) {
867  Uint32 sysram = 0;
868  DosQuerySysInfo(QSV_TOTPHYSMEM, QSV_TOTPHYSMEM, &sysram, 4);
869  SDL_SystemRAM = (int) (sysram / 0x100000U);
870  }
871 #endif
872 #endif
873  }
874  return SDL_SystemRAM;
875 }
uint32_t Uint32
Definition: SDL_stdinc.h:203
static int SDL_SystemRAM
Definition: SDL_cpuinfo.c:824
uint64_t Uint64
Definition: SDL_stdinc.h:216
GLenum GLsizei len
#define NULL
Definition: begin_code.h:164
int64_t Sint64
Definition: SDL_stdinc.h:210

◆ SDL_Has3DNow()

SDL_bool SDL_Has3DNow ( void  )

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

Definition at line 747 of file SDL_cpuinfo.c.

References CPU_FEATURE_AVAILABLE, and CPU_HAS_3DNOW.

Referenced by SDL_SIMDFree().

748 {
750 }
#define CPU_FEATURE_AVAILABLE(f)
Definition: SDL_cpuinfo.c:727
#define CPU_HAS_3DNOW
Definition: SDL_cpuinfo.c:84

◆ SDL_HasAltiVec()

SDL_bool SDL_HasAltiVec ( void  )

This function returns true if the CPU has AltiVec features.

Definition at line 735 of file SDL_cpuinfo.c.

References CPU_FEATURE_AVAILABLE, and CPU_HAS_ALTIVEC.

Referenced by SDL_SIMDFree().

736 {
738 }
#define CPU_HAS_ALTIVEC
Definition: SDL_cpuinfo.c:82
#define CPU_FEATURE_AVAILABLE(f)
Definition: SDL_cpuinfo.c:727

◆ SDL_HasAVX()

SDL_bool SDL_HasAVX ( void  )

This function returns true if the CPU has AVX features.

Definition at line 783 of file SDL_cpuinfo.c.

References CPU_FEATURE_AVAILABLE, and CPU_HAS_AVX.

Referenced by SDL_SIMDFree().

784 {
786 }
#define CPU_HAS_AVX
Definition: SDL_cpuinfo.c:90
#define CPU_FEATURE_AVAILABLE(f)
Definition: SDL_cpuinfo.c:727

◆ SDL_HasAVX2()

SDL_bool SDL_HasAVX2 ( void  )

This function returns true if the CPU has AVX2 features.

Definition at line 789 of file SDL_cpuinfo.c.

References CPU_FEATURE_AVAILABLE, and CPU_HAS_AVX2.

Referenced by SDL_SIMDFree().

790 {
792 }
#define CPU_FEATURE_AVAILABLE(f)
Definition: SDL_cpuinfo.c:727
#define CPU_HAS_AVX2
Definition: SDL_cpuinfo.c:91

◆ SDL_HasAVX512F()

SDL_bool SDL_HasAVX512F ( void  )

This function returns true if the CPU has AVX-512F (foundation) features.

Definition at line 795 of file SDL_cpuinfo.c.

References CPU_FEATURE_AVAILABLE, and CPU_HAS_AVX512F.

Referenced by SDL_SIMDFree().

796 {
798 }
#define CPU_HAS_AVX512F
Definition: SDL_cpuinfo.c:93
#define CPU_FEATURE_AVAILABLE(f)
Definition: SDL_cpuinfo.c:727

◆ SDL_HasLASX()

SDL_bool SDL_HasLASX ( void  )

This function returns true if the CPU has LASX (LOONGARCH SIMD) features.

Definition at line 819 of file SDL_cpuinfo.c.

References CPU_FEATURE_AVAILABLE, and CPU_HAS_LASX.

Referenced by SDL_SIMDFree().

820 {
822 }
#define CPU_FEATURE_AVAILABLE(f)
Definition: SDL_cpuinfo.c:727
#define CPU_HAS_LASX
Definition: SDL_cpuinfo.c:96

◆ SDL_HasLSX()

SDL_bool SDL_HasLSX ( void  )

This function returns true if the CPU has LSX (LOONGARCH SIMD) features.

Definition at line 813 of file SDL_cpuinfo.c.

References CPU_FEATURE_AVAILABLE, and CPU_HAS_LSX.

Referenced by SDL_SIMDFree(), and yuv_rgb_lsx().

814 {
816 }
#define CPU_HAS_LSX
Definition: SDL_cpuinfo.c:95
#define CPU_FEATURE_AVAILABLE(f)
Definition: SDL_cpuinfo.c:727

◆ SDL_HasMMX()

SDL_bool SDL_HasMMX ( void  )

This function returns true if the CPU has MMX features.

Definition at line 741 of file SDL_cpuinfo.c.

References CPU_FEATURE_AVAILABLE, and CPU_HAS_MMX.

Referenced by SDL_SIMDFree().

742 {
744 }
#define CPU_FEATURE_AVAILABLE(f)
Definition: SDL_cpuinfo.c:727
#define CPU_HAS_MMX
Definition: SDL_cpuinfo.c:83

◆ SDL_HasMSA()

SDL_bool SDL_HasMSA ( void  )

This function returns true if the CPU has MSA (MIPS SIMD) features.

Definition at line 807 of file SDL_cpuinfo.c.

References CPU_FEATURE_AVAILABLE, and CPU_HAS_MSA.

Referenced by SDL_SIMDFree().

808 {
810 }
#define CPU_HAS_MSA
Definition: SDL_cpuinfo.c:94
#define CPU_FEATURE_AVAILABLE(f)
Definition: SDL_cpuinfo.c:727

◆ SDL_HasNEON()

SDL_bool SDL_HasNEON ( void  )

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

Definition at line 801 of file SDL_cpuinfo.c.

References CPU_FEATURE_AVAILABLE, and CPU_HAS_NEON.

Referenced by SDL_SIMDFree().

802 {
804 }
#define CPU_FEATURE_AVAILABLE(f)
Definition: SDL_cpuinfo.c:727
#define CPU_HAS_NEON
Definition: SDL_cpuinfo.c:92

◆ SDL_HasRDTSC()

SDL_bool SDL_HasRDTSC ( void  )

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

Definition at line 729 of file SDL_cpuinfo.c.

References CPU_FEATURE_AVAILABLE, and CPU_HAS_RDTSC.

Referenced by SDL_SIMDFree().

730 {
732 }
#define CPU_HAS_RDTSC
Definition: SDL_cpuinfo.c:81
#define CPU_FEATURE_AVAILABLE(f)
Definition: SDL_cpuinfo.c:727

◆ SDL_HasSSE()

SDL_bool SDL_HasSSE ( void  )

This function returns true if the CPU has SSE features.

Definition at line 753 of file SDL_cpuinfo.c.

References CPU_FEATURE_AVAILABLE, and CPU_HAS_SSE.

Referenced by SDL_SIMDFree().

754 {
756 }
#define CPU_FEATURE_AVAILABLE(f)
Definition: SDL_cpuinfo.c:727
#define CPU_HAS_SSE
Definition: SDL_cpuinfo.c:85

◆ SDL_HasSSE2()

SDL_bool SDL_HasSSE2 ( void  )

This function returns true if the CPU has SSE2 features.

Definition at line 759 of file SDL_cpuinfo.c.

References CPU_FEATURE_AVAILABLE, and CPU_HAS_SSE2.

Referenced by SDL_SIMDFree().

760 {
762 }
#define CPU_HAS_SSE2
Definition: SDL_cpuinfo.c:86
#define CPU_FEATURE_AVAILABLE(f)
Definition: SDL_cpuinfo.c:727

◆ SDL_HasSSE3()

SDL_bool SDL_HasSSE3 ( void  )

This function returns true if the CPU has SSE3 features.

Definition at line 765 of file SDL_cpuinfo.c.

References CPU_FEATURE_AVAILABLE, and CPU_HAS_SSE3.

Referenced by SDL_SIMDFree().

766 {
768 }
#define CPU_HAS_SSE3
Definition: SDL_cpuinfo.c:87
#define CPU_FEATURE_AVAILABLE(f)
Definition: SDL_cpuinfo.c:727

◆ SDL_HasSSE41()

SDL_bool SDL_HasSSE41 ( void  )

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

Definition at line 771 of file SDL_cpuinfo.c.

References CPU_FEATURE_AVAILABLE, and CPU_HAS_SSE41.

Referenced by SDL_SIMDFree().

772 {
774 }
#define CPU_HAS_SSE41
Definition: SDL_cpuinfo.c:88
#define CPU_FEATURE_AVAILABLE(f)
Definition: SDL_cpuinfo.c:727

◆ SDL_HasSSE42()

SDL_bool SDL_HasSSE42 ( void  )

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

Definition at line 777 of file SDL_cpuinfo.c.

References CPU_FEATURE_AVAILABLE, and CPU_HAS_SSE42.

Referenced by SDL_SIMDFree().

778 {
780 }
#define CPU_FEATURE_AVAILABLE(f)
Definition: SDL_cpuinfo.c:727
#define CPU_HAS_SSE42
Definition: SDL_cpuinfo.c:89