From eba4eda245cb8fc498b61efb087e7e7182c9ea67 Mon Sep 17 00:00:00 2001 From: "James E. Stine" Date: Mon, 28 Feb 2022 14:10:22 -0600 Subject: [PATCH] Minor tweak of output of fpcalc - can be reversed with commented out code --- examples/fp/fpcalc/Makefile | 23 +++++++++++++++++++++ examples/fp/fpcalc/fpcalc.c | 22 ++++++++++++++++---- examples/fp/softfloat_demo/softfloat_demo.c | 11 ++++++++-- 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 examples/fp/fpcalc/Makefile diff --git a/examples/fp/fpcalc/Makefile b/examples/fp/fpcalc/Makefile new file mode 100644 index 000000000..4d0efe20e --- /dev/null +++ b/examples/fp/fpcalc/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/fpcalc/fpcalc.c b/examples/fp/fpcalc/fpcalc.c index 116cf8680..b8e180bf7 100644 --- a/examples/fp/fpcalc/fpcalc.c +++ b/examples/fp/fpcalc/fpcalc.c @@ -93,8 +93,13 @@ void printF32(char *msg, float32_t f) { else sprintf(sci, "%c1.%s x 2^%d", sign, fractstr, exp-127); //printf ("%s: 0x%08x = %g\n", msg, conv.v, conv.f); - printf ("%s: 0x%08x = %g = %s: Biased Exp %d Fract 0x%lx\n", - msg, conv.v, conv.f, sci, exp, fract); + printf("%s: ", msg); + printf("0x%04x", (conv.v >> 16)); + printf("_"); + printf("%04x", (conv.v & 0xFF)); + printf(" = %g = %s: Biased Exp %d Fract 0x%lx\n", conv.f, sci, exp, fract); + //printf ("%s: 0x%08x = %g = %s: Biased Exp %d Fract 0x%lx\n", + // msg, conv.v, conv.f, sci, exp, fract); } void printF64(char *msg, float64_t f) { @@ -118,8 +123,17 @@ void printF64(char *msg, float64_t f) { else sprintf(sci, "%c1.%s x 2^%d", sign, fractstr, exp-1023); //printf ("%s: 0x%016lx = %lg\n", msg, conv.v, conv.d); - printf ("%s: 0x%016lx = %lg = %s: Biased Exp %d Fract 0x%lx\n", - msg, conv.v, conv.d, sci, exp, fract); + printf("%s: ", msg); + printf("0x%04x", (conv.v >> 48)); + printf("_"); + printf("%04x", (conv.v >> 32) & 0xFFFF); + printf("_"); + printf("%04x", (conv.v >> 16)); + printf("_"); + printf("%04x", (conv.v & 0xFFFF)); + printf(" = %lg = %s: Biased Exp %d Fract 0x%lx\n", conv.d, sci, exp, fract); + //printf ("%s: 0x%016lx = %lg = %s: Biased Exp %d Fract 0x%lx\n", + // msg, conv.v, conv.d, sci, exp, fract); } void printFlags(void) { diff --git a/examples/fp/softfloat_demo/softfloat_demo.c b/examples/fp/softfloat_demo/softfloat_demo.c index 0f34ac255..111847a4f 100644 --- a/examples/fp/softfloat_demo/softfloat_demo.c +++ b/examples/fp/softfloat_demo/softfloat_demo.c @@ -12,10 +12,17 @@ typedef union sp { float f; } sp; -void printF32(char *msg, float32_t f) { +void printF32 (char *msg, float32_t f) { sp conv; + int i, j; 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); + // Print out nicely + printf("%s: ", msg); + printf("0x%04x", (conv.v >> 16)); + printf("_"); + printf("%04x", (conv.v & 0xFFFF)); + printf(" = %g\n", conv.f); + //printf ("%s: 0x%08x = %g\n", msg, conv.v, conv.f); } void printFlags(void) {