Blitz logo

Blitz Devel :

From: Todd Veldhuizen (tveldhui_at_[hidden])
Date: 1998-07-13 16:57:01


Someone noticed that this is unreasonably slow in Blitz++:

Array<complex<double>,1> A, B; // ...
B += A * A;

With KAI, no problem, but with egcs the array notation is twice
as slow as

for (int i=0; i < N; ++i)
    B(i) = A(i) * A(i);

I think the problem is due to egcs not being able to do
data flow analysis through structs/classes. In the expression
templates implementation, there are lots of complex<double>
temporaries created, which egcs apparently doesn't optimize
away.

For example:

#include <complex.h>

void sink(complex<double>&);

void foo()
{
    complex<double> a;
    sink(a);
    complex<double> b = a;
    complex<double> c = b;
    complex<double> d = c;
    complex<double> e = d;
    complex<double> f = e;
    sink(f);
}

In this example egcs won't get rid of b, c, d, and e. If you
do a similar example with just "double" (instead of complex<double>)
it will.

So, questions:

1. Does this problem duplicate in POOMA 2? I'm guessing it would.
2. Could this be added to the egcs TODO?
3. Mark, would it be hard to implement this optimization?

--------------------- blitz-dev list --------------------------------
* To subscribe/unsubscribe: mail to majordomo_at_[hidden], with
"subscribe blitz-dev" or "unsubscribe blitz-dev" in the body of the message
* Blitz++ web page: http://oonumerics.org/blitz/