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

Go to the source code of this file.

Macros

#define CPU_HAS_RDTSC   (1 << 0)
 
#define CPU_HAS_ALTIVEC   (1 << 1)
 
#define CPU_HAS_MMX   (1 << 2)
 
#define CPU_HAS_3DNOW   (1 << 3)
 
#define CPU_HAS_SSE   (1 << 4)
 
#define CPU_HAS_SSE2   (1 << 5)
 
#define CPU_HAS_SSE3   (1 << 6)
 
#define CPU_HAS_SSE41   (1 << 7)
 
#define CPU_HAS_SSE42   (1 << 8)
 
#define CPU_HAS_AVX   (1 << 9)
 
#define CPU_HAS_AVX2   (1 << 10)
 
#define CPU_HAS_NEON   (1 << 11)
 
#define CPU_HAS_AVX512F   (1 << 12)
 
#define CPU_HAS_ARM_SIMD   (1 << 13)
 
#define cpuid(func, a, b, c, d)    do { a = b = c = d = 0; (void) a; (void) b; (void) c; (void) d; } while (0)
 
#define CPU_haveRDTSC()   (CPU_CPUIDFeatures[3] & 0x00000010)
 
#define CPU_haveMMX()   (CPU_CPUIDFeatures[3] & 0x00800000)
 
#define CPU_haveSSE()   (CPU_CPUIDFeatures[3] & 0x02000000)
 
#define CPU_haveSSE2()   (CPU_CPUIDFeatures[3] & 0x04000000)
 
#define CPU_haveSSE3()   (CPU_CPUIDFeatures[2] & 0x00000001)
 
#define CPU_haveSSE41()   (CPU_CPUIDFeatures[2] & 0x00080000)
 
#define CPU_haveSSE42()   (CPU_CPUIDFeatures[2] & 0x00100000)
 
#define CPU_haveAVX()   (CPU_OSSavesYMM && (CPU_CPUIDFeatures[2] & 0x10000000))
 
#define CPU_FEATURE_AVAILABLE(f)   ((SDL_GetCPUFeatures() & f) ? SDL_TRUE : SDL_FALSE)
 

Functions

static int CPU_haveCPUID (void)
 
static void CPU_calcCPUIDFeatures (void)
 
static int CPU_haveAltiVec (void)
 
static int CPU_haveARMSIMD (void)
 
static int CPU_haveNEON (void)
 
static int CPU_have3DNow (void)
 
static int CPU_haveAVX2 (void)
 
static int CPU_haveAVX512F (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)
 
SDL_bool SDL_HasAVX512F (void)
 
SDL_bool SDL_HasARMSIMD (void)
 
SDL_bool SDL_HasNEON (void)
 
int SDL_GetSystemRAM (void)
 
size_t SDL_SIMDGetAlignment (void)
 Report the alignment this system needs for SIMD allocations. More...
 
voidSDL_SIMDAlloc (const size_t len)
 Allocate memory in a SIMD-friendly way. More...
 
voidSDL_SIMDRealloc (void *mem, const size_t len)
 Reallocate memory obtained from SDL_SIMDAlloc. More...
 
void SDL_SIMDFree (void *ptr)
 Deallocate memory obtained from SDL_SIMDAlloc. More...
 

Variables

static int CPU_CPUIDFeatures [4]
 
static int CPU_CPUIDMaxFunction = 0
 
static SDL_bool CPU_OSSavesYMM = SDL_FALSE
 
static SDL_bool CPU_OSSavesZMM = SDL_FALSE
 
static int SDL_CPUCount = 0
 
static Uint32 SDL_CPUFeatures = 0xFFFFFFFF
 
static Uint32 SDL_SIMDAlignment = 0xFFFFFFFF
 
static int SDL_SystemRAM = 0
 

Macro Definition Documentation

◆ CPU_FEATURE_AVAILABLE

#define CPU_FEATURE_AVAILABLE (   f)    ((SDL_GetCPUFeatures() & f) ? SDL_TRUE : SDL_FALSE)

Definition at line 798 of file SDL_cpuinfo.c.

◆ CPU_HAS_3DNOW

#define CPU_HAS_3DNOW   (1 << 3)

Definition at line 106 of file SDL_cpuinfo.c.

◆ CPU_HAS_ALTIVEC

#define CPU_HAS_ALTIVEC   (1 << 1)

Definition at line 104 of file SDL_cpuinfo.c.

◆ CPU_HAS_ARM_SIMD

#define CPU_HAS_ARM_SIMD   (1 << 13)

Definition at line 116 of file SDL_cpuinfo.c.

◆ CPU_HAS_AVX

#define CPU_HAS_AVX   (1 << 9)

Definition at line 112 of file SDL_cpuinfo.c.

◆ CPU_HAS_AVX2

#define CPU_HAS_AVX2   (1 << 10)

Definition at line 113 of file SDL_cpuinfo.c.

◆ CPU_HAS_AVX512F

#define CPU_HAS_AVX512F   (1 << 12)

Definition at line 115 of file SDL_cpuinfo.c.

◆ CPU_HAS_MMX

#define CPU_HAS_MMX   (1 << 2)

Definition at line 105 of file SDL_cpuinfo.c.

◆ CPU_HAS_NEON

#define CPU_HAS_NEON   (1 << 11)

Definition at line 114 of file SDL_cpuinfo.c.

◆ CPU_HAS_RDTSC

#define CPU_HAS_RDTSC   (1 << 0)

Definition at line 103 of file SDL_cpuinfo.c.

◆ CPU_HAS_SSE

#define CPU_HAS_SSE   (1 << 4)

Definition at line 107 of file SDL_cpuinfo.c.

◆ CPU_HAS_SSE2

#define CPU_HAS_SSE2   (1 << 5)

Definition at line 108 of file SDL_cpuinfo.c.

◆ CPU_HAS_SSE3

#define CPU_HAS_SSE3   (1 << 6)

Definition at line 109 of file SDL_cpuinfo.c.

◆ CPU_HAS_SSE41

#define CPU_HAS_SSE41   (1 << 7)

Definition at line 110 of file SDL_cpuinfo.c.

◆ CPU_HAS_SSE42

#define CPU_HAS_SSE42   (1 << 8)

Definition at line 111 of file SDL_cpuinfo.c.

◆ CPU_haveAVX

#define CPU_haveAVX ( )    (CPU_OSSavesYMM && (CPU_CPUIDFeatures[2] & 0x10000000))

Definition at line 533 of file SDL_cpuinfo.c.

◆ CPU_haveMMX

#define CPU_haveMMX ( )    (CPU_CPUIDFeatures[3] & 0x00800000)

Definition at line 527 of file SDL_cpuinfo.c.

◆ CPU_haveRDTSC

#define CPU_haveRDTSC ( )    (CPU_CPUIDFeatures[3] & 0x00000010)

Definition at line 526 of file SDL_cpuinfo.c.

◆ CPU_haveSSE

#define CPU_haveSSE ( )    (CPU_CPUIDFeatures[3] & 0x02000000)

Definition at line 528 of file SDL_cpuinfo.c.

◆ CPU_haveSSE2

#define CPU_haveSSE2 ( )    (CPU_CPUIDFeatures[3] & 0x04000000)

Definition at line 529 of file SDL_cpuinfo.c.

◆ CPU_haveSSE3

#define CPU_haveSSE3 ( )    (CPU_CPUIDFeatures[2] & 0x00000001)

Definition at line 530 of file SDL_cpuinfo.c.

◆ CPU_haveSSE41

#define CPU_haveSSE41 ( )    (CPU_CPUIDFeatures[2] & 0x00080000)

Definition at line 531 of file SDL_cpuinfo.c.

◆ CPU_haveSSE42

#define CPU_haveSSE42 ( )    (CPU_CPUIDFeatures[2] & 0x00100000)

Definition at line 532 of file SDL_cpuinfo.c.

◆ cpuid

#define cpuid (   func,
  a,
  b,
  c,
  d 
)     do { a = b = c = d = 0; (void) a; (void) b; (void) c; (void) d; } while (0)

Definition at line 268 of file SDL_cpuinfo.c.

Function Documentation

◆ CPU_calcCPUIDFeatures()

static void CPU_calcCPUIDFeatures ( void  )
static

Definition at line 278 of file SDL_cpuinfo.c.

279 {
280  static SDL_bool checked = SDL_FALSE;
281  if (!checked) {
282  checked = SDL_TRUE;
283  if (CPU_haveCPUID()) {
284  int a, b, c, d;
285  cpuid(0, a, b, c, d);
287  if (CPU_CPUIDMaxFunction >= 1) {
288  cpuid(1, a, b, c, d);
289  CPU_CPUIDFeatures[0] = a;
290  CPU_CPUIDFeatures[1] = b;
291  CPU_CPUIDFeatures[2] = c;
292  CPU_CPUIDFeatures[3] = d;
293 
294  /* Check to make sure we can call xgetbv */
295  if (c & 0x08000000) {
296  /* Call xgetbv to see if YMM (etc) register state is saved */
297 #if defined(__GNUC__) && (defined(i386) || defined(__x86_64__))
298  __asm__(".byte 0x0f, 0x01, 0xd0" : "=a" (a) : "c" (0) : "%edx");
299 #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) && (_MSC_FULL_VER >= 160040219) /* VS2010 SP1 */
300  a = (int)_xgetbv(0);
301 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
302  __asm
303  {
304  xor ecx, ecx
305  _asm _emit 0x0f _asm _emit 0x01 _asm _emit 0xd0
306  mov a, eax
307  }
308 #endif
309  CPU_OSSavesYMM = ((a & 6) == 6) ? SDL_TRUE : SDL_FALSE;
310  CPU_OSSavesZMM = (CPU_OSSavesYMM && ((a & 0xe0) == 0xe0)) ? SDL_TRUE : SDL_FALSE;
311  }
312  }
313  }
314  }
315 }
static SDL_bool CPU_OSSavesYMM
Definition: SDL_cpuinfo.c:274
#define cpuid(func, a, b, c, d)
Definition: SDL_cpuinfo.c:268
static SDL_bool CPU_OSSavesZMM
Definition: SDL_cpuinfo.c:275
static int CPU_CPUIDMaxFunction
Definition: SDL_cpuinfo.c:273
static int CPU_haveCPUID(void)
Definition: SDL_cpuinfo.c:131
static int CPU_CPUIDFeatures[4]
Definition: SDL_cpuinfo.c:272
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
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
const GLubyte * c
SDL_bool
Definition: SDL_stdinc.h:168
@ SDL_TRUE
Definition: SDL_stdinc.h:170
@ SDL_FALSE
Definition: SDL_stdinc.h:169
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF base if bpp PF set rept prefetch_distance PF set OFFSET endr endif endm macro preload_leading_step2 base if bpp ifc DST PF PF else if bpp lsl PF PF lsl PF PF lsl PF PF PF else PF mov
typedef int(__stdcall *FARPROC)()

References CPU_CPUIDFeatures, CPU_CPUIDMaxFunction, CPU_haveCPUID(), CPU_OSSavesYMM, CPU_OSSavesZMM, cpuid, d, int(), mov, SDL_FALSE, and SDL_TRUE.

Referenced by SDL_GetCPUFeatures(), and SDL_GetCPUType().

◆ CPU_have3DNow()

static int CPU_have3DNow ( void  )
static

Definition at line 513 of file SDL_cpuinfo.c.

514 {
515  if (CPU_CPUIDMaxFunction > 0) { /* that is, do we have CPUID at all? */
516  int a, b, c, d;
517  cpuid(0x80000000, a, b, c, d);
518  if (a >= 0x80000001) {
519  cpuid(0x80000001, a, b, c, d);
520  return (d & 0x80000000);
521  }
522  }
523  return 0;
524 }

References CPU_CPUIDMaxFunction, cpuid, and d.

