This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: complex - direct access to members?



> What about an implementation that stores polar values R,Theta?  The
> following code sets real(a), and generates a lot assembly code (egcs g++
> 1.1).  In particular it appears that the inlined a.imag=imag(a)
> assignment does not get optimized away.

This optimization failure is a more general problem in egcs, in that the
compiler decides too soon that it has a store to memory.  However, as you
suggest, in principle if this flaw were corrected, we could generate as
good code from

template<class T>
inline void setReal(complex<T>& z, T newReal)
{
	z = complex<T>(newReal, imag(z));
}

as we could if imag(z) were changed to return a reference.  Certainly
Neal could use this setReal, though at present he will get worse code.

If the speed penalty is too much, then this setReal can be made a
friend of complex<T> in his local copy and implemented as

	z.re = newReal;

retaining the other definition for portability.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]