SDL_intrin.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 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_intrin.h
  20. *
  21. * Header file for CPU intrinsics for SDL
  22. */
  23. #ifndef SDL_intrin_h_
  24. #define SDL_intrin_h_
  25. #include <SDL3/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. /* As of Clang 11, '_m_prefetchw' is conflicting with the winnt.h's version,
  31. so we define the needed '_m_prefetch' here as a pseudo-header, until the issue is fixed. */
  32. #ifndef __PRFCHWINTRIN_H
  33. #define __PRFCHWINTRIN_H
  34. static __inline__ void __attribute__((__always_inline__, __nodebug__))
  35. _m_prefetch(void *__P)
  36. {
  37. __builtin_prefetch (__P, 0, 3 /* _MM_HINT_T0 */);
  38. }
  39. #endif /* __PRFCHWINTRIN_H */
  40. #endif /* __clang__ */
  41. #include <intrin.h>
  42. #ifndef _WIN64
  43. #ifndef __MMX__
  44. #define __MMX__
  45. #endif
  46. #endif
  47. #ifndef __SSE__
  48. #define __SSE__
  49. #endif
  50. #ifndef __SSE2__
  51. #define __SSE2__
  52. #endif
  53. #ifndef __SSE3__
  54. #define __SSE3__
  55. #endif
  56. #elif defined(__MINGW64_VERSION_MAJOR)
  57. #include <intrin.h>
  58. #if !defined(SDL_DISABLE_ARM_NEON_H) && defined(__ARM_NEON)
  59. # include <arm_neon.h>
  60. #endif
  61. #else
  62. /* 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. */
  63. #if defined(HAVE_ALTIVEC_H) && defined(__ALTIVEC__) && !defined(__APPLE_ALTIVEC__) && defined(SDL_ENABLE_ALTIVEC_H)
  64. #include <altivec.h>
  65. #endif
  66. #if !defined(SDL_DISABLE_ARM_NEON_H)
  67. # if defined(__ARM_NEON)
  68. # include <arm_neon.h>
  69. # elif defined(__WINDOWS__) || defined(__WINRT__) || defined(__GDK__)
  70. /* Visual Studio doesn't define __ARM_ARCH, but _M_ARM (if set, always 7), and _M_ARM64 (if set, always 1). */
  71. # if defined(_M_ARM)
  72. # include <armintr.h>
  73. # include <arm_neon.h>
  74. # define __ARM_NEON 1 /* Set __ARM_NEON so that it can be used elsewhere, at compile time */
  75. # endif
  76. # if defined (_M_ARM64)
  77. # include <arm64intr.h>
  78. # include <arm64_neon.h>
  79. # define __ARM_NEON 1 /* Set __ARM_NEON so that it can be used elsewhere, at compile time */
  80. # define __ARM_ARCH 8
  81. # endif
  82. # endif
  83. #endif
  84. #endif /* compiler version */
  85. #if defined(__loongarch_sx) && !defined(SDL_DISABLE_LSX_H)
  86. #include <lsxintrin.h>
  87. #define __LSX__
  88. #endif
  89. #if defined(__loongarch_asx) && !defined(SDL_DISABLE_LASX_H)
  90. #include <lasxintrin.h>
  91. #define __LASX__
  92. #endif
  93. #if defined(HAVE_IMMINTRIN_H) && !defined(SDL_DISABLE_IMMINTRIN_H)
  94. #include <immintrin.h>
  95. #else
  96. #if defined(__MMX__) && !defined(SDL_DISABLE_MMINTRIN_H)
  97. #include <mmintrin.h>
  98. #endif
  99. #if defined(__SSE__) && !defined(SDL_DISABLE_XMMINTRIN_H)
  100. #include <xmmintrin.h>
  101. #endif
  102. #if defined(__SSE2__) && !defined(SDL_DISABLE_EMMINTRIN_H)
  103. #include <emmintrin.h>
  104. #endif
  105. #if defined(__SSE3__) && !defined(SDL_DISABLE_PMMINTRIN_H)
  106. #include <pmmintrin.h>
  107. #endif
  108. #endif /* HAVE_IMMINTRIN_H */
  109. #endif /* SDL_intrin_h_ */