FPU Question

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

FPU Question

Postby Tabulous » Mon Aug 06, 2018 9:10 am

Using STM32F411, with RT 3.1.5

I'm doing alot of maths based calculations, ie using sin,cos and atan2

Some for these are in loops i.e.

Code: Select all

    for( i=0; i<360; i++ )
    {
        // calculate pitch
        z2 = ( -x * sin( rads(i) )) + ( z * cos( rads(i) ));

        for( j=0; j<360; j++ )
        {
            // calculate roll
            z3 = ( y * sin( rads(j) )) + ( z2 * cos( rads( j ) ));

            ori.sortField = ( z3 + ( i * 0.0056f ));

            if( ori.sortField > ori.finalSortField )
            {
                ori.p1 = i;
                ori.r1 = j;

                ori.finalSortField = ori.sortField;
            }
        }
    }


When the FPU = no in makefile the processing time for thing is quite long, i.e. 9 seconds or so.
If i enable FPU = hard, this makes no difference to the length of time........

Is there other things i need to look at ? All my data types in the code are floats, but the math.h lib are in doubles. Ive read that doubles are still handle in software, thus this would explain why......

So is there away to force to use floats for doubles and thus allow the FPU to process everything ? PS other option might be to use sinf, cosf and atan2f....

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: FPU Question

Postby Tabulous » Mon Aug 06, 2018 9:48 am

Answered my own question:- using floating point versions of the maths functions and then switching on FPU, processing now at 500mS :-)

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: FPU Question

Postby Giovanni » Mon Aug 06, 2018 9:50 am

Hi,

The Cortex-M4 only support floats in FPU, double types are handled in SW. If you need double precision then you should look at the M7 (note not all M7 devices support double, you need to verify the RM).

In brief:
M0, M3: no FPU.
M4: single FPU or none.
M7: single FPU or double FPU.

Giovanni

User avatar
FXCoder
Posts: 384
Joined: Sun Jun 12, 2016 4:10 am
Location: Sydney, Australia
Has thanked: 180 times
Been thanked: 130 times

Re: FPU Question

Postby FXCoder » Mon Aug 06, 2018 2:24 pm

Depending on the precision required you might also find the fast math and other functions in the CMSIS DSP library useful to look into.


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 10 guests