From bffd4175675e7cceb5330b57158d2a860f177235 Mon Sep 17 00:00:00 2001 From: David Harris Date: Fri, 4 Mar 2022 07:21:18 -0800 Subject: [PATCH] Cleaned up printing and warnings in fpcalc.c --- examples/fp/fpcalc/Makefile | 2 +- examples/fp/fpcalc/fpcalc.c | 44 ++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/examples/fp/fpcalc/Makefile b/examples/fp/fpcalc/Makefile index 4d0efe20..196fdf3d 100644 --- a/examples/fp/fpcalc/Makefile +++ b/examples/fp/fpcalc/Makefile @@ -1,7 +1,7 @@ # Makefile CC = gcc -CFLAGS = -O3 +CFLAGS = -O3 -Wno-format-overflow LIBS = -lm LFLAGS = -L. # Link against the riscv-isa-sim version of SoftFloat rather than diff --git a/examples/fp/fpcalc/fpcalc.c b/examples/fp/fpcalc/fpcalc.c index b8e180bf..f41494c7 100644 --- a/examples/fp/fpcalc/fpcalc.c +++ b/examples/fp/fpcalc/fpcalc.c @@ -29,19 +29,23 @@ typedef union dp { int opSize = 0; -void long2binstr(long val, char *str, int bits) { - int i; - long masked; +void long2binstr(unsigned long val, char *str, int bits) { + int i, shamt; + unsigned long mask, masked; if (val == 0) { // just return zero str[0] = '0'; str[1] = 0; } else { - for (i=0; i> 16)); printf("_"); printf("%04x", (conv.v & 0xFF)); - printf(" = %g = %s: Biased Exp %d Fract 0x%lx\n", conv.f, sci, exp, fract); + printf(" = %g = %s: Biased Exp %ld 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); } @@ -107,7 +111,7 @@ void printF64(char *msg, float64_t f) { long exp, fract; long mask; char sign; - char sci[80], fractstr[80]; + char sci[200], fractstr[200]; conv.v = f.v; // use union to convert between hexadecimal and floating-point views @@ -120,18 +124,18 @@ void printF64(char *msg, float64_t f) { else if (exp == 0 && fract != 0) sprintf(sci, "Denorm: %c0.%s x 2^-1022", sign, fractstr); else if (exp == 2047 && fract == 0) sprintf(sci, "%cinf", sign); else if (exp == 2047 && fract != 0) sprintf(sci, "NaN Payload: %c%s", sign, fractstr); - else sprintf(sci, "%c1.%s x 2^%d", sign, fractstr, exp-1023); + else sprintf(sci, "%c1.%s x 2^%ld", sign, fractstr, exp-1023); //printf ("%s: 0x%016lx = %lg\n", msg, conv.v, conv.d); printf("%s: ", msg); - printf("0x%04x", (conv.v >> 48)); + printf("0x%04lx", (conv.v >> 48)); printf("_"); - printf("%04x", (conv.v >> 32) & 0xFFFF); + printf("%04lx", (conv.v >> 32) & 0xFFFF); printf("_"); - printf("%04x", (conv.v >> 16)); + printf("%04lx", (conv.v >> 16) & 0xFFFF); printf("_"); - printf("%04x", (conv.v & 0xFFFF)); - printf(" = %lg = %s: Biased Exp %d Fract 0x%lx\n", conv.d, sci, exp, fract); + printf("%04lx", (conv.v & 0xFFFF)); + printf(" = %lg = %s: Biased Exp %ld 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); } @@ -204,7 +208,7 @@ int main(int argc, char *argv[]) { uint64_t xn, yn, zn; char op1, op2; - char cmd[80]; + char cmd[200]; softfloatInit();