This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Execution times: sqrt() and other library functions

Other Parts Discussed in Thread: MSPWARE

Using CCS, I am interested in finding out the general execution times (in mcu cycles) for the standard sqrt() math library function, and other library functions that can be used to derive a custom sqrt function.

 

What is the general execution time of sqrt() from <math> library?

Also, what are the general execution times of the below msp430 library functions (referenced by assembler)?

I_LSL    (shift left)
__fs_div (float divide)
__fs_mpy (float multiply)
__fs_add (float add)

  • Hi Leighton,

    The compiler libraries do not include benchmarks for any of the RTS math functions but it's easy to benchmark them using a timer. The code below gives a short example of how you can benchmark both the "math.h" and hidden math functions for the EABI functions.

    #include <msp430.h> 
    
    #include <stdint.h>
    #include <math.h>
    
    #define startBench()    TA0CTL = TACLR;TA0CTL = TASSEL_2 + MC_2
    #define stopBench()     TA0CTL = MC_0
    #define getBench()      TA0R
    
    volatile uint16_t cycles;
    
    extern float __mspabi_divf(float, float);
    
    int main(void)
    {
        uint16_t delay;
        float res;
    
        WDTCTL = WDTPW | WDTHOLD;    // Stop watchdog timer
    
        /* Calculate delay of starting and stopping the counter. */
        startBench();
        stopBench();
        delay = getBench();
    
        /* Example benchmark of CCS math function */
        startBench();
        res = sqrtf(1.0);
        stopBench();
        cycles = getBench() - delay;
    
        /* Example benchmark of CCS RTS function */
        startBench();
        res = __mspabi_divf(1.0, 2.0);
        stopBench();
        cycles = getBench() - delay;
    
        return 0;
    }
    

    If you are interested in improved math performance on MSP430 I suggest checking out the IQmathLib which provides optimized fixed point math functions. For more information you can check out the IQmathLib page or download MSPware.

    Regards,

    Brent Peterson

**Attention** This is a public forum