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
)
434 * We use only the 32 LSB of the incoming fpr
442 new |= prev
& 0x60000000;
443 for (i
= 0; i
< 8; i
++) {
444 if (mask
& (1 << i
)) {
445 env
->fpscr
&= ~(0xF << (4 * i
));
446 env
->fpscr
|= new & (0xF << (4 * i
));
449 /* Update VX and FEX */
451 env
->fpscr
|= 1 << FPSCR_VX
;
453 env
->fpscr
&= ~(1 << FPSCR_VX
);
455 if ((fpscr_ex
& fpscr_eex
) != 0) {
456 env
->fpscr
|= 1 << FPSCR_FEX
;
457 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
458 /* XXX: we should compute it properly */
459 env
->error_code
= POWERPC_EXCP_FP
;
461 env
->fpscr
&= ~(1 << FPSCR_FEX
);
463 fpscr_set_rounding_mode(env
);
466 void helper_float_check_status(CPUPPCState
*env
)
468 if (env
->exception_index
== POWERPC_EXCP_PROGRAM
&&
469 (env
->error_code
& POWERPC_EXCP_FP
)) {
470 /* Differred floating-point exception after target FPR update */
471 if (msr_fe0
!= 0 || msr_fe1
!= 0) {
472 helper_raise_exception_err(env
, env
->exception_index
,
476 int status
= get_float_exception_flags(&env
->fp_status
);
477 if (status
& float_flag_divbyzero
) {
478 float_zero_divide_excp(env
);
479 } else if (status
& float_flag_overflow
) {
480 float_overflow_excp(env
);
481 } else if (status
& float_flag_underflow
) {
482 float_underflow_excp(env
);
483 } else if (status
& float_flag_inexact
) {
484 float_inexact_excp(env
);
489 void helper_reset_fpstatus(CPUPPCState
*env
)
491 set_float_exception_flags(0, &env
->fp_status
);
495 uint64_t helper_fadd(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
)
497 CPU_DoubleU farg1
, farg2
;
502 if (unlikely(float64_is_infinity(farg1
.d
) && float64_is_infinity(farg2
.d
) &&
503 float64_is_neg(farg1
.d
) != float64_is_neg(farg2
.d
))) {
504 /* Magnitude subtraction of infinities */
505 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXISI
);
507 if (unlikely(float64_is_signaling_nan(farg1
.d
) ||
508 float64_is_signaling_nan(farg2
.d
))) {
510 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
512 farg1
.d
= float64_add(farg1
.d
, farg2
.d
, &env
->fp_status
);
519 uint64_t helper_fsub(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
)
521 CPU_DoubleU farg1
, farg2
;
526 if (unlikely(float64_is_infinity(farg1
.d
) && float64_is_infinity(farg2
.d
) &&
527 float64_is_neg(farg1
.d
) == float64_is_neg(farg2
.d
))) {
528 /* Magnitude subtraction of infinities */
529 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXISI
);
531 if (unlikely(float64_is_signaling_nan(farg1
.d
) ||
532 float64_is_signaling_nan(farg2
.d
))) {
533 /* sNaN subtraction */
534 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
536 farg1
.d
= float64_sub(farg1
.d
, farg2
.d
, &env
->fp_status
);
543 uint64_t helper_fmul(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
)
545 CPU_DoubleU farg1
, farg2
;
550 if (unlikely((float64_is_infinity(farg1
.d
) && float64_is_zero(farg2
.d
)) ||
551 (float64_is_zero(farg1
.d
) && float64_is_infinity(farg2
.d
)))) {
552 /* Multiplication of zero by infinity */
553 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXIMZ
);
555 if (unlikely(float64_is_signaling_nan(farg1
.d
) ||
556 float64_is_signaling_nan(farg2
.d
))) {
557 /* sNaN multiplication */
558 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
560 farg1
.d
= float64_mul(farg1
.d
, farg2
.d
, &env
->fp_status
);
567 uint64_t helper_fdiv(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
)
569 CPU_DoubleU farg1
, farg2
;
574 if (unlikely(float64_is_infinity(farg1
.d
) &&
575 float64_is_infinity(farg2
.d
))) {
576 /* Division of infinity by infinity */
577 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXIDI
);
578 } else if (unlikely(float64_is_zero(farg1
.d
) && float64_is_zero(farg2
.d
))) {
579 /* Division of zero by zero */
580 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXZDZ
);
582 if (unlikely(float64_is_signaling_nan(farg1
.d
) ||
583 float64_is_signaling_nan(farg2
.d
))) {
585 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
587 farg1
.d
= float64_div(farg1
.d
, farg2
.d
, &env
->fp_status
);
594 uint64_t helper_fabs(CPUPPCState
*env
, uint64_t arg
)
599 farg
.d
= float64_abs(farg
.d
);
604 uint64_t helper_fnabs(CPUPPCState
*env
, uint64_t arg
)
609 farg
.d
= float64_abs(farg
.d
);
610 farg
.d
= float64_chs(farg
.d
);
615 uint64_t helper_fneg(CPUPPCState
*env
, uint64_t arg
)
620 farg
.d
= float64_chs(farg
.d
);
625 uint64_t helper_fctiw(CPUPPCState
*env
, uint64_t arg
)
631 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
632 /* sNaN conversion */
633 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
|
634 POWERPC_EXCP_FP_VXCVI
);
635 } else if (unlikely(float64_is_quiet_nan(farg
.d
) ||
636 float64_is_infinity(farg
.d
))) {
637 /* qNan / infinity conversion */
638 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXCVI
);
640 farg
.ll
= float64_to_int32(farg
.d
, &env
->fp_status
);
641 /* XXX: higher bits are not supposed to be significant.
642 * to make tests easier, return the same as a real PowerPC 750
644 farg
.ll
|= 0xFFF80000ULL
<< 32;
649 /* fctiwz - fctiwz. */
650 uint64_t helper_fctiwz(CPUPPCState
*env
, uint64_t arg
)
656 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
657 /* sNaN conversion */
658 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
|
659 POWERPC_EXCP_FP_VXCVI
);
660 } else if (unlikely(float64_is_quiet_nan(farg
.d
) ||
661 float64_is_infinity(farg
.d
))) {
662 /* qNan / infinity conversion */
663 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXCVI
);
665 farg
.ll
= float64_to_int32_round_to_zero(farg
.d
, &env
->fp_status
);
666 /* XXX: higher bits are not supposed to be significant.
667 * to make tests easier, return the same as a real PowerPC 750
669 farg
.ll
|= 0xFFF80000ULL
<< 32;
674 #if defined(TARGET_PPC64)
676 uint64_t helper_fcfid(CPUPPCState
*env
, uint64_t arg
)
680 farg
.d
= int64_to_float64(arg
, &env
->fp_status
);
685 uint64_t helper_fctid(CPUPPCState
*env
, uint64_t arg
)
691 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
692 /* sNaN conversion */
693 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
|
694 POWERPC_EXCP_FP_VXCVI
);
695 } else if (unlikely(float64_is_quiet_nan(farg
.d
) ||
696 float64_is_infinity(farg
.d
))) {
697 /* qNan / infinity conversion */
698 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXCVI
);
700 farg
.ll
= float64_to_int64(farg
.d
, &env
->fp_status
);
705 /* fctidz - fctidz. */
706 uint64_t helper_fctidz(CPUPPCState
*env
, uint64_t arg
)
712 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
713 /* sNaN conversion */
714 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
|
715 POWERPC_EXCP_FP_VXCVI
);
716 } else if (unlikely(float64_is_quiet_nan(farg
.d
) ||
717 float64_is_infinity(farg
.d
))) {
718 /* qNan / infinity conversion */
719 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXCVI
);
721 farg
.ll
= float64_to_int64_round_to_zero(farg
.d
, &env
->fp_status
);
728 static inline uint64_t do_fri(CPUPPCState
*env
, uint64_t arg
,
735 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
737 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
|
738 POWERPC_EXCP_FP_VXCVI
);
739 } else if (unlikely(float64_is_quiet_nan(farg
.d
) ||
740 float64_is_infinity(farg
.d
))) {
741 /* qNan / infinity round */
742 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXCVI
);
744 set_float_rounding_mode(rounding_mode
, &env
->fp_status
);
745 farg
.ll
= float64_round_to_int(farg
.d
, &env
->fp_status
);
746 /* Restore rounding mode from FPSCR */
747 fpscr_set_rounding_mode(env
);
752 uint64_t helper_frin(CPUPPCState
*env
, uint64_t arg
)
754 return do_fri(env
, arg
, float_round_nearest_even
);
757 uint64_t helper_friz(CPUPPCState
*env
, uint64_t arg
)
759 return do_fri(env
, arg
, float_round_to_zero
);
762 uint64_t helper_frip(CPUPPCState
*env
, uint64_t arg
)
764 return do_fri(env
, arg
, float_round_up
);
767 uint64_t helper_frim(CPUPPCState
*env
, uint64_t arg
)
769 return do_fri(env
, arg
, float_round_down
);
773 uint64_t helper_fmadd(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
776 CPU_DoubleU farg1
, farg2
, farg3
;
782 if (unlikely((float64_is_infinity(farg1
.d
) && float64_is_zero(farg2
.d
)) ||
783 (float64_is_zero(farg1
.d
) && float64_is_infinity(farg2
.d
)))) {
784 /* Multiplication of zero by infinity */
785 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXIMZ
);
787 if (unlikely(float64_is_signaling_nan(farg1
.d
) ||
788 float64_is_signaling_nan(farg2
.d
) ||
789 float64_is_signaling_nan(farg3
.d
))) {
791 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
793 /* This is the way the PowerPC specification defines it */
794 float128 ft0_128
, ft1_128
;
796 ft0_128
= float64_to_float128(farg1
.d
, &env
->fp_status
);
797 ft1_128
= float64_to_float128(farg2
.d
, &env
->fp_status
);
798 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
799 if (unlikely(float128_is_infinity(ft0_128
) &&
800 float64_is_infinity(farg3
.d
) &&
801 float128_is_neg(ft0_128
) != float64_is_neg(farg3
.d
))) {
802 /* Magnitude subtraction of infinities */
803 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXISI
);
805 ft1_128
= float64_to_float128(farg3
.d
, &env
->fp_status
);
806 ft0_128
= float128_add(ft0_128
, ft1_128
, &env
->fp_status
);
807 farg1
.d
= float128_to_float64(ft0_128
, &env
->fp_status
);
815 uint64_t helper_fmsub(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
818 CPU_DoubleU farg1
, farg2
, farg3
;
824 if (unlikely((float64_is_infinity(farg1
.d
) && float64_is_zero(farg2
.d
)) ||
825 (float64_is_zero(farg1
.d
) &&
826 float64_is_infinity(farg2
.d
)))) {
827 /* Multiplication of zero by infinity */
828 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXIMZ
);
830 if (unlikely(float64_is_signaling_nan(farg1
.d
) ||
831 float64_is_signaling_nan(farg2
.d
) ||
832 float64_is_signaling_nan(farg3
.d
))) {
834 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
836 /* This is the way the PowerPC specification defines it */
837 float128 ft0_128
, ft1_128
;
839 ft0_128
= float64_to_float128(farg1
.d
, &env
->fp_status
);
840 ft1_128
= float64_to_float128(farg2
.d
, &env
->fp_status
);
841 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
842 if (unlikely(float128_is_infinity(ft0_128
) &&
843 float64_is_infinity(farg3
.d
) &&
844 float128_is_neg(ft0_128
) == float64_is_neg(farg3
.d
))) {
845 /* Magnitude subtraction of infinities */
846 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXISI
);
848 ft1_128
= float64_to_float128(farg3
.d
, &env
->fp_status
);
849 ft0_128
= float128_sub(ft0_128
, ft1_128
, &env
->fp_status
);
850 farg1
.d
= float128_to_float64(ft0_128
, &env
->fp_status
);
856 /* fnmadd - fnmadd. */
857 uint64_t helper_fnmadd(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
860 CPU_DoubleU farg1
, farg2
, farg3
;
866 if (unlikely((float64_is_infinity(farg1
.d
) && float64_is_zero(farg2
.d
)) ||
867 (float64_is_zero(farg1
.d
) && float64_is_infinity(farg2
.d
)))) {
868 /* Multiplication of zero by infinity */
869 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXIMZ
);
871 if (unlikely(float64_is_signaling_nan(farg1
.d
) ||
872 float64_is_signaling_nan(farg2
.d
) ||
873 float64_is_signaling_nan(farg3
.d
))) {
875 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
877 /* This is the way the PowerPC specification defines it */
878 float128 ft0_128
, ft1_128
;
880 ft0_128
= float64_to_float128(farg1
.d
, &env
->fp_status
);
881 ft1_128
= float64_to_float128(farg2
.d
, &env
->fp_status
);
882 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
883 if (unlikely(float128_is_infinity(ft0_128
) &&
884 float64_is_infinity(farg3
.d
) &&
885 float128_is_neg(ft0_128
) != float64_is_neg(farg3
.d
))) {
886 /* Magnitude subtraction of infinities */
887 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXISI
);
889 ft1_128
= float64_to_float128(farg3
.d
, &env
->fp_status
);
890 ft0_128
= float128_add(ft0_128
, ft1_128
, &env
->fp_status
);
891 farg1
.d
= float128_to_float64(ft0_128
, &env
->fp_status
);
893 if (likely(!float64_is_any_nan(farg1
.d
))) {
894 farg1
.d
= float64_chs(farg1
.d
);
900 /* fnmsub - fnmsub. */
901 uint64_t helper_fnmsub(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
904 CPU_DoubleU farg1
, farg2
, farg3
;
910 if (unlikely((float64_is_infinity(farg1
.d
) && float64_is_zero(farg2
.d
)) ||
911 (float64_is_zero(farg1
.d
) &&
912 float64_is_infinity(farg2
.d
)))) {
913 /* Multiplication of zero by infinity */
914 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXIMZ
);
916 if (unlikely(float64_is_signaling_nan(farg1
.d
) ||
917 float64_is_signaling_nan(farg2
.d
) ||
918 float64_is_signaling_nan(farg3
.d
))) {
920 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
922 /* This is the way the PowerPC specification defines it */
923 float128 ft0_128
, ft1_128
;
925 ft0_128
= float64_to_float128(farg1
.d
, &env
->fp_status
);
926 ft1_128
= float64_to_float128(farg2
.d
, &env
->fp_status
);
927 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
928 if (unlikely(float128_is_infinity(ft0_128
) &&
929 float64_is_infinity(farg3
.d
) &&
930 float128_is_neg(ft0_128
) == float64_is_neg(farg3
.d
))) {
931 /* Magnitude subtraction of infinities */
932 farg1
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXISI
);
934 ft1_128
= float64_to_float128(farg3
.d
, &env
->fp_status
);
935 ft0_128
= float128_sub(ft0_128
, ft1_128
, &env
->fp_status
);
936 farg1
.d
= float128_to_float64(ft0_128
, &env
->fp_status
);
938 if (likely(!float64_is_any_nan(farg1
.d
))) {
939 farg1
.d
= float64_chs(farg1
.d
);
946 uint64_t helper_frsp(CPUPPCState
*env
, uint64_t arg
)
953 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
954 /* sNaN square root */
955 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
957 f32
= float64_to_float32(farg
.d
, &env
->fp_status
);
958 farg
.d
= float32_to_float64(f32
, &env
->fp_status
);
964 uint64_t helper_fsqrt(CPUPPCState
*env
, uint64_t arg
)
970 if (unlikely(float64_is_neg(farg
.d
) && !float64_is_zero(farg
.d
))) {
971 /* Square root of a negative nonzero number */
972 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSQRT
);
974 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
975 /* sNaN square root */
976 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
978 farg
.d
= float64_sqrt(farg
.d
, &env
->fp_status
);
984 uint64_t helper_fre(CPUPPCState
*env
, uint64_t arg
)
990 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
991 /* sNaN reciprocal */
992 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
994 farg
.d
= float64_div(float64_one
, farg
.d
, &env
->fp_status
);
999 uint64_t helper_fres(CPUPPCState
*env
, uint64_t arg
)
1006 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
1007 /* sNaN reciprocal */
1008 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
1010 farg
.d
= float64_div(float64_one
, farg
.d
, &env
->fp_status
);
1011 f32
= float64_to_float32(farg
.d
, &env
->fp_status
);
1012 farg
.d
= float32_to_float64(f32
, &env
->fp_status
);
1017 /* frsqrte - frsqrte. */
1018 uint64_t helper_frsqrte(CPUPPCState
*env
, uint64_t arg
)
1025 if (unlikely(float64_is_neg(farg
.d
) && !float64_is_zero(farg
.d
))) {
1026 /* Reciprocal square root of a negative nonzero number */
1027 farg
.ll
= fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSQRT
);
1029 if (unlikely(float64_is_signaling_nan(farg
.d
))) {
1030 /* sNaN reciprocal square root */
1031 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
1033 farg
.d
= float64_sqrt(farg
.d
, &env
->fp_status
);
1034 farg
.d
= float64_div(float64_one
, farg
.d
, &env
->fp_status
);
1035 f32
= float64_to_float32(farg
.d
, &env
->fp_status
);
1036 farg
.d
= float32_to_float64(f32
, &env
->fp_status
);
1042 uint64_t helper_fsel(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
1049 if ((!float64_is_neg(farg1
.d
) || float64_is_zero(farg1
.d
)) &&
1050 !float64_is_any_nan(farg1
.d
)) {
1057 void helper_fcmpu(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
1060 CPU_DoubleU farg1
, farg2
;
1066 if (unlikely(float64_is_any_nan(farg1
.d
) ||
1067 float64_is_any_nan(farg2
.d
))) {
1069 } else if (float64_lt(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1071 } else if (!float64_le(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1077 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
1078 env
->fpscr
|= ret
<< FPSCR_FPRF
;
1079 env
->crf
[crfD
] = ret
;
1080 if (unlikely(ret
== 0x01UL
1081 && (float64_is_signaling_nan(farg1
.d
) ||
1082 float64_is_signaling_nan(farg2
.d
)))) {
1083 /* sNaN comparison */
1084 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
);
1088 void helper_fcmpo(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
1091 CPU_DoubleU farg1
, farg2
;
1097 if (unlikely(float64_is_any_nan(farg1
.d
) ||
1098 float64_is_any_nan(farg2
.d
))) {
1100 } else if (float64_lt(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1102 } else if (!float64_le(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1108 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
1109 env
->fpscr
|= ret
<< FPSCR_FPRF
;
1110 env
->crf
[crfD
] = ret
;
1111 if (unlikely(ret
== 0x01UL
)) {
1112 if (float64_is_signaling_nan(farg1
.d
) ||
1113 float64_is_signaling_nan(farg2
.d
)) {
1114 /* sNaN comparison */
1115 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
|
1116 POWERPC_EXCP_FP_VXVC
);
1118 /* qNaN comparison */
1119 fload_invalid_op_excp(env
, POWERPC_EXCP_FP_VXVC
);
1124 /* Single-precision floating-point conversions */
1125 static inline uint32_t efscfsi(CPUPPCState
*env
, uint32_t val
)
1129 u
.f
= int32_to_float32(val
, &env
->vec_status
);
1134 static inline uint32_t efscfui(CPUPPCState
*env
, uint32_t val
)
1138 u
.f
= uint32_to_float32(val
, &env
->vec_status
);
1143 static inline int32_t efsctsi(CPUPPCState
*env
, uint32_t val
)
1148 /* NaN are not treated the same way IEEE 754 does */
1149 if (unlikely(float32_is_quiet_nan(u
.f
))) {
1153 return float32_to_int32(u
.f
, &env
->vec_status
);
1156 static inline uint32_t efsctui(CPUPPCState
*env
, uint32_t val
)
1161 /* NaN are not treated the same way IEEE 754 does */
1162 if (unlikely(float32_is_quiet_nan(u
.f
))) {
1166 return float32_to_uint32(u
.f
, &env
->vec_status
);
1169 static inline uint32_t efsctsiz(CPUPPCState
*env
, uint32_t val
)
1174 /* NaN are not treated the same way IEEE 754 does */
1175 if (unlikely(float32_is_quiet_nan(u
.f
))) {
1179 return float32_to_int32_round_to_zero(u
.f
, &env
->vec_status
);
1182 static inline uint32_t efsctuiz(CPUPPCState
*env
, uint32_t val
)
1187 /* NaN are not treated the same way IEEE 754 does */
1188 if (unlikely(float32_is_quiet_nan(u
.f
))) {
1192 return float32_to_uint32_round_to_zero(u
.f
, &env
->vec_status
);
1195 static inline uint32_t efscfsf(CPUPPCState
*env
, uint32_t val
)
1200 u
.f
= int32_to_float32(val
, &env
->vec_status
);
1201 tmp
= int64_to_float32(1ULL << 32, &env
->vec_status
);
1202 u
.f
= float32_div(u
.f
, tmp
, &env
->vec_status
);
1207 static inline uint32_t efscfuf(CPUPPCState
*env
, uint32_t val
)
1212 u
.f
= uint32_to_float32(val
, &env
->vec_status
);
1213 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1214 u
.f
= float32_div(u
.f
, tmp
, &env
->vec_status
);
1219 static inline uint32_t efsctsf(CPUPPCState
*env
, uint32_t val
)
1225 /* NaN are not treated the same way IEEE 754 does */
1226 if (unlikely(float32_is_quiet_nan(u
.f
))) {
1229 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1230 u
.f
= float32_mul(u
.f
, tmp
, &env
->vec_status
);
1232 return float32_to_int32(u
.f
, &env
->vec_status
);
1235 static inline uint32_t efsctuf(CPUPPCState
*env
, uint32_t val
)
1241 /* NaN are not treated the same way IEEE 754 does */
1242 if (unlikely(float32_is_quiet_nan(u
.f
))) {
1245 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1246 u
.f
= float32_mul(u
.f
, tmp
, &env
->vec_status
);
1248 return float32_to_uint32(u
.f
, &env
->vec_status
);
1251 #define HELPER_SPE_SINGLE_CONV(name) \
1252 uint32_t helper_e##name(CPUPPCState *env, uint32_t val) \
1254 return e##name(env, val); \
1257 HELPER_SPE_SINGLE_CONV(fscfsi
);
1259 HELPER_SPE_SINGLE_CONV(fscfui
);
1261 HELPER_SPE_SINGLE_CONV(fscfuf
);
1263 HELPER_SPE_SINGLE_CONV(fscfsf
);
1265 HELPER_SPE_SINGLE_CONV(fsctsi
);
1267 HELPER_SPE_SINGLE_CONV(fsctui
);
1269 HELPER_SPE_SINGLE_CONV(fsctsiz
);
1271 HELPER_SPE_SINGLE_CONV(fsctuiz
);
1273 HELPER_SPE_SINGLE_CONV(fsctsf
);
1275 HELPER_SPE_SINGLE_CONV(fsctuf
);
1277 #define HELPER_SPE_VECTOR_CONV(name) \
1278 uint64_t helper_ev##name(CPUPPCState *env, uint64_t val) \
1280 return ((uint64_t)e##name(env, val >> 32) << 32) | \
1281 (uint64_t)e##name(env, val); \
1284 HELPER_SPE_VECTOR_CONV(fscfsi
);
1286 HELPER_SPE_VECTOR_CONV(fscfui
);
1288 HELPER_SPE_VECTOR_CONV(fscfuf
);
1290 HELPER_SPE_VECTOR_CONV(fscfsf
);
1292 HELPER_SPE_VECTOR_CONV(fsctsi
);
1294 HELPER_SPE_VECTOR_CONV(fsctui
);
1296 HELPER_SPE_VECTOR_CONV(fsctsiz
);
1298 HELPER_SPE_VECTOR_CONV(fsctuiz
);
1300 HELPER_SPE_VECTOR_CONV(fsctsf
);
1302 HELPER_SPE_VECTOR_CONV(fsctuf
);
1304 /* Single-precision floating-point arithmetic */
1305 static inline uint32_t efsadd(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1311 u1
.f
= float32_add(u1
.f
, u2
.f
, &env
->vec_status
);
1315 static inline uint32_t efssub(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1321 u1
.f
= float32_sub(u1
.f
, u2
.f
, &env
->vec_status
);
1325 static inline uint32_t efsmul(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1331 u1
.f
= float32_mul(u1
.f
, u2
.f
, &env
->vec_status
);
1335 static inline uint32_t efsdiv(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1341 u1
.f
= float32_div(u1
.f
, u2
.f
, &env
->vec_status
);
1345 #define HELPER_SPE_SINGLE_ARITH(name) \
1346 uint32_t helper_e##name(CPUPPCState *env, uint32_t op1, uint32_t op2) \
1348 return e##name(env, op1, op2); \
1351 HELPER_SPE_SINGLE_ARITH(fsadd
);
1353 HELPER_SPE_SINGLE_ARITH(fssub
);
1355 HELPER_SPE_SINGLE_ARITH(fsmul
);
1357 HELPER_SPE_SINGLE_ARITH(fsdiv
);
1359 #define HELPER_SPE_VECTOR_ARITH(name) \
1360 uint64_t helper_ev##name(CPUPPCState *env, uint64_t op1, uint64_t op2) \
1362 return ((uint64_t)e##name(env, op1 >> 32, op2 >> 32) << 32) | \
1363 (uint64_t)e##name(env, op1, op2); \
1366 HELPER_SPE_VECTOR_ARITH(fsadd
);
1368 HELPER_SPE_VECTOR_ARITH(fssub
);
1370 HELPER_SPE_VECTOR_ARITH(fsmul
);
1372 HELPER_SPE_VECTOR_ARITH(fsdiv
);
1374 /* Single-precision floating-point comparisons */
1375 static inline uint32_t efscmplt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1381 return float32_lt(u1
.f
, u2
.f
, &env
->vec_status
) ? 4 : 0;
1384 static inline uint32_t efscmpgt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1390 return float32_le(u1
.f
, u2
.f
, &env
->vec_status
) ? 0 : 4;
1393 static inline uint32_t efscmpeq(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1399 return float32_eq(u1
.f
, u2
.f
, &env
->vec_status
) ? 4 : 0;
1402 static inline uint32_t efststlt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1404 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1405 return efscmplt(env
, op1
, op2
);
1408 static inline uint32_t efststgt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1410 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1411 return efscmpgt(env
, op1
, op2
);
1414 static inline uint32_t efststeq(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1416 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1417 return efscmpeq(env
, op1
, op2
);
1420 #define HELPER_SINGLE_SPE_CMP(name) \
1421 uint32_t helper_e##name(CPUPPCState *env, uint32_t op1, uint32_t op2) \
1423 return e##name(env, op1, op2) << 2; \
1426 HELPER_SINGLE_SPE_CMP(fststlt
);
1428 HELPER_SINGLE_SPE_CMP(fststgt
);
1430 HELPER_SINGLE_SPE_CMP(fststeq
);
1432 HELPER_SINGLE_SPE_CMP(fscmplt
);
1434 HELPER_SINGLE_SPE_CMP(fscmpgt
);
1436 HELPER_SINGLE_SPE_CMP(fscmpeq
);
1438 static inline uint32_t evcmp_merge(int t0
, int t1
)
1440 return (t0
<< 3) | (t1
<< 2) | ((t0
| t1
) << 1) | (t0
& t1
);
1443 #define HELPER_VECTOR_SPE_CMP(name) \
1444 uint32_t helper_ev##name(CPUPPCState *env, uint64_t op1, uint64_t op2) \
1446 return evcmp_merge(e##name(env, op1 >> 32, op2 >> 32), \
1447 e##name(env, op1, op2)); \
1450 HELPER_VECTOR_SPE_CMP(fststlt
);
1452 HELPER_VECTOR_SPE_CMP(fststgt
);
1454 HELPER_VECTOR_SPE_CMP(fststeq
);
1456 HELPER_VECTOR_SPE_CMP(fscmplt
);
1458 HELPER_VECTOR_SPE_CMP(fscmpgt
);
1460 HELPER_VECTOR_SPE_CMP(fscmpeq
);
1462 /* Double-precision floating-point conversion */
1463 uint64_t helper_efdcfsi(CPUPPCState
*env
, uint32_t val
)
1467 u
.d
= int32_to_float64(val
, &env
->vec_status
);
1472 uint64_t helper_efdcfsid(CPUPPCState
*env
, uint64_t val
)
1476 u
.d
= int64_to_float64(val
, &env
->vec_status
);
1481 uint64_t helper_efdcfui(CPUPPCState
*env
, uint32_t val
)
1485 u
.d
= uint32_to_float64(val
, &env
->vec_status
);
1490 uint64_t helper_efdcfuid(CPUPPCState
*env
, uint64_t val
)
1494 u
.d
= uint64_to_float64(val
, &env
->vec_status
);
1499 uint32_t helper_efdctsi(CPUPPCState
*env
, uint64_t val
)
1504 /* NaN are not treated the same way IEEE 754 does */
1505 if (unlikely(float64_is_any_nan(u
.d
))) {
1509 return float64_to_int32(u
.d
, &env
->vec_status
);
1512 uint32_t helper_efdctui(CPUPPCState
*env
, uint64_t val
)
1517 /* NaN are not treated the same way IEEE 754 does */
1518 if (unlikely(float64_is_any_nan(u
.d
))) {
1522 return float64_to_uint32(u
.d
, &env
->vec_status
);
1525 uint32_t helper_efdctsiz(CPUPPCState
*env
, uint64_t val
)
1530 /* NaN are not treated the same way IEEE 754 does */
1531 if (unlikely(float64_is_any_nan(u
.d
))) {
1535 return float64_to_int32_round_to_zero(u
.d
, &env
->vec_status
);
1538 uint64_t helper_efdctsidz(CPUPPCState
*env
, uint64_t val
)
1543 /* NaN are not treated the same way IEEE 754 does */
1544 if (unlikely(float64_is_any_nan(u
.d
))) {
1548 return float64_to_int64_round_to_zero(u
.d
, &env
->vec_status
);
1551 uint32_t helper_efdctuiz(CPUPPCState
*env
, uint64_t val
)
1556 /* NaN are not treated the same way IEEE 754 does */
1557 if (unlikely(float64_is_any_nan(u
.d
))) {
1561 return float64_to_uint32_round_to_zero(u
.d
, &env
->vec_status
);
1564 uint64_t helper_efdctuidz(CPUPPCState
*env
, uint64_t val
)
1569 /* NaN are not treated the same way IEEE 754 does */
1570 if (unlikely(float64_is_any_nan(u
.d
))) {
1574 return float64_to_uint64_round_to_zero(u
.d
, &env
->vec_status
);
1577 uint64_t helper_efdcfsf(CPUPPCState
*env
, uint32_t val
)
1582 u
.d
= int32_to_float64(val
, &env
->vec_status
);
1583 tmp
= int64_to_float64(1ULL << 32, &env
->vec_status
);
1584 u
.d
= float64_div(u
.d
, tmp
, &env
->vec_status
);
1589 uint64_t helper_efdcfuf(CPUPPCState
*env
, uint32_t val
)
1594 u
.d
= uint32_to_float64(val
, &env
->vec_status
);
1595 tmp
= int64_to_float64(1ULL << 32, &env
->vec_status
);
1596 u
.d
= float64_div(u
.d
, tmp
, &env
->vec_status
);
1601 uint32_t helper_efdctsf(CPUPPCState
*env
, uint64_t val
)
1607 /* NaN are not treated the same way IEEE 754 does */
1608 if (unlikely(float64_is_any_nan(u
.d
))) {
1611 tmp
= uint64_to_float64(1ULL << 32, &env
->vec_status
);
1612 u
.d
= float64_mul(u
.d
, tmp
, &env
->vec_status
);
1614 return float64_to_int32(u
.d
, &env
->vec_status
);
1617 uint32_t helper_efdctuf(CPUPPCState
*env
, uint64_t val
)
1623 /* NaN are not treated the same way IEEE 754 does */
1624 if (unlikely(float64_is_any_nan(u
.d
))) {
1627 tmp
= uint64_to_float64(1ULL << 32, &env
->vec_status
);
1628 u
.d
= float64_mul(u
.d
, tmp
, &env
->vec_status
);
1630 return float64_to_uint32(u
.d
, &env
->vec_status
);
1633 uint32_t helper_efscfd(CPUPPCState
*env
, uint64_t val
)
1639 u2
.f
= float64_to_float32(u1
.d
, &env
->vec_status
);
1644 uint64_t helper_efdcfs(CPUPPCState
*env
, uint32_t val
)
1650 u2
.d
= float32_to_float64(u1
.f
, &env
->vec_status
);
1655 /* Double precision fixed-point arithmetic */
1656 uint64_t helper_efdadd(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1662 u1
.d
= float64_add(u1
.d
, u2
.d
, &env
->vec_status
);
1666 uint64_t helper_efdsub(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1672 u1
.d
= float64_sub(u1
.d
, u2
.d
, &env
->vec_status
);
1676 uint64_t helper_efdmul(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1682 u1
.d
= float64_mul(u1
.d
, u2
.d
, &env
->vec_status
);
1686 uint64_t helper_efddiv(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1692 u1
.d
= float64_div(u1
.d
, u2
.d
, &env
->vec_status
);
1696 /* Double precision floating point helpers */
1697 uint32_t helper_efdtstlt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1703 return float64_lt(u1
.d
, u2
.d
, &env
->vec_status
) ? 4 : 0;
1706 uint32_t helper_efdtstgt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1712 return float64_le(u1
.d
, u2
.d
, &env
->vec_status
) ? 0 : 4;
1715 uint32_t helper_efdtsteq(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1721 return float64_eq_quiet(u1
.d
, u2
.d
, &env
->vec_status
) ? 4 : 0;
1724 uint32_t helper_efdcmplt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1726 /* XXX: TODO: test special values (NaN, infinites, ...) */
1727 return helper_efdtstlt(env
, op1
, op2
);
1730 uint32_t helper_efdcmpgt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1732 /* XXX: TODO: test special values (NaN, infinites, ...) */
1733 return helper_efdtstgt(env
, op1
, op2
);
1736 uint32_t helper_efdcmpeq(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1738 /* XXX: TODO: test special values (NaN, infinites, ...) */
1739 return helper_efdtsteq(env
, op1
, op2
);