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_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) |
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_FEATURE_AVAILABLE | ( | f | ) | ((SDL_GetCPUFeatures() & f) ? SDL_TRUE : SDL_FALSE) |
Definition at line 784 of file SDL_cpuinfo.c.
#define CPU_HAS_3DNOW (1 << 3) |
Definition at line 101 of file SDL_cpuinfo.c.
#define CPU_HAS_ALTIVEC (1 << 1) |
Definition at line 99 of file SDL_cpuinfo.c.
#define CPU_HAS_ARM_SIMD (1 << 13) |
Definition at line 111 of file SDL_cpuinfo.c.
#define CPU_HAS_AVX (1 << 9) |
Definition at line 107 of file SDL_cpuinfo.c.
#define CPU_HAS_AVX2 (1 << 10) |
Definition at line 108 of file SDL_cpuinfo.c.
#define CPU_HAS_AVX512F (1 << 12) |
Definition at line 110 of file SDL_cpuinfo.c.
#define CPU_HAS_MMX (1 << 2) |
Definition at line 100 of file SDL_cpuinfo.c.
#define CPU_HAS_NEON (1 << 11) |
Definition at line 109 of file SDL_cpuinfo.c.
#define CPU_HAS_RDTSC (1 << 0) |
Definition at line 98 of file SDL_cpuinfo.c.
#define CPU_HAS_SSE (1 << 4) |
Definition at line 102 of file SDL_cpuinfo.c.
#define CPU_HAS_SSE2 (1 << 5) |
Definition at line 103 of file SDL_cpuinfo.c.
#define CPU_HAS_SSE3 (1 << 6) |
Definition at line 104 of file SDL_cpuinfo.c.
#define CPU_HAS_SSE41 (1 << 7) |
Definition at line 105 of file SDL_cpuinfo.c.
#define CPU_HAS_SSE42 (1 << 8) |
Definition at line 106 of file SDL_cpuinfo.c.
#define CPU_haveAVX | ( | ) | (CPU_OSSavesYMM && (CPU_CPUIDFeatures[2] & 0x10000000)) |
Definition at line 519 of file SDL_cpuinfo.c.
#define CPU_haveMMX | ( | ) | (CPU_CPUIDFeatures[3] & 0x00800000) |
Definition at line 513 of file SDL_cpuinfo.c.
#define CPU_haveRDTSC | ( | ) | (CPU_CPUIDFeatures[3] & 0x00000010) |
Definition at line 512 of file SDL_cpuinfo.c.
#define CPU_haveSSE | ( | ) | (CPU_CPUIDFeatures[3] & 0x02000000) |
Definition at line 514 of file SDL_cpuinfo.c.
#define CPU_haveSSE2 | ( | ) | (CPU_CPUIDFeatures[3] & 0x04000000) |
Definition at line 515 of file SDL_cpuinfo.c.
#define CPU_haveSSE3 | ( | ) | (CPU_CPUIDFeatures[2] & 0x00000001) |
Definition at line 516 of file SDL_cpuinfo.c.
#define CPU_haveSSE41 | ( | ) | (CPU_CPUIDFeatures[2] & 0x00080000) |
Definition at line 517 of file SDL_cpuinfo.c.
#define CPU_haveSSE42 | ( | ) | (CPU_CPUIDFeatures[2] & 0x00100000) |
Definition at line 518 of file SDL_cpuinfo.c.
#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 263 of file SDL_cpuinfo.c.
Definition at line 273 of file SDL_cpuinfo.c.
References CPU_CPUIDFeatures, CPU_CPUIDMaxFunction, CPU_haveCPUID(), CPU_OSSavesYMM, CPU_OSSavesZMM, cpuid, d, mov, SDL_FALSE, and SDL_TRUE.
Referenced by SDL_GetCPUFeatures(), and SDL_GetCPUType().
|
static |
Definition at line 499 of file SDL_cpuinfo.c.
References CPU_CPUIDMaxFunction, cpuid, and d.
Referenced by SDL_GetCPUFeatures().
|
static |
Definition at line 313 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures().
|
static |
Definition at line 350 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures().
|
static |
Definition at line 522 of file SDL_cpuinfo.c.
References CPU_CPUIDMaxFunction, CPU_OSSavesYMM, cpuid, d, and void.
Referenced by SDL_GetCPUFeatures().
|
static |
Definition at line 534 of file SDL_cpuinfo.c.
References CPU_CPUIDMaxFunction, CPU_OSSavesZMM, cpuid, d, and void.
Referenced by SDL_GetCPUFeatures().
|
static |
Definition at line 126 of file SDL_cpuinfo.c.
References done, mov, and pop.
Referenced by CPU_calcCPUIDFeatures().
|
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 698 of file SDL_cpuinfo.c.
References cpuid, d, SDL_CACHELINE_SIZE, SDL_GetCPUType(), SDL_strcmp, and void.
int SDL_GetCPUCount | ( | void | ) |
This function returns the number of CPU cores available.
Definition at line 548 of file SDL_cpuinfo.c.
References NULL, and SDL_CPUCount.
Definition at line 719 of file SDL_cpuinfo.c.
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().
|
static |
Definition at line 587 of file SDL_cpuinfo.c.
References CPU_calcCPUIDFeatures(), CPU_CPUIDMaxFunction, cpuid, d, i, SDL_strlcpy, and void.
Referenced by SDL_GetCPUCacheLineSize().
int SDL_GetSystemRAM | ( | void | ) |
This function returns the amount of RAM configured in the system, in MB.
Definition at line 872 of file SDL_cpuinfo.c.
References NULL, and SDL_SystemRAM.
This function returns true if the CPU has 3DNow! features.
Definition at line 804 of file SDL_cpuinfo.c.
References CPU_FEATURE_AVAILABLE, and CPU_HAS_3DNOW.
This function returns true if the CPU has AltiVec features.
Definition at line 792 of file SDL_cpuinfo.c.
References CPU_FEATURE_AVAILABLE, and CPU_HAS_ALTIVEC.
This function returns true if the CPU has ARM SIMD (ARMv6) features.
Definition at line 858 of file SDL_cpuinfo.c.
References CPU_FEATURE_AVAILABLE, and CPU_HAS_ARM_SIMD.
This function returns true if the CPU has AVX features.
Definition at line 840 of file SDL_cpuinfo.c.
References CPU_FEATURE_AVAILABLE, and CPU_HAS_AVX.
This function returns true if the CPU has AVX2 features.
Definition at line 846 of file SDL_cpuinfo.c.
References CPU_FEATURE_AVAILABLE, and CPU_HAS_AVX2.
This function returns true if the CPU has AVX-512F (foundation) features.
Definition at line 852 of file SDL_cpuinfo.c.
References CPU_FEATURE_AVAILABLE, and CPU_HAS_AVX512F.
This function returns true if the CPU has MMX features.
Definition at line 798 of file SDL_cpuinfo.c.
References CPU_FEATURE_AVAILABLE, and CPU_HAS_MMX.
This function returns true if the CPU has NEON (ARM SIMD) features.
Definition at line 864 of file SDL_cpuinfo.c.
References CPU_FEATURE_AVAILABLE, and CPU_HAS_NEON.
This function returns true if the CPU has the RDTSC instruction.
Definition at line 786 of file SDL_cpuinfo.c.
References CPU_FEATURE_AVAILABLE, and CPU_HAS_RDTSC.
This function returns true if the CPU has SSE features.
Definition at line 810 of file SDL_cpuinfo.c.
References CPU_FEATURE_AVAILABLE, and CPU_HAS_SSE.
This function returns true if the CPU has SSE2 features.
Definition at line 816 of file SDL_cpuinfo.c.
References CPU_FEATURE_AVAILABLE, and CPU_HAS_SSE2.
This function returns true if the CPU has SSE3 features.
Definition at line 822 of file SDL_cpuinfo.c.
References CPU_FEATURE_AVAILABLE, and CPU_HAS_SSE3.
This function returns true if the CPU has SSE4.1 features.
Definition at line 828 of file SDL_cpuinfo.c.
References CPU_FEATURE_AVAILABLE, and CPU_HAS_SSE41.
This function returns true if the CPU has SSE4.2 features.
Definition at line 834 of file SDL_cpuinfo.c.
References CPU_FEATURE_AVAILABLE, and CPU_HAS_SSE42.
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 943 of file SDL_cpuinfo.c.
References NULL, ptr, 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 960 of file SDL_cpuinfo.c.
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 933 of file SDL_cpuinfo.c.
References SDL_assert, SDL_GetCPUFeatures(), and SDL_SIMDAlignment.
Referenced by SDL_SIMDAlloc().
|
static |
Definition at line 267 of file SDL_cpuinfo.c.
Referenced by CPU_calcCPUIDFeatures().
|
static |
Definition at line 268 of file SDL_cpuinfo.c.
Referenced by CPU_calcCPUIDFeatures(), CPU_have3DNow(), CPU_haveAVX2(), CPU_haveAVX512F(), and SDL_GetCPUType().
Definition at line 269 of file SDL_cpuinfo.c.
Referenced by CPU_calcCPUIDFeatures(), and CPU_haveAVX2().
Definition at line 270 of file SDL_cpuinfo.c.
Referenced by CPU_calcCPUIDFeatures(), and CPU_haveAVX512F().
|
static |
Definition at line 545 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUCount().
|
static |
Definition at line 715 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures().
|
static |
Definition at line 716 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures(), and SDL_SIMDGetAlignment().
|
static |
Definition at line 869 of file SDL_cpuinfo.c.
Referenced by SDL_GetSystemRAM().