aboutsummaryrefslogtreecommitdiff
path: root/gcc/doc/extend.texi
diff options
context:
space:
mode:
authorArtjoms Sinkarovs <artyom.shinkaroff@gmail.com>2011-08-10 14:44:02 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2011-08-10 14:44:02 +0000
commit0e3a99ae913c732f015b0dcfecb85d3236cc142f (patch)
tree1a68ab24120fe0d7e02fe83b3b5e700f8d676001 /gcc/doc/extend.texi
parent0eb778344e8c1d4e9da37a098bceef7201283432 (diff)
downloadgcc-0e3a99ae913c732f015b0dcfecb85d3236cc142f.zip
gcc-0e3a99ae913c732f015b0dcfecb85d3236cc142f.tar.gz
gcc-0e3a99ae913c732f015b0dcfecb85d3236cc142f.tar.bz2
c-typeck.c (scalar_to_vector): New function.
2011-08-10 Artjoms Sinkarovs <artyom.shinakroff@gmail.com> * 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
Diffstat (limited to 'gcc/doc/extend.texi')
-rw-r--r--gcc/doc/extend.texi19
1 files changed, 13 insertions, 6 deletions
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