SDL_cpuinfo.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /* WIKI CATEGORY: CPUInfo */
  19. /**
  20. * \file SDL_cpuinfo.h
  21. *
  22. * CPU feature detection for SDL.
  23. */
  24. #ifndef SDL_cpuinfo_h_
  25. #define SDL_cpuinfo_h_
  26. #include <SDL3/SDL_stdinc.h>
  27. #include <SDL3/SDL_begin_code.h>
  28. /* Set up for C function definitions, even when using C++ */
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /**
  33. * A guess for the cacheline size used for padding.
  34. *
  35. * Most x86 processors have a 64 byte cache line. The 64-bit PowerPC
  36. * processors have a 128 byte cache line. We use the larger value to be
  37. * generally safe.
  38. *
  39. * \since This macro is available since SDL 3.0.0.
  40. */
  41. #define SDL_CACHELINE_SIZE 128
  42. /**
  43. * Get the number of CPU cores available.
  44. *
  45. * \returns the total number of logical CPU cores. On CPUs that include
  46. * technologies such as hyperthreading, the number of logical cores
  47. * may be more than the number of physical cores.
  48. *
  49. * \since This function is available since SDL 3.0.0.
  50. */
  51. extern DECLSPEC int SDLCALL SDL_GetCPUCount(void);
  52. /**
  53. * Determine the L1 cache line size of the CPU.
  54. *
  55. * This is useful for determining multi-threaded structure padding or SIMD
  56. * prefetch sizes.
  57. *
  58. * \returns the L1 cache line size of the CPU, in bytes.
  59. *
  60. * \since This function is available since SDL 3.0.0.
  61. */
  62. extern DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void);
  63. /**
  64. * Determine whether the CPU has AltiVec features.
  65. *
  66. * This always returns false on CPUs that aren't using PowerPC instruction
  67. * sets.
  68. *
  69. * \returns SDL_TRUE if the CPU has AltiVec features or SDL_FALSE if not.
  70. *
  71. * \since This function is available since SDL 3.0.0.
  72. */
  73. extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void);
  74. /**
  75. * Determine whether the CPU has MMX features.
  76. *
  77. * This always returns false on CPUs that aren't using Intel instruction sets.
  78. *
  79. * \returns SDL_TRUE if the CPU has MMX features or SDL_FALSE if not.
  80. *
  81. * \since This function is available since SDL 3.0.0.
  82. */
  83. extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void);
  84. /**
  85. * Determine whether the CPU has SSE features.
  86. *
  87. * This always returns false on CPUs that aren't using Intel instruction sets.
  88. *
  89. * \returns SDL_TRUE if the CPU has SSE features or SDL_FALSE if not.
  90. *
  91. * \since This function is available since SDL 3.0.0.
  92. *
  93. * \sa SDL_HasSSE2
  94. * \sa SDL_HasSSE3
  95. * \sa SDL_HasSSE41
  96. * \sa SDL_HasSSE42
  97. */
  98. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void);
  99. /**
  100. * Determine whether the CPU has SSE2 features.
  101. *
  102. * This always returns false on CPUs that aren't using Intel instruction sets.
  103. *
  104. * \returns SDL_TRUE if the CPU has SSE2 features or SDL_FALSE if not.
  105. *
  106. * \since This function is available since SDL 3.0.0.
  107. *
  108. * \sa SDL_HasSSE
  109. * \sa SDL_HasSSE3
  110. * \sa SDL_HasSSE41
  111. * \sa SDL_HasSSE42
  112. */
  113. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void);
  114. /**
  115. * Determine whether the CPU has SSE3 features.
  116. *
  117. * This always returns false on CPUs that aren't using Intel instruction sets.
  118. *
  119. * \returns SDL_TRUE if the CPU has SSE3 features or SDL_FALSE if not.
  120. *
  121. * \since This function is available since SDL 3.0.0.
  122. *
  123. * \sa SDL_HasSSE
  124. * \sa SDL_HasSSE2
  125. * \sa SDL_HasSSE41
  126. * \sa SDL_HasSSE42
  127. */
  128. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void);
  129. /**
  130. * Determine whether the CPU has SSE4.1 features.
  131. *
  132. * This always returns false on CPUs that aren't using Intel instruction sets.
  133. *
  134. * \returns SDL_TRUE if the CPU has SSE4.1 features or SDL_FALSE if not.
  135. *
  136. * \since This function is available since SDL 3.0.0.
  137. *
  138. * \sa SDL_HasSSE
  139. * \sa SDL_HasSSE2
  140. * \sa SDL_HasSSE3
  141. * \sa SDL_HasSSE42
  142. */
  143. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void);
  144. /**
  145. * Determine whether the CPU has SSE4.2 features.
  146. *
  147. * This always returns false on CPUs that aren't using Intel instruction sets.
  148. *
  149. * \returns SDL_TRUE if the CPU has SSE4.2 features or SDL_FALSE if not.
  150. *
  151. * \since This function is available since SDL 3.0.0.
  152. *
  153. * \sa SDL_HasSSE
  154. * \sa SDL_HasSSE2
  155. * \sa SDL_HasSSE3
  156. * \sa SDL_HasSSE41
  157. */
  158. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void);
  159. /**
  160. * Determine whether the CPU has AVX features.
  161. *
  162. * This always returns false on CPUs that aren't using Intel instruction sets.
  163. *
  164. * \returns SDL_TRUE if the CPU has AVX features or SDL_FALSE if not.
  165. *
  166. * \since This function is available since SDL 3.0.0.
  167. *
  168. * \sa SDL_HasAVX2
  169. * \sa SDL_HasAVX512F
  170. */
  171. extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX(void);
  172. /**
  173. * Determine whether the CPU has AVX2 features.
  174. *
  175. * This always returns false on CPUs that aren't using Intel instruction sets.
  176. *
  177. * \returns SDL_TRUE if the CPU has AVX2 features or SDL_FALSE if not.
  178. *
  179. * \since This function is available since SDL 3.0.0.
  180. *
  181. * \sa SDL_HasAVX
  182. * \sa SDL_HasAVX512F
  183. */
  184. extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX2(void);
  185. /**
  186. * Determine whether the CPU has AVX-512F (foundation) features.
  187. *
  188. * This always returns false on CPUs that aren't using Intel instruction sets.
  189. *
  190. * \returns SDL_TRUE if the CPU has AVX-512F features or SDL_FALSE if not.
  191. *
  192. * \since This function is available since SDL 3.0.0.
  193. *
  194. * \sa SDL_HasAVX
  195. * \sa SDL_HasAVX2
  196. */
  197. extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX512F(void);
  198. /**
  199. * Determine whether the CPU has ARM SIMD (ARMv6) features.
  200. *
  201. * This is different from ARM NEON, which is a different instruction set.
  202. *
  203. * This always returns false on CPUs that aren't using ARM instruction sets.
  204. *
  205. * \returns SDL_TRUE if the CPU has ARM SIMD features or SDL_FALSE if not.
  206. *
  207. * \since This function is available since SDL 3.0.0.
  208. *
  209. * \sa SDL_HasNEON
  210. */
  211. extern DECLSPEC SDL_bool SDLCALL SDL_HasARMSIMD(void);
  212. /**
  213. * Determine whether the CPU has NEON (ARM SIMD) features.
  214. *
  215. * This always returns false on CPUs that aren't using ARM instruction sets.
  216. *
  217. * \returns SDL_TRUE if the CPU has ARM NEON features or SDL_FALSE if not.
  218. *
  219. * \since This function is available since SDL 3.0.0.
  220. */
  221. extern DECLSPEC SDL_bool SDLCALL SDL_HasNEON(void);
  222. /**
  223. * Determine whether the CPU has LSX (LOONGARCH SIMD) features.
  224. *
  225. * This always returns false on CPUs that aren't using LOONGARCH instruction
  226. * sets.
  227. *
  228. * \returns SDL_TRUE if the CPU has LOONGARCH LSX features or SDL_FALSE if
  229. * not.
  230. *
  231. * \since This function is available since SDL 3.0.0.
  232. */
  233. extern DECLSPEC SDL_bool SDLCALL SDL_HasLSX(void);
  234. /**
  235. * Determine whether the CPU has LASX (LOONGARCH SIMD) features.
  236. *
  237. * This always returns false on CPUs that aren't using LOONGARCH instruction
  238. * sets.
  239. *
  240. * \returns SDL_TRUE if the CPU has LOONGARCH LASX features or SDL_FALSE if
  241. * not.
  242. *
  243. * \since This function is available since SDL 3.0.0.
  244. */
  245. extern DECLSPEC SDL_bool SDLCALL SDL_HasLASX(void);
  246. /**
  247. * Get the amount of RAM configured in the system.
  248. *
  249. * \returns the amount of RAM configured in the system in MiB.
  250. *
  251. * \since This function is available since SDL 3.0.0.
  252. */
  253. extern DECLSPEC int SDLCALL SDL_GetSystemRAM(void);
  254. /**
  255. * Report the alignment this system needs for SIMD allocations.
  256. *
  257. * This will return the minimum number of bytes to which a pointer must be
  258. * aligned to be compatible with SIMD instructions on the current machine. For
  259. * example, if the machine supports SSE only, it will return 16, but if it
  260. * supports AVX-512F, it'll return 64 (etc). This only reports values for
  261. * instruction sets SDL knows about, so if your SDL build doesn't have
  262. * SDL_HasAVX512F(), then it might return 16 for the SSE support it sees and
  263. * not 64 for the AVX-512 instructions that exist but SDL doesn't know about.
  264. * Plan accordingly.
  265. *
  266. * \returns the alignment in bytes needed for available, known SIMD
  267. * instructions.
  268. *
  269. * \since This function is available since SDL 3.0.0.
  270. *
  271. * \sa SDL_aligned_alloc
  272. * \sa SDL_aligned_free
  273. */
  274. extern DECLSPEC size_t SDLCALL SDL_SIMDGetAlignment(void);
  275. /* Ends C function definitions when using C++ */
  276. #ifdef __cplusplus
  277. }
  278. #endif
  279. #include <SDL3/SDL_close_code.h>
  280. #endif /* SDL_cpuinfo_h_ */