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]
Other format: [Raw text]

Re: Fast operations on floating point numbers?


>I'm not completely sure whether this question belongs to a C/C++ newsgroup,
>but it is probably compiler-specific, so I'm trying my luck here.
>
>I'm developing a numerical simulation code which contains operations
>like this one
>
>double a;
>int flipsign;
>
>[...]
>
>if (flipsign)
>   a = -a;
>
>in an inner loop which is executed billions of times.
>I suspect that the conditional slows the execution down,
>and the "a=-a" statement might not be optimal as well.

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...

-- 
Peter Barada
peter@the-baradas.com


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