#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,
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");
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");
#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,
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");
#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};
: "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
#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;
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");
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");
#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)
: "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;
}