diff --git a/.gitignore b/.gitignore index 9b3e6dc62..6ea4b650e 100644 --- a/.gitignore +++ b/.gitignore @@ -52,6 +52,8 @@ examples/asm/sumtest/sumtest examples/asm/example/example examples/C/sum/sum examples/C/fir/fir +examples/fp/softfloat_demo/softfloat_demo +pipelined/src/fma/fma16_testgen linux/devicetree/debug/* !linux/devicetree/debug/dump-dts.sh linux/testvector-generation/genCheckpoint.gdb diff --git a/examples/fp/softfloat_demo/Makefile b/examples/fp/softfloat_demo/Makefile new file mode 100644 index 000000000..4d0efe20e --- /dev/null +++ b/examples/fp/softfloat_demo/Makefile @@ -0,0 +1,23 @@ +# Makefile + +CC = gcc +CFLAGS = -O3 +LIBS = -lm +LFLAGS = -L. +# Link against the riscv-isa-sim version of SoftFloat rather than +# the regular version to get RISC-V NaN behavior +IFLAGS = -I$(RISCV)/riscv-isa-sim/softfloat +LIBS = $(RISCV)/riscv-isa-sim/build/libsoftfloat.a +#IFLAGS = -I../../../addins/SoftFloat-3e/source/include/ +#LIBS = ../../../addins/SoftFloat-3e/build/Linux-x86_64-GCC/softfloat.a +SRCS = $(wildcard *.c) + +PROGS = $(patsubst %.c,%,$(SRCS)) + +all: $(PROGS) + +%: %.c + $(CC) $(CFLAGS) $(IFLAGS) $(LFLAGS) -o $@ $< $(LIBS) + +clean: + rm -f $(PROGS) diff --git a/examples/fp/softfloat_demo/softfloat_demo.c b/examples/fp/softfloat_demo/softfloat_demo.c new file mode 100644 index 000000000..0f34ac255 --- /dev/null +++ b/examples/fp/softfloat_demo/softfloat_demo.c @@ -0,0 +1,53 @@ +// softfloat_demo.c +// David_Harris@hmc.edu 27 February 2022 +// +// Demonstrate using SoftFloat do compute a floating-point, then print results + +#include +#include +#include "softfloat.h" +#include "softfloat_types.h" +typedef union sp { + uint32_t v; + float f; +} sp; + +void printF32(char *msg, float32_t f) { + sp conv; + conv.v = f.v; // use union to convert between hexadecimal and floating-point views + printf ("%s: 0x%08x = %g\n", msg, conv.v, conv.f); +} + +void printFlags(void) { + int NX = softfloat_exceptionFlags % 2; + int UF = (softfloat_exceptionFlags >> 1) % 2; + int OF = (softfloat_exceptionFlags >> 2) % 2; + int DZ = (softfloat_exceptionFlags >> 3) % 2; + int NV = (softfloat_exceptionFlags >> 4) % 2; + printf ("exceptions: Inexact %d Underflow %d Overflow %d DivideZero %d Invalid %d\n", + NX, UF, OF, DZ, NV); +} + +void softfloatInit(void) { + // rounding modes: RNE: softfloat_round_near_even + // RZ: softfloat_round_minMag + // RP: softfloat_round_max + // RM: softfloat_round_min + softfloat_roundingMode = softfloat_round_near_even; + softfloat_exceptionFlags = 0; // clear exceptions + softfloat_detectTininess = softfloat_tininess_beforeRounding; // RISC-V behavior for tininess +} + +int main() +{ + float32_t x, y, z, r; + + x.v = 0x3fc00000; + y.v = 0x3fc00000; + z.v = 0x00000001; + + softfloatInit(); + r = f32_mulAdd(x, y, z); + printF32("X", x); printF32("Y", y); printF32("Z", z); + printF32("result = X*Y+Z", r); printFlags(); +} diff --git a/pipelined/src/fma/div b/pipelined/src/fma/div deleted file mode 100755 index faeb00d97..000000000 Binary files a/pipelined/src/fma/div and /dev/null differ diff --git a/pipelined/src/fma/div.c b/pipelined/src/fma/div.c deleted file mode 100644 index c76efab20..000000000 --- a/pipelined/src/fma/div.c +++ /dev/null @@ -1,52 +0,0 @@ -#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/pipelined/src/fma/fma16_testgen b/pipelined/src/fma/fma16_testgen deleted file mode 100755 index 625c72189..000000000 Binary files a/pipelined/src/fma/fma16_testgen and /dev/null differ diff --git a/pipelined/src/fma/fma32 b/pipelined/src/fma/fma32 deleted file mode 100755 index 44be8588f..000000000 Binary files a/pipelined/src/fma/fma32 and /dev/null differ diff --git a/pipelined/src/fma/fma32.c b/pipelined/src/fma/fma32.c deleted file mode 100644 index 4b7bda1fd..000000000 --- a/pipelined/src/fma/fma32.c +++ /dev/null @@ -1,47 +0,0 @@ -#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; -}