AVX intrinsic and matrix multiplication with c language

39 Views Asked by At

Error message:

incompatible types when initializing type ‘__m256d {aka __vector(4) double}’ using type ‘__m256 {aka __vector(8) float}’ __m256d c0 = _mm256_setzero_ps();

I was running a c matrix multiplication with AVX intrinsic and i got the error when compiling. I included <x86intrin.h>

1

There are 1 best solutions below

0
Surak of Vulcan On

There are three relevant data types __m256 (holds 8 floats), __m256d (holds 4 doubles) and __m256i (holds 256 bits worth of integers). Each of these has an intrinsic for initialization to zero: _mm256_setzero_ps, _mm256_setzero_pd and _mm256_setzero_si256, respectively. You need to use the correct one according to the variable type.

As a side note, the integer and float/double variant also emit as different instructions, so that a register does not have to cross between integer and FP domains in the CPU. There are minor performance penalties for that - at least there used to be (AFAIK Golden Cove does not have those anymore).