[Complexity] Optimize minimum_s()
Basic info
This is a subtask of #1009 (closed) - it splits off the complexity optimization of the function minimum_s(). This optimization is BE.
Bug description
The proposed patch removes the IF()
condition in the FOR
-loop and replaces it by an if()
. The minimum value is not stored, just the array index, which allows for this optimization.
Word16 minimum_s(
const Word16 *vec, /* i : Input vector */
const Word16 lvec, /* i : Vector length */
Word16 *min_val /* o : minimum value in the input vector */
)
{
#ifdef PATCH
Word16 i, ind;
#else
Word16 i, ind, tmp;
#endif
ind = 0;
move16();
#ifndef PATCH
tmp = vec[0];
move16();
#endif
FOR( i = 1; i < lvec; i++ )
{
#ifdef PATCH
if ( LT_16( vec[i], vec[ind] ) )
{
ind = add( i, 0 );
}
#else
IF( LT_16( vec[i], tmp ) )
{
ind = i;
move16();
tmp = vec[i];
move16();
}
#endif
}
if ( min_val != NULL )
{
#ifdef PATCH
*min_val = vec[ind];
#else
*min_val = tmp;
#endif
move16();
}
return ind;
}
The proposed patch saves 4 cycles per FOR
iteration.
Ways to reproduce
(Clear steps or refer to a failing automated test, e.g. with a pipeline link)
Edited by multrus