Proposal: Operator overloading without temporaries
Don Clugston
dac at nospam.com.au
Tue Mar 28 01:59:01 PST 2006
Norbert Nemec wrote:
> 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.
Obviously not with real matrices (C*D is not a pointwise operation), but
point taken. (BTW, the temporaries are still there, they're just in
registers this time (A[i]*B[i], C[i]*D[i]). The proposal does get rid of
all unnecessary temporaries, the problem is that there's no vectorisation).
> 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.
I completely agree. I see this as fixing the general case, but it does
nothing for vectorisation. I suspect that array expressions are somewhat
special as regards expressions, because of the vectorisation
possibility. If we had array expressions, this might eliminate the
necessity for expression templates. Do you think that's right?
Thanks for putting this into perspective.
> Greetings,
> Norbert
More information about the Digitalmars-d
mailing list