cglm
cglm copied to clipboard
Use `_mm_sincos_ps` where both sin and cos are calculated for same angle
In //include/cglm/quat.h
, we've glm_quatv
which calculates a new quaternion from axis and angle; it does
c = cosf(a);
s = sinf(a);
This can be optimized by using
-
_mm_sincos_ps
- For non-SIMD cases, some platforms like Linux support
sincos
Moving to this would be a nice (micro-)optimization 😉
Related discussion on StackOverflow: What is the fastest way to compute sin
and cos
together?.
@legends2k thanks, I like micro optimizations :) we can create a function like glm_sincos()
then use _mm_sincos_ps()
in for related platforms, I liked the idea
It seems compilers can do this optimization for many platforms:
Details
@myfreeer thanks for the detailed explanation but I still like glm_sincos()
idea which uses sincos
internally if available, compilers may optimize this small inline function more easily without doubt rather than complex func I guess:
glm_sincos( ... ) {
*s = sinf(a);
*c = cosf(a);
}
let's keep the issue open for a while.
Another benefit to glm_sincos
is that most sin/cos approximation functions (e.g., when cross-platform determinism is required) compute both values simultaneously (rather, it is "free" to compute them simultaneously). So it is usually a nice abstraction to have.
@gottfriedleibniz thanks for your feedback[s]