This is the mail archive of the
`gcc-patches@gcc.gnu.org`
mailing list for the GCC project.

Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|

Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |

Other format: | [Raw text] |

*From*: Aldy Hernandez <aldyh at redhat dot com>*To*: Richard Henderson <rth at redhat dot com>, mark at codesourcery dot com, jason at redhat dot com, gcc-patches at gcc dot gnu dot org*Date*: Mon, 13 Jun 2005 09:25:14 -0400*Subject*: broken arithmetic operations on vectors (c and c++)*References*: <20050610134430.GA22224@redhat.com> <20050610204651.GB23605@redhat.com>

> I don't see any checks that the vectors are compatible. So given > > vector_size(16) float a, b; > vector_size(16) int c; > a = b + c; The above will error, but only because the assignment will trigger an incompatability before we get a chance to build the binary-op. However, "b + c" on its own will not error (and should). In keeping with the C front end, I think we should allow arithmetic between same type vectors with different signs. I tried to use comptypes, and a few other functions to no avail. The easiest thing I could think of was using the mode. Is this correct? Also, should I check TREE_TYPE or TYPE_MAIN_VARIANT (TREE_TYPE ()) ? The patch below is untested except with the testcase below. I just want to see if this is the right approach. Y'all might be interested to know that the C front end is also broken wrt the testcase below, as well as with a few other variations. I'll look into them when I'm done with the C++ front end. Aldy * cp/typeck.c (build_binary_op): Check compatability of vector types. * testsuite/g++.dg/conversion/simd3.C: New. Index: cp/typeck.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v retrieving revision 1.634 diff -c -p -r1.634 typeck.c *** cp/typeck.c 10 Jun 2005 17:35:35 -0000 1.634 --- cp/typeck.c 13 Jun 2005 13:13:56 -0000 *************** build_binary_op (enum tree_code code, tr *** 3182,3188 **** if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE) { if (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1))) ! error ("can't convert between vector values of different size"); arithmetic_types_p = 1; } } --- 3182,3202 ---- if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE) { if (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1))) ! { ! error ("can't convert between vector values of different size"); ! return error_mark_node; ! } ! /* The internal mode must be the same, so we allow arithmetic ! between different signness, if the modes are the same. ! ! e.g. ! V4SI arithmetic with "unsigned V4SI" will work, but ! V4SI arithmetic with "V2SI" won't. */ ! if (TYPE_MODE (TREE_TYPE (type0)) != TYPE_MODE (TREE_TYPE (type1))) ! { ! error ("can't convert between vector values of different types"); ! return error_mark_node; ! } arithmetic_types_p = 1; } } Index: testsuite/g++.dg/conversion/simd3.C =================================================================== RCS file: testsuite/g++.dg/conversion/simd3.C diff -N testsuite/g++.dg/conversion/simd3.C *** /dev/null 1 Jan 1970 00:00:00 -0000 --- testsuite/g++.dg/conversion/simd3.C 13 Jun 2005 13:13:56 -0000 *************** *** 0 **** --- 1,15 ---- + /* { dg-do compile } */ + + typedef int myint; + + float __attribute__((vector_size(16))) b; + int __attribute__((vector_size(16))) d; + myint __attribute__((vector_size(16))) d2; + unsigned int __attribute__((vector_size(16))) e; + + void foo() + { + b + d; /* { dg-error "can't convert between vector values of different types" } */ + d += e; + d2 += d; + }

**Follow-Ups**:**Re: broken arithmetic operations on vectors (c and c++)***From:*Jason Merrill

**Re: broken arithmetic operations on vectors (c and c++)***From:*Richard Henderson

**References**:**RFA: PR c++/10611 arithmetic operations on vectors***From:*Aldy Hernandez

**Re: RFA: PR c++/10611 arithmetic operations on vectors***From:*Richard Henderson

Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|

Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |