Fast operations on floating point numbers?

Martin Reinecke martin@MPA-Garching.MPG.DE
Thu Dec 4 14:30:00 GMT 2003


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. But maybe the cost of both operations
is not so different on today's CPUs; I don't know.

Thanks,
   Martin




More information about the Gcc mailing list