FreeBSD: add file descriptor tracking for _umtx_op
[valgrind.git] / none / tests / mips64 / round.c
blob44be246b70fac899f3112e69d59a151506c65875
1 #include <stdio.h>
2 #include "rounding_mode.h"
3 #include "macro_fpu.h"
5 /*
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
8 * values.
9 */
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) {
17 int fd_w = 0;
18 long long int fd_l = 0;
19 int i;
20 int fcsr = 0;
21 for (i = 0; i < MAX_ARR; i++) {
22 clear_fcc();
23 switch(op) {
24 case CEILWS:
25 UNOPfw("ceil.w.s");
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));
28 break;
29 case CEILWD:
30 UNOPdw("ceil.w.d");
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));
33 break;
34 case FLOORWS:
35 UNOPfw("floor.w.s");
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));
38 break;
39 case FLOORWD:
40 UNOPdw("floor.w.d");
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));
43 break;
44 case ROUNDWS:
45 UNOPfw("round.w.s");
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));
48 break;
49 case ROUNDWD:
50 UNOPdw("round.w.d");
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));
53 break;
54 case TRUNCWS:
55 UNOPfw("trunc.w.s");
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));
58 break;
59 case TRUNCWD:
60 UNOPdw("trunc.w.d");
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));
63 break;
64 case CEILLS:
65 UNOPsl("ceil.l.s");
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));
68 break;
69 case CEILLD:
70 UNOPdl("ceil.l.d");
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));
73 break;
74 case FLOORLS:
75 UNOPsl("floor.l.s");
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));
78 break;
79 case FLOORLD:
80 UNOPdl("floor.l.d");
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));
83 break;
84 case ROUNDLS:
85 UNOPsl("round.l.s");
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));
88 break;
89 case ROUNDLD:
90 UNOPdl("round.l.d");
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));
93 break;
94 case TRUNCLS:
95 UNOPsl("trunc.l.s");
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));
98 break;
99 case TRUNCLD:
100 UNOPdl("trunc.l.d");
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));
103 break;
104 default:
105 printf("error\n");
106 break;
109 return 0;
112 int FCSRRoundingMode(flt_round_op_t op1)
114 double fd_d = 0;
115 float fd_f = 0;
116 int fd_w = 0;
117 long long int fd_l = 0;
118 int i;
119 int fcsr = 0;
120 round_mode_t rm;
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++) {
125 clear_fcc();
126 set_rounding_mode(rm);
127 switch(op1) {
128 case CVTDS:
129 UNOPfd("cvt.d.s");
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));
132 break;
133 case CVTDW:
134 UNOPwd("cvt.d.w");
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));
137 break;
138 case CVTSD:
139 UNOPdf("cvt.s.d");
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));
142 break;
143 case CVTSW:
144 UNOPwf("cvt.s.w");
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));
147 break;
148 case CVTWS:
149 UNOPfw("cvt.w.s");
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));
152 break;
153 case CVTWD:
154 UNOPdw("cvt.w.d");
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));
157 break;
158 case CVTDL:
159 UNOPld("cvt.d.l");
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));
162 break;
163 case CVTLS:
164 UNOPsl("cvt.l.s");
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));
167 break;
168 case CVTLD:
169 UNOPdl("cvt.l.d");
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));
172 break;
173 case CVTSL:
174 UNOPls("cvt.s.l");
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));
177 break;
178 default:
179 printf("error\n");
180 break;
184 return 0;
186 #endif
188 int main()
190 #if defined(__mips_hard_float)
191 flt_dir_op_t op;
192 flt_round_op_t op1;
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);
205 #endif
206 return 0;