freepooma-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pooma-dev] Yes, Vector temporaries do appear in every operation...!


From: Richard Guenther
Subject: Re: [pooma-dev] Yes, Vector temporaries do appear in every operation...!!
Date: Fri, 28 May 2004 13:56:28 +0200 (CEST)

On Fri, 28 May 2004, Radek Pecher wrote:

> | Note that without your debugging stuff in the constructors, these
> | get inlined and optimized away by the optimizer.  Of course one
> | could argue creating the copies should be avoided in the first
> | place, but I cannot see how this can be done, as, f.i. for
> | BinaryOp<Vector1, Vector2, OpMultiply>::operator() we clearly need
> | to return a _new_ Vector as result.  To avoid this one would have
> | to expression-template the vector itself, so only primitive
> | variable types are ever copied.  But I don't think this will work
> | or pay off.
>
>
> I actually compiled the code with the original (unmodified) version of
> Vector.h first and used GDB to run it and disassemble it. Without
> much analysing, I noticed several looping jumps at the place of the
> algebraic expression which only confirms that the optimising compiler
> did not produce the required code:
> v2(0) = v1(0)*v1(0) + v1(0)*v1(0);
> v2(1) = v1(1)*v1(1) + v1(1)*v1(1);
> as was supposed to. (And I also tried several other optimisation
> configurations, of course.)

Oh, and you usually get a better idea of what the compiler is able to do
if not using main(), but just an externally visible function like

#include "Pooma/Arrays.h"

Vector<2> test(const Vector<2>& v1)
{
  Vector<2> v2;
  v2 = v1*v1 + v1*v1;
  return v2;
}

and indeed, comparing with

Vector<2> test2(const Vector<2>& v1)
{
  Vector<2> v2;
  v2(0) = v1(0)*v1(0) + v1(0)*v1(0);
  v2(1) = v1(1)*v1(1) + v1(1)*v1(1);
  return v2;
}

shows inefficient code.

--
Richard Guenther <richard dot guenther at uni-tuebingen dot de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]