I stumbled upon an interesting article regarding John Carmack's "black magic" hacks in the Quake 3 source. Some of these could be nicely inserted in Irrlicht. One of them is the sqrt function Carmack uses, which is waaaay faster than the default one, and the error is very small.
Here's the full article (with sourcecode).
http://www.codemaestro.com/reviews/9
It would be nice to see these enhancements in Irr.
Carmack's Magic Hacks
-
night_hawk
- Posts: 153
- Joined: Mon Mar 03, 2008 8:42 am
- Location: Suceava - Romania
- Contact:
-
rogerborg
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Re: Carmack's Magic Hacks
I calculate it as taking about 75% of the time as calling sqrt() on an Intel Core2 6700 using MS cl.exe 8.00 (VS 2005) in release mode on Windows. YMMV.night_hawk wrote:One of them is the sqrt function Carmack uses, which is waaaay faster than the default one
It does seem to be a small relative difference from the sqrt() result for the values that I've tested, although of course the absolute difference depends on the magnitude of the input.night_hawk wrote:and the error is very small.
For FLT_MAX, the difference in result (from my version of sqrt()) is 79164837199872.0000, for example.
A 33% increase in speed of one operation isn't necessarily an enhancement if you lose even a small amount of precision. It depends on the user.night_hawk wrote:It would be nice to see these enhancements in Irr.
Thanks, it's an interesting method.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
night_hawk
- Posts: 153
- Joined: Mon Mar 03, 2008 8:42 am
- Location: Suceava - Romania
- Contact:
Re: Carmack's Magic Hacks
Indeed, but as stated in the article, you could add a few more iterations of Newton's Algorithm to get a more precise value.rogerborg wrote:It does seem to be a small relative difference from the sqrt() result for the values that I've tested, although of course the absolute difference depends on the magnitude of the input.
As for the speed increase, apps that need lots of distances calculated would benefit quite a bit.
-
rogerborg
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Re: Carmack's Magic Hacks
And slower execution. We're only talking a ~33% reduction to begin with.night_hawk wrote:Indeed, but as stated in the article, you could add a few more iterations of Newton's Algorithm to get a more precise value.rogerborg wrote:It does seem to be a small relative difference from the sqrt() result for the values that I've tested, although of course the absolute difference depends on the magnitude of the input.
It depends on the definition of "lots" and "quite a bit". Apps that need accuracy with large values would get hosed (for various definitions of "accuracy", "large" and "hosed").night_hawk wrote:As for the speed increase, apps that need lots of distances calculated would benefit quite a bit.
It looks like a good fit for IRRLICHT_FAST_MATH, but I don't find the speed increase compelling enough to recommend replacing all uses of sqrt() by default.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
night_hawk
- Posts: 153
- Joined: Mon Mar 03, 2008 8:42 am
- Location: Suceava - Romania
- Contact:
