Skip to content

Commit

Permalink
lib/libm: Move Thumb-specific sqrtf function to separate file.
Browse files Browse the repository at this point in the history
This allows it to be used only when the hardware supports VFP
instructions, preventing compile errors.
  • Loading branch information
dpgeorge committed Nov 3, 2016
1 parent 828df54 commit cd527bb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
13 changes: 0 additions & 13 deletions lib/libm/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
11 changes: 11 additions & 0 deletions lib/libm/thumb_vfp_sqrtf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// an implementation of sqrtf for Thumb using hardware VFP instructions

#include <math.h>

float sqrtf(float x) {
asm volatile (
"vsqrt.f32 %[r], %[x]\n"
: [r] "=t" (x)
: [x] "t" (x));
return x;
}
1 change: 1 addition & 0 deletions stmhal/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit cd527bb

Please sign in to comment.