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.

dot product using LDW

Hello all

I'm about to write a code of floating point dot-product using software pipelining for TMS320C6713 by using  LDW . I encountered  a problem in the accumulation of the multiplication result ( I think it's loop carry path problem because the addsp require 4 cycles to complete ) . How can I solve this issue  . I blevie that LDDW will be more effecitiant . I try it ...but how can i deal with odd number of multiplication( if count is an odd number ) ...one solution is done by add a zero coef at the end of the coefficient array but if i don't know the value of count if it even or  odd 

here the C code

float dot-product(float *in, float *coef, int count)
{
    int i;
    float sum = 0;
 
    for (i=0; i < count; i++)
    {
        sum = sum + in[i] * coef[i];
    }

    return(sum);
}

thank you ^_^

  • Hi,

    You can loop for (count & ~1) and then check if a trailing operation is required.

    float dot_product(float *in, const float * const coef, int count)
    {
        int i;
        float sum = 0;

        int c=count & ~1;
        _nassert(c % 2 == 0);  //unroll by 2. Compiler generates LDDW
        _nassert((int)in % 8 == 0);  //generate aligned access (LDDW instead of LDNDW)
        _nassert((int)coef % 8 == 0);
        for (i=0; i < c; i++)
        {
            sum = sum + in[i] * coef[i];
        }
        if (count & 1)
          sum+=in[count-1]*coef[count-1];
        return(sum);
    }

    You can try also with (count % 4 == 0) (unroll by 4), but of course you have to adjust the loop limits ant the trailing operations.



    .