intrin.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright (c), Recep Aslantas.
  3. *
  4. * MIT License (MIT), http://opensource.org/licenses/MIT
  5. * Full license can be found in the LICENSE file
  6. */
  7. #ifndef cglm_intrin_h
  8. #define cglm_intrin_h
  9. #if defined(_MSC_VER) && !defined(_M_ARM64EC)
  10. # if (defined(_M_AMD64) || defined(_M_X64)) || _M_IX86_FP == 2
  11. # ifndef __SSE__
  12. # define __SSE__
  13. # endif
  14. # ifndef __SSE2__
  15. # define __SSE2__
  16. # endif
  17. # elif _M_IX86_FP == 1
  18. # ifndef __SSE__
  19. # define __SSE__
  20. # endif
  21. # endif
  22. /* do not use alignment for older visual studio versions */
  23. /* also ARM32 also causes similar error, disable it for now on ARM32 too */
  24. # if _MSC_VER < 1913 || _M_ARM /* Visual Studio 2017 version 15.6 */
  25. # define CGLM_ALL_UNALIGNED
  26. # endif
  27. #endif
  28. #ifdef __AVX__
  29. # include <immintrin.h>
  30. # define CGLM_AVX_FP 1
  31. # ifndef __SSE2__
  32. # define __SSE2__
  33. # endif
  34. # ifndef __SSE3__
  35. # define __SSE3__
  36. # endif
  37. # ifndef __SSE4__
  38. # define __SSE4__
  39. # endif
  40. # ifndef __SSE4_1__
  41. # define __SSE4_1__
  42. # endif
  43. # ifndef __SSE4_2__
  44. # define __SSE4_2__
  45. # endif
  46. # ifndef CGLM_SIMD_x86
  47. # define CGLM_SIMD_x86
  48. # endif
  49. #endif
  50. #if defined(__SSE__)
  51. # include <xmmintrin.h>
  52. # define CGLM_SSE_FP 1
  53. # ifndef CGLM_SIMD_x86
  54. # define CGLM_SIMD_x86
  55. # endif
  56. #endif
  57. #if defined(__SSE2__)
  58. # include <emmintrin.h>
  59. # define CGLM_SSE2_FP 1
  60. # ifndef CGLM_SIMD_x86
  61. # define CGLM_SIMD_x86
  62. # endif
  63. #endif
  64. #if defined(__SSE3__)
  65. # include <pmmintrin.h>
  66. # ifndef CGLM_SIMD_x86
  67. # define CGLM_SIMD_x86
  68. # endif
  69. #endif
  70. #if defined(__SSE4_1__)
  71. # include <smmintrin.h>
  72. # ifndef CGLM_SIMD_x86
  73. # define CGLM_SIMD_x86
  74. # endif
  75. #endif
  76. #if defined(__SSE4_2__)
  77. # include <nmmintrin.h>
  78. # ifndef CGLM_SIMD_x86
  79. # define CGLM_SIMD_x86
  80. # endif
  81. #endif
  82. /* ARM Neon */
  83. #if defined(_WIN32) && defined(_MSC_VER)
  84. /* TODO: non-ARM stuff already inported, will this be better option */
  85. /* # include <intrin.h> */
  86. # if defined(_M_ARM64) || defined(_M_HYBRID_X86_ARM64) || defined(_M_ARM64EC)
  87. # include <arm64intr.h>
  88. # include <arm64_neon.h>
  89. # ifndef CGLM_NEON_FP
  90. # define CGLM_NEON_FP 1
  91. # endif
  92. # ifndef CGLM_SIMD_ARM
  93. # define CGLM_SIMD_ARM
  94. # endif
  95. # elif defined(_M_ARM)
  96. # include <armintr.h>
  97. # include <arm_neon.h>
  98. # ifndef CGLM_NEON_FP
  99. # define CGLM_NEON_FP 1
  100. # endif
  101. # ifndef CGLM_SIMD_ARM
  102. # define CGLM_SIMD_ARM
  103. # endif
  104. # endif
  105. #else /* non-windows */
  106. # if defined(__ARM_NEON) || defined(__ARM_NEON__)
  107. # include <arm_neon.h>
  108. # if defined(__ARM_NEON_FP) || defined(__ARM_FP)
  109. # define CGLM_NEON_FP 1
  110. # endif
  111. # ifndef CGLM_SIMD_ARM
  112. # define CGLM_SIMD_ARM
  113. # endif
  114. # endif
  115. #endif
  116. /* WebAssembly */
  117. #if defined(__wasm__) && defined(__wasm_simd128__)
  118. # ifndef CGLM_SIMD_WASM
  119. # define CGLM_SIMD_WASM
  120. # endif
  121. #endif
  122. #if defined(CGLM_SIMD_x86) || defined(CGLM_SIMD_ARM) || defined(CGLM_SIMD_WASM)
  123. # ifndef CGLM_SIMD
  124. # define CGLM_SIMD
  125. # endif
  126. #endif
  127. #if defined(CGLM_SIMD_x86) && !defined(CGLM_SIMD_WASM)
  128. # include "x86.h"
  129. #endif
  130. #if defined(CGLM_SIMD_ARM)
  131. # include "arm.h"
  132. #endif
  133. #if defined(CGLM_SIMD_WASM)
  134. # include "wasm.h"
  135. #endif
  136. #endif /* cglm_intrin_h */