From: Petar Jovanovic Date: Fri, 3 Nov 2017 18:10:04 +0000 (+0100) Subject: mips: finetune tests that print FCSR X-Git-Tag: VALGRIND_3_14_0~210 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=95038d380d60e7af2d04ffdd8432fdebed1990aa;p=thirdparty%2Fvalgrind.git mips: finetune tests that print FCSR Bits 18 (NAN2008) and 19 (ABS2008) in FCSR are preset by hardware and can differ between platforms. Hence, we should clear these bits before printing FCSR value in order to have the same output on different platforms. This fixes several failures (tests modified by this change) that occur on MIPS P5600 board. The P5600 is a core that implements MIPS32 Release 5 arch. --- diff --git a/none/tests/mips32/round.c b/none/tests/mips32/round.c index feba168556..052508da39 100644 --- a/none/tests/mips32/round.c +++ b/none/tests/mips32/round.c @@ -2,6 +2,16 @@ #include +/* + * Bits 18 (NAN2008) and 19 (ABS2008) are preset by hardware and may differ + * between platforms. Hence a macro to clear them before printing FCSR + * values. + */ +#define FCSR_NAN2008 1 << 18 +#define FCSR_ABS2008 1 << 19 +#define FLAGS_RM_MASK 0xFFFFFFFF & ~(FCSR_ABS2008 | FCSR_NAN2008) +#define CLEAR_PRESETBITS_FCSR(fcsr) (fcsr & FLAGS_RM_MASK) + typedef enum { CEILWS=0, CEILWD, FLOORWS, FLOORWD, @@ -174,42 +184,42 @@ int directedRoundingMode(flt_dir_op_t op) { case CEILWS: UNOPfw("ceil.w.s"); printf("%s %d %f\n", flt_dir_op_names[op], fd_w, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CEILWD: UNOPdw("ceil.w.d"); printf("%s %d %lf\n", flt_dir_op_names[op], fd_w, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case FLOORWS: UNOPfw("floor.w.s"); printf("%s %d %f\n", flt_dir_op_names[op], fd_w, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case FLOORWD: UNOPdw("floor.w.d"); printf("%s %d %lf\n", flt_dir_op_names[op], fd_w, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case ROUNDWS: UNOPfw("round.w.s"); printf("%s %d %f\n", flt_dir_op_names[op], fd_w, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case ROUNDWD: UNOPdw("round.w.d"); printf("%s %d %lf\n", flt_dir_op_names[op], fd_w, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case TRUNCWS: UNOPfw("trunc.w.s"); printf("%s %d %f\n", flt_dir_op_names[op], fd_w, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case TRUNCWD: UNOPdw("trunc.w.d"); printf("%s %d %lf\n", flt_dir_op_names[op], fd_w, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; default: printf("error\n"); @@ -237,32 +247,32 @@ int FCSRRoundingMode(flt_round_op_t op1) case CVTDS: UNOPfd("cvt.d.s"); printf("%s %lf %lf\n", flt_round_op_names[op1], fd_d, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CVTDW: UNOPwd("cvt.d.w"); printf("%s %lf %d\n", flt_round_op_names[op1], fd_d, fs_w[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CVTSD: UNOPdf("cvt.s.d"); printf("%s %f %lf\n", flt_round_op_names[op1], fd_f, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CVTSW: UNOPwf("cvt.s.w"); printf("%s %f %d\n", flt_round_op_names[op1], fd_f, fs_w[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CVTWS: UNOPfw("cvt.w.s"); printf("%s %d %f\n", flt_round_op_names[op1], fd_w, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CVTWD: UNOPdw("cvt.w.d"); printf("%s %d %lf\n", flt_round_op_names[op1], fd_w, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; default: printf("error\n"); diff --git a/none/tests/mips32/round_fpu64.c b/none/tests/mips32/round_fpu64.c index e35c8b5a81..970dd05b0d 100644 --- a/none/tests/mips32/round_fpu64.c +++ b/none/tests/mips32/round_fpu64.c @@ -8,7 +8,15 @@ #define MAX_ARR 24 #define PERROR \ printf("This test is testing mips32r2 instructions in fpu64 mode.\n"); -#define FLAGS_RM_MASK 0xFFFFFFFF +/* + * Bits 18 (NAN2008) and 19 (ABS2008) are preset by hardware and may differ + * between platforms. Hence a macro to clear them before printing FCSR + * values. + */ +#define FCSR_NAN2008 1 << 18 +#define FCSR_ABS2008 1 << 19 +#define FLAGS_RM_MASK 0xFFFFFFFF & ~(FCSR_ABS2008 | FCSR_NAN2008) +#define CLEAR_PRESETBITS_FCSR(fcsr) (fcsr & FLAGS_RM_MASK) typedef enum { CVTLS, CVTLD, ROUNDLS, ROUNDLD, @@ -122,61 +130,61 @@ int FCSRRoundingMode(flt_round_op_t op) UNOPsl("cvt.l.s"); printf("%s %lld %f\n", flt_round_op_names[op], fd_l, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr & FLAGS_RM_MASK); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CVTLD: UNOPdl("cvt.l.d"); printf("%s %lld %lf\n", flt_round_op_names[op], fd_l, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr & FLAGS_RM_MASK); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case ROUNDLS: UNOPsl("round.l.s"); printf("%s %lld %f\n", flt_round_op_names[op], fd_l, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr & FLAGS_RM_MASK); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case ROUNDLD: UNOPdl("round.l.d"); printf("%s %lld %lf\n", flt_round_op_names[op], fd_l, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr & FLAGS_RM_MASK); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case TRUNCLS: UNOPsl("trunc.l.s"); printf("%s %lld %f\n", flt_round_op_names[op], fd_l, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr & FLAGS_RM_MASK); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case TRUNCLD: UNOPdl("trunc.l.d"); printf("%s %lld %lf\n", flt_round_op_names[op], fd_l, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr & FLAGS_RM_MASK); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case FLOORLS: UNOPsl("floor.l.s"); printf("%s %lld %f\n", flt_round_op_names[op], fd_l, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr & FLAGS_RM_MASK); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case FLOORLD: UNOPdl("floor.l.d"); printf("%s %lld %lf\n", flt_round_op_names[op], fd_l, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr & FLAGS_RM_MASK); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CEILLS: UNOPsl("ceil.l.s"); printf("%s %lld %f\n", flt_round_op_names[op], fd_l, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr & FLAGS_RM_MASK); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CEILLD: UNOPdl("ceil.l.d"); printf("%s %lld %lf\n", flt_round_op_names[op], fd_l, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr & FLAGS_RM_MASK); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; default: printf("error\n"); diff --git a/none/tests/mips32/test_fcsr.c b/none/tests/mips32/test_fcsr.c index 6bb03a0a42..c422482cbd 100644 --- a/none/tests/mips32/test_fcsr.c +++ b/none/tests/mips32/test_fcsr.c @@ -2,6 +2,16 @@ #include +/* + * Bits 18 (NAN2008) and 19 (ABS2008) are preset by hardware and may differ + * between platforms. Hence a macro to clear them before printing FCSR + * values. + */ +#define FCSR_NAN2008 1 << 18 +#define FCSR_ABS2008 1 << 19 +#define FLAGS_RM_MASK 0xFFFFFFFF & ~(FCSR_ABS2008 | FCSR_NAN2008) +#define CLEAR_PRESETBITS_FCSR(fcsr) (fcsr & FLAGS_RM_MASK) + int main () { int out [] = {0, 0}; @@ -22,7 +32,8 @@ int main () : "r" (in), "r" (out) : "a1", "a2", "t0", "$f0", "$f1" ); - printf("FCSR::1: 0x%x, 2: 0x%x\n", out[0], out[1]); + printf("FCSR::1: 0x%x, 2: 0x%x\n", CLEAR_PRESETBITS_FCSR(out[0]), + CLEAR_PRESETBITS_FCSR(out[1])); return 0; } #else diff --git a/none/tests/mips64/round.c b/none/tests/mips64/round.c index 4634057190..1894de14e6 100644 --- a/none/tests/mips64/round.c +++ b/none/tests/mips64/round.c @@ -2,6 +2,16 @@ #include "rounding_mode.h" #include "macro_fpu.h" +/* + * Bits 18 (NAN2008) and 19 (ABS2008) are preset by hardware and may differ + * between platforms. Hence a macro to clear them before printing FCSR + * values. + */ +#define FCSR_NAN2008 1 << 18 +#define FCSR_ABS2008 1 << 19 +#define FLAGS_RM_MASK 0xFFFFFFFF & ~(FCSR_ABS2008 | FCSR_NAN2008) +#define CLEAR_PRESETBITS_FCSR(fcsr) (fcsr & FLAGS_RM_MASK) + #if defined(__mips_hard_float) int directedRoundingMode(flt_dir_op_t op) { int fd_w = 0; @@ -14,82 +24,82 @@ int directedRoundingMode(flt_dir_op_t op) { case CEILWS: UNOPfw("ceil.w.s"); printf("%s %d %f\n", flt_dir_op_names[op], fd_w, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CEILWD: UNOPdw("ceil.w.d"); printf("%s %d %lf\n", flt_dir_op_names[op], fd_w, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case FLOORWS: UNOPfw("floor.w.s"); printf("%s %d %f\n", flt_dir_op_names[op], fd_w, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case FLOORWD: UNOPdw("floor.w.d"); printf("%s %d %lf\n", flt_dir_op_names[op], fd_w, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case ROUNDWS: UNOPfw("round.w.s"); printf("%s %d %f\n", flt_dir_op_names[op], fd_w, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case ROUNDWD: UNOPdw("round.w.d"); printf("%s %d %lf\n", flt_dir_op_names[op], fd_w, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case TRUNCWS: UNOPfw("trunc.w.s"); printf("%s %d %f\n", flt_dir_op_names[op], fd_w, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case TRUNCWD: UNOPdw("trunc.w.d"); printf("%s %d %lf\n", flt_dir_op_names[op], fd_w, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CEILLS: UNOPsl("ceil.l.s"); printf("%s %lld %f\n", flt_dir_op_names[op], fd_l, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CEILLD: UNOPdl("ceil.l.d"); printf("%s %lld %lf\n", flt_dir_op_names[op], fd_l, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case FLOORLS: UNOPsl("floor.l.s"); printf("%s %lld %f\n", flt_dir_op_names[op], fd_l, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case FLOORLD: UNOPdl("floor.l.d"); printf("%s %lld %lf\n", flt_dir_op_names[op], fd_l, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case ROUNDLS: UNOPsl("round.l.s"); printf("%s %lld %f\n", flt_dir_op_names[op], fd_l, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case ROUNDLD: UNOPdl("round.l.d"); printf("%s %lld %lf\n", flt_dir_op_names[op], fd_l, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case TRUNCLS: UNOPsl("trunc.l.s"); printf("%s %lld %f\n", flt_dir_op_names[op], fd_l, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case TRUNCLD: UNOPdl("trunc.l.d"); printf("%s %lld %lf\n", flt_dir_op_names[op], fd_l, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; default: printf("error\n"); @@ -118,52 +128,52 @@ int FCSRRoundingMode(flt_round_op_t op1) case CVTDS: UNOPfd("cvt.d.s"); printf("%s %lf %lf\n", flt_round_op_names[op1], fd_d, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CVTDW: UNOPwd("cvt.d.w"); printf("%s %lf %d\n", flt_round_op_names[op1], fd_d, fs_w[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CVTSD: UNOPdf("cvt.s.d"); printf("%s %f %lf\n", flt_round_op_names[op1], fd_f, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CVTSW: UNOPwf("cvt.s.w"); printf("%s %f %d\n", flt_round_op_names[op1], fd_f, fs_w[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CVTWS: UNOPfw("cvt.w.s"); printf("%s %d %f\n", flt_round_op_names[op1], fd_w, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CVTWD: UNOPdw("cvt.w.d"); printf("%s %d %lf\n", flt_round_op_names[op1], fd_w, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CVTDL: UNOPld("cvt.d.l"); printf("%s %lf %ld\n", flt_round_op_names[op1], fd_d, fs_l[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CVTLS: UNOPsl("cvt.l.s"); printf("%s %lld %f\n", flt_round_op_names[op1], fd_l, fs_f[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CVTLD: UNOPdl("cvt.l.d"); printf("%s %lld %lf\n", flt_round_op_names[op1], fd_l, fs_d[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; case CVTSL: UNOPls("cvt.s.l"); printf("%s %f %ld\n", flt_round_op_names[op1], fd_f, fs_l[i]); - printf("fcsr: 0x%x\n", fcsr); + printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr)); break; default: printf("error\n"); diff --git a/none/tests/mips64/test_fcsr.c b/none/tests/mips64/test_fcsr.c index 742bb83388..07e5e8c37c 100644 --- a/none/tests/mips64/test_fcsr.c +++ b/none/tests/mips64/test_fcsr.c @@ -1,5 +1,15 @@ #include +/* + * Bits 18 (NAN2008) and 19 (ABS2008) are preset by hardware and may differ + * between platforms. Hence a macro to clear them before printing FCSR + * values. + */ +#define FCSR_NAN2008 1 << 18 +#define FCSR_ABS2008 1 << 19 +#define FLAGS_RM_MASK 0xFFFFFFFF & ~(FCSR_ABS2008 | FCSR_NAN2008) +#define CLEAR_PRESETBITS_FCSR(fcsr) (fcsr & FLAGS_RM_MASK) + int main () { #if defined(__mips_hard_float) @@ -22,7 +32,8 @@ int main () : "r" (out) : "a1", "a2", "t0", "$f0" ); - printf("FCSR::1: 0x%lx, 2: 0x%lx\n", out[0], out[1]); + printf("FCSR::1: 0x%lx, 2: 0x%lx\n", CLEAR_PRESETBITS_FCSR(out[0]), + CLEAR_PRESETBITS_FCSR(out[1])); #endif return 0; }