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'
}
已解决! 转到解答。
You can down load the source from here:
Hello,
have you selected the options for hardware math (see screenshot from CW MCU10.3)?
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
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
After some digging, I found that ARM actually publishes an optomized DSP library for all arm Cortex-M variants. The library is called CMSIS.