2 #include "rounding_mode.h"
6 * Bits 18 (NAN2008) and 19 (ABS2008) are preset by hardware and may differ
7 * between platforms. Hence a macro to clear them before printing FCSR
10 #define FCSR_NAN2008 1 << 18
11 #define FCSR_ABS2008 1 << 19
12 #define FLAGS_RM_MASK 0xFFFFFFFF & ~(FCSR_ABS2008 | FCSR_NAN2008)
13 #define CLEAR_PRESETBITS_FCSR(fcsr) (fcsr & FLAGS_RM_MASK)
15 #if defined(__mips_hard_float)
16 int directedRoundingMode(flt_dir_op_t op
) {
18 long long int fd_l
= 0;
21 for (i
= 0; i
< MAX_ARR
; i
++) {
26 printf("%s %d %f\n", flt_dir_op_names
[op
], fd_w
, fs_f
[i
]);
27 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
31 printf("%s %d %lf\n", flt_dir_op_names
[op
], fd_w
, fs_d
[i
]);
32 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
36 printf("%s %d %f\n", flt_dir_op_names
[op
], fd_w
, fs_f
[i
]);
37 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
41 printf("%s %d %lf\n", flt_dir_op_names
[op
], fd_w
, fs_d
[i
]);
42 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
46 printf("%s %d %f\n", flt_dir_op_names
[op
], fd_w
, fs_f
[i
]);
47 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
51 printf("%s %d %lf\n", flt_dir_op_names
[op
], fd_w
, fs_d
[i
]);
52 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
56 printf("%s %d %f\n", flt_dir_op_names
[op
], fd_w
, fs_f
[i
]);
57 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
61 printf("%s %d %lf\n", flt_dir_op_names
[op
], fd_w
, fs_d
[i
]);
62 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
66 printf("%s %lld %f\n", flt_dir_op_names
[op
], fd_l
, fs_f
[i
]);
67 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
71 printf("%s %lld %lf\n", flt_dir_op_names
[op
], fd_l
, fs_d
[i
]);
72 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
76 printf("%s %lld %f\n", flt_dir_op_names
[op
], fd_l
, fs_f
[i
]);
77 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
81 printf("%s %lld %lf\n", flt_dir_op_names
[op
], fd_l
, fs_d
[i
]);
82 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
86 printf("%s %lld %f\n", flt_dir_op_names
[op
], fd_l
, fs_f
[i
]);
87 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
91 printf("%s %lld %lf\n", flt_dir_op_names
[op
], fd_l
, fs_d
[i
]);
92 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
96 printf("%s %lld %f\n", flt_dir_op_names
[op
], fd_l
, fs_f
[i
]);
97 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
101 printf("%s %lld %lf\n", flt_dir_op_names
[op
], fd_l
, fs_d
[i
]);
102 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
112 int FCSRRoundingMode(flt_round_op_t op1
)
117 long long int fd_l
= 0;
121 for (rm
= TO_NEAREST
; rm
<= TO_MINUS_INFINITY
; rm
++) {
122 set_rounding_mode(rm
);
123 printf("roundig mode: %s\n", round_mode_name
[rm
]);
124 for (i
= 0; i
< MAX_ARR
; i
++) {
126 set_rounding_mode(rm
);
130 printf("%s %lf %lf\n", flt_round_op_names
[op1
], fd_d
, fs_f
[i
]);
131 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
135 printf("%s %lf %d\n", flt_round_op_names
[op1
], fd_d
, fs_w
[i
]);
136 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
140 printf("%s %f %lf\n", flt_round_op_names
[op1
], fd_f
, fs_d
[i
]);
141 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
145 printf("%s %f %d\n", flt_round_op_names
[op1
], fd_f
, fs_w
[i
]);
146 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
150 printf("%s %d %f\n", flt_round_op_names
[op1
], fd_w
, fs_f
[i
]);
151 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
155 printf("%s %d %lf\n", flt_round_op_names
[op1
], fd_w
, fs_d
[i
]);
156 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
160 printf("%s %lf %lld\n", flt_round_op_names
[op1
], fd_d
, fs_l
[i
]);
161 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
165 printf("%s %lld %f\n", flt_round_op_names
[op1
], fd_l
, fs_f
[i
]);
166 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
170 printf("%s %lld %lf\n", flt_round_op_names
[op1
], fd_l
, fs_d
[i
]);
171 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
175 printf("%s %f %lld\n", flt_round_op_names
[op1
], fd_f
, fs_l
[i
]);
176 printf("fcsr: 0x%x\n", CLEAR_PRESETBITS_FCSR(fcsr
));
190 #if defined(__mips_hard_float)
194 printf("-------------------------- %s --------------------------\n",
195 "test FPU Conversion Operations Using a Directed Rounding Mode");
196 for (op
= CEILWS
; op
<= TRUNCLS
; op
++) {
197 directedRoundingMode(op
);
200 printf("-------------------------- %s --------------------------\n",
201 "test FPU Conversion Operations Using the FCSR Rounding Mode");
202 for (op1
= CVTDS
; op1
<= CVTSL
; op1
++) {
203 FCSRRoundingMode(op1
);