SDL_cpuinfo.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 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. * \brief 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. * \sa SDL_HasAVX
  69. * \sa SDL_HasAVX2
  70. * \sa SDL_HasMMX
  71. * \sa SDL_HasSSE
  72. * \sa SDL_HasSSE2
  73. * \sa SDL_HasSSE3
  74. * \sa SDL_HasSSE41
  75. * \sa SDL_HasSSE42
  76. */
  77. extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void);
  78. /**
  79. * Determine whether the CPU has MMX features.
  80. *
  81. * This always returns false on CPUs that aren't using Intel instruction sets.
  82. *
  83. * \returns SDL_TRUE if the CPU has MMX features or SDL_FALSE if not.
  84. *
  85. * \since This function is available since SDL 3.0.0.
  86. *
  87. * \sa SDL_HasAltiVec
  88. * \sa SDL_HasAVX
  89. * \sa SDL_HasAVX2
  90. * \sa SDL_HasSSE
  91. * \sa SDL_HasSSE2
  92. * \sa SDL_HasSSE3
  93. * \sa SDL_HasSSE41
  94. * \sa SDL_HasSSE42
  95. */
  96. extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void);
  97. /**
  98. * Determine whether the CPU has SSE features.
  99. *
  100. * This always returns false on CPUs that aren't using Intel instruction sets.
  101. *
  102. * \returns SDL_TRUE if the CPU has SSE features or SDL_FALSE if not.
  103. *
  104. * \since This function is available since SDL 3.0.0.
  105. *
  106. * \sa SDL_HasAltiVec
  107. * \sa SDL_HasAVX
  108. * \sa SDL_HasAVX2
  109. * \sa SDL_HasMMX
  110. * \sa SDL_HasSSE2
  111. * \sa SDL_HasSSE3
  112. * \sa SDL_HasSSE41
  113. * \sa SDL_HasSSE42
  114. */
  115. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void);
  116. /**
  117. * Determine whether the CPU has SSE2 features.
  118. *
  119. * This always returns false on CPUs that aren't using Intel instruction sets.
  120. *
  121. * \returns SDL_TRUE if the CPU has SSE2 features or SDL_FALSE if not.
  122. *
  123. * \since This function is available since SDL 3.0.0.
  124. *
  125. * \sa SDL_HasAltiVec
  126. * \sa SDL_HasAVX
  127. * \sa SDL_HasAVX2
  128. * \sa SDL_HasMMX
  129. * \sa SDL_HasSSE
  130. * \sa SDL_HasSSE3
  131. * \sa SDL_HasSSE41
  132. * \sa SDL_HasSSE42
  133. */
  134. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void);
  135. /**
  136. * Determine whether the CPU has SSE3 features.
  137. *
  138. * This always returns false on CPUs that aren't using Intel instruction sets.
  139. *
  140. * \returns SDL_TRUE if the CPU has SSE3 features or SDL_FALSE if not.
  141. *
  142. * \since This function is available since SDL 3.0.0.
  143. *
  144. * \sa SDL_HasAltiVec
  145. * \sa SDL_HasAVX
  146. * \sa SDL_HasAVX2
  147. * \sa SDL_HasMMX
  148. * \sa SDL_HasSSE
  149. * \sa SDL_HasSSE2
  150. * \sa SDL_HasSSE41
  151. * \sa SDL_HasSSE42
  152. */
  153. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void);
  154. /**
  155. * Determine whether the CPU has SSE4.1 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 SSE4.1 features or SDL_FALSE if not.
  160. *
  161. * \since This function is available since SDL 3.0.0.
  162. *
  163. * \sa SDL_HasAltiVec
  164. * \sa SDL_HasAVX
  165. * \sa SDL_HasAVX2
  166. * \sa SDL_HasMMX
  167. * \sa SDL_HasSSE
  168. * \sa SDL_HasSSE2
  169. * \sa SDL_HasSSE3
  170. * \sa SDL_HasSSE42
  171. */
  172. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void);
  173. /**
  174. * Determine whether the CPU has SSE4.2 features.
  175. *
  176. * This always returns false on CPUs that aren't using Intel instruction sets.
  177. *
  178. * \returns SDL_TRUE if the CPU has SSE4.2 features or SDL_FALSE if not.
  179. *
  180. * \since This function is available since SDL 3.0.0.
  181. *
  182. * \sa SDL_HasAltiVec
  183. * \sa SDL_HasAVX
  184. * \sa SDL_HasAVX2
  185. * \sa SDL_HasMMX
  186. * \sa SDL_HasSSE
  187. * \sa SDL_HasSSE2
  188. * \sa SDL_HasSSE3
  189. * \sa SDL_HasSSE41
  190. */
  191. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void);
  192. /**
  193. * Determine whether the CPU has AVX features.
  194. *
  195. * This always returns false on CPUs that aren't using Intel instruction sets.
  196. *
  197. * \returns SDL_TRUE if the CPU has AVX features or SDL_FALSE if not.
  198. *
  199. * \since This function is available since SDL 3.0.0.
  200. *
  201. * \sa SDL_HasAltiVec
  202. * \sa SDL_HasAVX2
  203. * \sa SDL_HasMMX
  204. * \sa SDL_HasSSE
  205. * \sa SDL_HasSSE2
  206. * \sa SDL_HasSSE3
  207. * \sa SDL_HasSSE41
  208. * \sa SDL_HasSSE42
  209. */
  210. extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX(void);
  211. /**
  212. * Determine whether the CPU has AVX2 features.
  213. *
  214. * This always returns false on CPUs that aren't using Intel instruction sets.
  215. *
  216. * \returns SDL_TRUE if the CPU has AVX2 features or SDL_FALSE if not.
  217. *
  218. * \since This function is available since SDL 3.0.0.
  219. *
  220. * \sa SDL_HasAltiVec
  221. * \sa SDL_HasAVX
  222. * \sa SDL_HasMMX
  223. * \sa SDL_HasSSE
  224. * \sa SDL_HasSSE2
  225. * \sa SDL_HasSSE3
  226. * \sa SDL_HasSSE41
  227. * \sa SDL_HasSSE42
  228. */
  229. extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX2(void);
  230. /**
  231. * Determine whether the CPU has AVX-512F (foundation) features.
  232. *
  233. * This always returns false on CPUs that aren't using Intel instruction sets.
  234. *
  235. * \returns SDL_TRUE if the CPU has AVX-512F features or SDL_FALSE if not.
  236. *
  237. * \since This function is available since SDL 3.0.0.
  238. *
  239. * \sa SDL_HasAVX
  240. */
  241. extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX512F(void);
  242. /**
  243. * Determine whether the CPU has ARM SIMD (ARMv6) features.
  244. *
  245. * This is different from ARM NEON, which is a different instruction set.
  246. *
  247. * This always returns false on CPUs that aren't using ARM instruction sets.
  248. *
  249. * \returns SDL_TRUE if the CPU has ARM SIMD features or SDL_FALSE if not.
  250. *
  251. * \since This function is available since SDL 3.0.0.
  252. *
  253. * \sa SDL_HasNEON
  254. */
  255. extern DECLSPEC SDL_bool SDLCALL SDL_HasARMSIMD(void);
  256. /**
  257. * Determine whether the CPU has NEON (ARM SIMD) features.
  258. *
  259. * This always returns false on CPUs that aren't using ARM instruction sets.
  260. *
  261. * \returns SDL_TRUE if the CPU has ARM NEON features or SDL_FALSE if not.
  262. *
  263. * \since This function is available since SDL 3.0.0.
  264. */
  265. extern DECLSPEC SDL_bool SDLCALL SDL_HasNEON(void);
  266. /**
  267. * Determine whether the CPU has LSX (LOONGARCH SIMD) features.
  268. *
  269. * This always returns false on CPUs that aren't using LOONGARCH instruction
  270. * sets.
  271. *
  272. * \returns SDL_TRUE if the CPU has LOONGARCH LSX features or SDL_FALSE if
  273. * not.
  274. *
  275. * \since This function is available since SDL 3.0.0.
  276. */
  277. extern DECLSPEC SDL_bool SDLCALL SDL_HasLSX(void);
  278. /**
  279. * Determine whether the CPU has LASX (LOONGARCH SIMD) features.
  280. *
  281. * This always returns false on CPUs that aren't using LOONGARCH instruction
  282. * sets.
  283. *
  284. * \returns SDL_TRUE if the CPU has LOONGARCH LASX features or SDL_FALSE if
  285. * not.
  286. *
  287. * \since This function is available since SDL 3.0.0.
  288. */
  289. extern DECLSPEC SDL_bool SDLCALL SDL_HasLASX(void);
  290. /**
  291. * Get the amount of RAM configured in the system.
  292. *
  293. * \returns the amount of RAM configured in the system in MiB.
  294. *
  295. * \since This function is available since SDL 3.0.0.
  296. */
  297. extern DECLSPEC int SDLCALL SDL_GetSystemRAM(void);
  298. /**
  299. * Report the alignment this system needs for SIMD allocations.
  300. *
  301. * This will return the minimum number of bytes to which a pointer must be
  302. * aligned to be compatible with SIMD instructions on the current machine. For
  303. * example, if the machine supports SSE only, it will return 16, but if it
  304. * supports AVX-512F, it'll return 64 (etc). This only reports values for
  305. * instruction sets SDL knows about, so if your SDL build doesn't have
  306. * SDL_HasAVX512F(), then it might return 16 for the SSE support it sees and
  307. * not 64 for the AVX-512 instructions that exist but SDL doesn't know about.
  308. * Plan accordingly.
  309. *
  310. * \returns the alignment in bytes needed for available, known SIMD
  311. * instructions.
  312. *
  313. * \since This function is available since SDL 3.0.0.
  314. *
  315. * \sa SDL_aligned_alloc
  316. * \sa SDL_aligned_free
  317. */
  318. extern DECLSPEC size_t SDLCALL SDL_SIMDGetAlignment(void);
  319. /* Ends C function definitions when using C++ */
  320. #ifdef __cplusplus
  321. }
  322. #endif
  323. #include <SDL3/SDL_close_code.h>
  324. #endif /* SDL_cpuinfo_h_ */