Scalar vector binary operation
Richard Guenther
richard.guenther@gmail.com
Wed Nov 3 13:27:00 GMT 2010
On Mon, Nov 1, 2010 at 5:16 PM, Artem Shinkarov
<artyom.shinkaroff@gmail.com> wrote:
> This patch allows binary operations: "vector <op> scalar" and "scalar
> <op> vector" in which case scalar is converted into the vector type,
> if the scalar type fits in the vectors element type.
>
> ChangeLog:
>
> 2010-11-01 Artjoms Sinkarovs <artyom.shinakroff@gmail.com>
>
> /gcc
> * tree.c (build_vector_from_val): Build vector from scalar
> * tree.h (build_vector_from_val): New declaration
Those are no longer part of this patch.
> * c-typeck.c (expr_fits_type_p): New function. Check if expression
> fits into the type considering constants.
> (scalar_to_vector): New function. Try scalar to vector conversion.
> (build_binary_op): Adjust.
> * doc/extend.texi: Description of scalar to vector expansion.
>
> /gcc/testsuite
> * gcc.c-torture/execute/scal-to-vec1.c: New test.
> * gcc.dg/scal-to-vec1.c: New test.
>
> bootstrapped and tested on x86_64_unknown-linux
+/* Check whether expression EXPR can be converted to the
+ vectortype TYPE, considering the case when EXPR is a constant. */
+static bool
+expr_fits_type_p (tree expr, tree type)
"Return true if expression ..."
also documents the return value. I think the comment should be adjusted
to match the intent of the function, namely
"... can be converted to TYPE preserving its value."
Passing the element type as TYPE seems to be enough as well.
The rationale is that OpenCL does not permit truncations to happen,
but people will write things like float_vector + 2.0 (instead of 2.0f),
so we allow value-preserving truncations for QOI reasons.
+#define SWAP(x, y) do { __typeof (x) __tmp = x; x = y; y = __tmp; } while (0)
we don't usually define such thing but expand it everywhere needed.
+ {
+ tree sc = save_expr(op0);
space after save_expr, likewise below.
Otherwise looks ok (but I've been looking at the patches before). I can't
approve it though.
Thanks,
Richard.
More information about the Gcc-patches
mailing list