Referenced by SDL_GetCPUFeatures().

◆ CPU_haveAltiVec()

static int CPU_haveAltiVec ( void  )
static

Definition at line 318 of file SDL_cpuinfo.c.

319 {
320  volatile int altivec = 0;
321 #ifndef SDL_CPUINFO_DISABLED
322 #if (defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))) || (defined(__OpenBSD__) && defined(__powerpc__)) || (defined(__FreeBSD__) && defined(__powerpc__))
323 #ifdef __OpenBSD__
324  int selectors[2] = { CTL_MACHDEP, CPU_ALTIVEC };
325 #elif defined(__FreeBSD__)
326  int selectors[2] = { CTL_HW, PPC_FEATURE_HAS_ALTIVEC };
327 #else
328  int selectors[2] = { CTL_HW, HW_VECTORUNIT };
329 #endif
330  int hasVectorUnit = 0;
331  size_t length = sizeof(hasVectorUnit);
332  int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0);
333  if (0 == error)
334  altivec = (hasVectorUnit != 0);
335 #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
336  void (*handler) (int sig);
337  handler = signal(SIGILL, illegal_instruction);
338  if (setjmp(jmpbuf) == 0) {
339  asm volatile ("mtspr 256, %0\n\t" "vand %%v0, %%v0, %%v0"::"r" (-1));
340  altivec = 1;
341  }
342  signal(SIGILL, handler);
343 #endif
344 #endif
345  return altivec;
346 }
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
#define NULL
Definition: begin_code.h:163

References NULL, and void.

Referenced by SDL_GetCPUFeatures().

◆ CPU_haveARMSIMD()

static int CPU_haveARMSIMD ( void  )
static

Definition at line 357 of file SDL_cpuinfo.c.

358 {
359  return 0;
360 }

Referenced by SDL_GetCPUFeatures().

◆ CPU_haveAVX2()

static int CPU_haveAVX2 ( void  )
static

Definition at line 536 of file SDL_cpuinfo.c.

537 {
538  if (CPU_OSSavesYMM && (CPU_CPUIDMaxFunction >= 7)) {
539  int a, b, c, d;
540  (void) a; (void) b; (void) c; (void) d; /* compiler warnings... */
541  cpuid(7, a, b, c, d);
542  return (b & 0x00000020);
543  }
544  return 0;
545 }

References CPU_CPUIDMaxFunction, CPU_OSSavesYMM, cpuid, d, and void.

Referenced by SDL_GetCPUFeatures().

◆ CPU_haveAVX512F()

static int CPU_haveAVX512F ( void  )
static

Definition at line 548 of file SDL_cpuinfo.c.

549 {
550  if (CPU_OSSavesZMM && (CPU_CPUIDMaxFunction >= 7)) {
551  int a, b, c, d;
552  (void) a; (void) b; (void) c; (void) d; /* compiler warnings... */
553  cpuid(7, a, b, c, d);
554  return (b & 0x00010000);
555  }
556  return 0;
557 }

References CPU_CPUIDMaxFunction, CPU_OSSavesZMM, cpuid, d, and void.

Referenced by SDL_GetCPUFeatures().

◆ CPU_haveCPUID()

static int CPU_haveCPUID ( void  )
static

Definition at line 131 of file SDL_cpuinfo.c.

132 {
133  int has_CPUID = 0;
134 
135 /* *INDENT-OFF* */
136 #ifndef SDL_CPUINFO_DISABLED
137 #if defined(__GNUC__) && defined(i386)
138  __asm__ (
139 " pushfl # Get original EFLAGS \n"
140 " popl %%eax \n"
141 " movl %%eax,%%ecx \n"
142 " xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n"
143 " pushl %%eax # Save new EFLAGS value on stack \n"
144 " popfl # Replace current EFLAGS value \n"
145 " pushfl # Get new EFLAGS \n"
146 " popl %%eax # Store new EFLAGS in EAX \n"
147 " xorl %%ecx,%%eax # Can not toggle ID bit, \n"
148 " jz 1f # Processor=80486 \n"
149 " movl $1,%0 # We have CPUID support \n"
150 "1: \n"
151  : "=m" (has_CPUID)
152  :
153  : "%eax", "%ecx"
154  );
155 #elif defined(__GNUC__) && defined(__x86_64__)
156 /* Technically, if this is being compiled under __x86_64__ then it has
157  CPUid by definition. But it's nice to be able to prove it. :) */
158  __asm__ (
159 " pushfq # Get original EFLAGS \n"
160 " popq %%rax \n"
161 " movq %%rax,%%rcx \n"
162 " xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n"
163 " pushq %%rax # Save new EFLAGS value on stack \n"
164 " popfq # Replace current EFLAGS value \n"
165 " pushfq # Get new EFLAGS \n"
166 " popq %%rax # Store new EFLAGS in EAX \n"
167 " xorl %%ecx,%%eax # Can not toggle ID bit, \n"
168 " jz 1f # Processor=80486 \n"
169 " movl $1,%0 # We have CPUID support \n"
170 "1: \n"
171  : "=m" (has_CPUID)
172  :
173  : "%rax", "%rcx"
174  );
175 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
176  __asm {
177  pushfd ; Get original EFLAGS
178  pop eax
179  mov ecx, eax
180  xor eax, 200000h ; Flip ID bit in EFLAGS
181  push eax ; Save new EFLAGS value on stack
182  popfd ; Replace current EFLAGS value
183  pushfd ; Get new EFLAGS
184  pop eax ; Store new EFLAGS in EAX
185  xor eax, ecx ; Can not toggle ID bit,
186  jz done ; Processor=80486
187  mov has_CPUID,1 ; We have CPUID support
188 done:
189  }
190 #elif defined(_MSC_VER) && defined(_M_X64)
191  has_CPUID = 1;
192 #elif defined(__sun) && defined(__i386)
193  __asm (
194 " pushfl \n"
195 " popl %eax \n"
196 " movl %eax,%ecx \n"
197 " xorl $0x200000,%eax \n"
198 " pushl %eax \n"
199 " popfl \n"
200 " pushfl \n"
201 " popl %eax \n"
202 " xorl %ecx,%eax \n"
203 " jz 1f \n"
204 " movl $1,-8(%ebp) \n"
205 "1: \n"
206  );
207 #elif defined(__sun) && defined(__amd64)
208  __asm (
209 " pushfq \n"
210 " popq %rax \n"
211 " movq %rax,%rcx \n"
212 " xorl $0x200000,%eax \n"
213 " pushq %rax \n"
214 " popfq \n"
215 " pushfq \n"
216 " popq %rax \n"
217 " xorl %ecx,%eax \n"
218 " jz 1f \n"
219 " movl $1,-8(%rbp) \n"
220 "1: \n"
221  );
222 #endif
223 #endif
224 /* *INDENT-ON* */
225  return has_CPUID;
226 }
GLuint in
GLsizei const GLfloat * value
GLfloat GLfloat GLfloat GLfloat h
#define pop
Definition: SDL_qsort.c:195
int done
Definition: checkkeys.c:28

