FPU Question

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

FPU Question

Post by Tabulous »

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: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: FPU Question

Post by Tabulous »

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: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: FPU Question

Post by Giovanni »

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: 403
Joined: Sun Jun 12, 2016 4:10 am
Has thanked: 188 times
Been thanked: 134 times

Re: FPU Question

Post by FXCoder »

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