[sim] made softfloat files C instead of C++
[riscv-isa-sim.git] / softfloat / i32_to_f64.c
diff --git a/softfloat/i32_to_f64.c b/softfloat/i32_to_f64.c
new file mode 100755 (executable)
index 0000000..d42cbe8
--- /dev/null
@@ -0,0 +1,31 @@
+\r
+#include <stdbool.h>\r
+#include <stdint.h>\r
+#include "platform.h"\r
+#include "primitives.h"\r
+#include "internals.h"\r
+#include "softfloat.h"\r
+\r
+float64_t i32_to_f64( int_fast32_t a )\r
+{\r
+    uint_fast64_t uiZ;\r
+    bool sign;\r
+    uint_fast32_t absA;\r
+    int shiftCount;\r
+    union ui64_f64 uZ;\r
+\r
+    if ( ! a ) {\r
+        uiZ = 0;\r
+    } else {\r
+        sign = ( a < 0 );\r
+        absA = sign ? - a : a;\r
+        shiftCount = softfloat_countLeadingZeros32( absA ) + 21;\r
+        uiZ =\r
+            packToF64UI(\r
+                sign, 0x432 - shiftCount, (uint_fast64_t) absA<<shiftCount );\r
+    }\r
+    uZ.ui = uiZ;\r
+    return uZ.f;\r
+\r
+}\r
+\r