References done, mov, and pop.

Referenced by CPU_calcCPUIDFeatures().

◆ CPU_haveNEON()

static int CPU_haveNEON ( void  )
static

Definition at line 446 of file SDL_cpuinfo.c.

447 {
448 /* The way you detect NEON is a privileged instruction on ARM, so you have
449  query the OS kernel in a platform-specific way. :/ */
450 #if defined(SDL_CPUINFO_DISABLED)
451  return 0; /* disabled */
452 #elif (defined(__WINDOWS__) || defined(__WINRT__)) && (defined(_M_ARM) || defined(_M_ARM64))
453 /* Visual Studio, for ARM, doesn't define __ARM_ARCH. Handle this first. */
454 /* Seems to have been removed */
455 # if !defined(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE)
456 # define PF_ARM_NEON_INSTRUCTIONS_AVAILABLE 19
457 # endif
458 /* All WinRT ARM devices are required to support NEON, but just in case. */
459  return IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE) != 0;
460 #elif defined(__ARM_ARCH) && (__ARM_ARCH >= 8)
461  return 1; /* ARMv8 always has non-optional NEON support. */
462 #elif defined(__APPLE__) && defined(__ARM_ARCH) && (__ARM_ARCH >= 7)
463  /* (note that sysctlbyname("hw.optional.neon") doesn't work!) */
464  return 1; /* all Apple ARMv7 chips and later have NEON. */
465 #elif defined(__APPLE__)
466  return 0; /* assume anything else from Apple doesn't have NEON. */
467 #elif defined(__OpenBSD__)
468  return 1; /* OpenBSD only supports ARMv7 CPUs that have NEON. */
469 #elif defined(HAVE_ELF_AUX_INFO) && defined(HWCAP_NEON)
470  unsigned long hasneon = 0;
471  if (elf_aux_info(AT_HWCAP, (void *)&hasneon, (int)sizeof(hasneon)) != 0)
472  return 0;
473  return ((hasneon & HWCAP_NEON) == HWCAP_NEON);
474 #elif !defined(__arm__)
475  return 0; /* not an ARM CPU at all. */
476 #elif defined(__QNXNTO__)
477  return SYSPAGE_ENTRY(cpuinfo)->flags & ARM_CPU_FLAG_NEON;
478 #elif (defined(__LINUX__) || defined(__ANDROID__)) && defined(HAVE_GETAUXVAL)
479  return ((getauxval(AT_HWCAP) & HWCAP_NEON) == HWCAP_NEON);
480 #elif defined(__LINUX__)
481  return readProcAuxvForNeon();
482 #elif defined(__ANDROID__)
483  /* Use NDK cpufeatures to read either /proc/self/auxv or /proc/cpuinfo */
484  {
485  AndroidCpuFamily cpu_family = android_getCpuFamily();
486  if (cpu_family == ANDROID_CPU_FAMILY_ARM) {
487  uint64_t cpu_features = android_getCpuFeatures();
488  if ((cpu_features & ANDROID_CPU_ARM_FEATURE_NEON) != 0) {
489  return 1;
490  }
491  }
492  return 0;
493  }
494 #elif defined(__RISCOS__)
495  /* Use the VFPSupport_Features SWI to access the MVFR registers */
496  {
497  _kernel_swi_regs regs;
498  regs.r[0] = 0;
499  if (_kernel_swi(VFPSupport_Features, &regs, &regs) == NULL) {
500  if ((regs.r[2] & 0xFFF000) == 0x111000) {
501  return 1;
502  }
503  }
504  return 0;
505  }
506 #else
507 #warning SDL_HasNEON is not implemented for this ARM platform. Write me.
508  return 0;
509 #endif
510 }
unsigned long long uint64_t

References NULL.

Referenced by SDL_GetCPUFeatures().

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

713 {
714  const char *cpuType = SDL_GetCPUType();
715  int a, b, c, d;
716  (void) a; (void) b; (void) c; (void) d;
717  if (SDL_strcmp(cpuType, "GenuineIntel") == 0 || SDL_strcmp(cpuType, "CentaurHauls") == 0 || SDL_strcmp(cpuType, " Shanghai ") == 0) {
718  cpuid(0x00000001, a, b, c, d);
719  return (((b >> 8) & 0xff) * 8);
720  } else if (SDL_strcmp(cpuType, "AuthenticAMD") == 0 || SDL_strcmp(cpuType, "HygonGenuine") == 0) {
721  cpuid(0x80000005, a, b, c, d);
722  return (c & 0xff);
723  } else {
724  /* Just make a guess here... */
725  return SDL_CACHELINE_SIZE;
726  }
727 }
static const char * SDL_GetCPUType(void)
Definition: SDL_cpuinfo.c:601
#define SDL_CACHELINE_SIZE
Definition: SDL_cpuinfo.h:114
#define SDL_strcmp

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

◆ SDL_GetCPUCount()

int SDL_GetCPUCount ( void  )

This function returns the number of CPU cores available.

