slow complex<double>'s with g++

Greg Buchholz
Fri Mar 3 18:59:00 GMT 2006

Brian Budge wrote:
> It may be that I'm missing something, but you appear to be computing
> different things...
> Zi = 2.0*Zr*Zi + Ci;
> Zr = Tr - Ti + Cr;
> vs
>  Z = Z*Z + C;
> No doubt the 2.0 makes a difference...

    Hmm.  I don't get what you are saying.  Squaring a complex number
like a+ib you get...

(a+ib) * (a+ib)
a*a + iab + iab - b*b
(a*a - b*b) + i2ab

...Are you saying a multiplication instead of an addition is the cause?
Yes, the C version is a little more optimized, but I was surprised at
the factor of 8.5 time difference for gcc-4.1pre021006.  I guess I
expecting something small, say a 20-50% slowdown.  And you get all of
the speed back if you just use "-ffast-math".  Maybe I'm just surprised
that the optimizations that "-ffast-math" turns on do such a good job.

Greg Buchholz

More information about the Gcc-help mailing list