]> git.proxmox.com Git - ceph.git/blob - ceph/cmake/modules/SIMDExt.cmake
update sources to v12.1.0
[ceph.git] / ceph / cmake / modules / SIMDExt.cmake
1 # detect SIMD extentions
2 #
3 # HAVE_ARMV8_CRC
4 # HAVE_ARMV8_SIMD
5 # HAVE_ARM_NEON
6 # HAVE_INTEL_SSE
7 # HAVE_INTEL_SSE2
8 # HAVE_INTEL_SSE3
9 # HAVE_INTEL_SSSE3
10 # HAVE_INTEL_PCLMUL
11 # HAVE_INTEL_SSE4_1
12 # HAVE_INTEL_SSE4_2
13 #
14 # SIMD_COMPILE_FLAGS
15 #
16
17 if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64")
18 set(HAVE_ARM 1)
19 set(save_quiet ${CMAKE_REQUIRED_QUIET})
20 set(CMAKE_REQUIRED_QUIET true)
21 include(CheckCXXSourceCompiles)
22
23 check_cxx_source_compiles("
24 #define CRC32CX(crc, value) __asm__(\"crc32cx %w[c], %w[c], %x[v]\":[c]\"+r\"(crc):[v]\"r\"(value))
25 asm(\".arch_extension crc\");
26 unsigned int foo(unsigned int ret) {
27 CRC32CX(ret, 0);
28 return ret;
29 }
30 int main() { foo(0); }" HAVE_ARMV8_CRC)
31 check_cxx_source_compiles("
32 asm(\".arch_extension crypto\");
33 unsigned int foo(unsigned int ret) {
34 __asm__(\"pmull v2.1q, v2.1d, v1.1d\");
35 return ret;
36 }
37 int main() { foo(0); }" HAVE_ARMV8_CRYPTO)
38
39 set(CMAKE_REQUIRED_QUIET ${save_quiet})
40 if(HAVE_ARMV8_CRC)
41 message(STATUS " aarch64 crc extensions supported")
42 endif()
43
44 if(HAVE_ARMV8_CRYPTO)
45 message(STATUS " aarch64 crypto extensions supported")
46 endif()
47 CHECK_C_COMPILER_FLAG(-march=armv8-a+crc+crypto HAVE_ARMV8_CRC_CRYPTO_MARCH)
48
49 # don't believe only the -march support; gcc 4.8.5 on RHEL/CentOS says
50 # it supports +crc but hasn't got the intrinsics or arm_acle.h. Test for
51 # the actual presence of one of the intrinsic functions.
52 if(HAVE_ARMV8_CRC_CRYPTO_MARCH)
53 check_cxx_source_compiles("
54 #include <inttypes.h>
55 int main() { uint32_t a; uint8_t b; __builtin_aarch64_crc32b(a, b); }
56 " HAVE_ARMV8_CRC_CRYPTO_INTRINSICS)
57 endif()
58
59 if(HAVE_ARMV8_CRC_CRYPTO_INTRINSICS)
60 message(STATUS " aarch64 crc+crypto intrinsics supported")
61 set(ARMV8_CRC_COMPILE_FLAGS "${ARMV8_CRC_COMPILE_FLAGS} -march=armv8-a+crc+crypto")
62 endif()
63
64 CHECK_C_COMPILER_FLAG(-march=armv8-a+simd HAVE_ARMV8_SIMD)
65 if(HAVE_ARMV8_SIMD)
66 set(SIMD_COMPILE_FLAGS "${SIMD_COMPILE_FLAGS} -march=armv8-a+simd")
67 endif()
68
69 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm|ARM")
70 set(HAVE_ARM 1)
71 CHECK_C_COMPILER_FLAG(-mfpu=neon HAVE_ARM_NEON)
72 if(HAVE_ARM_NEON)
73 set(SIMD_COMPILE_FLAGS "${SIMD_COMPILE_FLAGS} -mfpu=neon")
74 endif()
75
76 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i386|i686|amd64|x86_64|AMD64")
77 set(HAVE_INTEL 1)
78 if(CMAKE_SYSTEM_PROCESSOR MATCHES "i686|amd64|x86_64|AMD64")
79 CHECK_C_COMPILER_FLAG(-msse HAVE_INTEL_SSE)
80 if(HAVE_INTEL_SSE)
81 set(SIMD_COMPILE_FLAGS "${SIMD_COMPILE_FLAGS} -msse")
82 endif()
83 if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64")
84 CHECK_C_COMPILER_FLAG(-msse2 HAVE_INTEL_SSE2)
85 if(HAVE_INTEL_SSE2)
86 set(SIMD_COMPILE_FLAGS "${SIMD_COMPILE_FLAGS} -msse2")
87 endif()
88 CHECK_C_COMPILER_FLAG(-msse3 HAVE_INTEL_SSE3)
89 if(HAVE_INTEL_SSE3)
90 set(SIMD_COMPILE_FLAGS "${SIMD_COMPILE_FLAGS} -msse3")
91 endif()
92 CHECK_C_COMPILER_FLAG(-mssse3 HAVE_INTEL_SSSE3)
93 if(HAVE_INTEL_SSSE3)
94 set(SIMD_COMPILE_FLAGS "${SIMD_COMPILE_FLAGS} -mssse3")
95 endif()
96 CHECK_C_COMPILER_FLAG(-mpclmul HAVE_INTEL_PCLMUL)
97 if(HAVE_INTEL_PCLMUL)
98 set(SIMD_COMPILE_FLAGS "${SIMD_COMPILE_FLAGS} -mpclmul")
99 endif()
100 CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_INTEL_SSE4_1)
101 if(HAVE_INTEL_SSE4_1)
102 set(SIMD_COMPILE_FLAGS "${SIMD_COMPILE_FLAGS} -msse4.1")
103 endif()
104 CHECK_C_COMPILER_FLAG(-msse4.2 HAVE_INTEL_SSE4_2)
105 if(HAVE_INTEL_SSE4_2)
106 set(SIMD_COMPILE_FLAGS "${SIMD_COMPILE_FLAGS} -msse4.2")
107 endif()
108 endif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64")
109 endif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686|amd64|x86_64|AMD64")
110 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(powerpc|ppc)64le")
111 set(HAVE_PPC64LE 1)
112 message(STATUS " we are ppc64le")
113 CHECK_C_COMPILER_FLAG("-maltivec" HAS_ALTIVEC)
114 if(HAS_ALTIVEC)
115 message(STATUS " HAS_ALTIVEC yes")
116 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maltivec")
117 set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -maltivec")
118 endif()
119 CHECK_C_COMPILER_FLAG("-mcpu=power8" HAVE_POWER8)
120 if(HAVE_POWER8)
121 message(STATUS " HAVE_POWER8 yes")
122 endif()
123 endif()