Optimization caused loss of accurracy

Optimization caused loss of accurracy

iliyapolak的头像

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.

附件尺寸
下载 vec-lib.txt8.56 KB
2 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项
iliyapolak的头像

Can anyone shed light on that issue?

登陆并发表评论。