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
));
718 static void float_invalid_op_div(CPUPPCState
*env
, bool set_fprc
,
719 uintptr_t retaddr
, int classes
)
722 if (classes
== is_inf
) {
723 /* Division of infinity by infinity */
724 float_invalid_op_vxidi(env
, set_fprc
, retaddr
);
725 } else if (classes
== is_zero
) {
726 /* Division of zero by zero */
727 float_invalid_op_vxzdz(env
, set_fprc
, retaddr
);
728 } else if (classes
& is_snan
) {
729 float_invalid_op_vxsnan(env
, retaddr
);
734 float64
helper_fdiv(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
736 float64 ret
= float64_div(arg1
, arg2
, &env
->fp_status
);
737 int status
= get_float_exception_flags(&env
->fp_status
);
739 if (unlikely(status
)) {
740 if (status
& float_flag_invalid
) {
741 float_invalid_op_div(env
, 1, GETPC(),
742 float64_classify(arg1
) |
743 float64_classify(arg2
));
745 if (status
& float_flag_divbyzero
) {
746 float_zero_divide_excp(env
, GETPC());
753 static void float_invalid_cvt(CPUPPCState
*env
, bool set_fprc
,
754 uintptr_t retaddr
, int class1
)
756 float_invalid_op_vxcvi(env
, set_fprc
, retaddr
);
757 if (class1
& is_snan
) {
758 float_invalid_op_vxsnan(env
, retaddr
);
762 #define FPU_FCTI(op, cvt, nanval) \
763 uint64_t helper_##op(CPUPPCState *env, float64 arg) \
765 uint64_t ret = float64_to_##cvt(arg, &env->fp_status); \
766 int status = get_float_exception_flags(&env->fp_status); \
768 if (unlikely(status)) { \
769 if (status & float_flag_invalid) { \
770 float_invalid_cvt(env, 1, GETPC(), float64_classify(arg)); \
773 do_float_check_status(env, GETPC()); \
778 FPU_FCTI(fctiw
, int32
, 0x80000000U
)
779 FPU_FCTI(fctiwz
, int32_round_to_zero
, 0x80000000U
)
780 FPU_FCTI(fctiwu
, uint32
, 0x00000000U
)
781 FPU_FCTI(fctiwuz
, uint32_round_to_zero
, 0x00000000U
)
782 FPU_FCTI(fctid
, int64
, 0x8000000000000000ULL
)
783 FPU_FCTI(fctidz
, int64_round_to_zero
, 0x8000000000000000ULL
)
784 FPU_FCTI(fctidu
, uint64
, 0x0000000000000000ULL
)
785 FPU_FCTI(fctiduz
, uint64_round_to_zero
, 0x0000000000000000ULL
)
787 #define FPU_FCFI(op, cvtr, is_single) \
788 uint64_t helper_##op(CPUPPCState *env, uint64_t arg) \
793 float32 tmp = cvtr(arg, &env->fp_status); \
794 farg.d = float32_to_float64(tmp, &env->fp_status); \
796 farg.d = cvtr(arg, &env->fp_status); \
798 do_float_check_status(env, GETPC()); \
802 FPU_FCFI(fcfid
, int64_to_float64
, 0)
803 FPU_FCFI(fcfids
, int64_to_float32
, 1)
804 FPU_FCFI(fcfidu
, uint64_to_float64
, 0)
805 FPU_FCFI(fcfidus
, uint64_to_float32
, 1)
807 static inline uint64_t do_fri(CPUPPCState
*env
, uint64_t arg
,
814 if (unlikely(float64_is_signaling_nan(farg
.d
, &env
->fp_status
))) {
816 float_invalid_op_vxsnan(env
, GETPC());
817 farg
.ll
= arg
| 0x0008000000000000ULL
;
819 int inexact
= get_float_exception_flags(&env
->fp_status
) &
821 set_float_rounding_mode(rounding_mode
, &env
->fp_status
);
822 farg
.ll
= float64_round_to_int(farg
.d
, &env
->fp_status
);
823 /* Restore rounding mode from FPSCR */
824 fpscr_set_rounding_mode(env
);
826 /* fri* does not set FPSCR[XX] */
828 env
->fp_status
.float_exception_flags
&= ~float_flag_inexact
;
831 do_float_check_status(env
, GETPC());
835 uint64_t helper_frin(CPUPPCState
*env
, uint64_t arg
)
837 return do_fri(env
, arg
, float_round_ties_away
);
840 uint64_t helper_friz(CPUPPCState
*env
, uint64_t arg
)
842 return do_fri(env
, arg
, float_round_to_zero
);
845 uint64_t helper_frip(CPUPPCState
*env
, uint64_t arg
)
847 return do_fri(env
, arg
, float_round_up
);
850 uint64_t helper_frim(CPUPPCState
*env
, uint64_t arg
)
852 return do_fri(env
, arg
, float_round_down
);
855 #define FPU_MADDSUB_UPDATE(NAME, TP) \
856 static void NAME(CPUPPCState *env, TP arg1, TP arg2, TP arg3, \
857 unsigned int madd_flags, uintptr_t retaddr) \
859 if (TP##_is_signaling_nan(arg1, &env->fp_status) || \
860 TP##_is_signaling_nan(arg2, &env->fp_status) || \
861 TP##_is_signaling_nan(arg3, &env->fp_status)) { \
862 /* sNaN operation */ \
863 float_invalid_op_vxsnan(env, retaddr); \
865 if ((TP##_is_infinity(arg1) && TP##_is_zero(arg2)) || \
866 (TP##_is_zero(arg1) && TP##_is_infinity(arg2))) { \
867 /* Multiplication of zero by infinity */ \
868 float_invalid_op_vximz(env, 1, retaddr); \
870 if ((TP##_is_infinity(arg1) || TP##_is_infinity(arg2)) && \
871 TP##_is_infinity(arg3)) { \
872 uint8_t aSign, bSign, cSign; \
874 aSign = TP##_is_neg(arg1); \
875 bSign = TP##_is_neg(arg2); \
876 cSign = TP##_is_neg(arg3); \
877 if (madd_flags & float_muladd_negate_c) { \
880 if (aSign ^ bSign ^ cSign) { \
881 float_invalid_op_vxisi(env, 1, retaddr); \
885 FPU_MADDSUB_UPDATE(float32_maddsub_update_excp
, float32
)
886 FPU_MADDSUB_UPDATE(float64_maddsub_update_excp
, float64
)
888 #define FPU_FMADD(op, madd_flags) \
889 uint64_t helper_##op(CPUPPCState *env, uint64_t arg1, \
890 uint64_t arg2, uint64_t arg3) \
893 float64 ret = float64_muladd(arg1, arg2, arg3, madd_flags, \
895 flags = get_float_exception_flags(&env->fp_status); \
897 if (flags & float_flag_invalid) { \
898 float64_maddsub_update_excp(env, arg1, arg2, arg3, \
899 madd_flags, GETPC()); \
901 do_float_check_status(env, GETPC()); \
907 #define MSUB_FLGS float_muladd_negate_c
908 #define NMADD_FLGS float_muladd_negate_result
909 #define NMSUB_FLGS (float_muladd_negate_c | float_muladd_negate_result)
911 FPU_FMADD(fmadd
, MADD_FLGS
)
912 FPU_FMADD(fnmadd
, NMADD_FLGS
)
913 FPU_FMADD(fmsub
, MSUB_FLGS
)
914 FPU_FMADD(fnmsub
, NMSUB_FLGS
)
917 uint64_t helper_frsp(CPUPPCState
*env
, uint64_t arg
)
924 if (unlikely(float64_is_signaling_nan(farg
.d
, &env
->fp_status
))) {
925 float_invalid_op_vxsnan(env
, GETPC());
927 f32
= float64_to_float32(farg
.d
, &env
->fp_status
);
928 farg
.d
= float32_to_float64(f32
, &env
->fp_status
);
934 float64
helper_fsqrt(CPUPPCState
*env
, float64 arg
)
936 float64 ret
= float64_sqrt(arg
, &env
->fp_status
);
937 int status
= get_float_exception_flags(&env
->fp_status
);
939 if (unlikely(status
& float_flag_invalid
)) {
940 if (unlikely(float64_is_any_nan(arg
))) {
941 if (unlikely(float64_is_signaling_nan(arg
, &env
->fp_status
))) {
942 /* sNaN square root */
943 float_invalid_op_vxsnan(env
, GETPC());
946 /* Square root of a negative nonzero number */
947 float_invalid_op_vxsqrt(env
, 1, GETPC());
955 float64
helper_fre(CPUPPCState
*env
, float64 arg
)
957 /* "Estimate" the reciprocal with actual division. */
958 float64 ret
= float64_div(float64_one
, arg
, &env
->fp_status
);
959 int status
= get_float_exception_flags(&env
->fp_status
);
961 if (unlikely(status
)) {
962 if (status
& float_flag_invalid
) {
963 if (float64_is_signaling_nan(arg
, &env
->fp_status
)) {
964 /* sNaN reciprocal */
965 float_invalid_op_vxsnan(env
, GETPC());
968 if (status
& float_flag_divbyzero
) {
969 float_zero_divide_excp(env
, GETPC());
970 /* For FPSCR.ZE == 0, the result is 1/2. */
971 ret
= float64_set_sign(float64_half
, float64_is_neg(arg
));
979 uint64_t helper_fres(CPUPPCState
*env
, uint64_t arg
)
986 if (unlikely(float64_is_signaling_nan(farg
.d
, &env
->fp_status
))) {
987 /* sNaN reciprocal */
988 float_invalid_op_vxsnan(env
, GETPC());
990 farg
.d
= float64_div(float64_one
, farg
.d
, &env
->fp_status
);
991 f32
= float64_to_float32(farg
.d
, &env
->fp_status
);
992 farg
.d
= float32_to_float64(f32
, &env
->fp_status
);
997 /* frsqrte - frsqrte. */
998 float64
helper_frsqrte(CPUPPCState
*env
, float64 arg
)
1000 /* "Estimate" the reciprocal with actual division. */
1001 float64 rets
= float64_sqrt(arg
, &env
->fp_status
);
1002 float64 retd
= float64_div(float64_one
, rets
, &env
->fp_status
);
1003 int status
= get_float_exception_flags(&env
->fp_status
);
1005 if (unlikely(status
)) {
1006 if (status
& float_flag_invalid
) {
1007 if (float64_is_signaling_nan(arg
, &env
->fp_status
)) {
1008 /* sNaN reciprocal */
1009 float_invalid_op_vxsnan(env
, GETPC());
1011 /* Square root of a negative nonzero number */
1012 float_invalid_op_vxsqrt(env
, 1, GETPC());
1015 if (status
& float_flag_divbyzero
) {
1016 /* Reciprocal of (square root of) zero. */
1017 float_zero_divide_excp(env
, GETPC());
1025 uint64_t helper_fsel(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
1032 if ((!float64_is_neg(farg1
.d
) || float64_is_zero(farg1
.d
)) &&
1033 !float64_is_any_nan(farg1
.d
)) {
1040 uint32_t helper_ftdiv(uint64_t fra
, uint64_t frb
)
1045 if (unlikely(float64_is_infinity(fra
) ||
1046 float64_is_infinity(frb
) ||
1047 float64_is_zero(frb
))) {
1051 int e_a
= ppc_float64_get_unbiased_exp(fra
);
1052 int e_b
= ppc_float64_get_unbiased_exp(frb
);
1054 if (unlikely(float64_is_any_nan(fra
) ||
1055 float64_is_any_nan(frb
))) {
1057 } else if ((e_b
<= -1022) || (e_b
>= 1021)) {
1059 } else if (!float64_is_zero(fra
) &&
1060 (((e_a
- e_b
) >= 1023) ||
1061 ((e_a
- e_b
) <= -1021) ||
1066 if (unlikely(float64_is_zero_or_denormal(frb
))) {
1067 /* XB is not zero because of the above check and */
1068 /* so must be denormalized. */
1073 return 0x8 | (fg_flag
? 4 : 0) | (fe_flag
? 2 : 0);
1076 uint32_t helper_ftsqrt(uint64_t frb
)
1081 if (unlikely(float64_is_infinity(frb
) || float64_is_zero(frb
))) {
1085 int e_b
= ppc_float64_get_unbiased_exp(frb
);
1087 if (unlikely(float64_is_any_nan(frb
))) {
1089 } else if (unlikely(float64_is_zero(frb
))) {
1091 } else if (unlikely(float64_is_neg(frb
))) {
1093 } else if (!float64_is_zero(frb
) && (e_b
<= (-1022+52))) {
1097 if (unlikely(float64_is_zero_or_denormal(frb
))) {
1098 /* XB is not zero because of the above check and */
1099 /* therefore must be denormalized. */
1104 return 0x8 | (fg_flag
? 4 : 0) | (fe_flag
? 2 : 0);
1107 void helper_fcmpu(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
1110 CPU_DoubleU farg1
, farg2
;
1116 if (unlikely(float64_is_any_nan(farg1
.d
) ||
1117 float64_is_any_nan(farg2
.d
))) {
1119 } else if (float64_lt(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1121 } else if (!float64_le(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1127 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
1128 env
->fpscr
|= ret
<< FPSCR_FPRF
;
1129 env
->crf
[crfD
] = ret
;
1130 if (unlikely(ret
== 0x01UL
1131 && (float64_is_signaling_nan(farg1
.d
, &env
->fp_status
) ||
1132 float64_is_signaling_nan(farg2
.d
, &env
->fp_status
)))) {
1133 /* sNaN comparison */
1134 float_invalid_op_vxsnan(env
, GETPC());
1138 void helper_fcmpo(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
1141 CPU_DoubleU farg1
, farg2
;
1147 if (unlikely(float64_is_any_nan(farg1
.d
) ||
1148 float64_is_any_nan(farg2
.d
))) {
1150 } else if (float64_lt(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1152 } else if (!float64_le(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1158 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
1159 env
->fpscr
|= ret
<< FPSCR_FPRF
;
1160 env
->crf
[crfD
] = ret
;
1161 if (unlikely(ret
== 0x01UL
)) {
1162 float_invalid_op_vxvc(env
, 1, GETPC());
1163 if (float64_is_signaling_nan(farg1
.d
, &env
->fp_status
) ||
1164 float64_is_signaling_nan(farg2
.d
, &env
->fp_status
)) {
1165 /* sNaN comparison */
1166 float_invalid_op_vxsnan(env
, GETPC());
1171 /* Single-precision floating-point conversions */
1172 static inline uint32_t efscfsi(CPUPPCState
*env
, uint32_t val
)
1176 u
.f
= int32_to_float32(val
, &env
->vec_status
);
1181 static inline uint32_t efscfui(CPUPPCState
*env
, uint32_t val
)
1185 u
.f
= uint32_to_float32(val
, &env
->vec_status
);
1190 static inline int32_t efsctsi(CPUPPCState
*env
, uint32_t val
)
1195 /* NaN are not treated the same way IEEE 754 does */
1196 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1200 return float32_to_int32(u
.f
, &env
->vec_status
);
1203 static inline uint32_t efsctui(CPUPPCState
*env
, uint32_t val
)
1208 /* NaN are not treated the same way IEEE 754 does */
1209 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1213 return float32_to_uint32(u
.f
, &env
->vec_status
);
1216 static inline uint32_t efsctsiz(CPUPPCState
*env
, uint32_t val
)
1221 /* NaN are not treated the same way IEEE 754 does */
1222 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1226 return float32_to_int32_round_to_zero(u
.f
, &env
->vec_status
);
1229 static inline uint32_t efsctuiz(CPUPPCState
*env
, uint32_t val
)
1234 /* NaN are not treated the same way IEEE 754 does */
1235 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1239 return float32_to_uint32_round_to_zero(u
.f
, &env
->vec_status
);
1242 static inline uint32_t efscfsf(CPUPPCState
*env
, uint32_t val
)
1247 u
.f
= int32_to_float32(val
, &env
->vec_status
);
1248 tmp
= int64_to_float32(1ULL << 32, &env
->vec_status
);
1249 u
.f
= float32_div(u
.f
, tmp
, &env
->vec_status
);
1254 static inline uint32_t efscfuf(CPUPPCState
*env
, uint32_t val
)
1259 u
.f
= uint32_to_float32(val
, &env
->vec_status
);
1260 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1261 u
.f
= float32_div(u
.f
, tmp
, &env
->vec_status
);
1266 static inline uint32_t efsctsf(CPUPPCState
*env
, uint32_t val
)
1272 /* NaN are not treated the same way IEEE 754 does */
1273 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1276 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1277 u
.f
= float32_mul(u
.f
, tmp
, &env
->vec_status
);
1279 return float32_to_int32(u
.f
, &env
->vec_status
);
1282 static inline uint32_t efsctuf(CPUPPCState
*env
, uint32_t val
)
1288 /* NaN are not treated the same way IEEE 754 does */
1289 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1292 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1293 u
.f
= float32_mul(u
.f
, tmp
, &env
->vec_status
);
1295 return float32_to_uint32(u
.f
, &env
->vec_status
);
1298 #define HELPER_SPE_SINGLE_CONV(name) \
1299 uint32_t helper_e##name(CPUPPCState *env, uint32_t val) \
1301 return e##name(env, val); \
1304 HELPER_SPE_SINGLE_CONV(fscfsi
);
1306 HELPER_SPE_SINGLE_CONV(fscfui
);
1308 HELPER_SPE_SINGLE_CONV(fscfuf
);
1310 HELPER_SPE_SINGLE_CONV(fscfsf
);
1312 HELPER_SPE_SINGLE_CONV(fsctsi
);
1314 HELPER_SPE_SINGLE_CONV(fsctui
);
1316 HELPER_SPE_SINGLE_CONV(fsctsiz
);
1318 HELPER_SPE_SINGLE_CONV(fsctuiz
);
1320 HELPER_SPE_SINGLE_CONV(fsctsf
);
1322 HELPER_SPE_SINGLE_CONV(fsctuf
);
1324 #define HELPER_SPE_VECTOR_CONV(name) \
1325 uint64_t helper_ev##name(CPUPPCState *env, uint64_t val) \
1327 return ((uint64_t)e##name(env, val >> 32) << 32) | \
1328 (uint64_t)e##name(env, val); \
1331 HELPER_SPE_VECTOR_CONV(fscfsi
);
1333 HELPER_SPE_VECTOR_CONV(fscfui
);
1335 HELPER_SPE_VECTOR_CONV(fscfuf
);
1337 HELPER_SPE_VECTOR_CONV(fscfsf
);
1339 HELPER_SPE_VECTOR_CONV(fsctsi
);
1341 HELPER_SPE_VECTOR_CONV(fsctui
);
1343 HELPER_SPE_VECTOR_CONV(fsctsiz
);
1345 HELPER_SPE_VECTOR_CONV(fsctuiz
);
1347 HELPER_SPE_VECTOR_CONV(fsctsf
);
1349 HELPER_SPE_VECTOR_CONV(fsctuf
);
1351 /* Single-precision floating-point arithmetic */
1352 static inline uint32_t efsadd(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1358 u1
.f
= float32_add(u1
.f
, u2
.f
, &env
->vec_status
);
1362 static inline uint32_t efssub(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1368 u1
.f
= float32_sub(u1
.f
, u2
.f
, &env
->vec_status
);
1372 static inline uint32_t efsmul(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1378 u1
.f
= float32_mul(u1
.f
, u2
.f
, &env
->vec_status
);
1382 static inline uint32_t efsdiv(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1388 u1
.f
= float32_div(u1
.f
, u2
.f
, &env
->vec_status
);
1392 #define HELPER_SPE_SINGLE_ARITH(name) \
1393 uint32_t helper_e##name(CPUPPCState *env, uint32_t op1, uint32_t op2) \
1395 return e##name(env, op1, op2); \
1398 HELPER_SPE_SINGLE_ARITH(fsadd
);
1400 HELPER_SPE_SINGLE_ARITH(fssub
);
1402 HELPER_SPE_SINGLE_ARITH(fsmul
);
1404 HELPER_SPE_SINGLE_ARITH(fsdiv
);
1406 #define HELPER_SPE_VECTOR_ARITH(name) \
1407 uint64_t helper_ev##name(CPUPPCState *env, uint64_t op1, uint64_t op2) \
1409 return ((uint64_t)e##name(env, op1 >> 32, op2 >> 32) << 32) | \
1410 (uint64_t)e##name(env, op1, op2); \
1413 HELPER_SPE_VECTOR_ARITH(fsadd
);
1415 HELPER_SPE_VECTOR_ARITH(fssub
);
1417 HELPER_SPE_VECTOR_ARITH(fsmul
);
1419 HELPER_SPE_VECTOR_ARITH(fsdiv
);
1421 /* Single-precision floating-point comparisons */
1422 static inline uint32_t efscmplt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1428 return float32_lt(u1
.f
, u2
.f
, &env
->vec_status
) ? 4 : 0;
1431 static inline uint32_t efscmpgt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1437 return float32_le(u1
.f
, u2
.f
, &env
->vec_status
) ? 0 : 4;
1440 static inline uint32_t efscmpeq(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1446 return float32_eq(u1
.f
, u2
.f
, &env
->vec_status
) ? 4 : 0;
1449 static inline uint32_t efststlt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1451 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1452 return efscmplt(env
, op1
, op2
);
1455 static inline uint32_t efststgt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1457 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1458 return efscmpgt(env
, op1
, op2
);
1461 static inline uint32_t efststeq(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1463 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1464 return efscmpeq(env
, op1
, op2
);
1467 #define HELPER_SINGLE_SPE_CMP(name) \
1468 uint32_t helper_e##name(CPUPPCState *env, uint32_t op1, uint32_t op2) \
1470 return e##name(env, op1, op2); \
1473 HELPER_SINGLE_SPE_CMP(fststlt
);
1475 HELPER_SINGLE_SPE_CMP(fststgt
);
1477 HELPER_SINGLE_SPE_CMP(fststeq
);
1479 HELPER_SINGLE_SPE_CMP(fscmplt
);
1481 HELPER_SINGLE_SPE_CMP(fscmpgt
);
1483 HELPER_SINGLE_SPE_CMP(fscmpeq
);
1485 static inline uint32_t evcmp_merge(int t0
, int t1
)
1487 return (t0
<< 3) | (t1
<< 2) | ((t0
| t1
) << 1) | (t0
& t1
);
1490 #define HELPER_VECTOR_SPE_CMP(name) \
1491 uint32_t helper_ev##name(CPUPPCState *env, uint64_t op1, uint64_t op2) \
1493 return evcmp_merge(e##name(env, op1 >> 32, op2 >> 32), \
1494 e##name(env, op1, op2)); \
1497 HELPER_VECTOR_SPE_CMP(fststlt
);
1499 HELPER_VECTOR_SPE_CMP(fststgt
);
1501 HELPER_VECTOR_SPE_CMP(fststeq
);
1503 HELPER_VECTOR_SPE_CMP(fscmplt
);
1505 HELPER_VECTOR_SPE_CMP(fscmpgt
);
1507 HELPER_VECTOR_SPE_CMP(fscmpeq
);
1509 /* Double-precision floating-point conversion */
1510 uint64_t helper_efdcfsi(CPUPPCState
*env
, uint32_t val
)
1514 u
.d
= int32_to_float64(val
, &env
->vec_status
);
1519 uint64_t helper_efdcfsid(CPUPPCState
*env
, uint64_t val
)
1523 u
.d
= int64_to_float64(val
, &env
->vec_status
);
1528 uint64_t helper_efdcfui(CPUPPCState
*env
, uint32_t val
)
1532 u
.d
= uint32_to_float64(val
, &env
->vec_status
);
1537 uint64_t helper_efdcfuid(CPUPPCState
*env
, uint64_t val
)
1541 u
.d
= uint64_to_float64(val
, &env
->vec_status
);
1546 uint32_t helper_efdctsi(CPUPPCState
*env
, uint64_t val
)
1551 /* NaN are not treated the same way IEEE 754 does */
1552 if (unlikely(float64_is_any_nan(u
.d
))) {
1556 return float64_to_int32(u
.d
, &env
->vec_status
);
1559 uint32_t helper_efdctui(CPUPPCState
*env
, uint64_t val
)
1564 /* NaN are not treated the same way IEEE 754 does */
1565 if (unlikely(float64_is_any_nan(u
.d
))) {
1569 return float64_to_uint32(u
.d
, &env
->vec_status
);
1572 uint32_t helper_efdctsiz(CPUPPCState
*env
, uint64_t val
)
1577 /* NaN are not treated the same way IEEE 754 does */
1578 if (unlikely(float64_is_any_nan(u
.d
))) {
1582 return float64_to_int32_round_to_zero(u
.d
, &env
->vec_status
);
1585 uint64_t helper_efdctsidz(CPUPPCState
*env
, uint64_t val
)
1590 /* NaN are not treated the same way IEEE 754 does */
1591 if (unlikely(float64_is_any_nan(u
.d
))) {
1595 return float64_to_int64_round_to_zero(u
.d
, &env
->vec_status
);
1598 uint32_t helper_efdctuiz(CPUPPCState
*env
, uint64_t val
)
1603 /* NaN are not treated the same way IEEE 754 does */
1604 if (unlikely(float64_is_any_nan(u
.d
))) {
1608 return float64_to_uint32_round_to_zero(u
.d
, &env
->vec_status
);
1611 uint64_t helper_efdctuidz(CPUPPCState
*env
, uint64_t val
)
1616 /* NaN are not treated the same way IEEE 754 does */
1617 if (unlikely(float64_is_any_nan(u
.d
))) {
1621 return float64_to_uint64_round_to_zero(u
.d
, &env
->vec_status
);
1624 uint64_t helper_efdcfsf(CPUPPCState
*env
, uint32_t val
)
1629 u
.d
= int32_to_float64(val
, &env
->vec_status
);
1630 tmp
= int64_to_float64(1ULL << 32, &env
->vec_status
);
1631 u
.d
= float64_div(u
.d
, tmp
, &env
->vec_status
);
1636 uint64_t helper_efdcfuf(CPUPPCState
*env
, uint32_t val
)
1641 u
.d
= uint32_to_float64(val
, &env
->vec_status
);
1642 tmp
= int64_to_float64(1ULL << 32, &env
->vec_status
);
1643 u
.d
= float64_div(u
.d
, tmp
, &env
->vec_status
);
1648 uint32_t helper_efdctsf(CPUPPCState
*env
, uint64_t val
)
1654 /* NaN are not treated the same way IEEE 754 does */
1655 if (unlikely(float64_is_any_nan(u
.d
))) {
1658 tmp
= uint64_to_float64(1ULL << 32, &env
->vec_status
);
1659 u
.d
= float64_mul(u
.d
, tmp
, &env
->vec_status
);
1661 return float64_to_int32(u
.d
, &env
->vec_status
);
1664 uint32_t helper_efdctuf(CPUPPCState
*env
, uint64_t val
)
1670 /* NaN are not treated the same way IEEE 754 does */
1671 if (unlikely(float64_is_any_nan(u
.d
))) {
1674 tmp
= uint64_to_float64(1ULL << 32, &env
->vec_status
);
1675 u
.d
= float64_mul(u
.d
, tmp
, &env
->vec_status
);
1677 return float64_to_uint32(u
.d
, &env
->vec_status
);
1680 uint32_t helper_efscfd(CPUPPCState
*env
, uint64_t val
)
1686 u2
.f
= float64_to_float32(u1
.d
, &env
->vec_status
);
1691 uint64_t helper_efdcfs(CPUPPCState
*env
, uint32_t val
)
1697 u2
.d
= float32_to_float64(u1
.f
, &env
->vec_status
);
1702 /* Double precision fixed-point arithmetic */
1703 uint64_t helper_efdadd(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1709 u1
.d
= float64_add(u1
.d
, u2
.d
, &env
->vec_status
);
1713 uint64_t helper_efdsub(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1719 u1
.d
= float64_sub(u1
.d
, u2
.d
, &env
->vec_status
);
1723 uint64_t helper_efdmul(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1729 u1
.d
= float64_mul(u1
.d
, u2
.d
, &env
->vec_status
);
1733 uint64_t helper_efddiv(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1739 u1
.d
= float64_div(u1
.d
, u2
.d
, &env
->vec_status
);
1743 /* Double precision floating point helpers */
1744 uint32_t helper_efdtstlt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1750 return float64_lt(u1
.d
, u2
.d
, &env
->vec_status
) ? 4 : 0;
1753 uint32_t helper_efdtstgt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1759 return float64_le(u1
.d
, u2
.d
, &env
->vec_status
) ? 0 : 4;
1762 uint32_t helper_efdtsteq(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1768 return float64_eq_quiet(u1
.d
, u2
.d
, &env
->vec_status
) ? 4 : 0;
1771 uint32_t helper_efdcmplt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1773 /* XXX: TODO: test special values (NaN, infinites, ...) */
1774 return helper_efdtstlt(env
, op1
, op2
);
1777 uint32_t helper_efdcmpgt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1779 /* XXX: TODO: test special values (NaN, infinites, ...) */
1780 return helper_efdtstgt(env
, op1
, op2
);
1783 uint32_t helper_efdcmpeq(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1785 /* XXX: TODO: test special values (NaN, infinites, ...) */
1786 return helper_efdtsteq(env
, op1
, op2
);
1789 #define float64_to_float64(x, env) x
1792 /* VSX_ADD_SUB - VSX floating point add/subract
1793 * name - instruction mnemonic
1794 * op - operation (add or sub)
1795 * nels - number of elements (1, 2 or 4)
1796 * tp - type (float32 or float64)
1797 * fld - vsr_t field (VsrD(*) or VsrW(*))
1800 #define VSX_ADD_SUB(name, op, nels, tp, fld, sfprf, r2sp) \
1801 void helper_##name(CPUPPCState *env, uint32_t opcode) \
1803 ppc_vsr_t xt, xa, xb; \
1806 getVSR(xA(opcode), &xa, env); \
1807 getVSR(xB(opcode), &xb, env); \
1808 getVSR(xT(opcode), &xt, env); \
1809 helper_reset_fpstatus(env); \
1811 for (i = 0; i < nels; i++) { \
1812 float_status tstat = env->fp_status; \
1813 set_float_exception_flags(0, &tstat); \
1814 xt.fld = tp##_##op(xa.fld, xb.fld, &tstat); \
1815 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1817 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1818 float_invalid_op_addsub(env, sfprf, GETPC(), \
1819 tp##_classify(xa.fld) | \
1820 tp##_classify(xb.fld)); \
1824 xt.fld = helper_frsp(env, xt.fld); \
1828 helper_compute_fprf_float64(env, xt.fld); \
1831 putVSR(xT(opcode), &xt, env); \
1832 do_float_check_status(env, GETPC()); \
1835 VSX_ADD_SUB(xsadddp
, add
, 1, float64
, VsrD(0), 1, 0)
1836 VSX_ADD_SUB(xsaddsp
, add
, 1, float64
, VsrD(0), 1, 1)
1837 VSX_ADD_SUB(xvadddp
, add
, 2, float64
, VsrD(i
), 0, 0)
1838 VSX_ADD_SUB(xvaddsp
, add
, 4, float32
, VsrW(i
), 0, 0)
1839 VSX_ADD_SUB(xssubdp
, sub
, 1, float64
, VsrD(0), 1, 0)
1840 VSX_ADD_SUB(xssubsp
, sub
, 1, float64
, VsrD(0), 1, 1)
1841 VSX_ADD_SUB(xvsubdp
, sub
, 2, float64
, VsrD(i
), 0, 0)
1842 VSX_ADD_SUB(xvsubsp
, sub
, 4, float32
, VsrW(i
), 0, 0)
1844 void helper_xsaddqp(CPUPPCState
*env
, uint32_t opcode
)
1846 ppc_vsr_t xt
, xa
, xb
;
1849 getVSR(rA(opcode
) + 32, &xa
, env
);
1850 getVSR(rB(opcode
) + 32, &xb
, env
);
1851 getVSR(rD(opcode
) + 32, &xt
, env
);
1852 helper_reset_fpstatus(env
);
1854 tstat
= env
->fp_status
;
1855 if (unlikely(Rc(opcode
) != 0)) {
1856 tstat
.float_rounding_mode
= float_round_to_odd
;
1859 set_float_exception_flags(0, &tstat
);
1860 xt
.f128
= float128_add(xa
.f128
, xb
.f128
, &tstat
);
1861 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
1863 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
1864 float_invalid_op_addsub(env
, 1, GETPC(),
1865 float128_classify(xa
.f128
) |
1866 float128_classify(xb
.f128
));
1869 helper_compute_fprf_float128(env
, xt
.f128
);
1871 putVSR(rD(opcode
) + 32, &xt
, env
);
1872 do_float_check_status(env
, GETPC());
1875 /* VSX_MUL - VSX floating point multiply
1876 * op - instruction mnemonic
1877 * nels - number of elements (1, 2 or 4)
1878 * tp - type (float32 or float64)
1879 * fld - vsr_t field (VsrD(*) or VsrW(*))
1882 #define VSX_MUL(op, nels, tp, fld, sfprf, r2sp) \
1883 void helper_##op(CPUPPCState *env, uint32_t opcode) \
1885 ppc_vsr_t xt, xa, xb; \
1888 getVSR(xA(opcode), &xa, env); \
1889 getVSR(xB(opcode), &xb, env); \
1890 getVSR(xT(opcode), &xt, env); \
1891 helper_reset_fpstatus(env); \
1893 for (i = 0; i < nels; i++) { \
1894 float_status tstat = env->fp_status; \
1895 set_float_exception_flags(0, &tstat); \
1896 xt.fld = tp##_mul(xa.fld, xb.fld, &tstat); \
1897 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1899 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1900 float_invalid_op_mul(env, sfprf, GETPC(), \
1901 tp##_classify(xa.fld) | \
1902 tp##_classify(xb.fld)); \
1906 xt.fld = helper_frsp(env, xt.fld); \
1910 helper_compute_fprf_float64(env, xt.fld); \
1914 putVSR(xT(opcode), &xt, env); \
1915 do_float_check_status(env, GETPC()); \
1918 VSX_MUL(xsmuldp
, 1, float64
, VsrD(0), 1, 0)
1919 VSX_MUL(xsmulsp
, 1, float64
, VsrD(0), 1, 1)
1920 VSX_MUL(xvmuldp
, 2, float64
, VsrD(i
), 0, 0)
1921 VSX_MUL(xvmulsp
, 4, float32
, VsrW(i
), 0, 0)
1923 void helper_xsmulqp(CPUPPCState
*env
, uint32_t opcode
)
1925 ppc_vsr_t xt
, xa
, xb
;
1928 getVSR(rA(opcode
) + 32, &xa
, env
);
1929 getVSR(rB(opcode
) + 32, &xb
, env
);
1930 getVSR(rD(opcode
) + 32, &xt
, env
);
1932 helper_reset_fpstatus(env
);
1933 tstat
= env
->fp_status
;
1934 if (unlikely(Rc(opcode
) != 0)) {
1935 tstat
.float_rounding_mode
= float_round_to_odd
;
1938 set_float_exception_flags(0, &tstat
);
1939 xt
.f128
= float128_mul(xa
.f128
, xb
.f128
, &tstat
);
1940 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
1942 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
1943 float_invalid_op_mul(env
, 1, GETPC(),
1944 float128_classify(xa
.f128
) |
1945 float128_classify(xb
.f128
));
1947 helper_compute_fprf_float128(env
, xt
.f128
);
1949 putVSR(rD(opcode
) + 32, &xt
, env
);
1950 do_float_check_status(env
, GETPC());
1953 /* VSX_DIV - VSX floating point divide
1954 * op - instruction mnemonic
1955 * nels - number of elements (1, 2 or 4)
1956 * tp - type (float32 or float64)
1957 * fld - vsr_t field (VsrD(*) or VsrW(*))
1960 #define VSX_DIV(op, nels, tp, fld, sfprf, r2sp) \
1961 void helper_##op(CPUPPCState *env, uint32_t opcode) \
1963 ppc_vsr_t xt, xa, xb; \
1966 getVSR(xA(opcode), &xa, env); \
1967 getVSR(xB(opcode), &xb, env); \
1968 getVSR(xT(opcode), &xt, env); \
1969 helper_reset_fpstatus(env); \
1971 for (i = 0; i < nels; i++) { \
1972 float_status tstat = env->fp_status; \
1973 set_float_exception_flags(0, &tstat); \
1974 xt.fld = tp##_div(xa.fld, xb.fld, &tstat); \
1975 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1977 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1978 float_invalid_op_div(env, sfprf, GETPC(), \
1979 tp##_classify(xa.fld) | \
1980 tp##_classify(xb.fld)); \
1982 if (unlikely(tstat.float_exception_flags & float_flag_divbyzero)) { \
1983 float_zero_divide_excp(env, GETPC()); \
1987 xt.fld = helper_frsp(env, xt.fld); \
1991 helper_compute_fprf_float64(env, xt.fld); \
1995 putVSR(xT(opcode), &xt, env); \
1996 do_float_check_status(env, GETPC()); \
1999 VSX_DIV(xsdivdp
, 1, float64
, VsrD(0), 1, 0)
2000 VSX_DIV(xsdivsp
, 1, float64
, VsrD(0), 1, 1)
2001 VSX_DIV(xvdivdp
, 2, float64
, VsrD(i
), 0, 0)
2002 VSX_DIV(xvdivsp
, 4, float32
, VsrW(i
), 0, 0)
2004 void helper_xsdivqp(CPUPPCState
*env
, uint32_t opcode
)
2006 ppc_vsr_t xt
, xa
, xb
;
2009 getVSR(rA(opcode
) + 32, &xa
, env
);
2010 getVSR(rB(opcode
) + 32, &xb
, env
);
2011 getVSR(rD(opcode
) + 32, &xt
, env
);
2013 helper_reset_fpstatus(env
);
2014 tstat
= env
->fp_status
;
2015 if (unlikely(Rc(opcode
) != 0)) {
2016 tstat
.float_rounding_mode
= float_round_to_odd
;
2019 set_float_exception_flags(0, &tstat
);
2020 xt
.f128
= float128_div(xa
.f128
, xb
.f128
, &tstat
);
2021 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
2023 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
2024 float_invalid_op_div(env
, 1, GETPC(),
2025 float128_classify(xa
.f128
) |
2026 float128_classify(xb
.f128
));
2028 if (unlikely(tstat
.float_exception_flags
& float_flag_divbyzero
)) {
2029 float_zero_divide_excp(env
, GETPC());
2032 helper_compute_fprf_float128(env
, xt
.f128
);
2033 putVSR(rD(opcode
) + 32, &xt
, env
);
2034 do_float_check_status(env
, GETPC());
2037 /* VSX_RE - VSX floating point reciprocal estimate
2038 * op - instruction mnemonic
2039 * nels - number of elements (1, 2 or 4)
2040 * tp - type (float32 or float64)
2041 * fld - vsr_t field (VsrD(*) or VsrW(*))
2044 #define VSX_RE(op, nels, tp, fld, sfprf, r2sp) \
2045 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2050 getVSR(xB(opcode), &xb, env); \
2051 getVSR(xT(opcode), &xt, env); \
2052 helper_reset_fpstatus(env); \
2054 for (i = 0; i < nels; i++) { \
2055 if (unlikely(tp##_is_signaling_nan(xb.fld, &env->fp_status))) { \
2056 float_invalid_op_vxsnan(env, GETPC()); \
2058 xt.fld = tp##_div(tp##_one, xb.fld, &env->fp_status); \
2061 xt.fld = helper_frsp(env, xt.fld); \
2065 helper_compute_fprf_float64(env, xt.fld); \
2069 putVSR(xT(opcode), &xt, env); \
2070 do_float_check_status(env, GETPC()); \
2073 VSX_RE(xsredp
, 1, float64
, VsrD(0), 1, 0)
2074 VSX_RE(xsresp
, 1, float64
, VsrD(0), 1, 1)
2075 VSX_RE(xvredp
, 2, float64
, VsrD(i
), 0, 0)
2076 VSX_RE(xvresp
, 4, float32
, VsrW(i
), 0, 0)
2078 /* VSX_SQRT - VSX floating point square root
2079 * op - instruction mnemonic
2080 * nels - number of elements (1, 2 or 4)
2081 * tp - type (float32 or float64)
2082 * fld - vsr_t field (VsrD(*) or VsrW(*))
2085 #define VSX_SQRT(op, nels, tp, fld, sfprf, r2sp) \
2086 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2091 getVSR(xB(opcode), &xb, env); \
2092 getVSR(xT(opcode), &xt, env); \
2093 helper_reset_fpstatus(env); \
2095 for (i = 0; i < nels; i++) { \
2096 float_status tstat = env->fp_status; \
2097 set_float_exception_flags(0, &tstat); \
2098 xt.fld = tp##_sqrt(xb.fld, &tstat); \
2099 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
2101 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
2102 if (tp##_is_neg(xb.fld) && !tp##_is_zero(xb.fld)) { \
2103 float_invalid_op_vxsqrt(env, sfprf, GETPC()); \
2104 } else if (tp##_is_signaling_nan(xb.fld, &tstat)) { \
2105 float_invalid_op_vxsnan(env, GETPC()); \
2110 xt.fld = helper_frsp(env, xt.fld); \
2114 helper_compute_fprf_float64(env, xt.fld); \
2118 putVSR(xT(opcode), &xt, env); \
2119 do_float_check_status(env, GETPC()); \
2122 VSX_SQRT(xssqrtdp
, 1, float64
, VsrD(0), 1, 0)
2123 VSX_SQRT(xssqrtsp
, 1, float64
, VsrD(0), 1, 1)
2124 VSX_SQRT(xvsqrtdp
, 2, float64
, VsrD(i
), 0, 0)
2125 VSX_SQRT(xvsqrtsp
, 4, float32
, VsrW(i
), 0, 0)
2127 /* VSX_RSQRTE - VSX floating point reciprocal square root estimate
2128 * op - instruction mnemonic
2129 * nels - number of elements (1, 2 or 4)
2130 * tp - type (float32 or float64)
2131 * fld - vsr_t field (VsrD(*) or VsrW(*))
2134 #define VSX_RSQRTE(op, nels, tp, fld, sfprf, r2sp) \
2135 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2140 getVSR(xB(opcode), &xb, env); \
2141 getVSR(xT(opcode), &xt, env); \
2142 helper_reset_fpstatus(env); \
2144 for (i = 0; i < nels; i++) { \
2145 float_status tstat = env->fp_status; \
2146 set_float_exception_flags(0, &tstat); \
2147 xt.fld = tp##_sqrt(xb.fld, &tstat); \
2148 xt.fld = tp##_div(tp##_one, xt.fld, &tstat); \
2149 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
2151 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
2152 if (tp##_is_neg(xb.fld) && !tp##_is_zero(xb.fld)) { \
2153 float_invalid_op_vxsqrt(env, sfprf, GETPC()); \
2154 } else if (tp##_is_signaling_nan(xb.fld, &tstat)) { \
2155 float_invalid_op_vxsnan(env, GETPC()); \
2160 xt.fld = helper_frsp(env, xt.fld); \
2164 helper_compute_fprf_float64(env, xt.fld); \
2168 putVSR(xT(opcode), &xt, env); \
2169 do_float_check_status(env, GETPC()); \
2172 VSX_RSQRTE(xsrsqrtedp
, 1, float64
, VsrD(0), 1, 0)
2173 VSX_RSQRTE(xsrsqrtesp
, 1, float64
, VsrD(0), 1, 1)
2174 VSX_RSQRTE(xvrsqrtedp
, 2, float64
, VsrD(i
), 0, 0)
2175 VSX_RSQRTE(xvrsqrtesp
, 4, float32
, VsrW(i
), 0, 0)
2177 /* VSX_TDIV - VSX floating point test for divide
2178 * op - instruction mnemonic
2179 * nels - number of elements (1, 2 or 4)
2180 * tp - type (float32 or float64)
2181 * fld - vsr_t field (VsrD(*) or VsrW(*))
2182 * emin - minimum unbiased exponent
2183 * emax - maximum unbiased exponent
2184 * nbits - number of fraction bits
2186 #define VSX_TDIV(op, nels, tp, fld, emin, emax, nbits) \
2187 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2194 getVSR(xA(opcode), &xa, env); \
2195 getVSR(xB(opcode), &xb, env); \
2197 for (i = 0; i < nels; i++) { \
2198 if (unlikely(tp##_is_infinity(xa.fld) || \
2199 tp##_is_infinity(xb.fld) || \
2200 tp##_is_zero(xb.fld))) { \
2204 int e_a = ppc_##tp##_get_unbiased_exp(xa.fld); \
2205 int e_b = ppc_##tp##_get_unbiased_exp(xb.fld); \
2207 if (unlikely(tp##_is_any_nan(xa.fld) || \
2208 tp##_is_any_nan(xb.fld))) { \
2210 } else if ((e_b <= emin) || (e_b >= (emax-2))) { \
2212 } else if (!tp##_is_zero(xa.fld) && \
2213 (((e_a - e_b) >= emax) || \
2214 ((e_a - e_b) <= (emin+1)) || \
2215 (e_a <= (emin+nbits)))) { \
2219 if (unlikely(tp##_is_zero_or_denormal(xb.fld))) { \
2220 /* XB is not zero because of the above check and */ \
2221 /* so must be denormalized. */ \
2227 env->crf[BF(opcode)] = 0x8 | (fg_flag ? 4 : 0) | (fe_flag ? 2 : 0); \
2230 VSX_TDIV(xstdivdp
, 1, float64
, VsrD(0), -1022, 1023, 52)
2231 VSX_TDIV(xvtdivdp
, 2, float64
, VsrD(i
), -1022, 1023, 52)
2232 VSX_TDIV(xvtdivsp
, 4, float32
, VsrW(i
), -126, 127, 23)
2234 /* VSX_TSQRT - VSX floating point test for square root
2235 * op - instruction mnemonic
2236 * nels - number of elements (1, 2 or 4)
2237 * tp - type (float32 or float64)
2238 * fld - vsr_t field (VsrD(*) or VsrW(*))
2239 * emin - minimum unbiased exponent
2240 * emax - maximum unbiased exponent
2241 * nbits - number of fraction bits
2243 #define VSX_TSQRT(op, nels, tp, fld, emin, nbits) \
2244 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2251 getVSR(xA(opcode), &xa, env); \
2252 getVSR(xB(opcode), &xb, env); \
2254 for (i = 0; i < nels; i++) { \
2255 if (unlikely(tp##_is_infinity(xb.fld) || \
2256 tp##_is_zero(xb.fld))) { \
2260 int e_b = ppc_##tp##_get_unbiased_exp(xb.fld); \
2262 if (unlikely(tp##_is_any_nan(xb.fld))) { \
2264 } else if (unlikely(tp##_is_zero(xb.fld))) { \
2266 } else if (unlikely(tp##_is_neg(xb.fld))) { \
2268 } else if (!tp##_is_zero(xb.fld) && \
2269 (e_b <= (emin+nbits))) { \
2273 if (unlikely(tp##_is_zero_or_denormal(xb.fld))) { \
2274 /* XB is not zero because of the above check and */ \
2275 /* therefore must be denormalized. */ \
2281 env->crf[BF(opcode)] = 0x8 | (fg_flag ? 4 : 0) | (fe_flag ? 2 : 0); \
2284 VSX_TSQRT(xstsqrtdp
, 1, float64
, VsrD(0), -1022, 52)
2285 VSX_TSQRT(xvtsqrtdp
, 2, float64
, VsrD(i
), -1022, 52)
2286 VSX_TSQRT(xvtsqrtsp
, 4, float32
, VsrW(i
), -126, 23)
2288 /* VSX_MADD - VSX floating point muliply/add variations
2289 * op - instruction mnemonic
2290 * nels - number of elements (1, 2 or 4)
2291 * tp - type (float32 or float64)
2292 * fld - vsr_t field (VsrD(*) or VsrW(*))
2293 * maddflgs - flags for the float*muladd routine that control the
2294 * various forms (madd, msub, nmadd, nmsub)
2295 * afrm - A form (1=A, 0=M)
2298 #define VSX_MADD(op, nels, tp, fld, maddflgs, afrm, sfprf, r2sp) \
2299 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2301 ppc_vsr_t xt_in, xa, xb, xt_out; \
2305 if (afrm) { /* AxB + T */ \
2308 } else { /* AxT + B */ \
2313 getVSR(xA(opcode), &xa, env); \
2314 getVSR(xB(opcode), &xb, env); \
2315 getVSR(xT(opcode), &xt_in, env); \
2319 helper_reset_fpstatus(env); \
2321 for (i = 0; i < nels; i++) { \
2322 float_status tstat = env->fp_status; \
2323 set_float_exception_flags(0, &tstat); \
2324 if (r2sp && (tstat.float_rounding_mode == float_round_nearest_even)) {\
2325 /* Avoid double rounding errors by rounding the intermediate */ \
2326 /* result to odd. */ \
2327 set_float_rounding_mode(float_round_to_zero, &tstat); \
2328 xt_out.fld = tp##_muladd(xa.fld, b->fld, c->fld, \
2329 maddflgs, &tstat); \
2330 xt_out.fld |= (get_float_exception_flags(&tstat) & \
2331 float_flag_inexact) != 0; \
2333 xt_out.fld = tp##_muladd(xa.fld, b->fld, c->fld, \
2334 maddflgs, &tstat); \
2336 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
2338 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
2339 tp##_maddsub_update_excp(env, xa.fld, b->fld, \
2340 c->fld, maddflgs, GETPC()); \
2344 xt_out.fld = helper_frsp(env, xt_out.fld); \
2348 helper_compute_fprf_float64(env, xt_out.fld); \
2351 putVSR(xT(opcode), &xt_out, env); \
2352 do_float_check_status(env, GETPC()); \
2355 VSX_MADD(xsmaddadp
, 1, float64
, VsrD(0), MADD_FLGS
, 1, 1, 0)
2356 VSX_MADD(xsmaddmdp
, 1, float64
, VsrD(0), MADD_FLGS
, 0, 1, 0)
2357 VSX_MADD(xsmsubadp
, 1, float64
, VsrD(0), MSUB_FLGS
, 1, 1, 0)
2358 VSX_MADD(xsmsubmdp
, 1, float64
, VsrD(0), MSUB_FLGS
, 0, 1, 0)
2359 VSX_MADD(xsnmaddadp
, 1, float64
, VsrD(0), NMADD_FLGS
, 1, 1, 0)
2360 VSX_MADD(xsnmaddmdp
, 1, float64
, VsrD(0), NMADD_FLGS
, 0, 1, 0)
2361 VSX_MADD(xsnmsubadp
, 1, float64
, VsrD(0), NMSUB_FLGS
, 1, 1, 0)
2362 VSX_MADD(xsnmsubmdp
, 1, float64
, VsrD(0), NMSUB_FLGS
, 0, 1, 0)
2364 VSX_MADD(xsmaddasp
, 1, float64
, VsrD(0), MADD_FLGS
, 1, 1, 1)
2365 VSX_MADD(xsmaddmsp
, 1, float64
, VsrD(0), MADD_FLGS
, 0, 1, 1)
2366 VSX_MADD(xsmsubasp
, 1, float64
, VsrD(0), MSUB_FLGS
, 1, 1, 1)
2367 VSX_MADD(xsmsubmsp
, 1, float64
, VsrD(0), MSUB_FLGS
, 0, 1, 1)
2368 VSX_MADD(xsnmaddasp
, 1, float64
, VsrD(0), NMADD_FLGS
, 1, 1, 1)
2369 VSX_MADD(xsnmaddmsp
, 1, float64
, VsrD(0), NMADD_FLGS
, 0, 1, 1)
2370 VSX_MADD(xsnmsubasp
, 1, float64
, VsrD(0), NMSUB_FLGS
, 1, 1, 1)
2371 VSX_MADD(xsnmsubmsp
, 1, float64
, VsrD(0), NMSUB_FLGS
, 0, 1, 1)
2373 VSX_MADD(xvmaddadp
, 2, float64
, VsrD(i
), MADD_FLGS
, 1, 0, 0)
2374 VSX_MADD(xvmaddmdp
, 2, float64
, VsrD(i
), MADD_FLGS
, 0, 0, 0)
2375 VSX_MADD(xvmsubadp
, 2, float64
, VsrD(i
), MSUB_FLGS
, 1, 0, 0)
2376 VSX_MADD(xvmsubmdp
, 2, float64
, VsrD(i
), MSUB_FLGS
, 0, 0, 0)
2377 VSX_MADD(xvnmaddadp
, 2, float64
, VsrD(i
), NMADD_FLGS
, 1, 0, 0)
2378 VSX_MADD(xvnmaddmdp
, 2, float64
, VsrD(i
), NMADD_FLGS
, 0, 0, 0)
2379 VSX_MADD(xvnmsubadp
, 2, float64
, VsrD(i
), NMSUB_FLGS
, 1, 0, 0)
2380 VSX_MADD(xvnmsubmdp
, 2, float64
, VsrD(i
), NMSUB_FLGS
, 0, 0, 0)
2382 VSX_MADD(xvmaddasp
, 4, float32
, VsrW(i
), MADD_FLGS
, 1, 0, 0)
2383 VSX_MADD(xvmaddmsp
, 4, float32
, VsrW(i
), MADD_FLGS
, 0, 0, 0)
2384 VSX_MADD(xvmsubasp
, 4, float32
, VsrW(i
), MSUB_FLGS
, 1, 0, 0)
2385 VSX_MADD(xvmsubmsp
, 4, float32
, VsrW(i
), MSUB_FLGS
, 0, 0, 0)
2386 VSX_MADD(xvnmaddasp
, 4, float32
, VsrW(i
), NMADD_FLGS
, 1, 0, 0)
2387 VSX_MADD(xvnmaddmsp
, 4, float32
, VsrW(i
), NMADD_FLGS
, 0, 0, 0)
2388 VSX_MADD(xvnmsubasp
, 4, float32
, VsrW(i
), NMSUB_FLGS
, 1, 0, 0)
2389 VSX_MADD(xvnmsubmsp
, 4, float32
, VsrW(i
), NMSUB_FLGS
, 0, 0, 0)
2391 /* VSX_SCALAR_CMP_DP - VSX scalar floating point compare double precision
2392 * op - instruction mnemonic
2393 * cmp - comparison operation
2394 * exp - expected result of comparison
2395 * svxvc - set VXVC bit
2397 #define VSX_SCALAR_CMP_DP(op, cmp, exp, svxvc) \
2398 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2400 ppc_vsr_t xt, xa, xb; \
2401 bool vxsnan_flag = false, vxvc_flag = false, vex_flag = false; \
2403 getVSR(xA(opcode), &xa, env); \
2404 getVSR(xB(opcode), &xb, env); \
2405 getVSR(xT(opcode), &xt, env); \
2407 if (float64_is_signaling_nan(xa.VsrD(0), &env->fp_status) || \
2408 float64_is_signaling_nan(xb.VsrD(0), &env->fp_status)) { \
2409 vxsnan_flag = true; \
2410 if (fpscr_ve == 0 && svxvc) { \
2413 } else if (svxvc) { \
2414 vxvc_flag = float64_is_quiet_nan(xa.VsrD(0), &env->fp_status) || \
2415 float64_is_quiet_nan(xb.VsrD(0), &env->fp_status); \
2417 if (vxsnan_flag) { \
2418 float_invalid_op_vxsnan(env, GETPC()); \
2421 float_invalid_op_vxvc(env, 0, GETPC()); \
2423 vex_flag = fpscr_ve && (vxvc_flag || vxsnan_flag); \
2426 if (float64_##cmp(xb.VsrD(0), xa.VsrD(0), &env->fp_status) == exp) { \
2434 putVSR(xT(opcode), &xt, env); \
2435 do_float_check_status(env, GETPC()); \
2438 VSX_SCALAR_CMP_DP(xscmpeqdp
, eq
, 1, 0)
2439 VSX_SCALAR_CMP_DP(xscmpgedp
, le
, 1, 1)
2440 VSX_SCALAR_CMP_DP(xscmpgtdp
, lt
, 1, 1)
2441 VSX_SCALAR_CMP_DP(xscmpnedp
, eq
, 0, 0)
2443 void helper_xscmpexpdp(CPUPPCState
*env
, uint32_t opcode
)
2446 int64_t exp_a
, exp_b
;
2449 getVSR(xA(opcode
), &xa
, env
);
2450 getVSR(xB(opcode
), &xb
, env
);
2452 exp_a
= extract64(xa
.VsrD(0), 52, 11);
2453 exp_b
= extract64(xb
.VsrD(0), 52, 11);
2455 if (unlikely(float64_is_any_nan(xa
.VsrD(0)) ||
2456 float64_is_any_nan(xb
.VsrD(0)))) {
2459 if (exp_a
< exp_b
) {
2461 } else if (exp_a
> exp_b
) {
2468 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
2469 env
->fpscr
|= cc
<< FPSCR_FPRF
;
2470 env
->crf
[BF(opcode
)] = cc
;
2472 do_float_check_status(env
, GETPC());
2475 void helper_xscmpexpqp(CPUPPCState
*env
, uint32_t opcode
)
2478 int64_t exp_a
, exp_b
;
2481 getVSR(rA(opcode
) + 32, &xa
, env
);
2482 getVSR(rB(opcode
) + 32, &xb
, env
);
2484 exp_a
= extract64(xa
.VsrD(0), 48, 15);
2485 exp_b
= extract64(xb
.VsrD(0), 48, 15);
2487 if (unlikely(float128_is_any_nan(xa
.f128
) ||
2488 float128_is_any_nan(xb
.f128
))) {
2491 if (exp_a
< exp_b
) {
2493 } else if (exp_a
> exp_b
) {
2500 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
2501 env
->fpscr
|= cc
<< FPSCR_FPRF
;
2502 env
->crf
[BF(opcode
)] = cc
;
2504 do_float_check_status(env
, GETPC());
2507 #define VSX_SCALAR_CMP(op, ordered) \
2508 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2512 bool vxsnan_flag = false, vxvc_flag = false; \
2514 helper_reset_fpstatus(env); \
2515 getVSR(xA(opcode), &xa, env); \
2516 getVSR(xB(opcode), &xb, env); \
2518 if (float64_is_signaling_nan(xa.VsrD(0), &env->fp_status) || \
2519 float64_is_signaling_nan(xb.VsrD(0), &env->fp_status)) { \
2520 vxsnan_flag = true; \
2522 if (fpscr_ve == 0 && ordered) { \
2525 } else if (float64_is_quiet_nan(xa.VsrD(0), &env->fp_status) || \
2526 float64_is_quiet_nan(xb.VsrD(0), &env->fp_status)) { \
2532 if (vxsnan_flag) { \
2533 float_invalid_op_vxsnan(env, GETPC()); \
2536 float_invalid_op_vxvc(env, 0, GETPC()); \
2539 if (float64_lt(xa.VsrD(0), xb.VsrD(0), &env->fp_status)) { \
2541 } else if (!float64_le(xa.VsrD(0), xb.VsrD(0), &env->fp_status)) { \
2547 env->fpscr &= ~(0x0F << FPSCR_FPRF); \
2548 env->fpscr |= cc << FPSCR_FPRF; \
2549 env->crf[BF(opcode)] = cc; \
2551 do_float_check_status(env, GETPC()); \
2554 VSX_SCALAR_CMP(xscmpodp
, 1)
2555 VSX_SCALAR_CMP(xscmpudp
, 0)
2557 #define VSX_SCALAR_CMPQ(op, ordered) \
2558 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2562 bool vxsnan_flag = false, vxvc_flag = false; \
2564 helper_reset_fpstatus(env); \
2565 getVSR(rA(opcode) + 32, &xa, env); \
2566 getVSR(rB(opcode) + 32, &xb, env); \
2568 if (float128_is_signaling_nan(xa.f128, &env->fp_status) || \
2569 float128_is_signaling_nan(xb.f128, &env->fp_status)) { \
2570 vxsnan_flag = true; \
2572 if (fpscr_ve == 0 && ordered) { \
2575 } else if (float128_is_quiet_nan(xa.f128, &env->fp_status) || \
2576 float128_is_quiet_nan(xb.f128, &env->fp_status)) { \
2582 if (vxsnan_flag) { \
2583 float_invalid_op_vxsnan(env, GETPC()); \
2586 float_invalid_op_vxvc(env, 0, GETPC()); \
2589 if (float128_lt(xa.f128, xb.f128, &env->fp_status)) { \
2591 } else if (!float128_le(xa.f128, xb.f128, &env->fp_status)) { \
2597 env->fpscr &= ~(0x0F << FPSCR_FPRF); \
2598 env->fpscr |= cc << FPSCR_FPRF; \
2599 env->crf[BF(opcode)] = cc; \
2601 do_float_check_status(env, GETPC()); \
2604 VSX_SCALAR_CMPQ(xscmpoqp
, 1)
2605 VSX_SCALAR_CMPQ(xscmpuqp
, 0)
2607 /* VSX_MAX_MIN - VSX floating point maximum/minimum
2608 * name - instruction mnemonic
2609 * op - operation (max or min)
2610 * nels - number of elements (1, 2 or 4)
2611 * tp - type (float32 or float64)
2612 * fld - vsr_t field (VsrD(*) or VsrW(*))
2614 #define VSX_MAX_MIN(name, op, nels, tp, fld) \
2615 void helper_##name(CPUPPCState *env, uint32_t opcode) \
2617 ppc_vsr_t xt, xa, xb; \
2620 getVSR(xA(opcode), &xa, env); \
2621 getVSR(xB(opcode), &xb, env); \
2622 getVSR(xT(opcode), &xt, env); \
2624 for (i = 0; i < nels; i++) { \
2625 xt.fld = tp##_##op(xa.fld, xb.fld, &env->fp_status); \
2626 if (unlikely(tp##_is_signaling_nan(xa.fld, &env->fp_status) || \
2627 tp##_is_signaling_nan(xb.fld, &env->fp_status))) { \
2628 float_invalid_op_vxsnan(env, GETPC()); \
2632 putVSR(xT(opcode), &xt, env); \
2633 do_float_check_status(env, GETPC()); \
2636 VSX_MAX_MIN(xsmaxdp
, maxnum
, 1, float64
, VsrD(0))
2637 VSX_MAX_MIN(xvmaxdp
, maxnum
, 2, float64
, VsrD(i
))
2638 VSX_MAX_MIN(xvmaxsp
, maxnum
, 4, float32
, VsrW(i
))
2639 VSX_MAX_MIN(xsmindp
, minnum
, 1, float64
, VsrD(0))
2640 VSX_MAX_MIN(xvmindp
, minnum
, 2, float64
, VsrD(i
))
2641 VSX_MAX_MIN(xvminsp
, minnum
, 4, float32
, VsrW(i
))
2643 #define VSX_MAX_MINC(name, max) \
2644 void helper_##name(CPUPPCState *env, uint32_t opcode) \
2646 ppc_vsr_t xt, xa, xb; \
2647 bool vxsnan_flag = false, vex_flag = false; \
2649 getVSR(rA(opcode) + 32, &xa, env); \
2650 getVSR(rB(opcode) + 32, &xb, env); \
2651 getVSR(rD(opcode) + 32, &xt, env); \
2653 if (unlikely(float64_is_any_nan(xa.VsrD(0)) || \
2654 float64_is_any_nan(xb.VsrD(0)))) { \
2655 if (float64_is_signaling_nan(xa.VsrD(0), &env->fp_status) || \
2656 float64_is_signaling_nan(xb.VsrD(0), &env->fp_status)) { \
2657 vxsnan_flag = true; \
2659 xt.VsrD(0) = xb.VsrD(0); \
2660 } else if ((max && \
2661 !float64_lt(xa.VsrD(0), xb.VsrD(0), &env->fp_status)) || \
2663 float64_lt(xa.VsrD(0), xb.VsrD(0), &env->fp_status))) { \
2664 xt.VsrD(0) = xa.VsrD(0); \
2666 xt.VsrD(0) = xb.VsrD(0); \
2669 vex_flag = fpscr_ve & vxsnan_flag; \
2670 if (vxsnan_flag) { \
2671 float_invalid_op_vxsnan(env, GETPC()); \
2674 putVSR(rD(opcode) + 32, &xt, env); \
2678 VSX_MAX_MINC(xsmaxcdp, 1);
2679 VSX_MAX_MINC(xsmincdp
, 0);
2681 #define VSX_MAX_MINJ(name, max) \
2682 void helper_##name(CPUPPCState *env, uint32_t opcode) \
2684 ppc_vsr_t xt, xa, xb; \
2685 bool vxsnan_flag = false, vex_flag = false; \
2687 getVSR(rA(opcode) + 32, &xa, env); \
2688 getVSR(rB(opcode) + 32, &xb, env); \
2689 getVSR(rD(opcode) + 32, &xt, env); \
2691 if (unlikely(float64_is_any_nan(xa.VsrD(0)))) { \
2692 if (float64_is_signaling_nan(xa.VsrD(0), &env->fp_status)) { \
2693 vxsnan_flag = true; \
2695 xt.VsrD(0) = xa.VsrD(0); \
2696 } else if (unlikely(float64_is_any_nan(xb.VsrD(0)))) { \
2697 if (float64_is_signaling_nan(xb.VsrD(0), &env->fp_status)) { \
2698 vxsnan_flag = true; \
2700 xt.VsrD(0) = xb.VsrD(0); \
2701 } else if (float64_is_zero(xa.VsrD(0)) && float64_is_zero(xb.VsrD(0))) { \
2703 if (!float64_is_neg(xa.VsrD(0)) || !float64_is_neg(xb.VsrD(0))) { \
2704 xt.VsrD(0) = 0ULL; \
2706 xt.VsrD(0) = 0x8000000000000000ULL; \
2709 if (float64_is_neg(xa.VsrD(0)) || float64_is_neg(xb.VsrD(0))) { \
2710 xt.VsrD(0) = 0x8000000000000000ULL; \
2712 xt.VsrD(0) = 0ULL; \
2715 } else if ((max && \
2716 !float64_lt(xa.VsrD(0), xb.VsrD(0), &env->fp_status)) || \
2718 float64_lt(xa.VsrD(0), xb.VsrD(0), &env->fp_status))) { \
2719 xt.VsrD(0) = xa.VsrD(0); \
2721 xt.VsrD(0) = xb.VsrD(0); \
2724 vex_flag = fpscr_ve & vxsnan_flag; \
2725 if (vxsnan_flag) { \
2726 float_invalid_op_vxsnan(env, GETPC()); \
2729 putVSR(rD(opcode) + 32, &xt, env); \
2733 VSX_MAX_MINJ(xsmaxjdp, 1);
2734 VSX_MAX_MINJ(xsminjdp
, 0);
2736 /* VSX_CMP - VSX floating point compare
2737 * op - instruction mnemonic
2738 * nels - number of elements (1, 2 or 4)
2739 * tp - type (float32 or float64)
2740 * fld - vsr_t field (VsrD(*) or VsrW(*))
2741 * cmp - comparison operation
2742 * svxvc - set VXVC bit
2743 * exp - expected result of comparison
2745 #define VSX_CMP(op, nels, tp, fld, cmp, svxvc, exp) \
2746 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2748 ppc_vsr_t xt, xa, xb; \
2751 int all_false = 1; \
2753 getVSR(xA(opcode), &xa, env); \
2754 getVSR(xB(opcode), &xb, env); \
2755 getVSR(xT(opcode), &xt, env); \
2757 for (i = 0; i < nels; i++) { \
2758 if (unlikely(tp##_is_any_nan(xa.fld) || \
2759 tp##_is_any_nan(xb.fld))) { \
2760 if (tp##_is_signaling_nan(xa.fld, &env->fp_status) || \
2761 tp##_is_signaling_nan(xb.fld, &env->fp_status)) { \
2762 float_invalid_op_vxsnan(env, GETPC()); \
2765 float_invalid_op_vxvc(env, 0, GETPC()); \
2770 if (tp##_##cmp(xb.fld, xa.fld, &env->fp_status) == exp) { \
2780 putVSR(xT(opcode), &xt, env); \
2781 if ((opcode >> (31-21)) & 1) { \
2782 env->crf[6] = (all_true ? 0x8 : 0) | (all_false ? 0x2 : 0); \
2784 do_float_check_status(env, GETPC()); \
2787 VSX_CMP(xvcmpeqdp
, 2, float64
, VsrD(i
), eq
, 0, 1)
2788 VSX_CMP(xvcmpgedp
, 2, float64
, VsrD(i
), le
, 1, 1)
2789 VSX_CMP(xvcmpgtdp
, 2, float64
, VsrD(i
), lt
, 1, 1)
2790 VSX_CMP(xvcmpnedp
, 2, float64
, VsrD(i
), eq
, 0, 0)
2791 VSX_CMP(xvcmpeqsp
, 4, float32
, VsrW(i
), eq
, 0, 1)
2792 VSX_CMP(xvcmpgesp
, 4, float32
, VsrW(i
), le
, 1, 1)
2793 VSX_CMP(xvcmpgtsp
, 4, float32
, VsrW(i
), lt
, 1, 1)
2794 VSX_CMP(xvcmpnesp
, 4, float32
, VsrW(i
), eq
, 0, 0)
2796 /* VSX_CVT_FP_TO_FP - VSX floating point/floating point conversion
2797 * op - instruction mnemonic
2798 * nels - number of elements (1, 2 or 4)
2799 * stp - source type (float32 or float64)
2800 * ttp - target type (float32 or float64)
2801 * sfld - source vsr_t field
2802 * tfld - target vsr_t field (f32 or f64)
2805 #define VSX_CVT_FP_TO_FP(op, nels, stp, ttp, sfld, tfld, sfprf) \
2806 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2811 getVSR(xB(opcode), &xb, env); \
2812 getVSR(xT(opcode), &xt, env); \
2814 for (i = 0; i < nels; i++) { \
2815 xt.tfld = stp##_to_##ttp(xb.sfld, &env->fp_status); \
2816 if (unlikely(stp##_is_signaling_nan(xb.sfld, \
2817 &env->fp_status))) { \
2818 float_invalid_op_vxsnan(env, GETPC()); \
2819 xt.tfld = ttp##_snan_to_qnan(xt.tfld); \
2822 helper_compute_fprf_##ttp(env, xt.tfld); \
2826 putVSR(xT(opcode), &xt, env); \
2827 do_float_check_status(env, GETPC()); \
2830 VSX_CVT_FP_TO_FP(xscvdpsp
, 1, float64
, float32
, VsrD(0), VsrW(0), 1)
2831 VSX_CVT_FP_TO_FP(xscvspdp
, 1, float32
, float64
, VsrW(0), VsrD(0), 1)
2832 VSX_CVT_FP_TO_FP(xvcvdpsp
, 2, float64
, float32
, VsrD(i
), VsrW(2*i
), 0)
2833 VSX_CVT_FP_TO_FP(xvcvspdp
, 2, float32
, float64
, VsrW(2*i
), VsrD(i
), 0)
2835 /* VSX_CVT_FP_TO_FP_VECTOR - VSX floating point/floating point conversion
2836 * op - instruction mnemonic
2837 * nels - number of elements (1, 2 or 4)
2838 * stp - source type (float32 or float64)
2839 * ttp - target type (float32 or float64)
2840 * sfld - source vsr_t field
2841 * tfld - target vsr_t field (f32 or f64)
2844 #define VSX_CVT_FP_TO_FP_VECTOR(op, nels, stp, ttp, sfld, tfld, sfprf) \
2845 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2850 getVSR(rB(opcode) + 32, &xb, env); \
2851 getVSR(rD(opcode) + 32, &xt, env); \
2853 for (i = 0; i < nels; i++) { \
2854 xt.tfld = stp##_to_##ttp(xb.sfld, &env->fp_status); \
2855 if (unlikely(stp##_is_signaling_nan(xb.sfld, \
2856 &env->fp_status))) { \
2857 float_invalid_op_vxsnan(env, GETPC()); \
2858 xt.tfld = ttp##_snan_to_qnan(xt.tfld); \
2861 helper_compute_fprf_##ttp(env, xt.tfld); \
2865 putVSR(rD(opcode) + 32, &xt, env); \
2866 do_float_check_status(env, GETPC()); \
2869 VSX_CVT_FP_TO_FP_VECTOR(xscvdpqp
, 1, float64
, float128
, VsrD(0), f128
, 1)
2871 /* VSX_CVT_FP_TO_FP_HP - VSX floating point/floating point conversion
2872 * involving one half precision value
2873 * op - instruction mnemonic
2874 * nels - number of elements (1, 2 or 4)
2877 * sfld - source vsr_t field
2878 * tfld - target vsr_t field
2881 #define VSX_CVT_FP_TO_FP_HP(op, nels, stp, ttp, sfld, tfld, sfprf) \
2882 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2887 getVSR(xB(opcode), &xb, env); \
2888 memset(&xt, 0, sizeof(xt)); \
2890 for (i = 0; i < nels; i++) { \
2891 xt.tfld = stp##_to_##ttp(xb.sfld, 1, &env->fp_status); \
2892 if (unlikely(stp##_is_signaling_nan(xb.sfld, \
2893 &env->fp_status))) { \
2894 float_invalid_op_vxsnan(env, GETPC()); \
2895 xt.tfld = ttp##_snan_to_qnan(xt.tfld); \
2898 helper_compute_fprf_##ttp(env, xt.tfld); \
2902 putVSR(xT(opcode), &xt, env); \
2903 do_float_check_status(env, GETPC()); \
2906 VSX_CVT_FP_TO_FP_HP(xscvdphp
, 1, float64
, float16
, VsrD(0), VsrH(3), 1)
2907 VSX_CVT_FP_TO_FP_HP(xscvhpdp
, 1, float16
, float64
, VsrH(3), VsrD(0), 1)
2908 VSX_CVT_FP_TO_FP_HP(xvcvsphp
, 4, float32
, float16
, VsrW(i
), VsrH(2 * i
+ 1), 0)
2909 VSX_CVT_FP_TO_FP_HP(xvcvhpsp
, 4, float16
, float32
, VsrH(2 * i
+ 1), VsrW(i
), 0)
2912 * xscvqpdp isn't using VSX_CVT_FP_TO_FP() because xscvqpdpo will be
2913 * added to this later.
2915 void helper_xscvqpdp(CPUPPCState
*env
, uint32_t opcode
)
2920 getVSR(rB(opcode
) + 32, &xb
, env
);
2921 memset(&xt
, 0, sizeof(xt
));
2923 tstat
= env
->fp_status
;
2924 if (unlikely(Rc(opcode
) != 0)) {
2925 tstat
.float_rounding_mode
= float_round_to_odd
;
2928 xt
.VsrD(0) = float128_to_float64(xb
.f128
, &tstat
);
2929 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
2930 if (unlikely(float128_is_signaling_nan(xb
.f128
, &tstat
))) {
2931 float_invalid_op_vxsnan(env
, GETPC());
2932 xt
.VsrD(0) = float64_snan_to_qnan(xt
.VsrD(0));
2934 helper_compute_fprf_float64(env
, xt
.VsrD(0));
2936 putVSR(rD(opcode
) + 32, &xt
, env
);
2937 do_float_check_status(env
, GETPC());
2940 uint64_t helper_xscvdpspn(CPUPPCState
*env
, uint64_t xb
)
2942 float_status tstat
= env
->fp_status
;
2943 set_float_exception_flags(0, &tstat
);
2945 return (uint64_t)float64_to_float32(xb
, &tstat
) << 32;
2948 uint64_t helper_xscvspdpn(CPUPPCState
*env
, uint64_t xb
)
2950 float_status tstat
= env
->fp_status
;
2951 set_float_exception_flags(0, &tstat
);
2953 return float32_to_float64(xb
>> 32, &tstat
);
2956 /* VSX_CVT_FP_TO_INT - VSX floating point to integer conversion
2957 * op - instruction mnemonic
2958 * nels - number of elements (1, 2 or 4)
2959 * stp - source type (float32 or float64)
2960 * ttp - target type (int32, uint32, int64 or uint64)
2961 * sfld - source vsr_t field
2962 * tfld - target vsr_t field
2963 * rnan - resulting NaN
2965 #define VSX_CVT_FP_TO_INT(op, nels, stp, ttp, sfld, tfld, rnan) \
2966 void helper_##op(CPUPPCState *env, uint32_t opcode) \
2968 int all_flags = env->fp_status.float_exception_flags, flags; \
2972 getVSR(xB(opcode), &xb, env); \
2973 getVSR(xT(opcode), &xt, env); \
2975 for (i = 0; i < nels; i++) { \
2976 env->fp_status.float_exception_flags = 0; \
2977 xt.tfld = stp##_to_##ttp##_round_to_zero(xb.sfld, &env->fp_status); \
2978 flags = env->fp_status.float_exception_flags; \
2979 if (unlikely(flags & float_flag_invalid)) { \
2980 float_invalid_cvt(env, 0, GETPC(), stp##_classify(xb.sfld)); \
2983 all_flags |= flags; \
2986 putVSR(xT(opcode), &xt, env); \
2987 env->fp_status.float_exception_flags = all_flags; \
2988 do_float_check_status(env, GETPC()); \
2991 VSX_CVT_FP_TO_INT(xscvdpsxds
, 1, float64
, int64
, VsrD(0), VsrD(0), \
2992 0x8000000000000000ULL
)
2993 VSX_CVT_FP_TO_INT(xscvdpsxws
, 1, float64
, int32
, VsrD(0), VsrW(1), \
2995 VSX_CVT_FP_TO_INT(xscvdpuxds
, 1, float64
, uint64
, VsrD(0), VsrD(0), 0ULL)
2996 VSX_CVT_FP_TO_INT(xscvdpuxws
, 1, float64
, uint32
, VsrD(0), VsrW(1), 0U)
2997 VSX_CVT_FP_TO_INT(xvcvdpsxds
, 2, float64
, int64
, VsrD(i
), VsrD(i
), \
2998 0x8000000000000000ULL
)
2999 VSX_CVT_FP_TO_INT(xvcvdpsxws
, 2, float64
, int32
, VsrD(i
), VsrW(2*i
), \
3001 VSX_CVT_FP_TO_INT(xvcvdpuxds
, 2, float64
, uint64
, VsrD(i
), VsrD(i
), 0ULL)
3002 VSX_CVT_FP_TO_INT(xvcvdpuxws
, 2, float64
, uint32
, VsrD(i
), VsrW(2*i
), 0U)
3003 VSX_CVT_FP_TO_INT(xvcvspsxds
, 2, float32
, int64
, VsrW(2*i
), VsrD(i
), \
3004 0x8000000000000000ULL
)
3005 VSX_CVT_FP_TO_INT(xvcvspsxws
, 4, float32
, int32
, VsrW(i
), VsrW(i
), 0x80000000U
)
3006 VSX_CVT_FP_TO_INT(xvcvspuxds
, 2, float32
, uint64
, VsrW(2*i
), VsrD(i
), 0ULL)
3007 VSX_CVT_FP_TO_INT(xvcvspuxws
, 4, float32
, uint32
, VsrW(i
), VsrW(i
), 0U)
3009 /* VSX_CVT_FP_TO_INT_VECTOR - VSX floating point to integer conversion
3010 * op - instruction mnemonic
3011 * stp - source type (float32 or float64)
3012 * ttp - target type (int32, uint32, int64 or uint64)
3013 * sfld - source vsr_t field
3014 * tfld - target vsr_t field
3015 * rnan - resulting NaN
3017 #define VSX_CVT_FP_TO_INT_VECTOR(op, stp, ttp, sfld, tfld, rnan) \
3018 void helper_##op(CPUPPCState *env, uint32_t opcode) \
3022 getVSR(rB(opcode) + 32, &xb, env); \
3023 memset(&xt, 0, sizeof(xt)); \
3025 xt.tfld = stp##_to_##ttp##_round_to_zero(xb.sfld, &env->fp_status); \
3026 if (env->fp_status.float_exception_flags & float_flag_invalid) { \
3027 float_invalid_cvt(env, 0, GETPC(), stp##_classify(xb.sfld)); \
3031 putVSR(rD(opcode) + 32, &xt, env); \
3032 do_float_check_status(env, GETPC()); \
3035 VSX_CVT_FP_TO_INT_VECTOR(xscvqpsdz
, float128
, int64
, f128
, VsrD(0), \
3036 0x8000000000000000ULL
)
3038 VSX_CVT_FP_TO_INT_VECTOR(xscvqpswz
, float128
, int32
, f128
, VsrD(0), \
3039 0xffffffff80000000ULL
)
3040 VSX_CVT_FP_TO_INT_VECTOR(xscvqpudz
, float128
, uint64
, f128
, VsrD(0), 0x0ULL
)
3041 VSX_CVT_FP_TO_INT_VECTOR(xscvqpuwz
, float128
, uint32
, f128
, VsrD(0), 0x0ULL
)
3043 /* VSX_CVT_INT_TO_FP - VSX integer to floating point conversion
3044 * op - instruction mnemonic
3045 * nels - number of elements (1, 2 or 4)
3046 * stp - source type (int32, uint32, int64 or uint64)
3047 * ttp - target type (float32 or float64)
3048 * sfld - source vsr_t field
3049 * tfld - target vsr_t field
3050 * jdef - definition of the j index (i or 2*i)
3053 #define VSX_CVT_INT_TO_FP(op, nels, stp, ttp, sfld, tfld, sfprf, r2sp) \
3054 void helper_##op(CPUPPCState *env, uint32_t opcode) \
3059 getVSR(xB(opcode), &xb, env); \
3060 getVSR(xT(opcode), &xt, env); \
3062 for (i = 0; i < nels; i++) { \
3063 xt.tfld = stp##_to_##ttp(xb.sfld, &env->fp_status); \
3065 xt.tfld = helper_frsp(env, xt.tfld); \
3068 helper_compute_fprf_float64(env, xt.tfld); \
3072 putVSR(xT(opcode), &xt, env); \
3073 do_float_check_status(env, GETPC()); \
3076 VSX_CVT_INT_TO_FP(xscvsxddp
, 1, int64
, float64
, VsrD(0), VsrD(0), 1, 0)
3077 VSX_CVT_INT_TO_FP(xscvuxddp
, 1, uint64
, float64
, VsrD(0), VsrD(0), 1, 0)
3078 VSX_CVT_INT_TO_FP(xscvsxdsp
, 1, int64
, float64
, VsrD(0), VsrD(0), 1, 1)
3079 VSX_CVT_INT_TO_FP(xscvuxdsp
, 1, uint64
, float64
, VsrD(0), VsrD(0), 1, 1)
3080 VSX_CVT_INT_TO_FP(xvcvsxddp
, 2, int64
, float64
, VsrD(i
), VsrD(i
), 0, 0)
3081 VSX_CVT_INT_TO_FP(xvcvuxddp
, 2, uint64
, float64
, VsrD(i
), VsrD(i
), 0, 0)
3082 VSX_CVT_INT_TO_FP(xvcvsxwdp
, 2, int32
, float64
, VsrW(2*i
), VsrD(i
), 0, 0)
3083 VSX_CVT_INT_TO_FP(xvcvuxwdp
, 2, uint64
, float64
, VsrW(2*i
), VsrD(i
), 0, 0)
3084 VSX_CVT_INT_TO_FP(xvcvsxdsp
, 2, int64
, float32
, VsrD(i
), VsrW(2*i
), 0, 0)
3085 VSX_CVT_INT_TO_FP(xvcvuxdsp
, 2, uint64
, float32
, VsrD(i
), VsrW(2*i
), 0, 0)
3086 VSX_CVT_INT_TO_FP(xvcvsxwsp
, 4, int32
, float32
, VsrW(i
), VsrW(i
), 0, 0)
3087 VSX_CVT_INT_TO_FP(xvcvuxwsp
, 4, uint32
, float32
, VsrW(i
), VsrW(i
), 0, 0)
3089 /* VSX_CVT_INT_TO_FP_VECTOR - VSX integer to floating point conversion
3090 * op - instruction mnemonic
3091 * stp - source type (int32, uint32, int64 or uint64)
3092 * ttp - target type (float32 or float64)
3093 * sfld - source vsr_t field
3094 * tfld - target vsr_t field
3096 #define VSX_CVT_INT_TO_FP_VECTOR(op, stp, ttp, sfld, tfld) \
3097 void helper_##op(CPUPPCState *env, uint32_t opcode) \
3101 getVSR(rB(opcode) + 32, &xb, env); \
3102 getVSR(rD(opcode) + 32, &xt, env); \
3104 xt.tfld = stp##_to_##ttp(xb.sfld, &env->fp_status); \
3105 helper_compute_fprf_##ttp(env, xt.tfld); \
3107 putVSR(xT(opcode) + 32, &xt, env); \
3108 do_float_check_status(env, GETPC()); \
3111 VSX_CVT_INT_TO_FP_VECTOR(xscvsdqp
, int64
, float128
, VsrD(0), f128
)
3112 VSX_CVT_INT_TO_FP_VECTOR(xscvudqp
, uint64
, float128
, VsrD(0), f128
)
3114 /* For "use current rounding mode", define a value that will not be one of
3115 * the existing rounding model enums.
3117 #define FLOAT_ROUND_CURRENT (float_round_nearest_even + float_round_down + \
3118 float_round_up + float_round_to_zero)
3120 /* VSX_ROUND - VSX floating point round
3121 * op - instruction mnemonic
3122 * nels - number of elements (1, 2 or 4)
3123 * tp - type (float32 or float64)
3124 * fld - vsr_t field (VsrD(*) or VsrW(*))
3125 * rmode - rounding mode
3128 #define VSX_ROUND(op, nels, tp, fld, rmode, sfprf) \
3129 void helper_##op(CPUPPCState *env, uint32_t opcode) \
3133 getVSR(xB(opcode), &xb, env); \
3134 getVSR(xT(opcode), &xt, env); \
3136 if (rmode != FLOAT_ROUND_CURRENT) { \
3137 set_float_rounding_mode(rmode, &env->fp_status); \
3140 for (i = 0; i < nels; i++) { \
3141 if (unlikely(tp##_is_signaling_nan(xb.fld, \
3142 &env->fp_status))) { \
3143 float_invalid_op_vxsnan(env, GETPC()); \
3144 xt.fld = tp##_snan_to_qnan(xb.fld); \
3146 xt.fld = tp##_round_to_int(xb.fld, &env->fp_status); \
3149 helper_compute_fprf_float64(env, xt.fld); \
3153 /* If this is not a "use current rounding mode" instruction, \
3154 * then inhibit setting of the XX bit and restore rounding \
3155 * mode from FPSCR */ \
3156 if (rmode != FLOAT_ROUND_CURRENT) { \
3157 fpscr_set_rounding_mode(env); \
3158 env->fp_status.float_exception_flags &= ~float_flag_inexact; \
3161 putVSR(xT(opcode), &xt, env); \
3162 do_float_check_status(env, GETPC()); \
3165 VSX_ROUND(xsrdpi
, 1, float64
, VsrD(0), float_round_ties_away
, 1)
3166 VSX_ROUND(xsrdpic
, 1, float64
, VsrD(0), FLOAT_ROUND_CURRENT
, 1)
3167 VSX_ROUND(xsrdpim
, 1, float64
, VsrD(0), float_round_down
, 1)
3168 VSX_ROUND(xsrdpip
, 1, float64
, VsrD(0), float_round_up
, 1)
3169 VSX_ROUND(xsrdpiz
, 1, float64
, VsrD(0), float_round_to_zero
, 1)
3171 VSX_ROUND(xvrdpi
, 2, float64
, VsrD(i
), float_round_ties_away
, 0)
3172 VSX_ROUND(xvrdpic
, 2, float64
, VsrD(i
), FLOAT_ROUND_CURRENT
, 0)
3173 VSX_ROUND(xvrdpim
, 2, float64
, VsrD(i
), float_round_down
, 0)
3174 VSX_ROUND(xvrdpip
, 2, float64
, VsrD(i
), float_round_up
, 0)
3175 VSX_ROUND(xvrdpiz
, 2, float64
, VsrD(i
), float_round_to_zero
, 0)
3177 VSX_ROUND(xvrspi
, 4, float32
, VsrW(i
), float_round_ties_away
, 0)
3178 VSX_ROUND(xvrspic
, 4, float32
, VsrW(i
), FLOAT_ROUND_CURRENT
, 0)
3179 VSX_ROUND(xvrspim
, 4, float32
, VsrW(i
), float_round_down
, 0)
3180 VSX_ROUND(xvrspip
, 4, float32
, VsrW(i
), float_round_up
, 0)
3181 VSX_ROUND(xvrspiz
, 4, float32
, VsrW(i
), float_round_to_zero
, 0)
3183 uint64_t helper_xsrsp(CPUPPCState
*env
, uint64_t xb
)
3185 helper_reset_fpstatus(env
);
3187 uint64_t xt
= helper_frsp(env
, xb
);
3189 helper_compute_fprf_float64(env
, xt
);
3190 do_float_check_status(env
, GETPC());
3194 #define VSX_XXPERM(op, indexed) \
3195 void helper_##op(CPUPPCState *env, uint32_t opcode) \
3197 ppc_vsr_t xt, xa, pcv, xto; \
3200 getVSR(xA(opcode), &xa, env); \
3201 getVSR(xT(opcode), &xt, env); \
3202 getVSR(xB(opcode), &pcv, env); \
3204 for (i = 0; i < 16; i++) { \
3205 idx = pcv.VsrB(i) & 0x1F; \
3209 xto.VsrB(i) = (idx <= 15) ? xa.VsrB(idx) : xt.VsrB(idx - 16); \
3211 putVSR(xT(opcode), &xto, env); \
3214 VSX_XXPERM(xxperm
, 0)
3215 VSX_XXPERM(xxpermr
, 1)
3217 void helper_xvxsigsp(CPUPPCState
*env
, uint32_t opcode
)
3220 uint32_t exp
, i
, fraction
;
3222 getVSR(xB(opcode
), &xb
, env
);
3223 memset(&xt
, 0, sizeof(xt
));
3225 for (i
= 0; i
< 4; i
++) {
3226 exp
= (xb
.VsrW(i
) >> 23) & 0xFF;
3227 fraction
= xb
.VsrW(i
) & 0x7FFFFF;
3228 if (exp
!= 0 && exp
!= 255) {
3229 xt
.VsrW(i
) = fraction
| 0x00800000;
3231 xt
.VsrW(i
) = fraction
;
3234 putVSR(xT(opcode
), &xt
, env
);
3237 /* VSX_TEST_DC - VSX floating point test data class
3238 * op - instruction mnemonic
3239 * nels - number of elements (1, 2 or 4)
3240 * xbn - VSR register number
3241 * tp - type (float32 or float64)
3242 * fld - vsr_t field (VsrD(*) or VsrW(*))
3243 * tfld - target vsr_t field (VsrD(*) or VsrW(*))
3244 * fld_max - target field max
3245 * scrf - set result in CR and FPCC
3247 #define VSX_TEST_DC(op, nels, xbn, tp, fld, tfld, fld_max, scrf) \
3248 void helper_##op(CPUPPCState *env, uint32_t opcode) \
3251 uint32_t i, sign, dcmx; \
3252 uint32_t cc, match = 0; \
3254 getVSR(xbn, &xb, env); \
3256 memset(&xt, 0, sizeof(xt)); \
3257 dcmx = DCMX_XV(opcode); \
3259 dcmx = DCMX(opcode); \
3262 for (i = 0; i < nels; i++) { \
3263 sign = tp##_is_neg(xb.fld); \
3264 if (tp##_is_any_nan(xb.fld)) { \
3265 match = extract32(dcmx, 6, 1); \
3266 } else if (tp##_is_infinity(xb.fld)) { \
3267 match = extract32(dcmx, 4 + !sign, 1); \
3268 } else if (tp##_is_zero(xb.fld)) { \
3269 match = extract32(dcmx, 2 + !sign, 1); \
3270 } else if (tp##_is_zero_or_denormal(xb.fld)) { \
3271 match = extract32(dcmx, 0 + !sign, 1); \
3275 cc = sign << CRF_LT_BIT | match << CRF_EQ_BIT; \
3276 env->fpscr &= ~(0x0F << FPSCR_FPRF); \
3277 env->fpscr |= cc << FPSCR_FPRF; \
3278 env->crf[BF(opcode)] = cc; \
3280 xt.tfld = match ? fld_max : 0; \
3285 putVSR(xT(opcode), &xt, env); \
3289 VSX_TEST_DC(xvtstdcdp
, 2, xB(opcode
), float64
, VsrD(i
), VsrD(i
), UINT64_MAX
, 0)
3290 VSX_TEST_DC(xvtstdcsp
, 4, xB(opcode
), float32
, VsrW(i
), VsrW(i
), UINT32_MAX
, 0)
3291 VSX_TEST_DC(xststdcdp
, 1, xB(opcode
), float64
, VsrD(0), VsrD(0), 0, 1)
3292 VSX_TEST_DC(xststdcqp
, 1, (rB(opcode
) + 32), float128
, f128
, VsrD(0), 0, 1)
3294 void helper_xststdcsp(CPUPPCState
*env
, uint32_t opcode
)
3297 uint32_t dcmx
, sign
, exp
;
3298 uint32_t cc
, match
= 0, not_sp
= 0;
3300 getVSR(xB(opcode
), &xb
, env
);
3301 dcmx
= DCMX(opcode
);
3302 exp
= (xb
.VsrD(0) >> 52) & 0x7FF;
3304 sign
= float64_is_neg(xb
.VsrD(0));
3305 if (float64_is_any_nan(xb
.VsrD(0))) {
3306 match
= extract32(dcmx
, 6, 1);
3307 } else if (float64_is_infinity(xb
.VsrD(0))) {
3308 match
= extract32(dcmx
, 4 + !sign
, 1);
3309 } else if (float64_is_zero(xb
.VsrD(0))) {
3310 match
= extract32(dcmx
, 2 + !sign
, 1);
3311 } else if (float64_is_zero_or_denormal(xb
.VsrD(0)) ||
3312 (exp
> 0 && exp
< 0x381)) {
3313 match
= extract32(dcmx
, 0 + !sign
, 1);
3316 not_sp
= !float64_eq(xb
.VsrD(0),
3318 float64_to_float32(xb
.VsrD(0), &env
->fp_status
),
3319 &env
->fp_status
), &env
->fp_status
);
3321 cc
= sign
<< CRF_LT_BIT
| match
<< CRF_EQ_BIT
| not_sp
<< CRF_SO_BIT
;
3322 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
3323 env
->fpscr
|= cc
<< FPSCR_FPRF
;
3324 env
->crf
[BF(opcode
)] = cc
;
3327 void helper_xsrqpi(CPUPPCState
*env
, uint32_t opcode
)
3331 uint8_t r
= Rrm(opcode
);
3332 uint8_t ex
= Rc(opcode
);
3333 uint8_t rmc
= RMC(opcode
);
3337 getVSR(rB(opcode
) + 32, &xb
, env
);
3338 memset(&xt
, 0, sizeof(xt
));
3339 helper_reset_fpstatus(env
);
3341 if (r
== 0 && rmc
== 0) {
3342 rmode
= float_round_ties_away
;
3343 } else if (r
== 0 && rmc
== 0x3) {
3345 } else if (r
== 1) {
3348 rmode
= float_round_nearest_even
;
3351 rmode
= float_round_to_zero
;
3354 rmode
= float_round_up
;
3357 rmode
= float_round_down
;
3364 tstat
= env
->fp_status
;
3365 set_float_exception_flags(0, &tstat
);
3366 set_float_rounding_mode(rmode
, &tstat
);
3367 xt
.f128
= float128_round_to_int(xb
.f128
, &tstat
);
3368 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3370 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
3371 if (float128_is_signaling_nan(xb
.f128
, &tstat
)) {
3372 float_invalid_op_vxsnan(env
, GETPC());
3373 xt
.f128
= float128_snan_to_qnan(xt
.f128
);
3377 if (ex
== 0 && (tstat
.float_exception_flags
& float_flag_inexact
)) {
3378 env
->fp_status
.float_exception_flags
&= ~float_flag_inexact
;
3381 helper_compute_fprf_float128(env
, xt
.f128
);
3382 do_float_check_status(env
, GETPC());
3383 putVSR(rD(opcode
) + 32, &xt
, env
);
3386 void helper_xsrqpxp(CPUPPCState
*env
, uint32_t opcode
)
3390 uint8_t r
= Rrm(opcode
);
3391 uint8_t rmc
= RMC(opcode
);
3396 getVSR(rB(opcode
) + 32, &xb
, env
);
3397 memset(&xt
, 0, sizeof(xt
));
3398 helper_reset_fpstatus(env
);
3400 if (r
== 0 && rmc
== 0) {
3401 rmode
= float_round_ties_away
;
3402 } else if (r
== 0 && rmc
== 0x3) {
3404 } else if (r
== 1) {
3407 rmode
= float_round_nearest_even
;
3410 rmode
= float_round_to_zero
;
3413 rmode
= float_round_up
;
3416 rmode
= float_round_down
;
3423 tstat
= env
->fp_status
;
3424 set_float_exception_flags(0, &tstat
);
3425 set_float_rounding_mode(rmode
, &tstat
);
3426 round_res
= float128_to_floatx80(xb
.f128
, &tstat
);
3427 xt
.f128
= floatx80_to_float128(round_res
, &tstat
);
3428 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3430 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
3431 if (float128_is_signaling_nan(xb
.f128
, &tstat
)) {
3432 float_invalid_op_vxsnan(env
, GETPC());
3433 xt
.f128
= float128_snan_to_qnan(xt
.f128
);
3437 helper_compute_fprf_float128(env
, xt
.f128
);
3438 putVSR(rD(opcode
) + 32, &xt
, env
);
3439 do_float_check_status(env
, GETPC());
3442 void helper_xssqrtqp(CPUPPCState
*env
, uint32_t opcode
)
3448 getVSR(rB(opcode
) + 32, &xb
, env
);
3449 memset(&xt
, 0, sizeof(xt
));
3450 helper_reset_fpstatus(env
);
3452 tstat
= env
->fp_status
;
3453 if (unlikely(Rc(opcode
) != 0)) {
3454 tstat
.float_rounding_mode
= float_round_to_odd
;
3457 set_float_exception_flags(0, &tstat
);
3458 xt
.f128
= float128_sqrt(xb
.f128
, &tstat
);
3459 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3461 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
3462 if (float128_is_signaling_nan(xb
.f128
, &tstat
)) {
3463 float_invalid_op_vxsnan(env
, GETPC());
3464 xt
.f128
= float128_snan_to_qnan(xb
.f128
);
3465 } else if (float128_is_quiet_nan(xb
.f128
, &tstat
)) {
3467 } else if (float128_is_neg(xb
.f128
) && !float128_is_zero(xb
.f128
)) {
3468 float_invalid_op_vxsqrt(env
, 1, GETPC());
3469 xt
.f128
= float128_default_nan(&env
->fp_status
);
3473 helper_compute_fprf_float128(env
, xt
.f128
);
3474 putVSR(rD(opcode
) + 32, &xt
, env
);
3475 do_float_check_status(env
, GETPC());
3478 void helper_xssubqp(CPUPPCState
*env
, uint32_t opcode
)
3480 ppc_vsr_t xt
, xa
, xb
;
3483 getVSR(rA(opcode
) + 32, &xa
, env
);
3484 getVSR(rB(opcode
) + 32, &xb
, env
);
3485 getVSR(rD(opcode
) + 32, &xt
, env
);
3486 helper_reset_fpstatus(env
);
3488 tstat
= env
->fp_status
;
3489 if (unlikely(Rc(opcode
) != 0)) {
3490 tstat
.float_rounding_mode
= float_round_to_odd
;
3493 set_float_exception_flags(0, &tstat
);
3494 xt
.f128
= float128_sub(xa
.f128
, xb
.f128
, &tstat
);
3495 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3497 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
3498 float_invalid_op_addsub(env
, 1, GETPC(),
3499 float128_classify(xa
.f128
) |
3500 float128_classify(xb
.f128
));
3503 helper_compute_fprf_float128(env
, xt
.f128
);
3504 putVSR(rD(opcode
) + 32, &xt
, env
);
3505 do_float_check_status(env
, GETPC());