early-access version 2847
This commit is contained in:
85
externals/SDL/src/cpuinfo/SDL_cpuinfo.c
vendored
85
externals/SDL/src/cpuinfo/SDL_cpuinfo.c
vendored
@@ -98,10 +98,6 @@
|
||||
#include <swis.h>
|
||||
#endif
|
||||
|
||||
#ifdef __PS2__
|
||||
#include <kernel.h>
|
||||
#endif
|
||||
|
||||
#define CPU_HAS_RDTSC (1 << 0)
|
||||
#define CPU_HAS_ALTIVEC (1 << 1)
|
||||
#define CPU_HAS_MMX (1 << 2)
|
||||
@@ -116,12 +112,6 @@
|
||||
#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_CFG2 0x2
|
||||
#define CPU_CFG2_LSX (1 << 6)
|
||||
#define CPU_CFG2_LASX (1 << 7)
|
||||
|
||||
#if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__ && !__OpenBSD__ && !__FreeBSD__
|
||||
/* This is the brute force way of detecting instruction sets...
|
||||
@@ -140,7 +130,7 @@ CPU_haveCPUID(void)
|
||||
{
|
||||
int has_CPUID = 0;
|
||||
|
||||
/* *INDENT-OFF* */ /* clang-format off */
|
||||
/* *INDENT-OFF* */
|
||||
#ifndef SDL_CPUINFO_DISABLED
|
||||
#if (defined(__GNUC__) || defined(__llvm__)) && defined(__i386__)
|
||||
__asm__ (
|
||||
@@ -229,7 +219,7 @@ done:
|
||||
);
|
||||
#endif
|
||||
#endif
|
||||
/* *INDENT-ON* */ /* clang-format on */
|
||||
/* *INDENT-ON* */
|
||||
return has_CPUID;
|
||||
}
|
||||
|
||||
@@ -518,23 +508,6 @@ CPU_haveNEON(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
CPU_readCPUCFG(void)
|
||||
{
|
||||
uint32_t cfg2 = 0;
|
||||
#if defined __loongarch__
|
||||
__asm__ volatile(
|
||||
"cpucfg %0, %1 \n\t"
|
||||
: "+&r"(cfg2)
|
||||
: "r"(CPU_CFG2)
|
||||
);
|
||||
#endif
|
||||
return cfg2;
|
||||
}
|
||||
|
||||
#define CPU_haveLSX() (CPU_readCPUCFG() & CPU_CFG2_LSX)
|
||||
#define CPU_haveLASX() (CPU_readCPUCFG() & CPU_CFG2_LASX)
|
||||
|
||||
#if defined(__e2k__)
|
||||
inline int
|
||||
CPU_have3DNow(void)
|
||||
@@ -912,14 +885,6 @@ SDL_GetCPUFeatures(void)
|
||||
SDL_CPUFeatures |= CPU_HAS_NEON;
|
||||
SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 16);
|
||||
}
|
||||
if (CPU_haveLSX()) {
|
||||
SDL_CPUFeatures |= CPU_HAS_LSX;
|
||||
SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 16);
|
||||
}
|
||||
if (CPU_haveLASX()) {
|
||||
SDL_CPUFeatures |= CPU_HAS_LASX;
|
||||
SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 32);
|
||||
}
|
||||
}
|
||||
return SDL_CPUFeatures;
|
||||
}
|
||||
@@ -1009,18 +974,6 @@ SDL_HasNEON(void)
|
||||
return CPU_FEATURE_AVAILABLE(CPU_HAS_NEON);
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
SDL_HasLSX(void)
|
||||
{
|
||||
return CPU_FEATURE_AVAILABLE(CPU_HAS_LSX);
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
SDL_HasLASX(void)
|
||||
{
|
||||
return CPU_FEATURE_AVAILABLE(CPU_HAS_LASX);
|
||||
}
|
||||
|
||||
static int SDL_SystemRAM = 0;
|
||||
|
||||
int
|
||||
@@ -1085,12 +1038,6 @@ SDL_GetSystemRAM(void)
|
||||
SDL_SystemRAM = 536870912;
|
||||
}
|
||||
#endif
|
||||
#ifdef __PS2__
|
||||
if (SDL_SystemRAM <= 0) {
|
||||
/* PlayStation 2 has 32MiB however there are some special models with 64 and 128 */
|
||||
SDL_SystemRAM = GetMemorySize();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
return SDL_SystemRAM;
|
||||
@@ -1111,18 +1058,10 @@ void *
|
||||
SDL_SIMDAlloc(const size_t len)
|
||||
{
|
||||
const size_t alignment = SDL_SIMDGetAlignment();
|
||||
const size_t padding = (alignment - (len % alignment)) % alignment;
|
||||
const size_t padding = alignment - (len % alignment);
|
||||
const size_t padded = (padding != alignment) ? (len + padding) : len;
|
||||
Uint8 *retval = NULL;
|
||||
Uint8 *ptr;
|
||||
size_t to_allocate;
|
||||
|
||||
/* 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)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ptr = (Uint8 *) SDL_malloc(to_allocate);
|
||||
Uint8 *ptr = (Uint8 *) SDL_malloc(padded + alignment + sizeof (void *));
|
||||
if (ptr) {
|
||||
/* store the actual allocated pointer right before our aligned pointer. */
|
||||
retval = ptr + sizeof (void *);
|
||||
@@ -1136,18 +1075,12 @@ void *
|
||||
SDL_SIMDRealloc(void *mem, const size_t len)
|
||||
{
|
||||
const size_t alignment = SDL_SIMDGetAlignment();
|
||||
const size_t padding = (alignment - (len % alignment)) % alignment;
|
||||
const size_t padding = alignment - (len % alignment);
|
||||
const size_t padded = (padding != alignment) ? (len + padding) : len;
|
||||
Uint8 *retval = (Uint8*) mem;
|
||||
void *oldmem = mem;
|
||||
size_t memdiff = 0, ptrdiff;
|
||||
Uint8 *ptr;
|
||||
size_t to_allocate;
|
||||
|
||||
/* 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)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mem) {
|
||||
void **realptr = (void **) mem;
|
||||
@@ -1158,7 +1091,7 @@ SDL_SIMDRealloc(void *mem, const size_t len)
|
||||
memdiff = ((size_t) oldmem) - ((size_t) mem);
|
||||
}
|
||||
|
||||
ptr = (Uint8 *) SDL_realloc(mem, to_allocate);
|
||||
ptr = (Uint8 *) SDL_realloc(mem, padded + alignment + sizeof (void *));
|
||||
|
||||
if (ptr == NULL) {
|
||||
return NULL; /* Out of memory, bail! */
|
||||
@@ -1223,8 +1156,6 @@ main()
|
||||
printf("AVX-512F: %d\n", SDL_HasAVX512F());
|
||||
printf("ARM SIMD: %d\n", SDL_HasARMSIMD());
|
||||
printf("NEON: %d\n", SDL_HasNEON());
|
||||
printf("LSX: %d\n", SDL_HasLSX());
|
||||
printf("LASX: %d\n", SDL_HasLASX());
|
||||
printf("RAM: %d MB\n", SDL_GetSystemRAM());
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user