conversions between vectors

Aldy Hernandez aldyh@redhat.com
Fri Dec 21 23:26:00 GMT 2001


>>>>> "Richard" == Richard Henderson <rth@redhat.com> writes:

 > On Fri, Dec 21, 2001 at 11:13:06PM -0200, Alexandre Oliva wrote:
 >> Nope.  You can't assign a valarray<T1> to a valarray<T2> in C++, even
 >> if there's an implicit conversion from T1 to T2.

 > Not to mention in AltiVec terms, 

 > 	vector char foo
 > 	vector int bar

 > foo is a vector of 16 characters, and bar is a vector of 4 ints.
 > So we've changed sizes as well.

The vector size is still the same: 16bytes.  Could it be allowed with
a warning?  Either way, I'm not going to advocate this one too much.
OTOH, i will strongly defend the case below.

 > I think it makes sense to be able to cast the vectors (which 
 > valarray would _not_ allow, incidentally), but I do not think
 > it makes sense to allow assignment without casting.

Ok, but... How about:

        vector unsigned int foo;
        vector signed int bar;

        foo = bar;

we haven't changed the sizes of either the vector or the underlying
type.  And the underlying types are very compatible, if not the same.
I see no reason why the above should not work.  The underlying mode
(let's say V4SI) is the same for both "vector unsigned int" and
"vector signed int".  Also, assignments between "signed int" and
"unsigned int" are allowed even in pedantic mode.  So, IMO the above
is in spirit with the C language.

And wrt casting, it makes syntatic sense to allow casts (as they do
now), even if valarrays don't allow it, as long as the vector size is
the same for both types.  I don't think we should enforce a pedantic
1:1 relationship wrt valarrays and vector types.

I can change my patch to only work for vectors of the same size and
type, allowing sign differences.

Comments?

All-dee



More information about the Gcc-patches mailing list