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; }