Created
July 21, 2011 04:07
-
-
Save t-mat/1096468 to your computer and use it in GitHub Desktop.
XMVectorModAngles() compatible function for ARM NEON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
XMVectorModAngles() compatible function for ARM NEON | |
@sa XMVectorModAngles() | |
*/ | |
float32x4_t vectorModAngles(float32x4_t vAngle) { | |
#define M_PI 3.1415926535f | |
float32x4_t v0 = vmulq_f32(vAngle, vdupq_n_f32(1.0f/M_PI)); // v0.xyzw = vAngle.xyzw * vReciprocalPi.xyzw | |
uint32x4_t iq = vcgeq_f32(vAngle, vmovq_n_f32(0.0f)); // iq.xyzw = foreach(vAngle.xyzw) : a { (a > 0) ? -1 : 0; } | |
int32x4_t i1 = vcvtq_s32_f32(v0); // i1.xyzw = round_towards_zero(v0.xyzw); | |
int32x4_t ia = vreinterpretq_s32_u32(iq); // ia.xyzw = int32x4_t(i2.xyzw); | |
int32x4_t i2 = vsubq_s32(i1, ia); // i2.xyzw = i1.xyzw - ia.xyzw | |
int32x4_t i3 = vshrq_n_s32(i2, 1); // i3.xyzw = shift_right_each_component(i2.xyzw, 1) | |
float32x4_t v2 = vcvtq_f32_s32(i3); // v2.xyzw = round(i3.xyzw); | |
float32x4_t v3 = vmlsq_f32(vAngle, v2, vdupq_n_f32(2.0f*M_PI)); // v3.xyzw = vAngle.xyzw - v2.xyzw * vTwoPi.xyzw | |
return v3; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment