Forums » Suggestions

Fast InvSqrt()

Dec 20, 2006 Lexicon link
Would this help VO's 3D graphics?
http://www.beyond3d.com/articles/fastinvsqrt2/
Dec 20, 2006 a1k0n link
I heard of a faster inverse square root today:

float fasterinvsqrt(float x) { return x*x; }

But seriously, maybe. Not necessarily the graphics (the hardware pretty much does that for us in most cases), but maybe the physics.
Dec 20, 2006 upper case link
it's to be noted that inverted sqrt operations are now part of most (all?) superscalar and vectorisation hardware architecture such as powerpc and intel core chips.

that code was a hacked up approximation of the result by using 32-bit hardware-specific hacks wich would need re-factoring for 64-bit hardware.

it was a good and interesting story though. in my life as a professional software developer, i've stumbled on a few pieces of exotic code like that and sometime wondered how they came to be.
Dec 20, 2006 a1k0n link
It'd still work for 64-bit CPUs. floats and ints are still 32 bits, though it's really up to the compiler whether the int is 32 or 64 bits on a 64-bit platform.
Dec 20, 2006 Spider link
Its a fun one, but yeah, its actually slower than the one thats been in since SSE/MMX got really popular due to the amount of instructions.

This was faster back in the day when int vs. float was a real issue to care about, since then, floating point hardware has improved immensely, and at least the recent Pentium arches have a faster FP unit than their Int unit. (reverse in opterons I believe)

But yeah, the hack is way cool, and its an interesting piece of software history
Dec 20, 2006 upper case link
a1k0n, on that subject (i32/i64), apple has a compile-time define you can use to switch and use the proper type under leopard. if you want details of that, i could summarize the wwdc 2006 info for you.