Message ID | AANLkTikYQLr3vCKMJUFnyVS25_dG5pBJsdrbEFYZX_Sp@mail.gmail.com |
---|---|
State | New |
Headers | show |
On Wed, 27 Oct 2010, Artem Shinkarov wrote: > Ok, I do understand your concern, but my following patch > (http://gcc.gnu.org/ml/gcc-patches/2010-08/msg01075.html) implements > scalar <op> vector and vector <op> scalar for op in {+, -, /, ...}. In > that patch for integer types I use the function int_fits_type_p before > I allow scalar to vector conversion. And it would be strange to allow > scalar <op> vector everywhere except shifting operators. > > Would it be ok, if I'll use the same int_fits_type_p checking if scalr > fits in the vector type and if not then I'll throw an error. And I'll > add this statement in the documentation. That seems safer - but if other operations between scalars and vectors aren't supported until a subsequent patch, that clearly indicates that you should not be including mixed scalar/vector shifts in this patch - you should make this patch only accept vector/vector shifts. Mixed shifts can then go in the patch adding other mixed operations, and be reviewed in the context of the full documentation and set of testcases for that patch.
Index: gcc/doc/extend.texi =================================================================== --- gcc/doc/extend.texi (revision 165913) +++ gcc/doc/extend.texi (working copy) @@ -6315,6 +6315,27 @@ minus or complement operators on a vecto elements are the negative or complemented values of the corresponding elements in the operand. +In C it is possible to use shifting operators @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 one of the 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. +Consider the following code. + +@smallexample +typedef int v4si __attribute__ ((vector_size (16))); + +v4si a, b, c; +int i = 1; + +b = a >> 1; /* b = a >> @{1,1,1,1@}; */ +c = 1 << a; /* c = @{1,1,1,1@} << a; */ +@end smallexample + + + In C vectors can be subscripted as if the vector were an array with the same number of elements and base type. Out of bound accesses invoke undefined behavior at runtime. Warnings for out of bound