summaryrefslogtreecommitdiff
path: root/common/vec3.c
diff options
context:
space:
mode:
authorYilun Lin <yllin@google.com>2018-10-04 10:19:57 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-10-04 12:55:53 -0700
commit315aaca9467f49bc432ef5f2de9c0e3bb56f0251 (patch)
tree3ea739aca1db340e93b9daee7958d5afc5c9f31f /common/vec3.c
parentece03ab4d09b157c5e6f3c4fe0446678c0d8684b (diff)
downloadchrome-ec-315aaca9467f49bc432ef5f2de9c0e3bb56f0251.tar.gz
mag_cal: Support fixed-point calculation.
Modified from floating point version. This includes changes to vec3, vec4, mat33, mat44, and mag_cal. Now fixed-point type (fp_*) functions is a function wrapper for both fixed-point and floating point version operations: * define CONFIG_FPU to use floating version mag_cal * undef CONFIG_FPU to use fixed-point version mag_cal Also, add tests for both float and fp types operations. TEST=define CONFIG_FPU; flash on reef; See ARC++ magnetmeter app moving. TEST=undef CONFIG_FPU; flash on reef; See ARC++ magnetmeter app moving. TEST=make runtests -j TEST=make buildalltests -j BUG=b:113364863 BRANCH=None Change-Id: Ie695945acb666912babb2a603e09c602a0624d44 Signed-off-by: Yilun Lin <yllin@google.com> Reviewed-on: https://chromium-review.googlesource.com/1260704 Commit-Ready: Yilun Lin <yllin@chromium.org> Tested-by: Yilun Lin <yllin@chromium.org> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
Diffstat (limited to 'common/vec3.c')
-rw-r--r--common/vec3.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/common/vec3.c b/common/vec3.c
index 4c157467c1..9a3561365a 100644
--- a/common/vec3.c
+++ b/common/vec3.c
@@ -9,25 +9,24 @@
#include "vec3.h"
#include "util.h"
-void floatv3_scalar_mul(floatv3_t v, float c)
+void fpv3_scalar_mul(fpv3_t v, fp_t c)
{
- v[X] *= c;
- v[Y] *= c;
- v[Z] *= c;
+ v[X] = fp_mul(v[X], c);
+ v[Y] = fp_mul(v[Y], c);
+ v[Z] = fp_mul(v[Z], c);
}
-float floatv3_dot(const floatv3_t v, const floatv3_t w)
+fp_t fpv3_dot(const fpv3_t v, const fpv3_t w)
{
- return v[X] * w[X] + v[Y] * w[Y] + v[Z] * w[Z];
+ return fp_mul(v[X], w[X]) + fp_mul(v[Y], w[Y]) + fp_mul(v[Z], w[Z]);
}
-float floatv3_norm_squared(const floatv3_t v)
+fp_t fpv3_norm_squared(const fpv3_t v)
{
- return floatv3_dot(v, v);
+ return fpv3_dot(v, v);
}
-float floatv3_norm(const floatv3_t v)
+fp_t fpv3_norm(const fpv3_t v)
{
- return sqrtf(floatv3_norm_squared(v));
+ return fp_sqrtf(fpv3_norm_squared(v));
}
-