SystemIntrospection.cmake raw

   1  include_guard(GLOBAL)
   2  
   3  include(CheckCXXSourceCompiles)
   4  include(CMakePushCheckState)
   5  cmake_push_check_state(RESET)
   6  
   7  # Check for clmul instructions support.
   8  if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
   9    set(CMAKE_REQUIRED_FLAGS "-mpclmul")
  10  endif()
  11  check_cxx_source_compiles("
  12    #include <immintrin.h>
  13    #include <stdint.h>
  14  
  15    int main()
  16    {
  17      __m128i a = _mm_cvtsi64_si128((uint64_t)7);
  18      __m128i b = _mm_clmulepi64_si128(a, a, 37);
  19      __m128i c = _mm_srli_epi64(b, 41);
  20      __m128i d = _mm_xor_si128(b, c);
  21      uint64_t e = _mm_cvtsi128_si64(d);
  22      return e == 0;
  23    }
  24    " HAVE_CLMUL
  25  )
  26  if(HAVE_CLMUL)
  27    set(CLMUL_CXXFLAGS ${CMAKE_REQUIRED_FLAGS})
  28  endif()
  29  
  30  if(CMAKE_CXX_STANDARD LESS 20)
  31    # Check for working clz builtins.
  32    check_cxx_source_compiles("
  33      int main()
  34      {
  35        unsigned a = __builtin_clz(1);
  36        unsigned long b = __builtin_clzl(1);
  37        unsigned long long c = __builtin_clzll(1);
  38      }
  39      " HAVE_CLZ
  40    )
  41  endif()
  42  
  43  cmake_pop_check_state()
  44