SDL_cpuinfo.h 9.8 KB

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