vorner / slipstream

Nudging the compiler to auto-vectorize things
Apache License 2.0
71 stars 4 forks source link

Trigonometry functions #3

Open vorner opened 4 years ago

vorner commented 4 years ago

It seems processors don't have direct support for computing trigonometry functions like sin or cos, neither in scalar nor vector form. Standard libraries/libm supplies the scalar versions.

Therefore, the way other operations in slipstream are constructed (by calling a scalar operation for each lane and hoping for the best) won't get auto-vectorized.

So the alternative is borrow the scalar implementation somewhere, but rewrite it expressing the vectors (and blends instead of conditionals). These primitive operations should get autovectorized OK.

From a first glance, I don't see why this actually works (one example taken from over the internet): https://github.com/JuliaMath/openlibm/blob/97de1a46a9fedec7749e10da6770d189ff8012e9/src/s_sincos.c#L89.

What needs to be done:

If someone has the time and wants to play with it, please claim the issue so people don't collide (writing a comment is fine). I'm not sure myself when I might find the time for this, but I'll be happy to discuss anything.