3 ms·
x87 trig instructions are pretty inaccurate even in the supported range mainly because of faulty range reduction [1] and can't be vectorized at all. If you have
by lifthrasiir 5y ago
x87 trig instructions are pretty inaccurate even in the supported range mainly because of faulty range reduction [1] and can't be vectorized at all. If you have trig-heavy workloads nowadays you would want SIMD libm, not x87.
[1] http://notabs.org/fpuaccuracy/ http://notabs.org/fpuaccuracy/
- cogman10 5y agoWhy can't the trig instructions be vectorized? I've never quiet understood why SSE/AVX didn't add trig functions to finally kill off any argument for using x87.
- adrian_b 5y agoUnlike simple operations like a floating-point multiplication, trigonometric functions and the other transcedental functions are too complex, so they must be split into many steps. If a trigonometric function is encoded as a single instruction, then it must launch a microprogram, to execute the many required steps. A microprogram cannot execute faster than when the same execution steps would have been encoded as separate instructions, the only advantage of encoding a trigonometric function in a single instruction would be to reduce the program size. Most programs contain few trigonometric functions, so the reduction in program size is not worthwhile. While a microprogrammed trigonometric function could be as fast as the equivalent sequence of instructions, in reality it is usually much slower. The reason is that the modern CPUs are optimized for the most frequent instructions and they dedicate a minimum of resources for the seldom used microprogrammed instructions, so these hit various limitations that do not exist for the simple instructions. The microprogrammed instructions usually have some phases whose execution cannot be overlapped in time with other instructions, which leads to lower performance.
- cogman10 5y agoGotcha, hence the reason they've added instructions like FMA. Those don't require microprograms but do make things like calculating a taylor series faster. Right?
- jabl 5y agoThere exist libraries that provide SIMD versions (on the fast path) of math functions, e.g. https://sourceware.org/glibc/wiki/libmvec https://sourceware.org/glibc/wiki/libmvec