Hi All,

I am having trouble getting good performance from the maths library (libm.a). I wrote a quick (simple) benchmark program that does some simple floating point math, including an atan function, it is included below.

To measure the time taken, a scope is attached to the LED line on P1OUT/BIT4.

With the IAR compiler at fastest optimization, the loop executes at 35 times per second (35 hz). However msp430-gcc with -O2 optimization can only do 7Hz (Hardware is a x149 with a 7.3Mhz clock). This is a big difference.....

What is the state of the maths library, is it optimized?
In normal integer maths, operation etc, gcc seems to be as good as, if not faster than IAR.

Can someone verify my measurements, or comment on libm.a

Many Thanks,
Bernie Mentink

----------------------------------- Code follows ---------------------------


#include <msp430x14x.h>

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define LEDON() (P1OUT |= BIT4)
#define LEDOFF() (P1OUT &= ~BIT4)

void Start_HFXtal(void)
{
    IFG1=0;                 /* attach HF crystal  to XT2IN/OUT */
    BCSCTL1 &= ~0x80;
    do                     /* wait in loop until crystal is stable */
    {
        IFG1 &= ~0x02;
    }while(0x02 & IFG1);
    BCSCTL2 = 0x88;        /* set mclk & smclk = XT2 xtal  */
}

void bench_mark_delay(void)
{
        #define times 20

        static float a,b,c;
        double y = 0.1234;
        double x;
        int d;

        a=12345.123;
        b=54321.123;

for(d=0;d<times;d++)
        {
                a=a+1.03;
                b=b+2.032;
                c=a/b;
                x = asin(y);
        }
}

/* Main program beings here */
/* This  program blinks LED */
void main (void)
{       
WDTCTL = 0x5a80; // enable watchdog for 42ms timeout (770Khz clk) and clear it.
        Start_HFXtal();
        P1DIR = BIT4;
        while(1)                //  while loop
        {
                LEDOFF();
                bench_mark_delay();
                LEDON();
                bench_mark_delay();
        }
}

Reply via email to