Math library for Optimized for FPU

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Math library for Optimized for FPU

Jump to solution
2,692 Views
petermckinnis
Contributor II

I am working on a project using a Kinetis K60F processor with a FPU.  I noticed that the standard math library (math.h) seems to be implemented in software.  For example, the following code (see below) to take the sin of 0.0 is implemented in double precision (per the C standard).  Is there a compiler option somewhere that uses hardware accelerated math routines, (or alternatively a third party library)?  If so, how can I use this library.


#include <math.h>

void aFunction() {
float ans = sin(0.0f);  //Gives compiler warning: implicit arithmetic conversion from 'double' to 'float'
}

Tags (3)
1 Solution
5 Replies
1,069 Views
BlackNight
NXP Employee
NXP Employee

Hello,

have you selected the options for hardware math (see screenshot from CW MCU10.3)?

floating point options.png

About the warning: this sounds ok to me, as sin() returns a double, and you are assigning it to a float. Casting it to a float would suppress that warning.

Hope this helps,

Erich

0 Kudos
1,069 Views
petermckinnis
Contributor II

Erich

Thanks for the response.  Yes, I have hardware math enabled.

I think I mis-stated my question.   I wan't concerned about the compiler warning per say.  I want to use a version of the sin function that is implemented using single precision arithmetic.  The default math.h version does all calculations in double precision.  Since the K60F series of chips only has a single precision FPU, every opperation in the sin function is implemented in software and the calculation is VERY slow.  In summary the standard sine calculation is doing the following:

1.) Promotes the angle argument from float to double.

2.) Calculates the sin using software emulated double precision calculations.  FPU is not used.

3.) Casts the result back to a float.

I was wondering if there is a library that can do the following.

1.) Calculate sine in single precision, so that the FPU is used.  Argument and result will also be in single precision so no conversion will be necessary.

It would be best if the library was optomized for the arm M4 fpu core.

Thanks

Peter

0 Kudos
1,069 Views
JimDon
Senior Contributor III

That is the standard for the "C" math.h lib.

You will need to track down an  alternative I think. You can most likely find source for a fast sin function.

0 Kudos
1,069 Views
petermckinnis
Contributor II

After some digging, I found that ARM actually publishes an optomized DSP library for all arm Cortex-M variants.  The library is called CMSIS.

http://www.arm.com/products/processors/cortex-m/cortex-microcontroller-software-interface-standard.p...

1,070 Views
JimDon
Senior Contributor III