aboutsummaryrefslogtreecommitdiff
path: root/softfloat
diff options
context:
space:
mode:
authorChih-Min Chao <chihmin.chao@sifive.com>2020-04-22 20:01:14 -0700
committerChih-Min Chao <chihmin.chao@sifive.com>2020-04-22 20:02:30 -0700
commit6124093ce812364aa40243bdac6004883993cc39 (patch)
treecb2b66302acb8191f3535712bf5bf0b029f1ca24 /softfloat
parentbaf160fa42d3f112100b36f6831dbbcbda143336 (diff)
downloadspike-6124093ce812364aa40243bdac6004883993cc39.zip
spike-6124093ce812364aa40243bdac6004883993cc39.tar.gz
spike-6124093ce812364aa40243bdac6004883993cc39.tar.bz2
rvv: simplify f16_to_[u]i16 implementation
Signed-off-by: Chih-Min Chao <chihmin.chao@sifive.com>
Diffstat (limited to 'softfloat')
-rw-r--r--softfloat/f16_to_i16.c48
-rw-r--r--softfloat/f16_to_ui16.c47
-rw-r--r--softfloat/f32_to_i16.c2
-rw-r--r--softfloat/f32_to_ui16.c2
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 <stdbool.h>
#include <stdint.h>
-#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 <stdbool.h>
#include <stdint.h>
-#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 <stdint.h>
-#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 <stdint.h>
-#include "platform.h"
-#include "internals.h"
#include "specialize.h"
#include "softfloat.h"