From 3face89fafd851e17343d0fa646852f332af3a0b Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Tue, 12 Jan 2016 16:13:20 -0800 Subject: [PATCH] Use new NaN discipline --- softfloat/f32_to_i32.c | 1 + softfloat/f32_to_i64.c | 2 +- softfloat/f64_to_i32.c | 1 + softfloat/f64_to_i64.c | 2 ++ softfloat/specialize.h | 4 ++-- 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/softfloat/f32_to_i32.c b/softfloat/f32_to_i32.c index 98c67c9..bbbaee0 100755 --- a/softfloat/f32_to_i32.c +++ b/softfloat/f32_to_i32.c @@ -21,6 +21,7 @@ int_fast32_t f32_to_i32( float32_t a, int_fast8_t roundingMode, bool exact ) sign = signF32UI( uiA ); exp = expF32UI( uiA ); sig = fracF32UI( uiA ); + if ( ( exp == 0xFF ) && sig ) sign = 0; if ( exp ) sig |= 0x00800000; sig64 = (uint_fast64_t) sig<<32; shiftCount = 0xAF - exp; diff --git a/softfloat/f32_to_i64.c b/softfloat/f32_to_i64.c index 34f877f..c0b8981 100755 --- a/softfloat/f32_to_i64.c +++ b/softfloat/f32_to_i64.c @@ -25,7 +25,7 @@ int_fast64_t f32_to_i64( float32_t a, int_fast8_t roundingMode, bool exact ) shiftCount = 0xBE - exp; if ( shiftCount < 0 ) { softfloat_raiseFlags( softfloat_flag_invalid ); - if ( ! sign ) { + if ( ! sign || ( ( exp == 0xFF ) && sig ) ) { return INT64_C( 0x7FFFFFFFFFFFFFFF ); } return - INT64_C( 0x7FFFFFFFFFFFFFFF ) - 1; diff --git a/softfloat/f64_to_i32.c b/softfloat/f64_to_i32.c index 8259ee2..0778a86 100755 --- a/softfloat/f64_to_i32.c +++ b/softfloat/f64_to_i32.c @@ -20,6 +20,7 @@ int_fast32_t f64_to_i32( float64_t a, int_fast8_t roundingMode, bool exact ) sign = signF64UI( uiA ); exp = expF64UI( uiA ); sig = fracF64UI( uiA ); + if ( ( exp == 0x7FF ) && sig ) sign = 0; if ( exp ) sig |= UINT64_C( 0x0010000000000000 ); shiftCount = 0x42C - exp; if ( 0 < shiftCount ) sig = softfloat_shift64RightJam( sig, shiftCount ); diff --git a/softfloat/f64_to_i64.c b/softfloat/f64_to_i64.c index 0e6ddcd..676e944 100755 --- a/softfloat/f64_to_i64.c +++ b/softfloat/f64_to_i64.c @@ -28,6 +28,8 @@ int_fast64_t f64_to_i64( float64_t a, int_fast8_t roundingMode, bool exact ) softfloat_raiseFlags( softfloat_flag_invalid ); return ! sign + || ( ( exp == 0x7FF ) + && fracF64UI( uiA ) ) ? INT64_C( 0x7FFFFFFFFFFFFFFF ) : - INT64_C( 0x7FFFFFFFFFFFFFFF ) - 1; } diff --git a/softfloat/specialize.h b/softfloat/specialize.h index 1793c46..72a9f16 100755 --- a/softfloat/specialize.h +++ b/softfloat/specialize.h @@ -50,7 +50,7 @@ struct commonNaN { /*---------------------------------------------------------------------------- | The pattern for a default generated single-precision NaN. *----------------------------------------------------------------------------*/ -#define defaultNaNF32UI 0xFFFFFFFF +#define defaultNaNF32UI 0x7FC00000 /*---------------------------------------------------------------------------- | Returns 1 if the single-precision floating-point value `a' is a signaling @@ -83,7 +83,7 @@ uint_fast32_t softfloat_propagateNaNF32UI( uint_fast32_t, uint_fast32_t ); /*---------------------------------------------------------------------------- | The pattern for a default generated double-precision NaN. *----------------------------------------------------------------------------*/ -#define defaultNaNF64UI UINT64_C(0xFFFFFFFFFFFFFFFF) +#define defaultNaNF64UI UINT64_C(0x7FF8000000000000) /*---------------------------------------------------------------------------- *----------------------------------------------------------------------------*/ -- 2.30.2