SDL_cpuinfo.h 8.5 KB

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