10611 – operations on vector mode not recognized in C++ (original) (raw)

Description Richard Biener 2003-05-03 16:46:01 UTC

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

Comment 1 Wolfgang Bangerth 2003-05-05 14:40:45 UTC

State-Changed-From-To: open->analyzed State-Changed-Why: Confirmed. Never worked. Does work in C, however.

Comment 2 Wolfgang Bangerth 2003-05-05 19:40:07 UTC

Responsible-Changed-From-To: unassigned->aldyh Responsible-Changed-Why: As requested

Comment 3 Drea Pinski 2004-04-29 19:37:56 UTC

*** Bug 15208 has been marked as a duplicate of this bug. ***

Comment 4 dylan 2004-07-23 14:22:45 UTC

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 );

Comment 5 Richard Biener 2005-01-12 09:44:04 UTC

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.

Comment 6 Jim Wilson 2005-01-13 22:36:30 UTC

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.

Comment 7 dylan 2005-01-14 01:41:56 UTC

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.

Comment 10 Aldy Hernandez 2005-06-11 00:20:01 UTC

Fixed on mainline. Backported to 3.4. 4.0 patch will be committed once the branch is opened.

Comment 11 bert.hubert@netherlabs.nl 2005-06-11 14:13:35 UTC

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!

Comment 12 Ryan Hill 2005-07-11 06:24:53 UTC

Has this been backported to the 4.0 branch now that it's open again?

Comment 14 Aldy Hernandez 2005-07-11 14:42:20 UTC

I have just backported to the 4.0 branch.