3 ms·
Wonder 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%
by MauranKilom 6y ago
Wonder 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...