🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

299 lines
9.5 KiB

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2020 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. /**
  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 "SDL_stdinc.h"
  26. /* Need to do this here because intrin.h has C++ code in it */
  27. /* Visual Studio 2005 has a bug where intrin.h conflicts with winnt.h */
  28. #if defined(_MSC_VER) && (_MSC_VER >= 1500) && (defined(_M_IX86) || defined(_M_X64))
  29. #ifdef __clang__
  30. /* Many of the intrinsics SDL uses are not implemented by clang with Visual Studio */
  31. #undef __MMX__
  32. #undef __SSE__
  33. #undef __SSE2__
  34. #else
  35. #include <intrin.h>
  36. #ifndef _WIN64
  37. #ifndef __MMX__
  38. #define __MMX__
  39. #endif
  40. #ifndef __3dNOW__
  41. #define __3dNOW__
  42. #endif
  43. #endif
  44. #ifndef __SSE__
  45. #define __SSE__
  46. #endif
  47. #ifndef __SSE2__
  48. #define __SSE2__
  49. #endif
  50. #endif /* __clang__ */
  51. #elif defined(__MINGW64_VERSION_MAJOR)
  52. #include <intrin.h>
  53. #else
  54. /* altivec.h redefining bool causes a number of problems, see bugs 3993 and 4392, so you need to explicitly define SDL_ENABLE_ALTIVEC_H to have it included. */
  55. #if defined(HAVE_ALTIVEC_H) && defined(__ALTIVEC__) && !defined(__APPLE_ALTIVEC__) && defined(SDL_ENABLE_ALTIVEC_H)
  56. #include <altivec.h>
  57. #endif
  58. #if !defined(SDL_DISABLE_ARM_NEON_H)
  59. # if defined(__ARM_NEON)
  60. # include <arm_neon.h>
  61. # elif defined(__WINDOWS__) || defined(__WINRT__)
  62. /* Visual Studio doesn't define __ARM_ARCH, but _M_ARM (if set, always 7), and _M_ARM64 (if set, always 1). */
  63. # if defined(_M_ARM)
  64. # include <armintr.h>
  65. # include <arm_neon.h>
  66. # define __ARM_NEON 1 /* Set __ARM_NEON so that it can be used elsewhere, at compile time */
  67. # endif
  68. # if defined (_M_ARM64)
  69. # include <arm64intr.h>
  70. # include <arm64_neon.h>
  71. # define __ARM_NEON 1 /* Set __ARM_NEON so that it can be used elsewhere, at compile time */
  72. # endif
  73. # endif
  74. #endif
  75. #if defined(__3dNOW__) && !defined(SDL_DISABLE_MM3DNOW_H)
  76. #include <mm3dnow.h>
  77. #endif
  78. #if defined(HAVE_IMMINTRIN_H) && !defined(SDL_DISABLE_IMMINTRIN_H)
  79. #include <immintrin.h>
  80. #else
  81. #if defined(__MMX__) && !defined(SDL_DISABLE_MMINTRIN_H)
  82. #include <mmintrin.h>
  83. #endif
  84. #if defined(__SSE__) && !defined(SDL_DISABLE_XMMINTRIN_H)
  85. #include <xmmintrin.h>
  86. #endif
  87. #if defined(__SSE2__) && !defined(SDL_DISABLE_EMMINTRIN_H)
  88. #include <emmintrin.h>
  89. #endif
  90. #if defined(__SSE3__) && !defined(SDL_DISABLE_PMMINTRIN_H)
  91. #include <pmmintrin.h>
  92. #endif
  93. #endif /* HAVE_IMMINTRIN_H */
  94. #endif /* compiler version */
  95. #include "begin_code.h"
  96. /* Set up for C function definitions, even when using C++ */
  97. #ifdef __cplusplus
  98. extern "C" {
  99. #endif
  100. /* This is a guess for the cacheline size used for padding.
  101. * Most x86 processors have a 64 byte cache line.
  102. * The 64-bit PowerPC processors have a 128 byte cache line.
  103. * We'll use the larger value to be generally safe.
  104. */
  105. #define SDL_CACHELINE_SIZE 128
  106. /**
  107. * This function returns the number of CPU cores available.
  108. */
  109. extern DECLSPEC int SDLCALL SDL_GetCPUCount(void);
  110. /**
  111. * This function returns the L1 cache line size of the CPU
  112. *
  113. * This is useful for determining multi-threaded structure padding
  114. * or SIMD prefetch sizes.
  115. */
  116. extern DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void);
  117. /**
  118. * This function returns true if the CPU has the RDTSC instruction.
  119. */
  120. extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void);
  121. /**
  122. * This function returns true if the CPU has AltiVec features.
  123. */
  124. extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void);
  125. /**
  126. * This function returns true if the CPU has MMX features.
  127. */
  128. extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void);
  129. /**
  130. * This function returns true if the CPU has 3DNow! features.
  131. */
  132. extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void);
  133. /**
  134. * This function returns true if the CPU has SSE features.
  135. */
  136. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void);
  137. /**
  138. * This function returns true if the CPU has SSE2 features.
  139. */
  140. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void);
  141. /**
  142. * This function returns true if the CPU has SSE3 features.
  143. */
  144. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void);
  145. /**
  146. * This function returns true if the CPU has SSE4.1 features.
  147. */
  148. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void);
  149. /**
  150. * This function returns true if the CPU has SSE4.2 features.
  151. */
  152. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void);
  153. /**
  154. * This function returns true if the CPU has AVX features.
  155. */
  156. extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX(void);
  157. /**
  158. * This function returns true if the CPU has AVX2 features.
  159. */
  160. extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX2(void);
  161. /**
  162. * This function returns true if the CPU has AVX-512F (foundation) features.
  163. */
  164. extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX512F(void);
  165. /**
  166. * This function returns true if the CPU has ARM SIMD (ARMv6) features.
  167. */
  168. extern DECLSPEC SDL_bool SDLCALL SDL_HasARMSIMD(void);
  169. /**
  170. * This function returns true if the CPU has NEON (ARM SIMD) features.
  171. */
  172. extern DECLSPEC SDL_bool SDLCALL SDL_HasNEON(void);
  173. /**
  174. * This function returns the amount of RAM configured in the system, in MB.
  175. */
  176. extern DECLSPEC int SDLCALL SDL_GetSystemRAM(void);
  177. /**
  178. * \brief Report the alignment this system needs for SIMD allocations.
  179. *
  180. * This will return the minimum number of bytes to which a pointer must be
  181. * aligned to be compatible with SIMD instructions on the current machine.
  182. * For example, if the machine supports SSE only, it will return 16, but if
  183. * it supports AVX-512F, it'll return 64 (etc). This only reports values for
  184. * instruction sets SDL knows about, so if your SDL build doesn't have
  185. * SDL_HasAVX512F(), then it might return 16 for the SSE support it sees and
  186. * not 64 for the AVX-512 instructions that exist but SDL doesn't know about.
  187. * Plan accordingly.
  188. */
  189. extern DECLSPEC size_t SDLCALL SDL_SIMDGetAlignment(void);
  190. /**
  191. * \brief Allocate memory in a SIMD-friendly way.
  192. *
  193. * This will allocate a block of memory that is suitable for use with SIMD
  194. * instructions. Specifically, it will be properly aligned and padded for
  195. * the system's supported vector instructions.
  196. *
  197. * The memory returned will be padded such that it is safe to read or write
  198. * an incomplete vector at the end of the memory block. This can be useful
  199. * so you don't have to drop back to a scalar fallback at the end of your
  200. * SIMD processing loop to deal with the final elements without overflowing
  201. * the allocated buffer.
  202. *
  203. * You must free this memory with SDL_FreeSIMD(), not free() or SDL_free()
  204. * or delete[], etc.
  205. *
  206. * Note that SDL will only deal with SIMD instruction sets it is aware of;
  207. * for example, SDL 2.0.8 knows that SSE wants 16-byte vectors
  208. * (SDL_HasSSE()), and AVX2 wants 32 bytes (SDL_HasAVX2()), but doesn't
  209. * know that AVX-512 wants 64. To be clear: if you can't decide to use an
  210. * instruction set with an SDL_Has*() function, don't use that instruction
  211. * set with memory allocated through here.
  212. *
  213. * SDL_AllocSIMD(0) will return a non-NULL pointer, assuming the system isn't
  214. * out of memory.
  215. *
  216. * \param len The length, in bytes, of the block to allocated. The actual
  217. * allocated block might be larger due to padding, etc.
  218. * \return Pointer to newly-allocated block, NULL if out of memory.
  219. *
  220. * \sa SDL_SIMDAlignment
  221. * \sa SDL_SIMDRealloc
  222. * \sa SDL_SIMDFree
  223. */
  224. extern DECLSPEC void * SDLCALL SDL_SIMDAlloc(const size_t len);
  225. /**
  226. * \brief Reallocate memory obtained from SDL_SIMDAlloc
  227. *
  228. * It is not valid to use this function on a pointer from anything but
  229. * SDL_SIMDAlloc(). It can't be used on pointers from malloc, realloc,
  230. * SDL_malloc, memalign, new[], etc.
  231. *
  232. * \param mem The pointer obtained from SDL_SIMDAlloc. This function also
  233. * accepts NULL, at which point this function is the same as
  234. * calling SDL_realloc with a NULL pointer.
  235. * \param len The length, in bytes, of the block to allocated. The actual
  236. * allocated block might be larger due to padding, etc. Passing 0
  237. * will return a non-NULL pointer, assuming the system isn't out of
  238. * memory.
  239. * \return Pointer to newly-reallocated block, NULL if out of memory.
  240. *
  241. * \sa SDL_SIMDAlignment
  242. * \sa SDL_SIMDAlloc
  243. * \sa SDL_SIMDFree
  244. */
  245. extern DECLSPEC void * SDLCALL SDL_SIMDRealloc(void *mem, size_t len);
  246. /**
  247. * \brief Deallocate memory obtained from SDL_SIMDAlloc
  248. *
  249. * It is not valid to use this function on a pointer from anything but
  250. * SDL_SIMDAlloc(). It can't be used on pointers from malloc, realloc,
  251. * SDL_malloc, memalign, new[], etc.
  252. *
  253. * However, SDL_SIMDFree(NULL) is a legal no-op.
  254. *
  255. * \sa SDL_SIMDAlloc
  256. * \sa SDL_SIMDRealloc
  257. */
  258. extern DECLSPEC void SDLCALL SDL_SIMDFree(void *ptr);
  259. /* vi: set ts=4 sw=4 expandtab: */
  260. /* Ends C function definitions when using C++ */
  261. #ifdef __cplusplus
  262. }
  263. #endif
  264. #include "close_code.h"
  265. #endif /* SDL_cpuinfo_h_ */
  266. /* vi: set ts=4 sw=4 expandtab: */