cancel
Showing results for 
Search instead for 
Did you mean: 

FPU

matic
Associate III
Posted on October 08, 2015 at 21:05

Hi.

I am developing product, which should be small and fast as possible at the same time. Usually, I use parts which are in 48 pin QFPN or LQFP packages. Till now, I used F1 parts, but recently I went to F3. On F1 I did all calculations with integers only, because F1 doesn't have FPU and calculations with floats were too slow. Now, F3 parts also have FPU and I would like to ask a few questions.

First, how comparable is float calculation (with FPU enabled) with integer calculation in terms of speed?

Do you always use FPU and floats, even if speed is important for your application?

How could I enable FPU in Keil?

Is it possible to write FPU instructions in C or is it necessary to use assembly?

Thanks

#stm32f3 #fpu
5 REPLIES 5
Posted on October 08, 2015 at 21:45

Keil has this ''Floating Point Hardware'' ''Use FPU'' combo-box. Causes it to generate FPU code, push/pop register, and use FPU based library code. The FPU only implements relatively simple operations, it's not an Intel 80x87 type FPU.

32-bit floats have awful precision, and it's not as if the FPU carries the values with higher precision for intermediate results. I generally avoid them unless the math and the number-space is very well understood.

If you have an efficient integer implementation, I'd stick with it. Benchmark your code/algorithm implemented both ways. I have some code where the original author moved directly into 64-bit doubles from 64-bit integers and did the math, by keeping the math integer until I'd dropped the significant bit count below 50-bits we gained significant precision in the fractional portion of the results (all values below 0.1).

The F1 was somewhat crippled by the slow FLASH, this was significantly remedied in the F2/F4 implementation.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Chris1
Senior III
Posted on October 09, 2015 at 21:08

You may find ST's Application note AN4044 Using floating-point unit (FPU) with

STM32F405/07xx and STM32F415/417xx microcontrollers interesting.

The FPU offers arithmetic instructions for:

�? Absolute value (1 cycle)

�? Negate of a float or of multiple floats (1 cycle)

�? Addition (1 cycle)

�? Subtraction (1 cycle)

�? Multiply, multiply accumulate/subtract, multiply accumulate/subtract then negate (3

cycles)

�? Divide (14 cycles)

�? Square root (14 cycles)

etc.

Your compiler should be able to generate appropriate basic FPU instructions straight from C code.  If you use an RTOS, it's best if it has support for the ARM FPU (so that it automatically saves / restores the FPU context).

matic
Associate III
Posted on October 09, 2015 at 21:58

Thank you both.

Posted on October 09, 2015 at 22:16

�? Multiply, multiply accumulate/subtract, multiply accumulate/subtract then negate (3 cycles)

 

�? Divide (14 cycles)

Smiles, and let's the compiler compute reciprocal constants.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Bassett.David
Senior
Posted on October 09, 2015 at 22:34

I can confirm the Keil readily produces mentioned reciprocal constants!

Is anyone aware of the cycle counts for double precision operations on the 'F7 FPU?  I have been looking for this information since September 24th, 2014...

Regards,

Dave