Announcements

Curious on how you can apply PSoC™ 6 to Smart Home Appliances? Register for the ASEAN Smart Home Appliance Webinar here to find out how.

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

PSoC™ 6 Forum Discussions

ravo
Level 4
10 likes given 50 replies posted 10 questions asked
Level 4

Dears,

I would like to test GCC compiler and especially arithmetic operations with floating values using FPU unit.  I've written simple "pseudo" code:

...

float32_t x,y,z;

for (int i=0; i<3000; i++)
for (int j=0; j<1000; j++)
{
    x = (float32_t) i;
    y = (float32_t) j;
    z = z / 1000 + x / 1000 + y / 1000;
}

...

Tests:

[1] Enabled FPU - "HARD" mode

file makefile contains:

DEFINES=ARM_MATH_CM4 arm4-asm FLOATING_POINT USE_SMALLFT
VFP_SELECT=hardfp
CFLAGS =-mfloat-abi=hard -mthumb

Disassembly:

312 x = (float32_t) i;
10002a8a: vcvt.f32.s32 s12, s11
313 y = (float32_t) j;
10002a8e: vmov s15, r3
10002a92: vcvt.f32.s32 s13, s15
314 z = z / 1000 + x / 1000 + y / 1000;
10002a96: vldr s14, [pc, #356] ; 0x10002bfc <main+860>
10002a9a: vdiv.f32 s15, s16, s14
10002a9e: vdiv.f32 s16, s12, s14
10002aa2: vadd.f32 s15, s15, s16
10002aa6: vdiv.f32 s16, s13, s14
10002aaa: vadd.f32 s16, s15, s16

[2] Disabled FPU - "SOFT" mode

file makefile contains:

DEFINES=
VFP_SELECT=softfp
CFLAGS =-mfloat-abi=soft -mthumb

Disassembly:

312 x = (float32_t) i;
10002a80: vcvt.f32.s32 s12, s11
313 y = (float32_t) j;
10002a84: vmov s15, r3
10002a88: vcvt.f32.s32 s13, s15
314 z = z / 1000 + x / 1000 + y / 1000;
10002a8c: vldr s14, [pc, #356] ; 0x10002bf4 <main+852>
10002a90: vdiv.f32 s15, s16, s14
10002a94: vdiv.f32 s16, s12, s14
10002a98: vadd.f32 s15, s15, s16
10002a9c: vdiv.f32 s16, s13, s14
10002aa0: vadd.f32 s16, s15, s16

But I am getting same assembly code for HARD or SOFT mode. It look like that Modus Toolbox send some hidden params to compiler/make using FPU ?Am I able really to disable FPU unit ? Or maybe I am doing something in wrong way. Can someone help me ?

Best Regards

Radim

0 Likes
1 Solution
Ekta
Moderator
Moderator 250 solutions authored 100 likes received 250 sign-ins
Moderator

Hi Radim,

I checked internally and now I can confirm that setting the VPF_SELECT variable is sufficient to change assembly code to use Hardfp or Softfp. The CFLAGS will automatically get updated for them by the make build recipe. VFP_SELECT has three possible options: softfp hardfp softfloat. By default softfp is used. 

This instructs the toolchain to compile using floating point instructions, but will link assuming soft. This is a hybrid mode between softfloat and hardfp. The result is that if the floating point operations are all contained in a single file, like main.c it will have the same behavior whether the user used softfp or hardfp.

 

Please refer to the page below that contains more information regarding the Softfp:

https://embeddedartistry.com/blog/2017/10/11/demystifying-arm-floating-point-compiler-options/

I guess this is the reason we are observing the same assembly code in both cases.

Best Regards
Ekta

View solution in original post

0 Likes
3 Replies
Ekta
Moderator
Moderator 250 solutions authored 100 likes received 250 sign-ins
Moderator

Hi @ravo 

We tried enabling the hardfp at our end.

As per my understanding, the correct way to enable it is to set VFP_SELECT = hardfp and set the Complier flags as you have set and we have made a similar observation. The disassembly code for both softfp and hardfp are same.

We are checking internally to see if there is any other setting that is required.

Also, I found a link: how-to-enable-hardware-floating-point-math-for-cortex-m4-with-fpu-in-gcc
which mentions that the presence of functions like vldr, vmul, and vstr in the disassembly shows that hard FPU is being used in the code. But not sure why softfp code also has this.

I also wanted to ask you how are you seeing the disassembly code, are you using the disassembly window in modustoolbox for this?

Thank and Regrads
Ekta

 

0 Likes
ravo
Level 4
10 likes given 50 replies posted 10 questions asked
Level 4

Dear Ekta,

thanks for response. I'm wondering if you find anything, there may be some settings that are taken from the BSP config. I also suppose if we see vldr, vmul... instructions then FPU used. But why for soft as you note... I will wait for your investigation. To verify and check generated ASM code I use disassembly window in Modus Toolbox.

Regards

Radim

0 Likes
Ekta
Moderator
Moderator 250 solutions authored 100 likes received 250 sign-ins
Moderator

Hi Radim,

I checked internally and now I can confirm that setting the VPF_SELECT variable is sufficient to change assembly code to use Hardfp or Softfp. The CFLAGS will automatically get updated for them by the make build recipe. VFP_SELECT has three possible options: softfp hardfp softfloat. By default softfp is used. 

This instructs the toolchain to compile using floating point instructions, but will link assuming soft. This is a hybrid mode between softfloat and hardfp. The result is that if the floating point operations are all contained in a single file, like main.c it will have the same behavior whether the user used softfp or hardfp.

 

Please refer to the page below that contains more information regarding the Softfp:

https://embeddedartistry.com/blog/2017/10/11/demystifying-arm-floating-point-compiler-options/

I guess this is the reason we are observing the same assembly code in both cases.

Best Regards
Ekta

0 Likes