This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: RFA: PR c++/10611 arithmetic operations on vectors
On Fri, Jun 10, 2005 at 10:11:03AM -0400, Jason Merrill wrote:
> OK.
Thanks Jason.
Here is the version I am about to commit. The previous one had a typo
that showed up in testing. I've fixed it and re-tested.
Aldy
PR c++/10611
* cp/cvt.c (build_expr_type_conversion): Same.
* cp/typeck.c (build_binary_op): Handle vectors.
(common_type): Same.
(type_after_usual_arithmetic_conversions): Same.
* testsuite/g++.dg/conversion/simd2.C: New.
Index: cp/cvt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cvt.c,v
retrieving revision 1.181
diff -c -p -r1.181 cvt.c
*** cp/cvt.c 23 Apr 2005 21:28:50 -0000 1.181
--- cp/cvt.c 10 Jun 2005 17:19:11 -0000
*************** build_expr_type_conversion (int desires,
*** 1061,1066 ****
--- 1061,1067 ----
return expr;
/* else fall through... */
+ case VECTOR_TYPE:
case BOOLEAN_TYPE:
return (desires & WANT_INT) ? expr : NULL_TREE;
case ENUMERAL_TYPE:
Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.633
diff -c -p -r1.633 typeck.c
*** cp/typeck.c 3 Jun 2005 23:22:06 -0000 1.633
--- cp/typeck.c 10 Jun 2005 17:19:14 -0000
*************** type_after_usual_arithmetic_conversions
*** 249,257 ****
--- 249,259 ----
/* FIXME: Attributes. */
gcc_assert (ARITHMETIC_TYPE_P (t1)
|| TREE_CODE (t1) == COMPLEX_TYPE
+ || TREE_CODE (t1) == VECTOR_TYPE
|| TREE_CODE (t1) == ENUMERAL_TYPE);
gcc_assert (ARITHMETIC_TYPE_P (t2)
|| TREE_CODE (t2) == COMPLEX_TYPE
+ || TREE_CODE (t1) == VECTOR_TYPE
|| TREE_CODE (t2) == ENUMERAL_TYPE);
/* In what follows, we slightly generalize the rules given in [expr] so
*************** type_after_usual_arithmetic_conversions
*** 278,283 ****
--- 280,295 ----
attributes);
}
+ if (code1 == VECTOR_TYPE)
+ {
+ /* When we get here we should have two vectors of the same size.
+ Just prefer the unsigned one if present. */
+ if (TYPE_UNSIGNED (t1))
+ return build_type_attribute_variant (t1, attributes);
+ else
+ return build_type_attribute_variant (t2, attributes);
+ }
+
/* If only one is real, use it as the result. */
if (code1 == REAL_TYPE && code2 != REAL_TYPE)
return build_type_attribute_variant (t1, attributes);
*************** common_type (tree t1, tree t2)
*** 735,743 ****
code2 = TREE_CODE (t2);
if ((ARITHMETIC_TYPE_P (t1) || code1 == ENUMERAL_TYPE
! || code1 == COMPLEX_TYPE)
&& (ARITHMETIC_TYPE_P (t2) || code2 == ENUMERAL_TYPE
! || code2 == COMPLEX_TYPE))
return type_after_usual_arithmetic_conversions (t1, t2);
else if ((TYPE_PTR_P (t1) && TYPE_PTR_P (t2))
--- 747,755 ----
code2 = TREE_CODE (t2);
if ((ARITHMETIC_TYPE_P (t1) || code1 == ENUMERAL_TYPE
! || code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE)
&& (ARITHMETIC_TYPE_P (t2) || code2 == ENUMERAL_TYPE
! || code2 == COMPLEX_TYPE || code2 == VECTOR_TYPE))
return type_after_usual_arithmetic_conversions (t1, t2);
else if ((TYPE_PTR_P (t1) && TYPE_PTR_P (t2))
*************** build_binary_op (enum tree_code code, tr
*** 2902,2908 ****
case BIT_AND_EXPR:
case BIT_IOR_EXPR:
case BIT_XOR_EXPR:
! if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
shorten = -1;
break;
--- 2914,2921 ----
case BIT_AND_EXPR:
case BIT_IOR_EXPR:
case BIT_XOR_EXPR:
! if ((code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
! || (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE))
shorten = -1;
break;
*************** build_binary_op (enum tree_code code, tr
*** 3158,3167 ****
break;
}
! arithmetic_types_p =
! ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
! && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
! || code1 == COMPLEX_TYPE));
/* Determine the RESULT_TYPE, if it is not already known. */
if (!result_type
&& arithmetic_types_p
--- 3171,3191 ----
break;
}
! if (((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
! && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
! || code1 == COMPLEX_TYPE)))
! arithmetic_types_p = 1;
! else
! {
! arithmetic_types_p = 0;
! /* Vector arithmetic is only allowed when both sides are vectors. */
! 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;
! }
! }
/* Determine the RESULT_TYPE, if it is not already known. */
if (!result_type
&& arithmetic_types_p
Index: testsuite/g++.dg/conversion/simd2.C
===================================================================
RCS file: testsuite/g++.dg/conversion/simd2.C
diff -N testsuite/g++.dg/conversion/simd2.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/conversion/simd2.C 10 Jun 2005 17:19:14 -0000
***************
*** 0 ****
--- 1,16 ----
+ /* { dg-do compile } */
+
+ /* Test generic operations on vectors. */
+
+ int __attribute__((vector_size(16))) a, b, c;
+ int __attribute__((vector_size(8))) d;
+ void foo()
+ {
+ a = b ^ c;
+ a = b + c;
+ a = b - c;
+ a = b * c;
+ a = b / c;
+ a = -b;
+ a = d + b; /* { dg-error "can't convert between vector" } */
+ }