diff options
author | Yilun Lin <yllin@google.com> | 2018-09-13 14:41:51 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-09-26 10:32:47 -0700 |
commit | 56d600bb39433f804db4cc45e2b32fd6523b2316 (patch) | |
tree | f37b3ab42f6328018c8dc715a453b8f46dfc9ece /common/math_util.c | |
parent | 77949dd9fb9fc5de724690895d770b7b31f0b572 (diff) | |
download | chrome-ec-56d600bb39433f804db4cc45e2b32fd6523b2316.tar.gz |
math_util: Support fixed-point sqrtf fp_sqrtf.
TEST=make buildall -j
BUG=b:113364863
BRANCH=None
Change-Id: I63ee741a08e39cf6f234a2131137144c46ae0bbd
Signed-off-by: Yilun Lin <yllin@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1235476
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Yilun Lin <yllin@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
Diffstat (limited to 'common/math_util.c')
-rw-r--r-- | common/math_util.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/common/math_util.c b/common/math_util.c index d0b5887199..5e45f9efad 100644 --- a/common/math_util.c +++ b/common/math_util.c @@ -86,10 +86,16 @@ static inline int int_sqrtf(fp_inter_t x) { return sqrtf(x); } + +/* If the platform support FPU, just return sqrtf. */ +fp_t fp_sqrtf(fp_t x) +{ + return sqrtf(x); +} #else static int int_sqrtf(fp_inter_t x) { - int rmax = 0x7fffffff; + int rmax = INT32_MAX; int rmin = 0; /* Short cut if x is 32-bit value */ @@ -124,7 +130,14 @@ static int int_sqrtf(fp_inter_t x) } } } -#endif + +fp_t fp_sqrtf(fp_t x) +{ + fp_inter_t preshift_x = (fp_inter_t)x << FP_BITS; + + return int_sqrtf(preshift_x); +} +#endif /* CONFIG_FPU */ int vector_magnitude(const intv3_t v) { |