early-access version 2835

This commit is contained in:
pineappleEA
2022-07-15 04:00:50 +02:00
parent 5c0ee5eba6
commit 0e7aef7e36
1173 changed files with 55320 additions and 18881 deletions

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -98,6 +98,10 @@
#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)
@@ -112,6 +116,12 @@
#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...
@@ -130,7 +140,7 @@ CPU_haveCPUID(void)
{
int has_CPUID = 0;
/* *INDENT-OFF* */
/* *INDENT-OFF* */ /* clang-format off */
#ifndef SDL_CPUINFO_DISABLED
#if (defined(__GNUC__) || defined(__llvm__)) && defined(__i386__)
__asm__ (
@@ -219,7 +229,7 @@ done:
);
#endif
#endif
/* *INDENT-ON* */
/* *INDENT-ON* */ /* clang-format on */
return has_CPUID;
}
@@ -508,6 +518,23 @@ 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)
@@ -885,6 +912,14 @@ 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;
}
@@ -974,6 +1009,18 @@ 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
@@ -1038,6 +1085,12 @@ 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;
@@ -1058,10 +1111,18 @@ void *
SDL_SIMDAlloc(const size_t len)
{
const size_t alignment = SDL_SIMDGetAlignment();
const size_t padding = alignment - (len % alignment);
const size_t padded = (padding != alignment) ? (len + padding) : len;
const size_t padding = (alignment - (len % alignment)) % alignment;
Uint8 *retval = NULL;
Uint8 *ptr = (Uint8 *) SDL_malloc(padded + alignment + sizeof (void *));
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);
if (ptr) {
/* store the actual allocated pointer right before our aligned pointer. */
retval = ptr + sizeof (void *);
@@ -1075,12 +1136,18 @@ void *
SDL_SIMDRealloc(void *mem, const size_t len)
{
const size_t alignment = SDL_SIMDGetAlignment();
const size_t padding = alignment - (len % alignment);
const size_t padded = (padding != alignment) ? (len + padding) : len;
const size_t padding = (alignment - (len % alignment)) % alignment;
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;
@@ -1091,7 +1158,7 @@ SDL_SIMDRealloc(void *mem, const size_t len)
memdiff = ((size_t) oldmem) - ((size_t) mem);
}
ptr = (Uint8 *) SDL_realloc(mem, padded + alignment + sizeof (void *));
ptr = (Uint8 *) SDL_realloc(mem, to_allocate);
if (ptr == NULL) {
return NULL; /* Out of memory, bail! */
@@ -1156,6 +1223,8 @@ 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;
}