aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libm_dbl/thumb_vfp_sqrt.c10
-rw-r--r--ports/stm32/Makefile6
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/libm_dbl/thumb_vfp_sqrt.c b/lib/libm_dbl/thumb_vfp_sqrt.c
new file mode 100644
index 000000000..dd37a07b0
--- /dev/null
+++ b/lib/libm_dbl/thumb_vfp_sqrt.c
@@ -0,0 +1,10 @@
+// an implementation of sqrt for Thumb using hardware double-precision VFP instructions
+
+double sqrt(double x) {
+ double ret;
+ asm volatile (
+ "vsqrt.f64 %P0, %P1\n"
+ : "=w" (ret)
+ : "w" (x));
+ return ret;
+}
diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile
index 1a4e3c690..28b90199a 100644
--- a/ports/stm32/Makefile
+++ b/ports/stm32/Makefile
@@ -173,12 +173,16 @@ SRC_LIBM = $(addprefix lib/libm_dbl/,\
scalbn.c \
sin.c \
sinh.c \
- sqrt.c \
tan.c \
tanh.c \
tgamma.c \
trunc.c \
)
+ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f7 h7))
+SRC_LIBM += lib/libm_dbl/thumb_vfp_sqrt.c
+else
+SRC_LIBM += lib/libm_dbl/sqrt.c
+endif
else
SRC_LIBM = $(addprefix lib/libm/,\
math.c \