SDL_cpuinfo.h 4.0 KB

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