Search code examples
cmakeintelintrinsics

cmake CheckSymbolExists for intrinsic


I'd like to check for intel intrinsics such as _mm_popcnt_u32 or _mm_blendv_epi8 using cmake. However the function check_symbol_exists doesn't work properly depending on the compiler. (it works with Clang but not with GCC). Indeed it is documented

If the header files declare the symbol as a function or variable then the symbol must also be available for linking (so intrinsics may not be detected).

Is there a simple way to check for those ?


Solution

  • As the CMake documentation also states:

    If the symbol is a type, enum value, or intrinsic it will not be recognized (consider using CheckTypeSize or CheckCSourceCompiles).

    So, try to compile a small example with the Intel intrinsic using CheckCSourceCompiles. E.g.:

    include(CheckCSourceCompiles)
    check_c_source_compiles("
        int main() {
          int tmp = _mm_popcnt_u32(0);
          return 0;
        }
      "
      HAVE_INTRINISC
    )