To my delight, I found that clang will let you write explicit vector code, without resorting to intrinsics, using extended vectors.
For instance, this code:
typedef float floatx16 __attribute__((ext_vector_type(16)));
floatx16 add( floatx16 a, floatx16 b )
{
return a+b;
}
...will translate directly to a single instruction with clang -march=skylake-avx512 invocation:
vaddps zmm0, zmm0, zmm1
In order to write branch-free code, I want to blend avx512 vectors.
With intrinsics, you would use the _mm512_mask_blend_ps intrinsic. (By the way, why is does AVX512 use mask,a,b order, and AVX use a,b,mask order?)
Trying to do the blend with the ternary operator does not work:
typedef float floatx16 __attribute__((ext_vector_type(16)));
floatx16 minimum( floatx16 a, floatx16 b )
{
return a < b ? a : b;
}
...results in...
error: used type 'int __attribute__((ext_vector_type(16)))' (vector of 16 'int' values) where arithmetic or pointer type is required
Is it possible to do vector blending, vblendmps zmm {k}, zmm, zmm, using ext_vector_type(16) variables in C?