aboutsummaryrefslogtreecommitdiff
path: root/softfloat/f64_to_i32_r_minMag.c
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@s141.Millennium.Berkeley.EDU>2011-06-19 20:47:29 -0700
committerAndrew Waterman <waterman@s141.Millennium.Berkeley.EDU>2011-06-19 20:47:29 -0700
commit77452a26e7d95d29dbaa797595ae683f03a3345b (patch)
treee7aaae682f73a20ceb4d3366528b0cd38378f49d /softfloat/f64_to_i32_r_minMag.c
parent740f981cfd55604d46598144dccac26dd53f643c (diff)
downloadriscv-isa-sim-77452a26e7d95d29dbaa797595ae683f03a3345b.zip
riscv-isa-sim-77452a26e7d95d29dbaa797595ae683f03a3345b.tar.gz
riscv-isa-sim-77452a26e7d95d29dbaa797595ae683f03a3345b.tar.bz2
temporary undoing of renaming
Diffstat (limited to 'softfloat/f64_to_i32_r_minMag.c')
-rwxr-xr-xsoftfloat/f64_to_i32_r_minMag.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/softfloat/f64_to_i32_r_minMag.c b/softfloat/f64_to_i32_r_minMag.c
new file mode 100755
index 0000000..39246c2
--- /dev/null
+++ b/softfloat/f64_to_i32_r_minMag.c
@@ -0,0 +1,50 @@
+
+#include <stdbool.h>
+#include <stdint.h>
+#include "platform.h"
+#include "internals.h"
+#include "softfloat.h"
+
+int_fast32_t f64_to_i32_r_minMag( float64_t a, bool exact )
+{
+ union ui64_f64 uA;
+ uint_fast64_t uiA;
+ int_fast16_t exp;
+ uint_fast64_t sig;
+ bool sign;
+ int_fast16_t shiftCount;
+ uint_fast32_t absZ;
+ union { uint32_t ui; int32_t i; } uZ;
+ int_fast32_t z;
+
+ uA.f = a;
+ uiA = uA.ui;
+ exp = expF64UI( uiA );
+ sig = fracF64UI( uiA );
+ if ( exp < 0x3FF ) {
+ if ( exact && ( exp | sig ) ) {
+ softfloat_exceptionFlags |= softfloat_flag_inexact;
+ }
+ return 0;
+ }
+ sign = signF64UI( uiA );
+ if ( 0x41E < exp ) {
+ if ( ( exp == 0x7FF ) && sig ) sign = 0;
+ goto invalid;
+ }
+ sig |= UINT64_C( 0x0010000000000000 );
+ shiftCount = 0x433 - exp;
+ absZ = sig>>shiftCount;
+ uZ.ui = sign ? - absZ : absZ;
+ z = uZ.i;
+ if ( ( z < 0 ) != sign ) goto invalid;
+ if ( exact && ( (uint_fast64_t) absZ<<shiftCount != sig ) ) {
+ softfloat_exceptionFlags |= softfloat_flag_inexact;
+ }
+ return z;
+ invalid:
+ softfloat_raiseFlags( softfloat_flag_invalid );
+ return sign ? -0x7FFFFFFF - 1 : 0x7FFFFFFF;
+
+}
+