Commit 4159703f authored by patilsatish's avatar patilsatish
Browse files

Update Cadence and FhG division kernel variants to cover corner cases

parent 7f2e39d6
Loading
Loading
Loading
Loading
Loading
+23 −4
Original line number Diff line number Diff line
@@ -979,8 +979,8 @@ Word32 div_w( Word32 L_num, Word32 L_den, Word16 bits )
        return ( 0 );
    }
    Word64 W_num, W_den;
    W_num = W_deposit32_l( L_num );
    W_den = W_deposit32_l( L_den );
    W_num = W_deposit32_h( L_num );
    W_den = W_deposit32_h( L_den );

    IF( GE_64( W_num, W_den ) )
    {
@@ -1409,13 +1409,27 @@ Word32 BASOP_Util_Divide3232_Scale_FhG( Word32 x, Word32 y, Word16 *s )
        return ( (Word32) 0 );
    }

#if 0
    sign = L_xor( x, y ); /* check (sign < 0) for result negation */

    if ( x < 0 )
    {
        x = L_negate( x );
    }
#else
    IF( EQ_32( y, 0x80000000 ) )
    {
        /* Division by -1.0: same as negation of numerator */
        /* Return normalized negated numerator */
        sx = norm_l( x );
        x = L_shl( x, sx );
        *s = negate(sx);
        return L_negate( x );

    }
    sign = y;
    move32();
#endif
    if ( y < 0 )
    {
        y = L_negate( y );
@@ -1473,7 +1487,12 @@ Word32 BASOP_Util_Divide3232_Scale_cadence( Word32 x, Word32 y, Word16 *s )

    sign = 0;
    move16();

    Word16 exp_offset = 1;
    IF (EQ_32(x, 0x80000000))  /* Handle corner case to avoid data loss */
    {
        x = L_shr( x, 1 );
        exp_offset += 1;
    }
    IF( x < 0 )
    {
        x = L_negate( x );
@@ -1496,7 +1515,7 @@ Word32 BASOP_Util_Divide3232_Scale_cadence( Word32 x, Word32 y, Word16 *s )
    x = L_shl( x, sx );
    x = L_shr( x, 1 );
    move16();
    *s = sub( 1, sx );
    *s = sub( exp_offset, sx );

    sy = norm_l( y );
    y = L_shl( y, sy );