Definition at line 562 of file SDL_cpuinfo.c.

563 {
564  if (!SDL_CPUCount) {
565 #ifndef SDL_CPUINFO_DISABLED
566 #if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
567  if (SDL_CPUCount <= 0) {
568  SDL_CPUCount = (int)sysconf(_SC_NPROCESSORS_ONLN);
569  }
570 #endif
571 #ifdef HAVE_SYSCTLBYNAME
572  if (SDL_CPUCount <= 0) {
573  size_t size = sizeof(SDL_CPUCount);
574  sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0);
575  }
576 #endif
577 #ifdef __WIN32__
578  if (SDL_CPUCount <= 0) {
579  SYSTEM_INFO info;
580  GetSystemInfo(&info);
581  SDL_CPUCount = info.dwNumberOfProcessors;
582  }
583 #endif
584 #ifdef __OS2__
585  if (SDL_CPUCount <= 0) {
586  DosQuerySysInfo(QSV_NUMPROCESSORS, QSV_NUMPROCESSORS,
587  &SDL_CPUCount, sizeof(SDL_CPUCount) );
588  }
589 #endif
590 #endif
591  /* There has to be at least 1, right? :) */
592  if (SDL_CPUCount <= 0) {
593  SDL_CPUCount = 1;
594  }
595  }
596  return SDL_CPUCount;
597 }
static int SDL_CPUCount
Definition: SDL_cpuinfo.c:559
GLsizeiptr size

References int(), NULL, and SDL_CPUCount.

◆ SDL_GetCPUFeatures()

static Uint32 SDL_GetCPUFeatures ( void  )
static

Definition at line 733 of file SDL_cpuinfo.c.

734 {
735  if (SDL_CPUFeatures == 0xFFFFFFFF) {
737  SDL_CPUFeatures = 0;
738  SDL_SIMDAlignment = sizeof(void *); /* a good safe base value */
739  if (CPU_haveRDTSC()) {
741  }
742  if (CPU_haveAltiVec()) {
745  }
746  if (CPU_haveMMX()) {
749  }
750  if (CPU_have3DNow()) {
753  }
754  if (CPU_haveSSE()) {
757  }
758  if (CPU_haveSSE2()) {
761  }
762  if (CPU_haveSSE3()) {
765  }
766  if (CPU_haveSSE41()) {
769  }
770  if (CPU_haveSSE42()) {
773  }
774  if (CPU_haveAVX()) {
777  }
778  if (CPU_haveAVX2()) {
781  }
782  if (CPU_haveAVX512F()) {
785  }
786  if (CPU_haveARMSIMD()) {
789  }
790  if (CPU_haveNEON()) {
793  }
794  }
795  return SDL_CPUFeatures;
796 }
#define CPU_HAS_ARM_SIMD
Definition: SDL_cpuinfo.c:116
static int CPU_haveAVX512F(void)
Definition: SDL_cpuinfo.c:548
#define CPU_haveSSE3()
Definition: SDL_cpuinfo.c:530
#define CPU_HAS_SSE42
Definition: SDL_cpuinfo.c:111
static Uint32 SDL_SIMDAlignment
Definition: SDL_cpuinfo.c:730
#define CPU_haveSSE41()
Definition: SDL_cpuinfo.c:531
#define CPU_HAS_SSE3
Definition: SDL_cpuinfo.c:109
#define CPU_HAS_MMX
Definition: SDL_cpuinfo.c:105
#define CPU_haveSSE42()
Definition: SDL_cpuinfo.c:532
#define CPU_HAS_SSE2
Definition: SDL_cpuinfo.c:108
#define CPU_haveSSE()
Definition: SDL_cpuinfo.c:528
static Uint32 SDL_CPUFeatures
Definition: SDL_cpuinfo.c:729
#define CPU_HAS_SSE
Definition: SDL_cpuinfo.c:107
#define CPU_HAS_SSE41
Definition: SDL_cpuinfo.c:110
static int CPU_have3DNow(void)
Definition: SDL_cpuinfo.c:513
#define CPU_haveAVX()
Definition: SDL_cpuinfo.c:533
static int CPU_haveAVX2(void)
Definition: SDL_cpuinfo.c:536
#define CPU_HAS_AVX2
Definition: SDL_cpuinfo.c:113
#define CPU_HAS_ALTIVEC
Definition: SDL_cpuinfo.c:104
#define CPU_HAS_RDTSC
Definition: SDL_cpuinfo.c:103
static void CPU_calcCPUIDFeatures(void)
Definition: SDL_cpuinfo.c:278
#define CPU_HAS_NEON
Definition: SDL_cpuinfo.c:114
#define CPU_haveMMX()
Definition: SDL_cpuinfo.c:527
#define CPU_haveSSE2()
Definition: SDL_cpuinfo.c:529
#define CPU_haveRDTSC()
Definition: SDL_cpuinfo.c:526
#define CPU_HAS_AVX
Definition: SDL_cpuinfo.c:112
static int CPU_haveAltiVec(void)
Definition: SDL_cpuinfo.c:318
#define CPU_HAS_AVX512F
Definition: SDL_cpuinfo.c:115
static int CPU_haveNEON(void)
Definition: SDL_cpuinfo.c:446
static int CPU_haveARMSIMD(void)
Definition: SDL_cpuinfo.c:357
#define CPU_HAS_3DNOW
Definition: SDL_cpuinfo.c:106
#define SDL_max(x, y)
Definition: SDL_stdinc.h:413

References CPU_calcCPUIDFeatures(), CPU_HAS_3DNOW, CPU_HAS_ALTIVEC, CPU_HAS_ARM_SIMD, CPU_HAS_AVX, CPU_HAS_AVX2, CPU_HAS_AVX512F, CPU_HAS_MMX, CPU_HAS_NEON, CPU_HAS_RDTSC, CPU_HAS_SSE, CPU_HAS_SSE2, CPU_HAS_SSE3, CPU_HAS_SSE41, CPU_HAS_SSE42, CPU_have3DNow(), CPU_haveAltiVec(), CPU_haveARMSIMD(), CPU_haveAVX, CPU_haveAVX2(), CPU_haveAVX512F(), CPU_haveMMX, CPU_haveNEON(), CPU_haveRDTSC, CPU_haveSSE, CPU_haveSSE2, CPU_haveSSE3, CPU_haveSSE41, CPU_haveSSE42, SDL_CPUFeatures, SDL_max, and SDL_SIMDAlignment.

Referenced by SDL_SIMDGetAlignment().

◆ SDL_GetCPUType()

static const char* SDL_GetCPUType ( void  )
static

Definition at line 601 of file SDL_cpuinfo.c.

602 {
603  static char SDL_CPUType[13];
604 
605  if (!SDL_CPUType[0]) {
606  int i = 0;
607 
609  if (CPU_CPUIDMaxFunction > 0) { /* do we have CPUID at all? */
610  int a, b, c, d;
611  cpuid(0x00000000, a, b, c, d);
612  (void) a;
613  SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
614  SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
615  SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
616  SDL_CPUType[i++] = (char)(b & 0xff);
617 
618  SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
619  SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
620  SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
621  SDL_CPUType[i++] = (char)(d & 0xff);
622 
623  SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
624  SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
625  SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
626  SDL_CPUType[i++] = (char)(c & 0xff);
627  }
628  if (!SDL_CPUType[0]) {
629  SDL_strlcpy(SDL_CPUType, "Unknown", sizeof(SDL_CPUType));
630  }
631  }
632  return SDL_CPUType;
633 }
#define SDL_strlcpy
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

References CPU_calcCPUIDFeatures(), CPU_CPUIDMaxFunction, cpuid, d, i, SDL_strlcpy, and void.

Referenced by SDL_GetCPUCacheLineSize().

◆ SDL_GetSystemRAM()

int SDL_GetSystemRAM ( void  )

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

Definition at line 886 of file SDL_cpuinfo.c.

887 {
888  if (!SDL_SystemRAM) {
889 #ifndef SDL_CPUINFO_DISABLED
890 #if defined(HAVE_SYSCONF) && defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE)
891  if (SDL_SystemRAM <= 0) {
892  SDL_SystemRAM = (int)((Sint64)sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE) / (1024*1024));
893  }
894 #endif
895 #ifdef HAVE_SYSCTLBYNAME
896  if (SDL_SystemRAM <= 0) {
897 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__DragonFly__)
898 #ifdef HW_REALMEM
899  int mib[2] = {CTL_HW, HW_REALMEM};
900 #else
901  /* might only report up to 2 GiB */
902  int mib[2] = {CTL_HW, HW_PHYSMEM};
903 #endif /* HW_REALMEM */
904 #else
905  int mib[2] = {CTL_HW, HW_MEMSIZE};
906 #endif /* __FreeBSD__ || __FreeBSD_kernel__ */
907  Uint64 memsize = 0;
908  size_t len = sizeof(memsize);
909 
910  if (sysctl(mib, 2, &memsize, &len, NULL, 0) == 0) {
911  SDL_SystemRAM = (int)(memsize / (1024*1024));
912  }
913  }
914 #endif
915 #ifdef __WIN32__
916  if (SDL_SystemRAM <= 0) {
917  MEMORYSTATUSEX stat;
918  stat.dwLength = sizeof(stat);
919  if (GlobalMemoryStatusEx(&stat)) {
920  SDL_SystemRAM = (int)(stat.ullTotalPhys / (1024 * 1024));
921  }
922  }
923 #endif
924 #ifdef __OS2__
925  if (SDL_SystemRAM <= 0) {
926  Uint32 sysram = 0;
927  DosQuerySysInfo(QSV_TOTPHYSMEM, QSV_TOTPHYSMEM, &sysram, 4);
928  SDL_SystemRAM = (int) (sysram / 0x100000U);
929  }
930 #endif
931 #ifdef __RISCOS__
932  if (SDL_SystemRAM <= 0) {
933  _kernel_swi_regs regs;
934  regs.r[0] = 0x108;
935  if (_kernel_swi(OS_Memory, &regs, &regs) == NULL) {
936  SDL_SystemRAM = (int)(regs.r[1] * regs.r[2] / (1024 * 1024));
937  }
938  }
939 #endif
940 #endif
941  }
942  return SDL_SystemRAM;
943 }
static int SDL_SystemRAM
Definition: SDL_cpuinfo.c:883
GLenum GLsizei len
uint64_t Uint64
Definition: SDL_stdinc.h:222
uint32_t Uint32
Definition: SDL_stdinc.h:209
int64_t Sint64
Definition: SDL_stdinc.h:216

References int(), NULL, and SDL_SystemRAM.

◆ SDL_Has3DNow()

SDL_bool SDL_Has3DNow ( void  )

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

Definition at line 818 of file SDL_cpuinfo.c.

819 {
821 }
#define CPU_FEATURE_AVAILABLE(f)
Definition: SDL_cpuinfo.c:798

References CPU_FEATURE_AVAILABLE, and CPU_HAS_3DNOW.

◆ SDL_HasAltiVec()

SDL_bool SDL_HasAltiVec ( void  )

This function returns true if the CPU has AltiVec features.

Definition at line 806 of file SDL_cpuinfo.c.

807 {
809 }

References CPU_FEATURE_AVAILABLE, and CPU_HAS_ALTIVEC.

◆ SDL_HasARMSIMD()

SDL_bool SDL_HasARMSIMD ( void  )

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

Definition at line 872 of file SDL_cpuinfo.c.

873 {
875 }

References CPU_FEATURE_AVAILABLE, and CPU_HAS_ARM_SIMD.

◆ SDL_HasAVX()

SDL_bool SDL_HasAVX ( void  )

This function returns true if the CPU has AVX features.

Definition at line 854 of file SDL_cpuinfo.c.

855 {
857 }

References CPU_FEATURE_AVAILABLE, and CPU_HAS_AVX.

◆ SDL_HasAVX2()

