CheckSSEFeatures.cmake 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. macro (PCL_CHECK_FOR_SSE)
  2. include(CheckCXXSourceRuns)
  3. set(CMAKE_REQUIRED_FLAGS "-march=native")
  4. check_cxx_source_runs("
  5. #include <immintrin.h>
  6. int main()
  7. {
  8. volatile __m256i a, b;
  9. a = _mm256_set1_epi8 (1);
  10. b = _mm256_add_epi8 (a,a);
  11. return 0;
  12. }"
  13. HAVE_AVX2_EXTENSIONS)
  14. check_cxx_source_runs("
  15. #include <immintrin.h>
  16. int main()
  17. {
  18. __m256 a, b;
  19. float vals[8] = {1, 2, 3, 4, 5, 6, 7, 8};
  20. const int mask = 123;
  21. a = _mm256_loadu_ps(vals);
  22. b = a;
  23. b = _mm256_dp_ps (a, a, 3);
  24. _mm256_storeu_ps(vals,b);
  25. return 0;
  26. }"
  27. HAVE_AVX_EXTENSIONS)
  28. check_cxx_source_runs("
  29. #include <nmmintrin.h>
  30. int main ()
  31. {
  32. long long a[2] = { 1, 2 };
  33. long long b[2] = { -1, 3 };
  34. long long c[2];
  35. __m128i va = _mm_loadu_si128 ((__m128i*)a);
  36. __m128i vb = _mm_loadu_si128 ((__m128i*)b);
  37. __m128i vc = _mm_cmpgt_epi64 (va, vb);
  38. _mm_storeu_si128 ((__m128i*)c, vc);
  39. return 0;
  40. }"
  41. HAVE_SSE4_2_EXTENSIONS)
  42. check_cxx_source_runs("
  43. #include <smmintrin.h>
  44. int main ()
  45. {
  46. volatile __m128 a, b;
  47. float vals[4] = {1, 2, 3, 4};
  48. const int mask = 123;
  49. a = _mm_loadu_ps (vals);
  50. b = a;
  51. b = _mm_dp_ps (a, a, 4);
  52. _mm_storeu_ps (vals,b);
  53. return (0);
  54. }"
  55. HAVE_SSE4_1_EXTENSIONS)
  56. check_cxx_source_runs("
  57. #include <pmmintrin.h>
  58. int main ()
  59. {
  60. volatile __m128d a, b;
  61. double vals[2] = {0};
  62. a = _mm_loadu_pd (vals);
  63. b = _mm_hadd_pd (a,a);
  64. _mm_storeu_pd (vals, b);
  65. return (0);
  66. }"
  67. HAVE_SSE3_EXTENSIONS)
  68. check_cxx_source_runs("
  69. #include <emmintrin.h>
  70. int main ()
  71. {
  72. volatile __m128d a, b;
  73. double vals[2] = {0};
  74. a = _mm_loadu_pd (vals);
  75. b = _mm_add_pd (a,a);
  76. _mm_storeu_pd (vals,b);
  77. return (0);
  78. }"
  79. HAVE_SSE2_EXTENSIONS)
  80. check_cxx_source_runs("
  81. #include <xmmintrin.h>
  82. int main ()
  83. {
  84. volatile __m128 a, b;
  85. float vals[4] = {0};
  86. a = _mm_loadu_ps (vals);
  87. b = a;
  88. b = _mm_add_ps (a,b);
  89. _mm_storeu_ps (vals,b);
  90. return (0);
  91. }"
  92. HAVE_SSE_EXTENSIONS)
  93. set(CMAKE_REQUIRED_FLAGS)
  94. set(SSE_FLAGS)
  95. if(HAVE_AVX2_EXTENSIONS)
  96. if(CMAKE_COMPILER_IS_CLANG)
  97. SET(SSE_FLAGS "-mavx2")
  98. else()
  99. SET(SSE_FLAGS "-mavx2 -Wa,-q")
  100. endif()
  101. elseif(HAVE_AVX_EXTENSIONS)
  102. if(CMAKE_COMPILER_IS_CLANG)
  103. SET(SSE_FLAGS "-mavx")
  104. else()
  105. SET(SSE_FLAGS "-mavx -Wa,-q")
  106. endif()
  107. elseif(HAVE_SSE4_2_EXTENSIONS)
  108. SET(SSE_FLAGS "-msse4.2")
  109. elseif(HAVE_SSE4_1_EXTENSIONS)
  110. SET(SSE_FLAGS "-msse4.1")
  111. elseif(HAVE_SSE3_EXTENSIONS)
  112. SET(SSE_FLAGS "-msse3")
  113. elseif(HAVE_SSE2_EXTENSIONS)
  114. SET(SSE_FLAGS "-msse2")
  115. elseif(HAVE_SSE_EXTENSIONS)
  116. SET(SSE_FLAGS "-msse")
  117. endif()
  118. endmacro ()
  119. PCL_CHECK_FOR_SSE()