Re:A not so fast implementation of cosine similarity in C++ ...
by adgjlsfhk1 on Tuesday October 15, 2024 @06:33PM
(#41853821)
yeah you generally can't approximate sqrt faster than computing it. sqrt is generally roughly as fast as division.
I wonder have you tried non-approximated intrinsics like _mm_div_ps( mul, _mm_sqrt_ps( div2 ) ) ?
The reason standard library is so slow is exception handling and other edge cases. On modern CPUs normal non-approximated FP division and square root instructions aren’t terribly slow, e.g. on my computer FP32 square root instruction has 15 cycles latency and 0.5 cycles throughput.