Commit 53a1ac93 authored by Satish Patil's avatar Satish Patil
Browse files

Update BASOP_Util_Divide3232_Scale_cadence() with additional parameter - bits

parent 7b212b76
Loading
Loading
Loading
Loading
+104 −0
Original line number Diff line number Diff line
@@ -958,6 +958,55 @@ Word16 BASOP_Util_Divide3232_uu_1616_Scale( Word32 x, Word32 y, Word16 *s )
    return ( z );
}

#ifdef DIV32_OPT
Word32 div_w( Word32 L_num, Word32 L_den, Word16 bits )
{
    Word32 L_var_out = 0;
    Word16 iteration;
    move32();


    IF( L_den == 0 )
    {
        /* printf("Division by 0 in div_l, Fatal error in "); printStack(); */
        return ( 0 );
    }

    test();
    IF( ( L_num < 0 ) || ( L_den < 0 ) )
    {
        /* printf("Division Error in div_l, Fatal error in "); printStack(); */
        return ( 0 );
    }
    Word64 W_num, W_den;
    W_num = W_deposit32_l( L_num );
    W_den = W_deposit32_l( L_den );

    IF( GT_64( W_num, W_den ) )
    {
        return MAX_32;
    }
    ELSE
    {
        W_num = W_shr( W_num, 1 );
        W_den = W_shr( W_den, 1 );

        FOR( iteration = 0; iteration < bits; iteration++ )
        {
            L_var_out = L_shl( L_var_out, 1 );
            W_num = W_shl( W_num, 1 );

            IF( GT_64( W_num, W_den ) )
            {
                W_num = W_sub( W_num, W_den );
                L_var_out = L_add( L_var_out, 1 );
            }
        }

        return L_shl(L_var_out, 31-bits);
    }
}
#else /*  DIV32_OPT */
Word32 div_w( Word32 L_num, Word32 L_den )
{
    Word32 L_var_out = 0;
@@ -1005,7 +1054,9 @@ Word32 div_w( Word32 L_num, Word32 L_den )
        return L_var_out;
    }
}
#endif /*  DIV32_OPT */

#ifndef DIV32_OPT
Word32 BASOP_Util_Divide3232_Scale_cadence( Word32 x, Word32 y, Word16 *s )
{
    Word32 z;
@@ -1057,6 +1108,59 @@ Word32 BASOP_Util_Divide3232_Scale_cadence( Word32 x, Word32 y, Word16 *s )

    return z;
}
#else /*  DIV32_OPT */
Word32 BASOP_Util_Divide3232_Scale_cadence( Word32 x, Word32 y, Word16 *s, Word16 bits )
{
    Word32 z;
    Word16 sx;
    Word16 sy;
    Word32 sign;

    /* assert (x >= (Word32)0); */
    assert( y != (Word32) 0 );

    sign = 0;
    move16();

    IF( x < 0 )
    {
        x = L_negate( x );
        sign = L_xor( sign, 1 );
    }

    IF( y < 0 )
    {
        y = L_negate( y );
        sign = L_xor( sign, 1 );
    }

    IF( x == (Word32) 0 )
    {
        *s = 0;
        return ( (Word32) 0 );
    }

    sx = norm_l( x );
    x = L_shl( x, sx );
    x = L_shr( x, 1 );
    move16();
    *s = sub( 1, sx );

    sy = norm_l( y );
    y = L_shl( y, sy );
    move16();
    *s = add( *s, sy );

    z = div_w( x, y);

    if ( sign != 0 )
    {
        z = L_negate( z );
    }

    return z;
}
#endif /*  DIV32_OPT */

Word16 BASOP_Util_Divide3232_Scale( Word32 x, Word32 y, Word16 *s )
{
+7 −0
Original line number Diff line number Diff line
@@ -328,9 +328,16 @@ Word16 BASOP_Util_Divide3232_Scale( Word32 x, /*!< i : Numerator*/
                                    Word32 y,    /*!< i  : Denominator*/
                                    Word16 *s ); /*!< o  : Additional scalefactor difference*/

#ifdef DIV32_OPT
Word32 BASOP_Util_Divide3232_Scale_cadence( Word32 x,      /*!< i  : Numerator*/
                                            Word32 y,      /*!< i  : Denominator*/
                                            Word16 *s,     /*!< o  : Additional scalefactor difference*/
                                            Word16 bits ); /*!< o  : Additional scalefactor difference*/
#else /*  DIV32_OPT */
Word32 BASOP_Util_Divide3232_Scale_cadence( Word32 x,    /*!< i  : Numerator*/
                                            Word32 y,    /*!< i  : Denominator*/
                                            Word16 *s ); /*!< o  : Additional scalefactor difference*/
#endif /*  DIV32_OPT */


/************************************************************************/