Should I write a fast sqrt() routine?
I''m finishing up a small math library for general vector and matrix ops, and transformations. I am currently using fastcos, fastsin routines using a MacLaurin expansion to 7 terms each (although I think I will increase cos to 8 terms, since R <= .0019 in -pi <= x <= pi is a touch high...). Anyway, I was wondering if I should write any sort of fast sqrt() routine, and if it will even help...
I could do a MacLaurin expansion around 0, but that may not work terribly well since I will probably have to deal with fairly large numbers and there will be a lot of terms for acceptable accuracy. I could also use a fast integer sqrt and use fixed point to get the answer within .1% or so(my target accuracy). Or I could use a slightly less accurate sqrt tha works in float instead of double and save my compiler from mucking about the multi-variable variables (you know what i mean, right? low-high business...)
Or I could just continue using math.h''s sqrt(). I don''t really know how much I would gain, so I don''t actually know if it is worth the time...
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
The only thing it''s worth is the challange. Pretty much the same thing goes with sin and cos as well, as they are fast enough on modern systems.
The Artist Formerly Known as CmndrM
http://chaos.webhop.org
The Artist Formerly Known as CmndrM
http://chaos.webhop.org
what would be more interesting is to optimise your math library with SSE, MMX instruction sets.
Everything is better with Metal.
Do you really think you can write code that runs faster than a single instruction (FSQRT) on the FPU?
Stevie
Don''t follow me, I''m lost.
Stevie
Don''t follow me, I''m lost.
StevieDon't follow me, I'm lost.
Well, how many cycles does that single instruction take?
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
quote:
Original post by Promit
I don''t really know how much I would gain, so I don''t actually know if it is worth the time...
Things you don''t know:
1. How fast sqrt() is right now.
2. How accurate you need sqrt() to be.
3. How fast a sqrt() with that level of accuracy would be.
4. Whether sqrt() is slowing your program down.
5. How much extra time it would take to code and debug a new sqrt().
1, 3, and 4 will require a profiler. 2 and 5 will require good development instincts.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement