faster representation of pow on some áreas of subsurface?

Tomaz Canabrava tcanabrava at kde.org
Sun Jan 19 11:29:22 UTC 2014


People,

I noticed a little lag while switching dives on the new profile, thing that
I tougth it shouldn't exist because the new code of the profile tries real
hard to be very responsive, then I fired callgrind to find the guilty one:

add_segment

and the biggest part of add_segment is the pow() function.

I'v replaced the pow() call with the fastPow() that I found on the internet
and it got *way* snappyer.

double fastPow(double a, double b) {
  union {
    double d;
    int x[2];
  } u = { a };
  u.x[1] = (int)(b * (u.x[1] - 1072632447) + 1072632447);
  u.x[0] = 0;
  return u.d;
}

I dunno how is this compared with the real pow in terms of correctness, but
it make the profile very responsive, even the old one.

I found the code ( with the documentation on how the magic numbers works )
here:
http://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/

can you low level guys take a look at it and see if it woths the change?

Tomaz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.hohndel.org/pipermail/subsurface/attachments/20140119/ea6aaa79/attachment.html>


More information about the subsurface mailing list