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: June-Yub Lee <jylee at math dot ewha dot ac dot kr>
- Subject: Re: g77 performance for real*complex
- From: Toon Moene <toon at moene dot indiv dot nluug dot nl>
- Date: Thu, 03 Aug 2000 20:56:58 +0200
- CC: gcc-bugs at gcc dot gnu dot org
- Organization: Moene Computational Physics, Maartensdijk, The Netherlands
- References: <200008031337.WAA23578@math.ewha.ac.kr>
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.
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)