SDL_cpuinfo.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2018 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 "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. #define __MMX__
  38. #define __3dNOW__
  39. #endif
  40. #define __SSE__
  41. #define __SSE2__
  42. #endif /* __clang__ */
  43. #elif defined(__MINGW64_VERSION_MAJOR)
  44. #include <intrin.h>
  45. #else
  46. #ifdef __ALTIVEC__
  47. #if HAVE_ALTIVEC_H && !defined(__APPLE_ALTIVEC__) && !defined(SDL_DISABLE_ALTIVEC_H)
  48. #include <altivec.h>
  49. #undef pixel
  50. #undef bool
  51. #endif
  52. #endif
  53. #if defined(__3dNOW__) && !defined(SDL_DISABLE_MM3DNOW_H)
  54. #include <mm3dnow.h>
  55. #endif
  56. #if HAVE_IMMINTRIN_H && !defined(SDL_DISABLE_IMMINTRIN_H)
  57. #include <immintrin.h>
  58. #else
  59. #if defined(__MMX__) && !defined(SDL_DISABLE_MMINTRIN_H)
  60. #include <mmintrin.h>
  61. #endif
  62. #if defined(__SSE__) && !defined(SDL_DISABLE_XMMINTRIN_H)
  63. #include <xmmintrin.h>
  64. #endif
  65. #if defined(__SSE2__) && !defined(SDL_DISABLE_EMMINTRIN_H)
  66. #include <emmintrin.h>
  67. #endif
  68. #if defined(__SSE3__) && !defined(SDL_DISABLE_PMMINTRIN_H)
  69. #include <pmmintrin.h>
  70. #endif
  71. #endif /* HAVE_IMMINTRIN_H */
  72. #endif /* compiler version */
  73. #include "begin_code.h"
  74. /* Set up for C function definitions, even when using C++ */
  75. #ifdef __cplusplus
  76. extern "C" {
  77. #endif
  78. /* This is a guess for the cacheline size used for padding.
  79. * Most x86 processors have a 64 byte cache line.
  80. * The 64-bit PowerPC processors have a 128 byte cache line.
  81. * We'll use the larger value to be generally safe.
  82. */
  83. #define SDL_CACHELINE_SIZE 128
  84. /**
  85. * This function returns the number of CPU cores available.
  86. */
  87. extern DECLSPEC int SDLCALL SDL_GetCPUCount(void);
  88. /**
  89. * This function returns the L1 cache line size of the CPU
  90. *
  91. * This is useful for determining multi-threaded structure padding
  92. * or SIMD prefetch sizes.
  93. */
  94. extern DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void);
  95. /**
  96. * This function returns true if the CPU has the RDTSC instruction.
  97. */
  98. extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void);
  99. /**
  100. * This function returns true if the CPU has AltiVec features.
  101. */
  102. extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void);
  103. /**
  104. * This function returns true if the CPU has MMX features.
  105. */
  106. extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void);
  107. /**
  108. * This function returns true if the CPU has 3DNow! features.
  109. */
  110. extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void);
  111. /**
  112. * This function returns true if the CPU has SSE features.
  113. */
  114. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void);
  115. /**
  116. * This function returns true if the CPU has SSE2 features.
  117. */
  118. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void);
  119. /**
  120. * This function returns true if the CPU has SSE3 features.
  121. */
  122. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void);
  123. /**
  124. * This function returns true if the CPU has SSE4.1 features.
  125. */
  126. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void);
  127. /**
  128. * This function returns true if the CPU has SSE4.2 features.
  129. */
  130. extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void);
  131. /**
  132. * This function returns true if the CPU has AVX features.
  133. */
  134. extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX(void);
  135. /**
  136. * This function returns true if the CPU has AVX2 features.
  137. */
  138. extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX2(void);
  139. /**
  140. * This function returns true if the CPU has NEON (ARM SIMD) features.
  141. */
  142. extern DECLSPEC SDL_bool SDLCALL SDL_HasNEON(void);
  143. /**
  144. * This function returns the amount of RAM configured in the system, in MB.
  145. */
  146. extern DECLSPEC int SDLCALL SDL_GetSystemRAM(void);
  147. /* Ends C function definitions when using C++ */
  148. #ifdef __cplusplus
  149. }
  150. #endif
  151. #include "close_code.h"
  152. #endif /* SDL_cpuinfo_h_ */
  153. /* vi: set ts=4 sw=4 expandtab: */