conversions between vectors
Aldy Hernandez
aldyh@redhat.com
Fri Dec 21 16:14:00 GMT 2001
hi guys.
here is a patch to handle conversions between vectors. vectors of the
same size should convert without a problem.
i found this problem while trying to do:
vector int foo;
vector unsigned int bar;
foo=bar;
the following should also convert without a problem:
vector char foo;
vector int bar;
foo = bar; // should a warning be emitted?
// in convert_and_check?
provided, foo and bar are of the same size.
btw, convert_to_vector() further down the line will check that the sizes
are the same.
a c++ version is forthcoming.
ok?
--
Aldy Hernandez E-mail: aldyh@redhat.com
Professional Gypsy
Red Hat, Inc.
2001-12-21 Aldy Hernandez <aldyh@redhat.com>
* gcc.dg/altivec-3.c: New.
* c-typeck.c (convert_for_assignment): Handle vectors.
Index: c-typeck.c
===================================================================
RCS file: /cvs/uberbaum/gcc/c-typeck.c,v
retrieving revision 1.161
diff -c -p -r1.161 c-typeck.c
*** c-typeck.c 2001/12/17 04:19:08 1.161
--- c-typeck.c 2001/12/21 23:51:16
*************** convert_for_assignment (type, rhs, errty
*** 4159,4164 ****
--- 4159,4168 ----
|| coder == BOOLEAN_TYPE))
return convert_and_check (type, rhs);
+ /* Vectors of the same size interconvert. */
+ else if ((codel == VECTOR_TYPE && coder == VECTOR_TYPE))
+ return convert_and_check (type, rhs);
+
/* Conversion to a transparent union from its member types.
This applies only to function arguments. */
else if (codel == UNION_TYPE && TYPE_TRANSPARENT_UNION (type) && ! errtype)
Index: testsuite/gcc.dg/altivec-3.c
===================================================================
RCS file: altivec-3.c
diff -N altivec-3.c
*** /dev/null Tue May 5 13:32:27 1998
--- altivec-3.c Fri Dec 21 15:51:16 2001
***************
*** 0 ****
--- 1,17 ----
+ /* { dg-do compile { target powerpc-*-* } } */
+ /* { dg-options "-maltivec" } */
+
+ /* Program to test conversions between vector types. This needs
+ to run on a target that has vectors, so use AltiVec. */
+
+ #define vector __attribute__((vector_size(16)))
+
+ vector int sue;
+ vector unsigned int anne;
+ vector char darcy;
+
+ void foo()
+ {
+ sue = anne;
+ darcy = sue;
+ }
More information about the Gcc-patches
mailing list