Skip to content

Commit

Permalink
fixed overflow check on qfp
Browse files Browse the repository at this point in the history
  • Loading branch information
camilo committed Dec 22, 2023
1 parent c34b907 commit 9a817d8
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions qfp16.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ static qFP16_Settings_t *fp = &fp_default;

/*! @endcond */

static uint32_t qFP16_OverflowCheck( uint32_t res,
const uint32_t x,
const uint32_t y );
static qFP16_t qFP16_rs( const qFP16_t x );
static qFP16_t qFP16_log2i( qFP16_t x );
static char *qFP16_itoa( char *buf,
Expand Down Expand Up @@ -226,7 +223,9 @@ qFP16_t qFP16_Add( const qFP16_t X,
uint32_t retValue;

retValue = x + y;
retValue = qFP16_OverflowCheck( retValue, x, y );
if ( ( 0u == ( ( x ^ y ) & intern.overflow_mask ) ) && ( 0u != ( ( x ^ retValue ) & intern.overflow_mask ) ) ) {
retValue = (uint32_t)qFP16.overflow;
}

return qFP16_Saturate( (qFP16_t)retValue, X, X );
}
Expand All @@ -238,7 +237,9 @@ qFP16_t qFP16_Sub( const qFP16_t X,
uint32_t retValue;

retValue = x - y;
retValue = qFP16_OverflowCheck( retValue, x, y );
if ( ( 0u != ( ( x ^ y ) & intern.overflow_mask ) ) && ( 0u != ( ( x ^ retValue ) & intern.overflow_mask ) ) ) {
retValue = (uint32_t)qFP16.overflow;
}

return qFP16_Saturate( (qFP16_t)retValue, X, X );
}
Expand Down Expand Up @@ -913,18 +914,6 @@ qFP16_t qFP16_AToFP( const char *s )
return retValue;
}
/*============================================================================*/
static uint32_t qFP16_OverflowCheck( uint32_t res,
const uint32_t x,
const uint32_t y )
{
if ( ( 0u == ( ( x ^ y ) & intern.overflow_mask ) ) &&
( 0u != ( ( x ^ res ) & intern.overflow_mask ) ) ) {
res = (uint32_t)qFP16.overflow;
}

return res;
}
/*============================================================================*/
static qFP16_t qFP16_rs( const qFP16_t x )
{
qFP16_t retValue;
Expand Down

0 comments on commit 9a817d8

Please sign in to comment.