cloudflare/ClickHouse
Publicmirrored fromhttps://github.com/cloudflare/ClickHouse
cmake/cpu_features.cmake
113lines · modecode
6 years ago
| 1 | # https://software.intel.com/sites/landingpage/IntrinsicsGuide/ |
| 2 | |
| 3 | include (CheckCXXSourceCompiles) |
| 4 | include (CMakePushCheckState) |
| 5 | |
| 6 | cmake_push_check_state () |
| 7 | |
| 8 | # gcc -dM -E -mno-sse2 - < /dev/null | sort > gcc-dump-nosse2 |
| 9 | # gcc -dM -E -msse2 - < /dev/null | sort > gcc-dump-sse2 |
| 10 | #define __SSE2__ 1 |
| 11 | #define __SSE2_MATH__ 1 |
| 12 | |
| 13 | # gcc -dM -E -msse4.1 - < /dev/null | sort > gcc-dump-sse41 |
| 14 | #define __SSE4_1__ 1 |
| 15 | |
| 16 | set (TEST_FLAG "-msse4.1") |
| 17 | set (CMAKE_REQUIRED_FLAGS "${TEST_FLAG} -O0") |
| 18 | check_cxx_source_compiles(" |
| 19 | #include <smmintrin.h> |
| 20 | int main() { |
| 21 | auto a = _mm_insert_epi8(__m128i(), 0, 0); |
| 22 | (void)a; |
| 23 | return 0; |
| 24 | } |
| 25 | " HAVE_SSE41) |
| 26 | if (HAVE_SSE41) |
| 27 | set (COMPILER_FLAGS "${COMPILER_FLAGS} ${TEST_FLAG}") |
| 28 | endif () |
| 29 | |
| 30 | if (ARCH_PPC64LE) |
| 31 | set (COMPILER_FLAGS "${COMPILER_FLAGS} -maltivec -D__SSE2__=1 -DNO_WARN_X86_INTRINSICS") |
| 32 | endif () |
| 33 | |
| 34 | # gcc -dM -E -msse4.2 - < /dev/null | sort > gcc-dump-sse42 |
| 35 | #define __SSE4_2__ 1 |
| 36 | |
| 37 | set (TEST_FLAG "-msse4.2") |
| 38 | set (CMAKE_REQUIRED_FLAGS "${TEST_FLAG} -O0") |
| 39 | check_cxx_source_compiles(" |
| 40 | #include <nmmintrin.h> |
| 41 | int main() { |
| 42 | auto a = _mm_crc32_u64(0, 0); |
| 43 | (void)a; |
| 44 | return 0; |
| 45 | } |
| 46 | " HAVE_SSE42) |
| 47 | if (HAVE_SSE42) |
| 48 | set (COMPILER_FLAGS "${COMPILER_FLAGS} ${TEST_FLAG}") |
| 49 | endif () |
| 50 | |
| 51 | set (TEST_FLAG "-mssse3") |
| 52 | set (CMAKE_REQUIRED_FLAGS "${TEST_FLAG} -O0") |
| 53 | check_cxx_source_compiles(" |
| 54 | #include <tmmintrin.h> |
| 55 | int main() { |
| 56 | __m64 a = _mm_abs_pi8(__m64()); |
| 57 | (void)a; |
| 58 | return 0; |
| 59 | } |
| 60 | " HAVE_SSSE3) |
| 61 | |
| 62 | set (TEST_FLAG "-mavx") |
| 63 | set (CMAKE_REQUIRED_FLAGS "${TEST_FLAG} -O0") |
| 64 | check_cxx_source_compiles(" |
| 65 | #include <immintrin.h> |
| 66 | int main() { |
| 67 | auto a = _mm256_insert_epi8(__m256i(), 0, 0); |
| 68 | (void)a; |
| 69 | return 0; |
| 70 | } |
| 71 | " HAVE_AVX) |
| 72 | |
| 73 | set (TEST_FLAG "-mavx2") |
| 74 | set (CMAKE_REQUIRED_FLAGS "${TEST_FLAG} -O0") |
| 75 | check_cxx_source_compiles(" |
| 76 | #include <immintrin.h> |
| 77 | int main() { |
| 78 | auto a = _mm256_add_epi16(__m256i(), __m256i()); |
| 79 | (void)a; |
| 80 | return 0; |
| 81 | } |
| 82 | " HAVE_AVX2) |
| 83 | |
| 84 | set (TEST_FLAG "-mpclmul") |
| 85 | set (CMAKE_REQUIRED_FLAGS "${TEST_FLAG} -O0") |
| 86 | check_cxx_source_compiles(" |
| 87 | #include <wmmintrin.h> |
| 88 | int main() { |
| 89 | auto a = _mm_clmulepi64_si128(__m128i(), __m128i(), 0); |
| 90 | (void)a; |
| 91 | return 0; |
| 92 | } |
| 93 | " HAVE_PCLMULQDQ) |
| 94 | |
| 95 | # gcc -dM -E -mpopcnt - < /dev/null | sort > gcc-dump-popcnt |
| 96 | #define __POPCNT__ 1 |
| 97 | |
| 98 | set (TEST_FLAG "-mpopcnt") |
| 99 | |
| 100 | set (CMAKE_REQUIRED_FLAGS "${TEST_FLAG} -O0") |
| 101 | check_cxx_source_compiles(" |
| 102 | int main() { |
| 103 | auto a = __builtin_popcountll(0); |
| 104 | (void)a; |
| 105 | return 0; |
| 106 | } |
| 107 | " HAVE_POPCNT) |
| 108 | |
| 109 | if (HAVE_POPCNT AND NOT ARCH_AARCH64) |
| 110 | set (COMPILER_FLAGS "${COMPILER_FLAGS} ${TEST_FLAG}") |
| 111 | endif () |
| 112 | |
| 113 | cmake_pop_check_state () |