Hi,
I am using S32K14x controllers (Coretx-M4F). It has floating point math unit. I need to perform many mathematical operations as fast as possible. Which will be faster: fixed point q16 or fixed point q32 or single precision (32 bit) floating point?
Regards,
Pramod
Pramod Ranade said:fixed point math (using the DSP instructions) is faster than floating point math (using FPU). But the difference is marginal
thanks for the feedback.
An issue often noted with fixed point is that, aside from the actual calculations, it adds overhead & complexity to the code which needs to supply the input data and/or use the results. So I guess one would need a wider benchmark to see if that tips the balance for the overall system ... ?
#FloatingVsFixedPoint
Andy Neil said:An issue often noted with fixed point is that, aside from the actual calculations, it adds overhead & complexity to the code which needs to supply the input data and/or use the results.
I agree.
Another problem in using fixed point is that code won't be portable due to the use of non-standard intrinsic functions like __SMMLA etc.
One problem in using float is that it will increase ISR entry and exit times, due to the need of saving and restoring FPU registers.
Hi Pramod,
Hypothetically yes, however do your ISRs use the FPU registers?
Ronan Synnott said:Hypothetically yes, however do your ISRs use the FPU registers?
Yes!
Intrinsic functions are more commonly used for 'non C' type actions, such as barrier instructions. In higher order code, the compiler will generate VFP instructions automatically when compiled for VFP. If you really want to hand craft a function, you would use assembler, rather than intrinsics. For example:
float foo(float a, float b){ return (a+b); }
Compiled with:
armclang -c -O2 --target=arm-arm-none-eabi -mcpu=cortex-m4 -mfpu=vfpv3 float.c
outputs:
foo 0x00000000: ee001a10 .... VMOV s0,r1 0x00000004: ee010a10 .... VMOV s2,r0 0x00000008: ee310a00 1... VADD.F32 s0,s2,s0 0x0000000c: ee100a10 .... VMOV r0,s0 0x00000010: 4770 pG BX lr
For completeness, when compiled without VFP it calls a library function, which will take many cycles
foo 0x00000000: f7ffbffe .... B.W __aeabi_fadd