5 ms·
Inverse sqrt approximation is available since SSE1 with rsqrtss & rsqrtps instructions.
by mmozeiko 8y ago
Inverse sqrt approximation is available since SSE1 with rsqrtss & rsqrtps instructions.
- vardump 8y agoIndeed. Both reciprocal (inverse) square root SSE SIMD instructions were available in Intel Pentium III, released in 1999.
- slavik81 8y agoWhich is nice because SSE1 and SSE2 are mandatory parts of x86_64. If you're a 64bit application for desktop, you can use rsqrtss without any checks or fallbacks. Unfortunately, it doesn't tend to get used automatically in languages like C. The result of rsqrtss is slightly different from 1/sqrtf(x) as two seperate operations, so it cannot be applied as an optimization. If the rules for floating point optimization are loosened by passing -ffast-math to GCC, the compiler will use it. That being said, -ffast-math is a shotgun that affects a lot of things. If you need signed zeros, Infs, NaNs or denormals that flag may break your program.
- MaxBarraclough 8y ago> -ffast-math is a shotgun that affects a lot of things Interesting point. GCC and MSVC both seem to have (incompatible) intrinsic functions, for what that's worth. https://gcc.gnu.org/onlinedocs/gcc-4.8.5/gcc/X86-Built-in-Functions.html https://gcc.gnu.org/onlinedocs/gcc-4.8.5/gcc/X86-Built-in-Fu... https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2008/2h228y72%28v%3dvs.90%29 https://docs.microsoft.com/en-us/previous-versions/visualstu...
- mmozeiko 8y agoThat is not quite true. You don't need to use GCC __builtin functions for this. GCC supports SSE1 intrinsics like _mm_rsqrt_ss exactly same as MSVC - it is declared in xmmintrin.h header. Just include it and _mm_rsqrt_ss/ps will be available for you in gcc and msvc.
- edynoid 8y agoI find it quite fortunate, that they don't use it automatically. Introducing a 1e-3 relative error is quite a deal breaker for some. Not for games sure, but for science that is mostly unacceptable.
- meta_AU 8y agoFrom memory, GCC does one NewtonRaphson iteration on the approximate result so the error is much lower (closer to e-9 from memory again). They don't use the approximation directly in fast-math mode.
- deleted 8y ago[deleted]
- convolvatron 8y agothis is wildly off topic, but can anyone from either the scientific or the graphics community comment on the practical impact of losing denorms? i certainly understand that it softens the impact of underflow, but does anyone care?
- simonbyrne 8y agoAh, I should have done more googling. I guess the AVX-512 ones are marginally more accurate?