2026-06-04 12:20 AM
I need to perform lot of mathematical calculations and within a fixed time interval, the micro is STM32G474 my question is even if floating point calculator is available, do you recommend to use fixed point calcuations Q15 format etc. or I can go ahead with floating point calculations, will i get same performance? Please clarify.
Solved! Go to Solution.
2026-06-04 12:49 AM
If you get the needed precision by integer/fixed point calculation, it will always be faster than floating point, just because loading the floating point registers needs more time (32 or 64b) than having the value in 16b in the CPU registers and do one clock multiply.
Just do some simple test loops with the calculations you need and compare the time needed. I always do it, because this is 100% what you will get on this machine.
And always have optimizer on , -O2 is a fine setting, otherwise you see not the real performance of an arm CPU.
2026-06-04 12:49 AM
If you get the needed precision by integer/fixed point calculation, it will always be faster than floating point, just because loading the floating point registers needs more time (32 or 64b) than having the value in 16b in the CPU registers and do one clock multiply.
Just do some simple test loops with the calculations you need and compare the time needed. I always do it, because this is 100% what you will get on this machine.
And always have optimizer on , -O2 is a fine setting, otherwise you see not the real performance of an arm CPU.
2026-06-04 12:57 AM
I agree.
But another issue should be considered: with integral or fixed point arithmetic you need to be very clear about the range for your initial, intermediate and final values.
Floating point arithmetic is much more indulgent.
2026-06-04 12:58 AM
Just one question related to above what is the benefit of CORDIC and FMAC modules? can i assume it is only in case i require more precision as per above explanation?
2026-06-04 1:02 AM
Yes i really get confused with fixed point calculations, that is the concern i have.
2026-06-04 1:35 AM - edited 2026-06-04 1:36 AM
CORDIC gives you not more precision. It is either q1.15 or q1.31.
It is just a bunch of algorithms, which can be implemented efficiently in hardware for trigionometric functions, logarithms and square roots (using add and shift to avoid multiplication).
It is a bit strange regarding the representaion, e.g. angles range from -1 to +1 instead of -π to +π.
2026-06-04 1:45 AM - edited 2026-06-04 1:48 AM
Beware that the hardware FP unit in Cortex-M4 is only single precision:
https://mcuoneclipse.com/2019/03/29/be-aware-floating-point-operations-on-arm-cortex-m4f/
And floating point inherently has a number of issues:
What Every Computer Scientist Should Know About Floating-Point Arithmetic
There's an old computer science saying:
"If you think you need floating point to solve the problem, you don't understand the problem;
If you really do need floating point, then you have a problem you do not understand"
PS:
Previously, on this forum:
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.