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.

DSP library function - DSP_maxidx()

Other Parts Discussed in Thread: TMS320C6455

To find the max index of an array fast I have been using the below function from the DSP library. 

int DSP_maxidx(const short *x, int nx)

However, recently I discovered some odd results from it. For example, if my array has 128 elements and the max value is placed between index 16 and 31 the output is wrong. Placing the max value at index 16 gives a result of 112. The results are the same for larger arrays as well, but I seem to get correct result if the array is smaller, e.g. 64 elements. See the below test code for details. Am I using the function incorrect? The C64xDSPLIB version is 1.04b, but I cannot find any newer versions.

extern "C"
{
  int DSP_maxidx(const short *x, int nx);
}
static const int SIZE = 128;

#pragma DATA_ALIGN(8)
const short values[SIZE] = 
{
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   9, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
};

Int main(Void)
{
   int maxIdx = DSP_maxidx(values, SIZE);
   printf("Max=%d\n", maxIdx);

   return 0;
}
  • Hi nemis

    I got the same error it looks like as if it was using a signed 8 bit value, so we would go from -128 to 127. But the function uses an int parameter, so we shouldn't have this problem.

    Looking at the dsplib documentation SPRUEB8B http://www.ti.com/lit/ug/sprueb8b/sprueb8b.pdf page 4-61 I found the code that defines the maxidx function:

    int DSP_maxidx(const short *x, int nx)
    {
    	int max, index, i;
    	max = 0-32768;
    	for (i = 0; i < nx; i++)
    		if (x[i] > max) {
    			max = x[i];
    			index = i;
    		}
    	return index;
    }
      

    So I added this function definition to the code and commented ou the:

    extern"C"{int DSP_maxidx(const short *x, short nx);}

    With the new code it worked alright.

    Maybe there's some problem with the compiler when it does the extern part.

    Regards

     
  • joh 123456 said:

    Hi nemis

    I got the same error it looks like as if it was using a signed 8 bit value, so we would go from -128 to 127. But the function uses an int parameter, so we shouldn't have this problem.

    Looking at the dsplib documentation SPRUEB8B http://www.ti.com/lit/ug/sprueb8b/sprueb8b.pdf page 4-61 I found the code that defines the maxidx function:

    int DSP_maxidx(const short *x, int nx)
    {
        int max, index, i;
        max = 0-32768;
        for (i = 0; i < nx; i++)
            if (x[i] > max) {
                max = x[i];
                index = i;
            }
        return index;
    }
       

    So I added this function definition to the code and commented ou the:

    extern"C"{int DSP_maxidx(const short *x, short nx);}

    With the new code it worked alright.

    Maybe there's some problem with the compiler when it does the extern part.

    Regards

    Maybe, but I'm using the latest code generation tools.

    It seems like the DSPLIB version is from 2003, hence pretty old. I would expect new bug fixes from time to time. Could there be a bug in the assembly for the function?

  • Could you specify, what device you are using. I just want to make sure you are using the correct version of the library.

    Regards,

    Rahul

  • You are using a very old version of the DSPLIB that is meant for legacy C64x DSP devices(C641x and C642x). Please use the C64xplus DSPLIB, from the following link

    http://software-dl.ti.com/sdoemb/sdoemb_public_sw/dsplib/latest/index_FDS.html

    This is the correct version of the library that is meant for your device.

    Regards,

    Rahul 

  • Thanks! The new DSBLIB version solved the issue.