Bug 10611 - operations on vector mode not recognized in C++
Summary: operations on vector mode not recognized in C++
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P3 normal
Target Milestone: 4.0.2
Assignee: Aldy Hernandez
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: monitored, rejects-valid
: 15208 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-05-03 16:46 UTC by Richard Biener
Modified: 2005-07-11 14:42 UTC (History)
8 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-02-26 18:42:10


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 Andrew 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 8 GCC Commits 2005-06-10 17:35:47 UTC
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

Comment 9 GCC Commits 2005-06-11 00:16:14 UTC
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

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 13 GCC Commits 2005-07-11 14:24:18 UTC
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

Comment 14 Aldy Hernandez 2005-07-11 14:42:20 UTC
I have just backported to the 4.0 branch.