SDL
2.0
|
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_MSA (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) |
#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_haveLSX() (CPU_readCPUCFG() & CPU_CFG2_LSX) |
#define | CPU_haveLASX() (CPU_readCPUCFG() & CPU_CFG2_LASX) |
#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) |
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 |
#define CPU_CFG2 0x2 |
Definition at line 98 of file SDL_cpuinfo.c.
Referenced by CPU_readCPUCFG().
#define CPU_CFG2_LASX (1 << 7) |
Definition at line 100 of file SDL_cpuinfo.c.
#define CPU_CFG2_LSX (1 << 6) |
Definition at line 99 of file SDL_cpuinfo.c.
#define CPU_FEATURE_AVAILABLE | ( | f | ) | ((SDL_GetCPUFeatures() & f) ? SDL_TRUE : SDL_FALSE) |
Definition at line 727 of file SDL_cpuinfo.c.
Referenced by SDL_Has3DNow(), SDL_HasAltiVec(), SDL_HasAVX(), SDL_HasAVX2(), SDL_HasAVX512F(), SDL_HasLASX(), SDL_HasLSX(), SDL_HasMMX(), SDL_HasMSA(), SDL_HasNEON(), SDL_HasRDTSC(), SDL_HasSSE(), SDL_HasSSE2(), SDL_HasSSE3(), SDL_HasSSE41(), and SDL_HasSSE42().
#define CPU_HAS_3DNOW (1 << 3) |
Definition at line 84 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures(), and SDL_Has3DNow().
#define CPU_HAS_ALTIVEC (1 << 1) |
Definition at line 82 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures(), and SDL_HasAltiVec().
#define CPU_HAS_AVX (1 << 9) |
Definition at line 90 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures(), and SDL_HasAVX().
#define CPU_HAS_AVX2 (1 << 10) |
Definition at line 91 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures(), and SDL_HasAVX2().
#define CPU_HAS_AVX512F (1 << 12) |
Definition at line 93 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures(), and SDL_HasAVX512F().
#define CPU_HAS_LASX (1 << 15) |
Definition at line 96 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures(), and SDL_HasLASX().
#define CPU_HAS_LSX (1 << 14) |
Definition at line 95 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures(), and SDL_HasLSX().
#define CPU_HAS_MMX (1 << 2) |
Definition at line 83 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures(), and SDL_HasMMX().
#define CPU_HAS_MSA (1 << 13) |
Definition at line 94 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures(), and SDL_HasMSA().
#define CPU_HAS_NEON (1 << 11) |
Definition at line 92 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures(), and SDL_HasNEON().
#define CPU_HAS_RDTSC (1 << 0) |
Definition at line 81 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures(), and SDL_HasRDTSC().
#define CPU_HAS_SSE (1 << 4) |
Definition at line 85 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures(), and SDL_HasSSE().
#define CPU_HAS_SSE2 (1 << 5) |
Definition at line 86 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures(), and SDL_HasSSE2().
#define CPU_HAS_SSE3 (1 << 6) |
Definition at line 87 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures(), and SDL_HasSSE3().
#define CPU_HAS_SSE41 (1 << 7) |
Definition at line 88 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures(), and SDL_HasSSE41().
#define CPU_HAS_SSE42 (1 << 8) |
Definition at line 89 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures(), and SDL_HasSSE42().
#define CPU_haveAVX | ( | ) | (CPU_OSSavesYMM && (CPU_CPUIDFeatures[2] & 0x10000000)) |
Definition at line 454 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures().
#define CPU_haveLASX | ( | ) | (CPU_readCPUCFG() & CPU_CFG2_LASX) |
Definition at line 431 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures().
#define CPU_haveLSX | ( | ) | (CPU_readCPUCFG() & CPU_CFG2_LSX) |
Definition at line 430 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures().
#define CPU_haveMMX | ( | ) | (CPU_CPUIDFeatures[3] & 0x00800000) |
Definition at line 448 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures().
#define CPU_haveRDTSC | ( | ) | (CPU_CPUIDFeatures[3] & 0x00000010) |
Definition at line 447 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures().
#define CPU_haveSSE | ( | ) | (CPU_CPUIDFeatures[3] & 0x02000000) |
Definition at line 449 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures().
#define CPU_haveSSE2 | ( | ) | (CPU_CPUIDFeatures[3] & 0x04000000) |
Definition at line 450 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures().
#define CPU_haveSSE3 | ( | ) | (CPU_CPUIDFeatures[2] & 0x00000001) |
Definition at line 451 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures().
#define CPU_haveSSE41 | ( | ) | (CPU_CPUIDFeatures[2] & 0x00080000) |
Definition at line 452 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures().
#define CPU_haveSSE42 | ( | ) | (CPU_CPUIDFeatures[2] & 0x00100000) |
Definition at line 453 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures().
#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 252 of file SDL_cpuinfo.c.
Referenced by CPU_calcCPUIDFeatures(), CPU_have3DNow(), CPU_haveAVX2(), CPU_haveAVX512F(), SDL_GetCPUCacheLineSize(), and SDL_GetCPUType().
Definition at line 262 of file SDL_cpuinfo.c.
References CPU_CPUIDFeatures, CPU_CPUIDMaxFunction, CPU_haveCPUID(), CPU_OSSavesYMM, CPU_OSSavesZMM, cpuid, d, SDL_FALSE, and SDL_TRUE.
Referenced by SDL_GetCPUFeatures(), and SDL_GetCPUType().
|
static |
Definition at line 434 of file SDL_cpuinfo.c.
References CPU_CPUIDMaxFunction, cpuid, and d.
Referenced by SDL_GetCPUFeatures().
|
static |
Definition at line 302 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures().
|
static |
Definition at line 457 of file SDL_cpuinfo.c.
References CPU_CPUIDMaxFunction, CPU_OSSavesYMM, cpuid, d, and void.
Referenced by SDL_GetCPUFeatures().
|
static |
Definition at line 469 of file SDL_cpuinfo.c.
References CPU_CPUIDMaxFunction, CPU_OSSavesZMM, cpuid, d, and void.
Referenced by SDL_GetCPUFeatures().
|
static |
|
static |
Definition at line 381 of file SDL_cpuinfo.c.
References memset.
Referenced by SDL_GetCPUFeatures().
|
static |
Definition at line 352 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures().
|
static |
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().
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().
Definition at line 654 of file SDL_cpuinfo.c.
References CPU_calcCPUIDFeatures(), CPU_HAS_3DNOW, CPU_HAS_ALTIVEC, CPU_HAS_AVX, CPU_HAS_AVX2, CPU_HAS_AVX512F, CPU_HAS_LASX, CPU_HAS_LSX, CPU_HAS_MMX, CPU_HAS_MSA, 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_haveAVX, CPU_haveAVX2(), CPU_haveAVX512F(), CPU_haveLASX, CPU_haveLSX, CPU_haveMMX, CPU_haveMSA(), 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().
|
static |
Definition at line 522 of file SDL_cpuinfo.c.
References CPU_calcCPUIDFeatures(), CPU_CPUIDMaxFunction, cpuid, d, i, SDL_strlcpy, and void.
Referenced by SDL_GetCPUCacheLineSize(), and SDL_SIMDFree().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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.
len | The length, in bytes, of the block to allocated. The actual allocated block might be larger due to padding, etc. |
Definition at line 889 of file SDL_cpuinfo.c.
References NULL, retval, SDL_malloc, and SDL_SIMDGetAlignment().
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.
Definition at line 906 of file SDL_cpuinfo.c.
References main, SDL_free, SDL_GetCPUCacheLineSize(), SDL_GetCPUCount(), SDL_GetCPUType(), SDL_GetSystemRAM(), SDL_Has3DNow(), SDL_HasAltiVec(), SDL_HasAVX(), SDL_HasAVX2(), SDL_HasAVX512F(), SDL_HasLASX(), SDL_HasLSX(), SDL_HasMMX(), SDL_HasMSA(), SDL_HasNEON(), SDL_HasRDTSC(), SDL_HasSSE(), SDL_HasSSE2(), SDL_HasSSE3(), SDL_HasSSE41(), and SDL_HasSSE42().
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 879 of file SDL_cpuinfo.c.
References SDL_assert, SDL_GetCPUFeatures(), and SDL_SIMDAlignment.
Referenced by SDL_SIMDAlloc().
|
static |
Definition at line 256 of file SDL_cpuinfo.c.
Referenced by CPU_calcCPUIDFeatures().
|
static |
Definition at line 257 of file SDL_cpuinfo.c.
Referenced by CPU_calcCPUIDFeatures(), CPU_have3DNow(), CPU_haveAVX2(), CPU_haveAVX512F(), and SDL_GetCPUType().
Definition at line 258 of file SDL_cpuinfo.c.
Referenced by CPU_calcCPUIDFeatures(), and CPU_haveAVX2().
Definition at line 259 of file SDL_cpuinfo.c.
Referenced by CPU_calcCPUIDFeatures(), and CPU_haveAVX512F().
|
static |
Definition at line 480 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUCount().
|
static |
Definition at line 650 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures().
|
static |
Definition at line 651 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures(), and SDL_SIMDGetAlignment().
|
static |
Definition at line 824 of file SDL_cpuinfo.c.
Referenced by SDL_GetSystemRAM().