Update QP for Makefile that works on Ubuntu and RHEL - adds API call to quadmath instead of RHEL printf of %Q. This will allow the examples to compile for both OSes

This commit is contained in:
James E. Stine 2024-01-14 22:07:32 -06:00
parent c62ddc234a
commit f267c20601
4 changed files with 22 additions and 7 deletions

View File

@ -6,7 +6,7 @@ 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
#LIBS = $(RISCV)/riscv-isa-sim/build/libsoftfloat.a -lm -lquadmath
IFLAGS = -I../../../addins/SoftFloat-3e/source/include/
LIBS = ../../../addins/SoftFloat-3e/build/Linux-x86_64-GCC/softfloat.a -lm -lquadmath
SRCS = $(wildcard *.c)

View File

@ -38,16 +38,19 @@ void printF64 (char *msg, float64_t d) {
int i, j;
conv.v = d.v; // use union to convert between hexadecimal and floating-point views
printf("%s: ", msg); // print out nicely
printf("0x%08x_%08x = %g\n", (conv.v >> 32),(conv.v & 0xFFFFFFFF), conv.d);
printf("0x%08lx_%08lx = %g\n", (conv.v >> 32),(conv.v & 0xFFFFFFFF), conv.d);
}
void printF128 (char *msg, float128_t q) {
qp conv;
int i, j;
char buf[64];
conv.v[0] = q.v[0]; // use union to convert between hexadecimal and floating-point views
conv.v[1] = q.v[1]; // use union to convert between hexadecimal and floating-point views
printf("%s: ", msg); // print out nicely
printf("0x%016" PRIx64 "_%016" PRIx64 " = %1.15Qe\n", q.v[1], q.v[0], conv.q);
//printf("0x%016" PRIx64 "_%016" PRIx64 " = %1.15Qe\n", q.v[1], q.v[0], conv.q);
quadmath_snprintf (buf, sizeof buf, "%1.15Qe", conv.q);
printf("0x%016" PRIx64 "_%016" PRIx64 " = %s\n", q.v[1], q.v[0], buf);
}
void printFlags(void) {

View File

@ -38,16 +38,23 @@ void printF64 (char *msg, float64_t d) {
int i, j;
conv.v = d.v; // use union to convert between hexadecimal and floating-point views
printf("%s: ", msg); // print out nicely
printf("0x%08x_%08x = %g\n", (conv.v >> 32),(conv.v & 0xFFFFFFFF), conv.d);
printf("0x%08lx_%08lx = %g\n", (conv.v >> 32),(conv.v & 0xFFFFFFFF), conv.d);
}
void printF128 (char *msg, float128_t q) {
qp conv;
int i, j;
char buf[64];
conv.v[0] = q.v[0]; // use union to convert between hexadecimal and floating-point views
conv.v[1] = q.v[1]; // use union to convert between hexadecimal and floating-point views
printf("%s: ", msg); // print out nicely
printf("0x%016" PRIx64 "_%016" PRIx64 " = %1.15Qe\n", q.v[1], q.v[0], conv.q);
// Some compilers can understand %Q for printf on quad precision instead of the
// API call of quadmath_snprintf
// printf("0x%016" PRIx64 "_%016" PRIx64 " = %1.15Qe\n", q.v[1], q.v[0], conv.q);
quadmath_snprintf (buf, sizeof buf, "%1.15Qe", conv.q);
printf("0x%016" PRIx64 "_%016" PRIx64 " = %s\n", q.v[1], q.v[0], buf);
}
void printFlags(void) {
@ -74,6 +81,8 @@ int main() {
float128_t x, y, z;
float128_t r;
uint32_t u, v, w;
int32_t a, b, c;
x.v[1] = 0xBFFF988ECE97DFEB;
x.v[0] = 0xC3BBA082445B4836;

View File

@ -38,16 +38,19 @@ void printF64 (char *msg, float64_t d) {
int i, j;
conv.v = d.v; // use union to convert between hexadecimal and floating-point views
printf("%s: ", msg); // print out nicely
printf("0x%08x_%08x = %g\n", (conv.v >> 32),(conv.v & 0xFFFFFFFF), conv.d);
printf("0x%08lx_%08lx = %g\n", (conv.v >> 32),(conv.v & 0xFFFFFFFF), conv.d);
}
void printF128 (char *msg, float128_t q) {
qp conv;
int i, j;
char buf[64];
conv.v[0] = q.v[0]; // use union to convert between hexadecimal and floating-point views
conv.v[1] = q.v[1]; // use union to convert between hexadecimal and floating-point views
printf("%s: ", msg); // print out nicely
printf("0x%016" PRIx64 "_%016" PRIx64 " = %1.15Qe\n", q.v[1], q.v[0], conv.q);
//printf("0x%016" PRIx64 "_%016" PRIx64 " = %1.15Qe\n", q.v[1], q.v[0], conv.q);
quadmath_snprintf (buf, sizeof buf, "%1.15Qe", conv.q);
printf("0x%016" PRIx64 "_%016" PRIx64 " = %s\n", q.v[1], q.v[0], buf);
}
void printFlags(void) {