commit 0add4c02c451f18ec21f41fa90ce7a360377eb28
parent 133ee9ddb71a879815013ba50476a23b29ef618d
Author: vaplv <vaplv@free.fr>
Date: Fri, 17 Oct 2014 14:41:33 +0200
Add and test the aosf33_load function
Diffstat:
2 files changed, 35 insertions(+), 17 deletions(-)
diff --git a/src/aosf33.h b/src/aosf33.h
@@ -20,13 +20,39 @@
#include <math.h>
/*
- * SIMD Functions on column major AoS float33 matrices. A matrix is
- * respresented by 3 4-wide SIMD float vectors
+ * Functions on column major AoS float33 matrices. A 3x3 matrix is a set of 3
+ * 4-wide SIMD float vectors, each representing a matrix column. Actually the
+ * fourth component of each vector is ignored and its value is thus undefined.
*/
/*******************************************************************************
* Set operations
******************************************************************************/
+static FINLINE float*
+aosf33_store(float res[9]/* Column major */, const v4f_T m[3])
+{
+ ALIGN(16) float tmp[4];
+ int i;
+ ASSERT(res && m);
+ FOR_EACH(i, 0, 3) {
+ v4f_store(tmp, m[i]);
+ res[i*3 + 0] = tmp[0];
+ res[i*3 + 1] = tmp[1];
+ res[i*3 + 2] = tmp[2];
+ }
+ return res;
+}
+
+static FINLINE v4f_T*
+aosf33_load(v4f_T res[3], const float m[9]/* Column major */)
+{
+ int i;
+ ASSERT(res && m);
+ FOR_EACH(i, 0, 3)
+ res[i] = v4f_set(m[i*3+0], m[i*3+1], m[i*3+2], 0.f);
+ return res;
+}
+
static FINLINE v4f_T*
aosf33_set(v4f_T m[3], const v4f_T c0, const v4f_T c1, const v4f_T c2)
{
@@ -284,21 +310,6 @@ aosf33_col(const v4f_T m[3], int id)
return m[id];
}
-static FINLINE float*
-aosf33_store(float res[9] /* Column major */, const v4f_T m[3])
-{
- ALIGN(16) float tmp[4];
- int i;
- ASSERT(res && m);
- FOR_EACH(i, 0, 3) {
- v4f_store(tmp, m[i]);
- res[i*3 + 0] = tmp[0];
- res[i*3 + 1] = tmp[1];
- res[i*3 + 2] = tmp[2];
- }
- return res;
-}
-
/*******************************************************************************
* Build functions
******************************************************************************/
diff --git a/src/test_aosf33.c b/src/test_aosf33.c
@@ -54,6 +54,13 @@ main(int argc, char** argv)
CHECK(aosf33_zero(m), m);
AOSF33_EQ(m, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f);
+ f3(tmp+0, -1.f, -2.f, -3.f);
+ f3(tmp+3, -4.f, -5.f, -6.f);
+ f3(tmp+6, -7.f, -8.f, -9.f);
+ CHECK(aosf33_load(m, tmp), m);
+ AOSF33_EQ(m, -1.f, -2.f, -3.f, -4.f, -5.f, -6.f, -7.f, -8.f, -9.f);
+
+ CHECK(aosf33_zero(m), m);
CHECK(aosf33_set_row0(m, v4f_set(0.f, 1.f, 2.f, 9.f)), m);
AOSF33_EQ(m, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 2.f, 0.f, 0.f);
CHECK(aosf33_set_row1(m, v4f_set(3.f, 4.f, 5.f, 10.f)), m);