Header files for x86 SIMD intrinsics

前端 未结 5 598
借酒劲吻你
借酒劲吻你 2020-11-28 17:17

Which header files provide the intrinsics for the different x86 SIMD instruction set extensions (MMX, SSE, AVX, ...)? It seems impossible to find such a list online. Correct

5条回答
  •  鱼传尺愫
    2020-11-28 18:02

    The header name depends on your compiler and target architecture.

    • For Microsoft C++ (targeting x86, x86-64 or ARM) and Intel C/C++ Compiler for Windows use intrin.h
    • For gcc/clang/icc targeting x86/x86-64 use x86intrin.h
    • For gcc/clang/armcc targeting ARM with NEON use arm_neon.h
    • For gcc/clang/armcc targeting ARM with WMMX use mmintrin.h
    • For gcc/clang/xlcc targeting PowerPC with VMX (aka Altivec) and/or VSX use altivec.h
    • For gcc/clang targeting PowerPC with SPE use spe.h

    You can handle all these cases with conditional preprocessing directives:

    #if defined(_MSC_VER)
         /* Microsoft C/C++-compatible compiler */
         #include 
    #elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
         /* GCC-compatible compiler, targeting x86/x86-64 */
         #include 
    #elif defined(__GNUC__) && defined(__ARM_NEON__)
         /* GCC-compatible compiler, targeting ARM with NEON */
         #include 
    #elif defined(__GNUC__) && defined(__IWMMXT__)
         /* GCC-compatible compiler, targeting ARM with WMMX */
         #include 
    #elif (defined(__GNUC__) || defined(__xlC__)) && (defined(__VEC__) || defined(__ALTIVEC__))
         /* XLC or GCC-compatible compiler, targeting PowerPC with VMX/VSX */
         #include 
    #elif defined(__GNUC__) && defined(__SPE__)
         /* GCC-compatible compiler, targeting PowerPC with SPE */
         #include 
    #endif
    

提交回复
热议问题