2 * PowerPC floating point and SPE emulation helpers for QEMU.
4 * Copyright (c) 2003-2007 Jocelyn Mayer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 /*****************************************************************************/
23 /* Floating point operations helpers */
24 uint64_t helper_float32_to_float64(CPUPPCState
*env
, uint32_t arg
)
30 d
.d
= float32_to_float64(f
.f
, &env
->fp_status
);
34 uint32_t helper_float64_to_float32(CPUPPCState
*env
, uint64_t arg
)
40 f
.f
= float64_to_float32(d
.d
, &env
->fp_status
);
44 static inline int isden(float64 d
)
50 return ((u
.ll
>> 52) & 0x7FF) == 0;
53 uint32_t helper_compute_fprf(CPUPPCState
*env
, uint64_t arg
, uint32_t set_fprf
)
60 isneg
= float64_is_neg(farg
.d
);
61 if (unlikely(float64_is_any_nan(farg
.d
))) {
62 if (float64_is_signaling_nan(farg
.d
)) {
63 /* Signaling NaN: flags are undefined */
69 } else if (unlikely(float64_is_infinity(farg
.d
))) {
77 if (float64_is_zero(farg
.d
)) {
86 /* Denormalized numbers */
89 /* Normalized numbers */
100 /* We update FPSCR_FPRF */
101 env
->fpscr
&= ~(0x1F << FPSCR_FPRF
);
102 env
->fpscr
|= ret
<< FPSCR_FPRF
;
104 /* We just need fpcc to update Rc1 */
108 /* Floating-point invalid operations exception */
109 static inline uint64_t fload_invalid_op_excp(CPUPPCState
*env
, int op
)
116 case POWERPC_EXCP_FP_VXSNAN
:
117 env
->fpscr
|= 1 << FPSCR_VXSNAN
;
119 case POWERPC_EXCP_FP_VXSOFT
:
120 env
->fpscr
|= 1 << FPSCR_VXSOFT
;
122 case POWERPC_EXCP_FP_VXISI
:
123 /* Magnitude subtraction of infinities */
124 env
->fpscr
|= 1 << FPSCR_VXISI
;
126 case POWERPC_EXCP_FP_VXIDI
:
127 /* Division of infinity by infinity */
128 env
->fpscr
|= 1 << FPSCR_VXIDI
;
130 case POWERPC_EXCP_FP_VXZDZ
:
131 /* Division of zero by zero */
132 env
->fpscr
|= 1 << FPSCR_VXZDZ
;
134 case POWERPC_EXCP_FP_VXIMZ
:
135 /* Multiplication of zero by infinity */
136 env
->fpscr
|= 1 << FPSCR_VXIMZ
;
138 case POWERPC_EXCP_FP_VXVC
:
139 /* Ordered comparison of NaN */
140 env
->fpscr
|= 1 << FPSCR_VXVC
;
141 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
142 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
143 /* We must update the target FPR before raising the exception */
145 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
146 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_VXVC
;
147 /* Update the floating-point enabled exception summary */
148 env
->fpscr
|= 1 << FPSCR_FEX
;
149 /* Exception is differed */
153 case POWERPC_EXCP_FP_VXSQRT
:
154 /* Square root of a negative number */
155 env
->fpscr
|= 1 << FPSCR_VXSQRT
;
157 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
159 /* Set the result to quiet NaN */
160 ret
= 0x7FF8000000000000ULL
;
161 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
162 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
165 case POWERPC_EXCP_FP_VXCVI
:
166 /* Invalid conversion */
167 env
->fpscr
|= 1 << FPSCR_VXCVI
;
168 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
170 /* Set the result to quiet NaN */
171 ret
= 0x7FF8000000000000ULL
;
172 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
173 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
177 /* Update the floating-point invalid operation summary */
178 env
->fpscr
|= 1 << FPSCR_VX
;
179 /* Update the floating-point exception summary */
180 env
->fpscr
|= 1 << FPSCR_FX
;
182 /* Update the floating-point enabled exception summary */
183 env
->fpscr
|= 1 << FPSCR_FEX
;
184 if (msr_fe0
!= 0 || msr_fe1
!= 0) {
185 helper_raise_exception_err(env
, POWERPC_EXCP_PROGRAM
,
186 POWERPC_EXCP_FP
| op
);
192 static inline void float_zero_divide_excp(CPUPPCState
*env
)
194 env
->fpscr
|= 1 << FPSCR_ZX
;
195 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
196 /* Update the floating-point exception summary */
197 env
->fpscr
|= 1 << FPSCR_FX
;
199 /* Update the floating-point enabled exception summary */
200 env
->fpscr
|= 1 << FPSCR_FEX
;
201 if (msr_fe0
!= 0 || msr_fe1
!= 0) {
202 helper_raise_exception_err(env
, POWERPC_EXCP_PROGRAM
,
203 POWERPC_EXCP_FP
| POWERPC_EXCP_FP_ZX
);
208 static inline void float_overflow_excp(CPUPPCState
*env
)
210 env
->fpscr
|= 1 << FPSCR_OX
;
211 /* Update the floating-point exception summary */
212 env
->fpscr
|= 1 << FPSCR_FX
;
214 /* XXX: should adjust the result */
215 /* Update the floating-point enabled exception summary */
216 env
->fpscr
|= 1 << FPSCR_FEX
;
217 /* We must update the target FPR before raising the exception */
218 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
219 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_OX
;
221 env
->fpscr
|= 1 << FPSCR_XX
;
222 env
->fpscr
|= 1 << FPSCR_FI
;
226 static inline void float_underflow_excp(CPUPPCState
*env
)
228 env
->fpscr
|= 1 << FPSCR_UX
;
229 /* Update the floating-point exception summary */
230 env
->fpscr
|= 1 << FPSCR_FX
;
232 /* XXX: should adjust the result */
233 /* Update the floating-point enabled exception summary */
234 env
->fpscr
|= 1 << FPSCR_FEX
;
235 /* We must update the target FPR before raising the exception */
236 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
237 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_UX
;
241 static inline void float_inexact_excp(CPUPPCState
*env
)
243 env
->fpscr
|= 1 << FPSCR_XX
;
244 /* Update the floating-point exception summary */
245 env
->fpscr
|= 1 << FPSCR_FX
;
247 /* Update the floating-point enabled exception summary */
248 env
->fpscr
|= 1 << FPSCR_FEX
;
249 /* We must update the target FPR before raising the exception */
250 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
251 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_XX
;
255 static inline void fpscr_set_rounding_mode(CPUPPCState
*env
)
259 /* Set rounding mode */
262 /* Best approximation (round to nearest) */
263 rnd_type
= float_round_nearest_even
;
266 /* Smaller magnitude (round toward zero) */
267 rnd_type
= float_round_to_zero
;
270 /* Round toward +infinite */
271 rnd_type
= float_round_up
;
275 /* Round toward -infinite */
276 rnd_type
= float_round_down
;
279 set_float_rounding_mode(rnd_type
, &env
->fp_status
);
282 void helper_fpscr_clrbit(CPUPPCState
*env
, uint32_t bit
)
286 prev
= (env
->fpscr
>> bit
) & 1;
287 env
->fpscr
&= ~(1 << bit
);
292 fpscr_set_rounding_mode(env
);
300 void helper_fpscr_setbit(CPUPPCState
*env
, uint32_t bit
)
304 prev
= (env
->fpscr
>> bit
) & 1;
305 env
->fpscr
|= 1 << bit
;
309 env
->fpscr
|= 1 << FPSCR_FX
;
315 env
->fpscr
|= 1 << FPSCR_FX
;
321 env
->fpscr
|= 1 << FPSCR_FX
;
327 env
->fpscr
|= 1 << FPSCR_FX
;
333 env
->fpscr
|= 1 << FPSCR_FX
;
347 env
->fpscr
|= 1 << FPSCR_VX
;
348 env
->fpscr
|= 1 << FPSCR_FX
;
356 env
->error_code
= POWERPC_EXCP_FP
;
358 env
->error_code
|= POWERPC_EXCP_FP_VXSNAN
;
361 env
->error_code
|= POWERPC_EXCP_FP_VXISI
;
364 env
->error_code
|= POWERPC_EXCP_FP_VXIDI
;
367 env
->error_code
|= POWERPC_EXCP_FP_VXZDZ
;
370 env
->error_code
|= POWERPC_EXCP_FP_VXIMZ
;
373 env
->error_code
|= POWERPC_EXCP_FP_VXVC
;
376 env
->error_code
|= POWERPC_EXCP_FP_VXSOFT
;
379 env
->error_code
|= POWERPC_EXCP_FP_VXSQRT
;
382 env
->error_code
|= POWERPC_EXCP_FP_VXCVI
;
390 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_OX
;
397 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_UX
;
404 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_ZX
;
411 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_XX
;
417 fpscr_set_rounding_mode(env
);
422 /* Update the floating-point enabled exception summary */
423 env
->fpscr
|= 1 << FPSCR_FEX
;
424 /* We have to update Rc1 before raising the exception */
425 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
431 void helper_store_fpscr(CPUPPCState
*env
, uint64_t arg
, uint32_t mask
)
433 target_ulong prev
, new;
437 new = (target_ulong
)arg
;
438 new &= ~0x60000000LL
;
439 new |= prev
& 0x60000000LL
;
440 for (i
= 0; i
< sizeof(target_ulong
) * 2; i
++) {
441 if (mask
& (1 << i
)) {
442 env
->fpscr
&= ~(0xFLL
<< (4 * i
));
443 env
->fpscr
|= new & (0xFLL
<< (4 * i
));
446 /* Update VX and FEX */
448 env
->fpscr
|= 1 << FPSCR_VX
;
450 env
->fpscr
&= ~(1 << FPSCR_VX
);
452 if ((fpscr_ex
& fpscr_eex
) != 0) {
453 env
->fpscr
|= 1 << FPSCR_FEX
;
454 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
455 /* XXX: we should compute it properly */
456 env
->error_code
= POWERPC_EXCP_FP
;
458 env
->fpscr
&= ~(1 << FPSCR_FEX
);
460 fpscr_set_rounding_mode(env
);
463 void store_fpscr(CPUPPCState
*env
, uint64_t arg
, uint32_t mask
)
465 helper_store_fpscr(env
, arg
, mask
);
468 void helper_float_check_status(CPUPPCState
*env
)
470 int status
= get_float_exception_flags(&env
->fp_status
);
472 if (status
& float_flag_divbyzero
) {
473 float_zero_divide_excp(env
);
474 } else if (status
& float_flag_overflow
) {
475 float_overflow_excp(env
);
476 } else if (status
& float_flag_underflow
) {
477 float_underflow_excp(env
);
478 } else if (status
& float_flag_inexact
) {
479 float_inexact_excp(env
);
482 if (env
->exception_index
== POWERPC_EXCP_PROGRAM
&&
483 (env
->error_code
& POWERPC_EXCP_FP
)) {
484 /* Differred floating-point exception after target FPR update */
485 if (msr_fe0
!= 0 || msr_fe1
!= 0) {
486 helper_raise_exception_err(env
, env
->exception_index
,
492 void helper_reset_fpstatus(CPUPPCState
*env
)
494 set_float_exception_flags(0, &env
->fp_status
);
498 uint64_t helper_fadd(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
)
500 CPU_DoubleU farg1
, farg2
;
505 if (unlikely(float64_is_infinity(farg1
.d
) && float64_is_infinity(farg2
.d
) &&
506 float64_is_neg(farg1
.d
) != float64_is_neg(farg2
.d
))) {
507 /* Magnitude subtraction of infinities */
508 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXISI
);
510 if (unlikely(float64_is_signaling_nan(farg1
.d
) ||
511 float64_is_signaling_nan(farg2
.d
))) {
513 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
515 farg1
.d
= float64_add(farg1
.d
, farg2
.d
, &env
->fp_status
);
522 uint64_t helper_fsub(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
)
524 CPU_DoubleU farg1
, farg2
;
529 if (unlikely(float64_is_infinity(farg1
.d
) && float64_is_infinity(farg2
.d
) &&
530 float64_is_neg(farg1
.d
) == float64_is_neg(farg2
.d
))) {
531 /* Magnitude subtraction of infinities */
532 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXISI
);
534 if (unlikely(float64_is_signaling_nan(farg1
.d
) ||
535 float64_is_signaling_nan(farg2
.d
))) {
536 /* sNaN subtraction */
537 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
539 farg1
.d
= float64_sub(farg1
.d
, farg2
.d
, &env
->fp_status
);
546 uint64_t helper_fmul(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
)
548 CPU_DoubleU farg1
, farg2
;
553 if (unlikely((float64_is_infinity(farg1
.d
) && float64_is_zero(farg2
.d
)) ||
554 (float64_is_zero(farg1
.d
) && float64_is_infinity(farg2
.d
)))) {
555 /* Multiplication of zero by infinity */
556 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXIMZ
);
558 if (unlikely(float64_is_signaling_nan(farg1
.d
) ||
559 float64_is_signaling_nan(farg2
.d
))) {
560 /* sNaN multiplication */
561 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
563 farg1
.d
= float64_mul(farg1
.d
, farg2
.d
, &env
->fp_status
);
570 uint64_t helper_fdiv(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
)
572 CPU_DoubleU farg1
, farg2
;
577 if (unlikely(float64_is_infinity(farg1
.d
) &&
578 float64_is_infinity(farg2
.d
))) {
579 /* Division of infinity by infinity */
580 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXIDI
);
581 } else if (unlikely(float64_is_zero(farg1
.d
) && float64_is_zero(farg2
.d
))) {
582 /* Division of zero by zero */
583 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXZDZ
);
585 if (unlikely(float64_is_signaling_nan(farg1
.d
) ||
586 float64_is_signaling_nan(farg2
.d
))) {
588 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
590 farg1
.d
= float64_div(farg1
.d
, farg2
.d
, &env
->fp_status
);
597 uint64_t helper_fctiw(CPUPPCState
*env
, uint64_t arg
)
603 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
604 /* sNaN conversion */
605 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
|
606 POWERPC_EXCP_FP_VXCVI
);
607 } else if (unlikely(float64_is_quiet_nan(farg
.d
) ||
608 float64_is_infinity(farg
.d
))) {
609 /* qNan / infinity conversion */
610 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXCVI
);
612 farg
.ll
= float64_to_int32(farg
.d
, &env
->fp_status
);
613 /* XXX: higher bits are not supposed to be significant.
614 * to make tests easier, return the same as a real PowerPC 750
616 farg
.ll
|= 0xFFF80000ULL
<< 32;
621 /* fctiwz - fctiwz. */
622 uint64_t helper_fctiwz(CPUPPCState
*env
, uint64_t arg
)
628 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
629 /* sNaN conversion */
630 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
|
631 POWERPC_EXCP_FP_VXCVI
);
632 } else if (unlikely(float64_is_quiet_nan(farg
.d
) ||
633 float64_is_infinity(farg
.d
))) {
634 /* qNan / infinity conversion */
635 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXCVI
);
637 farg
.ll
= float64_to_int32_round_to_zero(farg
.d
, &env
->fp_status
);
638 /* XXX: higher bits are not supposed to be significant.
639 * to make tests easier, return the same as a real PowerPC 750
641 farg
.ll
|= 0xFFF80000ULL
<< 32;
646 #if defined(TARGET_PPC64)
648 uint64_t helper_fcfid(CPUPPCState
*env
, uint64_t arg
)
652 farg
.d
= int64_to_float64(arg
, &env
->fp_status
);
657 uint64_t helper_fctid(CPUPPCState
*env
, uint64_t arg
)
663 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
664 /* sNaN conversion */
665 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
|
666 POWERPC_EXCP_FP_VXCVI
);
667 } else if (unlikely(float64_is_quiet_nan(farg
.d
) ||
668 float64_is_infinity(farg
.d
))) {
669 /* qNan / infinity conversion */
670 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXCVI
);
672 farg
.ll
= float64_to_int64(farg
.d
, &env
->fp_status
);
677 /* fctidz - fctidz. */
678 uint64_t helper_fctidz(CPUPPCState
*env
, uint64_t arg
)
684 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
685 /* sNaN conversion */
686 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
|
687 POWERPC_EXCP_FP_VXCVI
);
688 } else if (unlikely(float64_is_quiet_nan(farg
.d
) ||
689 float64_is_infinity(farg
.d
))) {
690 /* qNan / infinity conversion */
691 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXCVI
);
693 farg
.ll
= float64_to_int64_round_to_zero(farg
.d
, &env
->fp_status
);
700 static inline uint64_t do_fri(CPUPPCState
*env
, uint64_t arg
,
707 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
709 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
|
710 POWERPC_EXCP_FP_VXCVI
);
711 } else if (unlikely(float64_is_quiet_nan(farg
.d
) ||
712 float64_is_infinity(farg
.d
))) {
713 /* qNan / infinity round */
714 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXCVI
);
716 set_float_rounding_mode(rounding_mode
, &env
->fp_status
);
717 farg
.ll
= float64_round_to_int(farg
.d
, &env
->fp_status
);
718 /* Restore rounding mode from FPSCR */
719 fpscr_set_rounding_mode(env
);
724 uint64_t helper_frin(CPUPPCState
*env
, uint64_t arg
)
726 return do_fri(env
, arg
, float_round_nearest_even
);
729 uint64_t helper_friz(CPUPPCState
*env
, uint64_t arg
)
731 return do_fri(env
, arg
, float_round_to_zero
);
734 uint64_t helper_frip(CPUPPCState
*env
, uint64_t arg
)
736 return do_fri(env
, arg
, float_round_up
);
739 uint64_t helper_frim(CPUPPCState
*env
, uint64_t arg
)
741 return do_fri(env
, arg
, float_round_down
);
745 uint64_t helper_fmadd(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
748 CPU_DoubleU farg1
, farg2
, farg3
;
754 if (unlikely((float64_is_infinity(farg1
.d
) && float64_is_zero(farg2
.d
)) ||
755 (float64_is_zero(farg1
.d
) && float64_is_infinity(farg2
.d
)))) {
756 /* Multiplication of zero by infinity */
757 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXIMZ
);
759 if (unlikely(float64_is_signaling_nan(farg1
.d
) ||
760 float64_is_signaling_nan(farg2
.d
) ||
761 float64_is_signaling_nan(farg3
.d
))) {
763 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
765 /* This is the way the PowerPC specification defines it */
766 float128 ft0_128
, ft1_128
;
768 ft0_128
= float64_to_float128(farg1
.d
, &env
->fp_status
);
769 ft1_128
= float64_to_float128(farg2
.d
, &env
->fp_status
);
770 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
771 if (unlikely(float128_is_infinity(ft0_128
) &&
772 float64_is_infinity(farg3
.d
) &&
773 float128_is_neg(ft0_128
) != float64_is_neg(farg3
.d
))) {
774 /* Magnitude subtraction of infinities */
775 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXISI
);
777 ft1_128
= float64_to_float128(farg3
.d
, &env
->fp_status
);
778 ft0_128
= float128_add(ft0_128
, ft1_128
, &env
->fp_status
);
779 farg1
.d
= float128_to_float64(ft0_128
, &env
->fp_status
);
787 uint64_t helper_fmsub(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
790 CPU_DoubleU farg1
, farg2
, farg3
;
796 if (unlikely((float64_is_infinity(farg1
.d
) && float64_is_zero(farg2
.d
)) ||
797 (float64_is_zero(farg1
.d
) &&
798 float64_is_infinity(farg2
.d
)))) {
799 /* Multiplication of zero by infinity */
800 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXIMZ
);
802 if (unlikely(float64_is_signaling_nan(farg1
.d
) ||
803 float64_is_signaling_nan(farg2
.d
) ||
804 float64_is_signaling_nan(farg3
.d
))) {
806 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
808 /* This is the way the PowerPC specification defines it */
809 float128 ft0_128
, ft1_128
;
811 ft0_128
= float64_to_float128(farg1
.d
, &env
->fp_status
);
812 ft1_128
= float64_to_float128(farg2
.d
, &env
->fp_status
);
813 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
814 if (unlikely(float128_is_infinity(ft0_128
) &&
815 float64_is_infinity(farg3
.d
) &&
816 float128_is_neg(ft0_128
) == float64_is_neg(farg3
.d
))) {
817 /* Magnitude subtraction of infinities */
818 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXISI
);
820 ft1_128
= float64_to_float128(farg3
.d
, &env
->fp_status
);
821 ft0_128
= float128_sub(ft0_128
, ft1_128
, &env
->fp_status
);
822 farg1
.d
= float128_to_float64(ft0_128
, &env
->fp_status
);
828 /* fnmadd - fnmadd. */
829 uint64_t helper_fnmadd(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
832 CPU_DoubleU farg1
, farg2
, farg3
;
838 if (unlikely((float64_is_infinity(farg1
.d
) && float64_is_zero(farg2
.d
)) ||
839 (float64_is_zero(farg1
.d
) && float64_is_infinity(farg2
.d
)))) {
840 /* Multiplication of zero by infinity */
841 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXIMZ
);
843 if (unlikely(float64_is_signaling_nan(farg1
.d
) ||
844 float64_is_signaling_nan(farg2
.d
) ||
845 float64_is_signaling_nan(farg3
.d
))) {
847 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
849 /* This is the way the PowerPC specification defines it */
850 float128 ft0_128
, ft1_128
;
852 ft0_128
= float64_to_float128(farg1
.d
, &env
->fp_status
);
853 ft1_128
= float64_to_float128(farg2
.d
, &env
->fp_status
);
854 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
855 if (unlikely(float128_is_infinity(ft0_128
) &&
856 float64_is_infinity(farg3
.d
) &&
857 float128_is_neg(ft0_128
) != float64_is_neg(farg3
.d
))) {
858 /* Magnitude subtraction of infinities */
859 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXISI
);
861 ft1_128
= float64_to_float128(farg3
.d
, &env
->fp_status
);
862 ft0_128
= float128_add(ft0_128
, ft1_128
, &env
->fp_status
);
863 farg1
.d
= float128_to_float64(ft0_128
, &env
->fp_status
);
865 if (likely(!float64_is_any_nan(farg1
.d
))) {
866 farg1
.d
= float64_chs(farg1
.d
);
872 /* fnmsub - fnmsub. */
873 uint64_t helper_fnmsub(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
876 CPU_DoubleU farg1
, farg2
, farg3
;
882 if (unlikely((float64_is_infinity(farg1
.d
) && float64_is_zero(farg2
.d
)) ||
883 (float64_is_zero(farg1
.d
) &&
884 float64_is_infinity(farg2
.d
)))) {
885 /* Multiplication of zero by infinity */
886 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXIMZ
);
888 if (unlikely(float64_is_signaling_nan(farg1
.d
) ||
889 float64_is_signaling_nan(farg2
.d
) ||
890 float64_is_signaling_nan(farg3
.d
))) {
892 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
894 /* This is the way the PowerPC specification defines it */
895 float128 ft0_128
, ft1_128
;
897 ft0_128
= float64_to_float128(farg1
.d
, &env
->fp_status
);
898 ft1_128
= float64_to_float128(farg2
.d
, &env
->fp_status
);
899 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
900 if (unlikely(float128_is_infinity(ft0_128
) &&
901 float64_is_infinity(farg3
.d
) &&
902 float128_is_neg(ft0_128
) == float64_is_neg(farg3
.d
))) {
903 /* Magnitude subtraction of infinities */
904 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXISI
);
906 ft1_128
= float64_to_float128(farg3
.d
, &env
->fp_status
);
907 ft0_128
= float128_sub(ft0_128
, ft1_128
, &env
->fp_status
);
908 farg1
.d
= float128_to_float64(ft0_128
, &env
->fp_status
);
910 if (likely(!float64_is_any_nan(farg1
.d
))) {
911 farg1
.d
= float64_chs(farg1
.d
);
918 uint64_t helper_frsp(CPUPPCState
*env
, uint64_t arg
)
925 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
926 /* sNaN square root */
927 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
929 f32
= float64_to_float32(farg
.d
, &env
->fp_status
);
930 farg
.d
= float32_to_float64(f32
, &env
->fp_status
);
936 uint64_t helper_fsqrt(CPUPPCState
*env
, uint64_t arg
)
942 if (unlikely(float64_is_neg(farg
.d
) && !float64_is_zero(farg
.d
))) {
943 /* Square root of a negative nonzero number */
944 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSQRT
);
946 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
947 /* sNaN square root */
948 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
950 farg
.d
= float64_sqrt(farg
.d
, &env
->fp_status
);
956 uint64_t helper_fre(CPUPPCState
*env
, uint64_t arg
)
962 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
963 /* sNaN reciprocal */
964 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
966 farg
.d
= float64_div(float64_one
, farg
.d
, &env
->fp_status
);
971 uint64_t helper_fres(CPUPPCState
*env
, uint64_t arg
)
978 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
979 /* sNaN reciprocal */
980 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
982 farg
.d
= float64_div(float64_one
, farg
.d
, &env
->fp_status
);
983 f32
= float64_to_float32(farg
.d
, &env
->fp_status
);
984 farg
.d
= float32_to_float64(f32
, &env
->fp_status
);
989 /* frsqrte - frsqrte. */
990 uint64_t helper_frsqrte(CPUPPCState
*env
, uint64_t arg
)
997 if (unlikely(float64_is_neg(farg
.d
) && !float64_is_zero(farg
.d
))) {
998 /* Reciprocal square root of a negative nonzero number */
999 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSQRT
);
1001 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
1002 /* sNaN reciprocal square root */
1003 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
1005 farg
.d
= float64_sqrt(farg
.d
, &env
->fp_status
);
1006 farg
.d
= float64_div(float64_one
, farg
.d
, &env
->fp_status
);
1007 f32
= float64_to_float32(farg
.d
, &env
->fp_status
);
1008 farg
.d
= float32_to_float64(f32
, &env
->fp_status
);
1014 uint64_t helper_fsel(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
1021 if ((!float64_is_neg(farg1
.d
) || float64_is_zero(farg1
.d
)) &&
1022 !float64_is_any_nan(farg1
.d
)) {
1029 void helper_fcmpu(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
1032 CPU_DoubleU farg1
, farg2
;
1038 if (unlikely(float64_is_any_nan(farg1
.d
) ||
1039 float64_is_any_nan(farg2
.d
))) {
1041 } else if (float64_lt(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1043 } else if (!float64_le(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1049 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
1050 env
->fpscr
|= ret
<< FPSCR_FPRF
;
1051 env
->crf
[crfD
] = ret
;
1052 if (unlikely(ret
== 0x01UL
1053 && (float64_is_signaling_nan(farg1
.d
) ||
1054 float64_is_signaling_nan(farg2
.d
)))) {
1055 /* sNaN comparison */
1056 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
1060 void helper_fcmpo(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
1063 CPU_DoubleU farg1
, farg2
;
1069 if (unlikely(float64_is_any_nan(farg1
.d
) ||
1070 float64_is_any_nan(farg2
.d
))) {
1072 } else if (float64_lt(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1074 } else if (!float64_le(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1080 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
1081 env
->fpscr
|= ret
<< FPSCR_FPRF
;
1082 env
->crf
[crfD
] = ret
;
1083 if (unlikely(ret
== 0x01UL
)) {
1084 if (float64_is_signaling_nan(farg1
.d
) ||
1085 float64_is_signaling_nan(farg2
.d
)) {
1086 /* sNaN comparison */
1087 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
|
1088 POWERPC_EXCP_FP_VXVC
);
1090 /* qNaN comparison */
1091 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXVC
);
1096 /* Single-precision floating-point conversions */
1097 static inline uint32_t efscfsi(CPUPPCState
*env
, uint32_t val
)
1101 u
.f
= int32_to_float32(val
, &env
->vec_status
);
1106 static inline uint32_t efscfui(CPUPPCState
*env
, uint32_t val
)
1110 u
.f
= uint32_to_float32(val
, &env
->vec_status
);
1115 static inline int32_t efsctsi(CPUPPCState
*env
, uint32_t val
)
1120 /* NaN are not treated the same way IEEE 754 does */
1121 if (unlikely(float32_is_quiet_nan(u
.f
))) {
1125 return float32_to_int32(u
.f
, &env
->vec_status
);
1128 static inline uint32_t efsctui(CPUPPCState
*env
, uint32_t val
)
1133 /* NaN are not treated the same way IEEE 754 does */
1134 if (unlikely(float32_is_quiet_nan(u
.f
))) {
1138 return float32_to_uint32(u
.f
, &env
->vec_status
);
1141 static inline uint32_t efsctsiz(CPUPPCState
*env
, uint32_t val
)
1146 /* NaN are not treated the same way IEEE 754 does */
1147 if (unlikely(float32_is_quiet_nan(u
.f
))) {
1151 return float32_to_int32_round_to_zero(u
.f
, &env
->vec_status
);
1154 static inline uint32_t efsctuiz(CPUPPCState
*env
, uint32_t val
)
1159 /* NaN are not treated the same way IEEE 754 does */
1160 if (unlikely(float32_is_quiet_nan(u
.f
))) {
1164 return float32_to_uint32_round_to_zero(u
.f
, &env
->vec_status
);
1167 static inline uint32_t efscfsf(CPUPPCState
*env
, uint32_t val
)
1172 u
.f
= int32_to_float32(val
, &env
->vec_status
);
1173 tmp
= int64_to_float32(1ULL << 32, &env
->vec_status
);
1174 u
.f
= float32_div(u
.f
, tmp
, &env
->vec_status
);
1179 static inline uint32_t efscfuf(CPUPPCState
*env
, uint32_t val
)
1184 u
.f
= uint32_to_float32(val
, &env
->vec_status
);
1185 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1186 u
.f
= float32_div(u
.f
, tmp
, &env
->vec_status
);
1191 static inline uint32_t efsctsf(CPUPPCState
*env
, uint32_t val
)
1197 /* NaN are not treated the same way IEEE 754 does */
1198 if (unlikely(float32_is_quiet_nan(u
.f
))) {
1201 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1202 u
.f
= float32_mul(u
.f
, tmp
, &env
->vec_status
);
1204 return float32_to_int32(u
.f
, &env
->vec_status
);
1207 static inline uint32_t efsctuf(CPUPPCState
*env
, uint32_t val
)
1213 /* NaN are not treated the same way IEEE 754 does */
1214 if (unlikely(float32_is_quiet_nan(u
.f
))) {
1217 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1218 u
.f
= float32_mul(u
.f
, tmp
, &env
->vec_status
);
1220 return float32_to_uint32(u
.f
, &env
->vec_status
);
1223 #define HELPER_SPE_SINGLE_CONV(name) \
1224 uint32_t helper_e##name(CPUPPCState *env, uint32_t val) \
1226 return e##name(env, val); \
1229 HELPER_SPE_SINGLE_CONV(fscfsi
);
1231 HELPER_SPE_SINGLE_CONV(fscfui
);
1233 HELPER_SPE_SINGLE_CONV(fscfuf
);
1235 HELPER_SPE_SINGLE_CONV(fscfsf
);
1237 HELPER_SPE_SINGLE_CONV(fsctsi
);
1239 HELPER_SPE_SINGLE_CONV(fsctui
);
1241 HELPER_SPE_SINGLE_CONV(fsctsiz
);
1243 HELPER_SPE_SINGLE_CONV(fsctuiz
);
1245 HELPER_SPE_SINGLE_CONV(fsctsf
);
1247 HELPER_SPE_SINGLE_CONV(fsctuf
);
1249 #define HELPER_SPE_VECTOR_CONV(name) \
1250 uint64_t helper_ev##name(CPUPPCState *env, uint64_t val) \
1252 return ((uint64_t)e##name(env, val >> 32) << 32) | \
1253 (uint64_t)e##name(env, val); \
1256 HELPER_SPE_VECTOR_CONV(fscfsi
);
1258 HELPER_SPE_VECTOR_CONV(fscfui
);
1260 HELPER_SPE_VECTOR_CONV(fscfuf
);
1262 HELPER_SPE_VECTOR_CONV(fscfsf
);
1264 HELPER_SPE_VECTOR_CONV(fsctsi
);
1266 HELPER_SPE_VECTOR_CONV(fsctui
);
1268 HELPER_SPE_VECTOR_CONV(fsctsiz
);
1270 HELPER_SPE_VECTOR_CONV(fsctuiz
);
1272 HELPER_SPE_VECTOR_CONV(fsctsf
);
1274 HELPER_SPE_VECTOR_CONV(fsctuf
);
1276 /* Single-precision floating-point arithmetic */
1277 static inline uint32_t efsadd(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1283 u1
.f
= float32_add(u1
.f
, u2
.f
, &env
->vec_status
);
1287 static inline uint32_t efssub(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1293 u1
.f
= float32_sub(u1
.f
, u2
.f
, &env
->vec_status
);
1297 static inline uint32_t efsmul(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1303 u1
.f
= float32_mul(u1
.f
, u2
.f
, &env
->vec_status
);
1307 static inline uint32_t efsdiv(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1313 u1
.f
= float32_div(u1
.f
, u2
.f
, &env
->vec_status
);
1317 #define HELPER_SPE_SINGLE_ARITH(name) \
1318 uint32_t helper_e##name(CPUPPCState *env, uint32_t op1, uint32_t op2) \
1320 return e##name(env, op1, op2); \
1323 HELPER_SPE_SINGLE_ARITH(fsadd
);
1325 HELPER_SPE_SINGLE_ARITH(fssub
);
1327 HELPER_SPE_SINGLE_ARITH(fsmul
);
1329 HELPER_SPE_SINGLE_ARITH(fsdiv
);
1331 #define HELPER_SPE_VECTOR_ARITH(name) \
1332 uint64_t helper_ev##name(CPUPPCState *env, uint64_t op1, uint64_t op2) \
1334 return ((uint64_t)e##name(env, op1 >> 32, op2 >> 32) << 32) | \
1335 (uint64_t)e##name(env, op1, op2); \
1338 HELPER_SPE_VECTOR_ARITH(fsadd
);
1340 HELPER_SPE_VECTOR_ARITH(fssub
);
1342 HELPER_SPE_VECTOR_ARITH(fsmul
);
1344 HELPER_SPE_VECTOR_ARITH(fsdiv
);
1346 /* Single-precision floating-point comparisons */
1347 static inline uint32_t efscmplt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1353 return float32_lt(u1
.f
, u2
.f
, &env
->vec_status
) ? 4 : 0;
1356 static inline uint32_t efscmpgt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1362 return float32_le(u1
.f
, u2
.f
, &env
->vec_status
) ? 0 : 4;
1365 static inline uint32_t efscmpeq(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1371 return float32_eq(u1
.f
, u2
.f
, &env
->vec_status
) ? 4 : 0;
1374 static inline uint32_t efststlt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1376 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1377 return efscmplt(env
, op1
, op2
);
1380 static inline uint32_t efststgt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1382 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1383 return efscmpgt(env
, op1
, op2
);
1386 static inline uint32_t efststeq(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1388 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1389 return efscmpeq(env
, op1
, op2
);
1392 #define HELPER_SINGLE_SPE_CMP(name) \
1393 uint32_t helper_e##name(CPUPPCState *env, uint32_t op1, uint32_t op2) \
1395 return e##name(env, op1, op2) << 2; \
1398 HELPER_SINGLE_SPE_CMP(fststlt
);
1400 HELPER_SINGLE_SPE_CMP(fststgt
);
1402 HELPER_SINGLE_SPE_CMP(fststeq
);
1404 HELPER_SINGLE_SPE_CMP(fscmplt
);
1406 HELPER_SINGLE_SPE_CMP(fscmpgt
);
1408 HELPER_SINGLE_SPE_CMP(fscmpeq
);
1410 static inline uint32_t evcmp_merge(int t0
, int t1
)
1412 return (t0
<< 3) | (t1
<< 2) | ((t0
| t1
) << 1) | (t0
& t1
);
1415 #define HELPER_VECTOR_SPE_CMP(name) \
1416 uint32_t helper_ev##name(CPUPPCState *env, uint64_t op1, uint64_t op2) \
1418 return evcmp_merge(e##name(env, op1 >> 32, op2 >> 32), \
1419 e##name(env, op1, op2)); \
1422 HELPER_VECTOR_SPE_CMP(fststlt
);
1424 HELPER_VECTOR_SPE_CMP(fststgt
);
1426 HELPER_VECTOR_SPE_CMP(fststeq
);
1428 HELPER_VECTOR_SPE_CMP(fscmplt
);
1430 HELPER_VECTOR_SPE_CMP(fscmpgt
);
1432 HELPER_VECTOR_SPE_CMP(fscmpeq
);
1434 /* Double-precision floating-point conversion */
1435 uint64_t helper_efdcfsi(CPUPPCState
*env
, uint32_t val
)
1439 u
.d
= int32_to_float64(val
, &env
->vec_status
);
1444 uint64_t helper_efdcfsid(CPUPPCState
*env
, uint64_t val
)
1448 u
.d
= int64_to_float64(val
, &env
->vec_status
);
1453 uint64_t helper_efdcfui(CPUPPCState
*env
, uint32_t val
)
1457 u
.d
= uint32_to_float64(val
, &env
->vec_status
);
1462 uint64_t helper_efdcfuid(CPUPPCState
*env
, uint64_t val
)
1466 u
.d
= uint64_to_float64(val
, &env
->vec_status
);
1471 uint32_t helper_efdctsi(CPUPPCState
*env
, uint64_t val
)
1476 /* NaN are not treated the same way IEEE 754 does */
1477 if (unlikely(float64_is_any_nan(u
.d
))) {
1481 return float64_to_int32(u
.d
, &env
->vec_status
);
1484 uint32_t helper_efdctui(CPUPPCState
*env
, uint64_t val
)
1489 /* NaN are not treated the same way IEEE 754 does */
1490 if (unlikely(float64_is_any_nan(u
.d
))) {
1494 return float64_to_uint32(u
.d
, &env
->vec_status
);
1497 uint32_t helper_efdctsiz(CPUPPCState
*env
, uint64_t val
)
1502 /* NaN are not treated the same way IEEE 754 does */
1503 if (unlikely(float64_is_any_nan(u
.d
))) {
1507 return float64_to_int32_round_to_zero(u
.d
, &env
->vec_status
);
1510 uint64_t helper_efdctsidz(CPUPPCState
*env
, uint64_t val
)
1515 /* NaN are not treated the same way IEEE 754 does */
1516 if (unlikely(float64_is_any_nan(u
.d
))) {
1520 return float64_to_int64_round_to_zero(u
.d
, &env
->vec_status
);
1523 uint32_t helper_efdctuiz(CPUPPCState
*env
, uint64_t val
)
1528 /* NaN are not treated the same way IEEE 754 does */
1529 if (unlikely(float64_is_any_nan(u
.d
))) {
1533 return float64_to_uint32_round_to_zero(u
.d
, &env
->vec_status
);
1536 uint64_t helper_efdctuidz(CPUPPCState
*env
, uint64_t val
)
1541 /* NaN are not treated the same way IEEE 754 does */
1542 if (unlikely(float64_is_any_nan(u
.d
))) {
1546 return float64_to_uint64_round_to_zero(u
.d
, &env
->vec_status
);
1549 uint64_t helper_efdcfsf(CPUPPCState
*env
, uint32_t val
)
1554 u
.d
= int32_to_float64(val
, &env
->vec_status
);
1555 tmp
= int64_to_float64(1ULL << 32, &env
->vec_status
);
1556 u
.d
= float64_div(u
.d
, tmp
, &env
->vec_status
);
1561 uint64_t helper_efdcfuf(CPUPPCState
*env
, uint32_t val
)
1566 u
.d
= uint32_to_float64(val
, &env
->vec_status
);
1567 tmp
= int64_to_float64(1ULL << 32, &env
->vec_status
);
1568 u
.d
= float64_div(u
.d
, tmp
, &env
->vec_status
);
1573 uint32_t helper_efdctsf(CPUPPCState
*env
, uint64_t val
)
1579 /* NaN are not treated the same way IEEE 754 does */
1580 if (unlikely(float64_is_any_nan(u
.d
))) {
1583 tmp
= uint64_to_float64(1ULL << 32, &env
->vec_status
);
1584 u
.d
= float64_mul(u
.d
, tmp
, &env
->vec_status
);
1586 return float64_to_int32(u
.d
, &env
->vec_status
);
1589 uint32_t helper_efdctuf(CPUPPCState
*env
, uint64_t val
)
1595 /* NaN are not treated the same way IEEE 754 does */
1596 if (unlikely(float64_is_any_nan(u
.d
))) {
1599 tmp
= uint64_to_float64(1ULL << 32, &env
->vec_status
);
1600 u
.d
= float64_mul(u
.d
, tmp
, &env
->vec_status
);
1602 return float64_to_uint32(u
.d
, &env
->vec_status
);
1605 uint32_t helper_efscfd(CPUPPCState
*env
, uint64_t val
)
1611 u2
.f
= float64_to_float32(u1
.d
, &env
->vec_status
);
1616 uint64_t helper_efdcfs(CPUPPCState
*env
, uint32_t val
)
1622 u2
.d
= float32_to_float64(u1
.f
, &env
->vec_status
);
1627 /* Double precision fixed-point arithmetic */
1628 uint64_t helper_efdadd(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1634 u1
.d
= float64_add(u1
.d
, u2
.d
, &env
->vec_status
);
1638 uint64_t helper_efdsub(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1644 u1
.d
= float64_sub(u1
.d
, u2
.d
, &env
->vec_status
);
1648 uint64_t helper_efdmul(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1654 u1
.d
= float64_mul(u1
.d
, u2
.d
, &env
->vec_status
);
1658 uint64_t helper_efddiv(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1664 u1
.d
= float64_div(u1
.d
, u2
.d
, &env
->vec_status
);
1668 /* Double precision floating point helpers */
1669 uint32_t helper_efdtstlt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1675 return float64_lt(u1
.d
, u2
.d
, &env
->vec_status
) ? 4 : 0;
1678 uint32_t helper_efdtstgt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1684 return float64_le(u1
.d
, u2
.d
, &env
->vec_status
) ? 0 : 4;
1687 uint32_t helper_efdtsteq(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1693 return float64_eq_quiet(u1
.d
, u2
.d
, &env
->vec_status
) ? 4 : 0;
1696 uint32_t helper_efdcmplt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1698 /* XXX: TODO: test special values (NaN, infinites, ...) */
1699 return helper_efdtstlt(env
, op1
, op2
);
1702 uint32_t helper_efdcmpgt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1704 /* XXX: TODO: test special values (NaN, infinites, ...) */
1705 return helper_efdtstgt(env
, op1
, op2
);
1708 uint32_t helper_efdcmpeq(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1710 /* XXX: TODO: test special values (NaN, infinites, ...) */
1711 return helper_efdtsteq(env
, op1
, op2
);