Path: blob/master/thirdparty/sdl/include/SDL3/SDL_cpuinfo.h
9912 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/2021/* WIKI CATEGORY: CPUInfo */2223/**24* # CategoryCPUInfo25*26* CPU feature detection for SDL.27*28* These functions are largely concerned with reporting if the system has29* access to various SIMD instruction sets, but also has other important info30* to share, such as system RAM size and number of logical CPU cores.31*32* CPU instruction set checks, like SDL_HasSSE() and SDL_HasNEON(), are33* available on all platforms, even if they don't make sense (an ARM processor34* will never have SSE and an x86 processor will never have NEON, for example,35* but these functions still exist and will simply return false in these36* cases).37*/3839#ifndef SDL_cpuinfo_h_40#define SDL_cpuinfo_h_4142#include <SDL3/SDL_stdinc.h>4344#include <SDL3/SDL_begin_code.h>45/* Set up for C function definitions, even when using C++ */46#ifdef __cplusplus47extern "C" {48#endif4950/**51* A guess for the cacheline size used for padding.52*53* Most x86 processors have a 64 byte cache line. The 64-bit PowerPC54* processors have a 128 byte cache line. We use the larger value to be55* generally safe.56*57* \since This macro is available since SDL 3.2.0.58*/59#define SDL_CACHELINE_SIZE 1286061/**62* Get the number of logical CPU cores available.63*64* \returns the total number of logical CPU cores. On CPUs that include65* technologies such as hyperthreading, the number of logical cores66* may be more than the number of physical cores.67*68* \threadsafety It is safe to call this function from any thread.69*70* \since This function is available since SDL 3.2.0.71*/72extern SDL_DECLSPEC int SDLCALL SDL_GetNumLogicalCPUCores(void);7374/**75* Determine the L1 cache line size of the CPU.76*77* This is useful for determining multi-threaded structure padding or SIMD78* prefetch sizes.79*80* \returns the L1 cache line size of the CPU, in bytes.81*82* \threadsafety It is safe to call this function from any thread.83*84* \since This function is available since SDL 3.2.0.85*/86extern SDL_DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void);8788/**89* Determine whether the CPU has AltiVec features.90*91* This always returns false on CPUs that aren't using PowerPC instruction92* sets.93*94* \returns true if the CPU has AltiVec features or false if not.95*96* \threadsafety It is safe to call this function from any thread.97*98* \since This function is available since SDL 3.2.0.99*/100extern SDL_DECLSPEC bool SDLCALL SDL_HasAltiVec(void);101102/**103* Determine whether the CPU has MMX features.104*105* This always returns false on CPUs that aren't using Intel instruction sets.106*107* \returns true if the CPU has MMX features or false if not.108*109* \threadsafety It is safe to call this function from any thread.110*111* \since This function is available since SDL 3.2.0.112*/113extern SDL_DECLSPEC bool SDLCALL SDL_HasMMX(void);114115/**116* Determine whether the CPU has SSE features.117*118* This always returns false on CPUs that aren't using Intel instruction sets.119*120* \returns true if the CPU has SSE features or false if not.121*122* \threadsafety It is safe to call this function from any thread.123*124* \since This function is available since SDL 3.2.0.125*126* \sa SDL_HasSSE2127* \sa SDL_HasSSE3128* \sa SDL_HasSSE41129* \sa SDL_HasSSE42130*/131extern SDL_DECLSPEC bool SDLCALL SDL_HasSSE(void);132133/**134* Determine whether the CPU has SSE2 features.135*136* This always returns false on CPUs that aren't using Intel instruction sets.137*138* \returns true if the CPU has SSE2 features or false if not.139*140* \threadsafety It is safe to call this function from any thread.141*142* \since This function is available since SDL 3.2.0.143*144* \sa SDL_HasSSE145* \sa SDL_HasSSE3146* \sa SDL_HasSSE41147* \sa SDL_HasSSE42148*/149extern SDL_DECLSPEC bool SDLCALL SDL_HasSSE2(void);150151/**152* Determine whether the CPU has SSE3 features.153*154* This always returns false on CPUs that aren't using Intel instruction sets.155*156* \returns true if the CPU has SSE3 features or false if not.157*158* \threadsafety It is safe to call this function from any thread.159*160* \since This function is available since SDL 3.2.0.161*162* \sa SDL_HasSSE163* \sa SDL_HasSSE2164* \sa SDL_HasSSE41165* \sa SDL_HasSSE42166*/167extern SDL_DECLSPEC bool SDLCALL SDL_HasSSE3(void);168169/**170* Determine whether the CPU has SSE4.1 features.171*172* This always returns false on CPUs that aren't using Intel instruction sets.173*174* \returns true if the CPU has SSE4.1 features or false if not.175*176* \threadsafety It is safe to call this function from any thread.177*178* \since This function is available since SDL 3.2.0.179*180* \sa SDL_HasSSE181* \sa SDL_HasSSE2182* \sa SDL_HasSSE3183* \sa SDL_HasSSE42184*/185extern SDL_DECLSPEC bool SDLCALL SDL_HasSSE41(void);186187/**188* Determine whether the CPU has SSE4.2 features.189*190* This always returns false on CPUs that aren't using Intel instruction sets.191*192* \returns true if the CPU has SSE4.2 features or false if not.193*194* \threadsafety It is safe to call this function from any thread.195*196* \since This function is available since SDL 3.2.0.197*198* \sa SDL_HasSSE199* \sa SDL_HasSSE2200* \sa SDL_HasSSE3201* \sa SDL_HasSSE41202*/203extern SDL_DECLSPEC bool SDLCALL SDL_HasSSE42(void);204205/**206* Determine whether the CPU has AVX features.207*208* This always returns false on CPUs that aren't using Intel instruction sets.209*210* \returns true if the CPU has AVX features or false if not.211*212* \threadsafety It is safe to call this function from any thread.213*214* \since This function is available since SDL 3.2.0.215*216* \sa SDL_HasAVX2217* \sa SDL_HasAVX512F218*/219extern SDL_DECLSPEC bool SDLCALL SDL_HasAVX(void);220221/**222* Determine whether the CPU has AVX2 features.223*224* This always returns false on CPUs that aren't using Intel instruction sets.225*226* \returns true if the CPU has AVX2 features or false if not.227*228* \threadsafety It is safe to call this function from any thread.229*230* \since This function is available since SDL 3.2.0.231*232* \sa SDL_HasAVX233* \sa SDL_HasAVX512F234*/235extern SDL_DECLSPEC bool SDLCALL SDL_HasAVX2(void);236237/**238* Determine whether the CPU has AVX-512F (foundation) features.239*240* This always returns false on CPUs that aren't using Intel instruction sets.241*242* \returns true if the CPU has AVX-512F features or false if not.243*244* \threadsafety It is safe to call this function from any thread.245*246* \since This function is available since SDL 3.2.0.247*248* \sa SDL_HasAVX249* \sa SDL_HasAVX2250*/251extern SDL_DECLSPEC bool SDLCALL SDL_HasAVX512F(void);252253/**254* Determine whether the CPU has ARM SIMD (ARMv6) features.255*256* This is different from ARM NEON, which is a different instruction set.257*258* This always returns false on CPUs that aren't using ARM instruction sets.259*260* \returns true if the CPU has ARM SIMD features or false if not.261*262* \threadsafety It is safe to call this function from any thread.263*264* \since This function is available since SDL 3.2.0.265*266* \sa SDL_HasNEON267*/268extern SDL_DECLSPEC bool SDLCALL SDL_HasARMSIMD(void);269270/**271* Determine whether the CPU has NEON (ARM SIMD) features.272*273* This always returns false on CPUs that aren't using ARM instruction sets.274*275* \returns true if the CPU has ARM NEON features or false if not.276*277* \threadsafety It is safe to call this function from any thread.278*279* \since This function is available since SDL 3.2.0.280*/281extern SDL_DECLSPEC bool SDLCALL SDL_HasNEON(void);282283/**284* Determine whether the CPU has LSX (LOONGARCH SIMD) features.285*286* This always returns false on CPUs that aren't using LOONGARCH instruction287* sets.288*289* \returns true if the CPU has LOONGARCH LSX features or false if not.290*291* \threadsafety It is safe to call this function from any thread.292*293* \since This function is available since SDL 3.2.0.294*/295extern SDL_DECLSPEC bool SDLCALL SDL_HasLSX(void);296297/**298* Determine whether the CPU has LASX (LOONGARCH SIMD) features.299*300* This always returns false on CPUs that aren't using LOONGARCH instruction301* sets.302*303* \returns true if the CPU has LOONGARCH LASX features or false if not.304*305* \threadsafety It is safe to call this function from any thread.306*307* \since This function is available since SDL 3.2.0.308*/309extern SDL_DECLSPEC bool SDLCALL SDL_HasLASX(void);310311/**312* Get the amount of RAM configured in the system.313*314* \returns the amount of RAM configured in the system in MiB.315*316* \threadsafety It is safe to call this function from any thread.317*318* \since This function is available since SDL 3.2.0.319*/320extern SDL_DECLSPEC int SDLCALL SDL_GetSystemRAM(void);321322/**323* Report the alignment this system needs for SIMD allocations.324*325* This will return the minimum number of bytes to which a pointer must be326* aligned to be compatible with SIMD instructions on the current machine. For327* example, if the machine supports SSE only, it will return 16, but if it328* supports AVX-512F, it'll return 64 (etc). This only reports values for329* instruction sets SDL knows about, so if your SDL build doesn't have330* SDL_HasAVX512F(), then it might return 16 for the SSE support it sees and331* not 64 for the AVX-512 instructions that exist but SDL doesn't know about.332* Plan accordingly.333*334* \returns the alignment in bytes needed for available, known SIMD335* instructions.336*337* \threadsafety It is safe to call this function from any thread.338*339* \since This function is available since SDL 3.2.0.340*341* \sa SDL_aligned_alloc342* \sa SDL_aligned_free343*/344extern SDL_DECLSPEC size_t SDLCALL SDL_GetSIMDAlignment(void);345346/* Ends C function definitions when using C++ */347#ifdef __cplusplus348}349#endif350#include <SDL3/SDL_close_code.h>351352#endif /* SDL_cpuinfo_h_ */353354355