Compiler crash when using intel intrinsics

Hi everyone,

I am trying to use Intel intrinsics from Swift for a CPU optimized CRC-32 calculation available in the SSE-4.2 instruction set and I am running into a compiler crash with

<unknown>:0: note: Cannot select: intrinsic <<INTERNAL ERROR: unparseable argument index in diagnostic text>>.x86.sse42.crc32.32.8`

In clang, it's possible to generate code for a specific microarchitecture (in this case e.g. using the -msse4.2 flag to allow for instructions in SSE 4.2).

A very simple reproducible case. This crashes the compiler on both the current stable Swift compiler as well as the current nightly build (DEVELOPMENT-SNAPSHOT-2020-08-18).

#if arch(x86_64)
import _Builtin_intrinsics.intel
import _Builtin_intrinsics.intel.cpuid
#endif


#if arch(x86_64)
func hasSSE42() -> Bool {
    var eax: UInt32 = 0
    var ebx: UInt32 = 0
    var ecx: UInt32 = 0
    var edx: UInt32 = 0
    __get_cpuid(1, &eax, &ebx, &ecx, &edx)
    return (ecx & UInt32(bit_SSE42)) == bit_SSE42
}
#else
func hasSSE42() -> Bool {
    return false
}
#endif

struct CRC32 {
    var value: UInt32 = 0
    mutating func append(_ data: [UInt8]) {
        #if arch(x86_64)
        if (hasSSE42()) {
            for byte in data {
                self.value = _mm_crc32_u8(self.value, byte)
            }
        }
        #endif
    }
}

Is this currently expected for the swift compiler? Am I missing a compiler flag?

Terms of Service

Privacy Policy

Cookie Policy