This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: complex - direct access to members?
- To: janr at molienergy dot bc dot ca (Jan Reimers)
- Subject: RE: complex - direct access to members?
- From: Joe Buck <jbuck at Synopsys dot COM>
- Date: Tue, 12 Jan 99 12:05:26 PST
- Cc: nbecker at fred dot net, egcs at cygnus dot com
> 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.