Skip to content

[Complexity] Optimize get_min_scalefactor()

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()-operators. 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 get_min_scalefactor( Word32 x, Word32 y )
{
#ifndef PATCH
    Word16 scf = Q31;
    move16();
    test();
    IF( x == 0 && y == 0 )
    {
        return 0;
    }
    IF( x != 0 )
    {
        scf = s_min( scf, norm_l( x ) );
    }
    IF( y != 0 )
    {
        scf = s_min( scf, norm_l( y ) );
    }
    return scf;
#else
    Word16 scf_y;
    Word16 scf = Q31;
    move16();

    test();
    if ( x == 0 && y == 0 )
    {
        scf = 0;
        move16();
    }

    if ( x != 0 )
    {
        scf = norm_l( x );
    }

    scf_y = norm_l( y );
    if ( y != 0 )
    {
        scf = s_min( scf_y, scf );
    }

    return scf;
#endif
}

The propsed patch saves 7-8 cycles per function call.

Ways to reproduce

See #1009 (closed) for commandline.