From 0e3a99ae913c732f015b0dcfecb85d3236cc142f Mon Sep 17 00:00:00 2001 From: Artjoms Sinkarovs Date: Wed, 10 Aug 2011 14:44:02 +0000 Subject: c-typeck.c (scalar_to_vector): New function. 2011-08-10 Artjoms Sinkarovs * c-typeck.c (scalar_to_vector): New function. Try scalar to vector conversion. (stv_conv): New enum for scalar_to_vector return type. (build_binary_op): Adjust. * doc/extend.texi: Description of scalar to vector expansion. c-family/ * c-common.c (unsafe_conversion_p): New function. Check if it is unsafe to convert an expression to the type. (conversion_warning): Adjust, use unsafe_conversion_p. * c-common.h (unsafe_conversion_p): New function declaration. testsuite/ * gcc.c-torture/execute/scal-to-vec1.c: New test. * gcc.c-torture/execute/scal-to-vec2.c: New test. * gcc.c-torture/execute/scal-to-vec3.c: New test. * gcc.dg/scal-to-vec1.c: New test. * gcc.dg/scal-to-vec2.c: New test. From-SVN: r177622 --- gcc/doc/extend.texi | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'gcc/doc') diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 480a8b0..49a8125 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -6526,18 +6526,25 @@ In C it is possible to use shifting operators @code{<<}, @code{>>} on integer-type vectors. The operation is defined as following: @code{@{a0, a1, @dots{}, an@} >> @{b0, b1, @dots{}, bn@} == @{a0 >> b0, a1 >> b1, @dots{}, an >> bn@}}@. Vector operands must have the same number of -elements. Additionally second operands can be a scalar integer in which -case the scalar is converted to the type used by the vector operand (with -possible truncation) and each element of this new vector is the scalar's -value. +elements. + +For the convenience in C it is allowed to use a binary vector operation +where one operand is a scalar. In that case the compiler will transform +the scalar operand into a vector where each element is the scalar from +the operation. The transformation will happen only if the scalar could be +safely converted to the vector-element type. Consider the following code. @smallexample typedef int v4si __attribute__ ((vector_size (16))); -v4si a, b; +v4si a, b, c; +long l; + +a = b + 1; /* a = b + @{1,1,1,1@}; */ +a = 2 * b; /* a = @{2,2,2,2@} * b; */ -b = a >> 1; /* b = a >> @{1,1,1,1@}; */ +a = l + a; /* Error, cannot convert long to int. */ @end smallexample In C vectors can be subscripted as if the vector were an array with -- cgit v1.1