SDL_intrin.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. /*
  19. * Header file for CPU intrinsics for SDL
  20. */
  21. #ifndef SDL_intrin_h_
  22. #define SDL_intrin_h_
  23. #include <SDL3/SDL_stdinc.h>
  24. /* Need to do this here because intrin.h has C++ code in it */
  25. /* Visual Studio 2005 has a bug where intrin.h conflicts with winnt.h */
  26. #if defined(_MSC_VER) && (_MSC_VER >= 1500) && (defined(_M_IX86) || defined(_M_X64))
  27. #ifdef __clang__
  28. /* As of Clang 11, '_m_prefetchw' is conflicting with the winnt.h's version,
  29. so we define the needed '_m_prefetch' here as a pseudo-header, until the issue is fixed. */
  30. #ifndef __PRFCHWINTRIN_H
  31. #define __PRFCHWINTRIN_H
  32. static __inline__ void __attribute__((__always_inline__, __nodebug__))
  33. _m_prefetch(void *__P)
  34. {
  35. __builtin_prefetch (__P, 0, 3 /* _MM_HINT_T0 */);
  36. }
  37. #endif /* __PRFCHWINTRIN_H */
  38. #endif /* __clang__ */
  39. #include <intrin.h>
  40. #elif defined(__MINGW64_VERSION_MAJOR)
  41. #include <intrin.h>
  42. #if defined(__ARM_NEON) && !defined(SDL_DISABLE_NEON)
  43. # define SDL_NEON_INTRINSICS 1
  44. # include <arm_neon.h>
  45. #endif
  46. #else
  47. /* altivec.h redefining bool causes a number of problems, see bugs 3993 and 4392, so you need to explicitly define SDL_ENABLE_ALTIVEC to have it included. */
  48. #if defined(__ALTIVEC__) && defined(SDL_ENABLE_ALTIVEC)
  49. #define SDL_ALTIVEC_INTRINSICS 1
  50. #include <altivec.h>
  51. #endif
  52. #ifndef SDL_DISABLE_NEON
  53. # ifdef __ARM_NEON
  54. # define SDL_NEON_INTRINSICS 1
  55. # include <arm_neon.h>
  56. # elif defined(SDL_PLATFORM_WINDOWS)
  57. /* Visual Studio doesn't define __ARM_ARCH, but _M_ARM (if set, always 7), and _M_ARM64 (if set, always 1). */
  58. # ifdef _M_ARM
  59. # define SDL_NEON_INTRINSICS 1
  60. # include <armintr.h>
  61. # include <arm_neon.h>
  62. # define __ARM_NEON 1 /* Set __ARM_NEON so that it can be used elsewhere, at compile time */
  63. # endif
  64. # if defined (_M_ARM64)
  65. # define SDL_NEON_INTRINSICS 1
  66. # include <arm64intr.h>
  67. # include <arm64_neon.h>
  68. # define __ARM_NEON 1 /* Set __ARM_NEON so that it can be used elsewhere, at compile time */
  69. # define __ARM_ARCH 8
  70. # endif
  71. # endif
  72. #endif
  73. #endif /* compiler version */
  74. #if defined(__clang__) && defined(__has_attribute)
  75. # if __has_attribute(target)
  76. # define SDL_HAS_TARGET_ATTRIBS
  77. # endif
  78. #elif defined(__GNUC__) && (__GNUC__ + (__GNUC_MINOR__ >= 9) > 4) /* gcc >= 4.9 */
  79. # define SDL_HAS_TARGET_ATTRIBS
  80. #elif defined(__ICC) && __ICC >= 1600
  81. # define SDL_HAS_TARGET_ATTRIBS
  82. #endif
  83. #ifdef SDL_HAS_TARGET_ATTRIBS
  84. # define SDL_TARGETING(x) __attribute__((target(x)))
  85. #else
  86. # define SDL_TARGETING(x)
  87. #endif
  88. #ifdef __loongarch64
  89. # ifndef SDL_DISABLE_LSX
  90. # define SDL_LSX_INTRINSICS 1
  91. # include <lsxintrin.h>
  92. # endif
  93. # ifndef SDL_DISABLE_LASX
  94. # define SDL_LASX_INTRINSICS 1
  95. # include <lasxintrin.h>
  96. # endif
  97. #endif
  98. #if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86)
  99. # if ((defined(_MSC_VER) && !defined(_M_X64)) || defined(__MMX__) || defined(SDL_HAS_TARGET_ATTRIBS)) && !defined(SDL_DISABLE_MMX)
  100. # define SDL_MMX_INTRINSICS 1
  101. # include <mmintrin.h>
  102. # endif
  103. # if (defined(_MSC_VER) || defined(__SSE__) || defined(SDL_HAS_TARGET_ATTRIBS)) && !defined(SDL_DISABLE_SSE)
  104. # define SDL_SSE_INTRINSICS 1
  105. # include <xmmintrin.h>
  106. # endif
  107. # if (defined(_MSC_VER) || defined(__SSE2__) || defined(SDL_HAS_TARGET_ATTRIBS)) && !defined(SDL_DISABLE_SSE2)
  108. # define SDL_SSE2_INTRINSICS 1
  109. # include <emmintrin.h>
  110. # endif
  111. # if (defined(_MSC_VER) || defined(__SSE3__) || defined(SDL_HAS_TARGET_ATTRIBS)) && !defined(SDL_DISABLE_SSE3)
  112. # define SDL_SSE3_INTRINSICS 1
  113. # include <pmmintrin.h>
  114. # endif
  115. # if (defined(_MSC_VER) || defined(__SSE4_1__) || defined(SDL_HAS_TARGET_ATTRIBS)) && !defined(SDL_DISABLE_SSE4_1)
  116. # define SDL_SSE4_1_INTRINSICS 1
  117. # include <smmintrin.h>
  118. # endif
  119. # if (defined(_MSC_VER) || defined(__SSE4_2__) || defined(SDL_HAS_TARGET_ATTRIBS)) && !defined(SDL_DISABLE_SSE4_2)
  120. # define SDL_SSE4_2_INTRINSICS 1
  121. # include <nmmintrin.h>
  122. # endif
  123. # if defined(__clang__) && (defined(_MSC_VER) || defined(__SCE__)) && !defined(__AVX__) && !defined(SDL_DISABLE_AVX)
  124. # define SDL_DISABLE_AVX /* see https://reviews.llvm.org/D20291 and https://reviews.llvm.org/D79194 */
  125. # endif
  126. # if (defined(_MSC_VER) || defined(__AVX__) || defined(SDL_HAS_TARGET_ATTRIBS)) && !defined(_M_ARM64EC) && !defined(SDL_DISABLE_AVX)
  127. # define SDL_AVX_INTRINSICS 1
  128. # include <immintrin.h>
  129. # endif
  130. # if defined(__clang__) && (defined(_MSC_VER) || defined(__SCE__)) && !defined(__AVX2__) && !defined(SDL_DISABLE_AVX2)
  131. # define SDL_DISABLE_AVX2 /* see https://reviews.llvm.org/D20291 and https://reviews.llvm.org/D79194 */
  132. # endif
  133. # if (defined(_MSC_VER) || defined(__AVX2__) || defined(SDL_HAS_TARGET_ATTRIBS)) && !defined(_M_ARM64EC) && !defined(SDL_DISABLE_AVX2)
  134. # define SDL_AVX2_INTRINSICS 1
  135. # include <immintrin.h>
  136. # endif
  137. # if defined(__clang__) && (defined(_MSC_VER) || defined(__SCE__)) && !defined(__AVX512F__) && !defined(SDL_DISABLE_AVX512F)
  138. # define SDL_DISABLE_AVX512F /* see https://reviews.llvm.org/D20291 and https://reviews.llvm.org/D79194 */
  139. # endif
  140. # if (defined(_MSC_VER) || defined(__AVX512F__) || defined(SDL_HAS_TARGET_ATTRIBS)) && !defined(_M_ARM64EC) && !defined(SDL_DISABLE_AVX512F)
  141. # define SDL_AVX512F_INTRINSICS 1
  142. # include <immintrin.h>
  143. # endif
  144. #endif /* defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86) */
  145. #endif /* SDL_intrin_h_ */