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/>.
19 #include "qemu/osdep.h"
21 #include "exec/helper-proto.h"
22 #include "exec/exec-all.h"
24 #include "fpu/softfloat.h"
26 static inline float128
float128_snan_to_qnan(float128 x
)
30 r
.high
= x
.high
| 0x0000800000000000;
35 #define float64_snan_to_qnan(x) ((x) | 0x0008000000000000ULL)
36 #define float32_snan_to_qnan(x) ((x) | 0x00400000)
37 #define float16_snan_to_qnan(x) ((x) | 0x0200)
39 static inline bool fp_exceptions_enabled(CPUPPCState
*env
)
41 #ifdef CONFIG_USER_ONLY
44 return (env
->msr
& ((1U << MSR_FE0
) | (1U << MSR_FE1
))) != 0;
48 /*****************************************************************************/
49 /* Floating point operations helpers */
52 * This is the non-arithmatic conversion that happens e.g. on loads.
53 * In the Power ISA pseudocode, this is called DOUBLE.
55 uint64_t helper_todouble(uint32_t arg
)
57 uint32_t abs_arg
= arg
& 0x7fffffff;
60 if (likely(abs_arg
>= 0x00800000)) {
61 /* Normalized operand, or Inf, or NaN. */
62 ret
= (uint64_t)extract32(arg
, 30, 2) << 62;
63 ret
|= ((extract32(arg
, 30, 1) ^ 1) * (uint64_t)7) << 59;
64 ret
|= (uint64_t)extract32(arg
, 0, 30) << 29;
66 /* Zero or Denormalized operand. */
67 ret
= (uint64_t)extract32(arg
, 31, 1) << 63;
68 if (unlikely(abs_arg
!= 0)) {
69 /* Denormalized operand. */
70 int shift
= clz32(abs_arg
) - 9;
71 int exp
= -126 - shift
+ 1023;
72 ret
|= (uint64_t)exp
<< 52;
73 ret
|= abs_arg
<< (shift
+ 29);
80 * This is the non-arithmatic conversion that happens e.g. on stores.
81 * In the Power ISA pseudocode, this is called SINGLE.
83 uint32_t helper_tosingle(uint64_t arg
)
85 int exp
= extract64(arg
, 52, 11);
88 if (likely(exp
> 896)) {
89 /* No denormalization required (includes Inf, NaN). */
90 ret
= extract64(arg
, 62, 2) << 30;
91 ret
|= extract64(arg
, 29, 30);
93 /* Zero or Denormal result. If the exponent is in bounds for
94 * a single-precision denormal result, extract the proper bits.
95 * If the input is not zero, and the exponent is out of bounds,
96 * then the result is undefined; this underflows to zero.
98 ret
= extract64(arg
, 63, 1) << 31;
99 if (unlikely(exp
>= 874)) {
100 /* Denormal result. */
101 ret
|= ((1ULL << 52) | extract64(arg
, 0, 52)) >> (896 + 30 - exp
);
107 static inline int ppc_float32_get_unbiased_exp(float32 f
)
109 return ((f
>> 23) & 0xFF) - 127;
112 static inline int ppc_float64_get_unbiased_exp(float64 f
)
114 return ((f
>> 52) & 0x7FF) - 1023;
117 /* Classify a floating-point number. */
128 #define COMPUTE_CLASS(tp) \
129 static int tp##_classify(tp arg) \
131 int ret = tp##_is_neg(arg) * is_neg; \
132 if (unlikely(tp##_is_any_nan(arg))) { \
133 float_status dummy = { }; /* snan_bit_is_one = 0 */ \
134 ret |= (tp##_is_signaling_nan(arg, &dummy) \
135 ? is_snan : is_qnan); \
136 } else if (unlikely(tp##_is_infinity(arg))) { \
138 } else if (tp##_is_zero(arg)) { \
140 } else if (tp##_is_zero_or_denormal(arg)) { \
141 ret |= is_denormal; \
148 COMPUTE_CLASS(float16
)
149 COMPUTE_CLASS(float32
)
150 COMPUTE_CLASS(float64
)
151 COMPUTE_CLASS(float128
)
153 static void set_fprf_from_class(CPUPPCState
*env
, int class)
155 static const uint8_t fprf
[6][2] = {
156 { 0x04, 0x08 }, /* normalized */
157 { 0x02, 0x12 }, /* zero */
158 { 0x14, 0x18 }, /* denormalized */
159 { 0x05, 0x09 }, /* infinity */
160 { 0x11, 0x11 }, /* qnan */
161 { 0x00, 0x00 }, /* snan -- flags are undefined */
163 bool isneg
= class & is_neg
;
165 env
->fpscr
&= ~(0x1F << FPSCR_FPRF
);
166 env
->fpscr
|= fprf
[ctz32(class)][isneg
] << FPSCR_FPRF
;
169 #define COMPUTE_FPRF(tp) \
170 void helper_compute_fprf_##tp(CPUPPCState *env, tp arg) \
172 set_fprf_from_class(env, tp##_classify(arg)); \
175 COMPUTE_FPRF(float16
)
176 COMPUTE_FPRF(float32
)
177 COMPUTE_FPRF(float64
)
178 COMPUTE_FPRF(float128
)
180 /* Floating-point invalid operations exception */
181 static void finish_invalid_op_excp(CPUPPCState
*env
, int op
, uintptr_t retaddr
)
183 /* Update the floating-point invalid operation summary */
184 env
->fpscr
|= 1 << FPSCR_VX
;
185 /* Update the floating-point exception summary */
188 /* Update the floating-point enabled exception summary */
189 env
->fpscr
|= 1 << FPSCR_FEX
;
190 if (fp_exceptions_enabled(env
)) {
191 raise_exception_err_ra(env
, POWERPC_EXCP_PROGRAM
,
192 POWERPC_EXCP_FP
| op
, retaddr
);
197 static void finish_invalid_op_arith(CPUPPCState
*env
, int op
,
198 bool set_fpcc
, uintptr_t retaddr
)
200 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
203 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
204 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
207 finish_invalid_op_excp(env
, op
, retaddr
);
211 static void float_invalid_op_vxsnan(CPUPPCState
*env
, uintptr_t retaddr
)
213 env
->fpscr
|= 1 << FPSCR_VXSNAN
;
214 finish_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
, retaddr
);
217 /* Magnitude subtraction of infinities */
218 static void float_invalid_op_vxisi(CPUPPCState
*env
, bool set_fpcc
,
221 env
->fpscr
|= 1 << FPSCR_VXISI
;
222 finish_invalid_op_arith(env
, POWERPC_EXCP_FP_VXISI
, set_fpcc
, retaddr
);
225 /* Division of infinity by infinity */
226 static void float_invalid_op_vxidi(CPUPPCState
*env
, bool set_fpcc
,
229 env
->fpscr
|= 1 << FPSCR_VXIDI
;
230 finish_invalid_op_arith(env
, POWERPC_EXCP_FP_VXIDI
, set_fpcc
, retaddr
);
233 /* Division of zero by zero */
234 static void float_invalid_op_vxzdz(CPUPPCState
*env
, bool set_fpcc
,
237 env
->fpscr
|= 1 << FPSCR_VXZDZ
;
238 finish_invalid_op_arith(env
, POWERPC_EXCP_FP_VXZDZ
, set_fpcc
, retaddr
);
241 /* Multiplication of zero by infinity */
242 static void float_invalid_op_vximz(CPUPPCState
*env
, bool set_fpcc
,
245 env
->fpscr
|= 1 << FPSCR_VXIMZ
;
246 finish_invalid_op_arith(env
, POWERPC_EXCP_FP_VXIMZ
, set_fpcc
, retaddr
);
249 /* Square root of a negative number */
250 static void float_invalid_op_vxsqrt(CPUPPCState
*env
, bool set_fpcc
,
253 env
->fpscr
|= 1 << FPSCR_VXSQRT
;
254 finish_invalid_op_arith(env
, POWERPC_EXCP_FP_VXSQRT
, set_fpcc
, retaddr
);
257 /* Ordered comparison of NaN */
258 static void float_invalid_op_vxvc(CPUPPCState
*env
, bool set_fpcc
,
261 env
->fpscr
|= 1 << FPSCR_VXVC
;
263 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
264 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
266 /* Update the floating-point invalid operation summary */
267 env
->fpscr
|= 1 << FPSCR_VX
;
268 /* Update the floating-point exception summary */
270 /* We must update the target FPR before raising the exception */
272 CPUState
*cs
= CPU(ppc_env_get_cpu(env
));
274 cs
->exception_index
= POWERPC_EXCP_PROGRAM
;
275 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_VXVC
;
276 /* Update the floating-point enabled exception summary */
277 env
->fpscr
|= 1 << FPSCR_FEX
;
278 /* Exception is differed */
282 /* Invalid conversion */
283 static void float_invalid_op_vxcvi(CPUPPCState
*env
, bool set_fpcc
,
286 env
->fpscr
|= 1 << FPSCR_VXCVI
;
287 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
290 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
291 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
294 finish_invalid_op_excp(env
, POWERPC_EXCP_FP_VXCVI
, retaddr
);
297 static inline void float_zero_divide_excp(CPUPPCState
*env
, uintptr_t raddr
)
299 env
->fpscr
|= 1 << FPSCR_ZX
;
300 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
301 /* Update the floating-point exception summary */
304 /* Update the floating-point enabled exception summary */
305 env
->fpscr
|= 1 << FPSCR_FEX
;
306 if (fp_exceptions_enabled(env
)) {
307 raise_exception_err_ra(env
, POWERPC_EXCP_PROGRAM
,
308 POWERPC_EXCP_FP
| POWERPC_EXCP_FP_ZX
,
314 static inline void float_overflow_excp(CPUPPCState
*env
)
316 CPUState
*cs
= CPU(ppc_env_get_cpu(env
));
318 env
->fpscr
|= 1 << FPSCR_OX
;
319 /* Update the floating-point exception summary */
322 /* XXX: should adjust the result */
323 /* Update the floating-point enabled exception summary */
324 env
->fpscr
|= 1 << FPSCR_FEX
;
325 /* We must update the target FPR before raising the exception */
326 cs
->exception_index
= POWERPC_EXCP_PROGRAM
;
327 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_OX
;
329 env
->fpscr
|= 1 << FPSCR_XX
;
330 env
->fpscr
|= 1 << FPSCR_FI
;
334 static inline void float_underflow_excp(CPUPPCState
*env
)
336 CPUState
*cs
= CPU(ppc_env_get_cpu(env
));
338 env
->fpscr
|= 1 << FPSCR_UX
;
339 /* Update the floating-point exception summary */
342 /* XXX: should adjust the result */
343 /* Update the floating-point enabled exception summary */
344 env
->fpscr
|= 1 << FPSCR_FEX
;
345 /* We must update the target FPR before raising the exception */
346 cs
->exception_index
= POWERPC_EXCP_PROGRAM
;
347 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_UX
;
351 static inline void float_inexact_excp(CPUPPCState
*env
)
353 CPUState
*cs
= CPU(ppc_env_get_cpu(env
));
355 env
->fpscr
|= 1 << FPSCR_FI
;
356 env
->fpscr
|= 1 << FPSCR_XX
;
357 /* Update the floating-point exception summary */
360 /* Update the floating-point enabled exception summary */
361 env
->fpscr
|= 1 << FPSCR_FEX
;
362 /* We must update the target FPR before raising the exception */
363 cs
->exception_index
= POWERPC_EXCP_PROGRAM
;
364 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_XX
;
368 static inline void fpscr_set_rounding_mode(CPUPPCState
*env
)
372 /* Set rounding mode */
375 /* Best approximation (round to nearest) */
376 rnd_type
= float_round_nearest_even
;
379 /* Smaller magnitude (round toward zero) */
380 rnd_type
= float_round_to_zero
;
383 /* Round toward +infinite */
384 rnd_type
= float_round_up
;
388 /* Round toward -infinite */
389 rnd_type
= float_round_down
;
392 set_float_rounding_mode(rnd_type
, &env
->fp_status
);
395 void helper_fpscr_clrbit(CPUPPCState
*env
, uint32_t bit
)
399 prev
= (env
->fpscr
>> bit
) & 1;
400 env
->fpscr
&= ~(1 << bit
);
405 fpscr_set_rounding_mode(env
);
417 /* Set VX bit to zero */
418 env
->fpscr
&= ~(1 << FPSCR_VX
);
431 /* Set the FEX bit */
432 env
->fpscr
&= ~(1 << FPSCR_FEX
);
441 void helper_fpscr_setbit(CPUPPCState
*env
, uint32_t bit
)
443 CPUState
*cs
= CPU(ppc_env_get_cpu(env
));
446 prev
= (env
->fpscr
>> bit
) & 1;
447 env
->fpscr
|= 1 << bit
;
489 env
->fpscr
|= 1 << FPSCR_VX
;
498 env
->error_code
= POWERPC_EXCP_FP
;
500 env
->error_code
|= POWERPC_EXCP_FP_VXSNAN
;
503 env
->error_code
|= POWERPC_EXCP_FP_VXISI
;
506 env
->error_code
|= POWERPC_EXCP_FP_VXIDI
;
509 env
->error_code
|= POWERPC_EXCP_FP_VXZDZ
;
512 env
->error_code
|= POWERPC_EXCP_FP_VXIMZ
;
515 env
->error_code
|= POWERPC_EXCP_FP_VXVC
;
518 env
->error_code
|= POWERPC_EXCP_FP_VXSOFT
;
521 env
->error_code
|= POWERPC_EXCP_FP_VXSQRT
;
524 env
->error_code
|= POWERPC_EXCP_FP_VXCVI
;
532 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_OX
;
539 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_UX
;
546 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_ZX
;
553 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_XX
;
559 fpscr_set_rounding_mode(env
);
564 /* Update the floating-point enabled exception summary */
565 env
->fpscr
|= 1 << FPSCR_FEX
;
566 /* We have to update Rc1 before raising the exception */
567 cs
->exception_index
= POWERPC_EXCP_PROGRAM
;
573 void helper_store_fpscr(CPUPPCState
*env
, uint64_t arg
, uint32_t mask
)
575 CPUState
*cs
= CPU(ppc_env_get_cpu(env
));
576 target_ulong prev
, new;
580 new = (target_ulong
)arg
;
581 new &= ~0x60000000LL
;
582 new |= prev
& 0x60000000LL
;
583 for (i
= 0; i
< sizeof(target_ulong
) * 2; i
++) {
584 if (mask
& (1 << i
)) {
585 env
->fpscr
&= ~(0xFLL
<< (4 * i
));
586 env
->fpscr
|= new & (0xFLL
<< (4 * i
));
589 /* Update VX and FEX */
591 env
->fpscr
|= 1 << FPSCR_VX
;
593 env
->fpscr
&= ~(1 << FPSCR_VX
);
595 if ((fpscr_ex
& fpscr_eex
) != 0) {
596 env
->fpscr
|= 1 << FPSCR_FEX
;
597 cs
->exception_index
= POWERPC_EXCP_PROGRAM
;
598 /* XXX: we should compute it properly */
599 env
->error_code
= POWERPC_EXCP_FP
;
601 env
->fpscr
&= ~(1 << FPSCR_FEX
);
603 fpscr_set_rounding_mode(env
);
606 void store_fpscr(CPUPPCState
*env
, uint64_t arg
, uint32_t mask
)
608 helper_store_fpscr(env
, arg
, mask
);
611 static void do_float_check_status(CPUPPCState
*env
, uintptr_t raddr
)
613 CPUState
*cs
= CPU(ppc_env_get_cpu(env
));
614 int status
= get_float_exception_flags(&env
->fp_status
);
615 bool inexact_happened
= false;
617 if (status
& float_flag_overflow
) {
618 float_overflow_excp(env
);
619 } else if (status
& float_flag_underflow
) {
620 float_underflow_excp(env
);
621 } else if (status
& float_flag_inexact
) {
622 float_inexact_excp(env
);
623 inexact_happened
= true;
626 /* if the inexact flag was not set */
627 if (inexact_happened
== false) {
628 env
->fpscr
&= ~(1 << FPSCR_FI
); /* clear the FPSCR[FI] bit */
631 if (cs
->exception_index
== POWERPC_EXCP_PROGRAM
&&
632 (env
->error_code
& POWERPC_EXCP_FP
)) {
633 /* Differred floating-point exception after target FPR update */
634 if (fp_exceptions_enabled(env
)) {
635 raise_exception_err_ra(env
, cs
->exception_index
,
636 env
->error_code
, raddr
);
641 void helper_float_check_status(CPUPPCState
*env
)
643 do_float_check_status(env
, GETPC());
646 void helper_reset_fpstatus(CPUPPCState
*env
)
648 set_float_exception_flags(0, &env
->fp_status
);
651 static void float_invalid_op_addsub(CPUPPCState
*env
, bool set_fpcc
,
652 uintptr_t retaddr
, int classes
)
654 if ((classes
& ~is_neg
) == is_inf
) {
655 /* Magnitude subtraction of infinities */
656 float_invalid_op_vxisi(env
, set_fpcc
, retaddr
);
657 } else if (classes
& is_snan
) {
658 float_invalid_op_vxsnan(env
, retaddr
);
663 float64
helper_fadd(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
665 float64 ret
= float64_add(arg1
, arg2
, &env
->fp_status
);
666 int status
= get_float_exception_flags(&env
->fp_status
);
668 if (unlikely(status
& float_flag_invalid
)) {
669 float_invalid_op_addsub(env
, 1, GETPC(),
670 float64_classify(arg1
) |
671 float64_classify(arg2
));
678 float64
helper_fsub(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
680 float64 ret
= float64_sub(arg1
, arg2
, &env
->fp_status
);
681 int status
= get_float_exception_flags(&env
->fp_status
);
683 if (unlikely(status
& float_flag_invalid
)) {
684 float_invalid_op_addsub(env
, 1, GETPC(),
685 float64_classify(arg1
) |
686 float64_classify(arg2
));
692 static void float_invalid_op_mul(CPUPPCState
*env
, bool set_fprc
,
693 uintptr_t retaddr
, int classes
)
695 if ((classes
& (is_zero
| is_inf
)) == (is_zero
| is_inf
)) {
696 /* Multiplication of zero by infinity */
697 float_invalid_op_vximz(env
, set_fprc
, retaddr
);
698 } else if (classes
& is_snan
) {
699 float_invalid_op_vxsnan(env
, retaddr
);
704 float64
helper_fmul(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
706 float64 ret
= float64_mul(arg1
, arg2
, &env
->fp_status
);
707 int status
= get_float_exception_flags(&env
->fp_status
);
709 if (unlikely(status
& float_flag_invalid
)) {
710 float_invalid_op_mul(env
, 1, GETPC(),
711 float64_classify(arg1
) |
712 float64_classify(arg2
));
719 float64
helper_fdiv(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
721 float64 ret
= float64_div(arg1
, arg2
, &env
->fp_status
);
722 int status
= get_float_exception_flags(&env
->fp_status
);
724 if (unlikely(status
)) {
725 if (status
& float_flag_invalid
) {
726 /* Determine what kind of invalid operation was seen. */
727 if (float64_is_infinity(arg1
) && float64_is_infinity(arg2
)) {
728 /* Division of infinity by infinity */
729 float_invalid_op_vxidi(env
, 1, GETPC());
730 } else if (float64_is_zero(arg1
) && float64_is_zero(arg2
)) {
731 /* Division of zero by zero */
732 float_invalid_op_vxzdz(env
, 1, GETPC());
733 } else if (float64_is_signaling_nan(arg1
, &env
->fp_status
) ||
734 float64_is_signaling_nan(arg2
, &env
->fp_status
)) {
736 float_invalid_op_vxsnan(env
, GETPC());
739 if (status
& float_flag_divbyzero
) {
740 float_zero_divide_excp(env
, GETPC());
748 #define FPU_FCTI(op, cvt, nanval) \
749 uint64_t helper_##op(CPUPPCState *env, uint64_t arg) \
754 farg.ll = float64_to_##cvt(farg.d, &env->fp_status); \
756 if (unlikely(env->fp_status.float_exception_flags)) { \
757 if (float64_is_any_nan(arg)) { \
758 float_invalid_op_vxcvi(env, 1, GETPC()); \
759 if (float64_is_signaling_nan(arg, &env->fp_status)) { \
760 float_invalid_op_vxsnan(env, GETPC()); \
763 } else if (env->fp_status.float_exception_flags & \
764 float_flag_invalid) { \
765 float_invalid_op_vxcvi(env, 1, GETPC()); \
767 do_float_check_status(env, GETPC()); \
772 FPU_FCTI(fctiw
, int32
, 0x80000000U
)
773 FPU_FCTI(fctiwz
, int32_round_to_zero
, 0x80000000U
)
774 FPU_FCTI(fctiwu
, uint32
, 0x00000000U
)
775 FPU_FCTI(fctiwuz
, uint32_round_to_zero
, 0x00000000U
)
776 FPU_FCTI(fctid
, int64
, 0x8000000000000000ULL
)
777 FPU_FCTI(fctidz
, int64_round_to_zero
, 0x8000000000000000ULL
)
778 FPU_FCTI(fctidu
, uint64
, 0x0000000000000000ULL
)
779 FPU_FCTI(fctiduz
, uint64_round_to_zero
, 0x0000000000000000ULL
)
781 #define FPU_FCFI(op, cvtr, is_single) \
782 uint64_t helper_##op(CPUPPCState *env, uint64_t arg) \
787 float32 tmp = cvtr(arg, &env->fp_status); \
788 farg.d = float32_to_float64(tmp, &env->fp_status); \
790 farg.d = cvtr(arg, &env->fp_status); \
792 do_float_check_status(env, GETPC()); \
796 FPU_FCFI(fcfid
, int64_to_float64
, 0)
797 FPU_FCFI(fcfids
, int64_to_float32
, 1)
798 FPU_FCFI(fcfidu
, uint64_to_float64
, 0)
799 FPU_FCFI(fcfidus
, uint64_to_float32
, 1)
801 static inline uint64_t do_fri(CPUPPCState
*env
, uint64_t arg
,
808 if (unlikely(float64_is_signaling_nan(farg
.d
, &env
->fp_status
))) {
810 float_invalid_op_vxsnan(env
, GETPC());
811 farg
.ll
= arg
| 0x0008000000000000ULL
;
813 int inexact
= get_float_exception_flags(&env
->fp_status
) &
815 set_float_rounding_mode(rounding_mode
, &env
->fp_status
);
816 farg
.ll
= float64_round_to_int(farg
.d
, &env
->fp_status
);
817 /* Restore rounding mode from FPSCR */
818 fpscr_set_rounding_mode(env
);
820 /* fri* does not set FPSCR[XX] */
822 env
->fp_status
.float_exception_flags
&= ~float_flag_inexact
;
825 do_float_check_status(env
, GETPC());
829 uint64_t helper_frin(CPUPPCState
*env
, uint64_t arg
)
831 return do_fri(env
, arg
, float_round_ties_away
);
834 uint64_t helper_friz(CPUPPCState
*env
, uint64_t arg
)
836 return do_fri(env
, arg
, float_round_to_zero
);
839 uint64_t helper_frip(CPUPPCState
*env
, uint64_t arg
)
841 return do_fri(env
, arg
, float_round_up
);
844 uint64_t helper_frim(CPUPPCState
*env
, uint64_t arg
)
846 return do_fri(env
, arg
, float_round_down
);
849 #define FPU_MADDSUB_UPDATE(NAME, TP) \
850 static void NAME(CPUPPCState *env, TP arg1, TP arg2, TP arg3, \
851 unsigned int madd_flags, uintptr_t retaddr) \
853 if (TP##_is_signaling_nan(arg1, &env->fp_status) || \
854 TP##_is_signaling_nan(arg2, &env->fp_status) || \
855 TP##_is_signaling_nan(arg3, &env->fp_status)) { \
856 /* sNaN operation */ \
857 float_invalid_op_vxsnan(env, retaddr); \
859 if ((TP##_is_infinity(arg1) && TP##_is_zero(arg2)) || \
860 (TP##_is_zero(arg1) && TP##_is_infinity(arg2))) { \
861 /* Multiplication of zero by infinity */ \
862 float_invalid_op_vximz(env, 1, retaddr); \
864 if ((TP##_is_infinity(arg1) || TP##_is_infinity(arg2)) && \
865 TP##_is_infinity(arg3)) { \
866 uint8_t aSign, bSign, cSign; \
868 aSign = TP##_is_neg(arg1); \
869 bSign = TP##_is_neg(arg2); \
870 cSign = TP##_is_neg(arg3); \
871 if (madd_flags & float_muladd_negate_c) { \
874 if (aSign ^ bSign ^ cSign) { \
875 float_invalid_op_vxisi(env, 1, retaddr); \
879 FPU_MADDSUB_UPDATE(float32_maddsub_update_excp
, float32
)
880 FPU_MADDSUB_UPDATE(float64_maddsub_update_excp
, float64
)
882 #define FPU_FMADD(op, madd_flags) \
883 uint64_t helper_##op(CPUPPCState *env, uint64_t arg1, \
884 uint64_t arg2, uint64_t arg3) \
887 float64 ret = float64_muladd(arg1, arg2, arg3, madd_flags, \
889 flags = get_float_exception_flags(&env->fp_status); \
891 if (flags & float_flag_invalid) { \
892 float64_maddsub_update_excp(env, arg1, arg2, arg3, \
893 madd_flags, GETPC()); \
895 do_float_check_status(env, GETPC()); \
901 #define MSUB_FLGS float_muladd_negate_c
902 #define NMADD_FLGS float_muladd_negate_result
903 #define NMSUB_FLGS (float_muladd_negate_c | float_muladd_negate_result)
905 FPU_FMADD(fmadd
, MADD_FLGS
)
906 FPU_FMADD(fnmadd
, NMADD_FLGS
)
907 FPU_FMADD(fmsub
, MSUB_FLGS
)
908 FPU_FMADD(fnmsub
, NMSUB_FLGS
)
911 uint64_t helper_frsp(CPUPPCState
*env
, uint64_t arg
)
918 if (unlikely(float64_is_signaling_nan(farg
.d
, &env
->fp_status
))) {
919 float_invalid_op_vxsnan(env
, GETPC());
921 f32
= float64_to_float32(farg
.d
, &env
->fp_status
);
922 farg
.d
= float32_to_float64(f32
, &env
->fp_status
);
928 float64
helper_fsqrt(CPUPPCState
*env
, float64 arg
)
930 float64 ret
= float64_sqrt(arg
, &env
->fp_status
);
931 int status
= get_float_exception_flags(&env
->fp_status
);
933 if (unlikely(status
& float_flag_invalid
)) {
934 if (unlikely(float64_is_any_nan(arg
))) {
935 if (unlikely(float64_is_signaling_nan(arg
, &env
->fp_status
))) {
936 /* sNaN square root */
937 float_invalid_op_vxsnan(env
, GETPC());
940 /* Square root of a negative nonzero number */
941 float_invalid_op_vxsqrt(env
, 1, GETPC());
949 float64
helper_fre(CPUPPCState
*env
, float64 arg
)
951 /* "Estimate" the reciprocal with actual division. */
952 float64 ret
= float64_div(float64_one
, arg
, &env
->fp_status
);
953 int status
= get_float_exception_flags(&env
->fp_status
);
955 if (unlikely(status
)) {
956 if (status
& float_flag_invalid
) {
957 if (float64_is_signaling_nan(arg
, &env
->fp_status
)) {
958 /* sNaN reciprocal */
959 float_invalid_op_vxsnan(env
, GETPC());
962 if (status
& float_flag_divbyzero
) {
963 float_zero_divide_excp(env
, GETPC());
964 /* For FPSCR.ZE == 0, the result is 1/2. */
965 ret
= float64_set_sign(float64_half
, float64_is_neg(arg
));
973 uint64_t helper_fres(CPUPPCState
*env
, uint64_t arg
)
980 if (unlikely(float64_is_signaling_nan(farg
.d
, &env
->fp_status
))) {
981 /* sNaN reciprocal */
982 float_invalid_op_vxsnan(env
, GETPC());
984 farg
.d
= float64_div(float64_one
, farg
.d
, &env
->fp_status
);
985 f32
= float64_to_float32(farg
.d
, &env
->fp_status
);
986 farg
.d
= float32_to_float64(f32
, &env
->fp_status
);
991 /* frsqrte - frsqrte. */
992 float64
helper_frsqrte(CPUPPCState
*env
, float64 arg
)
994 /* "Estimate" the reciprocal with actual division. */
995 float64 rets
= float64_sqrt(arg
, &env
->fp_status
);
996 float64 retd
= float64_div(float64_one
, rets
, &env
->fp_status
);
997 int status
= get_float_exception_flags(&env
->fp_status
);
999 if (unlikely(status
)) {
1000 if (status
& float_flag_invalid
) {
1001 if (float64_is_signaling_nan(arg
, &env
->fp_status
)) {
1002 /* sNaN reciprocal */
1003 float_invalid_op_vxsnan(env
, GETPC());
1005 /* Square root of a negative nonzero number */
1006 float_invalid_op_vxsqrt(env
, 1, GETPC());
1009 if (status
& float_flag_divbyzero
) {
1010 /* Reciprocal of (square root of) zero. */
1011 float_zero_divide_excp(env
, GETPC());
1019 uint64_t helper_fsel(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
1026 if ((!float64_is_neg(farg1
.d
) || float64_is_zero(farg1
.d
)) &&
1027 !float64_is_any_nan(farg1
.d
)) {
1034 uint32_t helper_ftdiv(uint64_t fra
, uint64_t frb
)
1039 if (unlikely(float64_is_infinity(fra
) ||
1040 float64_is_infinity(frb
) ||
1041 float64_is_zero(frb
))) {
1045 int e_a
= ppc_float64_get_unbiased_exp(fra
);
1046 int e_b
= ppc_float64_get_unbiased_exp(frb
);
1048 if (unlikely(float64_is_any_nan(fra
) ||
1049 float64_is_any_nan(frb
))) {
1051 } else if ((e_b
<= -1022) || (e_b
>= 1021)) {
1053 } else if (!float64_is_zero(fra
) &&
1054 (((e_a
- e_b
) >= 1023) ||
1055 ((e_a
- e_b
) <= -1021) ||
1060 if (unlikely(float64_is_zero_or_denormal(frb
))) {
1061 /* XB is not zero because of the above check and */
1062 /* so must be denormalized. */
1067 return 0x8 | (fg_flag
? 4 : 0) | (fe_flag
? 2 : 0);
1070 uint32_t helper_ftsqrt(uint64_t frb
)
1075 if (unlikely(float64_is_infinity(frb
) || float64_is_zero(frb
))) {
1079 int e_b
= ppc_float64_get_unbiased_exp(frb
);
1081 if (unlikely(float64_is_any_nan(frb
))) {
1083 } else if (unlikely(float64_is_zero(frb
))) {
1085 } else if (unlikely(float64_is_neg(frb
))) {
1087 } else if (!float64_is_zero(frb
) && (e_b
<= (-1022+52))) {
1091 if (unlikely(float64_is_zero_or_denormal(frb
))) {
1092 /* XB is not zero because of the above check and */
1093 /* therefore must be denormalized. */
1098 return 0x8 | (fg_flag
? 4 : 0) | (fe_flag
? 2 : 0);
1101 void helper_fcmpu(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
1104 CPU_DoubleU farg1
, farg2
;
1110 if (unlikely(float64_is_any_nan(farg1
.d
) ||
1111 float64_is_any_nan(farg2
.d
))) {
1113 } else if (float64_lt(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1115 } else if (!float64_le(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1121 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
1122 env
->fpscr
|= ret
<< FPSCR_FPRF
;
1123 env
->crf
[crfD
] = ret
;
1124 if (unlikely(ret
== 0x01UL
1125 && (float64_is_signaling_nan(farg1
.d
, &env
->fp_status
) ||
1126 float64_is_signaling_nan(farg2
.d
, &env
->fp_status
)))) {
1127 /* sNaN comparison */
1128 float_invalid_op_vxsnan(env
, GETPC());
1132 void helper_fcmpo(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
1135 CPU_DoubleU farg1
, farg2
;
1141 if (unlikely(float64_is_any_nan(farg1
.d
) ||
1142 float64_is_any_nan(farg2
.d
))) {
1144 } else if (float64_lt(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1146 } else if (!float64_le(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1152 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
1153 env
->fpscr
|= ret
<< FPSCR_FPRF
;
1154 env
->crf
[crfD
] = ret
;
1155 if (unlikely(ret
== 0x01UL
)) {
1156 float_invalid_op_vxvc(env
, 1, GETPC());
1157 if (float64_is_signaling_nan(farg1
.d
, &env
->fp_status
) ||
1158 float64_is_signaling_nan(farg2
.d
, &env
->fp_status
)) {
1159 /* sNaN comparison */
1160 float_invalid_op_vxsnan(env
, GETPC());
1165 /* Single-precision floating-point conversions */
1166 static inline uint32_t efscfsi(CPUPPCState
*env
, uint32_t val
)
1170 u
.f
= int32_to_float32(val
, &env
->vec_status
);
1175 static inline uint32_t efscfui(CPUPPCState
*env
, uint32_t val
)
1179 u
.f
= uint32_to_float32(val
, &env
->vec_status
);
1184 static inline int32_t efsctsi(CPUPPCState
*env
, uint32_t val
)
1189 /* NaN are not treated the same way IEEE 754 does */
1190 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1194 return float32_to_int32(u
.f
, &env
->vec_status
);
1197 static inline uint32_t efsctui(CPUPPCState
*env
, uint32_t val
)
1202 /* NaN are not treated the same way IEEE 754 does */
1203 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1207 return float32_to_uint32(u
.f
, &env
->vec_status
);
1210 static inline uint32_t efsctsiz(CPUPPCState
*env
, uint32_t val
)
1215 /* NaN are not treated the same way IEEE 754 does */
1216 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1220 return float32_to_int32_round_to_zero(u
.f
, &env
->vec_status
);
1223 static inline uint32_t efsctuiz(CPUPPCState
*env
, uint32_t val
)
1228 /* NaN are not treated the same way IEEE 754 does */
1229 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1233 return float32_to_uint32_round_to_zero(u
.f
, &env
->vec_status
);
1236 static inline uint32_t efscfsf(CPUPPCState
*env
, uint32_t val
)
1241 u
.f
= int32_to_float32(val
, &env
->vec_status
);
1242 tmp
= int64_to_float32(1ULL << 32, &env
->vec_status
);
1243 u
.f
= float32_div(u
.f
, tmp
, &env
->vec_status
);
1248 static inline uint32_t efscfuf(CPUPPCState
*env
, uint32_t val
)
1253 u
.f
= uint32_to_float32(val
, &env
->vec_status
);
1254 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1255 u
.f
= float32_div(u
.f
, tmp
, &env
->vec_status
);
1260 static inline uint32_t efsctsf(CPUPPCState
*env
, uint32_t val
)
1266 /* NaN are not treated the same way IEEE 754 does */
1267 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1270 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1271 u
.f
= float32_mul(u
.f
, tmp
, &env
->vec_status
);
1273 return float32_to_int32(u
.f
, &env
->vec_status
);
1276 static inline uint32_t efsctuf(CPUPPCState
*env
, uint32_t val
)
1282 /* NaN are not treated the same way IEEE 754 does */
1283 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1286 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1287 u
.f
= float32_mul(u
.f
, tmp
, &env
->vec_status
);
1289 return float32_to_uint32(u
.f
, &env
->vec_status
);
1292 #define HELPER_SPE_SINGLE_CONV(name) \
1293 uint32_t helper_e##name(CPUPPCState *env, uint32_t val) \
1295 return e##name(env, val); \
1298 HELPER_SPE_SINGLE_CONV(fscfsi
);
1300 HELPER_SPE_SINGLE_CONV(fscfui
);
1302 HELPER_SPE_SINGLE_CONV(fscfuf
);
1304 HELPER_SPE_SINGLE_CONV(fscfsf
);
1306 HELPER_SPE_SINGLE_CONV(fsctsi
);
1308 HELPER_SPE_SINGLE_CONV(fsctui
);
1310 HELPER_SPE_SINGLE_CONV(fsctsiz
);
1312 HELPER_SPE_SINGLE_CONV(fsctuiz
);
1314 HELPER_SPE_SINGLE_CONV(fsctsf
);
1316 HELPER_SPE_SINGLE_CONV(fsctuf
);
1318 #define HELPER_SPE_VECTOR_CONV(name) \
1319 uint64_t helper_ev##name(CPUPPCState *env, uint64_t val) \
1321 return ((uint64_t)e##name(env, val >> 32) << 32) | \
1322 (uint64_t)e##name(env, val); \
1325 HELPER_SPE_VECTOR_CONV(fscfsi
);
1327 HELPER_SPE_VECTOR_CONV(fscfui
);
1329 HELPER_SPE_VECTOR_CONV(fscfuf
);
1331 HELPER_SPE_VECTOR_CONV(fscfsf
);
1333 HELPER_SPE_VECTOR_CONV(fsctsi
);
1335 HELPER_SPE_VECTOR_CONV(fsctui
);
1337 HELPER_SPE_VECTOR_CONV(fsctsiz
);
1339 HELPER_SPE_VECTOR_CONV(fsctuiz
);
1341 HELPER_SPE_VECTOR_CONV(fsctsf
);
1343 HELPER_SPE_VECTOR_CONV(fsctuf
);
1345 /* Single-precision floating-point arithmetic */
1346 static inline uint32_t efsadd(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1352 u1
.f
= float32_add(u1
.f
, u2
.f
, &env
->vec_status
);
1356 static inline uint32_t efssub(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1362 u1
.f
= float32_sub(u1
.f
, u2
.f
, &env
->vec_status
);
1366 static inline uint32_t efsmul(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1372 u1
.f
= float32_mul(u1
.f
, u2
.f
, &env
->vec_status
);
1376 static inline uint32_t efsdiv(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1382 u1
.f
= float32_div(u1
.f
, u2
.f
, &env
->vec_status
);
1386 #define HELPER_SPE_SINGLE_ARITH(name) \
1387 uint32_t helper_e##name(CPUPPCState *env, uint32_t op1, uint32_t op2) \
1389 return e##name(env, op1, op2); \
1392 HELPER_SPE_SINGLE_ARITH(fsadd
);
1394 HELPER_SPE_SINGLE_ARITH(fssub
);
1396 HELPER_SPE_SINGLE_ARITH(fsmul
);
1398 HELPER_SPE_SINGLE_ARITH(fsdiv
);
1400 #define HELPER_SPE_VECTOR_ARITH(name) \
1401 uint64_t helper_ev##name(CPUPPCState *env, uint64_t op1, uint64_t op2) \
1403 return ((uint64_t)e##name(env, op1 >> 32, op2 >> 32) << 32) | \
1404 (uint64_t)e##name(env, op1, op2); \
1407 HELPER_SPE_VECTOR_ARITH(fsadd
);
1409 HELPER_SPE_VECTOR_ARITH(fssub
);
1411 HELPER_SPE_VECTOR_ARITH(fsmul
);
1413 HELPER_SPE_VECTOR_ARITH(fsdiv
);
1415 /* Single-precision floating-point comparisons */
1416 static inline uint32_t efscmplt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1422 return float32_lt(u1
.f
, u2
.f
, &env
->vec_status
) ? 4 : 0;
1425 static inline uint32_t efscmpgt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1431 return float32_le(u1
.f
, u2
.f
, &env
->vec_status
) ? 0 : 4;
1434 static inline uint32_t efscmpeq(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1440 return float32_eq(u1
.f
, u2
.f
, &env
->vec_status
) ? 4 : 0;
1443 static inline uint32_t efststlt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1445 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1446 return efscmplt(env
, op1
, op2
);
1449 static inline uint32_t efststgt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1451 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1452 return efscmpgt(env
, op1
, op2
);
1455 static inline uint32_t efststeq(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1457 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1458 return efscmpeq(env
, op1
, op2
);
1461 #define HELPER_SINGLE_SPE_CMP(name) \
1462 uint32_t helper_e##name(CPUPPCState *env, uint32_t op1, uint32_t op2) \
1464 return e##name(env, op1, op2); \
1467 HELPER_SINGLE_SPE_CMP(fststlt
);
1469 HELPER_SINGLE_SPE_CMP(fststgt
);
1471 HELPER_SINGLE_SPE_CMP(fststeq
);
1473 HELPER_SINGLE_SPE_CMP(fscmplt
);
1475 HELPER_SINGLE_SPE_CMP(fscmpgt
);
1477 HELPER_SINGLE_SPE_CMP(fscmpeq
);
1479 static inline uint32_t evcmp_merge(int t0
, int t1
)
1481 return (t0
<< 3) | (t1
<< 2) | ((t0
| t1
) << 1) | (t0
& t1
);
1484 #define HELPER_VECTOR_SPE_CMP(name) \
1485 uint32_t helper_ev##name(CPUPPCState *env, uint64_t op1, uint64_t op2) \
1487 return evcmp_merge(e##name(env, op1 >> 32, op2 >> 32), \
1488 e##name(env, op1, op2)); \
1491 HELPER_VECTOR_SPE_CMP(fststlt
);
1493 HELPER_VECTOR_SPE_CMP(fststgt
);
1495 HELPER_VECTOR_SPE_CMP(fststeq
);
1497 HELPER_VECTOR_SPE_CMP(fscmplt
);
1499 HELPER_VECTOR_SPE_CMP(fscmpgt
);
1501 HELPER_VECTOR_SPE_CMP(fscmpeq
);
1503 /* Double-precision floating-point conversion */
1504 uint64_t helper_efdcfsi(CPUPPCState
*env
, uint32_t val
)
1508 u
.d
= int32_to_float64(val
, &env
->vec_status
);
1513 uint64_t helper_efdcfsid(CPUPPCState
*env
, uint64_t val
)
1517 u
.d
= int64_to_float64(val
, &env
->vec_status
);
1522 uint64_t helper_efdcfui(CPUPPCState
*env
, uint32_t val
)
1526 u
.d
= uint32_to_float64(val
, &env
->vec_status
);
1531 uint64_t helper_efdcfuid(CPUPPCState
*env
, uint64_t val
)
1535 u
.d
= uint64_to_float64(val
, &env
->vec_status
);
1540 uint32_t helper_efdctsi(CPUPPCState
*env
, uint64_t val
)
1545 /* NaN are not treated the same way IEEE 754 does */
1546 if (unlikely(float64_is_any_nan(u
.d
))) {
1550 return float64_to_int32(u
.d
, &env
->vec_status
);
1553 uint32_t helper_efdctui(CPUPPCState
*env
, uint64_t val
)
1558 /* NaN are not treated the same way IEEE 754 does */
1559 if (unlikely(float64_is_any_nan(u
.d
))) {
1563 return float64_to_uint32(u
.d
, &env
->vec_status
);
1566 uint32_t helper_efdctsiz(CPUPPCState
*env
, uint64_t val
)
1571 /* NaN are not treated the same way IEEE 754 does */
1572 if (unlikely(float64_is_any_nan(u
.d
))) {
1576 return float64_to_int32_round_to_zero(u
.d
, &env
->vec_status
);
1579 uint64_t helper_efdctsidz(CPUPPCState
*env
, uint64_t val
)
1584 /* NaN are not treated the same way IEEE 754 does */
1585 if (unlikely(float64_is_any_nan(u
.d
))) {
1589 return float64_to_int64_round_to_zero(u
.d
, &env
->vec_status
);
1592 uint32_t helper_efdctuiz(CPUPPCState
*env
, uint64_t val
)
1597 /* NaN are not treated the same way IEEE 754 does */
1598 if (unlikely(float64_is_any_nan(u
.d
))) {
1602 return float64_to_uint32_round_to_zero(u
.d
, &env
->vec_status
);
1605 uint64_t helper_efdctuidz(CPUPPCState
*env
, uint64_t val
)
1610 /* NaN are not treated the same way IEEE 754 does */
1611 if (unlikely(float64_is_any_nan(u
.d
))) {
1615 return float64_to_uint64_round_to_zero(u
.d
, &env
->vec_status
);
1618 uint64_t helper_efdcfsf(CPUPPCState
*env
, uint32_t val
)
1623 u
.d
= int32_to_float64(val
, &env
->vec_status
);
1624 tmp
= int64_to_float64(1ULL << 32, &env
->vec_status
);
1625 u
.d
= float64_div(u
.d
, tmp
, &env
->vec_status
);
1630 uint64_t helper_efdcfuf(CPUPPCState
*env
, uint32_t val
)
1635 u
.d
= uint32_to_float64(val
, &env
->vec_status
);
1636 tmp
= int64_to_float64(1ULL << 32, &env
->vec_status
);
1637 u
.d
= float64_div(u
.d
, tmp
, &env
->vec_status
);
1642 uint32_t helper_efdctsf(CPUPPCState
*env
, uint64_t val
)
1648 /* NaN are not treated the same way IEEE 754 does */
1649 if (unlikely(float64_is_any_nan(u
.d
))) {
1652 tmp
= uint64_to_float64(1ULL << 32, &env
->vec_status
);
1653 u
.d
= float64_mul(u
.d
, tmp
, &env
->vec_status
);
1655 return float64_to_int32(u
.d
, &env
->vec_status
);
1658 uint32_t helper_efdctuf(CPUPPCState
*env
, uint64_t val
)
1664 /* NaN are not treated the same way IEEE 754 does */
1665 if (unlikely(float64_is_any_nan(u
.d
))) {
1668 tmp
= uint64_to_float64(1ULL << 32, &env
->vec_status
);
1669 u
.d
= float64_mul(u
.d
, tmp
, &env
->vec_status
);
1671 return float64_to_uint32(u
.d
, &env
->vec_status
);
1674 uint32_t helper_efscfd(CPUPPCState
*env
, uint64_t val
)
1680 u2
.f
= float64_to_float32(u1
.d
, &env
->vec_status
);
1685 uint64_t helper_efdcfs(CPUPPCState
*env
, uint32_t val
)
1691 u2
.d
= float32_to_float64(u1
.f
, &env
->vec_status
);
1696 /* Double precision fixed-point arithmetic */
1697 uint64_t helper_efdadd(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1703 u1
.d
= float64_add(u1
.d
, u2
.d
, &env
->vec_status
);
1707 uint64_t helper_efdsub(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1713 u1
.d
= float64_sub(u1
.d
, u2
.d
, &env
->vec_status
);
1717 uint64_t helper_efdmul(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1723 u1
.d
= float64_mul(u1
.d
, u2
.d
, &env
->vec_status
);
1727 uint64_t helper_efddiv(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1733 u1
.d
= float64_div(u1
.d
, u2
.d
, &env
->vec_status
);
1737 /* Double precision floating point helpers */
1738 uint32_t helper_efdtstlt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1744 return float64_lt(u1
.d
, u2
.d
, &env
->vec_status
) ? 4 : 0;
1747 uint32_t helper_efdtstgt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1753 return float64_le(u1
.d
, u2
.d
, &env
->vec_status
) ? 0 : 4;
1756 uint32_t helper_efdtsteq(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1762 return float64_eq_quiet(u1
.d
, u2
.d
, &env
->vec_status
) ? 4 : 0;
1765 uint32_t helper_efdcmplt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1767 /* XXX: TODO: test special values (NaN, infinites, ...) */
1768 return helper_efdtstlt(env
, op1
, op2
);
1771 uint32_t helper_efdcmpgt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1773 /* XXX: TODO: test special values (NaN, infinites, ...) */
1774 return helper_efdtstgt(env
, op1
, op2
);
1777 uint32_t helper_efdcmpeq(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1779 /* XXX: TODO: test special values (NaN, infinites, ...) */
1780 return helper_efdtsteq(env
, op1
, op2
);
1783 #define float64_to_float64(x, env) x
1786 /* VSX_ADD_SUB - VSX floating point add/subract
1787 * name - instruction mnemonic
1788 * op - operation (add or sub)
1789 * nels - number of elements (1, 2 or 4)
1790 * tp - type (float32 or float64)
1791 * fld - vsr_t field (VsrD(*) or VsrW(*))
1794 #define VSX_ADD_SUB(name, op, nels, tp, fld, sfprf, r2sp) \
1795 void helper_##name(CPUPPCState *env, uint32_t opcode) \
1797 ppc_vsr_t xt, xa, xb; \
1800 getVSR(xA(opcode), &xa, env); \
1801 getVSR(xB(opcode), &xb, env); \
1802 getVSR(xT(opcode), &xt, env); \
1803 helper_reset_fpstatus(env); \
1805 for (i = 0; i < nels; i++) { \
1806 float_status tstat = env->fp_status; \
1807 set_float_exception_flags(0, &tstat); \
1808 xt.fld = tp##_##op(xa.fld, xb.fld, &tstat); \
1809 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1811 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1812 float_invalid_op_addsub(env, sfprf, GETPC(), \
1813 tp##_classify(xa.fld) | \
1814 tp##_classify(xb.fld)); \
1818 xt.fld = helper_frsp(env, xt.fld); \
1822 helper_compute_fprf_float64(env, xt.fld); \
1825 putVSR(xT(opcode), &xt, env); \
1826 do_float_check_status(env, GETPC()); \
1829 VSX_ADD_SUB(xsadddp
, add
, 1, float64
, VsrD(0), 1, 0)
1830 VSX_ADD_SUB(xsaddsp
, add
, 1, float64
, VsrD(0), 1, 1)
1831 VSX_ADD_SUB(xvadddp
, add
, 2, float64
, VsrD(i
), 0, 0)
1832 VSX_ADD_SUB(xvaddsp
, add
, 4, float32
, VsrW(i
), 0, 0)
1833 VSX_ADD_SUB(xssubdp
, sub
, 1, float64
, VsrD(0), 1, 0)
1834 VSX_ADD_SUB(xssubsp
, sub
, 1, float64
, VsrD(0), 1, 1)
1835 VSX_ADD_SUB(xvsubdp
, sub
, 2, float64
, VsrD(i
), 0, 0)
1836 VSX_ADD_SUB(xvsubsp
, sub
, 4, float32
, VsrW(i
), 0, 0)
1838 void helper_xsaddqp(CPUPPCState
*env
, uint32_t opcode
)
1840 ppc_vsr_t xt
, xa
, xb
;
1843 getVSR(rA(opcode
) + 32, &xa
, env
);
1844 getVSR(rB(opcode
) + 32, &xb
, env
);
1845 getVSR(rD(opcode
) + 32, &xt
, env
);
1846 helper_reset_fpstatus(env
);
1848 tstat
= env
->fp_status
;
1849 if (unlikely(Rc(opcode
) != 0)) {
1850 tstat
.float_rounding_mode
= float_round_to_odd
;
1853 set_float_exception_flags(0, &tstat
);
1854 xt
.f128
= float128_add(xa
.f128
, xb
.f128
, &tstat
);
1855 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
1857 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
1858 float_invalid_op_addsub(env
, 1, GETPC(),
1859 float128_classify(xa
.f128
) |
1860 float128_classify(xb
.f128
));
1863 helper_compute_fprf_float128(env
, xt
.f128
);
1865 putVSR(rD(opcode
) + 32, &xt
, env
);
1866 do_float_check_status(env
, GETPC());
1869 /* VSX_MUL - VSX floating point multiply
1870 * op - instruction mnemonic
1871 * nels - number of elements (1, 2 or 4)
1872 * tp - type (float32 or float64)
1873 * fld - vsr_t field (VsrD(*) or VsrW(*))
1876 #define VSX_MUL(op, nels, tp, fld, sfprf, r2sp) \
1877 void helper_##op(CPUPPCState *env, uint32_t opcode) \
1879 ppc_vsr_t xt, xa, xb; \
1882 getVSR(xA(opcode), &xa, env); \
1883 getVSR(xB(opcode), &xb, env); \
1884 getVSR(xT(opcode), &xt, env); \
1885 helper_reset_fpstatus(env); \
1887 for (i = 0; i < nels; i++) { \
1888 float_status tstat = env->fp_status; \
1889 set_float_exception_flags(0, &tstat); \
1890 xt.fld = tp##_mul(xa.fld, xb.fld, &tstat); \
1891 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1893 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1894 float_invalid_op_mul(env, sfprf, GETPC(), \
1895 tp##_classify(xa.fld) | \
1896 tp##_classify(xb.fld)); \
1900 xt.fld = helper_frsp(env, xt.fld); \
1904 helper_compute_fprf_float64(env, xt.fld); \
1908 putVSR(xT(opcode), &xt, env); \
1909 do_float_check_status(env, GETPC()); \
1912 VSX_MUL(xsmuldp
, 1, float64
, VsrD(0), 1, 0)
1913 VSX_MUL(xsmulsp
, 1, float64
, VsrD(0), 1, 1)
1914 VSX_MUL(xvmuldp
, 2, float64
, VsrD(i
), 0, 0)
1915 VSX_MUL(xvmulsp
, 4, float32
, VsrW(i
), 0, 0)
1917 void helper_xsmulqp(CPUPPCState
*env
, uint32_t opcode
)
1919 ppc_vsr_t xt
, xa
, xb
;
1922 getVSR(rA(opcode
) + 32, &xa
, env
);
1923 getVSR(rB(opcode
) + 32, &xb
, env
);
1924 getVSR(rD(opcode
) + 32, &xt
, env
);
1926 helper_reset_fpstatus(env
);
1927 tstat
= env
->fp_status
;
1928 if (unlikely(Rc(opcode
) != 0)) {
1929 tstat
.float_rounding_mode
= float_round_to_odd
;
1932 set_float_exception_flags(0, &tstat
);
1933 xt
.f128
= float128_mul(xa
.f128
, xb
.f128
, &tstat
);
1934 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
1936 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
1937 float_invalid_op_mul(env
, 1, GETPC(),
1938 float128_classify(xa
.f128
) |
1939 float128_classify(xb
.f128
));
1941 helper_compute_fprf_float128(env
, xt
.f128
);
1943 putVSR(rD(opcode
) + 32, &xt
, env
);
1944 do_float_check_status(env
, GETPC());
1947 /* VSX_DIV - VSX floating point divide
1948 * op - instruction mnemonic
1949 * nels - number of elements (1, 2 or 4)
1950 * tp - type (float32 or float64)
1951 * fld - vsr_t field (VsrD(*) or VsrW(*))
1954 #define VSX_DIV(op, nels, tp, fld, sfprf, r2sp) \
1955 void helper_##op(CPUPPCState *env, uint32_t opcode) \
1957 ppc_vsr_t xt, xa, xb; \
1960 getVSR(xA(opcode), &xa, env); \
1961 getVSR(xB(opcode), &xb, env); \
1962 getVSR(xT(opcode), &xt, env); \
1963 helper_reset_fpstatus(env); \
1965 for (i = 0; i < nels; i++) { \
1966 float_status tstat = env->fp_status; \
1967 set_float_exception_flags(0, &tstat); \
1968 xt.fld = tp##_div(xa.fld, xb.fld, &tstat); \
1969 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1971 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1972 if (tp##_is_infinity(xa.fld) && tp##_is_infinity(xb.fld)) { \
1973 float_invalid_op_vxidi(env, sfprf, GETPC()); \
1974 } else if (tp##_is_zero(xa.fld) && tp##_is_zero(xb.fld)) { \
1975 float_invalid_op_vxzdz(env, sfprf, GETPC()); \
1976 } else if (tp##_is_signaling_nan(xa.fld, &tstat) || \
1977 tp##_is_signaling_nan(xb.fld, &tstat)) { \
1978 float_invalid_op_vxsnan(env, GETPC()); \
1981 if (unlikely(tstat.float_exception_flags & float_flag_divbyzero)) { \
1982 float_zero_divide_excp(env, GETPC()); \
1986 xt.fld = helper_frsp(env, xt.fld); \
1990 helper_compute_fprf_float64(env, xt.fld); \
1994 putVSR(xT(opcode), &xt, env); \
1995 do_float_check_status(env, GETPC()); \
1998 VSX_DIV(xsdivdp
, 1, float64
, VsrD(0), 1, 0)
1999 VSX_DIV(xsdivsp
, 1, float64
, VsrD(0), 1, 1)
2000 VSX_DIV(xvdivdp
, 2, float64
, VsrD(i
), 0, 0)
2001 VSX_DIV(xvdivsp
, 4, float32
, VsrW(i
), 0, 0)
2003 void helper_xsdivqp(CPUPPCState
*env
, uint32_t opcode
)
2005 ppc_vsr_t xt
, xa
, xb
;
2008 getVSR(rA(opcode
) + 32, &xa
, env
);
2009 getVSR(rB(opcode
) + 32, &xb
, env
);
2010 getVSR(rD(opcode
) + 32, &xt
, env
);
2012 helper_reset_fpstatus(env
);
2013 tstat
= env
->fp_status
;
2014 if (unlikely(Rc(opcode
) != 0)) {
2015 tstat
.float_rounding_mode
= float_round_to_odd
;
2018 set_float_exception_flags(0, &tstat
);
2019 xt
.f128
= float128_div(xa
.f128
, xb
.f128
, &tstat
);
2020 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
2022 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
2023 if (float128_is_infinity(xa
.f128
) && float128_is_infinity(xb
.f128
)) {
2024 float_invalid_op_vxidi(env
, 1, GETPC());
2025 } else if (float128_is_zero(xa
.f128
) && float128_is_zero(xb
.f128
)) {
2026 float_invalid_op_vxzdz(env
, 1, GETPC());
2027 } else if (float128_is_signaling_nan(xa
.f128
, &tstat
) ||
2028 float128_is_signaling_nan(xb
.f128
, &tstat
)) {
2029 float_invalid_op_vxsnan(env
, GETPC());
2032 if (unlikely(tstat
.float_exception_flags
& float_flag_divbyzero
)) {
2033 float_zero_divide_excp(env
, GETPC());
2036 helper_compute_fprf_float128(env
, xt
.f128
);
2037 putVSR(rD(opcode
) + 32, &xt
, env
);
2038 do_float_check_status(env
, GETPC());
2041 /* VSX_RE - VSX floating point reciprocal estimate
2042 * op - instruction mnemonic
2043 * nels - number of elements (1, 2 or 4)
2044 * tp - type (float32 or float64)
2045 * fld - vsr_t field (VsrD(*) or VsrW(*))
2048 #define VSX_RE(op, nels, tp, fld, sfprf, r2sp) \
2049 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2054 getVSR(xB(opcode), &xb, env); \
2055 getVSR(xT(opcode), &xt, env); \
2056 helper_reset_fpstatus(env); \
2058 for (i = 0; i < nels; i++) { \
2059 if (unlikely(tp##_is_signaling_nan(xb.fld, &env->fp_status))) { \
2060 float_invalid_op_vxsnan(env, GETPC()); \
2062 xt.fld = tp##_div(tp##_one, xb.fld, &env->fp_status); \
2065 xt.fld = helper_frsp(env, xt.fld); \
2069 helper_compute_fprf_float64(env, xt.fld); \
2073 putVSR(xT(opcode), &xt, env); \
2074 do_float_check_status(env, GETPC()); \
2077 VSX_RE(xsredp
, 1, float64
, VsrD(0), 1, 0)
2078 VSX_RE(xsresp
, 1, float64
, VsrD(0), 1, 1)
2079 VSX_RE(xvredp
, 2, float64
, VsrD(i
), 0, 0)
2080 VSX_RE(xvresp
, 4, float32
, VsrW(i
), 0, 0)
2082 /* VSX_SQRT - VSX floating point square root
2083 * op - instruction mnemonic
2084 * nels - number of elements (1, 2 or 4)
2085 * tp - type (float32 or float64)
2086 * fld - vsr_t field (VsrD(*) or VsrW(*))
2089 #define VSX_SQRT(op, nels, tp, fld, sfprf, r2sp) \
2090 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2095 getVSR(xB(opcode), &xb, env); \
2096 getVSR(xT(opcode), &xt, env); \
2097 helper_reset_fpstatus(env); \
2099 for (i = 0; i < nels; i++) { \
2100 float_status tstat = env->fp_status; \
2101 set_float_exception_flags(0, &tstat); \
2102 xt.fld = tp##_sqrt(xb.fld, &tstat); \
2103 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
2105 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
2106 if (tp##_is_neg(xb.fld) && !tp##_is_zero(xb.fld)) { \
2107 float_invalid_op_vxsqrt(env, sfprf, GETPC()); \
2108 } else if (tp##_is_signaling_nan(xb.fld, &tstat)) { \
2109 float_invalid_op_vxsnan(env, GETPC()); \
2114 xt.fld = helper_frsp(env, xt.fld); \
2118 helper_compute_fprf_float64(env, xt.fld); \
2122 putVSR(xT(opcode), &xt, env); \
2123 do_float_check_status(env, GETPC()); \
2126 VSX_SQRT(xssqrtdp
, 1, float64
, VsrD(0), 1, 0)
2127 VSX_SQRT(xssqrtsp
, 1, float64
, VsrD(0), 1, 1)
2128 VSX_SQRT(xvsqrtdp
, 2, float64
, VsrD(i
), 0, 0)
2129 VSX_SQRT(xvsqrtsp
, 4, float32
, VsrW(i
), 0, 0)
2131 /* VSX_RSQRTE - VSX floating point reciprocal square root estimate
2132 * op - instruction mnemonic
2133 * nels - number of elements (1, 2 or 4)
2134 * tp - type (float32 or float64)
2135 * fld - vsr_t field (VsrD(*) or VsrW(*))
2138 #define VSX_RSQRTE(op, nels, tp, fld, sfprf, r2sp) \
2139 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2144 getVSR(xB(opcode), &xb, env); \
2145 getVSR(xT(opcode), &xt, env); \
2146 helper_reset_fpstatus(env); \
2148 for (i = 0; i < nels; i++) { \
2149 float_status tstat = env->fp_status; \
2150 set_float_exception_flags(0, &tstat); \
2151 xt.fld = tp##_sqrt(xb.fld, &tstat); \
2152 xt.fld = tp##_div(tp##_one, xt.fld, &tstat); \
2153 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
2155 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
2156 if (tp##_is_neg(xb.fld) && !tp##_is_zero(xb.fld)) { \
2157 float_invalid_op_vxsqrt(env, sfprf, GETPC()); \
2158 } else if (tp##_is_signaling_nan(xb.fld, &tstat)) { \
2159 float_invalid_op_vxsnan(env, GETPC()); \
2164 xt.fld = helper_frsp(env, xt.fld); \
2168 helper_compute_fprf_float64(env, xt.fld); \
2172 putVSR(xT(opcode), &xt, env); \
2173 do_float_check_status(env, GETPC()); \
2176 VSX_RSQRTE(xsrsqrtedp
, 1, float64
, VsrD(0), 1, 0)
2177 VSX_RSQRTE(xsrsqrtesp
, 1, float64
, VsrD(0), 1, 1)
2178 VSX_RSQRTE(xvrsqrtedp
, 2, float64
, VsrD(i
), 0, 0)
2179 VSX_RSQRTE(xvrsqrtesp
, 4, float32
, VsrW(i
), 0, 0)
2181 /* VSX_TDIV - VSX floating point test for divide
2182 * op - instruction mnemonic
2183 * nels - number of elements (1, 2 or 4)
2184 * tp - type (float32 or float64)
2185 * fld - vsr_t field (VsrD(*) or VsrW(*))
2186 * emin - minimum unbiased exponent
2187 * emax - maximum unbiased exponent
2188 * nbits - number of fraction bits
2190 #define VSX_TDIV(op, nels, tp, fld, emin, emax, nbits) \
2191 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2198 getVSR(xA(opcode), &xa, env); \
2199 getVSR(xB(opcode), &xb, env); \
2201 for (i = 0; i < nels; i++) { \
2202 if (unlikely(tp##_is_infinity(xa.fld) || \
2203 tp##_is_infinity(xb.fld) || \
2204 tp##_is_zero(xb.fld))) { \
2208 int e_a = ppc_##tp##_get_unbiased_exp(xa.fld); \
2209 int e_b = ppc_##tp##_get_unbiased_exp(xb.fld); \
2211 if (unlikely(tp##_is_any_nan(xa.fld) || \
2212 tp##_is_any_nan(xb.fld))) { \
2214 } else if ((e_b <= emin) || (e_b >= (emax-2))) { \
2216 } else if (!tp##_is_zero(xa.fld) && \
2217 (((e_a - e_b) >= emax) || \
2218 ((e_a - e_b) <= (emin+1)) || \
2219 (e_a <= (emin+nbits)))) { \
2223 if (unlikely(tp##_is_zero_or_denormal(xb.fld))) { \
2224 /* XB is not zero because of the above check and */ \
2225 /* so must be denormalized. */ \
2231 env->crf[BF(opcode)] = 0x8 | (fg_flag ? 4 : 0) | (fe_flag ? 2 : 0); \
2234 VSX_TDIV(xstdivdp
, 1, float64
, VsrD(0), -1022, 1023, 52)
2235 VSX_TDIV(xvtdivdp
, 2, float64
, VsrD(i
), -1022, 1023, 52)
2236 VSX_TDIV(xvtdivsp
, 4, float32
, VsrW(i
), -126, 127, 23)
2238 /* VSX_TSQRT - VSX floating point test for square root
2239 * op - instruction mnemonic
2240 * nels - number of elements (1, 2 or 4)
2241 * tp - type (float32 or float64)
2242 * fld - vsr_t field (VsrD(*) or VsrW(*))
2243 * emin - minimum unbiased exponent
2244 * emax - maximum unbiased exponent
2245 * nbits - number of fraction bits
2247 #define VSX_TSQRT(op, nels, tp, fld, emin, nbits) \
2248 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2255 getVSR(xA(opcode), &xa, env); \
2256 getVSR(xB(opcode), &xb, env); \
2258 for (i = 0; i < nels; i++) { \
2259 if (unlikely(tp##_is_infinity(xb.fld) || \
2260 tp##_is_zero(xb.fld))) { \
2264 int e_b = ppc_##tp##_get_unbiased_exp(xb.fld); \
2266 if (unlikely(tp##_is_any_nan(xb.fld))) { \
2268 } else if (unlikely(tp##_is_zero(xb.fld))) { \
2270 } else if (unlikely(tp##_is_neg(xb.fld))) { \
2272 } else if (!tp##_is_zero(xb.fld) && \
2273 (e_b <= (emin+nbits))) { \
2277 if (unlikely(tp##_is_zero_or_denormal(xb.fld))) { \
2278 /* XB is not zero because of the above check and */ \
2279 /* therefore must be denormalized. */ \
2285 env->crf[BF(opcode)] = 0x8 | (fg_flag ? 4 : 0) | (fe_flag ? 2 : 0); \
2288 VSX_TSQRT(xstsqrtdp
, 1, float64
, VsrD(0), -1022, 52)
2289 VSX_TSQRT(xvtsqrtdp
, 2, float64
, VsrD(i
), -1022, 52)
2290 VSX_TSQRT(xvtsqrtsp
, 4, float32
, VsrW(i
), -126, 23)
2292 /* VSX_MADD - VSX floating point muliply/add variations
2293 * op - instruction mnemonic
2294 * nels - number of elements (1, 2 or 4)
2295 * tp - type (float32 or float64)
2296 * fld - vsr_t field (VsrD(*) or VsrW(*))
2297 * maddflgs - flags for the float*muladd routine that control the
2298 * various forms (madd, msub, nmadd, nmsub)
2299 * afrm - A form (1=A, 0=M)
2302 #define VSX_MADD(op, nels, tp, fld, maddflgs, afrm, sfprf, r2sp) \
2303 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2305 ppc_vsr_t xt_in, xa, xb, xt_out; \
2309 if (afrm) { /* AxB + T */ \
2312 } else { /* AxT + B */ \
2317 getVSR(xA(opcode), &xa, env); \
2318 getVSR(xB(opcode), &xb, env); \
2319 getVSR(xT(opcode), &xt_in, env); \
2323 helper_reset_fpstatus(env); \
2325 for (i = 0; i < nels; i++) { \
2326 float_status tstat = env->fp_status; \
2327 set_float_exception_flags(0, &tstat); \
2328 if (r2sp && (tstat.float_rounding_mode == float_round_nearest_even)) {\
2329 /* Avoid double rounding errors by rounding the intermediate */ \
2330 /* result to odd. */ \
2331 set_float_rounding_mode(float_round_to_zero, &tstat); \
2332 xt_out.fld = tp##_muladd(xa.fld, b->fld, c->fld, \
2333 maddflgs, &tstat); \
2334 xt_out.fld |= (get_float_exception_flags(&tstat) & \
2335 float_flag_inexact) != 0; \
2337 xt_out.fld = tp##_muladd(xa.fld, b->fld, c->fld, \
2338 maddflgs, &tstat); \
2340 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
2342 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
2343 tp##_maddsub_update_excp(env, xa.fld, b->fld, \
2344 c->fld, maddflgs, GETPC()); \
2348 xt_out.fld = helper_frsp(env, xt_out.fld); \
2352 helper_compute_fprf_float64(env, xt_out.fld); \
2355 putVSR(xT(opcode), &xt_out, env); \
2356 do_float_check_status(env, GETPC()); \
2359 VSX_MADD(xsmaddadp
, 1, float64
, VsrD(0), MADD_FLGS
, 1, 1, 0)
2360 VSX_MADD(xsmaddmdp
, 1, float64
, VsrD(0), MADD_FLGS
, 0, 1, 0)
2361 VSX_MADD(xsmsubadp
, 1, float64
, VsrD(0), MSUB_FLGS
, 1, 1, 0)
2362 VSX_MADD(xsmsubmdp
, 1, float64
, VsrD(0), MSUB_FLGS
, 0, 1, 0)
2363 VSX_MADD(xsnmaddadp
, 1, float64
, VsrD(0), NMADD_FLGS
, 1, 1, 0)
2364 VSX_MADD(xsnmaddmdp
, 1, float64
, VsrD(0), NMADD_FLGS
, 0, 1, 0)
2365 VSX_MADD(xsnmsubadp
, 1, float64
, VsrD(0), NMSUB_FLGS
, 1, 1, 0)
2366 VSX_MADD(xsnmsubmdp
, 1, float64
, VsrD(0), NMSUB_FLGS
, 0, 1, 0)
2368 VSX_MADD(xsmaddasp
, 1, float64
, VsrD(0), MADD_FLGS
, 1, 1, 1)
2369 VSX_MADD(xsmaddmsp
, 1, float64
, VsrD(0), MADD_FLGS
, 0, 1, 1)
2370 VSX_MADD(xsmsubasp
, 1, float64
, VsrD(0), MSUB_FLGS
, 1, 1, 1)
2371 VSX_MADD(xsmsubmsp
, 1, float64
, VsrD(0), MSUB_FLGS
, 0, 1, 1)
2372 VSX_MADD(xsnmaddasp
, 1, float64
, VsrD(0), NMADD_FLGS
, 1, 1, 1)
2373 VSX_MADD(xsnmaddmsp
, 1, float64
, VsrD(0), NMADD_FLGS
, 0, 1, 1)
2374 VSX_MADD(xsnmsubasp
, 1, float64
, VsrD(0), NMSUB_FLGS
, 1, 1, 1)
2375 VSX_MADD(xsnmsubmsp
, 1, float64
, VsrD(0), NMSUB_FLGS
, 0, 1, 1)
2377 VSX_MADD(xvmaddadp
, 2, float64
, VsrD(i
), MADD_FLGS
, 1, 0, 0)
2378 VSX_MADD(xvmaddmdp
, 2, float64
, VsrD(i
), MADD_FLGS
, 0, 0, 0)
2379 VSX_MADD(xvmsubadp
, 2, float64
, VsrD(i
), MSUB_FLGS
, 1, 0, 0)
2380 VSX_MADD(xvmsubmdp
, 2, float64
, VsrD(i
), MSUB_FLGS
, 0, 0, 0)
2381 VSX_MADD(xvnmaddadp
, 2, float64
, VsrD(i
), NMADD_FLGS
, 1, 0, 0)
2382 VSX_MADD(xvnmaddmdp
, 2, float64
, VsrD(i
), NMADD_FLGS
, 0, 0, 0)
2383 VSX_MADD(xvnmsubadp
, 2, float64
, VsrD(i
), NMSUB_FLGS
, 1, 0, 0)
2384 VSX_MADD(xvnmsubmdp
, 2, float64
, VsrD(i
), NMSUB_FLGS
, 0, 0, 0)
2386 VSX_MADD(xvmaddasp
, 4, float32
, VsrW(i
), MADD_FLGS
, 1, 0, 0)
2387 VSX_MADD(xvmaddmsp
, 4, float32
, VsrW(i
), MADD_FLGS
, 0, 0, 0)
2388 VSX_MADD(xvmsubasp
, 4, float32
, VsrW(i
), MSUB_FLGS
, 1, 0, 0)
2389 VSX_MADD(xvmsubmsp
, 4, float32
, VsrW(i
), MSUB_FLGS
, 0, 0, 0)
2390 VSX_MADD(xvnmaddasp
, 4, float32
, VsrW(i
), NMADD_FLGS
, 1, 0, 0)
2391 VSX_MADD(xvnmaddmsp
, 4, float32
, VsrW(i
), NMADD_FLGS
, 0, 0, 0)
2392 VSX_MADD(xvnmsubasp
, 4, float32
, VsrW(i
), NMSUB_FLGS
, 1, 0, 0)
2393 VSX_MADD(xvnmsubmsp
, 4, float32
, VsrW(i
), NMSUB_FLGS
, 0, 0, 0)
2395 /* VSX_SCALAR_CMP_DP - VSX scalar floating point compare double precision
2396 * op - instruction mnemonic
2397 * cmp - comparison operation
2398 * exp - expected result of comparison
2399 * svxvc - set VXVC bit
2401 #define VSX_SCALAR_CMP_DP(op, cmp, exp, svxvc) \
2402 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2404 ppc_vsr_t xt, xa, xb; \
2405 bool vxsnan_flag = false, vxvc_flag = false, vex_flag = false; \
2407 getVSR(xA(opcode), &xa, env); \
2408 getVSR(xB(opcode), &xb, env); \
2409 getVSR(xT(opcode), &xt, env); \
2411 if (float64_is_signaling_nan(xa.VsrD(0), &env->fp_status) || \
2412 float64_is_signaling_nan(xb.VsrD(0), &env->fp_status)) { \
2413 vxsnan_flag = true; \
2414 if (fpscr_ve == 0 && svxvc) { \
2417 } else if (svxvc) { \
2418 vxvc_flag = float64_is_quiet_nan(xa.VsrD(0), &env->fp_status) || \
2419 float64_is_quiet_nan(xb.VsrD(0), &env->fp_status); \
2421 if (vxsnan_flag) { \
2422 float_invalid_op_vxsnan(env, GETPC()); \
2425 float_invalid_op_vxvc(env, 0, GETPC()); \
2427 vex_flag = fpscr_ve && (vxvc_flag || vxsnan_flag); \
2430 if (float64_##cmp(xb.VsrD(0), xa.VsrD(0), &env->fp_status) == exp) { \
2438 putVSR(xT(opcode), &xt, env); \
2439 do_float_check_status(env, GETPC()); \
2442 VSX_SCALAR_CMP_DP(xscmpeqdp
, eq
, 1, 0)
2443 VSX_SCALAR_CMP_DP(xscmpgedp
, le
, 1, 1)
2444 VSX_SCALAR_CMP_DP(xscmpgtdp
, lt
, 1, 1)
2445 VSX_SCALAR_CMP_DP(xscmpnedp
, eq
, 0, 0)
2447 void helper_xscmpexpdp(CPUPPCState
*env
, uint32_t opcode
)
2450 int64_t exp_a
, exp_b
;
2453 getVSR(xA(opcode
), &xa
, env
);
2454 getVSR(xB(opcode
), &xb
, env
);
2456 exp_a
= extract64(xa
.VsrD(0), 52, 11);
2457 exp_b
= extract64(xb
.VsrD(0), 52, 11);
2459 if (unlikely(float64_is_any_nan(xa
.VsrD(0)) ||
2460 float64_is_any_nan(xb
.VsrD(0)))) {
2463 if (exp_a
< exp_b
) {
2465 } else if (exp_a
> exp_b
) {
2472 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
2473 env
->fpscr
|= cc
<< FPSCR_FPRF
;
2474 env
->crf
[BF(opcode
)] = cc
;
2476 do_float_check_status(env
, GETPC());
2479 void helper_xscmpexpqp(CPUPPCState
*env
, uint32_t opcode
)
2482 int64_t exp_a
, exp_b
;
2485 getVSR(rA(opcode
) + 32, &xa
, env
);
2486 getVSR(rB(opcode
) + 32, &xb
, env
);
2488 exp_a
= extract64(xa
.VsrD(0), 48, 15);
2489 exp_b
= extract64(xb
.VsrD(0), 48, 15);
2491 if (unlikely(float128_is_any_nan(xa
.f128
) ||
2492 float128_is_any_nan(xb
.f128
))) {
2495 if (exp_a
< exp_b
) {
2497 } else if (exp_a
> exp_b
) {
2504 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
2505 env
->fpscr
|= cc
<< FPSCR_FPRF
;
2506 env
->crf
[BF(opcode
)] = cc
;
2508 do_float_check_status(env
, GETPC());
2511 #define VSX_SCALAR_CMP(op, ordered) \
2512 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2516 bool vxsnan_flag = false, vxvc_flag = false; \
2518 helper_reset_fpstatus(env); \
2519 getVSR(xA(opcode), &xa, env); \
2520 getVSR(xB(opcode), &xb, env); \
2522 if (float64_is_signaling_nan(xa.VsrD(0), &env->fp_status) || \
2523 float64_is_signaling_nan(xb.VsrD(0), &env->fp_status)) { \
2524 vxsnan_flag = true; \
2526 if (fpscr_ve == 0 && ordered) { \
2529 } else if (float64_is_quiet_nan(xa.VsrD(0), &env->fp_status) || \
2530 float64_is_quiet_nan(xb.VsrD(0), &env->fp_status)) { \
2536 if (vxsnan_flag) { \
2537 float_invalid_op_vxsnan(env, GETPC()); \
2540 float_invalid_op_vxvc(env, 0, GETPC()); \
2543 if (float64_lt(xa.VsrD(0), xb.VsrD(0), &env->fp_status)) { \
2545 } else if (!float64_le(xa.VsrD(0), xb.VsrD(0), &env->fp_status)) { \
2551 env->fpscr &= ~(0x0F << FPSCR_FPRF); \
2552 env->fpscr |= cc << FPSCR_FPRF; \
2553 env->crf[BF(opcode)] = cc; \
2555 do_float_check_status(env, GETPC()); \
2558 VSX_SCALAR_CMP(xscmpodp
, 1)
2559 VSX_SCALAR_CMP(xscmpudp
, 0)
2561 #define VSX_SCALAR_CMPQ(op, ordered) \
2562 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2566 bool vxsnan_flag = false, vxvc_flag = false; \
2568 helper_reset_fpstatus(env); \
2569 getVSR(rA(opcode) + 32, &xa, env); \
2570 getVSR(rB(opcode) + 32, &xb, env); \
2572 if (float128_is_signaling_nan(xa.f128, &env->fp_status) || \
2573 float128_is_signaling_nan(xb.f128, &env->fp_status)) { \
2574 vxsnan_flag = true; \
2576 if (fpscr_ve == 0 && ordered) { \
2579 } else if (float128_is_quiet_nan(xa.f128, &env->fp_status) || \
2580 float128_is_quiet_nan(xb.f128, &env->fp_status)) { \
2586 if (vxsnan_flag) { \
2587 float_invalid_op_vxsnan(env, GETPC()); \
2590 float_invalid_op_vxvc(env, 0, GETPC()); \
2593 if (float128_lt(xa.f128, xb.f128, &env->fp_status)) { \
2595 } else if (!float128_le(xa.f128, xb.f128, &env->fp_status)) { \
2601 env->fpscr &= ~(0x0F << FPSCR_FPRF); \
2602 env->fpscr |= cc << FPSCR_FPRF; \
2603 env->crf[BF(opcode)] = cc; \
2605 do_float_check_status(env, GETPC()); \
2608 VSX_SCALAR_CMPQ(xscmpoqp
, 1)
2609 VSX_SCALAR_CMPQ(xscmpuqp
, 0)
2611 /* VSX_MAX_MIN - VSX floating point maximum/minimum
2612 * name - instruction mnemonic
2613 * op - operation (max or min)
2614 * nels - number of elements (1, 2 or 4)
2615 * tp - type (float32 or float64)
2616 * fld - vsr_t field (VsrD(*) or VsrW(*))
2618 #define VSX_MAX_MIN(name, op, nels, tp, fld) \
2619 void helper_##name(CPUPPCState *env, uint32_t opcode) \
2621 ppc_vsr_t xt, xa, xb; \
2624 getVSR(xA(opcode), &xa, env); \
2625 getVSR(xB(opcode), &xb, env); \
2626 getVSR(xT(opcode), &xt, env); \
2628 for (i = 0; i < nels; i++) { \
2629 xt.fld = tp##_##op(xa.fld, xb.fld, &env->fp_status); \
2630 if (unlikely(tp##_is_signaling_nan(xa.fld, &env->fp_status) || \
2631 tp##_is_signaling_nan(xb.fld, &env->fp_status))) { \
2632 float_invalid_op_vxsnan(env, GETPC()); \
2636 putVSR(xT(opcode), &xt, env); \
2637 do_float_check_status(env, GETPC()); \
2640 VSX_MAX_MIN(xsmaxdp
, maxnum
, 1, float64
, VsrD(0))
2641 VSX_MAX_MIN(xvmaxdp
, maxnum
, 2, float64
, VsrD(i
))
2642 VSX_MAX_MIN(xvmaxsp
, maxnum
, 4, float32
, VsrW(i
))
2643 VSX_MAX_MIN(xsmindp
, minnum
, 1, float64
, VsrD(0))
2644 VSX_MAX_MIN(xvmindp
, minnum
, 2, float64
, VsrD(i
))
2645 VSX_MAX_MIN(xvminsp
, minnum
, 4, float32
, VsrW(i
))
2647 #define VSX_MAX_MINC(name, max) \
2648 void helper_##name(CPUPPCState *env, uint32_t opcode) \
2650 ppc_vsr_t xt, xa, xb; \
2651 bool vxsnan_flag = false, vex_flag = false; \
2653 getVSR(rA(opcode) + 32, &xa, env); \
2654 getVSR(rB(opcode) + 32, &xb, env); \
2655 getVSR(rD(opcode) + 32, &xt, env); \
2657 if (unlikely(float64_is_any_nan(xa.VsrD(0)) || \
2658 float64_is_any_nan(xb.VsrD(0)))) { \
2659 if (float64_is_signaling_nan(xa.VsrD(0), &env->fp_status) || \
2660 float64_is_signaling_nan(xb.VsrD(0), &env->fp_status)) { \
2661 vxsnan_flag = true; \
2663 xt.VsrD(0) = xb.VsrD(0); \
2664 } else if ((max && \
2665 !float64_lt(xa.VsrD(0), xb.VsrD(0), &env->fp_status)) || \
2667 float64_lt(xa.VsrD(0), xb.VsrD(0), &env->fp_status))) { \
2668 xt.VsrD(0) = xa.VsrD(0); \
2670 xt.VsrD(0) = xb.VsrD(0); \
2673 vex_flag = fpscr_ve & vxsnan_flag; \
2674 if (vxsnan_flag) { \
2675 float_invalid_op_vxsnan(env, GETPC()); \
2678 putVSR(rD(opcode) + 32, &xt, env); \
2682 VSX_MAX_MINC(xsmaxcdp, 1);
2683 VSX_MAX_MINC(xsmincdp
, 0);
2685 #define VSX_MAX_MINJ(name, max) \
2686 void helper_##name(CPUPPCState *env, uint32_t opcode) \
2688 ppc_vsr_t xt, xa, xb; \
2689 bool vxsnan_flag = false, vex_flag = false; \
2691 getVSR(rA(opcode) + 32, &xa, env); \
2692 getVSR(rB(opcode) + 32, &xb, env); \
2693 getVSR(rD(opcode) + 32, &xt, env); \
2695 if (unlikely(float64_is_any_nan(xa.VsrD(0)))) { \
2696 if (float64_is_signaling_nan(xa.VsrD(0), &env->fp_status)) { \
2697 vxsnan_flag = true; \
2699 xt.VsrD(0) = xa.VsrD(0); \
2700 } else if (unlikely(float64_is_any_nan(xb.VsrD(0)))) { \
2701 if (float64_is_signaling_nan(xb.VsrD(0), &env->fp_status)) { \
2702 vxsnan_flag = true; \
2704 xt.VsrD(0) = xb.VsrD(0); \
2705 } else if (float64_is_zero(xa.VsrD(0)) && float64_is_zero(xb.VsrD(0))) { \
2707 if (!float64_is_neg(xa.VsrD(0)) || !float64_is_neg(xb.VsrD(0))) { \
2708 xt.VsrD(0) = 0ULL; \
2710 xt.VsrD(0) = 0x8000000000000000ULL; \
2713 if (float64_is_neg(xa.VsrD(0)) || float64_is_neg(xb.VsrD(0))) { \
2714 xt.VsrD(0) = 0x8000000000000000ULL; \
2716 xt.VsrD(0) = 0ULL; \
2719 } else if ((max && \
2720 !float64_lt(xa.VsrD(0), xb.VsrD(0), &env->fp_status)) || \
2722 float64_lt(xa.VsrD(0), xb.VsrD(0), &env->fp_status))) { \
2723 xt.VsrD(0) = xa.VsrD(0); \
2725 xt.VsrD(0) = xb.VsrD(0); \
2728 vex_flag = fpscr_ve & vxsnan_flag; \
2729 if (vxsnan_flag) { \
2730 float_invalid_op_vxsnan(env, GETPC()); \
2733 putVSR(rD(opcode) + 32, &xt, env); \
2737 VSX_MAX_MINJ(xsmaxjdp, 1);
2738 VSX_MAX_MINJ(xsminjdp
, 0);
2740 /* VSX_CMP - VSX floating point compare
2741 * op - instruction mnemonic
2742 * nels - number of elements (1, 2 or 4)
2743 * tp - type (float32 or float64)
2744 * fld - vsr_t field (VsrD(*) or VsrW(*))
2745 * cmp - comparison operation
2746 * svxvc - set VXVC bit
2747 * exp - expected result of comparison
2749 #define VSX_CMP(op, nels, tp, fld, cmp, svxvc, exp) \
2750 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2752 ppc_vsr_t xt, xa, xb; \
2755 int all_false = 1; \
2757 getVSR(xA(opcode), &xa, env); \
2758 getVSR(xB(opcode), &xb, env); \
2759 getVSR(xT(opcode), &xt, env); \
2761 for (i = 0; i < nels; i++) { \
2762 if (unlikely(tp##_is_any_nan(xa.fld) || \
2763 tp##_is_any_nan(xb.fld))) { \
2764 if (tp##_is_signaling_nan(xa.fld, &env->fp_status) || \
2765 tp##_is_signaling_nan(xb.fld, &env->fp_status)) { \
2766 float_invalid_op_vxsnan(env, GETPC()); \
2769 float_invalid_op_vxvc(env, 0, GETPC()); \
2774 if (tp##_##cmp(xb.fld, xa.fld, &env->fp_status) == exp) { \
2784 putVSR(xT(opcode), &xt, env); \
2785 if ((opcode >> (31-21)) & 1) { \
2786 env->crf[6] = (all_true ? 0x8 : 0) | (all_false ? 0x2 : 0); \
2788 do_float_check_status(env, GETPC()); \
2791 VSX_CMP(xvcmpeqdp
, 2, float64
, VsrD(i
), eq
, 0, 1)
2792 VSX_CMP(xvcmpgedp
, 2, float64
, VsrD(i
), le
, 1, 1)
2793 VSX_CMP(xvcmpgtdp
, 2, float64
, VsrD(i
), lt
, 1, 1)
2794 VSX_CMP(xvcmpnedp
, 2, float64
, VsrD(i
), eq
, 0, 0)
2795 VSX_CMP(xvcmpeqsp
, 4, float32
, VsrW(i
), eq
, 0, 1)
2796 VSX_CMP(xvcmpgesp
, 4, float32
, VsrW(i
), le
, 1, 1)
2797 VSX_CMP(xvcmpgtsp
, 4, float32
, VsrW(i
), lt
, 1, 1)
2798 VSX_CMP(xvcmpnesp
, 4, float32
, VsrW(i
), eq
, 0, 0)
2800 /* VSX_CVT_FP_TO_FP - VSX floating point/floating point conversion
2801 * op - instruction mnemonic
2802 * nels - number of elements (1, 2 or 4)
2803 * stp - source type (float32 or float64)
2804 * ttp - target type (float32 or float64)
2805 * sfld - source vsr_t field
2806 * tfld - target vsr_t field (f32 or f64)
2809 #define VSX_CVT_FP_TO_FP(op, nels, stp, ttp, sfld, tfld, sfprf) \
2810 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2815 getVSR(xB(opcode), &xb, env); \
2816 getVSR(xT(opcode), &xt, env); \
2818 for (i = 0; i < nels; i++) { \
2819 xt.tfld = stp##_to_##ttp(xb.sfld, &env->fp_status); \
2820 if (unlikely(stp##_is_signaling_nan(xb.sfld, \
2821 &env->fp_status))) { \
2822 float_invalid_op_vxsnan(env, GETPC()); \
2823 xt.tfld = ttp##_snan_to_qnan(xt.tfld); \
2826 helper_compute_fprf_##ttp(env, xt.tfld); \
2830 putVSR(xT(opcode), &xt, env); \
2831 do_float_check_status(env, GETPC()); \
2834 VSX_CVT_FP_TO_FP(xscvdpsp
, 1, float64
, float32
, VsrD(0), VsrW(0), 1)
2835 VSX_CVT_FP_TO_FP(xscvspdp
, 1, float32
, float64
, VsrW(0), VsrD(0), 1)
2836 VSX_CVT_FP_TO_FP(xvcvdpsp
, 2, float64
, float32
, VsrD(i
), VsrW(2*i
), 0)
2837 VSX_CVT_FP_TO_FP(xvcvspdp
, 2, float32
, float64
, VsrW(2*i
), VsrD(i
), 0)
2839 /* VSX_CVT_FP_TO_FP_VECTOR - VSX floating point/floating point conversion
2840 * op - instruction mnemonic
2841 * nels - number of elements (1, 2 or 4)
2842 * stp - source type (float32 or float64)
2843 * ttp - target type (float32 or float64)
2844 * sfld - source vsr_t field
2845 * tfld - target vsr_t field (f32 or f64)
2848 #define VSX_CVT_FP_TO_FP_VECTOR(op, nels, stp, ttp, sfld, tfld, sfprf) \
2849 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2854 getVSR(rB(opcode) + 32, &xb, env); \
2855 getVSR(rD(opcode) + 32, &xt, env); \
2857 for (i = 0; i < nels; i++) { \
2858 xt.tfld = stp##_to_##ttp(xb.sfld, &env->fp_status); \
2859 if (unlikely(stp##_is_signaling_nan(xb.sfld, \
2860 &env->fp_status))) { \
2861 float_invalid_op_vxsnan(env, GETPC()); \
2862 xt.tfld = ttp##_snan_to_qnan(xt.tfld); \
2865 helper_compute_fprf_##ttp(env, xt.tfld); \
2869 putVSR(rD(opcode) + 32, &xt, env); \
2870 do_float_check_status(env, GETPC()); \
2873 VSX_CVT_FP_TO_FP_VECTOR(xscvdpqp
, 1, float64
, float128
, VsrD(0), f128
, 1)
2875 /* VSX_CVT_FP_TO_FP_HP - VSX floating point/floating point conversion
2876 * involving one half precision value
2877 * op - instruction mnemonic
2878 * nels - number of elements (1, 2 or 4)
2881 * sfld - source vsr_t field
2882 * tfld - target vsr_t field
2885 #define VSX_CVT_FP_TO_FP_HP(op, nels, stp, ttp, sfld, tfld, sfprf) \
2886 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2891 getVSR(xB(opcode), &xb, env); \
2892 memset(&xt, 0, sizeof(xt)); \
2894 for (i = 0; i < nels; i++) { \
2895 xt.tfld = stp##_to_##ttp(xb.sfld, 1, &env->fp_status); \
2896 if (unlikely(stp##_is_signaling_nan(xb.sfld, \
2897 &env->fp_status))) { \
2898 float_invalid_op_vxsnan(env, GETPC()); \
2899 xt.tfld = ttp##_snan_to_qnan(xt.tfld); \
2902 helper_compute_fprf_##ttp(env, xt.tfld); \
2906 putVSR(xT(opcode), &xt, env); \
2907 do_float_check_status(env, GETPC()); \
2910 VSX_CVT_FP_TO_FP_HP(xscvdphp
, 1, float64
, float16
, VsrD(0), VsrH(3), 1)
2911 VSX_CVT_FP_TO_FP_HP(xscvhpdp
, 1, float16
, float64
, VsrH(3), VsrD(0), 1)
2912 VSX_CVT_FP_TO_FP_HP(xvcvsphp
, 4, float32
, float16
, VsrW(i
), VsrH(2 * i
+ 1), 0)
2913 VSX_CVT_FP_TO_FP_HP(xvcvhpsp
, 4, float16
, float32
, VsrH(2 * i
+ 1), VsrW(i
), 0)
2916 * xscvqpdp isn't using VSX_CVT_FP_TO_FP() because xscvqpdpo will be
2917 * added to this later.
2919 void helper_xscvqpdp(CPUPPCState
*env
, uint32_t opcode
)
2924 getVSR(rB(opcode
) + 32, &xb
, env
);
2925 memset(&xt
, 0, sizeof(xt
));
2927 tstat
= env
->fp_status
;
2928 if (unlikely(Rc(opcode
) != 0)) {
2929 tstat
.float_rounding_mode
= float_round_to_odd
;
2932 xt
.VsrD(0) = float128_to_float64(xb
.f128
, &tstat
);
2933 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
2934 if (unlikely(float128_is_signaling_nan(xb
.f128
, &tstat
))) {
2935 float_invalid_op_vxsnan(env
, GETPC());
2936 xt
.VsrD(0) = float64_snan_to_qnan(xt
.VsrD(0));
2938 helper_compute_fprf_float64(env
, xt
.VsrD(0));
2940 putVSR(rD(opcode
) + 32, &xt
, env
);
2941 do_float_check_status(env
, GETPC());
2944 uint64_t helper_xscvdpspn(CPUPPCState
*env
, uint64_t xb
)
2946 float_status tstat
= env
->fp_status
;
2947 set_float_exception_flags(0, &tstat
);
2949 return (uint64_t)float64_to_float32(xb
, &tstat
) << 32;
2952 uint64_t helper_xscvspdpn(CPUPPCState
*env
, uint64_t xb
)
2954 float_status tstat
= env
->fp_status
;
2955 set_float_exception_flags(0, &tstat
);
2957 return float32_to_float64(xb
>> 32, &tstat
);
2960 /* VSX_CVT_FP_TO_INT - VSX floating point to integer conversion
2961 * op - instruction mnemonic
2962 * nels - number of elements (1, 2 or 4)
2963 * stp - source type (float32 or float64)
2964 * ttp - target type (int32, uint32, int64 or uint64)
2965 * sfld - source vsr_t field
2966 * tfld - target vsr_t field
2967 * rnan - resulting NaN
2969 #define VSX_CVT_FP_TO_INT(op, nels, stp, ttp, sfld, tfld, rnan) \
2970 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2975 getVSR(xB(opcode), &xb, env); \
2976 getVSR(xT(opcode), &xt, env); \
2978 for (i = 0; i < nels; i++) { \
2979 if (unlikely(stp##_is_any_nan(xb.sfld))) { \
2980 if (stp##_is_signaling_nan(xb.sfld, &env->fp_status)) { \
2981 float_invalid_op_vxsnan(env, GETPC()); \
2983 float_invalid_op_vxcvi(env, 0, GETPC()); \
2986 xt.tfld = stp##_to_##ttp##_round_to_zero(xb.sfld, \
2988 if (env->fp_status.float_exception_flags & float_flag_invalid) { \
2989 float_invalid_op_vxcvi(env, 0, GETPC()); \
2994 putVSR(xT(opcode), &xt, env); \
2995 do_float_check_status(env, GETPC()); \
2998 VSX_CVT_FP_TO_INT(xscvdpsxds
, 1, float64
, int64
, VsrD(0), VsrD(0), \
2999 0x8000000000000000ULL
)
3000 VSX_CVT_FP_TO_INT(xscvdpsxws
, 1, float64
, int32
, VsrD(0), VsrW(1), \
3002 VSX_CVT_FP_TO_INT(xscvdpuxds
, 1, float64
, uint64
, VsrD(0), VsrD(0), 0ULL)
3003 VSX_CVT_FP_TO_INT(xscvdpuxws
, 1, float64
, uint32
, VsrD(0), VsrW(1), 0U)
3004 VSX_CVT_FP_TO_INT(xvcvdpsxds
, 2, float64
, int64
, VsrD(i
), VsrD(i
), \
3005 0x8000000000000000ULL
)
3006 VSX_CVT_FP_TO_INT(xvcvdpsxws
, 2, float64
, int32
, VsrD(i
), VsrW(2*i
), \
3008 VSX_CVT_FP_TO_INT(xvcvdpuxds
, 2, float64
, uint64
, VsrD(i
), VsrD(i
), 0ULL)
3009 VSX_CVT_FP_TO_INT(xvcvdpuxws
, 2, float64
, uint32
, VsrD(i
), VsrW(2*i
), 0U)
3010 VSX_CVT_FP_TO_INT(xvcvspsxds
, 2, float32
, int64
, VsrW(2*i
), VsrD(i
), \
3011 0x8000000000000000ULL
)
3012 VSX_CVT_FP_TO_INT(xvcvspsxws
, 4, float32
, int32
, VsrW(i
), VsrW(i
), 0x80000000U
)
3013 VSX_CVT_FP_TO_INT(xvcvspuxds
, 2, float32
, uint64
, VsrW(2*i
), VsrD(i
), 0ULL)
3014 VSX_CVT_FP_TO_INT(xvcvspuxws
, 4, float32
, uint32
, VsrW(i
), VsrW(i
), 0U)
3016 /* VSX_CVT_FP_TO_INT_VECTOR - VSX floating point to integer conversion
3017 * op - instruction mnemonic
3018 * stp - source type (float32 or float64)
3019 * ttp - target type (int32, uint32, int64 or uint64)
3020 * sfld - source vsr_t field
3021 * tfld - target vsr_t field
3022 * rnan - resulting NaN
3024 #define VSX_CVT_FP_TO_INT_VECTOR(op, stp, ttp, sfld, tfld, rnan) \
3025 void helper_##op(CPUPPCState *env, uint32_t opcode) \
3029 getVSR(rB(opcode) + 32, &xb, env); \
3030 memset(&xt, 0, sizeof(xt)); \
3032 if (unlikely(stp##_is_any_nan(xb.sfld))) { \
3033 if (stp##_is_signaling_nan(xb.sfld, &env->fp_status)) { \
3034 float_invalid_op_vxsnan(env, GETPC()); \
3036 float_invalid_op_vxcvi(env, 0, GETPC()); \
3039 xt.tfld = stp##_to_##ttp##_round_to_zero(xb.sfld, \
3041 if (env->fp_status.float_exception_flags & float_flag_invalid) { \
3042 float_invalid_op_vxcvi(env, 0, GETPC()); \
3046 putVSR(rD(opcode) + 32, &xt, env); \
3047 do_float_check_status(env, GETPC()); \
3050 VSX_CVT_FP_TO_INT_VECTOR(xscvqpsdz
, float128
, int64
, f128
, VsrD(0), \
3051 0x8000000000000000ULL
)
3053 VSX_CVT_FP_TO_INT_VECTOR(xscvqpswz
, float128
, int32
, f128
, VsrD(0), \
3054 0xffffffff80000000ULL
)
3055 VSX_CVT_FP_TO_INT_VECTOR(xscvqpudz
, float128
, uint64
, f128
, VsrD(0), 0x0ULL
)
3056 VSX_CVT_FP_TO_INT_VECTOR(xscvqpuwz
, float128
, uint32
, f128
, VsrD(0), 0x0ULL
)
3058 /* VSX_CVT_INT_TO_FP - VSX integer to floating point conversion
3059 * op - instruction mnemonic
3060 * nels - number of elements (1, 2 or 4)
3061 * stp - source type (int32, uint32, int64 or uint64)
3062 * ttp - target type (float32 or float64)
3063 * sfld - source vsr_t field
3064 * tfld - target vsr_t field
3065 * jdef - definition of the j index (i or 2*i)
3068 #define VSX_CVT_INT_TO_FP(op, nels, stp, ttp, sfld, tfld, sfprf, r2sp) \
3069 void helper_##op(CPUPPCState *env, uint32_t opcode) \
3074 getVSR(xB(opcode), &xb, env); \
3075 getVSR(xT(opcode), &xt, env); \
3077 for (i = 0; i < nels; i++) { \
3078 xt.tfld = stp##_to_##ttp(xb.sfld, &env->fp_status); \
3080 xt.tfld = helper_frsp(env, xt.tfld); \
3083 helper_compute_fprf_float64(env, xt.tfld); \
3087 putVSR(xT(opcode), &xt, env); \
3088 do_float_check_status(env, GETPC()); \
3091 VSX_CVT_INT_TO_FP(xscvsxddp
, 1, int64
, float64
, VsrD(0), VsrD(0), 1, 0)
3092 VSX_CVT_INT_TO_FP(xscvuxddp
, 1, uint64
, float64
, VsrD(0), VsrD(0), 1, 0)
3093 VSX_CVT_INT_TO_FP(xscvsxdsp
, 1, int64
, float64
, VsrD(0), VsrD(0), 1, 1)
3094 VSX_CVT_INT_TO_FP(xscvuxdsp
, 1, uint64
, float64
, VsrD(0), VsrD(0), 1, 1)
3095 VSX_CVT_INT_TO_FP(xvcvsxddp
, 2, int64
, float64
, VsrD(i
), VsrD(i
), 0, 0)
3096 VSX_CVT_INT_TO_FP(xvcvuxddp
, 2, uint64
, float64
, VsrD(i
), VsrD(i
), 0, 0)
3097 VSX_CVT_INT_TO_FP(xvcvsxwdp
, 2, int32
, float64
, VsrW(2*i
), VsrD(i
), 0, 0)
3098 VSX_CVT_INT_TO_FP(xvcvuxwdp
, 2, uint64
, float64
, VsrW(2*i
), VsrD(i
), 0, 0)
3099 VSX_CVT_INT_TO_FP(xvcvsxdsp
, 2, int64
, float32
, VsrD(i
), VsrW(2*i
), 0, 0)
3100 VSX_CVT_INT_TO_FP(xvcvuxdsp
, 2, uint64
, float32
, VsrD(i
), VsrW(2*i
), 0, 0)
3101 VSX_CVT_INT_TO_FP(xvcvsxwsp
, 4, int32
, float32
, VsrW(i
), VsrW(i
), 0, 0)
3102 VSX_CVT_INT_TO_FP(xvcvuxwsp
, 4, uint32
, float32
, VsrW(i
), VsrW(i
), 0, 0)
3104 /* VSX_CVT_INT_TO_FP_VECTOR - VSX integer to floating point conversion
3105 * op - instruction mnemonic
3106 * stp - source type (int32, uint32, int64 or uint64)
3107 * ttp - target type (float32 or float64)
3108 * sfld - source vsr_t field
3109 * tfld - target vsr_t field
3111 #define VSX_CVT_INT_TO_FP_VECTOR(op, stp, ttp, sfld, tfld) \
3112 void helper_##op(CPUPPCState *env, uint32_t opcode) \
3116 getVSR(rB(opcode) + 32, &xb, env); \
3117 getVSR(rD(opcode) + 32, &xt, env); \
3119 xt.tfld = stp##_to_##ttp(xb.sfld, &env->fp_status); \
3120 helper_compute_fprf_##ttp(env, xt.tfld); \
3122 putVSR(xT(opcode) + 32, &xt, env); \
3123 do_float_check_status(env, GETPC()); \
3126 VSX_CVT_INT_TO_FP_VECTOR(xscvsdqp
, int64
, float128
, VsrD(0), f128
)
3127 VSX_CVT_INT_TO_FP_VECTOR(xscvudqp
, uint64
, float128
, VsrD(0), f128
)
3129 /* For "use current rounding mode", define a value that will not be one of
3130 * the existing rounding model enums.
3132 #define FLOAT_ROUND_CURRENT (float_round_nearest_even + float_round_down + \
3133 float_round_up + float_round_to_zero)
3135 /* VSX_ROUND - VSX floating point round
3136 * op - instruction mnemonic
3137 * nels - number of elements (1, 2 or 4)
3138 * tp - type (float32 or float64)
3139 * fld - vsr_t field (VsrD(*) or VsrW(*))
3140 * rmode - rounding mode
3143 #define VSX_ROUND(op, nels, tp, fld, rmode, sfprf) \
3144 void helper_##op(CPUPPCState *env, uint32_t opcode) \
3148 getVSR(xB(opcode), &xb, env); \
3149 getVSR(xT(opcode), &xt, env); \
3151 if (rmode != FLOAT_ROUND_CURRENT) { \
3152 set_float_rounding_mode(rmode, &env->fp_status); \
3155 for (i = 0; i < nels; i++) { \
3156 if (unlikely(tp##_is_signaling_nan(xb.fld, \
3157 &env->fp_status))) { \
3158 float_invalid_op_vxsnan(env, GETPC()); \
3159 xt.fld = tp##_snan_to_qnan(xb.fld); \
3161 xt.fld = tp##_round_to_int(xb.fld, &env->fp_status); \
3164 helper_compute_fprf_float64(env, xt.fld); \
3168 /* If this is not a "use current rounding mode" instruction, \
3169 * then inhibit setting of the XX bit and restore rounding \
3170 * mode from FPSCR */ \
3171 if (rmode != FLOAT_ROUND_CURRENT) { \
3172 fpscr_set_rounding_mode(env); \
3173 env->fp_status.float_exception_flags &= ~float_flag_inexact; \
3176 putVSR(xT(opcode), &xt, env); \
3177 do_float_check_status(env, GETPC()); \
3180 VSX_ROUND(xsrdpi
, 1, float64
, VsrD(0), float_round_ties_away
, 1)
3181 VSX_ROUND(xsrdpic
, 1, float64
, VsrD(0), FLOAT_ROUND_CURRENT
, 1)
3182 VSX_ROUND(xsrdpim
, 1, float64
, VsrD(0), float_round_down
, 1)
3183 VSX_ROUND(xsrdpip
, 1, float64
, VsrD(0), float_round_up
, 1)
3184 VSX_ROUND(xsrdpiz
, 1, float64
, VsrD(0), float_round_to_zero
, 1)
3186 VSX_ROUND(xvrdpi
, 2, float64
, VsrD(i
), float_round_ties_away
, 0)
3187 VSX_ROUND(xvrdpic
, 2, float64
, VsrD(i
), FLOAT_ROUND_CURRENT
, 0)
3188 VSX_ROUND(xvrdpim
, 2, float64
, VsrD(i
), float_round_down
, 0)
3189 VSX_ROUND(xvrdpip
, 2, float64
, VsrD(i
), float_round_up
, 0)
3190 VSX_ROUND(xvrdpiz
, 2, float64
, VsrD(i
), float_round_to_zero
, 0)
3192 VSX_ROUND(xvrspi
, 4, float32
, VsrW(i
), float_round_ties_away
, 0)
3193 VSX_ROUND(xvrspic
, 4, float32
, VsrW(i
), FLOAT_ROUND_CURRENT
, 0)
3194 VSX_ROUND(xvrspim
, 4, float32
, VsrW(i
), float_round_down
, 0)
3195 VSX_ROUND(xvrspip
, 4, float32
, VsrW(i
), float_round_up
, 0)
3196 VSX_ROUND(xvrspiz
, 4, float32
, VsrW(i
), float_round_to_zero
, 0)
3198 uint64_t helper_xsrsp(CPUPPCState
*env
, uint64_t xb
)
3200 helper_reset_fpstatus(env
);
3202 uint64_t xt
= helper_frsp(env
, xb
);
3204 helper_compute_fprf_float64(env
, xt
);
3205 do_float_check_status(env
, GETPC());
3209 #define VSX_XXPERM(op, indexed) \
3210 void helper_##op(CPUPPCState *env, uint32_t opcode) \
3212 ppc_vsr_t xt, xa, pcv, xto; \
3215 getVSR(xA(opcode), &xa, env); \
3216 getVSR(xT(opcode), &xt, env); \
3217 getVSR(xB(opcode), &pcv, env); \
3219 for (i = 0; i < 16; i++) { \
3220 idx = pcv.VsrB(i) & 0x1F; \
3224 xto.VsrB(i) = (idx <= 15) ? xa.VsrB(idx) : xt.VsrB(idx - 16); \
3226 putVSR(xT(opcode), &xto, env); \
3229 VSX_XXPERM(xxperm
, 0)
3230 VSX_XXPERM(xxpermr
, 1)
3232 void helper_xvxsigsp(CPUPPCState
*env
, uint32_t opcode
)
3235 uint32_t exp
, i
, fraction
;
3237 getVSR(xB(opcode
), &xb
, env
);
3238 memset(&xt
, 0, sizeof(xt
));
3240 for (i
= 0; i
< 4; i
++) {
3241 exp
= (xb
.VsrW(i
) >> 23) & 0xFF;
3242 fraction
= xb
.VsrW(i
) & 0x7FFFFF;
3243 if (exp
!= 0 && exp
!= 255) {
3244 xt
.VsrW(i
) = fraction
| 0x00800000;
3246 xt
.VsrW(i
) = fraction
;
3249 putVSR(xT(opcode
), &xt
, env
);
3252 /* VSX_TEST_DC - VSX floating point test data class
3253 * op - instruction mnemonic
3254 * nels - number of elements (1, 2 or 4)
3255 * xbn - VSR register number
3256 * tp - type (float32 or float64)
3257 * fld - vsr_t field (VsrD(*) or VsrW(*))
3258 * tfld - target vsr_t field (VsrD(*) or VsrW(*))
3259 * fld_max - target field max
3260 * scrf - set result in CR and FPCC
3262 #define VSX_TEST_DC(op, nels, xbn, tp, fld, tfld, fld_max, scrf) \
3263 void helper_##op(CPUPPCState *env, uint32_t opcode) \
3266 uint32_t i, sign, dcmx; \
3267 uint32_t cc, match = 0; \
3269 getVSR(xbn, &xb, env); \
3271 memset(&xt, 0, sizeof(xt)); \
3272 dcmx = DCMX_XV(opcode); \
3274 dcmx = DCMX(opcode); \
3277 for (i = 0; i < nels; i++) { \
3278 sign = tp##_is_neg(xb.fld); \
3279 if (tp##_is_any_nan(xb.fld)) { \
3280 match = extract32(dcmx, 6, 1); \
3281 } else if (tp##_is_infinity(xb.fld)) { \
3282 match = extract32(dcmx, 4 + !sign, 1); \
3283 } else if (tp##_is_zero(xb.fld)) { \
3284 match = extract32(dcmx, 2 + !sign, 1); \
3285 } else if (tp##_is_zero_or_denormal(xb.fld)) { \
3286 match = extract32(dcmx, 0 + !sign, 1); \
3290 cc = sign << CRF_LT_BIT | match << CRF_EQ_BIT; \
3291 env->fpscr &= ~(0x0F << FPSCR_FPRF); \
3292 env->fpscr |= cc << FPSCR_FPRF; \
3293 env->crf[BF(opcode)] = cc; \
3295 xt.tfld = match ? fld_max : 0; \
3300 putVSR(xT(opcode), &xt, env); \
3304 VSX_TEST_DC(xvtstdcdp
, 2, xB(opcode
), float64
, VsrD(i
), VsrD(i
), UINT64_MAX
, 0)
3305 VSX_TEST_DC(xvtstdcsp
, 4, xB(opcode
), float32
, VsrW(i
), VsrW(i
), UINT32_MAX
, 0)
3306 VSX_TEST_DC(xststdcdp
, 1, xB(opcode
), float64
, VsrD(0), VsrD(0), 0, 1)
3307 VSX_TEST_DC(xststdcqp
, 1, (rB(opcode
) + 32), float128
, f128
, VsrD(0), 0, 1)
3309 void helper_xststdcsp(CPUPPCState
*env
, uint32_t opcode
)
3312 uint32_t dcmx
, sign
, exp
;
3313 uint32_t cc
, match
= 0, not_sp
= 0;
3315 getVSR(xB(opcode
), &xb
, env
);
3316 dcmx
= DCMX(opcode
);
3317 exp
= (xb
.VsrD(0) >> 52) & 0x7FF;
3319 sign
= float64_is_neg(xb
.VsrD(0));
3320 if (float64_is_any_nan(xb
.VsrD(0))) {
3321 match
= extract32(dcmx
, 6, 1);
3322 } else if (float64_is_infinity(xb
.VsrD(0))) {
3323 match
= extract32(dcmx
, 4 + !sign
, 1);
3324 } else if (float64_is_zero(xb
.VsrD(0))) {
3325 match
= extract32(dcmx
, 2 + !sign
, 1);
3326 } else if (float64_is_zero_or_denormal(xb
.VsrD(0)) ||
3327 (exp
> 0 && exp
< 0x381)) {
3328 match
= extract32(dcmx
, 0 + !sign
, 1);
3331 not_sp
= !float64_eq(xb
.VsrD(0),
3333 float64_to_float32(xb
.VsrD(0), &env
->fp_status
),
3334 &env
->fp_status
), &env
->fp_status
);
3336 cc
= sign
<< CRF_LT_BIT
| match
<< CRF_EQ_BIT
| not_sp
<< CRF_SO_BIT
;
3337 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
3338 env
->fpscr
|= cc
<< FPSCR_FPRF
;
3339 env
->crf
[BF(opcode
)] = cc
;
3342 void helper_xsrqpi(CPUPPCState
*env
, uint32_t opcode
)
3346 uint8_t r
= Rrm(opcode
);
3347 uint8_t ex
= Rc(opcode
);
3348 uint8_t rmc
= RMC(opcode
);
3352 getVSR(rB(opcode
) + 32, &xb
, env
);
3353 memset(&xt
, 0, sizeof(xt
));
3354 helper_reset_fpstatus(env
);
3356 if (r
== 0 && rmc
== 0) {
3357 rmode
= float_round_ties_away
;
3358 } else if (r
== 0 && rmc
== 0x3) {
3360 } else if (r
== 1) {
3363 rmode
= float_round_nearest_even
;
3366 rmode
= float_round_to_zero
;
3369 rmode
= float_round_up
;
3372 rmode
= float_round_down
;
3379 tstat
= env
->fp_status
;
3380 set_float_exception_flags(0, &tstat
);
3381 set_float_rounding_mode(rmode
, &tstat
);
3382 xt
.f128
= float128_round_to_int(xb
.f128
, &tstat
);
3383 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3385 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
3386 if (float128_is_signaling_nan(xb
.f128
, &tstat
)) {
3387 float_invalid_op_vxsnan(env
, GETPC());
3388 xt
.f128
= float128_snan_to_qnan(xt
.f128
);
3392 if (ex
== 0 && (tstat
.float_exception_flags
& float_flag_inexact
)) {
3393 env
->fp_status
.float_exception_flags
&= ~float_flag_inexact
;
3396 helper_compute_fprf_float128(env
, xt
.f128
);
3397 do_float_check_status(env
, GETPC());
3398 putVSR(rD(opcode
) + 32, &xt
, env
);
3401 void helper_xsrqpxp(CPUPPCState
*env
, uint32_t opcode
)
3405 uint8_t r
= Rrm(opcode
);
3406 uint8_t rmc
= RMC(opcode
);
3411 getVSR(rB(opcode
) + 32, &xb
, env
);
3412 memset(&xt
, 0, sizeof(xt
));
3413 helper_reset_fpstatus(env
);
3415 if (r
== 0 && rmc
== 0) {
3416 rmode
= float_round_ties_away
;
3417 } else if (r
== 0 && rmc
== 0x3) {
3419 } else if (r
== 1) {
3422 rmode
= float_round_nearest_even
;
3425 rmode
= float_round_to_zero
;
3428 rmode
= float_round_up
;
3431 rmode
= float_round_down
;
3438 tstat
= env
->fp_status
;
3439 set_float_exception_flags(0, &tstat
);
3440 set_float_rounding_mode(rmode
, &tstat
);
3441 round_res
= float128_to_floatx80(xb
.f128
, &tstat
);
3442 xt
.f128
= floatx80_to_float128(round_res
, &tstat
);
3443 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3445 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
3446 if (float128_is_signaling_nan(xb
.f128
, &tstat
)) {
3447 float_invalid_op_vxsnan(env
, GETPC());
3448 xt
.f128
= float128_snan_to_qnan(xt
.f128
);
3452 helper_compute_fprf_float128(env
, xt
.f128
);
3453 putVSR(rD(opcode
) + 32, &xt
, env
);
3454 do_float_check_status(env
, GETPC());
3457 void helper_xssqrtqp(CPUPPCState
*env
, uint32_t opcode
)
3463 getVSR(rB(opcode
) + 32, &xb
, env
);
3464 memset(&xt
, 0, sizeof(xt
));
3465 helper_reset_fpstatus(env
);
3467 tstat
= env
->fp_status
;
3468 if (unlikely(Rc(opcode
) != 0)) {
3469 tstat
.float_rounding_mode
= float_round_to_odd
;
3472 set_float_exception_flags(0, &tstat
);
3473 xt
.f128
= float128_sqrt(xb
.f128
, &tstat
);
3474 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3476 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
3477 if (float128_is_signaling_nan(xb
.f128
, &tstat
)) {
3478 float_invalid_op_vxsnan(env
, GETPC());
3479 xt
.f128
= float128_snan_to_qnan(xb
.f128
);
3480 } else if (float128_is_quiet_nan(xb
.f128
, &tstat
)) {
3482 } else if (float128_is_neg(xb
.f128
) && !float128_is_zero(xb
.f128
)) {
3483 float_invalid_op_vxsqrt(env
, 1, GETPC());
3484 xt
.f128
= float128_default_nan(&env
->fp_status
);
3488 helper_compute_fprf_float128(env
, xt
.f128
);
3489 putVSR(rD(opcode
) + 32, &xt
, env
);
3490 do_float_check_status(env
, GETPC());
3493 void helper_xssubqp(CPUPPCState
*env
, uint32_t opcode
)
3495 ppc_vsr_t xt
, xa
, xb
;
3498 getVSR(rA(opcode
) + 32, &xa
, env
);
3499 getVSR(rB(opcode
) + 32, &xb
, env
);
3500 getVSR(rD(opcode
) + 32, &xt
, env
);
3501 helper_reset_fpstatus(env
);
3503 tstat
= env
->fp_status
;
3504 if (unlikely(Rc(opcode
) != 0)) {
3505 tstat
.float_rounding_mode
= float_round_to_odd
;
3508 set_float_exception_flags(0, &tstat
);
3509 xt
.f128
= float128_sub(xa
.f128
, xb
.f128
, &tstat
);
3510 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3512 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
3513 float_invalid_op_addsub(env
, 1, GETPC(),
3514 float128_classify(xa
.f128
) |
3515 float128_classify(xb
.f128
));
3518 helper_compute_fprf_float128(env
, xt
.f128
);
3519 putVSR(rD(opcode
) + 32, &xt
, env
);
3520 do_float_check_status(env
, GETPC());