mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-09 03:16:26 +00:00
Update for SDL3 coding style (#6717)
I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base. In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted. The script I ran for the src directory is added as build-scripts/clang-format-src.sh This fixes: #6592 #6593 #6594
This commit is contained in:
@@ -26,7 +26,6 @@
|
||||
|
||||
/* CPU feature detection for SDL */
|
||||
|
||||
|
||||
#ifdef HAVE_SYSCONF
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
@@ -35,7 +34,7 @@
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
#if defined(__MACOS__) && (defined(__ppc__) || defined(__ppc64__))
|
||||
#include <sys/sysctl.h> /* For AltiVec check */
|
||||
#include <sys/sysctl.h> /* For AltiVec check */
|
||||
#elif defined(__OpenBSD__) && defined(__powerpc__)
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h> /* For AltiVec check */
|
||||
@@ -84,41 +83,39 @@
|
||||
#include <kernel.h>
|
||||
#endif
|
||||
|
||||
#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_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 CPU_HAS_LSX (1 << 14)
|
||||
#define CPU_HAS_LASX (1 << 15)
|
||||
#define CPU_HAS_LSX (1 << 14)
|
||||
#define CPU_HAS_LASX (1 << 15)
|
||||
|
||||
#define CPU_CFG2 0x2
|
||||
#define CPU_CFG2_LSX (1 << 6)
|
||||
#define CPU_CFG2_LASX (1 << 7)
|
||||
#define CPU_CFG2 0x2
|
||||
#define CPU_CFG2_LSX (1 << 6)
|
||||
#define CPU_CFG2_LASX (1 << 7)
|
||||
|
||||
#if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOS__ && !__OpenBSD__ && !__FreeBSD__
|
||||
/* This is the brute force way of detecting instruction sets...
|
||||
the idea is borrowed from the libmpeg2 library - thanks!
|
||||
*/
|
||||
static jmp_buf jmpbuf;
|
||||
static void
|
||||
illegal_instruction(int sig)
|
||||
static void illegal_instruction(int sig)
|
||||
{
|
||||
longjmp(jmpbuf, 1);
|
||||
}
|
||||
#endif /* HAVE_SETJMP */
|
||||
|
||||
static int
|
||||
CPU_haveCPUID(void)
|
||||
static int CPU_haveCPUID(void)
|
||||
{
|
||||
int has_CPUID = 0;
|
||||
|
||||
@@ -216,23 +213,25 @@ done:
|
||||
}
|
||||
|
||||
#if (defined(__GNUC__) || defined(__llvm__)) && defined(__i386__)
|
||||
#define cpuid(func, a, b, c, d) \
|
||||
__asm__ __volatile__ ( \
|
||||
" pushl %%ebx \n" \
|
||||
" xorl %%ecx,%%ecx \n" \
|
||||
" cpuid \n" \
|
||||
" movl %%ebx, %%esi \n" \
|
||||
" popl %%ebx \n" : \
|
||||
"=a" (a), "=S" (b), "=c" (c), "=d" (d) : "a" (func))
|
||||
#define cpuid(func, a, b, c, d) \
|
||||
__asm__ __volatile__( \
|
||||
" pushl %%ebx \n" \
|
||||
" xorl %%ecx,%%ecx \n" \
|
||||
" cpuid \n" \
|
||||
" movl %%ebx, %%esi \n" \
|
||||
" popl %%ebx \n" \
|
||||
: "=a"(a), "=S"(b), "=c"(c), "=d"(d) \
|
||||
: "a"(func))
|
||||
#elif (defined(__GNUC__) || defined(__llvm__)) && defined(__x86_64__)
|
||||
#define cpuid(func, a, b, c, d) \
|
||||
__asm__ __volatile__ ( \
|
||||
" pushq %%rbx \n" \
|
||||
" xorq %%rcx,%%rcx \n" \
|
||||
" cpuid \n" \
|
||||
" movq %%rbx, %%rsi \n" \
|
||||
" popq %%rbx \n" : \
|
||||
"=a" (a), "=S" (b), "=c" (c), "=d" (d) : "a" (func))
|
||||
#define cpuid(func, a, b, c, d) \
|
||||
__asm__ __volatile__( \
|
||||
" pushq %%rbx \n" \
|
||||
" xorq %%rcx,%%rcx \n" \
|
||||
" cpuid \n" \
|
||||
" movq %%rbx, %%rsi \n" \
|
||||
" popq %%rbx \n" \
|
||||
: "=a"(a), "=S"(b), "=c"(c), "=d"(d) \
|
||||
: "a"(func))
|
||||
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
|
||||
#define cpuid(func, a, b, c, d) \
|
||||
__asm { \
|
||||
@@ -242,21 +241,27 @@ done:
|
||||
__asm mov a, eax \
|
||||
__asm mov b, ebx \
|
||||
__asm mov c, ecx \
|
||||
__asm mov d, edx \
|
||||
}
|
||||
__asm mov d, edx \
|
||||
}
|
||||
#elif defined(_MSC_VER) && defined(_M_X64)
|
||||
#define cpuid(func, a, b, c, d) \
|
||||
{ \
|
||||
int CPUInfo[4]; \
|
||||
__cpuid(CPUInfo, func); \
|
||||
a = CPUInfo[0]; \
|
||||
b = CPUInfo[1]; \
|
||||
c = CPUInfo[2]; \
|
||||
d = CPUInfo[3]; \
|
||||
}
|
||||
{ \
|
||||
int CPUInfo[4]; \
|
||||
__cpuid(CPUInfo, func); \
|
||||
a = CPUInfo[0]; \
|
||||
b = CPUInfo[1]; \
|
||||
c = CPUInfo[2]; \
|
||||
d = CPUInfo[3]; \
|
||||
}
|
||||
#else
|
||||
#define cpuid(func, a, b, c, d) \
|
||||
do { a = b = c = d = 0; (void) a; (void) b; (void) c; (void) d; } while (0)
|
||||
do { \
|
||||
a = b = c = d = 0; \
|
||||
(void)a; \
|
||||
(void)b; \
|
||||
(void)c; \
|
||||
(void)d; \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
static int CPU_CPUIDFeatures[4];
|
||||
@@ -264,8 +269,7 @@ static int CPU_CPUIDMaxFunction = 0;
|
||||
static SDL_bool CPU_OSSavesYMM = SDL_FALSE;
|
||||
static SDL_bool CPU_OSSavesZMM = SDL_FALSE;
|
||||
|
||||
static void
|
||||
CPU_calcCPUIDFeatures(void)
|
||||
static void CPU_calcCPUIDFeatures(void)
|
||||
{
|
||||
static SDL_bool checked = SDL_FALSE;
|
||||
if (!checked) {
|
||||
@@ -285,16 +289,19 @@ CPU_calcCPUIDFeatures(void)
|
||||
if (c & 0x08000000) {
|
||||
/* Call xgetbv to see if YMM (etc) register state is saved */
|
||||
#if (defined(__GNUC__) || defined(__llvm__)) && (defined(__i386__) || defined(__x86_64__))
|
||||
__asm__(".byte 0x0f, 0x01, 0xd0" : "=a" (a) : "c" (0) : "%edx");
|
||||
__asm__(".byte 0x0f, 0x01, 0xd0"
|
||||
: "=a"(a)
|
||||
: "c"(0)
|
||||
: "%edx");
|
||||
#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) && (_MSC_FULL_VER >= 160040219) /* VS2010 SP1 */
|
||||
a = (int)_xgetbv(0);
|
||||
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
|
||||
__asm
|
||||
{
|
||||
{
|
||||
xor ecx, ecx
|
||||
_asm _emit 0x0f _asm _emit 0x01 _asm _emit 0xd0
|
||||
mov a, eax
|
||||
}
|
||||
}
|
||||
#endif
|
||||
CPU_OSSavesYMM = ((a & 6) == 6) ? SDL_TRUE : SDL_FALSE;
|
||||
CPU_OSSavesZMM = (CPU_OSSavesYMM && ((a & 0xe0) == 0xe0)) ? SDL_TRUE : SDL_FALSE;
|
||||
@@ -304,8 +311,7 @@ CPU_calcCPUIDFeatures(void)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
CPU_haveAltiVec(void)
|
||||
static int CPU_haveAltiVec(void)
|
||||
{
|
||||
volatile int altivec = 0;
|
||||
#ifndef SDL_CPUINFO_DISABLED
|
||||
@@ -327,10 +333,11 @@ CPU_haveAltiVec(void)
|
||||
altivec = cpufeatures & PPC_FEATURE_HAS_ALTIVEC;
|
||||
return altivec;
|
||||
#elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
|
||||
void (*handler) (int sig);
|
||||
void (*handler)(int sig);
|
||||
handler = signal(SIGILL, illegal_instruction);
|
||||
if (setjmp(jmpbuf) == 0) {
|
||||
asm volatile ("mtspr 256, %0\n\t" "vand %%v0, %%v0, %%v0"::"r" (-1));
|
||||
asm volatile("mtspr 256, %0\n\t"
|
||||
"vand %%v0, %%v0, %%v0" ::"r"(-1));
|
||||
altivec = 1;
|
||||
}
|
||||
signal(SIGILL, handler);
|
||||
@@ -340,22 +347,19 @@ CPU_haveAltiVec(void)
|
||||
}
|
||||
|
||||
#if (defined(__ARM_ARCH) && (__ARM_ARCH >= 6)) || defined(__aarch64__)
|
||||
static int
|
||||
CPU_haveARMSIMD(void)
|
||||
static int CPU_haveARMSIMD(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
#elif !defined(__arm__)
|
||||
static int
|
||||
CPU_haveARMSIMD(void)
|
||||
static int CPU_haveARMSIMD(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#elif defined(__LINUX__)
|
||||
static int
|
||||
CPU_haveARMSIMD(void)
|
||||
static int CPU_haveARMSIMD(void)
|
||||
{
|
||||
int arm_simd = 0;
|
||||
int fd;
|
||||
@@ -365,7 +369,7 @@ CPU_haveARMSIMD(void)
|
||||
Elf32_auxv_t aux;
|
||||
while (read(fd, &aux, sizeof aux) == sizeof aux) {
|
||||
if (aux.a_type == AT_PLATFORM) {
|
||||
const char *plat = (const char *) aux.a_un.a_val;
|
||||
const char *plat = (const char *)aux.a_un.a_val;
|
||||
if (plat) {
|
||||
arm_simd = SDL_strncmp(plat, "v6l", 3) == 0 ||
|
||||
SDL_strncmp(plat, "v7l", 3) == 0;
|
||||
@@ -378,8 +382,7 @@ CPU_haveARMSIMD(void)
|
||||
}
|
||||
|
||||
#elif defined(__RISCOS__)
|
||||
static int
|
||||
CPU_haveARMSIMD(void)
|
||||
static int CPU_haveARMSIMD(void)
|
||||
{
|
||||
_kernel_swi_regs regs;
|
||||
regs.r[0] = 0;
|
||||
@@ -401,8 +404,7 @@ CPU_haveARMSIMD(void)
|
||||
}
|
||||
|
||||
#else
|
||||
static int
|
||||
CPU_haveARMSIMD(void)
|
||||
static int CPU_haveARMSIMD(void)
|
||||
{
|
||||
#warning SDL_HasARMSIMD is not implemented for this ARM platform. Write me.
|
||||
return 0;
|
||||
@@ -410,8 +412,7 @@ CPU_haveARMSIMD(void)
|
||||
#endif
|
||||
|
||||
#if defined(__LINUX__) && defined(__arm__) && !defined(HAVE_GETAUXVAL)
|
||||
static int
|
||||
readProcAuxvForNeon(void)
|
||||
static int readProcAuxvForNeon(void)
|
||||
{
|
||||
int neon = 0;
|
||||
int fd;
|
||||
@@ -419,7 +420,7 @@ readProcAuxvForNeon(void)
|
||||
fd = open("/proc/self/auxv", O_RDONLY | O_CLOEXEC);
|
||||
if (fd >= 0) {
|
||||
Elf32_auxv_t aux;
|
||||
while (read(fd, &aux, sizeof (aux)) == sizeof (aux)) {
|
||||
while (read(fd, &aux, sizeof(aux)) == sizeof(aux)) {
|
||||
if (aux.a_type == AT_HWCAP) {
|
||||
neon = (aux.a_un.a_val & HWCAP_NEON) == HWCAP_NEON;
|
||||
break;
|
||||
@@ -431,36 +432,35 @@ readProcAuxvForNeon(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
CPU_haveNEON(void)
|
||||
static int CPU_haveNEON(void)
|
||||
{
|
||||
/* The way you detect NEON is a privileged instruction on ARM, so you have
|
||||
query the OS kernel in a platform-specific way. :/ */
|
||||
#if defined(SDL_CPUINFO_DISABLED)
|
||||
return 0; /* disabled */
|
||||
return 0; /* disabled */
|
||||
#elif (defined(__WINDOWS__) || defined(__WINRT__) || defined(__GDK__)) && (defined(_M_ARM) || defined(_M_ARM64))
|
||||
/* Visual Studio, for ARM, doesn't define __ARM_ARCH. Handle this first. */
|
||||
/* Seems to have been removed */
|
||||
# if !defined(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE)
|
||||
# define PF_ARM_NEON_INSTRUCTIONS_AVAILABLE 19
|
||||
# endif
|
||||
/* All WinRT ARM devices are required to support NEON, but just in case. */
|
||||
#if !defined(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE)
|
||||
#define PF_ARM_NEON_INSTRUCTIONS_AVAILABLE 19
|
||||
#endif
|
||||
/* All WinRT ARM devices are required to support NEON, but just in case. */
|
||||
return IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE) != 0;
|
||||
#elif (defined(__ARM_ARCH) && (__ARM_ARCH >= 8)) || defined(__aarch64__)
|
||||
return 1; /* ARMv8 always has non-optional NEON support. */
|
||||
return 1; /* ARMv8 always has non-optional NEON support. */
|
||||
#elif __VITA__
|
||||
return 1;
|
||||
#elif __3DS__
|
||||
return 0;
|
||||
#elif defined(__APPLE__) && defined(__ARM_ARCH) && (__ARM_ARCH >= 7)
|
||||
/* (note that sysctlbyname("hw.optional.neon") doesn't work!) */
|
||||
return 1; /* all Apple ARMv7 chips and later have NEON. */
|
||||
return 1; /* all Apple ARMv7 chips and later have NEON. */
|
||||
#elif defined(__APPLE__)
|
||||
return 0; /* assume anything else from Apple doesn't have NEON. */
|
||||
return 0; /* assume anything else from Apple doesn't have NEON. */
|
||||
#elif !defined(__arm__)
|
||||
return 0; /* not an ARM CPU at all. */
|
||||
return 0; /* not an ARM CPU at all. */
|
||||
#elif defined(__OpenBSD__)
|
||||
return 1; /* OpenBSD only supports ARMv7 CPUs that have NEON. */
|
||||
return 1; /* OpenBSD only supports ARMv7 CPUs that have NEON. */
|
||||
#elif defined(HAVE_ELF_AUX_INFO)
|
||||
unsigned long hasneon = 0;
|
||||
if (elf_aux_info(AT_HWCAP, (void *)&hasneon, (int)sizeof(hasneon)) != 0) {
|
||||
@@ -501,21 +501,19 @@ CPU_haveNEON(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
CPU_readCPUCFG(void)
|
||||
static int CPU_readCPUCFG(void)
|
||||
{
|
||||
uint32_t cfg2 = 0;
|
||||
#if defined __loongarch__
|
||||
__asm__ volatile(
|
||||
"cpucfg %0, %1 \n\t"
|
||||
: "+&r"(cfg2)
|
||||
: "r"(CPU_CFG2)
|
||||
);
|
||||
: "r"(CPU_CFG2));
|
||||
#endif
|
||||
return cfg2;
|
||||
}
|
||||
|
||||
#define CPU_haveLSX() (CPU_readCPUCFG() & CPU_CFG2_LSX)
|
||||
#define CPU_haveLSX() (CPU_readCPUCFG() & CPU_CFG2_LSX)
|
||||
#define CPU_haveLASX() (CPU_readCPUCFG() & CPU_CFG2_LASX)
|
||||
|
||||
#if defined(__e2k__)
|
||||
@@ -529,10 +527,9 @@ CPU_have3DNow(void)
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
static int
|
||||
CPU_have3DNow(void)
|
||||
static int CPU_have3DNow(void)
|
||||
{
|
||||
if (CPU_CPUIDMaxFunction > 0) { /* that is, do we have CPUID at all? */
|
||||
if (CPU_CPUIDMaxFunction > 0) { /* that is, do we have CPUID at all? */
|
||||
int a, b, c, d;
|
||||
cpuid(0x80000000, a, b, c, d);
|
||||
if (a >= 0x80000001) {
|
||||
@@ -583,13 +580,13 @@ CPU_have3DNow(void)
|
||||
#endif
|
||||
#else
|
||||
#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_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_haveAVX() (CPU_OSSavesYMM && (CPU_CPUIDFeatures[2] & 0x10000000))
|
||||
#endif
|
||||
|
||||
#if defined(__e2k__)
|
||||
@@ -603,12 +600,14 @@ CPU_haveAVX2(void)
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
static int
|
||||
CPU_haveAVX2(void)
|
||||
static int CPU_haveAVX2(void)
|
||||
{
|
||||
if (CPU_OSSavesYMM && (CPU_CPUIDMaxFunction >= 7)) {
|
||||
int a, b, c, d;
|
||||
(void) a; (void) b; (void) c; (void) d; /* compiler warnings... */
|
||||
(void)a;
|
||||
(void)b;
|
||||
(void)c;
|
||||
(void)d; /* compiler warnings... */
|
||||
cpuid(7, a, b, c, d);
|
||||
return b & 0x00000020;
|
||||
}
|
||||
@@ -623,12 +622,14 @@ CPU_haveAVX512F(void)
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
static int
|
||||
CPU_haveAVX512F(void)
|
||||
static int CPU_haveAVX512F(void)
|
||||
{
|
||||
if (CPU_OSSavesZMM && (CPU_CPUIDMaxFunction >= 7)) {
|
||||
int a, b, c, d;
|
||||
(void) a; (void) b; (void) c; (void) d; /* compiler warnings... */
|
||||
(void)a;
|
||||
(void)b;
|
||||
(void)c;
|
||||
(void)d; /* compiler warnings... */
|
||||
cpuid(7, a, b, c, d);
|
||||
return b & 0x00010000;
|
||||
}
|
||||
@@ -638,8 +639,7 @@ CPU_haveAVX512F(void)
|
||||
|
||||
static int SDL_CPUCount = 0;
|
||||
|
||||
int
|
||||
SDL_GetCPUCount(void)
|
||||
int SDL_GetCPUCount(void)
|
||||
{
|
||||
if (!SDL_CPUCount) {
|
||||
#ifndef SDL_CPUINFO_DISABLED
|
||||
@@ -682,8 +682,7 @@ SDL_GetCPUType(void)
|
||||
}
|
||||
#else
|
||||
/* Oh, such a sweet sweet trick, just not very useful. :) */
|
||||
static const char *
|
||||
SDL_GetCPUType(void)
|
||||
static const char *SDL_GetCPUType(void)
|
||||
{
|
||||
static char SDL_CPUType[13];
|
||||
|
||||
@@ -691,23 +690,32 @@ SDL_GetCPUType(void)
|
||||
int i = 0;
|
||||
|
||||
CPU_calcCPUIDFeatures();
|
||||
if (CPU_CPUIDMaxFunction > 0) { /* do we have CPUID at all? */
|
||||
if (CPU_CPUIDMaxFunction > 0) { /* do we have CPUID at all? */
|
||||
int a, b, c, d;
|
||||
cpuid(0x00000000, a, b, c, d);
|
||||
(void) a;
|
||||
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
|
||||
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
|
||||
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
|
||||
(void)a;
|
||||
SDL_CPUType[i++] = (char)(b & 0xff);
|
||||
b >>= 8;
|
||||
SDL_CPUType[i++] = (char)(b & 0xff);
|
||||
b >>= 8;
|
||||
SDL_CPUType[i++] = (char)(b & 0xff);
|
||||
b >>= 8;
|
||||
SDL_CPUType[i++] = (char)(b & 0xff);
|
||||
|
||||
SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
|
||||
SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
|
||||
SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
|
||||
SDL_CPUType[i++] = (char)(d & 0xff);
|
||||
d >>= 8;
|
||||
SDL_CPUType[i++] = (char)(d & 0xff);
|
||||
d >>= 8;
|
||||
SDL_CPUType[i++] = (char)(d & 0xff);
|
||||
d >>= 8;
|
||||
SDL_CPUType[i++] = (char)(d & 0xff);
|
||||
|
||||
SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
|
||||
SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
|
||||
SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
|
||||
SDL_CPUType[i++] = (char)(c & 0xff);
|
||||
c >>= 8;
|
||||
SDL_CPUType[i++] = (char)(c & 0xff);
|
||||
c >>= 8;
|
||||
SDL_CPUType[i++] = (char)(c & 0xff);
|
||||
c >>= 8;
|
||||
SDL_CPUType[i++] = (char)(c & 0xff);
|
||||
}
|
||||
if (!SDL_CPUType[0]) {
|
||||
@@ -718,8 +726,7 @@ SDL_GetCPUType(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef TEST_MAIN /* !!! FIXME: only used for test at the moment. */
|
||||
#ifdef TEST_MAIN /* !!! FIXME: only used for test at the moment. */
|
||||
#if defined(__e2k__)
|
||||
inline const char *
|
||||
SDL_GetCPUName(void)
|
||||
@@ -731,8 +738,7 @@ SDL_GetCPUName(void)
|
||||
return SDL_CPUName;
|
||||
}
|
||||
#else
|
||||
static const char *
|
||||
SDL_GetCPUName(void)
|
||||
static const char *SDL_GetCPUName(void)
|
||||
{
|
||||
static char SDL_CPUName[48];
|
||||
|
||||
@@ -741,60 +747,108 @@ SDL_GetCPUName(void)
|
||||
int a, b, c, d;
|
||||
|
||||
CPU_calcCPUIDFeatures();
|
||||
if (CPU_CPUIDMaxFunction > 0) { /* do we have CPUID at all? */
|
||||
if (CPU_CPUIDMaxFunction > 0) { /* do we have CPUID at all? */
|
||||
cpuid(0x80000000, a, b, c, d);
|
||||
if (a >= 0x80000004) {
|
||||
cpuid(0x80000002, a, b, c, d);
|
||||
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff);
|
||||
a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff);
|
||||
a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff);
|
||||
a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff);
|
||||
a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff);
|
||||
b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff);
|
||||
b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff);
|
||||
b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff);
|
||||
b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff);
|
||||
c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff);
|
||||
c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff);
|
||||
c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff);
|
||||
c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff);
|
||||
d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff);
|
||||
d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff);
|
||||
d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff);
|
||||
d >>= 8;
|
||||
cpuid(0x80000003, a, b, c, d);
|
||||
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff);
|
||||
a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff);
|
||||
a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff);
|
||||
a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff);
|
||||
a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff);
|
||||
b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff);
|
||||
b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff);
|
||||
b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff);
|
||||
b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff);
|
||||
c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff);
|
||||
c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff);
|
||||
c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff);
|
||||
c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff);
|
||||
d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff);
|
||||
d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff);
|
||||
d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff);
|
||||
d >>= 8;
|
||||
cpuid(0x80000004, a, b, c, d);
|
||||
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff);
|
||||
a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff);
|
||||
a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff);
|
||||
a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(a & 0xff);
|
||||
a >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff);
|
||||
b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff);
|
||||
b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff);
|
||||
b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(b & 0xff);
|
||||
b >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff);
|
||||
c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff);
|
||||
c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff);
|
||||
c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(c & 0xff);
|
||||
c >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff);
|
||||
d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff);
|
||||
d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff);
|
||||
d >>= 8;
|
||||
SDL_CPUName[i++] = (char)(d & 0xff);
|
||||
d >>= 8;
|
||||
}
|
||||
}
|
||||
if (!SDL_CPUName[0]) {
|
||||
@@ -806,13 +860,15 @@ SDL_GetCPUName(void)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int
|
||||
SDL_GetCPUCacheLineSize(void)
|
||||
int SDL_GetCPUCacheLineSize(void)
|
||||
{
|
||||
const char *cpuType = SDL_GetCPUType();
|
||||
int a, b, c, d;
|
||||
(void) a; (void) b; (void) c; (void) d;
|
||||
if (SDL_strcmp(cpuType, "GenuineIntel") == 0 || SDL_strcmp(cpuType, "CentaurHauls") == 0 || SDL_strcmp(cpuType, " Shanghai ") == 0) {
|
||||
(void)a;
|
||||
(void)b;
|
||||
(void)c;
|
||||
(void)d;
|
||||
if (SDL_strcmp(cpuType, "GenuineIntel") == 0 || SDL_strcmp(cpuType, "CentaurHauls") == 0 || SDL_strcmp(cpuType, " Shanghai ") == 0) {
|
||||
cpuid(0x00000001, a, b, c, d);
|
||||
return ((b >> 8) & 0xff) * 8;
|
||||
} else if (SDL_strcmp(cpuType, "AuthenticAMD") == 0 || SDL_strcmp(cpuType, "HygonGenuine") == 0) {
|
||||
@@ -827,13 +883,12 @@ SDL_GetCPUCacheLineSize(void)
|
||||
static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
|
||||
static Uint32 SDL_SIMDAlignment = 0xFFFFFFFF;
|
||||
|
||||
static Uint32
|
||||
SDL_GetCPUFeatures(void)
|
||||
static Uint32 SDL_GetCPUFeatures(void)
|
||||
{
|
||||
if (SDL_CPUFeatures == 0xFFFFFFFF) {
|
||||
CPU_calcCPUIDFeatures();
|
||||
SDL_CPUFeatures = 0;
|
||||
SDL_SIMDAlignment = sizeof(void *); /* a good safe base value */
|
||||
SDL_SIMDAlignment = sizeof(void *); /* a good safe base value */
|
||||
if (CPU_haveRDTSC()) {
|
||||
SDL_CPUFeatures |= CPU_HAS_RDTSC;
|
||||
}
|
||||
@@ -1000,33 +1055,32 @@ SDL_HasLASX(void)
|
||||
|
||||
static int SDL_SystemRAM = 0;
|
||||
|
||||
int
|
||||
SDL_GetSystemRAM(void)
|
||||
int SDL_GetSystemRAM(void)
|
||||
{
|
||||
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));
|
||||
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__) || defined(__DragonFly__)
|
||||
#ifdef HW_REALMEM
|
||||
int mib[2] = {CTL_HW, HW_REALMEM};
|
||||
int mib[2] = { CTL_HW, HW_REALMEM };
|
||||
#else
|
||||
/* might only report up to 2 GiB */
|
||||
int mib[2] = {CTL_HW, HW_PHYSMEM};
|
||||
int mib[2] = { CTL_HW, HW_PHYSMEM };
|
||||
#endif /* HW_REALMEM */
|
||||
#else
|
||||
int mib[2] = {CTL_HW, HW_MEMSIZE};
|
||||
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));
|
||||
SDL_SystemRAM = (int)(memsize / (1024 * 1024));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1066,12 +1120,11 @@ SDL_GetSystemRAM(void)
|
||||
return SDL_SystemRAM;
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
SDL_SIMDGetAlignment(void)
|
||||
{
|
||||
if (SDL_SIMDAlignment == 0xFFFFFFFF) {
|
||||
SDL_GetCPUFeatures(); /* make sure this has been calculated */
|
||||
SDL_GetCPUFeatures(); /* make sure this has been calculated */
|
||||
}
|
||||
SDL_assert(SDL_SIMDAlignment != 0);
|
||||
return SDL_SIMDAlignment;
|
||||
@@ -1088,16 +1141,16 @@ SDL_SIMDAlloc(const size_t len)
|
||||
|
||||
/* alignment + padding + sizeof (void *) is bounded (a few hundred
|
||||
* bytes max), so no need to check for overflow within that argument */
|
||||
if (SDL_size_add_overflow(len, alignment + padding + sizeof (void *), &to_allocate)) {
|
||||
if (SDL_size_add_overflow(len, alignment + padding + sizeof(void *), &to_allocate)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ptr = (Uint8 *) SDL_malloc(to_allocate);
|
||||
ptr = (Uint8 *)SDL_malloc(to_allocate);
|
||||
if (ptr) {
|
||||
/* store the actual allocated pointer right before our aligned pointer. */
|
||||
retval = ptr + sizeof (void *);
|
||||
retval += alignment - (((size_t) retval) % alignment);
|
||||
*(((void **) retval) - 1) = ptr;
|
||||
retval = ptr + sizeof(void *);
|
||||
retval += alignment - (((size_t)retval) % alignment);
|
||||
*(((void **)retval) - 1) = ptr;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
@@ -1107,7 +1160,7 @@ SDL_SIMDRealloc(void *mem, const size_t len)
|
||||
{
|
||||
const size_t alignment = SDL_SIMDGetAlignment();
|
||||
const size_t padding = (alignment - (len % alignment)) % alignment;
|
||||
Uint8 *retval = (Uint8*) mem;
|
||||
Uint8 *retval = (Uint8 *)mem;
|
||||
void *oldmem = mem;
|
||||
size_t memdiff = 0, ptrdiff;
|
||||
Uint8 *ptr;
|
||||
@@ -1115,32 +1168,32 @@ SDL_SIMDRealloc(void *mem, const size_t len)
|
||||
|
||||
/* alignment + padding + sizeof (void *) is bounded (a few hundred
|
||||
* bytes max), so no need to check for overflow within that argument */
|
||||
if (SDL_size_add_overflow(len, alignment + padding + sizeof (void *), &to_allocate)) {
|
||||
if (SDL_size_add_overflow(len, alignment + padding + sizeof(void *), &to_allocate)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mem) {
|
||||
mem = *(((void **) mem) - 1);
|
||||
mem = *(((void **)mem) - 1);
|
||||
|
||||
/* Check the delta between the real pointer and user pointer */
|
||||
memdiff = ((size_t) oldmem) - ((size_t) mem);
|
||||
memdiff = ((size_t)oldmem) - ((size_t)mem);
|
||||
}
|
||||
|
||||
ptr = (Uint8 *) SDL_realloc(mem, to_allocate);
|
||||
ptr = (Uint8 *)SDL_realloc(mem, to_allocate);
|
||||
|
||||
if (ptr == NULL) {
|
||||
return NULL; /* Out of memory, bail! */
|
||||
}
|
||||
|
||||
/* Store the actual allocated pointer right before our aligned pointer. */
|
||||
retval = ptr + sizeof (void *);
|
||||
retval += alignment - (((size_t) retval) % alignment);
|
||||
retval = ptr + sizeof(void *);
|
||||
retval += alignment - (((size_t)retval) % alignment);
|
||||
|
||||
/* Make sure the delta is the same! */
|
||||
if (mem) {
|
||||
ptrdiff = ((size_t) retval) - ((size_t) ptr);
|
||||
ptrdiff = ((size_t)retval) - ((size_t)ptr);
|
||||
if (memdiff != ptrdiff) { /* Delta has changed, copy to new offset! */
|
||||
oldmem = (void*) (((uintptr_t) ptr) + memdiff);
|
||||
oldmem = (void *)(((uintptr_t)ptr) + memdiff);
|
||||
|
||||
/* Even though the data past the old `len` is undefined, this is the
|
||||
* only length value we have, and it guarantees that we copy all the
|
||||
@@ -1151,25 +1204,22 @@ SDL_SIMDRealloc(void *mem, const size_t len)
|
||||
}
|
||||
|
||||
/* Actually store the allocated pointer, finally. */
|
||||
*(((void **) retval) - 1) = ptr;
|
||||
*(((void **)retval) - 1) = ptr;
|
||||
return retval;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SIMDFree(void *ptr)
|
||||
void SDL_SIMDFree(void *ptr)
|
||||
{
|
||||
if (ptr) {
|
||||
SDL_free(*(((void **) ptr) - 1));
|
||||
SDL_free(*(((void **)ptr) - 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef TEST_MAIN
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
printf("CPU count: %d\n", SDL_GetCPUCount());
|
||||
printf("CPU type: %s\n", SDL_GetCPUType());
|
||||
|
Reference in New Issue
Block a user