How do I use the FPU for fast maths functions on the xmc4500. e.g. sqrt, pow, etc

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

cross mob
Not applicable
I need to perform maths functions like sqrt, pow, etc as fast as possible on the xmc4500.

Do I need to use an App to enable and utilise the Floating Point Unit (FPU) ?

Do I need to include an FPU specific maths library ?

Any help and advise would be greatly appreciated.

Aaron
0 Likes
10 Replies
Not applicable
Hi Aaron,

The pow function is available in CMSIS. The math library is under C:\DAVE-3.1\CMSIS\Lib\GCC.
What you need to do is:
1) Go to Project -> Active Project Properties -> C/C++ Build -> Settings -> ARM-GCC C Compiler, add "__FPU_PRESENT" & "ARM_MATH_CM4" in the Preprocessor
198.attach
2) Go to Project -> Active Project Properties -> C/C++ Build -> Settings -> ARM-GCC C Linker, add "arm_cortexM4_mathL_1" & "arm_cortexM4_mathL_2" in the Libraries (-l) and ""${eclipse_home}/.../CMSIS/Lib/GCC"" in the Libraries search path (-L)
199.attach
3) Add "#include "
4) Use function "arm_power_f32(float32_t * pSrc, uint32_t blockSize, float32_t * pResult)"

As for the sqrt function, you can refer to previous "May 16th" post (http://www.infineonforums.com/threads/639-Does-XMC4500-support-the-sqrt-function-please?highlight=sq...)

Best regards,
Sophia
0 Likes
Not applicable
Hi Sophia,

Fantastic, very very helpful. Thank you.

Best regards
Aaron
0 Likes
Not applicable
Hi Sophia,

I made all the changes to my project. Unfortunately I get the following build errors...

c:/dave-3.1/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/bin/ld.exe: cannot find -larm_cortexM4_mathL_1
c:/dave-3.1/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/bin/ld.exe: cannot find -larm_cortexM4_mathL_1

I found similar files on my PC...

C:\DAVE-3.1\CMSIS\Lib\GCC\libarm_cortexM4_mathL_1.a
C:\DAVE-3.1\CMSIS\Lib\GCC\libarm_cortexM4_mathL_2.a

I changed the Libraries (-l) to "libarm_cortexM4_mathL_1" & "libarm_cortexM4_mathL_2" but this did not help.
I changed the Libraries (-l) to "libarm_cortexM4_mathL_1.a" & "libarm_cortexM4_mathL_2.a" but this did not help.

Any ideas ?

Thank you very much
Aaron



0 Likes
Not applicable
Hi Aaron,

You didn't set the Libraries search path (-L).
There are two settings in step 2:
2a) Add libraries (-l) "arm_cortexM4_mathL_1" & "arm_cortexM4_mathL_2"
2b) Add Libraries search path (-L) ""${eclipse_home}/.../CMSIS/Lib/GCC""

Pls follow the exact settings shown in LinkerSetting_FPU.jpg (Jul 5th post) , thanks.

Best regards,
Sophia
0 Likes
Not applicable
Hi Aaron,

There is another simple way to do "pow" function which is to use newlib library. What you need to do is:
1) Go to Project -> Active Project Properties -> C/C++ Build -> Settings -> ARM-GCC C Linker, add "m" in the Libraries (-l)
200.attach
2) Add "#include "
3) Use function "float powf(float x, float y)"

The steps 1 & 2 are applicable for other math functions provided by newlib library (http://sourceware.org/newlib/libm.html).

Best regards,
Sophia
0 Likes
Not applicable
The libraries search path is incorrect. It should be set to : ""C:\DAVE-3.1\CMSIS\Lib\GCC"". The libraries are not located in the eclipse_home directory (C:\DAVE-3.1\eclipse\CMSIS\Lib\GCC) but in. C:\DAVE-3.1\CMSIS\Lib\GCC
0 Likes
Not applicable
Thank you Sophia and Jochem.

I have implemented Sophia's suggestion (see below) and this is now working.

Best regards
Aaron

1) Go to Project -> Active Project Properties -> C/C++ Build -> Settings -> ARM-GCC C Linker, add "m" in the Libraries (-l)

2) Add "#include "
3) Use function "float powf(float x, float y)"
0 Likes
User6412
Level 4
Level 4
I have just measured the performance of fpu calculations (uc tackt clock 120 MHz).
This is not very accurate, but close.

Approximately the number of uc tackts for functions/operations:

Operation/Function Tackts
sqrtf 21
sqrt 1000
float++ 1
float * float 1
float / float 13
sinf 1300
sin 2300

sqrt is about 50 times slower as sqrtf! I think the sqrtf uses fpu implementation but the sqrt not. Means the float is fpu optimized, but double is not optimized!
0 Likes
Not applicable
Hi Dmitry, thankyou for the very interesting information. It will help me choose the right functions for fastest program execution.

Best regards
Aaron
0 Likes
Not applicable
sophia wrote:
Hi Aaron,

You didn't set the Libraries search path (-L).
There are two settings in step 2:
2a) Add libraries (-l) "arm_cortexM4_mathL_1" & "arm_cortexM4_mathL_2"
2b) Add Libraries search path (-L) ""${eclipse_home}/.../CMSIS/Lib/GCC""

Pls follow the exact settings shown in LinkerSetting_FPU.jpg (Jul 5th post) , thanks.

Best regards,
Sophia


A similar question, where to find these binary libraries for DAVE4?
0 Likes