sse2 version of vec4 dot product

* use this for normalizing vector
This commit is contained in:
Recep Aslantas
2018-04-08 18:27:54 +03:00
parent 932f638d5a
commit e4e0fa623c
7 changed files with 61 additions and 3 deletions

View File

@@ -36,6 +36,16 @@ test_rand_vec3(vec3 dest) {
dest[2] = drand48();
}
void
test_rand_vec4(vec4 dest) {
srand((unsigned int)time(NULL));
dest[0] = drand48();
dest[1] = drand48();
dest[2] = drand48();
dest[3] = drand48();
}
float
test_rand_angle(void) {
srand((unsigned int)time(NULL));

View File

@@ -40,6 +40,9 @@ test_assert_quat_eq(versor v1, versor v2);
void
test_rand_vec3(vec3 dest);
void
test_rand_vec4(vec4 dest) ;
float
test_rand_angle(void);

View File

@@ -26,7 +26,10 @@ main(int argc, const char * argv[]) {
cmocka_unit_test(test_euler),
/* quaternion */
cmocka_unit_test(test_quat)
cmocka_unit_test(test_quat),
/* vec4 */
cmocka_unit_test(test_vec4)
};
return cmocka_run_group_tests(tests, NULL, NULL);

View File

@@ -28,4 +28,7 @@ test_euler(void **state);
void
test_quat(void **state);
void
test_vec4(void **state);
#endif /* test_tests_h */

30
test/src/test_vec4.c Normal file
View File

@@ -0,0 +1,30 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#include "test_common.h"
CGLM_INLINE
float
test_vec4_dot(vec4 a, vec4 b) {
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
}
void
test_vec4(void **state) {
vec4 v;
int i;
float d1, d2;
/* test SSE/SIMD dot product */
for (i = 0; i < 100; i++) {
test_rand_vec4(v);
d1 = glm_vec4_dot(v, v);
d2 = test_vec4_dot(v, v);
assert_true(fabsf(d1 - d2) <= 0.000009);
}
}