Proposal: Operator overloading without temporaries

Norbert Nemec Norbert at Nemec-online.de
Tue Mar 28 02:00:41 PST 2006


I don't see any obvious reasons against this proposal, but one should
not overestimate it!

It is true that it allows a number of optimizations and helps avoiding
some unnecessary temporaries, but it is not a replacement for expression
templates or vectorized expressions (aka array expressions).

Imagine A,B,C,D and X being arrays of the same size and consider the
last example in the proposal:

> X = (A*B) + (C*D);
> becomes
> T1 = A*B;
> T2 = C*D;
> T1 += T2;
> X = T1;

Fortran90 could translate the original expression into something like
	for(int i=0;i<N;i++)
		X[i] = (A[i]*B[i]) + (C[i]*D[i]);
which not only eliminates *all* temporaries, but does something more:
handle all calculations in one loop, allowing the memory to be read
cache friendly and all the calculations being done in registers.

C++ expression templates as used in blitz++ et al allow the same kind of
optimizations. Array expressions in D could do the same thing. The
operator optimization cannot handle this optimization.

So, as it stands I have no objections against the proposal, but it
should *NOT* be used as excuse against expression templates or array
expressions in the long term.

Greetings,
Norbert



More information about the Digitalmars-d mailing list