From cd527bb324ade952d11a134859d38bf5272c165e Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 3 Nov 2016 12:26:32 +1100 Subject: [PATCH] lib/libm: Move Thumb-specific sqrtf function to separate file. This allows it to be used only when the hardware supports VFP instructions, preventing compile errors. --- lib/libm/math.c | 13 ------------- lib/libm/thumb_vfp_sqrtf.c | 11 +++++++++++ stmhal/Makefile | 1 + 3 files changed, 12 insertions(+), 13 deletions(-) create mode 100644 lib/libm/thumb_vfp_sqrtf.c diff --git a/lib/libm/math.c b/lib/libm/math.c index 7cbec5fb3..732049236 100644 --- a/lib/libm/math.c +++ b/lib/libm/math.c @@ -86,19 +86,6 @@ double __aeabi_dmul(double x , double y) { #endif // defined(__thumb__) -// TODO this needs a better way of testing for Thumb2 FP hardware -#if defined(__thumb2__) - -float sqrtf(float x) { - asm volatile ( - "vsqrt.f32 %[r], %[x]\n" - : [r] "=t" (x) - : [x] "t" (x)); - return x; -} - -#endif - #ifndef NDEBUG float copysignf(float x, float y) { float_s_t fx={.f = x}; diff --git a/lib/libm/thumb_vfp_sqrtf.c b/lib/libm/thumb_vfp_sqrtf.c new file mode 100644 index 000000000..12ffebf82 --- /dev/null +++ b/lib/libm/thumb_vfp_sqrtf.c @@ -0,0 +1,11 @@ +// an implementation of sqrtf for Thumb using hardware VFP instructions + +#include + +float sqrtf(float x) { + asm volatile ( + "vsqrt.f32 %[r], %[x]\n" + : [r] "=t" (x) + : [x] "t" (x)); + return x; +} diff --git a/stmhal/Makefile b/stmhal/Makefile index e2e1dc6a1..a7a3018cc 100644 --- a/stmhal/Makefile +++ b/stmhal/Makefile @@ -81,6 +81,7 @@ endif SRC_LIB = $(addprefix lib/,\ libc/string0.c \ libm/math.c \ + libm/thumb_vfp_sqrtf.c \ libm/asinfacosf.c \ libm/atanf.c \ libm/atan2f.c \