You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ArchDep.cmake 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. TARGET_ARCHITECTURE(ARCH)
  2. SET(ASM_CODE "
  3. .macro TEST1 op
  4. \\op %eax, %eax
  5. .endm
  6. TEST1 xorl
  7. ")
  8. ASM_OP(HAVE_SLASHMACRO "slash macro convention")
  9. SET(ASM_CODE "
  10. .macro TEST1 op
  11. $0 %eax, %eax
  12. .endm
  13. TEST1 xorl
  14. ")
  15. ASM_OP(HAVE_DOLLARMACRO "dollar macro convention")
  16. # For now we support only x86_64/i386 architecture with optimizations
  17. IF("${ARCH}" STREQUAL "x86_64" OR "${ARCH}" STREQUAL "i386")
  18. IF(NOT HAVE_SLASHMACRO AND NOT HAVE_DOLLARMACRO)
  19. MESSAGE(FATAL_ERROR "Your assembler cannot compile macros, please check your CMakeFiles/CMakeError.log")
  20. ENDIF()
  21. SET(ASM_CODE "vpaddq %ymm0, %ymm0, %ymm0")
  22. ASM_OP(HAVE_AVX2 "avx2")
  23. # Handle broken compilers, sigh...
  24. IF(HAVE_AVX2)
  25. CHECK_C_SOURCE_COMPILES(
  26. "
  27. #include <stddef.h>
  28. #pragma GCC push_options
  29. #pragma GCC target(\"avx2\")
  30. #ifndef __SSE2__
  31. #define __SSE2__
  32. #endif
  33. #ifndef __SSE__
  34. #define __SSE__
  35. #endif
  36. #ifndef __SSE4_2__
  37. #define __SSE4_2__
  38. #endif
  39. #ifndef __SSE4_1__
  40. #define __SSE4_1__
  41. #endif
  42. #ifndef __SSEE3__
  43. #define __SSEE3__
  44. #endif
  45. #ifndef __AVX__
  46. #define __AVX__
  47. #endif
  48. #ifndef __AVX2__
  49. #define __AVX2__
  50. #endif
  51. #ifndef __clang__
  52. #if __GNUC__ < 6
  53. #error Broken due to compiler bug
  54. #endif
  55. #endif
  56. #include <immintrin.h>
  57. static void foo(const char* a) __attribute__((__target__(\"avx2\")));
  58. static void foo(const char* a)
  59. {
  60. __m256i str = _mm256_loadu_si256((__m256i *)a);
  61. __m256i t = _mm256_loadu_si256((__m256i *)a + 1);
  62. _mm256_add_epi8(str, t);
  63. }
  64. int main(int argc, char** argv) {
  65. foo(argv[0]);
  66. }" HAVE_AVX2_C_COMPILER)
  67. IF(NOT HAVE_AVX2_C_COMPILER)
  68. MESSAGE(STATUS "Your compiler has broken AVX2 support")
  69. UNSET(HAVE_AVX2 CACHE)
  70. ENDIF()
  71. ENDIF()
  72. SET(ASM_CODE "vpaddq %xmm0, %xmm0, %xmm0")
  73. ASM_OP(HAVE_AVX "avx")
  74. SET(ASM_CODE "pmuludq %xmm0, %xmm0")
  75. ASM_OP(HAVE_SSE2 "sse2")
  76. SET(ASM_CODE "lddqu 0(%esi), %xmm0")
  77. ASM_OP(HAVE_SSE3 "sse3")
  78. SET(ASM_CODE "pshufb %xmm0, %xmm0")
  79. ASM_OP(HAVE_SSSE3 "ssse3")
  80. SET(ASM_CODE "pblendw \$0, %xmm0, %xmm0")
  81. ASM_OP(HAVE_SSE41 "sse41")
  82. SET(ASM_CODE "crc32 %eax, %eax")
  83. ASM_OP(HAVE_SSE42 "sse42")
  84. ENDIF()
  85. IF ("${ARCH}" STREQUAL "x86_64")
  86. MESSAGE(STATUS "Enable sse2 on x86_64 architecture")
  87. IF((CMAKE_C_COMPILER_ID MATCHES "GNU") OR (CMAKE_C_COMPILER_ID MATCHES "Clang"))
  88. ADD_COMPILE_OPTIONS(-msse2)
  89. ADD_COMPILE_OPTIONS(-m64)
  90. ELSEIF(CMAKE_C_COMPILER_ID MATCHES "Intel")
  91. ADD_COMPILE_OPTIONS(/QxSSE2)
  92. ELSEIF((CMAKE_C_COMPILER_ID MATCHES "MSVC"))
  93. ADD_COMPILE_OPTIONS(/arch:SSE2)
  94. ENDIF()
  95. ENDIF()