diff options
Diffstat (limited to 'fpu/softfloat-specialize.h')
-rw-r--r-- | fpu/softfloat-specialize.h | 95 |
1 files changed, 60 insertions, 35 deletions
diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h index 8f9dd5c45..18c6dd52d 100644 --- a/fpu/softfloat-specialize.h +++ b/fpu/softfloat-specialize.h @@ -66,9 +66,9 @@ typedef struct { | The pattern for a default generated single-precision NaN. *----------------------------------------------------------------------------*/ #if SNAN_BIT_IS_ONE -#define float32_default_nan 0x7FBFFFFF +#define float32_default_nan make_float32(0x7FBFFFFF) #else -#define float32_default_nan 0xFFC00000 +#define float32_default_nan make_float32(0xFFC00000) #endif /*---------------------------------------------------------------------------- @@ -76,8 +76,9 @@ typedef struct { | NaN; otherwise returns 0. *----------------------------------------------------------------------------*/ -int float32_is_nan( float32 a ) +int float32_is_nan( float32 a_ ) { + uint32_t a = float32_val(a_); #if SNAN_BIT_IS_ONE return ( ( ( a>>22 ) & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF ); #else @@ -90,8 +91,9 @@ int float32_is_nan( float32 a ) | NaN; otherwise returns 0. *----------------------------------------------------------------------------*/ -int float32_is_signaling_nan( float32 a ) +int float32_is_signaling_nan( float32 a_ ) { + uint32_t a = float32_val(a_); #if SNAN_BIT_IS_ONE return ( 0xFF800000 <= (bits32) ( a<<1 ) ); #else @@ -110,9 +112,9 @@ static commonNaNT float32ToCommonNaN( float32 a STATUS_PARAM ) commonNaNT z; if ( float32_is_signaling_nan( a ) ) float_raise( float_flag_invalid STATUS_VAR ); - z.sign = a>>31; + z.sign = float32_val(a)>>31; z.low = 0; - z.high = ( (bits64) a )<<41; + z.high = ( (bits64) float32_val(a) )<<41; return z; } @@ -123,7 +125,8 @@ static commonNaNT float32ToCommonNaN( float32 a STATUS_PARAM ) static float32 commonNaNToFloat32( commonNaNT a ) { - return ( ( (bits32) a.sign )<<31 ) | 0x7FC00000 | ( a.high>>41 ); + return make_float32( + ( ( (bits32) a.sign )<<31 ) | 0x7FC00000 | ( a.high>>41 ) ); } /*---------------------------------------------------------------------------- @@ -135,42 +138,52 @@ static float32 commonNaNToFloat32( commonNaNT a ) static float32 propagateFloat32NaN( float32 a, float32 b STATUS_PARAM) { flag aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN; + bits32 av, bv, res; aIsNaN = float32_is_nan( a ); aIsSignalingNaN = float32_is_signaling_nan( a ); bIsNaN = float32_is_nan( b ); bIsSignalingNaN = float32_is_signaling_nan( b ); + av = float32_val(a); + bv = float32_val(b); #if SNAN_BIT_IS_ONE - a &= ~0x00400000; - b &= ~0x00400000; + av &= ~0x00400000; + bv &= ~0x00400000; #else - a |= 0x00400000; - b |= 0x00400000; + av |= 0x00400000; + bv |= 0x00400000; #endif if ( aIsSignalingNaN | bIsSignalingNaN ) float_raise( float_flag_invalid STATUS_VAR); if ( aIsSignalingNaN ) { if ( bIsSignalingNaN ) goto returnLargerSignificand; - return bIsNaN ? b : a; + res = bIsNaN ? bv : av; } else if ( aIsNaN ) { - if ( bIsSignalingNaN | ! bIsNaN ) return a; + if ( bIsSignalingNaN | ! bIsNaN ) + res = av; + else { returnLargerSignificand: - if ( (bits32) ( a<<1 ) < (bits32) ( b<<1 ) ) return b; - if ( (bits32) ( b<<1 ) < (bits32) ( a<<1 ) ) return a; - return ( a < b ) ? a : b; + if ( (bits32) ( av<<1 ) < (bits32) ( bv<<1 ) ) + res = bv; + else if ( (bits32) ( bv<<1 ) < (bits32) ( av<<1 ) ) + res = av; + else + res = ( av < bv ) ? av : bv; + } } else { - return b; + res = bv; } + return make_float32(res); } /*---------------------------------------------------------------------------- | The pattern for a default generated double-precision NaN. *----------------------------------------------------------------------------*/ #if SNAN_BIT_IS_ONE -#define float64_default_nan LIT64( 0x7FF7FFFFFFFFFFFF ) +#define float64_default_nan make_float64(LIT64( 0x7FF7FFFFFFFFFFFF )) #else -#define float64_default_nan LIT64( 0xFFF8000000000000 ) +#define float64_default_nan make_float64(LIT64( 0xFFF8000000000000 )) #endif /*---------------------------------------------------------------------------- @@ -178,8 +191,9 @@ static float32 propagateFloat32NaN( float32 a, float32 b STATUS_PARAM) | NaN; otherwise returns 0. *----------------------------------------------------------------------------*/ -int float64_is_nan( float64 a ) +int float64_is_nan( float64 a_ ) { + bits64 a = float64_val(a_); #if SNAN_BIT_IS_ONE return ( ( ( a>>51 ) & 0xFFF ) == 0xFFE ) @@ -194,8 +208,9 @@ int float64_is_nan( float64 a ) | NaN; otherwise returns 0. *----------------------------------------------------------------------------*/ -int float64_is_signaling_nan( float64 a ) +int float64_is_signaling_nan( float64 a_ ) { + bits64 a = float64_val(a_); #if SNAN_BIT_IS_ONE return ( LIT64( 0xFFF0000000000000 ) <= (bits64) ( a<<1 ) ); #else @@ -216,9 +231,9 @@ static commonNaNT float64ToCommonNaN( float64 a STATUS_PARAM) commonNaNT z; if ( float64_is_signaling_nan( a ) ) float_raise( float_flag_invalid STATUS_VAR); - z.sign = a>>63; + z.sign = float64_val(a)>>63; z.low = 0; - z.high = a<<12; + z.high = float64_val(a)<<12; return z; } @@ -229,10 +244,10 @@ static commonNaNT float64ToCommonNaN( float64 a STATUS_PARAM) static float64 commonNaNToFloat64( commonNaNT a ) { - return + return make_float64( ( ( (bits64) a.sign )<<63 ) | LIT64( 0x7FF8000000000000 ) - | ( a.high>>12 ); + | ( a.high>>12 )); } /*---------------------------------------------------------------------------- @@ -244,33 +259,43 @@ static float64 commonNaNToFloat64( commonNaNT a ) static float64 propagateFloat64NaN( float64 a, float64 b STATUS_PARAM) { flag aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN; + bits64 av, bv, res; aIsNaN = float64_is_nan( a ); aIsSignalingNaN = float64_is_signaling_nan( a ); bIsNaN = float64_is_nan( b ); bIsSignalingNaN = float64_is_signaling_nan( b ); + av = float64_val(a); + bv = float64_val(b); #if SNAN_BIT_IS_ONE - a &= ~LIT64( 0x0008000000000000 ); - b &= ~LIT64( 0x0008000000000000 ); + av &= ~LIT64( 0x0008000000000000 ); + bv &= ~LIT64( 0x0008000000000000 ); #else - a |= LIT64( 0x0008000000000000 ); - b |= LIT64( 0x0008000000000000 ); + av |= LIT64( 0x0008000000000000 ); + bv |= LIT64( 0x0008000000000000 ); #endif if ( aIsSignalingNaN | bIsSignalingNaN ) float_raise( float_flag_invalid STATUS_VAR); if ( aIsSignalingNaN ) { if ( bIsSignalingNaN ) goto returnLargerSignificand; - return bIsNaN ? b : a; + res = bIsNaN ? bv : av; } else if ( aIsNaN ) { - if ( bIsSignalingNaN | ! bIsNaN ) return a; + if ( bIsSignalingNaN | ! bIsNaN ) + res = av; + else { returnLargerSignificand: - if ( (bits64) ( a<<1 ) < (bits64) ( b<<1 ) ) return b; - if ( (bits64) ( b<<1 ) < (bits64) ( a<<1 ) ) return a; - return ( a < b ) ? a : b; + if ( (bits64) ( av<<1 ) < (bits64) ( bv<<1 ) ) + res = bv; + else if ( (bits64) ( bv<<1 ) < (bits64) ( av<<1 ) ) + res = av; + else + res = ( av < bv ) ? av : bv; + } } else { - return b; + res = bv; } + return make_float64(res); } #ifdef FLOATX80 |