Skip to content

Commit cd527bb

Browse files
committed
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.
1 parent 828df54 commit cd527bb

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

lib/libm/math.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,6 @@ double __aeabi_dmul(double x , double y) {
8686

8787
#endif // defined(__thumb__)
8888

89-
// TODO this needs a better way of testing for Thumb2 FP hardware
90-
#if defined(__thumb2__)
91-
92-
float sqrtf(float x) {
93-
asm volatile (
94-
"vsqrt.f32 %[r], %[x]\n"
95-
: [r] "=t" (x)
96-
: [x] "t" (x));
97-
return x;
98-
}
99-
100-
#endif
101-
10289
#ifndef NDEBUG
10390
float copysignf(float x, float y) {
10491
float_s_t fx={.f = x};

lib/libm/thumb_vfp_sqrtf.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// an implementation of sqrtf for Thumb using hardware VFP instructions
2+
3+
#include <math.h>
4+
5+
float sqrtf(float x) {
6+
asm volatile (
7+
"vsqrt.f32 %[r], %[x]\n"
8+
: [r] "=t" (x)
9+
: [x] "t" (x));
10+
return x;
11+
}

stmhal/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ endif
8181
SRC_LIB = $(addprefix lib/,\
8282
libc/string0.c \
8383
libm/math.c \
84+
libm/thumb_vfp_sqrtf.c \
8485
libm/asinfacosf.c \
8586
libm/atanf.c \
8687
libm/atan2f.c \

0 commit comments

Comments
 (0)