Operations (+ - * /, etc.) on vector modes are not recognized in c++. The following testcase works for C, but not for C++: typedef float v4sf __attribute__((mode(V4SF))); void foo() { v4sf a, b, c; a = b + c; } bellatrix:~/src/tests$ g++-3.3 -c -msse2 simd2.cpp simd2.cpp: In function `void foo()': simd2.cpp:6: error: invalid operands of types `vector float' and `vector float' to binary `operator+' same for gcc 3.4. I suspect this is really rejects-legal, as I see no reason that it shouldnt (but the documentation isnt clear either - vector mode extensions are within the C Extensions part). Release: gcc-3.3 (GCC) 3.3 20030427 (Debian prerelease), gcc-3.4 (GCC) 3.4 20030422 (experimental) Environment: ia32 gnu-linux
State-Changed-From-To: open->analyzed State-Changed-Why: Confirmed. Never worked. Does work in C, however.
Responsible-Changed-From-To: unassigned->aldyh Responsible-Changed-Why: As requested
*** Bug 15208 has been marked as a duplicate of this bug. ***
I seem to have gotten this working to some extent by doing the following: This is just a quick hack but is it the right direction? If so, I can tidy it up and fix the side-effects. (or someone else with more knowledge of the internals of gcc/cp can) cp/cp-tree.h, change the ARITHMETIC_TYPE_P define to: #define ARITHMETIC_TYPE_P(TYPE) \ (CP_INTEGRAL_TYPE_P (TYPE) || TREE_CODE (TYPE) == REAL_TYPE || TREE_CODE (TYPE) == VECTOR_TYPE ) and cp/typeck.c, function build_binary_op ** CHANGE ** if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE) && (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE)) { int none_complex = (code0 != COMPLEX_TYPE && code1 != COMPLEX_TYPE); ** TO ** if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE) && (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE)) { int none_complex = (code0 != COMPLEX_TYPE && code1 != COMPLEX_TYPE && code0 != VECTOR_TYPE && code1 != VECTOR_TYPE );
What is the status on this issue? I.e. +,-,*,/ on vector types for C++? Note that trying to work around this missing feature with operator overloading like v4sf operator+(const v4sf& a, const v4sf& b) { return __builtin_ia32_addps(a, b); } (which would be again machine specific, but anyhow) doesn't work: t.c:3: error: 'float __vector__ operator+(const float __vector__&, const float __vector__&)' must have an argument of class or enumerated type.
Subject: Re: operations on vector mode not recognized in C++ On Wed, 2005-01-12 at 01:44, rguenth at tat dot physik dot uni-tuebingen dot de wrote: > ------- Additional Comments From rguenth at tat dot physik dot uni-tuebingen dot de 2005-01-12 09:44 ------- > What is the status on this issue? It is waiting for someone who works on the C++ FE to look at it.
I am implementing this locally to gcc 3.3.3, if it all seems to work ok I will attach the patches to this bug in a month or so (it's slow careful work). It's interesting because the side effect is the math optimizing pass of g++ begins to work with vector registers.
Subject: Bug 10611 CVSROOT: /cvs/gcc Module name: gcc Changes by: aldyh@gcc.gnu.org 2005-06-10 17:35:37 Modified files: gcc/cp : ChangeLog cvt.c typeck.c Added files: gcc/testsuite/g++.dg/conversion: simd2.C Log message: PR c++/10611 * cvt.c (build_expr_type_conversion): Same. * typeck.c (build_binary_op): Handle vectors. (common_type): Same. (type_after_usual_arithmetic_conversions): Same. * testsuite/g++.dg/conversion/simd2.C: New. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4783&r2=1.4784 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cvt.c.diff?cvsroot=gcc&r1=1.181&r2=1.182 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.633&r2=1.634 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/conversion/simd2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
Subject: Bug 10611 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: aldyh@gcc.gnu.org 2005-06-11 00:16:03 Modified files: gcc/cp : ChangeLog cvt.c typeck.c Added files: gcc/testsuite/g++.dg/conversion: simd2.C Log message: 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. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.224&r2=1.3892.2.225 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cvt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.151.4.3&r2=1.151.4.4 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.519.2.28&r2=1.519.2.29 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/conversion/simd2.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
Fixed on mainline. Backported to 3.4. 4.0 patch will be committed once the branch is opened.
Subject: Re: operations on vector mode not recognized in C++ Updated http://ds9a.nl/gcc-simd/ to this effect, thanks. On Sat, Jun 11, 2005 at 12:20:03AM -0000, aldyh at gcc dot gnu dot org wrote: > > ------- Additional Comments From aldyh at gcc dot gnu dot org 2005-06-11 00:20 ------- > Fixed on mainline. Backported to 3.4. 4.0 patch will be committed once the > branch is opened. > > -- > What |Removed |Added > ---------------------------------------------------------------------------- > Status|ASSIGNED |RESOLVED > Resolution| |FIXED > > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10611 > > ------- You are receiving this mail because: ------- > You are on the CC list for the bug, or are watching someone who is. > > > !DSPAM:42aa2e35254161288245759!
Has this been backported to the 4.0 branch now that it's open again?
Subject: Bug 10611 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: aldyh@gcc.gnu.org 2005-07-11 14:24:07 Modified files: gcc/cp : ChangeLog cvt.c typeck.c Added files: gcc/testsuite/g++.dg/conversion: simd2.C Log message: 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. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.4648.2.62&r2=1.4648.2.63 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cvt.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.180&r2=1.180.6.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.616.2.10&r2=1.616.2.11 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/conversion/simd2.C.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.2.8.1
I have just backported to the 4.0 branch.