From 6124093ce812364aa40243bdac6004883993cc39 Mon Sep 17 00:00:00 2001 From: Chih-Min Chao Date: Wed, 22 Apr 2020 20:01:14 -0700 Subject: rvv: simplify f16_to_[u]i16 implementation Signed-off-by: Chih-Min Chao --- softfloat/f16_to_i16.c | 48 +----------------------------------------------- softfloat/f16_to_ui16.c | 47 +---------------------------------------------- softfloat/f32_to_i16.c | 2 -- softfloat/f32_to_ui16.c | 2 -- 4 files changed, 2 insertions(+), 97 deletions(-) diff --git a/softfloat/f16_to_i16.c b/softfloat/f16_to_i16.c index b05cd8c..0ec7ce1 100644 --- a/softfloat/f16_to_i16.c +++ b/softfloat/f16_to_i16.c @@ -34,59 +34,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =============================================================================*/ -#include #include -#include "platform.h" -#include "internals.h" #include "specialize.h" #include "softfloat.h" int_fast16_t f16_to_i16( float16_t a, uint_fast8_t roundingMode, bool exact ) { - union ui16_f16 uA; - uint_fast16_t uiA; - bool sign; - int_fast8_t exp; - uint_fast16_t frac; - int_fast32_t sig32; - int_fast8_t shiftDist; - bool do_round = true; - - /*------------------------------------------------------------------------ - *------------------------------------------------------------------------*/ - uA.f = a; - uiA = uA.ui; - sign = signF16UI( uiA ); - exp = expF16UI( uiA ); - frac = fracF16UI( uiA ); - /*------------------------------------------------------------------------ - *------------------------------------------------------------------------*/ - if ( exp == 0x1F ) { - softfloat_raiseFlags( softfloat_flag_invalid ); - return - frac ? i16_fromNaN - : sign ? i16_fromNegOverflow : i16_fromPosOverflow; - } - /*------------------------------------------------------------------------ - *------------------------------------------------------------------------*/ - sig32 = frac; - if ( exp ) { - sig32 |= 0x0400; - shiftDist = exp - 0x19; - if ( 0 <= shiftDist ) { - sig32 <<= shiftDist; - sig32 = sign ? -sig32 : sig32; - do_round = false; - } else { - shiftDist = exp - 0x0D; - if ( 0 < shiftDist ) - sig32 <<= shiftDist; - } - } - - if (do_round) - sig32 = softfloat_roundToI32( - sign, (uint_fast32_t) sig32, roundingMode, exact); + int_fast32_t sig32 = f16_to_i32(a, roundingMode, exact); if (sig32 > INT16_MAX) { softfloat_exceptionFlags |= softfloat_flag_invalid; diff --git a/softfloat/f16_to_ui16.c b/softfloat/f16_to_ui16.c index 652daff..818328a 100644 --- a/softfloat/f16_to_ui16.c +++ b/softfloat/f16_to_ui16.c @@ -34,57 +34,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =============================================================================*/ -#include #include -#include "platform.h" -#include "internals.h" #include "specialize.h" #include "softfloat.h" uint_fast16_t f16_to_ui16( float16_t a, uint_fast8_t roundingMode, bool exact ) { - union ui16_f16 uA; - uint_fast16_t uiA; - bool sign; - int_fast8_t exp; - uint_fast16_t frac; - uint_fast32_t sig32; - int_fast8_t shiftDist; - bool do_round = true; - - /*------------------------------------------------------------------------ - *------------------------------------------------------------------------*/ - uA.f = a; - uiA = uA.ui; - sign = signF16UI( uiA ); - exp = expF16UI( uiA ); - frac = fracF16UI( uiA ); - /*------------------------------------------------------------------------ - *------------------------------------------------------------------------*/ - if ( exp == 0x1F ) { - softfloat_raiseFlags( softfloat_flag_invalid ); - return - frac ? ui16_fromNaN - : sign ? ui16_fromNegOverflow : ui16_fromPosOverflow; - } - /*------------------------------------------------------------------------ - *------------------------------------------------------------------------*/ - sig32 = frac; - if ( exp ) { - sig32 |= 0x0400; - shiftDist = exp - 0x19; - if ( (0 <= shiftDist) && !sign ) { - sig32 << shiftDist; - do_round = false; - } else { - shiftDist = exp - 0x0D; - if ( 0 < shiftDist ) - sig32 <<= shiftDist; - } - } - - if (do_round) - sig32 = softfloat_roundToUI32( sign, sig32, roundingMode, exact ); + uint_fast32_t sig32 = f16_to_ui32(a, roundingMode, exact); if (sig32 > UINT16_MAX) { softfloat_exceptionFlags |= softfloat_flag_invalid; @@ -92,6 +48,5 @@ uint_fast16_t f16_to_ui16( float16_t a, uint_fast8_t roundingMode, bool exact ) } else { return sig32; } - } diff --git a/softfloat/f32_to_i16.c b/softfloat/f32_to_i16.c index 3ec0658..14ebc6b 100644 --- a/softfloat/f32_to_i16.c +++ b/softfloat/f32_to_i16.c @@ -35,8 +35,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =============================================================================*/ #include -#include "platform.h" -#include "internals.h" #include "specialize.h" #include "softfloat.h" diff --git a/softfloat/f32_to_ui16.c b/softfloat/f32_to_ui16.c index 16b8a4d..a8f458d 100644 --- a/softfloat/f32_to_ui16.c +++ b/softfloat/f32_to_ui16.c @@ -35,8 +35,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =============================================================================*/ #include -#include "platform.h" -#include "internals.h" #include "specialize.h" #include "softfloat.h" -- cgit v1.1