Skip to content

[Complexity] Optimize L_norm_arr()

Basic info

This is a subtask of #1009 (closed) - it splits off the complexity optimization of the function L_norm_arr(). This optimization is BE.

Bug description

Avoid IF()-operator in the FOR-loop; the IF() operator has a complexity count of 3; instead, if() can be used if it conditions only one basic operator (control operators excluded).

Word16 L_norm_arr( Word32 *arr, Word16 size )
{
    Word16 q = 31;
    move16();
    FOR( Word16 i = 0; i < size; i++ )
#ifndef PATCH
    IF( arr[i] != 0 )
    {
        q = s_min( q, norm_l( arr[i] ) );
    }
#else
    {
        Word16 q_tst;

        q_tst = norm_l( arr[i] );
        if ( arr[i] != 0 )
        {
            q = s_min( q, q_tst );
        }
    }

#endif
    return q;
}

This saves 2-3 cycles per iteration at minimum cost (one additional 16 bit word on stack).

Ways to reproduce

See #1009 (closed) for commandline.