From 896fc0be0e7445c48d777a1f2369842c9a685dd5 Mon Sep 17 00:00:00 2001 From: "James E. Stine" Date: Sat, 26 Feb 2022 13:20:50 -0600 Subject: [PATCH] Update sample SoftFloat programs --- tests/fp/sample/compile.sh | 3 +++ tests/fp/sample/div.c | 52 ++++++++++++++++++++++++++++++++++++++ tests/fp/sample/fma.c | 47 ++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100755 tests/fp/sample/compile.sh create mode 100644 tests/fp/sample/div.c create mode 100644 tests/fp/sample/fma.c diff --git a/tests/fp/sample/compile.sh b/tests/fp/sample/compile.sh new file mode 100755 index 00000000..24d71efa --- /dev/null +++ b/tests/fp/sample/compile.sh @@ -0,0 +1,3 @@ +#!/bin/sh +gcc -c -I. -I../../source/include -O2 -o $1.o $1.c +gcc -I -I. -I../../source/include -o $1 $1.o softfloat.a diff --git a/tests/fp/sample/div.c b/tests/fp/sample/div.c new file mode 100644 index 00000000..c76efab2 --- /dev/null +++ b/tests/fp/sample/div.c @@ -0,0 +1,52 @@ +#include +#include +#include "softfloat.h" +#include "softfloat_types.h" + +int float_rounding_mode = 0; + +union dp { + unsigned short x[4]; + double y; +} X; + + +int main() +{ + uint8_t rounding_mode; + uint8_t exceptions; + + uint64_t n, d, result; + float64_t d_n, d_d, d_result; + + n = 0x3feffffffefffff6; + d = 0xffeffffffffffffe; + //n = 0x00000000400001ff; + //d = 0x3ffffdfffffffbfe; + + d_n.v = n; + d_d.v = d; + + softfloat_roundingMode = rounding_mode; + softfloat_exceptionFlags = 0; + softfloat_detectTininess = softfloat_tininess_beforeRounding; + + d_result = f64_div(d_n, d_d); + + //result = d_result.v; + //exceptions = softfloat_exceptionFlags & 0x1f; + + X.x[3] = (d_result.v & 0xffff000000000000) >> 48; + X.x[2] = (d_result.v & 0x0000ffff00000000) >> 32; + X.x[1] = (d_result.v & 0x00000000ffff0000) >> 16; + X.x[0] = (d_result.v & 0x000000000000ffff); + + printf("Number = %.4x\n", X.x[3]); + printf("Number = %.4x\n", X.x[2]); + printf("Number = %.4x\n", X.x[1]); + printf("Number = %.4x\n", X.x[0]); + printf("Number = %1.25lg\n", X.y); + + + return 0; +} diff --git a/tests/fp/sample/fma.c b/tests/fp/sample/fma.c new file mode 100644 index 00000000..4b7bda1f --- /dev/null +++ b/tests/fp/sample/fma.c @@ -0,0 +1,47 @@ +#include +#include +#include "softfloat.h" +#include "softfloat_types.h" + +int float_rounding_mode = 0; + +union sp { + unsigned short x[2]; + float y; +} X; + + +int main() +{ + uint8_t rounding_mode; + uint8_t exceptions; + + uint32_t multiplier, multiplicand, addend, result; + float32_t f_multiplier, f_multiplicand, f_addend, f_result; + + multiplier = 0xbf800000; + multiplicand = 0xbf800000; + addend = 0xffaaaaaa; + + f_multiplier.v = multiplier; + f_multiplicand.v = multiplicand; + f_addend.v = addend; + + softfloat_roundingMode = rounding_mode; + softfloat_exceptionFlags = 0; + softfloat_detectTininess = softfloat_tininess_beforeRounding; + + f_result = f32_mulAdd(f_multiplier, f_multiplicand, f_addend); + + result = f_result.v; + exceptions = softfloat_exceptionFlags & 0x1f; + + printf("%x\n", f_result.v); + + // Print out SP number + X.x[1] = (f_result.v & 0xffff0000) >> 16; + X.x[0] = (f_result.v & 0x0000ffff); + printf("Number = %f\n", X.y); + + return 0; +}