Optimization caused loss of accurracy

Optimization caused loss of accurracy

Hi everybody!

I'm posting an update related to my VecLib project.While testing slightly optimized version of sine function where the sine convergence
is achieved with the help of SSE inline assembly I ran into some problem.I eliminated one instruction which performed explicit multiplication of the argument by x^2 so the total count of instruction per one term was three,but the accurracy was greatly reduced up to 2-3 decimal places.Double precision  primitives were used so the loss of accurracy can not be blamed for the inaccurate result.
I suspect that somehow combined multiplication of an argument by pre-calculated coefficient coupled with exponentiation of the argument all of it performed in the same xmm0 register which served as an accumulator could have caused probably the loss in accuracy.
I rewrote the inline asm block and removed the load of xmm0 register by adding another instruction which multiplies the argument by x^2 and that problem dissapeared.
Please look at Vec_Sin_f() function inline assembly code block and Vec_Cos_d() inline assembly block.

Here is the part of optimized code which is responsible for the loss of accuracy.This code calculate third term of Taylor expansion by mean of of Horner scheme

movupd xmm1,veclib3

mulpd xmm0,xmm1
This part of the code is responsible for the inaccurrate result

addpd xmm7,xmm0

And here is the part of corrected code.I added another instruction which performs a multiplication of an argument by x^2 in different register

movupd xmm1,vec3lib

mulpd xmm0,xmm5

mulpd xmm1,xmm0

addpd xmm7,xmm1

Thanks in advance.

Downloadtext/plain vec-lib.txt8.56 KB
2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Can anyone shed light on that issue?

Leave a Comment

Please sign in to add a comment. Not a member? Join today