4 ms·
Huh, why would reciprocal sqrt and fpmul be faster than regular sqrt?
by pxmpxm 2y ago
Huh, why would reciprocal sqrt and fpmul be faster than regular sqrt?
- pkhuong 2y agoIt's less accurate.
- GrantMoyer 2y agoIntel's explanation (at section 15.12): https://cdrdv2.intel.com/v1/dl/getContent/814198?fileName=248966-Optimization-Reference-Manual-V1-050.pdf#G16.92586 https://cdrdv2.intel.com/v1/dl/getContent/814198?fileName=24... > In Intel microarchitectures prior to Skylake, the SSE divide and square root instructions DIVPS and SQRTPS have a latency of 14 cycles (or the neighborhood) and they are not pipelined. This means that the throughput of these instructions is one in every fourteen cycles. The 256-bit Intel AVX instructions VDIVPS and VSQRTPS execute with 128-bit data path and have a latency of twenty-eight cycles and they are not pipelined as well. > In microarchitectures that provide DIVPS/SQRTPS with high latency and low throughput, it is possible to speed up single-precision divide and square root calculations using the (V)RSQRTPS and (V)RCPPS instructions. For example, with 128-bit RCPPS/RSQRTPS at five-cycle latency and one-cycle throughput or with 256-bit implementation of these instructions at seven-cycle latency and two-cycle throughput, a single Newton-Raphson iteration or Taylor approximation can achieve almost the same precision as the (V)DIVPS and (V)SQRTPS instructions (emphasis mine)
- dooglius 2y agoThat's a different case where one is trying to calculate rsqrt(x) from 1/sqrt(x) whereas the article involves computing sqrt(x) from x*rsqrt(x) and in this case you don't need the divps instruction for sqrt but do need an additional mul instruction for the rsqrt case.
- GrantMoyer 2y agoI think you've misread the section: > it is possible to speed up single-precision divide and square root calculations using the (V)RSQRTPS and (V)RCPPS instructions
- TinkersW 2y agoOnly on some older hardware really, pretty dumb optimization from clang, people writing SIMD probably already know this trick and have a version of sqrt that is exactly this, so going behind their backs and forcing it when they requested sqrt_ps is very uncool.
- cozzyd 2y agoArguably this is an incorrect default of mtune