cancel
Showing results for 
Search instead for 
Did you mean: 

Floating point instructions

Vivek Sankaranarayanan
Associate II
Posted on August 17, 2017 at 15:16

I am using STM32F303VC with System Workbench IDE.

I can't for the life of me get the hard floating point option to work. The compiler never generates floating point instructions. It' only generating soft code with library calls. Anyone knows what the problem could be?

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on August 17, 2017 at 20:36

What is your SW4STM32 version ?

Maybe upgrade to latest version should be fix your issue.

Best regards

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

10 REPLIES 10
Posted on August 17, 2017 at 17:01

>>Anyone knows what the problem could be?

Settings and defines sent to the compiler? Not hard to get GNU/GCC to compile FPU instructions.

The FPU only supports 32-bit floats, not doubles.

1.23 is a double, 1.23f is a float

printf/scanf use doubles

The FPU only supports simple arithmetic functions, anything complex or transcendental will use mix of software/hardware.

Most stuff tends to use the Soft ABI, though that might be changing now the M7 and M4F are getting more prevalent.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
RomainR.
ST Employee
Posted on August 17, 2017 at 17:12

Hi,

Can you check the configuration of your project this way:

Into 

System Workbench Project \ Properties \ C/C++ Build \ Settings \ Tool Settings \ Preprocessor

Check if __FPU_PRESENT and __FPU_USED symbols are defined

0690X00000607waQAA.png

And then into MCU Settings Floating Point ABI is hard

0690X00000607rmQAA.png

Best regards

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on August 17, 2017 at 19:42

I have both those symbols defined in the preprocessor.

But my problem could be this. I cannot select anything under Float Point Hardware. I have only No unit listed.

0690X00000607wqQAA.png

Could this be the problem?

Posted on August 17, 2017 at 19:46

The FPU only supports 32-bit floats, not doubles.

1.23 is a double, 1.23f is a float

printf/scanf use doubles

The FPU only supports simple arithmetic functions, anything complex or transcendental will use mix of software/hardware.

Most stuff tends to use the Soft ABI, though that might be changing now the M7 and M4F are getting more prevalent.

So i have a simple statement saying:

float x; x = 1.25; x = x*x;

x = 1.25; x = x*x;

x = x*x;

Going through the dissasembly I don't see a single floating point instruction. Even if it were double, the compiler must be making use of 32bit floating point hardware to do double right?

Posted on August 17, 2017 at 20:36

What is your SW4STM32 version ?

Maybe upgrade to latest version should be fix your issue.

Best regards

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on August 17, 2017 at 21:32

The optimizer should flatten that to constants.

This was one of my test cases, built with GNU/GCC 4.9.3

float test1(float x, float y)

{

  return(x + y + sqrtf((x * x) + (y * y)));

}

demo.lss listing

...

08002578 <test1>:

//******************************************************************************

♯ include <math.h>

float test1(float x, float y)

{

 8002578:    b508          push    {r3, lr}

 800257a:    ed2d 8b02     vpush    {d8}

 800257e:    eeb0 8a40     vmov.f32    s16, s0

  return(x + y + sqrtf((x * x) + (y * y)));

 8002582:    ee20 0aa0     vmul.f32    s0, s1, s1

//******************************************************************************

♯ include <math.h>

float test1(float x, float y)

{

 8002586:    eef0 8a60     vmov.f32    s17, s1

  return(x + y + sqrtf((x * x) + (y * y)));

 800258a:    eea8 0a08     vfma.f32    s0, s16, s16

 800258e:    f001 fcd9     bl    8003f44 <sqrtf>

 8002592:    ee38 8a28     vadd.f32    s16, s16, s17

}

 8002596:    ee38 0a00     vadd.f32    s0, s16, s0

 800259a:    ecbd 8b02     vpop    {d8}

 800259e:    bd08          pop    {r3, pc}

Compiling file: main.c

arm-none-eabi-gcc -c -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16

-Os -ffunction-sections -fdata-sections -Wall -Wstrict-prototypes -Wextra -std=gnu89

-g -ggdb3 -fverbose-asm -Wa,-ahlms=out/main.lst  -DUSE_STDPERIPH_DRIVER 

-DSTM32F4XX  -DUSE_STM32F4_DISCOVERY  -DUSE_USB_OTG_FS  -DHSE_VALUE=8000000 

-D__FPU_PRESENT=1 -MD -MP -MF out/main.d -I.  -Iinc main.c -o out/main.o

Linking target: out/demo.elf

arm-none-eabi-g++ -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16

-Tstm32f4xx.ld -g -Wl,-Map=out/demo.map,--cref,--no-warn-mismatch -Wl,--gc-sections

-nostartfiles  out/startup_stm32f4xx.o out/diskio.o out/ff.o out/main.o out/misc.o

out/newlib_stubs.o out/stm32f4_discovery.o out/stm32f4_discovery_sdio_sd.o

out/stm32f4xx_dma.o out/stm32f4xx_gpio.o out/stm32f4xx_rcc.o out/stm32f4xx_sdio.o

out/stm32fxxx_it.o out/system_stm32f4xx.o    -o out/demo.elf
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on August 18, 2017 at 10:15

Oh.. yes.. Finally.. Upgrade did the trick..

I hate it when upgrading fixes a compiler issue. That's so non-intuitive. Wouldn't have figured it out ever!!

Posted on August 18, 2017 at 10:25

Great !!!

Official thread on AC6 forum here.

http://www.openstm32.org/forumthread92

 

BR

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on August 18, 2017 at 14:01

Not really a compiler issue, that's worked for years, the IDE hiding the options/settings is the problem.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..