Fast operations on floating point numbers?

Joe Buck jbuck@synopsys.com
Thu Dec 4 17:44:00 GMT 2003


On Thu, Dec 04, 2003 at 03:22:31PM +0100, Martin Reinecke wrote:
> Peter Barada wrote:
> 
> > If flipsign is only refered to inside the(hevily executed) loop, you
> > could try:
> > 
> > double a, flip;
> > int flipsign;
> > 
> > flip = flipsign ? -1.0 : 1.0;
> > 
> > for (;;) {
> >   ...
> >   a *= flip;
> >   ...
> > }
> > 
> > And get rid of the conditional...
> 
> Unfortunately this does not work in all places where I have this
> problem. But even where I can use it, there is still a
> full floating-point multiplication where the simple XORing of
> a single bit should do.

On many modern CPUs, the full floating point multiplication will be
faster than the XOR, because you'll be using a pipelined multiplier
and keeping the pipe full, and there isn't an XOR instruction that
operates on a floating point register.



More information about the Gcc mailing list