+ Reply to Thread
Results 1 to 10 of 10

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

  1. #1
    Intermediate Intermediate
    Join Date
    Jun 2013
    Location
    UK
    Posts
    201
    Points
    730

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

    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

  2. #2

    Infineon Employee
    Infineon Employee
    Expert

    Join Date
    Nov 2011
    Posts
    325
    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
    Click image for larger version

Name:	CompilerSetting_FPU.jpg
Views:	30
Size:	151.6 KB
ID:	221
    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)
    Click image for larger version

Name:	LinkerSetting_FPU.jpg
Views:	34
Size:	157.1 KB
ID:	222
    3) Add "#include <arm_math.h>"
    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/thread...highlight=sqrt)

    Best regards,
    Sophia
    The views expressed here are my personal opinions, have not been reviewed or authorized by Infineon and do not necessarily represent the views of Infineon.

  3. #3
    Intermediate Intermediate
    Join Date
    Jun 2013
    Location
    UK
    Posts
    201
    Points
    730
    Hi Sophia,

    Fantastic, very very helpful. Thank you.

    Best regards
    Aaron

  4. #4
    Intermediate Intermediate
    Join Date
    Jun 2013
    Location
    UK
    Posts
    201
    Points
    730
    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



  5. #5

    Infineon Employee
    Infineon Employee
    Expert

    Join Date
    Nov 2011
    Posts
    325
    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
    The views expressed here are my personal opinions, have not been reviewed or authorized by Infineon and do not necessarily represent the views of Infineon.

  6. #6

    Infineon Employee
    Infineon Employee
    Expert

    Join Date
    Nov 2011
    Posts
    325
    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)
    Click image for larger version

Name:	LinkerSetting.jpg
Views:	23
Size:	162.1 KB
ID:	224
    2) Add "#include <math.h>"
    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
    The views expressed here are my personal opinions, have not been reviewed or authorized by Infineon and do not necessarily represent the views of Infineon.

  7. #7
    New Member New Member
    Join Date
    Dec 2012
    Posts
    5
    Points
    37.5
    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

  8. #8
    Intermediate Intermediate
    Join Date
    Jun 2013
    Location
    UK
    Posts
    201
    Points
    730
    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 <math.h>"
    3) Use function "float powf(float x, float y)"

  9. #9
    Beginner Beginner Dmitry Podobedov's Avatar
    Join Date
    Mar 2013
    Location
    Konstanz, Germany
    Posts
    57
    Points
    480
    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!
    Last edited by Dmitry Podobedov; Jul 8th, 2013 at 05:38 AM.

  10. #10
    Intermediate Intermediate
    Join Date
    Jun 2013
    Location
    UK
    Posts
    201
    Points
    730
    Hi Dmitry, thankyou for the very interesting information. It will help me choose the right functions for fastest program execution.

    Best regards
    Aaron

+ Reply to Thread

Bookmarks

Disclaimer

All content and materials on this site are provided “as is“. Infineon makes no warranties or representations with regard to this content and these materials of any kind, whether express or implied, including without limitation, warranties or representations of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. No license, whether express or implied, is granted by Infineon. Use of the information on this site may require a license from a third party, or a license from Infineon.


Infineon accepts no liability for the content and materials on this site being accurate, complete or up- to-date or for the contents of external links. Infineon distances itself expressly from the contents of the linked pages, over the structure of which Infineon has no control.


Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Usage Terms of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Usage Terms of this site. Infineon reserves the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.