]> git.proxmox.com Git - mirror_qemu.git/blob - target/mips/fpu_helper.c
target/mips: fpu: Demacro ADD.<D|S|PS>
[mirror_qemu.git] / target / mips / fpu_helper.c
1 /*
2 * Helpers for emulation of FPU-related MIPS instructions.
3 *
4 * Copyright (C) 2004-2005 Jocelyn Mayer
5 * Copyright (C) 2020 Wave Computing, Inc.
6 * Copyright (C) 2020 Aleksandar Markovic <amarkovic@wavecomp.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23 #include "qemu/osdep.h"
24 #include "qemu/main-loop.h"
25 #include "cpu.h"
26 #include "internal.h"
27 #include "qemu/host-utils.h"
28 #include "exec/helper-proto.h"
29 #include "exec/exec-all.h"
30 #include "exec/cpu_ldst.h"
31 #include "exec/memop.h"
32 #include "sysemu/kvm.h"
33 #include "fpu/softfloat.h"
34
35
36 /* Complex FPU operations which may need stack space. */
37
38 #define FLOAT_TWO32 make_float32(1 << 30)
39 #define FLOAT_TWO64 make_float64(1ULL << 62)
40
41 #define FP_TO_INT32_OVERFLOW 0x7fffffff
42 #define FP_TO_INT64_OVERFLOW 0x7fffffffffffffffULL
43
44 /* convert MIPS rounding mode in FCR31 to IEEE library */
45 unsigned int ieee_rm[] = {
46 float_round_nearest_even,
47 float_round_to_zero,
48 float_round_up,
49 float_round_down
50 };
51
52 target_ulong helper_cfc1(CPUMIPSState *env, uint32_t reg)
53 {
54 target_ulong arg1 = 0;
55
56 switch (reg) {
57 case 0:
58 arg1 = (int32_t)env->active_fpu.fcr0;
59 break;
60 case 1:
61 /* UFR Support - Read Status FR */
62 if (env->active_fpu.fcr0 & (1 << FCR0_UFRP)) {
63 if (env->CP0_Config5 & (1 << CP0C5_UFR)) {
64 arg1 = (int32_t)
65 ((env->CP0_Status & (1 << CP0St_FR)) >> CP0St_FR);
66 } else {
67 do_raise_exception(env, EXCP_RI, GETPC());
68 }
69 }
70 break;
71 case 5:
72 /* FRE Support - read Config5.FRE bit */
73 if (env->active_fpu.fcr0 & (1 << FCR0_FREP)) {
74 if (env->CP0_Config5 & (1 << CP0C5_UFE)) {
75 arg1 = (env->CP0_Config5 >> CP0C5_FRE) & 1;
76 } else {
77 helper_raise_exception(env, EXCP_RI);
78 }
79 }
80 break;
81 case 25:
82 arg1 = ((env->active_fpu.fcr31 >> 24) & 0xfe) |
83 ((env->active_fpu.fcr31 >> 23) & 0x1);
84 break;
85 case 26:
86 arg1 = env->active_fpu.fcr31 & 0x0003f07c;
87 break;
88 case 28:
89 arg1 = (env->active_fpu.fcr31 & 0x00000f83) |
90 ((env->active_fpu.fcr31 >> 22) & 0x4);
91 break;
92 default:
93 arg1 = (int32_t)env->active_fpu.fcr31;
94 break;
95 }
96
97 return arg1;
98 }
99
100 void helper_ctc1(CPUMIPSState *env, target_ulong arg1, uint32_t fs, uint32_t rt)
101 {
102 switch (fs) {
103 case 1:
104 /* UFR Alias - Reset Status FR */
105 if (!((env->active_fpu.fcr0 & (1 << FCR0_UFRP)) && (rt == 0))) {
106 return;
107 }
108 if (env->CP0_Config5 & (1 << CP0C5_UFR)) {
109 env->CP0_Status &= ~(1 << CP0St_FR);
110 compute_hflags(env);
111 } else {
112 do_raise_exception(env, EXCP_RI, GETPC());
113 }
114 break;
115 case 4:
116 /* UNFR Alias - Set Status FR */
117 if (!((env->active_fpu.fcr0 & (1 << FCR0_UFRP)) && (rt == 0))) {
118 return;
119 }
120 if (env->CP0_Config5 & (1 << CP0C5_UFR)) {
121 env->CP0_Status |= (1 << CP0St_FR);
122 compute_hflags(env);
123 } else {
124 do_raise_exception(env, EXCP_RI, GETPC());
125 }
126 break;
127 case 5:
128 /* FRE Support - clear Config5.FRE bit */
129 if (!((env->active_fpu.fcr0 & (1 << FCR0_FREP)) && (rt == 0))) {
130 return;
131 }
132 if (env->CP0_Config5 & (1 << CP0C5_UFE)) {
133 env->CP0_Config5 &= ~(1 << CP0C5_FRE);
134 compute_hflags(env);
135 } else {
136 helper_raise_exception(env, EXCP_RI);
137 }
138 break;
139 case 6:
140 /* FRE Support - set Config5.FRE bit */
141 if (!((env->active_fpu.fcr0 & (1 << FCR0_FREP)) && (rt == 0))) {
142 return;
143 }
144 if (env->CP0_Config5 & (1 << CP0C5_UFE)) {
145 env->CP0_Config5 |= (1 << CP0C5_FRE);
146 compute_hflags(env);
147 } else {
148 helper_raise_exception(env, EXCP_RI);
149 }
150 break;
151 case 25:
152 if ((env->insn_flags & ISA_MIPS32R6) || (arg1 & 0xffffff00)) {
153 return;
154 }
155 env->active_fpu.fcr31 = (env->active_fpu.fcr31 & 0x017fffff) |
156 ((arg1 & 0xfe) << 24) |
157 ((arg1 & 0x1) << 23);
158 break;
159 case 26:
160 if (arg1 & 0x007c0000) {
161 return;
162 }
163 env->active_fpu.fcr31 = (env->active_fpu.fcr31 & 0xfffc0f83) |
164 (arg1 & 0x0003f07c);
165 break;
166 case 28:
167 if (arg1 & 0x007c0000) {
168 return;
169 }
170 env->active_fpu.fcr31 = (env->active_fpu.fcr31 & 0xfefff07c) |
171 (arg1 & 0x00000f83) |
172 ((arg1 & 0x4) << 22);
173 break;
174 case 31:
175 env->active_fpu.fcr31 = (arg1 & env->active_fpu.fcr31_rw_bitmask) |
176 (env->active_fpu.fcr31 & ~(env->active_fpu.fcr31_rw_bitmask));
177 break;
178 default:
179 if (env->insn_flags & ISA_MIPS32R6) {
180 do_raise_exception(env, EXCP_RI, GETPC());
181 }
182 return;
183 }
184 restore_fp_status(env);
185 set_float_exception_flags(0, &env->active_fpu.fp_status);
186 if ((GET_FP_ENABLE(env->active_fpu.fcr31) | 0x20) &
187 GET_FP_CAUSE(env->active_fpu.fcr31)) {
188 do_raise_exception(env, EXCP_FPE, GETPC());
189 }
190 }
191
192 int ieee_ex_to_mips(int xcpt)
193 {
194 int ret = 0;
195 if (xcpt) {
196 if (xcpt & float_flag_invalid) {
197 ret |= FP_INVALID;
198 }
199 if (xcpt & float_flag_overflow) {
200 ret |= FP_OVERFLOW;
201 }
202 if (xcpt & float_flag_underflow) {
203 ret |= FP_UNDERFLOW;
204 }
205 if (xcpt & float_flag_divbyzero) {
206 ret |= FP_DIV0;
207 }
208 if (xcpt & float_flag_inexact) {
209 ret |= FP_INEXACT;
210 }
211 }
212 return ret;
213 }
214
215 static inline void update_fcr31(CPUMIPSState *env, uintptr_t pc)
216 {
217 int tmp = ieee_ex_to_mips(get_float_exception_flags(
218 &env->active_fpu.fp_status));
219
220 SET_FP_CAUSE(env->active_fpu.fcr31, tmp);
221
222 if (tmp) {
223 set_float_exception_flags(0, &env->active_fpu.fp_status);
224
225 if (GET_FP_ENABLE(env->active_fpu.fcr31) & tmp) {
226 do_raise_exception(env, EXCP_FPE, pc);
227 } else {
228 UPDATE_FP_FLAGS(env->active_fpu.fcr31, tmp);
229 }
230 }
231 }
232
233 /*
234 * Float support.
235 * Single precition routines have a "s" suffix, double precision a
236 * "d" suffix, 32bit integer "w", 64bit integer "l", paired single "ps",
237 * paired single lower "pl", paired single upper "pu".
238 */
239
240 /* unary operations, modifying fp status */
241 uint64_t helper_float_sqrt_d(CPUMIPSState *env, uint64_t fdt0)
242 {
243 fdt0 = float64_sqrt(fdt0, &env->active_fpu.fp_status);
244 update_fcr31(env, GETPC());
245 return fdt0;
246 }
247
248 uint32_t helper_float_sqrt_s(CPUMIPSState *env, uint32_t fst0)
249 {
250 fst0 = float32_sqrt(fst0, &env->active_fpu.fp_status);
251 update_fcr31(env, GETPC());
252 return fst0;
253 }
254
255 uint64_t helper_float_cvtd_s(CPUMIPSState *env, uint32_t fst0)
256 {
257 uint64_t fdt2;
258
259 fdt2 = float32_to_float64(fst0, &env->active_fpu.fp_status);
260 update_fcr31(env, GETPC());
261 return fdt2;
262 }
263
264 uint64_t helper_float_cvtd_w(CPUMIPSState *env, uint32_t wt0)
265 {
266 uint64_t fdt2;
267
268 fdt2 = int32_to_float64(wt0, &env->active_fpu.fp_status);
269 update_fcr31(env, GETPC());
270 return fdt2;
271 }
272
273 uint64_t helper_float_cvtd_l(CPUMIPSState *env, uint64_t dt0)
274 {
275 uint64_t fdt2;
276
277 fdt2 = int64_to_float64(dt0, &env->active_fpu.fp_status);
278 update_fcr31(env, GETPC());
279 return fdt2;
280 }
281
282 uint64_t helper_float_cvt_l_d(CPUMIPSState *env, uint64_t fdt0)
283 {
284 uint64_t dt2;
285
286 dt2 = float64_to_int64(fdt0, &env->active_fpu.fp_status);
287 if (get_float_exception_flags(&env->active_fpu.fp_status)
288 & (float_flag_invalid | float_flag_overflow)) {
289 dt2 = FP_TO_INT64_OVERFLOW;
290 }
291 update_fcr31(env, GETPC());
292 return dt2;
293 }
294
295 uint64_t helper_float_cvt_l_s(CPUMIPSState *env, uint32_t fst0)
296 {
297 uint64_t dt2;
298
299 dt2 = float32_to_int64(fst0, &env->active_fpu.fp_status);
300 if (get_float_exception_flags(&env->active_fpu.fp_status)
301 & (float_flag_invalid | float_flag_overflow)) {
302 dt2 = FP_TO_INT64_OVERFLOW;
303 }
304 update_fcr31(env, GETPC());
305 return dt2;
306 }
307
308 uint64_t helper_float_cvtps_pw(CPUMIPSState *env, uint64_t dt0)
309 {
310 uint32_t fst2;
311 uint32_t fsth2;
312
313 fst2 = int32_to_float32(dt0 & 0XFFFFFFFF, &env->active_fpu.fp_status);
314 fsth2 = int32_to_float32(dt0 >> 32, &env->active_fpu.fp_status);
315 update_fcr31(env, GETPC());
316 return ((uint64_t)fsth2 << 32) | fst2;
317 }
318
319 uint64_t helper_float_cvtpw_ps(CPUMIPSState *env, uint64_t fdt0)
320 {
321 uint32_t wt2;
322 uint32_t wth2;
323 int excp, excph;
324
325 wt2 = float32_to_int32(fdt0 & 0XFFFFFFFF, &env->active_fpu.fp_status);
326 excp = get_float_exception_flags(&env->active_fpu.fp_status);
327 if (excp & (float_flag_overflow | float_flag_invalid)) {
328 wt2 = FP_TO_INT32_OVERFLOW;
329 }
330
331 set_float_exception_flags(0, &env->active_fpu.fp_status);
332 wth2 = float32_to_int32(fdt0 >> 32, &env->active_fpu.fp_status);
333 excph = get_float_exception_flags(&env->active_fpu.fp_status);
334 if (excph & (float_flag_overflow | float_flag_invalid)) {
335 wth2 = FP_TO_INT32_OVERFLOW;
336 }
337
338 set_float_exception_flags(excp | excph, &env->active_fpu.fp_status);
339 update_fcr31(env, GETPC());
340
341 return ((uint64_t)wth2 << 32) | wt2;
342 }
343
344 uint32_t helper_float_cvts_d(CPUMIPSState *env, uint64_t fdt0)
345 {
346 uint32_t fst2;
347
348 fst2 = float64_to_float32(fdt0, &env->active_fpu.fp_status);
349 update_fcr31(env, GETPC());
350 return fst2;
351 }
352
353 uint32_t helper_float_cvts_w(CPUMIPSState *env, uint32_t wt0)
354 {
355 uint32_t fst2;
356
357 fst2 = int32_to_float32(wt0, &env->active_fpu.fp_status);
358 update_fcr31(env, GETPC());
359 return fst2;
360 }
361
362 uint32_t helper_float_cvts_l(CPUMIPSState *env, uint64_t dt0)
363 {
364 uint32_t fst2;
365
366 fst2 = int64_to_float32(dt0, &env->active_fpu.fp_status);
367 update_fcr31(env, GETPC());
368 return fst2;
369 }
370
371 uint32_t helper_float_cvts_pl(CPUMIPSState *env, uint32_t wt0)
372 {
373 uint32_t wt2;
374
375 wt2 = wt0;
376 update_fcr31(env, GETPC());
377 return wt2;
378 }
379
380 uint32_t helper_float_cvts_pu(CPUMIPSState *env, uint32_t wth0)
381 {
382 uint32_t wt2;
383
384 wt2 = wth0;
385 update_fcr31(env, GETPC());
386 return wt2;
387 }
388
389 uint32_t helper_float_cvt_w_s(CPUMIPSState *env, uint32_t fst0)
390 {
391 uint32_t wt2;
392
393 wt2 = float32_to_int32(fst0, &env->active_fpu.fp_status);
394 if (get_float_exception_flags(&env->active_fpu.fp_status)
395 & (float_flag_invalid | float_flag_overflow)) {
396 wt2 = FP_TO_INT32_OVERFLOW;
397 }
398 update_fcr31(env, GETPC());
399 return wt2;
400 }
401
402 uint32_t helper_float_cvt_w_d(CPUMIPSState *env, uint64_t fdt0)
403 {
404 uint32_t wt2;
405
406 wt2 = float64_to_int32(fdt0, &env->active_fpu.fp_status);
407 if (get_float_exception_flags(&env->active_fpu.fp_status)
408 & (float_flag_invalid | float_flag_overflow)) {
409 wt2 = FP_TO_INT32_OVERFLOW;
410 }
411 update_fcr31(env, GETPC());
412 return wt2;
413 }
414
415 uint64_t helper_float_round_l_d(CPUMIPSState *env, uint64_t fdt0)
416 {
417 uint64_t dt2;
418
419 set_float_rounding_mode(float_round_nearest_even,
420 &env->active_fpu.fp_status);
421 dt2 = float64_to_int64(fdt0, &env->active_fpu.fp_status);
422 restore_rounding_mode(env);
423 if (get_float_exception_flags(&env->active_fpu.fp_status)
424 & (float_flag_invalid | float_flag_overflow)) {
425 dt2 = FP_TO_INT64_OVERFLOW;
426 }
427 update_fcr31(env, GETPC());
428 return dt2;
429 }
430
431 uint64_t helper_float_round_l_s(CPUMIPSState *env, uint32_t fst0)
432 {
433 uint64_t dt2;
434
435 set_float_rounding_mode(float_round_nearest_even,
436 &env->active_fpu.fp_status);
437 dt2 = float32_to_int64(fst0, &env->active_fpu.fp_status);
438 restore_rounding_mode(env);
439 if (get_float_exception_flags(&env->active_fpu.fp_status)
440 & (float_flag_invalid | float_flag_overflow)) {
441 dt2 = FP_TO_INT64_OVERFLOW;
442 }
443 update_fcr31(env, GETPC());
444 return dt2;
445 }
446
447 uint32_t helper_float_round_w_d(CPUMIPSState *env, uint64_t fdt0)
448 {
449 uint32_t wt2;
450
451 set_float_rounding_mode(float_round_nearest_even,
452 &env->active_fpu.fp_status);
453 wt2 = float64_to_int32(fdt0, &env->active_fpu.fp_status);
454 restore_rounding_mode(env);
455 if (get_float_exception_flags(&env->active_fpu.fp_status)
456 & (float_flag_invalid | float_flag_overflow)) {
457 wt2 = FP_TO_INT32_OVERFLOW;
458 }
459 update_fcr31(env, GETPC());
460 return wt2;
461 }
462
463 uint32_t helper_float_round_w_s(CPUMIPSState *env, uint32_t fst0)
464 {
465 uint32_t wt2;
466
467 set_float_rounding_mode(float_round_nearest_even,
468 &env->active_fpu.fp_status);
469 wt2 = float32_to_int32(fst0, &env->active_fpu.fp_status);
470 restore_rounding_mode(env);
471 if (get_float_exception_flags(&env->active_fpu.fp_status)
472 & (float_flag_invalid | float_flag_overflow)) {
473 wt2 = FP_TO_INT32_OVERFLOW;
474 }
475 update_fcr31(env, GETPC());
476 return wt2;
477 }
478
479 uint64_t helper_float_trunc_l_d(CPUMIPSState *env, uint64_t fdt0)
480 {
481 uint64_t dt2;
482
483 dt2 = float64_to_int64_round_to_zero(fdt0,
484 &env->active_fpu.fp_status);
485 if (get_float_exception_flags(&env->active_fpu.fp_status)
486 & (float_flag_invalid | float_flag_overflow)) {
487 dt2 = FP_TO_INT64_OVERFLOW;
488 }
489 update_fcr31(env, GETPC());
490 return dt2;
491 }
492
493 uint64_t helper_float_trunc_l_s(CPUMIPSState *env, uint32_t fst0)
494 {
495 uint64_t dt2;
496
497 dt2 = float32_to_int64_round_to_zero(fst0, &env->active_fpu.fp_status);
498 if (get_float_exception_flags(&env->active_fpu.fp_status)
499 & (float_flag_invalid | float_flag_overflow)) {
500 dt2 = FP_TO_INT64_OVERFLOW;
501 }
502 update_fcr31(env, GETPC());
503 return dt2;
504 }
505
506 uint32_t helper_float_trunc_w_d(CPUMIPSState *env, uint64_t fdt0)
507 {
508 uint32_t wt2;
509
510 wt2 = float64_to_int32_round_to_zero(fdt0, &env->active_fpu.fp_status);
511 if (get_float_exception_flags(&env->active_fpu.fp_status)
512 & (float_flag_invalid | float_flag_overflow)) {
513 wt2 = FP_TO_INT32_OVERFLOW;
514 }
515 update_fcr31(env, GETPC());
516 return wt2;
517 }
518
519 uint32_t helper_float_trunc_w_s(CPUMIPSState *env, uint32_t fst0)
520 {
521 uint32_t wt2;
522
523 wt2 = float32_to_int32_round_to_zero(fst0, &env->active_fpu.fp_status);
524 if (get_float_exception_flags(&env->active_fpu.fp_status)
525 & (float_flag_invalid | float_flag_overflow)) {
526 wt2 = FP_TO_INT32_OVERFLOW;
527 }
528 update_fcr31(env, GETPC());
529 return wt2;
530 }
531
532 uint64_t helper_float_ceil_l_d(CPUMIPSState *env, uint64_t fdt0)
533 {
534 uint64_t dt2;
535
536 set_float_rounding_mode(float_round_up, &env->active_fpu.fp_status);
537 dt2 = float64_to_int64(fdt0, &env->active_fpu.fp_status);
538 restore_rounding_mode(env);
539 if (get_float_exception_flags(&env->active_fpu.fp_status)
540 & (float_flag_invalid | float_flag_overflow)) {
541 dt2 = FP_TO_INT64_OVERFLOW;
542 }
543 update_fcr31(env, GETPC());
544 return dt2;
545 }
546
547 uint64_t helper_float_ceil_l_s(CPUMIPSState *env, uint32_t fst0)
548 {
549 uint64_t dt2;
550
551 set_float_rounding_mode(float_round_up, &env->active_fpu.fp_status);
552 dt2 = float32_to_int64(fst0, &env->active_fpu.fp_status);
553 restore_rounding_mode(env);
554 if (get_float_exception_flags(&env->active_fpu.fp_status)
555 & (float_flag_invalid | float_flag_overflow)) {
556 dt2 = FP_TO_INT64_OVERFLOW;
557 }
558 update_fcr31(env, GETPC());
559 return dt2;
560 }
561
562 uint32_t helper_float_ceil_w_d(CPUMIPSState *env, uint64_t fdt0)
563 {
564 uint32_t wt2;
565
566 set_float_rounding_mode(float_round_up, &env->active_fpu.fp_status);
567 wt2 = float64_to_int32(fdt0, &env->active_fpu.fp_status);
568 restore_rounding_mode(env);
569 if (get_float_exception_flags(&env->active_fpu.fp_status)
570 & (float_flag_invalid | float_flag_overflow)) {
571 wt2 = FP_TO_INT32_OVERFLOW;
572 }
573 update_fcr31(env, GETPC());
574 return wt2;
575 }
576
577 uint32_t helper_float_ceil_w_s(CPUMIPSState *env, uint32_t fst0)
578 {
579 uint32_t wt2;
580
581 set_float_rounding_mode(float_round_up, &env->active_fpu.fp_status);
582 wt2 = float32_to_int32(fst0, &env->active_fpu.fp_status);
583 restore_rounding_mode(env);
584 if (get_float_exception_flags(&env->active_fpu.fp_status)
585 & (float_flag_invalid | float_flag_overflow)) {
586 wt2 = FP_TO_INT32_OVERFLOW;
587 }
588 update_fcr31(env, GETPC());
589 return wt2;
590 }
591
592 uint64_t helper_float_floor_l_d(CPUMIPSState *env, uint64_t fdt0)
593 {
594 uint64_t dt2;
595
596 set_float_rounding_mode(float_round_down, &env->active_fpu.fp_status);
597 dt2 = float64_to_int64(fdt0, &env->active_fpu.fp_status);
598 restore_rounding_mode(env);
599 if (get_float_exception_flags(&env->active_fpu.fp_status)
600 & (float_flag_invalid | float_flag_overflow)) {
601 dt2 = FP_TO_INT64_OVERFLOW;
602 }
603 update_fcr31(env, GETPC());
604 return dt2;
605 }
606
607 uint64_t helper_float_floor_l_s(CPUMIPSState *env, uint32_t fst0)
608 {
609 uint64_t dt2;
610
611 set_float_rounding_mode(float_round_down, &env->active_fpu.fp_status);
612 dt2 = float32_to_int64(fst0, &env->active_fpu.fp_status);
613 restore_rounding_mode(env);
614 if (get_float_exception_flags(&env->active_fpu.fp_status)
615 & (float_flag_invalid | float_flag_overflow)) {
616 dt2 = FP_TO_INT64_OVERFLOW;
617 }
618 update_fcr31(env, GETPC());
619 return dt2;
620 }
621
622 uint32_t helper_float_floor_w_d(CPUMIPSState *env, uint64_t fdt0)
623 {
624 uint32_t wt2;
625
626 set_float_rounding_mode(float_round_down, &env->active_fpu.fp_status);
627 wt2 = float64_to_int32(fdt0, &env->active_fpu.fp_status);
628 restore_rounding_mode(env);
629 if (get_float_exception_flags(&env->active_fpu.fp_status)
630 & (float_flag_invalid | float_flag_overflow)) {
631 wt2 = FP_TO_INT32_OVERFLOW;
632 }
633 update_fcr31(env, GETPC());
634 return wt2;
635 }
636
637 uint32_t helper_float_floor_w_s(CPUMIPSState *env, uint32_t fst0)
638 {
639 uint32_t wt2;
640
641 set_float_rounding_mode(float_round_down, &env->active_fpu.fp_status);
642 wt2 = float32_to_int32(fst0, &env->active_fpu.fp_status);
643 restore_rounding_mode(env);
644 if (get_float_exception_flags(&env->active_fpu.fp_status)
645 & (float_flag_invalid | float_flag_overflow)) {
646 wt2 = FP_TO_INT32_OVERFLOW;
647 }
648 update_fcr31(env, GETPC());
649 return wt2;
650 }
651
652 uint64_t helper_float_cvt_2008_l_d(CPUMIPSState *env, uint64_t fdt0)
653 {
654 uint64_t dt2;
655
656 dt2 = float64_to_int64(fdt0, &env->active_fpu.fp_status);
657 if (get_float_exception_flags(&env->active_fpu.fp_status)
658 & float_flag_invalid) {
659 if (float64_is_any_nan(fdt0)) {
660 dt2 = 0;
661 }
662 }
663 update_fcr31(env, GETPC());
664 return dt2;
665 }
666
667 uint64_t helper_float_cvt_2008_l_s(CPUMIPSState *env, uint32_t fst0)
668 {
669 uint64_t dt2;
670
671 dt2 = float32_to_int64(fst0, &env->active_fpu.fp_status);
672 if (get_float_exception_flags(&env->active_fpu.fp_status)
673 & float_flag_invalid) {
674 if (float32_is_any_nan(fst0)) {
675 dt2 = 0;
676 }
677 }
678 update_fcr31(env, GETPC());
679 return dt2;
680 }
681
682 uint32_t helper_float_cvt_2008_w_d(CPUMIPSState *env, uint64_t fdt0)
683 {
684 uint32_t wt2;
685
686 wt2 = float64_to_int32(fdt0, &env->active_fpu.fp_status);
687 if (get_float_exception_flags(&env->active_fpu.fp_status)
688 & float_flag_invalid) {
689 if (float64_is_any_nan(fdt0)) {
690 wt2 = 0;
691 }
692 }
693 update_fcr31(env, GETPC());
694 return wt2;
695 }
696
697 uint32_t helper_float_cvt_2008_w_s(CPUMIPSState *env, uint32_t fst0)
698 {
699 uint32_t wt2;
700
701 wt2 = float32_to_int32(fst0, &env->active_fpu.fp_status);
702 if (get_float_exception_flags(&env->active_fpu.fp_status)
703 & float_flag_invalid) {
704 if (float32_is_any_nan(fst0)) {
705 wt2 = 0;
706 }
707 }
708 update_fcr31(env, GETPC());
709 return wt2;
710 }
711
712 uint64_t helper_float_round_2008_l_d(CPUMIPSState *env, uint64_t fdt0)
713 {
714 uint64_t dt2;
715
716 set_float_rounding_mode(float_round_nearest_even,
717 &env->active_fpu.fp_status);
718 dt2 = float64_to_int64(fdt0, &env->active_fpu.fp_status);
719 restore_rounding_mode(env);
720 if (get_float_exception_flags(&env->active_fpu.fp_status)
721 & float_flag_invalid) {
722 if (float64_is_any_nan(fdt0)) {
723 dt2 = 0;
724 }
725 }
726 update_fcr31(env, GETPC());
727 return dt2;
728 }
729
730 uint64_t helper_float_round_2008_l_s(CPUMIPSState *env, uint32_t fst0)
731 {
732 uint64_t dt2;
733
734 set_float_rounding_mode(float_round_nearest_even,
735 &env->active_fpu.fp_status);
736 dt2 = float32_to_int64(fst0, &env->active_fpu.fp_status);
737 restore_rounding_mode(env);
738 if (get_float_exception_flags(&env->active_fpu.fp_status)
739 & float_flag_invalid) {
740 if (float32_is_any_nan(fst0)) {
741 dt2 = 0;
742 }
743 }
744 update_fcr31(env, GETPC());
745 return dt2;
746 }
747
748 uint32_t helper_float_round_2008_w_d(CPUMIPSState *env, uint64_t fdt0)
749 {
750 uint32_t wt2;
751
752 set_float_rounding_mode(float_round_nearest_even,
753 &env->active_fpu.fp_status);
754 wt2 = float64_to_int32(fdt0, &env->active_fpu.fp_status);
755 restore_rounding_mode(env);
756 if (get_float_exception_flags(&env->active_fpu.fp_status)
757 & float_flag_invalid) {
758 if (float64_is_any_nan(fdt0)) {
759 wt2 = 0;
760 }
761 }
762 update_fcr31(env, GETPC());
763 return wt2;
764 }
765
766 uint32_t helper_float_round_2008_w_s(CPUMIPSState *env, uint32_t fst0)
767 {
768 uint32_t wt2;
769
770 set_float_rounding_mode(float_round_nearest_even,
771 &env->active_fpu.fp_status);
772 wt2 = float32_to_int32(fst0, &env->active_fpu.fp_status);
773 restore_rounding_mode(env);
774 if (get_float_exception_flags(&env->active_fpu.fp_status)
775 & float_flag_invalid) {
776 if (float32_is_any_nan(fst0)) {
777 wt2 = 0;
778 }
779 }
780 update_fcr31(env, GETPC());
781 return wt2;
782 }
783
784 uint64_t helper_float_trunc_2008_l_d(CPUMIPSState *env, uint64_t fdt0)
785 {
786 uint64_t dt2;
787
788 dt2 = float64_to_int64_round_to_zero(fdt0, &env->active_fpu.fp_status);
789 if (get_float_exception_flags(&env->active_fpu.fp_status)
790 & float_flag_invalid) {
791 if (float64_is_any_nan(fdt0)) {
792 dt2 = 0;
793 }
794 }
795 update_fcr31(env, GETPC());
796 return dt2;
797 }
798
799 uint64_t helper_float_trunc_2008_l_s(CPUMIPSState *env, uint32_t fst0)
800 {
801 uint64_t dt2;
802
803 dt2 = float32_to_int64_round_to_zero(fst0, &env->active_fpu.fp_status);
804 if (get_float_exception_flags(&env->active_fpu.fp_status)
805 & float_flag_invalid) {
806 if (float32_is_any_nan(fst0)) {
807 dt2 = 0;
808 }
809 }
810 update_fcr31(env, GETPC());
811 return dt2;
812 }
813
814 uint32_t helper_float_trunc_2008_w_d(CPUMIPSState *env, uint64_t fdt0)
815 {
816 uint32_t wt2;
817
818 wt2 = float64_to_int32_round_to_zero(fdt0, &env->active_fpu.fp_status);
819 if (get_float_exception_flags(&env->active_fpu.fp_status)
820 & float_flag_invalid) {
821 if (float64_is_any_nan(fdt0)) {
822 wt2 = 0;
823 }
824 }
825 update_fcr31(env, GETPC());
826 return wt2;
827 }
828
829 uint32_t helper_float_trunc_2008_w_s(CPUMIPSState *env, uint32_t fst0)
830 {
831 uint32_t wt2;
832
833 wt2 = float32_to_int32_round_to_zero(fst0, &env->active_fpu.fp_status);
834 if (get_float_exception_flags(&env->active_fpu.fp_status)
835 & float_flag_invalid) {
836 if (float32_is_any_nan(fst0)) {
837 wt2 = 0;
838 }
839 }
840 update_fcr31(env, GETPC());
841 return wt2;
842 }
843
844 uint64_t helper_float_ceil_2008_l_d(CPUMIPSState *env, uint64_t fdt0)
845 {
846 uint64_t dt2;
847
848 set_float_rounding_mode(float_round_up, &env->active_fpu.fp_status);
849 dt2 = float64_to_int64(fdt0, &env->active_fpu.fp_status);
850 restore_rounding_mode(env);
851 if (get_float_exception_flags(&env->active_fpu.fp_status)
852 & float_flag_invalid) {
853 if (float64_is_any_nan(fdt0)) {
854 dt2 = 0;
855 }
856 }
857 update_fcr31(env, GETPC());
858 return dt2;
859 }
860
861 uint64_t helper_float_ceil_2008_l_s(CPUMIPSState *env, uint32_t fst0)
862 {
863 uint64_t dt2;
864
865 set_float_rounding_mode(float_round_up, &env->active_fpu.fp_status);
866 dt2 = float32_to_int64(fst0, &env->active_fpu.fp_status);
867 restore_rounding_mode(env);
868 if (get_float_exception_flags(&env->active_fpu.fp_status)
869 & float_flag_invalid) {
870 if (float32_is_any_nan(fst0)) {
871 dt2 = 0;
872 }
873 }
874 update_fcr31(env, GETPC());
875 return dt2;
876 }
877
878 uint32_t helper_float_ceil_2008_w_d(CPUMIPSState *env, uint64_t fdt0)
879 {
880 uint32_t wt2;
881
882 set_float_rounding_mode(float_round_up, &env->active_fpu.fp_status);
883 wt2 = float64_to_int32(fdt0, &env->active_fpu.fp_status);
884 restore_rounding_mode(env);
885 if (get_float_exception_flags(&env->active_fpu.fp_status)
886 & float_flag_invalid) {
887 if (float64_is_any_nan(fdt0)) {
888 wt2 = 0;
889 }
890 }
891 update_fcr31(env, GETPC());
892 return wt2;
893 }
894
895 uint32_t helper_float_ceil_2008_w_s(CPUMIPSState *env, uint32_t fst0)
896 {
897 uint32_t wt2;
898
899 set_float_rounding_mode(float_round_up, &env->active_fpu.fp_status);
900 wt2 = float32_to_int32(fst0, &env->active_fpu.fp_status);
901 restore_rounding_mode(env);
902 if (get_float_exception_flags(&env->active_fpu.fp_status)
903 & float_flag_invalid) {
904 if (float32_is_any_nan(fst0)) {
905 wt2 = 0;
906 }
907 }
908 update_fcr31(env, GETPC());
909 return wt2;
910 }
911
912 uint64_t helper_float_floor_2008_l_d(CPUMIPSState *env, uint64_t fdt0)
913 {
914 uint64_t dt2;
915
916 set_float_rounding_mode(float_round_down, &env->active_fpu.fp_status);
917 dt2 = float64_to_int64(fdt0, &env->active_fpu.fp_status);
918 restore_rounding_mode(env);
919 if (get_float_exception_flags(&env->active_fpu.fp_status)
920 & float_flag_invalid) {
921 if (float64_is_any_nan(fdt0)) {
922 dt2 = 0;
923 }
924 }
925 update_fcr31(env, GETPC());
926 return dt2;
927 }
928
929 uint64_t helper_float_floor_2008_l_s(CPUMIPSState *env, uint32_t fst0)
930 {
931 uint64_t dt2;
932
933 set_float_rounding_mode(float_round_down, &env->active_fpu.fp_status);
934 dt2 = float32_to_int64(fst0, &env->active_fpu.fp_status);
935 restore_rounding_mode(env);
936 if (get_float_exception_flags(&env->active_fpu.fp_status)
937 & float_flag_invalid) {
938 if (float32_is_any_nan(fst0)) {
939 dt2 = 0;
940 }
941 }
942 update_fcr31(env, GETPC());
943 return dt2;
944 }
945
946 uint32_t helper_float_floor_2008_w_d(CPUMIPSState *env, uint64_t fdt0)
947 {
948 uint32_t wt2;
949
950 set_float_rounding_mode(float_round_down, &env->active_fpu.fp_status);
951 wt2 = float64_to_int32(fdt0, &env->active_fpu.fp_status);
952 restore_rounding_mode(env);
953 if (get_float_exception_flags(&env->active_fpu.fp_status)
954 & float_flag_invalid) {
955 if (float64_is_any_nan(fdt0)) {
956 wt2 = 0;
957 }
958 }
959 update_fcr31(env, GETPC());
960 return wt2;
961 }
962
963 uint32_t helper_float_floor_2008_w_s(CPUMIPSState *env, uint32_t fst0)
964 {
965 uint32_t wt2;
966
967 set_float_rounding_mode(float_round_down, &env->active_fpu.fp_status);
968 wt2 = float32_to_int32(fst0, &env->active_fpu.fp_status);
969 restore_rounding_mode(env);
970 if (get_float_exception_flags(&env->active_fpu.fp_status)
971 & float_flag_invalid) {
972 if (float32_is_any_nan(fst0)) {
973 wt2 = 0;
974 }
975 }
976 update_fcr31(env, GETPC());
977 return wt2;
978 }
979
980 /* unary operations, not modifying fp status */
981 #define FLOAT_UNOP(name) \
982 uint64_t helper_float_ ## name ## _d(uint64_t fdt0) \
983 { \
984 return float64_ ## name(fdt0); \
985 } \
986 uint32_t helper_float_ ## name ## _s(uint32_t fst0) \
987 { \
988 return float32_ ## name(fst0); \
989 } \
990 uint64_t helper_float_ ## name ## _ps(uint64_t fdt0) \
991 { \
992 uint32_t wt0; \
993 uint32_t wth0; \
994 \
995 wt0 = float32_ ## name(fdt0 & 0XFFFFFFFF); \
996 wth0 = float32_ ## name(fdt0 >> 32); \
997 return ((uint64_t)wth0 << 32) | wt0; \
998 }
999 FLOAT_UNOP(abs)
1000 FLOAT_UNOP(chs)
1001 #undef FLOAT_UNOP
1002
1003 /* MIPS specific unary operations */
1004 uint64_t helper_float_recip_d(CPUMIPSState *env, uint64_t fdt0)
1005 {
1006 uint64_t fdt2;
1007
1008 fdt2 = float64_div(float64_one, fdt0, &env->active_fpu.fp_status);
1009 update_fcr31(env, GETPC());
1010 return fdt2;
1011 }
1012
1013 uint32_t helper_float_recip_s(CPUMIPSState *env, uint32_t fst0)
1014 {
1015 uint32_t fst2;
1016
1017 fst2 = float32_div(float32_one, fst0, &env->active_fpu.fp_status);
1018 update_fcr31(env, GETPC());
1019 return fst2;
1020 }
1021
1022 uint64_t helper_float_rsqrt_d(CPUMIPSState *env, uint64_t fdt0)
1023 {
1024 uint64_t fdt2;
1025
1026 fdt2 = float64_sqrt(fdt0, &env->active_fpu.fp_status);
1027 fdt2 = float64_div(float64_one, fdt2, &env->active_fpu.fp_status);
1028 update_fcr31(env, GETPC());
1029 return fdt2;
1030 }
1031
1032 uint32_t helper_float_rsqrt_s(CPUMIPSState *env, uint32_t fst0)
1033 {
1034 uint32_t fst2;
1035
1036 fst2 = float32_sqrt(fst0, &env->active_fpu.fp_status);
1037 fst2 = float32_div(float32_one, fst2, &env->active_fpu.fp_status);
1038 update_fcr31(env, GETPC());
1039 return fst2;
1040 }
1041
1042 uint64_t helper_float_recip1_d(CPUMIPSState *env, uint64_t fdt0)
1043 {
1044 uint64_t fdt2;
1045
1046 fdt2 = float64_div(float64_one, fdt0, &env->active_fpu.fp_status);
1047 update_fcr31(env, GETPC());
1048 return fdt2;
1049 }
1050
1051 uint32_t helper_float_recip1_s(CPUMIPSState *env, uint32_t fst0)
1052 {
1053 uint32_t fst2;
1054
1055 fst2 = float32_div(float32_one, fst0, &env->active_fpu.fp_status);
1056 update_fcr31(env, GETPC());
1057 return fst2;
1058 }
1059
1060 uint64_t helper_float_recip1_ps(CPUMIPSState *env, uint64_t fdt0)
1061 {
1062 uint32_t fst2;
1063 uint32_t fsth2;
1064
1065 fst2 = float32_div(float32_one, fdt0 & 0XFFFFFFFF,
1066 &env->active_fpu.fp_status);
1067 fsth2 = float32_div(float32_one, fdt0 >> 32, &env->active_fpu.fp_status);
1068 update_fcr31(env, GETPC());
1069 return ((uint64_t)fsth2 << 32) | fst2;
1070 }
1071
1072 uint64_t helper_float_rsqrt1_d(CPUMIPSState *env, uint64_t fdt0)
1073 {
1074 uint64_t fdt2;
1075
1076 fdt2 = float64_sqrt(fdt0, &env->active_fpu.fp_status);
1077 fdt2 = float64_div(float64_one, fdt2, &env->active_fpu.fp_status);
1078 update_fcr31(env, GETPC());
1079 return fdt2;
1080 }
1081
1082 uint32_t helper_float_rsqrt1_s(CPUMIPSState *env, uint32_t fst0)
1083 {
1084 uint32_t fst2;
1085
1086 fst2 = float32_sqrt(fst0, &env->active_fpu.fp_status);
1087 fst2 = float32_div(float32_one, fst2, &env->active_fpu.fp_status);
1088 update_fcr31(env, GETPC());
1089 return fst2;
1090 }
1091
1092 uint64_t helper_float_rsqrt1_ps(CPUMIPSState *env, uint64_t fdt0)
1093 {
1094 uint32_t fst2;
1095 uint32_t fsth2;
1096
1097 fst2 = float32_sqrt(fdt0 & 0XFFFFFFFF, &env->active_fpu.fp_status);
1098 fsth2 = float32_sqrt(fdt0 >> 32, &env->active_fpu.fp_status);
1099 fst2 = float32_div(float32_one, fst2, &env->active_fpu.fp_status);
1100 fsth2 = float32_div(float32_one, fsth2, &env->active_fpu.fp_status);
1101 update_fcr31(env, GETPC());
1102 return ((uint64_t)fsth2 << 32) | fst2;
1103 }
1104
1105 #define FLOAT_RINT(name, bits) \
1106 uint ## bits ## _t helper_float_ ## name(CPUMIPSState *env, \
1107 uint ## bits ## _t fs) \
1108 { \
1109 uint ## bits ## _t fdret; \
1110 \
1111 fdret = float ## bits ## _round_to_int(fs, &env->active_fpu.fp_status); \
1112 update_fcr31(env, GETPC()); \
1113 return fdret; \
1114 }
1115
1116 FLOAT_RINT(rint_s, 32)
1117 FLOAT_RINT(rint_d, 64)
1118 #undef FLOAT_RINT
1119
1120 #define FLOAT_CLASS_SIGNALING_NAN 0x001
1121 #define FLOAT_CLASS_QUIET_NAN 0x002
1122 #define FLOAT_CLASS_NEGATIVE_INFINITY 0x004
1123 #define FLOAT_CLASS_NEGATIVE_NORMAL 0x008
1124 #define FLOAT_CLASS_NEGATIVE_SUBNORMAL 0x010
1125 #define FLOAT_CLASS_NEGATIVE_ZERO 0x020
1126 #define FLOAT_CLASS_POSITIVE_INFINITY 0x040
1127 #define FLOAT_CLASS_POSITIVE_NORMAL 0x080
1128 #define FLOAT_CLASS_POSITIVE_SUBNORMAL 0x100
1129 #define FLOAT_CLASS_POSITIVE_ZERO 0x200
1130
1131 #define FLOAT_CLASS(name, bits) \
1132 uint ## bits ## _t float_ ## name(uint ## bits ## _t arg, \
1133 float_status *status) \
1134 { \
1135 if (float ## bits ## _is_signaling_nan(arg, status)) { \
1136 return FLOAT_CLASS_SIGNALING_NAN; \
1137 } else if (float ## bits ## _is_quiet_nan(arg, status)) { \
1138 return FLOAT_CLASS_QUIET_NAN; \
1139 } else if (float ## bits ## _is_neg(arg)) { \
1140 if (float ## bits ## _is_infinity(arg)) { \
1141 return FLOAT_CLASS_NEGATIVE_INFINITY; \
1142 } else if (float ## bits ## _is_zero(arg)) { \
1143 return FLOAT_CLASS_NEGATIVE_ZERO; \
1144 } else if (float ## bits ## _is_zero_or_denormal(arg)) { \
1145 return FLOAT_CLASS_NEGATIVE_SUBNORMAL; \
1146 } else { \
1147 return FLOAT_CLASS_NEGATIVE_NORMAL; \
1148 } \
1149 } else { \
1150 if (float ## bits ## _is_infinity(arg)) { \
1151 return FLOAT_CLASS_POSITIVE_INFINITY; \
1152 } else if (float ## bits ## _is_zero(arg)) { \
1153 return FLOAT_CLASS_POSITIVE_ZERO; \
1154 } else if (float ## bits ## _is_zero_or_denormal(arg)) { \
1155 return FLOAT_CLASS_POSITIVE_SUBNORMAL; \
1156 } else { \
1157 return FLOAT_CLASS_POSITIVE_NORMAL; \
1158 } \
1159 } \
1160 } \
1161 \
1162 uint ## bits ## _t helper_float_ ## name(CPUMIPSState *env, \
1163 uint ## bits ## _t arg) \
1164 { \
1165 return float_ ## name(arg, &env->active_fpu.fp_status); \
1166 }
1167
1168 FLOAT_CLASS(class_s, 32)
1169 FLOAT_CLASS(class_d, 64)
1170 #undef FLOAT_CLASS
1171
1172 /* binary operations */
1173 #define FLOAT_BINOP(name) \
1174 uint64_t helper_float_ ## name ## _d(CPUMIPSState *env, \
1175 uint64_t fdt0, uint64_t fdt1) \
1176 { \
1177 uint64_t dt2; \
1178 \
1179 dt2 = float64_ ## name(fdt0, fdt1, &env->active_fpu.fp_status);\
1180 update_fcr31(env, GETPC()); \
1181 return dt2; \
1182 } \
1183 \
1184 uint32_t helper_float_ ## name ## _s(CPUMIPSState *env, \
1185 uint32_t fst0, uint32_t fst1) \
1186 { \
1187 uint32_t wt2; \
1188 \
1189 wt2 = float32_ ## name(fst0, fst1, &env->active_fpu.fp_status);\
1190 update_fcr31(env, GETPC()); \
1191 return wt2; \
1192 } \
1193 \
1194 uint64_t helper_float_ ## name ## _ps(CPUMIPSState *env, \
1195 uint64_t fdt0, \
1196 uint64_t fdt1) \
1197 { \
1198 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
1199 uint32_t fsth0 = fdt0 >> 32; \
1200 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
1201 uint32_t fsth1 = fdt1 >> 32; \
1202 uint32_t wt2; \
1203 uint32_t wth2; \
1204 \
1205 wt2 = float32_ ## name(fst0, fst1, &env->active_fpu.fp_status); \
1206 wth2 = float32_ ## name(fsth0, fsth1, &env->active_fpu.fp_status); \
1207 update_fcr31(env, GETPC()); \
1208 return ((uint64_t)wth2 << 32) | wt2; \
1209 }
1210
1211 FLOAT_BINOP(sub)
1212 FLOAT_BINOP(mul)
1213 FLOAT_BINOP(div)
1214 #undef FLOAT_BINOP
1215
1216 uint64_t helper_float_add_d(CPUMIPSState *env,
1217 uint64_t fdt0, uint64_t fdt1)
1218 {
1219 uint64_t dt2;
1220
1221 dt2 = float64_add(fdt0, fdt1, &env->active_fpu.fp_status);
1222 update_fcr31(env, GETPC());
1223 return dt2;
1224 }
1225
1226 uint32_t helper_float_add_s(CPUMIPSState *env,
1227 uint32_t fst0, uint32_t fst1)
1228 {
1229 uint32_t wt2;
1230
1231 wt2 = float32_sub(fst0, fst1, &env->active_fpu.fp_status);
1232 update_fcr31(env, GETPC());
1233 return wt2;
1234 }
1235
1236 uint64_t helper_float_add_ps(CPUMIPSState *env,
1237 uint64_t fdt0, uint64_t fdt1)
1238 {
1239 uint32_t fstl0 = fdt0 & 0XFFFFFFFF;
1240 uint32_t fsth0 = fdt0 >> 32;
1241 uint32_t fstl1 = fdt1 & 0XFFFFFFFF;
1242 uint32_t fsth1 = fdt1 >> 32;
1243 uint32_t wtl2;
1244 uint32_t wth2;
1245
1246 wtl2 = float32_add(fstl0, fstl1, &env->active_fpu.fp_status);
1247 wth2 = float32_add(fsth0, fsth1, &env->active_fpu.fp_status);
1248 update_fcr31(env, GETPC());
1249 return ((uint64_t)wth2 << 32) | wtl2;
1250 }
1251
1252
1253 /* MIPS specific binary operations */
1254 uint64_t helper_float_recip2_d(CPUMIPSState *env, uint64_t fdt0, uint64_t fdt2)
1255 {
1256 fdt2 = float64_mul(fdt0, fdt2, &env->active_fpu.fp_status);
1257 fdt2 = float64_chs(float64_sub(fdt2, float64_one,
1258 &env->active_fpu.fp_status));
1259 update_fcr31(env, GETPC());
1260 return fdt2;
1261 }
1262
1263 uint32_t helper_float_recip2_s(CPUMIPSState *env, uint32_t fst0, uint32_t fst2)
1264 {
1265 fst2 = float32_mul(fst0, fst2, &env->active_fpu.fp_status);
1266 fst2 = float32_chs(float32_sub(fst2, float32_one,
1267 &env->active_fpu.fp_status));
1268 update_fcr31(env, GETPC());
1269 return fst2;
1270 }
1271
1272 uint64_t helper_float_recip2_ps(CPUMIPSState *env, uint64_t fdt0, uint64_t fdt2)
1273 {
1274 uint32_t fst0 = fdt0 & 0XFFFFFFFF;
1275 uint32_t fsth0 = fdt0 >> 32;
1276 uint32_t fst2 = fdt2 & 0XFFFFFFFF;
1277 uint32_t fsth2 = fdt2 >> 32;
1278
1279 fst2 = float32_mul(fst0, fst2, &env->active_fpu.fp_status);
1280 fsth2 = float32_mul(fsth0, fsth2, &env->active_fpu.fp_status);
1281 fst2 = float32_chs(float32_sub(fst2, float32_one,
1282 &env->active_fpu.fp_status));
1283 fsth2 = float32_chs(float32_sub(fsth2, float32_one,
1284 &env->active_fpu.fp_status));
1285 update_fcr31(env, GETPC());
1286 return ((uint64_t)fsth2 << 32) | fst2;
1287 }
1288
1289 uint64_t helper_float_rsqrt2_d(CPUMIPSState *env, uint64_t fdt0, uint64_t fdt2)
1290 {
1291 fdt2 = float64_mul(fdt0, fdt2, &env->active_fpu.fp_status);
1292 fdt2 = float64_sub(fdt2, float64_one, &env->active_fpu.fp_status);
1293 fdt2 = float64_chs(float64_div(fdt2, FLOAT_TWO64,
1294 &env->active_fpu.fp_status));
1295 update_fcr31(env, GETPC());
1296 return fdt2;
1297 }
1298
1299 uint32_t helper_float_rsqrt2_s(CPUMIPSState *env, uint32_t fst0, uint32_t fst2)
1300 {
1301 fst2 = float32_mul(fst0, fst2, &env->active_fpu.fp_status);
1302 fst2 = float32_sub(fst2, float32_one, &env->active_fpu.fp_status);
1303 fst2 = float32_chs(float32_div(fst2, FLOAT_TWO32,
1304 &env->active_fpu.fp_status));
1305 update_fcr31(env, GETPC());
1306 return fst2;
1307 }
1308
1309 uint64_t helper_float_rsqrt2_ps(CPUMIPSState *env, uint64_t fdt0, uint64_t fdt2)
1310 {
1311 uint32_t fst0 = fdt0 & 0XFFFFFFFF;
1312 uint32_t fsth0 = fdt0 >> 32;
1313 uint32_t fst2 = fdt2 & 0XFFFFFFFF;
1314 uint32_t fsth2 = fdt2 >> 32;
1315
1316 fst2 = float32_mul(fst0, fst2, &env->active_fpu.fp_status);
1317 fsth2 = float32_mul(fsth0, fsth2, &env->active_fpu.fp_status);
1318 fst2 = float32_sub(fst2, float32_one, &env->active_fpu.fp_status);
1319 fsth2 = float32_sub(fsth2, float32_one, &env->active_fpu.fp_status);
1320 fst2 = float32_chs(float32_div(fst2, FLOAT_TWO32,
1321 &env->active_fpu.fp_status));
1322 fsth2 = float32_chs(float32_div(fsth2, FLOAT_TWO32,
1323 &env->active_fpu.fp_status));
1324 update_fcr31(env, GETPC());
1325 return ((uint64_t)fsth2 << 32) | fst2;
1326 }
1327
1328 uint64_t helper_float_addr_ps(CPUMIPSState *env, uint64_t fdt0, uint64_t fdt1)
1329 {
1330 uint32_t fst0 = fdt0 & 0XFFFFFFFF;
1331 uint32_t fsth0 = fdt0 >> 32;
1332 uint32_t fst1 = fdt1 & 0XFFFFFFFF;
1333 uint32_t fsth1 = fdt1 >> 32;
1334 uint32_t fst2;
1335 uint32_t fsth2;
1336
1337 fst2 = float32_add(fst0, fsth0, &env->active_fpu.fp_status);
1338 fsth2 = float32_add(fst1, fsth1, &env->active_fpu.fp_status);
1339 update_fcr31(env, GETPC());
1340 return ((uint64_t)fsth2 << 32) | fst2;
1341 }
1342
1343 uint64_t helper_float_mulr_ps(CPUMIPSState *env, uint64_t fdt0, uint64_t fdt1)
1344 {
1345 uint32_t fst0 = fdt0 & 0XFFFFFFFF;
1346 uint32_t fsth0 = fdt0 >> 32;
1347 uint32_t fst1 = fdt1 & 0XFFFFFFFF;
1348 uint32_t fsth1 = fdt1 >> 32;
1349 uint32_t fst2;
1350 uint32_t fsth2;
1351
1352 fst2 = float32_mul(fst0, fsth0, &env->active_fpu.fp_status);
1353 fsth2 = float32_mul(fst1, fsth1, &env->active_fpu.fp_status);
1354 update_fcr31(env, GETPC());
1355 return ((uint64_t)fsth2 << 32) | fst2;
1356 }
1357
1358 #define FLOAT_MINMAX(name, bits, minmaxfunc) \
1359 uint ## bits ## _t helper_float_ ## name(CPUMIPSState *env, \
1360 uint ## bits ## _t fs, \
1361 uint ## bits ## _t ft) \
1362 { \
1363 uint ## bits ## _t fdret; \
1364 \
1365 fdret = float ## bits ## _ ## minmaxfunc(fs, ft, \
1366 &env->active_fpu.fp_status); \
1367 update_fcr31(env, GETPC()); \
1368 return fdret; \
1369 }
1370
1371 FLOAT_MINMAX(max_s, 32, maxnum)
1372 FLOAT_MINMAX(max_d, 64, maxnum)
1373 FLOAT_MINMAX(maxa_s, 32, maxnummag)
1374 FLOAT_MINMAX(maxa_d, 64, maxnummag)
1375
1376 FLOAT_MINMAX(min_s, 32, minnum)
1377 FLOAT_MINMAX(min_d, 64, minnum)
1378 FLOAT_MINMAX(mina_s, 32, minnummag)
1379 FLOAT_MINMAX(mina_d, 64, minnummag)
1380 #undef FLOAT_MINMAX
1381
1382 /* ternary operations */
1383 #define UNFUSED_FMA(prefix, a, b, c, flags) \
1384 { \
1385 a = prefix##_mul(a, b, &env->active_fpu.fp_status); \
1386 if ((flags) & float_muladd_negate_c) { \
1387 a = prefix##_sub(a, c, &env->active_fpu.fp_status); \
1388 } else { \
1389 a = prefix##_add(a, c, &env->active_fpu.fp_status); \
1390 } \
1391 if ((flags) & float_muladd_negate_result) { \
1392 a = prefix##_chs(a); \
1393 } \
1394 }
1395
1396 /* FMA based operations */
1397 #define FLOAT_FMA(name, type) \
1398 uint64_t helper_float_ ## name ## _d(CPUMIPSState *env, \
1399 uint64_t fdt0, uint64_t fdt1, \
1400 uint64_t fdt2) \
1401 { \
1402 UNFUSED_FMA(float64, fdt0, fdt1, fdt2, type); \
1403 update_fcr31(env, GETPC()); \
1404 return fdt0; \
1405 } \
1406 \
1407 uint32_t helper_float_ ## name ## _s(CPUMIPSState *env, \
1408 uint32_t fst0, uint32_t fst1, \
1409 uint32_t fst2) \
1410 { \
1411 UNFUSED_FMA(float32, fst0, fst1, fst2, type); \
1412 update_fcr31(env, GETPC()); \
1413 return fst0; \
1414 } \
1415 \
1416 uint64_t helper_float_ ## name ## _ps(CPUMIPSState *env, \
1417 uint64_t fdt0, uint64_t fdt1, \
1418 uint64_t fdt2) \
1419 { \
1420 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
1421 uint32_t fsth0 = fdt0 >> 32; \
1422 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
1423 uint32_t fsth1 = fdt1 >> 32; \
1424 uint32_t fst2 = fdt2 & 0XFFFFFFFF; \
1425 uint32_t fsth2 = fdt2 >> 32; \
1426 \
1427 UNFUSED_FMA(float32, fst0, fst1, fst2, type); \
1428 UNFUSED_FMA(float32, fsth0, fsth1, fsth2, type); \
1429 update_fcr31(env, GETPC()); \
1430 return ((uint64_t)fsth0 << 32) | fst0; \
1431 }
1432 FLOAT_FMA(madd, 0)
1433 FLOAT_FMA(msub, float_muladd_negate_c)
1434 FLOAT_FMA(nmadd, float_muladd_negate_result)
1435 FLOAT_FMA(nmsub, float_muladd_negate_result | float_muladd_negate_c)
1436 #undef FLOAT_FMA
1437
1438 #define FLOAT_FMADDSUB(name, bits, muladd_arg) \
1439 uint ## bits ## _t helper_float_ ## name(CPUMIPSState *env, \
1440 uint ## bits ## _t fs, \
1441 uint ## bits ## _t ft, \
1442 uint ## bits ## _t fd) \
1443 { \
1444 uint ## bits ## _t fdret; \
1445 \
1446 fdret = float ## bits ## _muladd(fs, ft, fd, muladd_arg, \
1447 &env->active_fpu.fp_status); \
1448 update_fcr31(env, GETPC()); \
1449 return fdret; \
1450 }
1451
1452 FLOAT_FMADDSUB(maddf_s, 32, 0)
1453 FLOAT_FMADDSUB(maddf_d, 64, 0)
1454 FLOAT_FMADDSUB(msubf_s, 32, float_muladd_negate_product)
1455 FLOAT_FMADDSUB(msubf_d, 64, float_muladd_negate_product)
1456 #undef FLOAT_FMADDSUB
1457
1458 /* compare operations */
1459 #define FOP_COND_D(op, cond) \
1460 void helper_cmp_d_ ## op(CPUMIPSState *env, uint64_t fdt0, \
1461 uint64_t fdt1, int cc) \
1462 { \
1463 int c; \
1464 c = cond; \
1465 update_fcr31(env, GETPC()); \
1466 if (c) \
1467 SET_FP_COND(cc, env->active_fpu); \
1468 else \
1469 CLEAR_FP_COND(cc, env->active_fpu); \
1470 } \
1471 void helper_cmpabs_d_ ## op(CPUMIPSState *env, uint64_t fdt0, \
1472 uint64_t fdt1, int cc) \
1473 { \
1474 int c; \
1475 fdt0 = float64_abs(fdt0); \
1476 fdt1 = float64_abs(fdt1); \
1477 c = cond; \
1478 update_fcr31(env, GETPC()); \
1479 if (c) \
1480 SET_FP_COND(cc, env->active_fpu); \
1481 else \
1482 CLEAR_FP_COND(cc, env->active_fpu); \
1483 }
1484
1485 /*
1486 * NOTE: the comma operator will make "cond" to eval to false,
1487 * but float64_unordered_quiet() is still called.
1488 */
1489 FOP_COND_D(f, (float64_unordered_quiet(fdt1, fdt0,
1490 &env->active_fpu.fp_status), 0))
1491 FOP_COND_D(un, float64_unordered_quiet(fdt1, fdt0,
1492 &env->active_fpu.fp_status))
1493 FOP_COND_D(eq, float64_eq_quiet(fdt0, fdt1,
1494 &env->active_fpu.fp_status))
1495 FOP_COND_D(ueq, float64_unordered_quiet(fdt1, fdt0,
1496 &env->active_fpu.fp_status)
1497 || float64_eq_quiet(fdt0, fdt1,
1498 &env->active_fpu.fp_status))
1499 FOP_COND_D(olt, float64_lt_quiet(fdt0, fdt1,
1500 &env->active_fpu.fp_status))
1501 FOP_COND_D(ult, float64_unordered_quiet(fdt1, fdt0,
1502 &env->active_fpu.fp_status)
1503 || float64_lt_quiet(fdt0, fdt1,
1504 &env->active_fpu.fp_status))
1505 FOP_COND_D(ole, float64_le_quiet(fdt0, fdt1,
1506 &env->active_fpu.fp_status))
1507 FOP_COND_D(ule, float64_unordered_quiet(fdt1, fdt0,
1508 &env->active_fpu.fp_status)
1509 || float64_le_quiet(fdt0, fdt1,
1510 &env->active_fpu.fp_status))
1511 /*
1512 * NOTE: the comma operator will make "cond" to eval to false,
1513 * but float64_unordered() is still called.
1514 */
1515 FOP_COND_D(sf, (float64_unordered(fdt1, fdt0,
1516 &env->active_fpu.fp_status), 0))
1517 FOP_COND_D(ngle, float64_unordered(fdt1, fdt0,
1518 &env->active_fpu.fp_status))
1519 FOP_COND_D(seq, float64_eq(fdt0, fdt1,
1520 &env->active_fpu.fp_status))
1521 FOP_COND_D(ngl, float64_unordered(fdt1, fdt0,
1522 &env->active_fpu.fp_status)
1523 || float64_eq(fdt0, fdt1,
1524 &env->active_fpu.fp_status))
1525 FOP_COND_D(lt, float64_lt(fdt0, fdt1,
1526 &env->active_fpu.fp_status))
1527 FOP_COND_D(nge, float64_unordered(fdt1, fdt0,
1528 &env->active_fpu.fp_status)
1529 || float64_lt(fdt0, fdt1,
1530 &env->active_fpu.fp_status))
1531 FOP_COND_D(le, float64_le(fdt0, fdt1,
1532 &env->active_fpu.fp_status))
1533 FOP_COND_D(ngt, float64_unordered(fdt1, fdt0,
1534 &env->active_fpu.fp_status)
1535 || float64_le(fdt0, fdt1,
1536 &env->active_fpu.fp_status))
1537
1538 #define FOP_COND_S(op, cond) \
1539 void helper_cmp_s_ ## op(CPUMIPSState *env, uint32_t fst0, \
1540 uint32_t fst1, int cc) \
1541 { \
1542 int c; \
1543 c = cond; \
1544 update_fcr31(env, GETPC()); \
1545 if (c) \
1546 SET_FP_COND(cc, env->active_fpu); \
1547 else \
1548 CLEAR_FP_COND(cc, env->active_fpu); \
1549 } \
1550 void helper_cmpabs_s_ ## op(CPUMIPSState *env, uint32_t fst0, \
1551 uint32_t fst1, int cc) \
1552 { \
1553 int c; \
1554 fst0 = float32_abs(fst0); \
1555 fst1 = float32_abs(fst1); \
1556 c = cond; \
1557 update_fcr31(env, GETPC()); \
1558 if (c) \
1559 SET_FP_COND(cc, env->active_fpu); \
1560 else \
1561 CLEAR_FP_COND(cc, env->active_fpu); \
1562 }
1563
1564 /*
1565 * NOTE: the comma operator will make "cond" to eval to false,
1566 * but float32_unordered_quiet() is still called.
1567 */
1568 FOP_COND_S(f, (float32_unordered_quiet(fst1, fst0,
1569 &env->active_fpu.fp_status), 0))
1570 FOP_COND_S(un, float32_unordered_quiet(fst1, fst0,
1571 &env->active_fpu.fp_status))
1572 FOP_COND_S(eq, float32_eq_quiet(fst0, fst1,
1573 &env->active_fpu.fp_status))
1574 FOP_COND_S(ueq, float32_unordered_quiet(fst1, fst0,
1575 &env->active_fpu.fp_status)
1576 || float32_eq_quiet(fst0, fst1,
1577 &env->active_fpu.fp_status))
1578 FOP_COND_S(olt, float32_lt_quiet(fst0, fst1,
1579 &env->active_fpu.fp_status))
1580 FOP_COND_S(ult, float32_unordered_quiet(fst1, fst0,
1581 &env->active_fpu.fp_status)
1582 || float32_lt_quiet(fst0, fst1,
1583 &env->active_fpu.fp_status))
1584 FOP_COND_S(ole, float32_le_quiet(fst0, fst1,
1585 &env->active_fpu.fp_status))
1586 FOP_COND_S(ule, float32_unordered_quiet(fst1, fst0,
1587 &env->active_fpu.fp_status)
1588 || float32_le_quiet(fst0, fst1,
1589 &env->active_fpu.fp_status))
1590 /*
1591 * NOTE: the comma operator will make "cond" to eval to false,
1592 * but float32_unordered() is still called.
1593 */
1594 FOP_COND_S(sf, (float32_unordered(fst1, fst0,
1595 &env->active_fpu.fp_status), 0))
1596 FOP_COND_S(ngle, float32_unordered(fst1, fst0,
1597 &env->active_fpu.fp_status))
1598 FOP_COND_S(seq, float32_eq(fst0, fst1,
1599 &env->active_fpu.fp_status))
1600 FOP_COND_S(ngl, float32_unordered(fst1, fst0,
1601 &env->active_fpu.fp_status)
1602 || float32_eq(fst0, fst1,
1603 &env->active_fpu.fp_status))
1604 FOP_COND_S(lt, float32_lt(fst0, fst1,
1605 &env->active_fpu.fp_status))
1606 FOP_COND_S(nge, float32_unordered(fst1, fst0,
1607 &env->active_fpu.fp_status)
1608 || float32_lt(fst0, fst1,
1609 &env->active_fpu.fp_status))
1610 FOP_COND_S(le, float32_le(fst0, fst1,
1611 &env->active_fpu.fp_status))
1612 FOP_COND_S(ngt, float32_unordered(fst1, fst0,
1613 &env->active_fpu.fp_status)
1614 || float32_le(fst0, fst1,
1615 &env->active_fpu.fp_status))
1616
1617 #define FOP_COND_PS(op, condl, condh) \
1618 void helper_cmp_ps_ ## op(CPUMIPSState *env, uint64_t fdt0, \
1619 uint64_t fdt1, int cc) \
1620 { \
1621 uint32_t fst0, fsth0, fst1, fsth1; \
1622 int ch, cl; \
1623 fst0 = fdt0 & 0XFFFFFFFF; \
1624 fsth0 = fdt0 >> 32; \
1625 fst1 = fdt1 & 0XFFFFFFFF; \
1626 fsth1 = fdt1 >> 32; \
1627 cl = condl; \
1628 ch = condh; \
1629 update_fcr31(env, GETPC()); \
1630 if (cl) \
1631 SET_FP_COND(cc, env->active_fpu); \
1632 else \
1633 CLEAR_FP_COND(cc, env->active_fpu); \
1634 if (ch) \
1635 SET_FP_COND(cc + 1, env->active_fpu); \
1636 else \
1637 CLEAR_FP_COND(cc + 1, env->active_fpu); \
1638 } \
1639 void helper_cmpabs_ps_ ## op(CPUMIPSState *env, uint64_t fdt0, \
1640 uint64_t fdt1, int cc) \
1641 { \
1642 uint32_t fst0, fsth0, fst1, fsth1; \
1643 int ch, cl; \
1644 fst0 = float32_abs(fdt0 & 0XFFFFFFFF); \
1645 fsth0 = float32_abs(fdt0 >> 32); \
1646 fst1 = float32_abs(fdt1 & 0XFFFFFFFF); \
1647 fsth1 = float32_abs(fdt1 >> 32); \
1648 cl = condl; \
1649 ch = condh; \
1650 update_fcr31(env, GETPC()); \
1651 if (cl) \
1652 SET_FP_COND(cc, env->active_fpu); \
1653 else \
1654 CLEAR_FP_COND(cc, env->active_fpu); \
1655 if (ch) \
1656 SET_FP_COND(cc + 1, env->active_fpu); \
1657 else \
1658 CLEAR_FP_COND(cc + 1, env->active_fpu); \
1659 }
1660
1661 /*
1662 * NOTE: the comma operator will make "cond" to eval to false,
1663 * but float32_unordered_quiet() is still called.
1664 */
1665 FOP_COND_PS(f, (float32_unordered_quiet(fst1, fst0,
1666 &env->active_fpu.fp_status), 0),
1667 (float32_unordered_quiet(fsth1, fsth0,
1668 &env->active_fpu.fp_status), 0))
1669 FOP_COND_PS(un, float32_unordered_quiet(fst1, fst0,
1670 &env->active_fpu.fp_status),
1671 float32_unordered_quiet(fsth1, fsth0,
1672 &env->active_fpu.fp_status))
1673 FOP_COND_PS(eq, float32_eq_quiet(fst0, fst1,
1674 &env->active_fpu.fp_status),
1675 float32_eq_quiet(fsth0, fsth1,
1676 &env->active_fpu.fp_status))
1677 FOP_COND_PS(ueq, float32_unordered_quiet(fst1, fst0,
1678 &env->active_fpu.fp_status)
1679 || float32_eq_quiet(fst0, fst1,
1680 &env->active_fpu.fp_status),
1681 float32_unordered_quiet(fsth1, fsth0,
1682 &env->active_fpu.fp_status)
1683 || float32_eq_quiet(fsth0, fsth1,
1684 &env->active_fpu.fp_status))
1685 FOP_COND_PS(olt, float32_lt_quiet(fst0, fst1,
1686 &env->active_fpu.fp_status),
1687 float32_lt_quiet(fsth0, fsth1,
1688 &env->active_fpu.fp_status))
1689 FOP_COND_PS(ult, float32_unordered_quiet(fst1, fst0,
1690 &env->active_fpu.fp_status)
1691 || float32_lt_quiet(fst0, fst1,
1692 &env->active_fpu.fp_status),
1693 float32_unordered_quiet(fsth1, fsth0,
1694 &env->active_fpu.fp_status)
1695 || float32_lt_quiet(fsth0, fsth1,
1696 &env->active_fpu.fp_status))
1697 FOP_COND_PS(ole, float32_le_quiet(fst0, fst1,
1698 &env->active_fpu.fp_status),
1699 float32_le_quiet(fsth0, fsth1,
1700 &env->active_fpu.fp_status))
1701 FOP_COND_PS(ule, float32_unordered_quiet(fst1, fst0,
1702 &env->active_fpu.fp_status)
1703 || float32_le_quiet(fst0, fst1,
1704 &env->active_fpu.fp_status),
1705 float32_unordered_quiet(fsth1, fsth0,
1706 &env->active_fpu.fp_status)
1707 || float32_le_quiet(fsth0, fsth1,
1708 &env->active_fpu.fp_status))
1709 /*
1710 * NOTE: the comma operator will make "cond" to eval to false,
1711 * but float32_unordered() is still called.
1712 */
1713 FOP_COND_PS(sf, (float32_unordered(fst1, fst0,
1714 &env->active_fpu.fp_status), 0),
1715 (float32_unordered(fsth1, fsth0,
1716 &env->active_fpu.fp_status), 0))
1717 FOP_COND_PS(ngle, float32_unordered(fst1, fst0,
1718 &env->active_fpu.fp_status),
1719 float32_unordered(fsth1, fsth0,
1720 &env->active_fpu.fp_status))
1721 FOP_COND_PS(seq, float32_eq(fst0, fst1,
1722 &env->active_fpu.fp_status),
1723 float32_eq(fsth0, fsth1,
1724 &env->active_fpu.fp_status))
1725 FOP_COND_PS(ngl, float32_unordered(fst1, fst0,
1726 &env->active_fpu.fp_status)
1727 || float32_eq(fst0, fst1,
1728 &env->active_fpu.fp_status),
1729 float32_unordered(fsth1, fsth0,
1730 &env->active_fpu.fp_status)
1731 || float32_eq(fsth0, fsth1,
1732 &env->active_fpu.fp_status))
1733 FOP_COND_PS(lt, float32_lt(fst0, fst1,
1734 &env->active_fpu.fp_status),
1735 float32_lt(fsth0, fsth1,
1736 &env->active_fpu.fp_status))
1737 FOP_COND_PS(nge, float32_unordered(fst1, fst0,
1738 &env->active_fpu.fp_status)
1739 || float32_lt(fst0, fst1,
1740 &env->active_fpu.fp_status),
1741 float32_unordered(fsth1, fsth0,
1742 &env->active_fpu.fp_status)
1743 || float32_lt(fsth0, fsth1,
1744 &env->active_fpu.fp_status))
1745 FOP_COND_PS(le, float32_le(fst0, fst1,
1746 &env->active_fpu.fp_status),
1747 float32_le(fsth0, fsth1,
1748 &env->active_fpu.fp_status))
1749 FOP_COND_PS(ngt, float32_unordered(fst1, fst0,
1750 &env->active_fpu.fp_status)
1751 || float32_le(fst0, fst1,
1752 &env->active_fpu.fp_status),
1753 float32_unordered(fsth1, fsth0,
1754 &env->active_fpu.fp_status)
1755 || float32_le(fsth0, fsth1,
1756 &env->active_fpu.fp_status))
1757
1758 /* R6 compare operations */
1759 #define FOP_CONDN_D(op, cond) \
1760 uint64_t helper_r6_cmp_d_ ## op(CPUMIPSState *env, uint64_t fdt0, \
1761 uint64_t fdt1) \
1762 { \
1763 uint64_t c; \
1764 c = cond; \
1765 update_fcr31(env, GETPC()); \
1766 if (c) { \
1767 return -1; \
1768 } else { \
1769 return 0; \
1770 } \
1771 }
1772
1773 /*
1774 * NOTE: the comma operator will make "cond" to eval to false,
1775 * but float64_unordered_quiet() is still called.
1776 */
1777 FOP_CONDN_D(af, (float64_unordered_quiet(fdt1, fdt0,
1778 &env->active_fpu.fp_status), 0))
1779 FOP_CONDN_D(un, (float64_unordered_quiet(fdt1, fdt0,
1780 &env->active_fpu.fp_status)))
1781 FOP_CONDN_D(eq, (float64_eq_quiet(fdt0, fdt1,
1782 &env->active_fpu.fp_status)))
1783 FOP_CONDN_D(ueq, (float64_unordered_quiet(fdt1, fdt0,
1784 &env->active_fpu.fp_status)
1785 || float64_eq_quiet(fdt0, fdt1,
1786 &env->active_fpu.fp_status)))
1787 FOP_CONDN_D(lt, (float64_lt_quiet(fdt0, fdt1,
1788 &env->active_fpu.fp_status)))
1789 FOP_CONDN_D(ult, (float64_unordered_quiet(fdt1, fdt0,
1790 &env->active_fpu.fp_status)
1791 || float64_lt_quiet(fdt0, fdt1,
1792 &env->active_fpu.fp_status)))
1793 FOP_CONDN_D(le, (float64_le_quiet(fdt0, fdt1,
1794 &env->active_fpu.fp_status)))
1795 FOP_CONDN_D(ule, (float64_unordered_quiet(fdt1, fdt0,
1796 &env->active_fpu.fp_status)
1797 || float64_le_quiet(fdt0, fdt1,
1798 &env->active_fpu.fp_status)))
1799 /*
1800 * NOTE: the comma operator will make "cond" to eval to false,
1801 * but float64_unordered() is still called.\
1802 */
1803 FOP_CONDN_D(saf, (float64_unordered(fdt1, fdt0,
1804 &env->active_fpu.fp_status), 0))
1805 FOP_CONDN_D(sun, (float64_unordered(fdt1, fdt0,
1806 &env->active_fpu.fp_status)))
1807 FOP_CONDN_D(seq, (float64_eq(fdt0, fdt1,
1808 &env->active_fpu.fp_status)))
1809 FOP_CONDN_D(sueq, (float64_unordered(fdt1, fdt0,
1810 &env->active_fpu.fp_status)
1811 || float64_eq(fdt0, fdt1,
1812 &env->active_fpu.fp_status)))
1813 FOP_CONDN_D(slt, (float64_lt(fdt0, fdt1,
1814 &env->active_fpu.fp_status)))
1815 FOP_CONDN_D(sult, (float64_unordered(fdt1, fdt0,
1816 &env->active_fpu.fp_status)
1817 || float64_lt(fdt0, fdt1,
1818 &env->active_fpu.fp_status)))
1819 FOP_CONDN_D(sle, (float64_le(fdt0, fdt1,
1820 &env->active_fpu.fp_status)))
1821 FOP_CONDN_D(sule, (float64_unordered(fdt1, fdt0,
1822 &env->active_fpu.fp_status)
1823 || float64_le(fdt0, fdt1,
1824 &env->active_fpu.fp_status)))
1825 FOP_CONDN_D(or, (float64_le_quiet(fdt1, fdt0,
1826 &env->active_fpu.fp_status)
1827 || float64_le_quiet(fdt0, fdt1,
1828 &env->active_fpu.fp_status)))
1829 FOP_CONDN_D(une, (float64_unordered_quiet(fdt1, fdt0,
1830 &env->active_fpu.fp_status)
1831 || float64_lt_quiet(fdt1, fdt0,
1832 &env->active_fpu.fp_status)
1833 || float64_lt_quiet(fdt0, fdt1,
1834 &env->active_fpu.fp_status)))
1835 FOP_CONDN_D(ne, (float64_lt_quiet(fdt1, fdt0,
1836 &env->active_fpu.fp_status)
1837 || float64_lt_quiet(fdt0, fdt1,
1838 &env->active_fpu.fp_status)))
1839 FOP_CONDN_D(sor, (float64_le(fdt1, fdt0,
1840 &env->active_fpu.fp_status)
1841 || float64_le(fdt0, fdt1,
1842 &env->active_fpu.fp_status)))
1843 FOP_CONDN_D(sune, (float64_unordered(fdt1, fdt0,
1844 &env->active_fpu.fp_status)
1845 || float64_lt(fdt1, fdt0,
1846 &env->active_fpu.fp_status)
1847 || float64_lt(fdt0, fdt1,
1848 &env->active_fpu.fp_status)))
1849 FOP_CONDN_D(sne, (float64_lt(fdt1, fdt0,
1850 &env->active_fpu.fp_status)
1851 || float64_lt(fdt0, fdt1,
1852 &env->active_fpu.fp_status)))
1853
1854 #define FOP_CONDN_S(op, cond) \
1855 uint32_t helper_r6_cmp_s_ ## op(CPUMIPSState *env, uint32_t fst0, \
1856 uint32_t fst1) \
1857 { \
1858 uint64_t c; \
1859 c = cond; \
1860 update_fcr31(env, GETPC()); \
1861 if (c) { \
1862 return -1; \
1863 } else { \
1864 return 0; \
1865 } \
1866 }
1867
1868 /*
1869 * NOTE: the comma operator will make "cond" to eval to false,
1870 * but float32_unordered_quiet() is still called.
1871 */
1872 FOP_CONDN_S(af, (float32_unordered_quiet(fst1, fst0,
1873 &env->active_fpu.fp_status), 0))
1874 FOP_CONDN_S(un, (float32_unordered_quiet(fst1, fst0,
1875 &env->active_fpu.fp_status)))
1876 FOP_CONDN_S(eq, (float32_eq_quiet(fst0, fst1,
1877 &env->active_fpu.fp_status)))
1878 FOP_CONDN_S(ueq, (float32_unordered_quiet(fst1, fst0,
1879 &env->active_fpu.fp_status)
1880 || float32_eq_quiet(fst0, fst1,
1881 &env->active_fpu.fp_status)))
1882 FOP_CONDN_S(lt, (float32_lt_quiet(fst0, fst1,
1883 &env->active_fpu.fp_status)))
1884 FOP_CONDN_S(ult, (float32_unordered_quiet(fst1, fst0,
1885 &env->active_fpu.fp_status)
1886 || float32_lt_quiet(fst0, fst1,
1887 &env->active_fpu.fp_status)))
1888 FOP_CONDN_S(le, (float32_le_quiet(fst0, fst1,
1889 &env->active_fpu.fp_status)))
1890 FOP_CONDN_S(ule, (float32_unordered_quiet(fst1, fst0,
1891 &env->active_fpu.fp_status)
1892 || float32_le_quiet(fst0, fst1,
1893 &env->active_fpu.fp_status)))
1894 /*
1895 * NOTE: the comma operator will make "cond" to eval to false,
1896 * but float32_unordered() is still called.
1897 */
1898 FOP_CONDN_S(saf, (float32_unordered(fst1, fst0,
1899 &env->active_fpu.fp_status), 0))
1900 FOP_CONDN_S(sun, (float32_unordered(fst1, fst0,
1901 &env->active_fpu.fp_status)))
1902 FOP_CONDN_S(seq, (float32_eq(fst0, fst1,
1903 &env->active_fpu.fp_status)))
1904 FOP_CONDN_S(sueq, (float32_unordered(fst1, fst0,
1905 &env->active_fpu.fp_status)
1906 || float32_eq(fst0, fst1,
1907 &env->active_fpu.fp_status)))
1908 FOP_CONDN_S(slt, (float32_lt(fst0, fst1,
1909 &env->active_fpu.fp_status)))
1910 FOP_CONDN_S(sult, (float32_unordered(fst1, fst0,
1911 &env->active_fpu.fp_status)
1912 || float32_lt(fst0, fst1,
1913 &env->active_fpu.fp_status)))
1914 FOP_CONDN_S(sle, (float32_le(fst0, fst1,
1915 &env->active_fpu.fp_status)))
1916 FOP_CONDN_S(sule, (float32_unordered(fst1, fst0,
1917 &env->active_fpu.fp_status)
1918 || float32_le(fst0, fst1,
1919 &env->active_fpu.fp_status)))
1920 FOP_CONDN_S(or, (float32_le_quiet(fst1, fst0,
1921 &env->active_fpu.fp_status)
1922 || float32_le_quiet(fst0, fst1,
1923 &env->active_fpu.fp_status)))
1924 FOP_CONDN_S(une, (float32_unordered_quiet(fst1, fst0,
1925 &env->active_fpu.fp_status)
1926 || float32_lt_quiet(fst1, fst0,
1927 &env->active_fpu.fp_status)
1928 || float32_lt_quiet(fst0, fst1,
1929 &env->active_fpu.fp_status)))
1930 FOP_CONDN_S(ne, (float32_lt_quiet(fst1, fst0,
1931 &env->active_fpu.fp_status)
1932 || float32_lt_quiet(fst0, fst1,
1933 &env->active_fpu.fp_status)))
1934 FOP_CONDN_S(sor, (float32_le(fst1, fst0,
1935 &env->active_fpu.fp_status)
1936 || float32_le(fst0, fst1,
1937 &env->active_fpu.fp_status)))
1938 FOP_CONDN_S(sune, (float32_unordered(fst1, fst0,
1939 &env->active_fpu.fp_status)
1940 || float32_lt(fst1, fst0,
1941 &env->active_fpu.fp_status)
1942 || float32_lt(fst0, fst1,
1943 &env->active_fpu.fp_status)))
1944 FOP_CONDN_S(sne, (float32_lt(fst1, fst0,
1945 &env->active_fpu.fp_status)
1946 || float32_lt(fst0, fst1,
1947 &env->active_fpu.fp_status)))