Good morning
I need to optimize the floating point execution. The CPU is the K64...
I have been looking for similar thematics, but I did not find the right answer. I understand the core is offering the FPU only for the shorter floating,
while for the double only the software emulation is available.
I see the math.h is proposing the functions ex...
sin() and sinf()
for the data of type float and double. In parallel the CMSYS has the function arm_sin_f32() not the arm_sin_f64()
So I have some limited trouble in evaluating the usage of the functions.
1) It seemd for double data type the only function to use is the sin()
2) If I use the sinf() the hardware support is automatically used???
3) Is the arm_sin_f32() better than the sinf() ? Precision wise ???
I would like to be sure the FPU is used. What is the way to verify??? Maybe looking the disassembled code for some floating point instruction....
I will pleasantly book some advice on the subject
Thank You
Solved! Go to Solution.
Hi, Pietro,
I have used the following code based on KDS tools, the f2 return the correct result.
BR
XiangJun Rong
#include "MKV58F22.h"
#include "math.h"
#define PI 3.1415926
static int i = 0;
double f1,f2;
int main(void)
{
/* Write your code here */
f1=1.23;
f2=1.23;
f2=f1+f2;
f1=PI/4.0;
f2=sin(f1);
__asm("nop"); //set break point here to observe the result in debugger
/* This for loop should be replaced. By default this loop allows a single stepping. */
for (;;) {
i++;
}
/* Never leave main */
return 0;
}
Hi, Pietro,
As you said that the Kinetis family K64 has FPU module, which supports float operation. The Floating-Point Unit (FPU) provides IEEE754-compliant operations on single-precision, 32-bit, floating-point values. But the FPU does not support 64 bits double operation.
The CMSIS library only support arm_sin_f32(), arm_sin_q15() anf arm_sin_q31() data format sin operation, but the CMSIS does not support double data format operation either.
Regarding the double data format sin() function, of course, the compiler uses software simulation to implement the double data type sin() function. But it is dependent on the compiler tools whether the double data type sin(0 function is implemented or not.
which compiler tools are you using, KDS, codewarrior for mcu, IAR, Keil? you have to consult the compiler individually.
BR
Xiangjun Rong
Hi, Pietro,
I have used the following code based on KDS tools, the f2 return the correct result.
BR
XiangJun Rong
#include "MKV58F22.h"
#include "math.h"
#define PI 3.1415926
static int i = 0;
double f1,f2;
int main(void)
{
/* Write your code here */
f1=1.23;
f2=1.23;
f2=f1+f2;
f1=PI/4.0;
f2=sin(f1);
__asm("nop"); //set break point here to observe the result in debugger
/* This for loop should be replaced. By default this loop allows a single stepping. */
for (;;) {
i++;
}
/* Never leave main */
return 0;
}
I am trying th get familiar with the FPU, with some help and some try and retry. Thank You for the suggestions.
If You have time, have You tested if the arm_sin_f32() is better than the sinf() ???
Thank You
Hi, Pie,
I think both the function can give correct result, but the arm_sin_f32() takes short time, but the sinf() takes long time due to the fact that the function is implemented by software simulation.
Hope it can help you.
BR
Xiangjun Rong