This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: g77 performance for real*complex
- To: "Toon Moene" <toon at moene dot indiv dot nluug dot nl>, "June-Yub Lee" <jylee at math dot ewha dot ac dot kr>
- Subject: Re: g77 performance for real*complex
- From: "Tim Prince" <tprince at computer dot org>
- Date: Thu, 3 Aug 2000 15:02:26 -0700
- Cc: <gcc-bugs at gcc dot gnu dot org>
- References: <200008031337.WAA23578@math.ewha.ac.kr> <3989C07A.4BCDD405@moene.indiv.nluug.nl>
----- Original Message -----
From: "Toon Moene" <toon@moene.indiv.nluug.nl>
To: "June-Yub Lee" <jylee@math.ewha.ac.kr>
Cc: <gcc-bugs@gcc.gnu.org>
Sent: Thursday, August 03, 2000 11:56 AM
Subject: Re: g77 performance for real*complex
> June-Yub Lee wrote:
>
> > Maybe you alreay know that the problem of real*complex but
>
> No, I hadn't realised this.
>
> > let me present a simplest example:
> > > cat t.f
> > real*8 x
> > complex*16 z1, z2
> > x = 1.1d0
> > z1 = (2.2d0, 3.3d0)
> > z2 = x*z1
> > end
> >
> > The program needs only TWO double precision multiplication (fmuld):
> > x*dble(z1) for the real part, x*dimag(z1) for the imaginary part.
> > However, the g77 (2.95.1) generates 2*fmuld & fsubd for the real part
> > and 2*fmuld & faddd for the imaginary part. And it comsumes 6 flops
> > for real*complex even under -O2 optimization mode.
>
> The reason for this behaviour is simple: the DOUBLE PRECISION variable
> X first is converted to the DOUBLE COMPLEX variable (1.1d0, 0.0d0)
> before the DOUBLE COMPLEX multiplication (1.1d0, 0.0d0) * (2.2d0, 3.3d0)
> is done [according to the promotion rules of the Fortran Standard]. The
> latter needs 4 multiplications and 2 additions 1) (one with a minus
> sign). Apparently, the SUN compiler knows how to make use of the fact
> that the imaginary part of a real number is zero.
>
As does g77, (at least on Windows!), when optimization is invoked.
> Clever trick - if I have some spare time (hah :-) I might look into
> teaching the Fortran frontend such tricks.
>
> 1) (a + b i) * (c + d i) = a * c - b * d + (a * d + b * c) i
>
> --
> Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
> Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
> GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
> GNU Fortran 95: http://g95.sourceforge.net/ (under construction)
Tim Prince