scalar operations to vectors and implicit conversions

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

scalar operations to vectors and implicit conversions

Neil Nelson via cfe-dev
Hi All,

Clang currently objects when scalar operations are applied to vectors (vector_size), while GCC does not.

Here is an example for X86:

#include <stdio.h>
#include <xmmintrin.h>

int main(int argc, char* argv[])
__m128 vec_a = _mm_set_ps(0, 1, 2, 3);
__m128 vec_b = _mm_set_ps(1, 2, 3, 4);
__m128 vec_r;

vec_a = vec_a + 5;
vec_r = _mm_add_ps(vec_a, vec_b);

printf("result = { %2.1f, %2.1f, %2.1f, %2.1f }\n", vec_r[0], vec_r[1], vec_r[2], vec_r[3]);

return 0;

Building this example with Clang will raise a build error:

$ clang -msse x86-simd.c -o x86-simd.exe
x86-simd.c:10:15: error: cannot convert between vector values of different size ('__m128' (vector of 4 'float' values) and 'int')
vec_a = vec_a + 5;
        ~~~~~ ^ ~
1 error generated.

Would anyone object to taking a vector x scalar operation to mean that the scalar should be replicated to the same width as the vector, same way GCC does? AFAICS, this is already the case with OpenCl's ext_vector_type.

This probably could be fixed in Sema::CheckVectorOperands() along with the changes in the test examples (test/Sema/zvector.c and possibly other). How should "-fno-lax-vector-conversions" interfere in those case?

Please share your opinion. Thanks.


cfe-dev mailing list
[hidden email]