]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
mips: finetune tests that print FCSR
authorPetar Jovanovic <mips32r2@gmail.com>
Fri, 3 Nov 2017 18:10:04 +0000 (19:10 +0100)
committerPetar Jovanovic <mips32r2@gmail.com>
Fri, 3 Nov 2017 18:11:36 +0000 (19:11 +0100)
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.

none/tests/mips32/round.c
none/tests/mips32/round_fpu64.c
none/tests/mips32/test_fcsr.c
none/tests/mips64/round.c
none/tests/mips64/test_fcsr.c

index feba1685561e98e99f58926c66d31e4088c2cc19..052508da39107be969b89a396a31b1c8ebe816de 100644 (file)
@@ -2,6 +2,16 @@
 
 #include <stdio.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)
+
 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");
index e35c8b5a81f963e4b064a458869ee3614c32409b..970dd05b0d294e0c1a3ed8c416d9325f112e335e 100644 (file)
@@ -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");
index 6bb03a0a42faa38d91951c48947a64ebdb8fa251..c422482cbd8832a5848466317788103e66856e65 100644 (file)
@@ -2,6 +2,16 @@
 
 #include <stdio.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)
+
 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
index 463405719057ec9ee54803066d82339da17afd70..1894de14e6db32c19bccfe7547fbd0d7bdd97394 100644 (file)
@@ -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");
index 742bb833885c6bdc2fc2f068e983e5f10ab526cb..07e5e8c37c82fe92ab166e0795aea5c632731df1 100644 (file)
@@ -1,5 +1,15 @@
 #include <stdio.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)
+
 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;
 }