I was wondering if exp()
is faster than more general pow()
. I run fast benchmark on JsPerf http://jsperf.com/pow-vs-exp and it shown interesting result
As a partial answer, there are instructions for exp, log or pow on some architectures yes. However, that doesn't necessarily mean much.
For example, on x86 there's
f2xm1
which calculates 2x - 1fscale
which calculates y * 2(int)xfyl2x
which calculates y * log2 xfyl2xp1
which calculates y * log2(x + 1) (has restrictions on input range)However, they are not much used. It varies from architecture to architecture, but they're never fast. As a more extreme example, fyl2x
has a latency of 724 on Sandy Bridge (pretty recent!), in that time on the same processor you could do about 700 independent floating point additions, or about 240 dependent floating point additions, or about 2000 independent simple integer operations.
That's about as bad as it gets, but they're typically slow. Slow enough that a manual implementation can beat them or at least not significantly lose.
Also, FPU code is slowly disappearing in favour of SSE code. There are no SSE equivalents of those instructions.