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 | 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 679 of file SDL_cpuinfo.c.
#define CPU_HAS_3DNOW (1 << 3) |
Definition at line 89 of file SDL_cpuinfo.c.
#define CPU_HAS_ALTIVEC (1 << 1) |
Definition at line 87 of file SDL_cpuinfo.c.
#define CPU_HAS_AVX (1 << 9) |
Definition at line 95 of file SDL_cpuinfo.c.
#define CPU_HAS_AVX2 (1 << 10) |
Definition at line 96 of file SDL_cpuinfo.c.
#define CPU_HAS_AVX512F (1 << 12) |
Definition at line 98 of file SDL_cpuinfo.c.
#define CPU_HAS_MMX (1 << 2) |
Definition at line 88 of file SDL_cpuinfo.c.
#define CPU_HAS_NEON (1 << 11) |
Definition at line 97 of file SDL_cpuinfo.c.
#define CPU_HAS_RDTSC (1 << 0) |
Definition at line 86 of file SDL_cpuinfo.c.
#define CPU_HAS_SSE (1 << 4) |
Definition at line 90 of file SDL_cpuinfo.c.
#define CPU_HAS_SSE2 (1 << 5) |
Definition at line 91 of file SDL_cpuinfo.c.
#define CPU_HAS_SSE3 (1 << 6) |
Definition at line 92 of file SDL_cpuinfo.c.
#define CPU_HAS_SSE41 (1 << 7) |
Definition at line 93 of file SDL_cpuinfo.c.
#define CPU_HAS_SSE42 (1 << 8) |
Definition at line 94 of file SDL_cpuinfo.c.
#define CPU_haveAVX | ( | ) | (CPU_OSSavesYMM && (CPU_CPUIDFeatures[2] & 0x10000000)) |
Definition at line 418 of file SDL_cpuinfo.c.
#define CPU_haveMMX | ( | ) | (CPU_CPUIDFeatures[3] & 0x00800000) |
Definition at line 412 of file SDL_cpuinfo.c.
#define CPU_haveRDTSC | ( | ) | (CPU_CPUIDFeatures[3] & 0x00000010) |
Definition at line 411 of file SDL_cpuinfo.c.
#define CPU_haveSSE | ( | ) | (CPU_CPUIDFeatures[3] & 0x02000000) |
Definition at line 413 of file SDL_cpuinfo.c.
#define CPU_haveSSE2 | ( | ) | (CPU_CPUIDFeatures[3] & 0x04000000) |
Definition at line 414 of file SDL_cpuinfo.c.
#define CPU_haveSSE3 | ( | ) | (CPU_CPUIDFeatures[2] & 0x00000001) |
Definition at line 415 of file SDL_cpuinfo.c.
#define CPU_haveSSE41 | ( | ) | (CPU_CPUIDFeatures[2] & 0x00080000) |
Definition at line 416 of file SDL_cpuinfo.c.
#define CPU_haveSSE42 | ( | ) | (CPU_CPUIDFeatures[2] & 0x00100000) |
Definition at line 417 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 250 of file SDL_cpuinfo.c.
Definition at line 260 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 398 of file SDL_cpuinfo.c.
References CPU_CPUIDMaxFunction, cpuid, and d.
Referenced by SDL_GetCPUFeatures().
|
static |
Definition at line 300 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures().
|
static |
Definition at line 421 of file SDL_cpuinfo.c.
References CPU_CPUIDMaxFunction, CPU_OSSavesYMM, cpuid, d, and void.
Referenced by SDL_GetCPUFeatures().
|
static |
Definition at line 433 of file SDL_cpuinfo.c.
References CPU_CPUIDMaxFunction, CPU_OSSavesZMM, cpuid, d, and void.
Referenced by SDL_GetCPUFeatures().
|
static |
Definition at line 113 of file SDL_cpuinfo.c.
Referenced by CPU_calcCPUIDFeatures().
|
static |
Definition at line 350 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures().
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 597 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 447 of file SDL_cpuinfo.c.
References NULL, and SDL_CPUCount.
Definition at line 618 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_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_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 486 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 761 of file SDL_cpuinfo.c.
References NULL, and SDL_SystemRAM.
This function returns true if the CPU has 3DNow! features.
Definition at line 699 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 687 of file SDL_cpuinfo.c.
References CPU_FEATURE_AVAILABLE, and CPU_HAS_ALTIVEC.
This function returns true if the CPU has AVX features.
Definition at line 735 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 741 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 747 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 693 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 753 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 681 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 705 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 711 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 717 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 723 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 729 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 823 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 840 of file SDL_cpuinfo.c.
References SDL_free.
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 813 of file SDL_cpuinfo.c.
References SDL_assert, SDL_GetCPUFeatures(), and SDL_SIMDAlignment.
Referenced by SDL_SIMDAlloc().
|
static |
Definition at line 254 of file SDL_cpuinfo.c.
Referenced by CPU_calcCPUIDFeatures().
|
static |
Definition at line 255 of file SDL_cpuinfo.c.
Referenced by CPU_calcCPUIDFeatures(), CPU_have3DNow(), CPU_haveAVX2(), CPU_haveAVX512F(), and SDL_GetCPUType().
Definition at line 256 of file SDL_cpuinfo.c.
Referenced by CPU_calcCPUIDFeatures(), and CPU_haveAVX2().
Definition at line 257 of file SDL_cpuinfo.c.
Referenced by CPU_calcCPUIDFeatures(), and CPU_haveAVX512F().
|
static |
Definition at line 444 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUCount().
|
static |
Definition at line 614 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures().
|
static |
Definition at line 615 of file SDL_cpuinfo.c.
Referenced by SDL_GetCPUFeatures(), and SDL_SIMDGetAlignment().
|
static |
Definition at line 758 of file SDL_cpuinfo.c.
Referenced by SDL_GetSystemRAM().