3 ms·
I wonder how it holds up to something like this on a modern processor and compiler: float rsqrt(float number) { return 1.0f / sqrtf(number); }
by echeese 6y ago
I wonder how it holds up to something like this on a modern processor and compiler:
float rsqrt(float number) { return 1.0f / sqrtf(number); }
- MauranKilom 6y agoWonder no longer! https://godbolt.org/z/M4TKb7 https://godbolt.org/z/M4TKb7 While this may look disappointing, it should be clear that adding 5% (or even 0.1%) error to inverse square root calculations is not something compilers are in the business of. Now, when you give the compiler more leeway (and -ffast-math is substantial leeway for anything less ephemeral than triangle normals on screen), you get much more interesting things: https://godbolt.org/z/85zG5r https://godbolt.org/z/85zG5r Turns out x86 has a (microcoded) instruction for this (and newer processors also have vectorized versions[1] of it). The compiler adds Newton-Rhapson for good measure. [1]: https://uops.info/html-lat/KBL/VRSQRTSS_XMM_XMM_XMM-Measurements.html https://uops.info/html-lat/KBL/VRSQRTSS_XMM_XMM_XMM-Measurem...