SDL_bool SDL_HasAVX2 ( void  )

This function returns true if the CPU has AVX2 features.

Definition at line 860 of file SDL_cpuinfo.c.

861 {
863 }

References CPU_FEATURE_AVAILABLE, and CPU_HAS_AVX2.

◆ SDL_HasAVX512F()

SDL_bool SDL_HasAVX512F ( void  )

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

Definition at line 866 of file SDL_cpuinfo.c.

867 {
869 }

References CPU_FEATURE_AVAILABLE, and CPU_HAS_AVX512F.

◆ SDL_HasMMX()

SDL_bool SDL_HasMMX ( void  )

This function returns true if the CPU has MMX features.

Definition at line 812 of file SDL_cpuinfo.c.

813 {
815 }

References CPU_FEATURE_AVAILABLE, and CPU_HAS_MMX.

◆ SDL_HasNEON()

SDL_bool SDL_HasNEON ( void  )

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

Definition at line 878 of file SDL_cpuinfo.c.

879 {
881 }

References CPU_FEATURE_AVAILABLE, and CPU_HAS_NEON.

◆ SDL_HasRDTSC()

SDL_bool SDL_HasRDTSC ( void  )

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

Definition at line 800 of file SDL_cpuinfo.c.

801 {
803 }

References CPU_FEATURE_AVAILABLE, and CPU_HAS_RDTSC.

◆ SDL_HasSSE()

SDL_bool SDL_HasSSE ( void  )

This function returns true if the CPU has SSE features.

Definition at line 824 of file SDL_cpuinfo.c.

825 {
827 }

References CPU_FEATURE_AVAILABLE, and CPU_HAS_SSE.

◆ SDL_HasSSE2()

SDL_bool SDL_HasSSE2 ( void  )

This function returns true if the CPU has SSE2 features.

Definition at line 830 of file SDL_cpuinfo.c.

831 {
833 }

References CPU_FEATURE_AVAILABLE, and CPU_HAS_SSE2.

◆ SDL_HasSSE3()

SDL_bool SDL_HasSSE3 ( void  )

This function returns true if the CPU has SSE3 features.

Definition at line 836 of file SDL_cpuinfo.c.

837 {
839 }

References CPU_FEATURE_AVAILABLE, and CPU_HAS_SSE3.

◆ SDL_HasSSE41()

SDL_bool SDL_HasSSE41 ( void  )

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

Definition at line 842 of file SDL_cpuinfo.c.

843 {
845 }

References CPU_FEATURE_AVAILABLE, and CPU_HAS_SSE41.

◆ SDL_HasSSE42()

SDL_bool SDL_HasSSE42 ( void  )

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

Definition at line 848 of file SDL_cpuinfo.c.

849 {
851 }

References CPU_FEATURE_AVAILABLE, and CPU_HAS_SSE42.

◆ SDL_SIMDAlloc()

void* SDL_SIMDAlloc ( const size_t  len)

Allocate memory in a SIMD-friendly way.

This will allocate a block of memory that is suitable for use with SIMD instructions. Specifically, it will be properly aligned and padded for the system's supported vector instructions.

The memory returned will be padded such that it is safe to read or write an incomplete vector at the end of the memory block. This can be useful so you don't have to drop back to a scalar fallback at the end of your SIMD processing loop to deal with the final elements without overflowing the allocated buffer.

You must free this memory with SDL_FreeSIMD(), not free() or SDL_free() or delete[], etc.

Note that SDL will only deal with SIMD instruction sets it is aware of; for example, SDL 2.0.8 knows that SSE wants 16-byte vectors (SDL_HasSSE()), and AVX2 wants 32 bytes (SDL_HasAVX2()), but doesn't know that AVX-512 wants 64. To be clear: if you can't decide to use an instruction set with an SDL_Has*() function, don't use that instruction set with memory allocated through here.

SDL_AllocSIMD(0) will return a non-NULL pointer, assuming the system isn't out of memory.

Parameters
lenThe length, in bytes, of the block to allocated. The actual allocated block might be larger due to padding, etc.
Returns
Pointer to newly-allocated block, NULL if out of memory.
See also
SDL_SIMDAlignment
SDL_SIMDRealloc
SDL_SIMDFree

Definition at line 957 of file SDL_cpuinfo.c.

958 {
959  const size_t alignment = SDL_SIMDGetAlignment();
960  const size_t padding = alignment - (len % alignment);
961  const size_t padded = (padding != alignment) ? (len + padding) : len;
962  Uint8 *retval = NULL;
963  Uint8 *ptr = (Uint8 *) SDL_malloc(padded + alignment + sizeof (void *));
964  if (ptr) {
965  /* store the actual malloc pointer right before our aligned pointer. */
966  retval = ptr + sizeof (void *);
967  retval += alignment - (((size_t) retval) % alignment);
968  *(((void **) retval) - 1) = ptr;
969  }
970  return retval;
971 }
unsigned int size_t
size_t SDL_SIMDGetAlignment(void)
Report the alignment this system needs for SIMD allocations.
Definition: SDL_cpuinfo.c:947
#define SDL_malloc
uint8_t Uint8
Definition: SDL_stdinc.h:185
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF ptr
SDL_bool retval

References NULL, ptr, retval, SDL_malloc, and SDL_SIMDGetAlignment().

◆ SDL_SIMDFree()

void SDL_SIMDFree ( void ptr)

Deallocate memory obtained from SDL_SIMDAlloc.

It is not valid to use this function on a pointer from anything but SDL_SIMDAlloc(). It can't be used on pointers from malloc, realloc, SDL_malloc, memalign, new[], etc.

However, SDL_SIMDFree(NULL) is a legal no-op.

See also
SDL_SIMDAlloc
SDL_SIMDRealloc

Definition at line 1026 of file SDL_cpuinfo.c.

1027 {
1028  if (ptr) {
1029  void **realptr = (void **) ptr;
1030  realptr--;
1031  SDL_free(*(((void **) ptr) - 1));
1032  }
1033 }
#define SDL_free

References ptr, and SDL_free.

◆ SDL_SIMDGetAlignment()

size_t SDL_SIMDGetAlignment ( void  )

Report the alignment this system needs for SIMD allocations.

This will return the minimum number of bytes to which a pointer must be aligned to be compatible with SIMD instructions on the current machine. For example, if the machine supports SSE only, it will return 16, but if it supports AVX-512F, it'll return 64 (etc). This only reports values for instruction sets SDL knows about, so if your SDL build doesn't have SDL_HasAVX512F(), then it might return 16 for the SSE support it sees and not 64 for the AVX-512 instructions that exist but SDL doesn't know about. Plan accordingly.

Definition at line 947 of file SDL_cpuinfo.c.

948 {
949  if (SDL_SIMDAlignment == 0xFFFFFFFF) {
950  SDL_GetCPUFeatures(); /* make sure this has been calculated */
951  }
953  return SDL_SIMDAlignment;
954 }
#define SDL_assert(condition)
Definition: SDL_assert.h:171
static Uint32 SDL_GetCPUFeatures(void)
Definition: SDL_cpuinfo.c:733

References SDL_assert, SDL_GetCPUFeatures(), and SDL_SIMDAlignment.

Referenced by SDL_SIMDAlloc(), and SDL_SIMDRealloc().

◆ SDL_SIMDRealloc()

void* SDL_SIMDRealloc ( void mem,
const size_t  len 
)

Reallocate memory obtained from SDL_SIMDAlloc.

It is not valid to use this function on a pointer from anything but SDL_SIMDAlloc(). It can't be used on pointers from malloc, realloc, SDL_malloc, memalign, new[], etc.

Parameters
memThe pointer obtained from SDL_SIMDAlloc. This function also accepts NULL, at which point this function is the same as calling SDL_realloc with a NULL pointer.
lenThe length, in bytes, of the block to allocated. The actual allocated block might be larger due to padding, etc. Passing 0 will return a non-NULL pointer, assuming the system isn't out of memory.
Returns
Pointer to newly-reallocated block, NULL if out of memory.
See also
SDL_SIMDAlignment
SDL_SIMDAlloc
SDL_SIMDFree

Definition at line 974 of file SDL_cpuinfo.c.

975 {
976  const size_t alignment = SDL_SIMDGetAlignment();
977  const size_t padding = alignment - (len % alignment);
978  const size_t padded = (padding != alignment) ? (len + padding) : len;
979  Uint8 *retval = (Uint8*) mem;
980  void *oldmem = mem;
981  size_t memdiff = 0, ptrdiff;
982  Uint8 *ptr;
983 
984  if (mem) {
985  void **realptr = (void **) mem;
986  realptr--;
987  mem = *(((void **) mem) - 1);
988 
989  /* Check the delta between the real pointer and user pointer */
990  memdiff = ((size_t) oldmem) - ((size_t) mem);
991  }
992 
993  ptr = (Uint8 *) SDL_realloc(mem, padded + alignment + sizeof (void *));
994 
995  if (ptr == mem) {
996  return retval; /* Pointer didn't change, nothing to do */
997  }
998  if (ptr == NULL) {
999  return NULL; /* Out of memory, bail! */
1000  }
1001 
1002  /* Store the actual malloc pointer right before our aligned pointer. */
1003  retval = ptr + sizeof (void *);
1004  retval += alignment - (((size_t) retval) % alignment);
1005 
1006  /* Make sure the delta is the same! */
1007  if (mem) {
1008  ptrdiff = ((size_t) retval) - ((size_t) ptr);
1009  if (memdiff != ptrdiff) { /* Delta has changed, copy to new offset! */
1010  oldmem = (void*) (((size_t) ptr) + memdiff);
1011 
1012  /* Even though the data past the old `len` is undefined, this is the
1013  * only length value we have, and it guarantees that we copy all the
1014  * previous memory anyhow.
1015  */
1016  SDL_memmove(retval, oldmem, len);
1017  }
1018  }
1019 
1020  /* Actually store the malloc pointer, finally. */
1021  *(((void **) retval) - 1) = ptr;
1022  return retval;
1023 }
#define SDL_realloc
#define SDL_memmove

References NULL, ptr, retval, SDL_memmove, SDL_realloc, and SDL_SIMDGetAlignment().

Variable Documentation

◆ CPU_CPUIDFeatures

int CPU_CPUIDFeatures[4]
static

Definition at line 272 of file SDL_cpuinfo.c.

Referenced by CPU_calcCPUIDFeatures().

◆ CPU_CPUIDMaxFunction

int CPU_CPUIDMaxFunction = 0
static

◆ CPU_OSSavesYMM

SDL_bool CPU_OSSavesYMM = SDL_FALSE
static

Definition at line 274 of file SDL_cpuinfo.c.

Referenced by CPU_calcCPUIDFeatures(), and CPU_haveAVX2().

◆ CPU_OSSavesZMM

SDL_bool CPU_OSSavesZMM = SDL_FALSE
static

Definition at line 275 of file SDL_cpuinfo.c.

Referenced by CPU_calcCPUIDFeatures(), and CPU_haveAVX512F().

◆ SDL_CPUCount

int SDL_CPUCount = 0
static

Definition at line 559 of file SDL_cpuinfo.c.

Referenced by SDL_GetCPUCount().

◆ SDL_CPUFeatures

Uint32 SDL_CPUFeatures = 0xFFFFFFFF
static

Definition at line 729 of file SDL_cpuinfo.c.

Referenced by SDL_GetCPUFeatures().

◆ SDL_SIMDAlignment

Uint32 SDL_SIMDAlignment = 0xFFFFFFFF
static

Definition at line 730 of file SDL_cpuinfo.c.

Referenced by SDL_GetCPUFeatures(), and SDL_SIMDGetAlignment().

◆ SDL_SystemRAM

int SDL_SystemRAM = 0
static

Definition at line 883 of file SDL_cpuinfo.c.

Referenced by SDL_GetSystemRAM().