1
0

SDL_cpuinfo.h 8.7 KB

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