Sin(x) Aproximation (with SSE code)

notes
Sin Aproximation: sin(x) = x + ( x * (-x * x / 6));

This is very handy and fast, but not precise. Below you will find a simple SSE code.

Remember that all movaps command requires 16 bit aligned variables.
code
1
2
3
4
5
6
7
8
9
SSE code for computing only ONE value (scalar)
Replace all "ss" with "ps" if you want to calculate 4 values. And instead of "movps" use "movaps".

movss       xmm1,   xmm0                                            ; xmm0 = x
mulss       xmm1,   Filter_GenVal[k_n1]                     ; * -1
mulss       xmm1,   xmm0                                            ; -x * x
divss       xmm1,   Filter_GenVal[k_6]                      ; / 6
mulss       xmm1,   xmm0
addss       xmm0,   xmm1

Comments

Divides hurt. Change your constant 6 to a constant (1.0/6.0) and change divss to mulss.
error about 7.5% by +/- pi/2
you can improve this considerably by
fitting cubic at points -pi/2, 0, pi/2 i.e:
sin(x) = x - x^3 / 6.7901358