Original Post
🔒 Locked
Fast Math Needed
Advertisement
you could always make a lookup table (if the range of numbers you need to sqrt is not too large)
Im not sure how fast that would actually be though, since nowadays functions like sqrt are fairly efficient
All you can do is try it and see how fast it would work. A lookup table wouldnt be near as accurate also
Im not sure how fast that would actually be though, since nowadays functions like sqrt are fairly efficient
All you can do is try it and see how fast it would work. A lookup table wouldnt be near as accurate also
What version of VB?
If its VB6, you are (almost) stuck with Sqr() or a lookup table (make sure its a static array for performance)
If its VB.NET, you might be able to get the compiler to inline a call to the bitconverter so that you can extract the exponent efficiently and thus be able to get a good fast estimate.
If you have any division operations going on, then your bottleneck may infact be the divisions and not the sqrt.
If its VB6, you are (almost) stuck with Sqr() or a lookup table (make sure its a static array for performance)
If its VB.NET, you might be able to get the compiler to inline a call to the bitconverter so that you can extract the exponent efficiently and thus be able to get a good fast estimate.
If you have any division operations going on, then your bottleneck may infact be the divisions and not the sqrt.
Quote:
Original post by TheKrust
I have a custom built lighting engine in visual basic. It runs pretty fast, but I need to get it as fast as possible. Is there an easy replacement for the sqare root function that uses less CPU time? It doesn't need to be %100 accurate
Yes.
1. Don't use sqrt.
2. Calculate by fast way inverse sqrt.
3. Use asm instruction for fast incorrect inverse sqrt (if present on your CPU).
4. GFX card could do fast inverse incorrect sqrt.
On modern platforms, the sqrt function call has been so streamlined by the CPU that any fancy tricks are actually going to be slower. Be sure you test the speed of your code before and after you tinker. You should find that the sqrt operation is easily 30% faster than any math tricks you can do yourself.
The bit hacks are really only necessary on embedded systems anymore, to be honest.
The bit hacks are really only necessary on embedded systems anymore, to be honest.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement