Search code examples
macosclangavx512

Are AVX512 instrinsics supported in Clang on OSX 32-bit?


I get millions of errors when using AVX512 intrinsics under OSX, but only when building 32-bit app, 64-bit is fine. Is it supported? I'm including it via x86intrin.h and immintrin.h. zmmintrin.h apparently isn't there at all...


Solution

  • I can reproduce it with clang6.0 (mainline, not Apple's version) on Godbolt (https://godbolt.org/z/d-mnAy), but not clang7.0.

    It might be a bug, but Intel lists _mm512_maskz_set1_epi64 as the intrinsic for vpbroadcastq zmm {k}, r64, which is obviously only available in 64-bit mode.

    Of course this is silly, and vpbroadcastq with a memory or xmm source is still available in 32-bit mode. Recent clang versions that support it in 32-bit mode compile this code into a non-broadcast load of a vector constant, even in 64-bit mode:

    #include <immintrin.h>
    
    __m512i foo() {
        return _mm512_maskz_set1_epi64(0xf0, 123);
    }
    

    But clang5.0 and older compiles it like this, in 64-bit mode, though:

    foo:                                    # @foo
        mov     al, -16
        kmovd   k1, eax
        mov     eax, 123
        vpbroadcastq    zmm0 {k1} {z}, rax
        ret
    

    And clang 5.0 -m32 gives an internal compiler error.


    I don't have a Mac to try actual Xcode, but it's pretty clear that some clang/LLVM versions treat _mm512_maskz_set1_epi64 and _mm512_set1_epi64 as 64-bit-mode-only. You might be able to define your own for 32-bit mode using the same built-ins that the headers use.