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.1 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 if (unlikely(extract32(arg
, 23, 8) == 0xff)) {
63 ret
= (uint64_t)extract32(arg
, 31, 1) << 63;
64 ret
|= (uint64_t)0x7ff << 52;
65 ret
|= (uint64_t)extract32(arg
, 0, 23) << 29;
67 /* Normalized operand. */
68 ret
= (uint64_t)extract32(arg
, 30, 2) << 62;
69 ret
|= ((extract32(arg
, 30, 1) ^ 1) * (uint64_t)7) << 59;
70 ret
|= (uint64_t)extract32(arg
, 0, 30) << 29;
73 /* Zero or Denormalized operand. */
74 ret
= (uint64_t)extract32(arg
, 31, 1) << 63;
75 if (unlikely(abs_arg
!= 0)) {
77 * Denormalized operand.
78 * Shift fraction so that the msb is in the implicit bit position.
79 * Thus, shift is in the range [1:23].
81 int shift
= clz32(abs_arg
) - 8;
83 * The first 3 terms compute the float64 exponent. We then bias
84 * this result by -1 so that we can swallow the implicit bit below.
86 int exp
= -126 - shift
+ 1023 - 1;
88 ret
|= (uint64_t)exp
<< 52;
89 ret
+= (uint64_t)abs_arg
<< (52 - 23 + shift
);
96 * This is the non-arithmatic conversion that happens e.g. on stores.
97 * In the Power ISA pseudocode, this is called SINGLE.
99 uint32_t helper_tosingle(uint64_t arg
)
101 int exp
= extract64(arg
, 52, 11);
104 if (likely(exp
> 896)) {
105 /* No denormalization required (includes Inf, NaN). */
106 ret
= extract64(arg
, 62, 2) << 30;
107 ret
|= extract64(arg
, 29, 30);
110 * Zero or Denormal result. If the exponent is in bounds for
111 * a single-precision denormal result, extract the proper
112 * bits. If the input is not zero, and the exponent is out of
113 * bounds, then the result is undefined; this underflows to
116 ret
= extract64(arg
, 63, 1) << 31;
117 if (unlikely(exp
>= 874)) {
118 /* Denormal result. */
119 ret
|= ((1ULL << 52) | extract64(arg
, 0, 52)) >> (896 + 30 - exp
);
125 static inline int ppc_float32_get_unbiased_exp(float32 f
)
127 return ((f
>> 23) & 0xFF) - 127;
130 static inline int ppc_float64_get_unbiased_exp(float64 f
)
132 return ((f
>> 52) & 0x7FF) - 1023;
135 /* Classify a floating-point number. */
146 #define COMPUTE_CLASS(tp) \
147 static int tp##_classify(tp arg) \
149 int ret = tp##_is_neg(arg) * is_neg; \
150 if (unlikely(tp##_is_any_nan(arg))) { \
151 float_status dummy = { }; /* snan_bit_is_one = 0 */ \
152 ret |= (tp##_is_signaling_nan(arg, &dummy) \
153 ? is_snan : is_qnan); \
154 } else if (unlikely(tp##_is_infinity(arg))) { \
156 } else if (tp##_is_zero(arg)) { \
158 } else if (tp##_is_zero_or_denormal(arg)) { \
159 ret |= is_denormal; \
166 COMPUTE_CLASS(float16
)
167 COMPUTE_CLASS(float32
)
168 COMPUTE_CLASS(float64
)
169 COMPUTE_CLASS(float128
)
171 static void set_fprf_from_class(CPUPPCState
*env
, int class)
173 static const uint8_t fprf
[6][2] = {
174 { 0x04, 0x08 }, /* normalized */
175 { 0x02, 0x12 }, /* zero */
176 { 0x14, 0x18 }, /* denormalized */
177 { 0x05, 0x09 }, /* infinity */
178 { 0x11, 0x11 }, /* qnan */
179 { 0x00, 0x00 }, /* snan -- flags are undefined */
181 bool isneg
= class & is_neg
;
183 env
->fpscr
&= ~FP_FPRF
;
184 env
->fpscr
|= fprf
[ctz32(class)][isneg
] << FPSCR_FPRF
;
187 #define COMPUTE_FPRF(tp) \
188 void helper_compute_fprf_##tp(CPUPPCState *env, tp arg) \
190 set_fprf_from_class(env, tp##_classify(arg)); \
193 COMPUTE_FPRF(float16
)
194 COMPUTE_FPRF(float32
)
195 COMPUTE_FPRF(float64
)
196 COMPUTE_FPRF(float128
)
198 /* Floating-point invalid operations exception */
199 static void finish_invalid_op_excp(CPUPPCState
*env
, int op
, uintptr_t retaddr
)
201 /* Update the floating-point invalid operation summary */
203 /* Update the floating-point exception summary */
206 /* Update the floating-point enabled exception summary */
207 env
->fpscr
|= FP_FEX
;
208 if (fp_exceptions_enabled(env
)) {
209 raise_exception_err_ra(env
, POWERPC_EXCP_PROGRAM
,
210 POWERPC_EXCP_FP
| op
, retaddr
);
215 static void finish_invalid_op_arith(CPUPPCState
*env
, int op
,
216 bool set_fpcc
, uintptr_t retaddr
)
218 env
->fpscr
&= ~(FP_FR
| FP_FI
);
221 env
->fpscr
&= ~FP_FPCC
;
222 env
->fpscr
|= (FP_C
| FP_FU
);
225 finish_invalid_op_excp(env
, op
, retaddr
);
229 static void float_invalid_op_vxsnan(CPUPPCState
*env
, uintptr_t retaddr
)
231 env
->fpscr
|= FP_VXSNAN
;
232 finish_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
, retaddr
);
235 /* Magnitude subtraction of infinities */
236 static void float_invalid_op_vxisi(CPUPPCState
*env
, bool set_fpcc
,
239 env
->fpscr
|= FP_VXISI
;
240 finish_invalid_op_arith(env
, POWERPC_EXCP_FP_VXISI
, set_fpcc
, retaddr
);
243 /* Division of infinity by infinity */
244 static void float_invalid_op_vxidi(CPUPPCState
*env
, bool set_fpcc
,
247 env
->fpscr
|= FP_VXIDI
;
248 finish_invalid_op_arith(env
, POWERPC_EXCP_FP_VXIDI
, set_fpcc
, retaddr
);
251 /* Division of zero by zero */
252 static void float_invalid_op_vxzdz(CPUPPCState
*env
, bool set_fpcc
,
255 env
->fpscr
|= FP_VXZDZ
;
256 finish_invalid_op_arith(env
, POWERPC_EXCP_FP_VXZDZ
, set_fpcc
, retaddr
);
259 /* Multiplication of zero by infinity */
260 static void float_invalid_op_vximz(CPUPPCState
*env
, bool set_fpcc
,
263 env
->fpscr
|= FP_VXIMZ
;
264 finish_invalid_op_arith(env
, POWERPC_EXCP_FP_VXIMZ
, set_fpcc
, retaddr
);
267 /* Square root of a negative number */
268 static void float_invalid_op_vxsqrt(CPUPPCState
*env
, bool set_fpcc
,
271 env
->fpscr
|= FP_VXSQRT
;
272 finish_invalid_op_arith(env
, POWERPC_EXCP_FP_VXSQRT
, set_fpcc
, retaddr
);
275 /* Ordered comparison of NaN */
276 static void float_invalid_op_vxvc(CPUPPCState
*env
, bool set_fpcc
,
279 env
->fpscr
|= FP_VXVC
;
281 env
->fpscr
&= ~FP_FPCC
;
282 env
->fpscr
|= (FP_C
| FP_FU
);
284 /* Update the floating-point invalid operation summary */
286 /* Update the floating-point exception summary */
288 /* We must update the target FPR before raising the exception */
290 CPUState
*cs
= env_cpu(env
);
292 cs
->exception_index
= POWERPC_EXCP_PROGRAM
;
293 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_VXVC
;
294 /* Update the floating-point enabled exception summary */
295 env
->fpscr
|= FP_FEX
;
296 /* Exception is deferred */
300 /* Invalid conversion */
301 static void float_invalid_op_vxcvi(CPUPPCState
*env
, bool set_fpcc
,
304 env
->fpscr
|= FP_VXCVI
;
305 env
->fpscr
&= ~(FP_FR
| FP_FI
);
308 env
->fpscr
&= ~FP_FPCC
;
309 env
->fpscr
|= (FP_C
| FP_FU
);
312 finish_invalid_op_excp(env
, POWERPC_EXCP_FP_VXCVI
, retaddr
);
315 static inline void float_zero_divide_excp(CPUPPCState
*env
, uintptr_t raddr
)
318 env
->fpscr
&= ~(FP_FR
| FP_FI
);
319 /* Update the floating-point exception summary */
322 /* Update the floating-point enabled exception summary */
323 env
->fpscr
|= FP_FEX
;
324 if (fp_exceptions_enabled(env
)) {
325 raise_exception_err_ra(env
, POWERPC_EXCP_PROGRAM
,
326 POWERPC_EXCP_FP
| POWERPC_EXCP_FP_ZX
,
332 static inline void float_overflow_excp(CPUPPCState
*env
)
334 CPUState
*cs
= env_cpu(env
);
337 /* Update the floating-point exception summary */
340 /* XXX: should adjust the result */
341 /* Update the floating-point enabled exception summary */
342 env
->fpscr
|= FP_FEX
;
343 /* We must update the target FPR before raising the exception */
344 cs
->exception_index
= POWERPC_EXCP_PROGRAM
;
345 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_OX
;
352 static inline void float_underflow_excp(CPUPPCState
*env
)
354 CPUState
*cs
= env_cpu(env
);
357 /* Update the floating-point exception summary */
360 /* XXX: should adjust the result */
361 /* Update the floating-point enabled exception summary */
362 env
->fpscr
|= FP_FEX
;
363 /* We must update the target FPR before raising the exception */
364 cs
->exception_index
= POWERPC_EXCP_PROGRAM
;
365 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_UX
;
369 static inline void float_inexact_excp(CPUPPCState
*env
)
371 CPUState
*cs
= env_cpu(env
);
375 /* Update the floating-point exception summary */
378 /* Update the floating-point enabled exception summary */
379 env
->fpscr
|= FP_FEX
;
380 /* We must update the target FPR before raising the exception */
381 cs
->exception_index
= POWERPC_EXCP_PROGRAM
;
382 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_XX
;
386 void helper_fpscr_clrbit(CPUPPCState
*env
, uint32_t bit
)
388 uint32_t mask
= 1u << bit
;
389 if (env
->fpscr
& mask
) {
390 ppc_store_fpscr(env
, env
->fpscr
& ~(target_ulong
)mask
);
394 void helper_fpscr_setbit(CPUPPCState
*env
, uint32_t bit
)
396 uint32_t mask
= 1u << bit
;
397 if (!(env
->fpscr
& mask
)) {
398 ppc_store_fpscr(env
, env
->fpscr
| mask
);
402 void helper_store_fpscr(CPUPPCState
*env
, uint64_t val
, uint32_t nibbles
)
404 target_ulong mask
= 0;
407 /* TODO: push this extension back to translation time */
408 for (i
= 0; i
< sizeof(target_ulong
) * 2; i
++) {
409 if (nibbles
& (1 << i
)) {
410 mask
|= (target_ulong
) 0xf << (4 * i
);
413 val
= (val
& mask
) | (env
->fpscr
& ~mask
);
414 ppc_store_fpscr(env
, val
);
417 void helper_fpscr_check_status(CPUPPCState
*env
)
419 CPUState
*cs
= env_cpu(env
);
420 target_ulong fpscr
= env
->fpscr
;
423 if ((fpscr
& FP_OX
) && (fpscr
& FP_OE
)) {
424 error
= POWERPC_EXCP_FP_OX
;
425 } else if ((fpscr
& FP_UX
) && (fpscr
& FP_UE
)) {
426 error
= POWERPC_EXCP_FP_UX
;
427 } else if ((fpscr
& FP_XX
) && (fpscr
& FP_XE
)) {
428 error
= POWERPC_EXCP_FP_XX
;
429 } else if ((fpscr
& FP_ZX
) && (fpscr
& FP_ZE
)) {
430 error
= POWERPC_EXCP_FP_ZX
;
431 } else if (fpscr
& FP_VE
) {
432 if (fpscr
& FP_VXSOFT
) {
433 error
= POWERPC_EXCP_FP_VXSOFT
;
434 } else if (fpscr
& FP_VXSNAN
) {
435 error
= POWERPC_EXCP_FP_VXSNAN
;
436 } else if (fpscr
& FP_VXISI
) {
437 error
= POWERPC_EXCP_FP_VXISI
;
438 } else if (fpscr
& FP_VXIDI
) {
439 error
= POWERPC_EXCP_FP_VXIDI
;
440 } else if (fpscr
& FP_VXZDZ
) {
441 error
= POWERPC_EXCP_FP_VXZDZ
;
442 } else if (fpscr
& FP_VXIMZ
) {
443 error
= POWERPC_EXCP_FP_VXIMZ
;
444 } else if (fpscr
& FP_VXVC
) {
445 error
= POWERPC_EXCP_FP_VXVC
;
446 } else if (fpscr
& FP_VXSQRT
) {
447 error
= POWERPC_EXCP_FP_VXSQRT
;
448 } else if (fpscr
& FP_VXCVI
) {
449 error
= POWERPC_EXCP_FP_VXCVI
;
456 cs
->exception_index
= POWERPC_EXCP_PROGRAM
;
457 env
->error_code
= error
| POWERPC_EXCP_FP
;
458 /* Deferred floating-point exception after target FPSCR update */
459 if (fp_exceptions_enabled(env
)) {
460 raise_exception_err_ra(env
, cs
->exception_index
,
461 env
->error_code
, GETPC());
465 static void do_float_check_status(CPUPPCState
*env
, uintptr_t raddr
)
467 CPUState
*cs
= env_cpu(env
);
468 int status
= get_float_exception_flags(&env
->fp_status
);
470 if (status
& float_flag_overflow
) {
471 float_overflow_excp(env
);
472 } else if (status
& float_flag_underflow
) {
473 float_underflow_excp(env
);
475 if (status
& float_flag_inexact
) {
476 float_inexact_excp(env
);
478 env
->fpscr
&= ~FP_FI
; /* clear the FPSCR[FI] bit */
481 if (cs
->exception_index
== POWERPC_EXCP_PROGRAM
&&
482 (env
->error_code
& POWERPC_EXCP_FP
)) {
483 /* Deferred floating-point exception after target FPR update */
484 if (fp_exceptions_enabled(env
)) {
485 raise_exception_err_ra(env
, cs
->exception_index
,
486 env
->error_code
, raddr
);
491 void helper_float_check_status(CPUPPCState
*env
)
493 do_float_check_status(env
, GETPC());
496 void helper_reset_fpstatus(CPUPPCState
*env
)
498 set_float_exception_flags(0, &env
->fp_status
);
501 static void float_invalid_op_addsub(CPUPPCState
*env
, int flags
,
502 bool set_fpcc
, uintptr_t retaddr
)
504 if (flags
& float_flag_invalid_isi
) {
505 float_invalid_op_vxisi(env
, set_fpcc
, retaddr
);
506 } else if (flags
& float_flag_invalid_snan
) {
507 float_invalid_op_vxsnan(env
, retaddr
);
512 float64
helper_fadd(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
514 float64 ret
= float64_add(arg1
, arg2
, &env
->fp_status
);
515 int flags
= get_float_exception_flags(&env
->fp_status
);
517 if (unlikely(flags
& float_flag_invalid
)) {
518 float_invalid_op_addsub(env
, flags
, 1, GETPC());
525 float64
helper_fsub(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
527 float64 ret
= float64_sub(arg1
, arg2
, &env
->fp_status
);
528 int flags
= get_float_exception_flags(&env
->fp_status
);
530 if (unlikely(flags
& float_flag_invalid
)) {
531 float_invalid_op_addsub(env
, flags
, 1, GETPC());
537 static void float_invalid_op_mul(CPUPPCState
*env
, int flags
,
538 bool set_fprc
, uintptr_t retaddr
)
540 if (flags
& float_flag_invalid_imz
) {
541 float_invalid_op_vximz(env
, set_fprc
, retaddr
);
542 } else if (flags
& float_flag_invalid_snan
) {
543 float_invalid_op_vxsnan(env
, retaddr
);
548 float64
helper_fmul(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
550 float64 ret
= float64_mul(arg1
, arg2
, &env
->fp_status
);
551 int flags
= get_float_exception_flags(&env
->fp_status
);
553 if (unlikely(flags
& float_flag_invalid
)) {
554 float_invalid_op_mul(env
, flags
, 1, GETPC());
560 static void float_invalid_op_div(CPUPPCState
*env
, int flags
,
561 bool set_fprc
, uintptr_t retaddr
)
563 if (flags
& float_flag_invalid_idi
) {
564 float_invalid_op_vxidi(env
, set_fprc
, retaddr
);
565 } else if (flags
& float_flag_invalid_zdz
) {
566 float_invalid_op_vxzdz(env
, set_fprc
, retaddr
);
567 } else if (flags
& float_flag_invalid_snan
) {
568 float_invalid_op_vxsnan(env
, retaddr
);
573 float64
helper_fdiv(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
575 float64 ret
= float64_div(arg1
, arg2
, &env
->fp_status
);
576 int flags
= get_float_exception_flags(&env
->fp_status
);
578 if (unlikely(flags
& float_flag_invalid
)) {
579 float_invalid_op_div(env
, flags
, 1, GETPC());
581 if (unlikely(flags
& float_flag_divbyzero
)) {
582 float_zero_divide_excp(env
, GETPC());
588 static uint64_t float_invalid_cvt(CPUPPCState
*env
, int flags
,
589 uint64_t ret
, uint64_t ret_nan
,
590 bool set_fprc
, uintptr_t retaddr
)
593 * VXCVI is different from most in that it sets two exception bits,
594 * VXCVI and VXSNAN for an SNaN input.
596 if (flags
& float_flag_invalid_snan
) {
597 env
->fpscr
|= FP_VXSNAN
;
599 float_invalid_op_vxcvi(env
, set_fprc
, retaddr
);
601 return flags
& float_flag_invalid_cvti
? ret
: ret_nan
;
604 #define FPU_FCTI(op, cvt, nanval) \
605 uint64_t helper_##op(CPUPPCState *env, float64 arg) \
607 uint64_t ret = float64_to_##cvt(arg, &env->fp_status); \
608 int flags = get_float_exception_flags(&env->fp_status); \
609 if (unlikely(flags & float_flag_invalid)) { \
610 ret = float_invalid_cvt(env, flags, ret, nanval, 1, GETPC()); \
615 FPU_FCTI(fctiw
, int32
, 0x80000000U
)
616 FPU_FCTI(fctiwz
, int32_round_to_zero
, 0x80000000U
)
617 FPU_FCTI(fctiwu
, uint32
, 0x00000000U
)
618 FPU_FCTI(fctiwuz
, uint32_round_to_zero
, 0x00000000U
)
619 FPU_FCTI(fctid
, int64
, 0x8000000000000000ULL
)
620 FPU_FCTI(fctidz
, int64_round_to_zero
, 0x8000000000000000ULL
)
621 FPU_FCTI(fctidu
, uint64
, 0x0000000000000000ULL
)
622 FPU_FCTI(fctiduz
, uint64_round_to_zero
, 0x0000000000000000ULL
)
624 #define FPU_FCFI(op, cvtr, is_single) \
625 uint64_t helper_##op(CPUPPCState *env, uint64_t arg) \
630 float32 tmp = cvtr(arg, &env->fp_status); \
631 farg.d = float32_to_float64(tmp, &env->fp_status); \
633 farg.d = cvtr(arg, &env->fp_status); \
635 do_float_check_status(env, GETPC()); \
639 FPU_FCFI(fcfid
, int64_to_float64
, 0)
640 FPU_FCFI(fcfids
, int64_to_float32
, 1)
641 FPU_FCFI(fcfidu
, uint64_to_float64
, 0)
642 FPU_FCFI(fcfidus
, uint64_to_float32
, 1)
644 static uint64_t do_fri(CPUPPCState
*env
, uint64_t arg
,
645 FloatRoundMode rounding_mode
)
647 FloatRoundMode old_rounding_mode
= get_float_rounding_mode(&env
->fp_status
);
650 set_float_rounding_mode(rounding_mode
, &env
->fp_status
);
651 arg
= float64_round_to_int(arg
, &env
->fp_status
);
652 set_float_rounding_mode(old_rounding_mode
, &env
->fp_status
);
654 flags
= get_float_exception_flags(&env
->fp_status
);
655 if (flags
& float_flag_invalid_snan
) {
656 float_invalid_op_vxsnan(env
, GETPC());
659 /* fri* does not set FPSCR[XX] */
660 set_float_exception_flags(flags
& ~float_flag_inexact
, &env
->fp_status
);
661 do_float_check_status(env
, GETPC());
666 uint64_t helper_frin(CPUPPCState
*env
, uint64_t arg
)
668 return do_fri(env
, arg
, float_round_ties_away
);
671 uint64_t helper_friz(CPUPPCState
*env
, uint64_t arg
)
673 return do_fri(env
, arg
, float_round_to_zero
);
676 uint64_t helper_frip(CPUPPCState
*env
, uint64_t arg
)
678 return do_fri(env
, arg
, float_round_up
);
681 uint64_t helper_frim(CPUPPCState
*env
, uint64_t arg
)
683 return do_fri(env
, arg
, float_round_down
);
686 static void float_invalid_op_madd(CPUPPCState
*env
, int flags
,
687 bool set_fpcc
, uintptr_t retaddr
)
689 if (flags
& float_flag_invalid_imz
) {
690 float_invalid_op_vximz(env
, set_fpcc
, retaddr
);
692 float_invalid_op_addsub(env
, flags
, set_fpcc
, retaddr
);
696 static float64
do_fmadd(CPUPPCState
*env
, float64 a
, float64 b
,
697 float64 c
, int madd_flags
, uintptr_t retaddr
)
699 float64 ret
= float64_muladd(a
, b
, c
, madd_flags
, &env
->fp_status
);
700 int flags
= get_float_exception_flags(&env
->fp_status
);
702 if (unlikely(flags
& float_flag_invalid
)) {
703 float_invalid_op_madd(env
, flags
, 1, retaddr
);
708 static uint64_t do_fmadds(CPUPPCState
*env
, float64 a
, float64 b
,
709 float64 c
, int madd_flags
, uintptr_t retaddr
)
711 float64 ret
= float64r32_muladd(a
, b
, c
, madd_flags
, &env
->fp_status
);
712 int flags
= get_float_exception_flags(&env
->fp_status
);
714 if (unlikely(flags
& float_flag_invalid
)) {
715 float_invalid_op_madd(env
, flags
, 1, retaddr
);
720 #define FPU_FMADD(op, madd_flags) \
721 uint64_t helper_##op(CPUPPCState *env, uint64_t arg1, \
722 uint64_t arg2, uint64_t arg3) \
723 { return do_fmadd(env, arg1, arg2, arg3, madd_flags, GETPC()); } \
724 uint64_t helper_##op##s(CPUPPCState *env, uint64_t arg1, \
725 uint64_t arg2, uint64_t arg3) \
726 { return do_fmadds(env, arg1, arg2, arg3, madd_flags, GETPC()); }
729 #define MSUB_FLGS float_muladd_negate_c
730 #define NMADD_FLGS float_muladd_negate_result
731 #define NMSUB_FLGS (float_muladd_negate_c | float_muladd_negate_result)
733 FPU_FMADD(fmadd
, MADD_FLGS
)
734 FPU_FMADD(fnmadd
, NMADD_FLGS
)
735 FPU_FMADD(fmsub
, MSUB_FLGS
)
736 FPU_FMADD(fnmsub
, NMSUB_FLGS
)
739 static uint64_t do_frsp(CPUPPCState
*env
, uint64_t arg
, uintptr_t retaddr
)
741 float32 f32
= float64_to_float32(arg
, &env
->fp_status
);
742 int flags
= get_float_exception_flags(&env
->fp_status
);
744 if (unlikely(flags
& float_flag_invalid_snan
)) {
745 float_invalid_op_vxsnan(env
, retaddr
);
747 return helper_todouble(f32
);
750 uint64_t helper_frsp(CPUPPCState
*env
, uint64_t arg
)
752 return do_frsp(env
, arg
, GETPC());
755 static void float_invalid_op_sqrt(CPUPPCState
*env
, int flags
,
756 bool set_fpcc
, uintptr_t retaddr
)
758 if (unlikely(flags
& float_flag_invalid_sqrt
)) {
759 float_invalid_op_vxsqrt(env
, set_fpcc
, retaddr
);
760 } else if (unlikely(flags
& float_flag_invalid_snan
)) {
761 float_invalid_op_vxsnan(env
, retaddr
);
766 float64
helper_fsqrt(CPUPPCState
*env
, float64 arg
)
768 float64 ret
= float64_sqrt(arg
, &env
->fp_status
);
769 int flags
= get_float_exception_flags(&env
->fp_status
);
771 if (unlikely(flags
& float_flag_invalid
)) {
772 float_invalid_op_sqrt(env
, flags
, 1, GETPC());
779 float64
helper_fre(CPUPPCState
*env
, float64 arg
)
781 /* "Estimate" the reciprocal with actual division. */
782 float64 ret
= float64_div(float64_one
, arg
, &env
->fp_status
);
783 int flags
= get_float_exception_flags(&env
->fp_status
);
785 if (unlikely(flags
& float_flag_invalid_snan
)) {
786 float_invalid_op_vxsnan(env
, GETPC());
788 if (unlikely(flags
& float_flag_divbyzero
)) {
789 float_zero_divide_excp(env
, GETPC());
790 /* For FPSCR.ZE == 0, the result is 1/2. */
791 ret
= float64_set_sign(float64_half
, float64_is_neg(arg
));
798 uint64_t helper_fres(CPUPPCState
*env
, uint64_t arg
)
805 if (unlikely(float64_is_signaling_nan(farg
.d
, &env
->fp_status
))) {
806 /* sNaN reciprocal */
807 float_invalid_op_vxsnan(env
, GETPC());
809 farg
.d
= float64_div(float64_one
, farg
.d
, &env
->fp_status
);
810 f32
= float64_to_float32(farg
.d
, &env
->fp_status
);
811 farg
.d
= float32_to_float64(f32
, &env
->fp_status
);
816 /* frsqrte - frsqrte. */
817 float64
helper_frsqrte(CPUPPCState
*env
, float64 arg
)
819 /* "Estimate" the reciprocal with actual division. */
820 float64 rets
= float64_sqrt(arg
, &env
->fp_status
);
821 float64 retd
= float64_div(float64_one
, rets
, &env
->fp_status
);
822 int flags
= get_float_exception_flags(&env
->fp_status
);
824 if (unlikely(flags
& float_flag_invalid
)) {
825 float_invalid_op_sqrt(env
, flags
, 1, GETPC());
827 if (unlikely(flags
& float_flag_divbyzero
)) {
828 /* Reciprocal of (square root of) zero. */
829 float_zero_divide_excp(env
, GETPC());
836 uint64_t helper_fsel(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
843 if ((!float64_is_neg(farg1
.d
) || float64_is_zero(farg1
.d
)) &&
844 !float64_is_any_nan(farg1
.d
)) {
851 uint32_t helper_ftdiv(uint64_t fra
, uint64_t frb
)
856 if (unlikely(float64_is_infinity(fra
) ||
857 float64_is_infinity(frb
) ||
858 float64_is_zero(frb
))) {
862 int e_a
= ppc_float64_get_unbiased_exp(fra
);
863 int e_b
= ppc_float64_get_unbiased_exp(frb
);
865 if (unlikely(float64_is_any_nan(fra
) ||
866 float64_is_any_nan(frb
))) {
868 } else if ((e_b
<= -1022) || (e_b
>= 1021)) {
870 } else if (!float64_is_zero(fra
) &&
871 (((e_a
- e_b
) >= 1023) ||
872 ((e_a
- e_b
) <= -1021) ||
877 if (unlikely(float64_is_zero_or_denormal(frb
))) {
878 /* XB is not zero because of the above check and */
879 /* so must be denormalized. */
884 return 0x8 | (fg_flag
? 4 : 0) | (fe_flag
? 2 : 0);
887 uint32_t helper_ftsqrt(uint64_t frb
)
892 if (unlikely(float64_is_infinity(frb
) || float64_is_zero(frb
))) {
896 int e_b
= ppc_float64_get_unbiased_exp(frb
);
898 if (unlikely(float64_is_any_nan(frb
))) {
900 } else if (unlikely(float64_is_zero(frb
))) {
902 } else if (unlikely(float64_is_neg(frb
))) {
904 } else if (!float64_is_zero(frb
) && (e_b
<= (-1022 + 52))) {
908 if (unlikely(float64_is_zero_or_denormal(frb
))) {
909 /* XB is not zero because of the above check and */
910 /* therefore must be denormalized. */
915 return 0x8 | (fg_flag
? 4 : 0) | (fe_flag
? 2 : 0);
918 void helper_fcmpu(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
921 CPU_DoubleU farg1
, farg2
;
927 if (unlikely(float64_is_any_nan(farg1
.d
) ||
928 float64_is_any_nan(farg2
.d
))) {
930 } else if (float64_lt(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
932 } else if (!float64_le(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
938 env
->fpscr
&= ~FP_FPCC
;
939 env
->fpscr
|= ret
<< FPSCR_FPCC
;
940 env
->crf
[crfD
] = ret
;
941 if (unlikely(ret
== 0x01UL
942 && (float64_is_signaling_nan(farg1
.d
, &env
->fp_status
) ||
943 float64_is_signaling_nan(farg2
.d
, &env
->fp_status
)))) {
944 /* sNaN comparison */
945 float_invalid_op_vxsnan(env
, GETPC());
949 void helper_fcmpo(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
952 CPU_DoubleU farg1
, farg2
;
958 if (unlikely(float64_is_any_nan(farg1
.d
) ||
959 float64_is_any_nan(farg2
.d
))) {
961 } else if (float64_lt(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
963 } else if (!float64_le(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
969 env
->fpscr
&= ~FP_FPCC
;
970 env
->fpscr
|= ret
<< FPSCR_FPCC
;
971 env
->crf
[crfD
] = (uint32_t) ret
;
972 if (unlikely(ret
== 0x01UL
)) {
973 float_invalid_op_vxvc(env
, 1, GETPC());
974 if (float64_is_signaling_nan(farg1
.d
, &env
->fp_status
) ||
975 float64_is_signaling_nan(farg2
.d
, &env
->fp_status
)) {
976 /* sNaN comparison */
977 float_invalid_op_vxsnan(env
, GETPC());
982 /* Single-precision floating-point conversions */
983 static inline uint32_t efscfsi(CPUPPCState
*env
, uint32_t val
)
987 u
.f
= int32_to_float32(val
, &env
->vec_status
);
992 static inline uint32_t efscfui(CPUPPCState
*env
, uint32_t val
)
996 u
.f
= uint32_to_float32(val
, &env
->vec_status
);
1001 static inline int32_t efsctsi(CPUPPCState
*env
, uint32_t val
)
1006 /* NaN are not treated the same way IEEE 754 does */
1007 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1011 return float32_to_int32(u
.f
, &env
->vec_status
);
1014 static inline uint32_t efsctui(CPUPPCState
*env
, uint32_t val
)
1019 /* NaN are not treated the same way IEEE 754 does */
1020 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1024 return float32_to_uint32(u
.f
, &env
->vec_status
);
1027 static inline uint32_t efsctsiz(CPUPPCState
*env
, uint32_t val
)
1032 /* NaN are not treated the same way IEEE 754 does */
1033 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1037 return float32_to_int32_round_to_zero(u
.f
, &env
->vec_status
);
1040 static inline uint32_t efsctuiz(CPUPPCState
*env
, uint32_t val
)
1045 /* NaN are not treated the same way IEEE 754 does */
1046 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1050 return float32_to_uint32_round_to_zero(u
.f
, &env
->vec_status
);
1053 static inline uint32_t efscfsf(CPUPPCState
*env
, uint32_t val
)
1058 u
.f
= int32_to_float32(val
, &env
->vec_status
);
1059 tmp
= int64_to_float32(1ULL << 32, &env
->vec_status
);
1060 u
.f
= float32_div(u
.f
, tmp
, &env
->vec_status
);
1065 static inline uint32_t efscfuf(CPUPPCState
*env
, uint32_t val
)
1070 u
.f
= uint32_to_float32(val
, &env
->vec_status
);
1071 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1072 u
.f
= float32_div(u
.f
, tmp
, &env
->vec_status
);
1077 static inline uint32_t efsctsf(CPUPPCState
*env
, uint32_t val
)
1083 /* NaN are not treated the same way IEEE 754 does */
1084 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1087 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1088 u
.f
= float32_mul(u
.f
, tmp
, &env
->vec_status
);
1090 return float32_to_int32(u
.f
, &env
->vec_status
);
1093 static inline uint32_t efsctuf(CPUPPCState
*env
, uint32_t val
)
1099 /* NaN are not treated the same way IEEE 754 does */
1100 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1103 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1104 u
.f
= float32_mul(u
.f
, tmp
, &env
->vec_status
);
1106 return float32_to_uint32(u
.f
, &env
->vec_status
);
1109 #define HELPER_SPE_SINGLE_CONV(name) \
1110 uint32_t helper_e##name(CPUPPCState *env, uint32_t val) \
1112 return e##name(env, val); \
1115 HELPER_SPE_SINGLE_CONV(fscfsi
);
1117 HELPER_SPE_SINGLE_CONV(fscfui
);
1119 HELPER_SPE_SINGLE_CONV(fscfuf
);
1121 HELPER_SPE_SINGLE_CONV(fscfsf
);
1123 HELPER_SPE_SINGLE_CONV(fsctsi
);
1125 HELPER_SPE_SINGLE_CONV(fsctui
);
1127 HELPER_SPE_SINGLE_CONV(fsctsiz
);
1129 HELPER_SPE_SINGLE_CONV(fsctuiz
);
1131 HELPER_SPE_SINGLE_CONV(fsctsf
);
1133 HELPER_SPE_SINGLE_CONV(fsctuf
);
1135 #define HELPER_SPE_VECTOR_CONV(name) \
1136 uint64_t helper_ev##name(CPUPPCState *env, uint64_t val) \
1138 return ((uint64_t)e##name(env, val >> 32) << 32) | \
1139 (uint64_t)e##name(env, val); \
1142 HELPER_SPE_VECTOR_CONV(fscfsi
);
1144 HELPER_SPE_VECTOR_CONV(fscfui
);
1146 HELPER_SPE_VECTOR_CONV(fscfuf
);
1148 HELPER_SPE_VECTOR_CONV(fscfsf
);
1150 HELPER_SPE_VECTOR_CONV(fsctsi
);
1152 HELPER_SPE_VECTOR_CONV(fsctui
);
1154 HELPER_SPE_VECTOR_CONV(fsctsiz
);
1156 HELPER_SPE_VECTOR_CONV(fsctuiz
);
1158 HELPER_SPE_VECTOR_CONV(fsctsf
);
1160 HELPER_SPE_VECTOR_CONV(fsctuf
);
1162 /* Single-precision floating-point arithmetic */
1163 static inline uint32_t efsadd(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1169 u1
.f
= float32_add(u1
.f
, u2
.f
, &env
->vec_status
);
1173 static inline uint32_t efssub(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1179 u1
.f
= float32_sub(u1
.f
, u2
.f
, &env
->vec_status
);
1183 static inline uint32_t efsmul(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1189 u1
.f
= float32_mul(u1
.f
, u2
.f
, &env
->vec_status
);
1193 static inline uint32_t efsdiv(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1199 u1
.f
= float32_div(u1
.f
, u2
.f
, &env
->vec_status
);
1203 #define HELPER_SPE_SINGLE_ARITH(name) \
1204 uint32_t helper_e##name(CPUPPCState *env, uint32_t op1, uint32_t op2) \
1206 return e##name(env, op1, op2); \
1209 HELPER_SPE_SINGLE_ARITH(fsadd
);
1211 HELPER_SPE_SINGLE_ARITH(fssub
);
1213 HELPER_SPE_SINGLE_ARITH(fsmul
);
1215 HELPER_SPE_SINGLE_ARITH(fsdiv
);
1217 #define HELPER_SPE_VECTOR_ARITH(name) \
1218 uint64_t helper_ev##name(CPUPPCState *env, uint64_t op1, uint64_t op2) \
1220 return ((uint64_t)e##name(env, op1 >> 32, op2 >> 32) << 32) | \
1221 (uint64_t)e##name(env, op1, op2); \
1224 HELPER_SPE_VECTOR_ARITH(fsadd
);
1226 HELPER_SPE_VECTOR_ARITH(fssub
);
1228 HELPER_SPE_VECTOR_ARITH(fsmul
);
1230 HELPER_SPE_VECTOR_ARITH(fsdiv
);
1232 /* Single-precision floating-point comparisons */
1233 static inline uint32_t efscmplt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1239 return float32_lt(u1
.f
, u2
.f
, &env
->vec_status
) ? 4 : 0;
1242 static inline uint32_t efscmpgt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1248 return float32_le(u1
.f
, u2
.f
, &env
->vec_status
) ? 0 : 4;
1251 static inline uint32_t efscmpeq(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1257 return float32_eq(u1
.f
, u2
.f
, &env
->vec_status
) ? 4 : 0;
1260 static inline uint32_t efststlt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1262 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1263 return efscmplt(env
, op1
, op2
);
1266 static inline uint32_t efststgt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1268 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1269 return efscmpgt(env
, op1
, op2
);
1272 static inline uint32_t efststeq(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1274 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1275 return efscmpeq(env
, op1
, op2
);
1278 #define HELPER_SINGLE_SPE_CMP(name) \
1279 uint32_t helper_e##name(CPUPPCState *env, uint32_t op1, uint32_t op2) \
1281 return e##name(env, op1, op2); \
1284 HELPER_SINGLE_SPE_CMP(fststlt
);
1286 HELPER_SINGLE_SPE_CMP(fststgt
);
1288 HELPER_SINGLE_SPE_CMP(fststeq
);
1290 HELPER_SINGLE_SPE_CMP(fscmplt
);
1292 HELPER_SINGLE_SPE_CMP(fscmpgt
);
1294 HELPER_SINGLE_SPE_CMP(fscmpeq
);
1296 static inline uint32_t evcmp_merge(int t0
, int t1
)
1298 return (t0
<< 3) | (t1
<< 2) | ((t0
| t1
) << 1) | (t0
& t1
);
1301 #define HELPER_VECTOR_SPE_CMP(name) \
1302 uint32_t helper_ev##name(CPUPPCState *env, uint64_t op1, uint64_t op2) \
1304 return evcmp_merge(e##name(env, op1 >> 32, op2 >> 32), \
1305 e##name(env, op1, op2)); \
1308 HELPER_VECTOR_SPE_CMP(fststlt
);
1310 HELPER_VECTOR_SPE_CMP(fststgt
);
1312 HELPER_VECTOR_SPE_CMP(fststeq
);
1314 HELPER_VECTOR_SPE_CMP(fscmplt
);
1316 HELPER_VECTOR_SPE_CMP(fscmpgt
);
1318 HELPER_VECTOR_SPE_CMP(fscmpeq
);
1320 /* Double-precision floating-point conversion */
1321 uint64_t helper_efdcfsi(CPUPPCState
*env
, uint32_t val
)
1325 u
.d
= int32_to_float64(val
, &env
->vec_status
);
1330 uint64_t helper_efdcfsid(CPUPPCState
*env
, uint64_t val
)
1334 u
.d
= int64_to_float64(val
, &env
->vec_status
);
1339 uint64_t helper_efdcfui(CPUPPCState
*env
, uint32_t val
)
1343 u
.d
= uint32_to_float64(val
, &env
->vec_status
);
1348 uint64_t helper_efdcfuid(CPUPPCState
*env
, uint64_t val
)
1352 u
.d
= uint64_to_float64(val
, &env
->vec_status
);
1357 uint32_t helper_efdctsi(CPUPPCState
*env
, uint64_t val
)
1362 /* NaN are not treated the same way IEEE 754 does */
1363 if (unlikely(float64_is_any_nan(u
.d
))) {
1367 return float64_to_int32(u
.d
, &env
->vec_status
);
1370 uint32_t helper_efdctui(CPUPPCState
*env
, uint64_t val
)
1375 /* NaN are not treated the same way IEEE 754 does */
1376 if (unlikely(float64_is_any_nan(u
.d
))) {
1380 return float64_to_uint32(u
.d
, &env
->vec_status
);
1383 uint32_t helper_efdctsiz(CPUPPCState
*env
, uint64_t val
)
1388 /* NaN are not treated the same way IEEE 754 does */
1389 if (unlikely(float64_is_any_nan(u
.d
))) {
1393 return float64_to_int32_round_to_zero(u
.d
, &env
->vec_status
);
1396 uint64_t helper_efdctsidz(CPUPPCState
*env
, uint64_t val
)
1401 /* NaN are not treated the same way IEEE 754 does */
1402 if (unlikely(float64_is_any_nan(u
.d
))) {
1406 return float64_to_int64_round_to_zero(u
.d
, &env
->vec_status
);
1409 uint32_t helper_efdctuiz(CPUPPCState
*env
, uint64_t val
)
1414 /* NaN are not treated the same way IEEE 754 does */
1415 if (unlikely(float64_is_any_nan(u
.d
))) {
1419 return float64_to_uint32_round_to_zero(u
.d
, &env
->vec_status
);
1422 uint64_t helper_efdctuidz(CPUPPCState
*env
, uint64_t val
)
1427 /* NaN are not treated the same way IEEE 754 does */
1428 if (unlikely(float64_is_any_nan(u
.d
))) {
1432 return float64_to_uint64_round_to_zero(u
.d
, &env
->vec_status
);
1435 uint64_t helper_efdcfsf(CPUPPCState
*env
, uint32_t val
)
1440 u
.d
= int32_to_float64(val
, &env
->vec_status
);
1441 tmp
= int64_to_float64(1ULL << 32, &env
->vec_status
);
1442 u
.d
= float64_div(u
.d
, tmp
, &env
->vec_status
);
1447 uint64_t helper_efdcfuf(CPUPPCState
*env
, uint32_t val
)
1452 u
.d
= uint32_to_float64(val
, &env
->vec_status
);
1453 tmp
= int64_to_float64(1ULL << 32, &env
->vec_status
);
1454 u
.d
= float64_div(u
.d
, tmp
, &env
->vec_status
);
1459 uint32_t helper_efdctsf(CPUPPCState
*env
, uint64_t val
)
1465 /* NaN are not treated the same way IEEE 754 does */
1466 if (unlikely(float64_is_any_nan(u
.d
))) {
1469 tmp
= uint64_to_float64(1ULL << 32, &env
->vec_status
);
1470 u
.d
= float64_mul(u
.d
, tmp
, &env
->vec_status
);
1472 return float64_to_int32(u
.d
, &env
->vec_status
);
1475 uint32_t helper_efdctuf(CPUPPCState
*env
, uint64_t val
)
1481 /* NaN are not treated the same way IEEE 754 does */
1482 if (unlikely(float64_is_any_nan(u
.d
))) {
1485 tmp
= uint64_to_float64(1ULL << 32, &env
->vec_status
);
1486 u
.d
= float64_mul(u
.d
, tmp
, &env
->vec_status
);
1488 return float64_to_uint32(u
.d
, &env
->vec_status
);
1491 uint32_t helper_efscfd(CPUPPCState
*env
, uint64_t val
)
1497 u2
.f
= float64_to_float32(u1
.d
, &env
->vec_status
);
1502 uint64_t helper_efdcfs(CPUPPCState
*env
, uint32_t val
)
1508 u2
.d
= float32_to_float64(u1
.f
, &env
->vec_status
);
1513 /* Double precision fixed-point arithmetic */
1514 uint64_t helper_efdadd(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1520 u1
.d
= float64_add(u1
.d
, u2
.d
, &env
->vec_status
);
1524 uint64_t helper_efdsub(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1530 u1
.d
= float64_sub(u1
.d
, u2
.d
, &env
->vec_status
);
1534 uint64_t helper_efdmul(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1540 u1
.d
= float64_mul(u1
.d
, u2
.d
, &env
->vec_status
);
1544 uint64_t helper_efddiv(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1550 u1
.d
= float64_div(u1
.d
, u2
.d
, &env
->vec_status
);
1554 /* Double precision floating point helpers */
1555 uint32_t helper_efdtstlt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1561 return float64_lt(u1
.d
, u2
.d
, &env
->vec_status
) ? 4 : 0;
1564 uint32_t helper_efdtstgt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1570 return float64_le(u1
.d
, u2
.d
, &env
->vec_status
) ? 0 : 4;
1573 uint32_t helper_efdtsteq(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1579 return float64_eq_quiet(u1
.d
, u2
.d
, &env
->vec_status
) ? 4 : 0;
1582 uint32_t helper_efdcmplt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1584 /* XXX: TODO: test special values (NaN, infinites, ...) */
1585 return helper_efdtstlt(env
, op1
, op2
);
1588 uint32_t helper_efdcmpgt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1590 /* XXX: TODO: test special values (NaN, infinites, ...) */
1591 return helper_efdtstgt(env
, op1
, op2
);
1594 uint32_t helper_efdcmpeq(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1596 /* XXX: TODO: test special values (NaN, infinites, ...) */
1597 return helper_efdtsteq(env
, op1
, op2
);
1600 #define float64_to_float64(x, env) x
1604 * VSX_ADD_SUB - VSX floating point add/subtract
1605 * name - instruction mnemonic
1606 * op - operation (add or sub)
1607 * nels - number of elements (1, 2 or 4)
1608 * tp - type (float32 or float64)
1609 * fld - vsr_t field (VsrD(*) or VsrW(*))
1612 #define VSX_ADD_SUB(name, op, nels, tp, fld, sfprf, r2sp) \
1613 void helper_##name(CPUPPCState *env, ppc_vsr_t *xt, \
1614 ppc_vsr_t *xa, ppc_vsr_t *xb) \
1616 ppc_vsr_t t = *xt; \
1619 helper_reset_fpstatus(env); \
1621 for (i = 0; i < nels; i++) { \
1622 float_status tstat = env->fp_status; \
1623 set_float_exception_flags(0, &tstat); \
1624 t.fld = tp##_##op(xa->fld, xb->fld, &tstat); \
1625 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1627 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1628 float_invalid_op_addsub(env, tstat.float_exception_flags, \
1633 t.fld = do_frsp(env, t.fld, GETPC()); \
1637 helper_compute_fprf_float64(env, t.fld); \
1641 do_float_check_status(env, GETPC()); \
1644 VSX_ADD_SUB(xsadddp
, add
, 1, float64
, VsrD(0), 1, 0)
1645 VSX_ADD_SUB(xsaddsp
, add
, 1, float64
, VsrD(0), 1, 1)
1646 VSX_ADD_SUB(xvadddp
, add
, 2, float64
, VsrD(i
), 0, 0)
1647 VSX_ADD_SUB(xvaddsp
, add
, 4, float32
, VsrW(i
), 0, 0)
1648 VSX_ADD_SUB(xssubdp
, sub
, 1, float64
, VsrD(0), 1, 0)
1649 VSX_ADD_SUB(xssubsp
, sub
, 1, float64
, VsrD(0), 1, 1)
1650 VSX_ADD_SUB(xvsubdp
, sub
, 2, float64
, VsrD(i
), 0, 0)
1651 VSX_ADD_SUB(xvsubsp
, sub
, 4, float32
, VsrW(i
), 0, 0)
1653 void helper_xsaddqp(CPUPPCState
*env
, uint32_t opcode
,
1654 ppc_vsr_t
*xt
, ppc_vsr_t
*xa
, ppc_vsr_t
*xb
)
1659 helper_reset_fpstatus(env
);
1661 tstat
= env
->fp_status
;
1662 if (unlikely(Rc(opcode
) != 0)) {
1663 tstat
.float_rounding_mode
= float_round_to_odd
;
1666 set_float_exception_flags(0, &tstat
);
1667 t
.f128
= float128_add(xa
->f128
, xb
->f128
, &tstat
);
1668 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
1670 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
1671 float_invalid_op_addsub(env
, tstat
.float_exception_flags
, 1, GETPC());
1674 helper_compute_fprf_float128(env
, t
.f128
);
1677 do_float_check_status(env
, GETPC());
1681 * VSX_MUL - VSX floating point multiply
1682 * op - instruction mnemonic
1683 * nels - number of elements (1, 2 or 4)
1684 * tp - type (float32 or float64)
1685 * fld - vsr_t field (VsrD(*) or VsrW(*))
1688 #define VSX_MUL(op, nels, tp, fld, sfprf, r2sp) \
1689 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
1690 ppc_vsr_t *xa, ppc_vsr_t *xb) \
1692 ppc_vsr_t t = *xt; \
1695 helper_reset_fpstatus(env); \
1697 for (i = 0; i < nels; i++) { \
1698 float_status tstat = env->fp_status; \
1699 set_float_exception_flags(0, &tstat); \
1700 t.fld = tp##_mul(xa->fld, xb->fld, &tstat); \
1701 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1703 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1704 float_invalid_op_mul(env, tstat.float_exception_flags, \
1709 t.fld = do_frsp(env, t.fld, GETPC()); \
1713 helper_compute_fprf_float64(env, t.fld); \
1718 do_float_check_status(env, GETPC()); \
1721 VSX_MUL(xsmuldp
, 1, float64
, VsrD(0), 1, 0)
1722 VSX_MUL(xsmulsp
, 1, float64
, VsrD(0), 1, 1)
1723 VSX_MUL(xvmuldp
, 2, float64
, VsrD(i
), 0, 0)
1724 VSX_MUL(xvmulsp
, 4, float32
, VsrW(i
), 0, 0)
1726 void helper_xsmulqp(CPUPPCState
*env
, uint32_t opcode
,
1727 ppc_vsr_t
*xt
, ppc_vsr_t
*xa
, ppc_vsr_t
*xb
)
1732 helper_reset_fpstatus(env
);
1733 tstat
= env
->fp_status
;
1734 if (unlikely(Rc(opcode
) != 0)) {
1735 tstat
.float_rounding_mode
= float_round_to_odd
;
1738 set_float_exception_flags(0, &tstat
);
1739 t
.f128
= float128_mul(xa
->f128
, xb
->f128
, &tstat
);
1740 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
1742 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
1743 float_invalid_op_mul(env
, tstat
.float_exception_flags
, 1, GETPC());
1745 helper_compute_fprf_float128(env
, t
.f128
);
1748 do_float_check_status(env
, GETPC());
1752 * VSX_DIV - VSX floating point divide
1753 * op - instruction mnemonic
1754 * nels - number of elements (1, 2 or 4)
1755 * tp - type (float32 or float64)
1756 * fld - vsr_t field (VsrD(*) or VsrW(*))
1759 #define VSX_DIV(op, nels, tp, fld, sfprf, r2sp) \
1760 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
1761 ppc_vsr_t *xa, ppc_vsr_t *xb) \
1763 ppc_vsr_t t = *xt; \
1766 helper_reset_fpstatus(env); \
1768 for (i = 0; i < nels; i++) { \
1769 float_status tstat = env->fp_status; \
1770 set_float_exception_flags(0, &tstat); \
1771 t.fld = tp##_div(xa->fld, xb->fld, &tstat); \
1772 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1774 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1775 float_invalid_op_div(env, tstat.float_exception_flags, \
1778 if (unlikely(tstat.float_exception_flags & float_flag_divbyzero)) { \
1779 float_zero_divide_excp(env, GETPC()); \
1783 t.fld = do_frsp(env, t.fld, GETPC()); \
1787 helper_compute_fprf_float64(env, t.fld); \
1792 do_float_check_status(env, GETPC()); \
1795 VSX_DIV(xsdivdp
, 1, float64
, VsrD(0), 1, 0)
1796 VSX_DIV(xsdivsp
, 1, float64
, VsrD(0), 1, 1)
1797 VSX_DIV(xvdivdp
, 2, float64
, VsrD(i
), 0, 0)
1798 VSX_DIV(xvdivsp
, 4, float32
, VsrW(i
), 0, 0)
1800 void helper_xsdivqp(CPUPPCState
*env
, uint32_t opcode
,
1801 ppc_vsr_t
*xt
, ppc_vsr_t
*xa
, ppc_vsr_t
*xb
)
1806 helper_reset_fpstatus(env
);
1807 tstat
= env
->fp_status
;
1808 if (unlikely(Rc(opcode
) != 0)) {
1809 tstat
.float_rounding_mode
= float_round_to_odd
;
1812 set_float_exception_flags(0, &tstat
);
1813 t
.f128
= float128_div(xa
->f128
, xb
->f128
, &tstat
);
1814 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
1816 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
1817 float_invalid_op_div(env
, tstat
.float_exception_flags
, 1, GETPC());
1819 if (unlikely(tstat
.float_exception_flags
& float_flag_divbyzero
)) {
1820 float_zero_divide_excp(env
, GETPC());
1823 helper_compute_fprf_float128(env
, t
.f128
);
1825 do_float_check_status(env
, GETPC());
1829 * VSX_RE - VSX floating point reciprocal estimate
1830 * op - instruction mnemonic
1831 * nels - number of elements (1, 2 or 4)
1832 * tp - type (float32 or float64)
1833 * fld - vsr_t field (VsrD(*) or VsrW(*))
1836 #define VSX_RE(op, nels, tp, fld, sfprf, r2sp) \
1837 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
1839 ppc_vsr_t t = *xt; \
1842 helper_reset_fpstatus(env); \
1844 for (i = 0; i < nels; i++) { \
1845 if (unlikely(tp##_is_signaling_nan(xb->fld, &env->fp_status))) { \
1846 float_invalid_op_vxsnan(env, GETPC()); \
1848 t.fld = tp##_div(tp##_one, xb->fld, &env->fp_status); \
1851 t.fld = do_frsp(env, t.fld, GETPC()); \
1855 helper_compute_fprf_float64(env, t.fld); \
1860 do_float_check_status(env, GETPC()); \
1863 VSX_RE(xsredp
, 1, float64
, VsrD(0), 1, 0)
1864 VSX_RE(xsresp
, 1, float64
, VsrD(0), 1, 1)
1865 VSX_RE(xvredp
, 2, float64
, VsrD(i
), 0, 0)
1866 VSX_RE(xvresp
, 4, float32
, VsrW(i
), 0, 0)
1869 * VSX_SQRT - VSX floating point square root
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_SQRT(op, nels, tp, fld, sfprf, r2sp) \
1877 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
1879 ppc_vsr_t t = *xt; \
1882 helper_reset_fpstatus(env); \
1884 for (i = 0; i < nels; i++) { \
1885 float_status tstat = env->fp_status; \
1886 set_float_exception_flags(0, &tstat); \
1887 t.fld = tp##_sqrt(xb->fld, &tstat); \
1888 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1890 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1891 float_invalid_op_sqrt(env, tstat.float_exception_flags, \
1896 t.fld = do_frsp(env, t.fld, GETPC()); \
1900 helper_compute_fprf_float64(env, t.fld); \
1905 do_float_check_status(env, GETPC()); \
1908 VSX_SQRT(xssqrtdp
, 1, float64
, VsrD(0), 1, 0)
1909 VSX_SQRT(xssqrtsp
, 1, float64
, VsrD(0), 1, 1)
1910 VSX_SQRT(xvsqrtdp
, 2, float64
, VsrD(i
), 0, 0)
1911 VSX_SQRT(xvsqrtsp
, 4, float32
, VsrW(i
), 0, 0)
1914 *VSX_RSQRTE - VSX floating point reciprocal square root estimate
1915 * op - instruction mnemonic
1916 * nels - number of elements (1, 2 or 4)
1917 * tp - type (float32 or float64)
1918 * fld - vsr_t field (VsrD(*) or VsrW(*))
1921 #define VSX_RSQRTE(op, nels, tp, fld, sfprf, r2sp) \
1922 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
1924 ppc_vsr_t t = *xt; \
1927 helper_reset_fpstatus(env); \
1929 for (i = 0; i < nels; i++) { \
1930 float_status tstat = env->fp_status; \
1931 set_float_exception_flags(0, &tstat); \
1932 t.fld = tp##_sqrt(xb->fld, &tstat); \
1933 t.fld = tp##_div(tp##_one, t.fld, &tstat); \
1934 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1935 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1936 float_invalid_op_sqrt(env, tstat.float_exception_flags, \
1940 t.fld = do_frsp(env, t.fld, GETPC()); \
1944 helper_compute_fprf_float64(env, t.fld); \
1949 do_float_check_status(env, GETPC()); \
1952 VSX_RSQRTE(xsrsqrtedp
, 1, float64
, VsrD(0), 1, 0)
1953 VSX_RSQRTE(xsrsqrtesp
, 1, float64
, VsrD(0), 1, 1)
1954 VSX_RSQRTE(xvrsqrtedp
, 2, float64
, VsrD(i
), 0, 0)
1955 VSX_RSQRTE(xvrsqrtesp
, 4, float32
, VsrW(i
), 0, 0)
1958 * VSX_TDIV - VSX floating point test for divide
1959 * op - instruction mnemonic
1960 * nels - number of elements (1, 2 or 4)
1961 * tp - type (float32 or float64)
1962 * fld - vsr_t field (VsrD(*) or VsrW(*))
1963 * emin - minimum unbiased exponent
1964 * emax - maximum unbiased exponent
1965 * nbits - number of fraction bits
1967 #define VSX_TDIV(op, nels, tp, fld, emin, emax, nbits) \
1968 void helper_##op(CPUPPCState *env, uint32_t opcode, \
1969 ppc_vsr_t *xa, ppc_vsr_t *xb) \
1975 for (i = 0; i < nels; i++) { \
1976 if (unlikely(tp##_is_infinity(xa->fld) || \
1977 tp##_is_infinity(xb->fld) || \
1978 tp##_is_zero(xb->fld))) { \
1982 int e_a = ppc_##tp##_get_unbiased_exp(xa->fld); \
1983 int e_b = ppc_##tp##_get_unbiased_exp(xb->fld); \
1985 if (unlikely(tp##_is_any_nan(xa->fld) || \
1986 tp##_is_any_nan(xb->fld))) { \
1988 } else if ((e_b <= emin) || (e_b >= (emax - 2))) { \
1990 } else if (!tp##_is_zero(xa->fld) && \
1991 (((e_a - e_b) >= emax) || \
1992 ((e_a - e_b) <= (emin + 1)) || \
1993 (e_a <= (emin + nbits)))) { \
1997 if (unlikely(tp##_is_zero_or_denormal(xb->fld))) { \
1999 * XB is not zero because of the above check and so \
2000 * must be denormalized. \
2007 env->crf[BF(opcode)] = 0x8 | (fg_flag ? 4 : 0) | (fe_flag ? 2 : 0); \
2010 VSX_TDIV(xstdivdp
, 1, float64
, VsrD(0), -1022, 1023, 52)
2011 VSX_TDIV(xvtdivdp
, 2, float64
, VsrD(i
), -1022, 1023, 52)
2012 VSX_TDIV(xvtdivsp
, 4, float32
, VsrW(i
), -126, 127, 23)
2015 * VSX_TSQRT - VSX floating point test for square root
2016 * op - instruction mnemonic
2017 * nels - number of elements (1, 2 or 4)
2018 * tp - type (float32 or float64)
2019 * fld - vsr_t field (VsrD(*) or VsrW(*))
2020 * emin - minimum unbiased exponent
2021 * emax - maximum unbiased exponent
2022 * nbits - number of fraction bits
2024 #define VSX_TSQRT(op, nels, tp, fld, emin, nbits) \
2025 void helper_##op(CPUPPCState *env, uint32_t opcode, ppc_vsr_t *xb) \
2031 for (i = 0; i < nels; i++) { \
2032 if (unlikely(tp##_is_infinity(xb->fld) || \
2033 tp##_is_zero(xb->fld))) { \
2037 int e_b = ppc_##tp##_get_unbiased_exp(xb->fld); \
2039 if (unlikely(tp##_is_any_nan(xb->fld))) { \
2041 } else if (unlikely(tp##_is_zero(xb->fld))) { \
2043 } else if (unlikely(tp##_is_neg(xb->fld))) { \
2045 } else if (!tp##_is_zero(xb->fld) && \
2046 (e_b <= (emin + nbits))) { \
2050 if (unlikely(tp##_is_zero_or_denormal(xb->fld))) { \
2052 * XB is not zero because of the above check and \
2053 * therefore must be denormalized. \
2060 env->crf[BF(opcode)] = 0x8 | (fg_flag ? 4 : 0) | (fe_flag ? 2 : 0); \
2063 VSX_TSQRT(xstsqrtdp
, 1, float64
, VsrD(0), -1022, 52)
2064 VSX_TSQRT(xvtsqrtdp
, 2, float64
, VsrD(i
), -1022, 52)
2065 VSX_TSQRT(xvtsqrtsp
, 4, float32
, VsrW(i
), -126, 23)
2068 * VSX_MADD - VSX floating point muliply/add variations
2069 * op - instruction mnemonic
2070 * nels - number of elements (1, 2 or 4)
2071 * tp - type (float32 or float64)
2072 * fld - vsr_t field (VsrD(*) or VsrW(*))
2073 * maddflgs - flags for the float*muladd routine that control the
2074 * various forms (madd, msub, nmadd, nmsub)
2077 #define VSX_MADD(op, nels, tp, fld, maddflgs, sfprf, r2sp) \
2078 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
2079 ppc_vsr_t *xa, ppc_vsr_t *b, ppc_vsr_t *c) \
2081 ppc_vsr_t t = *xt; \
2084 helper_reset_fpstatus(env); \
2086 for (i = 0; i < nels; i++) { \
2087 float_status tstat = env->fp_status; \
2088 set_float_exception_flags(0, &tstat); \
2089 if (r2sp && (tstat.float_rounding_mode == float_round_nearest_even)) {\
2091 * Avoid double rounding errors by rounding the intermediate \
2094 set_float_rounding_mode(float_round_to_zero, &tstat); \
2095 t.fld = tp##_muladd(xa->fld, b->fld, c->fld, \
2096 maddflgs, &tstat); \
2097 t.fld |= (get_float_exception_flags(&tstat) & \
2098 float_flag_inexact) != 0; \
2100 t.fld = tp##_muladd(xa->fld, b->fld, c->fld, \
2101 maddflgs, &tstat); \
2103 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
2105 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
2106 float_invalid_op_madd(env, tstat.float_exception_flags, \
2111 t.fld = do_frsp(env, t.fld, GETPC()); \
2115 helper_compute_fprf_float64(env, t.fld); \
2119 do_float_check_status(env, GETPC()); \
2122 VSX_MADD(xsmadddp
, 1, float64
, VsrD(0), MADD_FLGS
, 1, 0)
2123 VSX_MADD(xsmsubdp
, 1, float64
, VsrD(0), MSUB_FLGS
, 1, 0)
2124 VSX_MADD(xsnmadddp
, 1, float64
, VsrD(0), NMADD_FLGS
, 1, 0)
2125 VSX_MADD(xsnmsubdp
, 1, float64
, VsrD(0), NMSUB_FLGS
, 1, 0)
2126 VSX_MADD(xsmaddsp
, 1, float64
, VsrD(0), MADD_FLGS
, 1, 1)
2127 VSX_MADD(xsmsubsp
, 1, float64
, VsrD(0), MSUB_FLGS
, 1, 1)
2128 VSX_MADD(xsnmaddsp
, 1, float64
, VsrD(0), NMADD_FLGS
, 1, 1)
2129 VSX_MADD(xsnmsubsp
, 1, float64
, VsrD(0), NMSUB_FLGS
, 1, 1)
2131 VSX_MADD(xvmadddp
, 2, float64
, VsrD(i
), MADD_FLGS
, 0, 0)
2132 VSX_MADD(xvmsubdp
, 2, float64
, VsrD(i
), MSUB_FLGS
, 0, 0)
2133 VSX_MADD(xvnmadddp
, 2, float64
, VsrD(i
), NMADD_FLGS
, 0, 0)
2134 VSX_MADD(xvnmsubdp
, 2, float64
, VsrD(i
), NMSUB_FLGS
, 0, 0)
2136 VSX_MADD(xvmaddsp
, 4, float32
, VsrW(i
), MADD_FLGS
, 0, 0)
2137 VSX_MADD(xvmsubsp
, 4, float32
, VsrW(i
), MSUB_FLGS
, 0, 0)
2138 VSX_MADD(xvnmaddsp
, 4, float32
, VsrW(i
), NMADD_FLGS
, 0, 0)
2139 VSX_MADD(xvnmsubsp
, 4, float32
, VsrW(i
), NMSUB_FLGS
, 0, 0)
2142 * VSX_SCALAR_CMP_DP - VSX scalar floating point compare double precision
2143 * op - instruction mnemonic
2144 * cmp - comparison operation
2145 * exp - expected result of comparison
2146 * svxvc - set VXVC bit
2148 #define VSX_SCALAR_CMP_DP(op, cmp, exp, svxvc) \
2149 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
2150 ppc_vsr_t *xa, ppc_vsr_t *xb) \
2152 ppc_vsr_t t = *xt; \
2153 bool vxsnan_flag = false, vxvc_flag = false, vex_flag = false; \
2155 if (float64_is_signaling_nan(xa->VsrD(0), &env->fp_status) || \
2156 float64_is_signaling_nan(xb->VsrD(0), &env->fp_status)) { \
2157 vxsnan_flag = true; \
2158 if (fpscr_ve == 0 && svxvc) { \
2161 } else if (svxvc) { \
2162 vxvc_flag = float64_is_quiet_nan(xa->VsrD(0), &env->fp_status) || \
2163 float64_is_quiet_nan(xb->VsrD(0), &env->fp_status); \
2165 if (vxsnan_flag) { \
2166 float_invalid_op_vxsnan(env, GETPC()); \
2169 float_invalid_op_vxvc(env, 0, GETPC()); \
2171 vex_flag = fpscr_ve && (vxvc_flag || vxsnan_flag); \
2174 if (float64_##cmp(xb->VsrD(0), xa->VsrD(0), \
2175 &env->fp_status) == exp) { \
2184 do_float_check_status(env, GETPC()); \
2187 VSX_SCALAR_CMP_DP(xscmpeqdp
, eq
, 1, 0)
2188 VSX_SCALAR_CMP_DP(xscmpgedp
, le
, 1, 1)
2189 VSX_SCALAR_CMP_DP(xscmpgtdp
, lt
, 1, 1)
2190 VSX_SCALAR_CMP_DP(xscmpnedp
, eq
, 0, 0)
2192 void helper_xscmpexpdp(CPUPPCState
*env
, uint32_t opcode
,
2193 ppc_vsr_t
*xa
, ppc_vsr_t
*xb
)
2195 int64_t exp_a
, exp_b
;
2198 exp_a
= extract64(xa
->VsrD(0), 52, 11);
2199 exp_b
= extract64(xb
->VsrD(0), 52, 11);
2201 if (unlikely(float64_is_any_nan(xa
->VsrD(0)) ||
2202 float64_is_any_nan(xb
->VsrD(0)))) {
2205 if (exp_a
< exp_b
) {
2207 } else if (exp_a
> exp_b
) {
2214 env
->fpscr
&= ~FP_FPCC
;
2215 env
->fpscr
|= cc
<< FPSCR_FPCC
;
2216 env
->crf
[BF(opcode
)] = cc
;
2218 do_float_check_status(env
, GETPC());
2221 void helper_xscmpexpqp(CPUPPCState
*env
, uint32_t opcode
,
2222 ppc_vsr_t
*xa
, ppc_vsr_t
*xb
)
2224 int64_t exp_a
, exp_b
;
2227 exp_a
= extract64(xa
->VsrD(0), 48, 15);
2228 exp_b
= extract64(xb
->VsrD(0), 48, 15);
2230 if (unlikely(float128_is_any_nan(xa
->f128
) ||
2231 float128_is_any_nan(xb
->f128
))) {
2234 if (exp_a
< exp_b
) {
2236 } else if (exp_a
> exp_b
) {
2243 env
->fpscr
&= ~FP_FPCC
;
2244 env
->fpscr
|= cc
<< FPSCR_FPCC
;
2245 env
->crf
[BF(opcode
)] = cc
;
2247 do_float_check_status(env
, GETPC());
2250 static inline void do_scalar_cmp(CPUPPCState
*env
, ppc_vsr_t
*xa
, ppc_vsr_t
*xb
,
2251 int crf_idx
, bool ordered
)
2254 bool vxsnan_flag
= false, vxvc_flag
= false;
2256 helper_reset_fpstatus(env
);
2258 switch (float64_compare(xa
->VsrD(0), xb
->VsrD(0), &env
->fp_status
)) {
2259 case float_relation_less
:
2262 case float_relation_equal
:
2265 case float_relation_greater
:
2268 case float_relation_unordered
:
2271 if (float64_is_signaling_nan(xa
->VsrD(0), &env
->fp_status
) ||
2272 float64_is_signaling_nan(xb
->VsrD(0), &env
->fp_status
)) {
2274 if (fpscr_ve
== 0 && ordered
) {
2277 } else if (float64_is_quiet_nan(xa
->VsrD(0), &env
->fp_status
) ||
2278 float64_is_quiet_nan(xb
->VsrD(0), &env
->fp_status
)) {
2286 g_assert_not_reached();
2289 env
->fpscr
&= ~FP_FPCC
;
2290 env
->fpscr
|= cc
<< FPSCR_FPCC
;
2291 env
->crf
[crf_idx
] = cc
;
2294 float_invalid_op_vxsnan(env
, GETPC());
2297 float_invalid_op_vxvc(env
, 0, GETPC());
2300 do_float_check_status(env
, GETPC());
2303 void helper_xscmpodp(CPUPPCState
*env
, uint32_t opcode
, ppc_vsr_t
*xa
,
2306 do_scalar_cmp(env
, xa
, xb
, BF(opcode
), true);
2309 void helper_xscmpudp(CPUPPCState
*env
, uint32_t opcode
, ppc_vsr_t
*xa
,
2312 do_scalar_cmp(env
, xa
, xb
, BF(opcode
), false);
2315 static inline void do_scalar_cmpq(CPUPPCState
*env
, ppc_vsr_t
*xa
,
2316 ppc_vsr_t
*xb
, int crf_idx
, bool ordered
)
2319 bool vxsnan_flag
= false, vxvc_flag
= false;
2321 helper_reset_fpstatus(env
);
2323 switch (float128_compare(xa
->f128
, xb
->f128
, &env
->fp_status
)) {
2324 case float_relation_less
:
2327 case float_relation_equal
:
2330 case float_relation_greater
:
2333 case float_relation_unordered
:
2336 if (float128_is_signaling_nan(xa
->f128
, &env
->fp_status
) ||
2337 float128_is_signaling_nan(xb
->f128
, &env
->fp_status
)) {
2339 if (fpscr_ve
== 0 && ordered
) {
2342 } else if (float128_is_quiet_nan(xa
->f128
, &env
->fp_status
) ||
2343 float128_is_quiet_nan(xb
->f128
, &env
->fp_status
)) {
2351 g_assert_not_reached();
2354 env
->fpscr
&= ~FP_FPCC
;
2355 env
->fpscr
|= cc
<< FPSCR_FPCC
;
2356 env
->crf
[crf_idx
] = cc
;
2359 float_invalid_op_vxsnan(env
, GETPC());
2362 float_invalid_op_vxvc(env
, 0, GETPC());
2365 do_float_check_status(env
, GETPC());
2368 void helper_xscmpoqp(CPUPPCState
*env
, uint32_t opcode
, ppc_vsr_t
*xa
,
2371 do_scalar_cmpq(env
, xa
, xb
, BF(opcode
), true);
2374 void helper_xscmpuqp(CPUPPCState
*env
, uint32_t opcode
, ppc_vsr_t
*xa
,
2377 do_scalar_cmpq(env
, xa
, xb
, BF(opcode
), false);
2381 * VSX_MAX_MIN - VSX floating point maximum/minimum
2382 * name - instruction mnemonic
2383 * op - operation (max or min)
2384 * nels - number of elements (1, 2 or 4)
2385 * tp - type (float32 or float64)
2386 * fld - vsr_t field (VsrD(*) or VsrW(*))
2388 #define VSX_MAX_MIN(name, op, nels, tp, fld) \
2389 void helper_##name(CPUPPCState *env, ppc_vsr_t *xt, \
2390 ppc_vsr_t *xa, ppc_vsr_t *xb) \
2392 ppc_vsr_t t = *xt; \
2395 for (i = 0; i < nels; i++) { \
2396 t.fld = tp##_##op(xa->fld, xb->fld, &env->fp_status); \
2397 if (unlikely(tp##_is_signaling_nan(xa->fld, &env->fp_status) || \
2398 tp##_is_signaling_nan(xb->fld, &env->fp_status))) { \
2399 float_invalid_op_vxsnan(env, GETPC()); \
2404 do_float_check_status(env, GETPC()); \
2407 VSX_MAX_MIN(xsmaxdp
, maxnum
, 1, float64
, VsrD(0))
2408 VSX_MAX_MIN(xvmaxdp
, maxnum
, 2, float64
, VsrD(i
))
2409 VSX_MAX_MIN(xvmaxsp
, maxnum
, 4, float32
, VsrW(i
))
2410 VSX_MAX_MIN(xsmindp
, minnum
, 1, float64
, VsrD(0))
2411 VSX_MAX_MIN(xvmindp
, minnum
, 2, float64
, VsrD(i
))
2412 VSX_MAX_MIN(xvminsp
, minnum
, 4, float32
, VsrW(i
))
2414 #define VSX_MAX_MINC(name, max) \
2415 void helper_##name(CPUPPCState *env, uint32_t opcode, \
2416 ppc_vsr_t *xt, ppc_vsr_t *xa, ppc_vsr_t *xb) \
2418 ppc_vsr_t t = *xt; \
2419 bool vxsnan_flag = false, vex_flag = false; \
2421 if (unlikely(float64_is_any_nan(xa->VsrD(0)) || \
2422 float64_is_any_nan(xb->VsrD(0)))) { \
2423 if (float64_is_signaling_nan(xa->VsrD(0), &env->fp_status) || \
2424 float64_is_signaling_nan(xb->VsrD(0), &env->fp_status)) { \
2425 vxsnan_flag = true; \
2427 t.VsrD(0) = xb->VsrD(0); \
2428 } else if ((max && \
2429 !float64_lt(xa->VsrD(0), xb->VsrD(0), &env->fp_status)) || \
2431 float64_lt(xa->VsrD(0), xb->VsrD(0), &env->fp_status))) { \
2432 t.VsrD(0) = xa->VsrD(0); \
2434 t.VsrD(0) = xb->VsrD(0); \
2437 vex_flag = fpscr_ve & vxsnan_flag; \
2438 if (vxsnan_flag) { \
2439 float_invalid_op_vxsnan(env, GETPC()); \
2446 VSX_MAX_MINC(xsmaxcdp, 1);
2447 VSX_MAX_MINC(xsmincdp
, 0);
2449 #define VSX_MAX_MINJ(name, max) \
2450 void helper_##name(CPUPPCState *env, uint32_t opcode, \
2451 ppc_vsr_t *xt, ppc_vsr_t *xa, ppc_vsr_t *xb) \
2453 ppc_vsr_t t = *xt; \
2454 bool vxsnan_flag = false, vex_flag = false; \
2456 if (unlikely(float64_is_any_nan(xa->VsrD(0)))) { \
2457 if (float64_is_signaling_nan(xa->VsrD(0), &env->fp_status)) { \
2458 vxsnan_flag = true; \
2460 t.VsrD(0) = xa->VsrD(0); \
2461 } else if (unlikely(float64_is_any_nan(xb->VsrD(0)))) { \
2462 if (float64_is_signaling_nan(xb->VsrD(0), &env->fp_status)) { \
2463 vxsnan_flag = true; \
2465 t.VsrD(0) = xb->VsrD(0); \
2466 } else if (float64_is_zero(xa->VsrD(0)) && \
2467 float64_is_zero(xb->VsrD(0))) { \
2469 if (!float64_is_neg(xa->VsrD(0)) || \
2470 !float64_is_neg(xb->VsrD(0))) { \
2473 t.VsrD(0) = 0x8000000000000000ULL; \
2476 if (float64_is_neg(xa->VsrD(0)) || \
2477 float64_is_neg(xb->VsrD(0))) { \
2478 t.VsrD(0) = 0x8000000000000000ULL; \
2483 } else if ((max && \
2484 !float64_lt(xa->VsrD(0), xb->VsrD(0), &env->fp_status)) || \
2486 float64_lt(xa->VsrD(0), xb->VsrD(0), &env->fp_status))) { \
2487 t.VsrD(0) = xa->VsrD(0); \
2489 t.VsrD(0) = xb->VsrD(0); \
2492 vex_flag = fpscr_ve & vxsnan_flag; \
2493 if (vxsnan_flag) { \
2494 float_invalid_op_vxsnan(env, GETPC()); \
2501 VSX_MAX_MINJ(xsmaxjdp, 1);
2502 VSX_MAX_MINJ(xsminjdp
, 0);
2505 * VSX_CMP - VSX floating point compare
2506 * op - instruction mnemonic
2507 * nels - number of elements (1, 2 or 4)
2508 * tp - type (float32 or float64)
2509 * fld - vsr_t field (VsrD(*) or VsrW(*))
2510 * cmp - comparison operation
2511 * svxvc - set VXVC bit
2512 * exp - expected result of comparison
2514 #define VSX_CMP(op, nels, tp, fld, cmp, svxvc, exp) \
2515 uint32_t helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
2516 ppc_vsr_t *xa, ppc_vsr_t *xb) \
2518 ppc_vsr_t t = *xt; \
2519 uint32_t crf6 = 0; \
2522 int all_false = 1; \
2524 for (i = 0; i < nels; i++) { \
2525 if (unlikely(tp##_is_any_nan(xa->fld) || \
2526 tp##_is_any_nan(xb->fld))) { \
2527 if (tp##_is_signaling_nan(xa->fld, &env->fp_status) || \
2528 tp##_is_signaling_nan(xb->fld, &env->fp_status)) { \
2529 float_invalid_op_vxsnan(env, GETPC()); \
2532 float_invalid_op_vxvc(env, 0, GETPC()); \
2537 if (tp##_##cmp(xb->fld, xa->fld, &env->fp_status) == exp) { \
2548 crf6 = (all_true ? 0x8 : 0) | (all_false ? 0x2 : 0); \
2552 VSX_CMP(xvcmpeqdp
, 2, float64
, VsrD(i
), eq
, 0, 1)
2553 VSX_CMP(xvcmpgedp
, 2, float64
, VsrD(i
), le
, 1, 1)
2554 VSX_CMP(xvcmpgtdp
, 2, float64
, VsrD(i
), lt
, 1, 1)
2555 VSX_CMP(xvcmpnedp
, 2, float64
, VsrD(i
), eq
, 0, 0)
2556 VSX_CMP(xvcmpeqsp
, 4, float32
, VsrW(i
), eq
, 0, 1)
2557 VSX_CMP(xvcmpgesp
, 4, float32
, VsrW(i
), le
, 1, 1)
2558 VSX_CMP(xvcmpgtsp
, 4, float32
, VsrW(i
), lt
, 1, 1)
2559 VSX_CMP(xvcmpnesp
, 4, float32
, VsrW(i
), eq
, 0, 0)
2562 * VSX_CVT_FP_TO_FP - VSX floating point/floating point conversion
2563 * op - instruction mnemonic
2564 * nels - number of elements (1, 2 or 4)
2565 * stp - source type (float32 or float64)
2566 * ttp - target type (float32 or float64)
2567 * sfld - source vsr_t field
2568 * tfld - target vsr_t field (f32 or f64)
2571 #define VSX_CVT_FP_TO_FP(op, nels, stp, ttp, sfld, tfld, sfprf) \
2572 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
2574 ppc_vsr_t t = *xt; \
2577 for (i = 0; i < nels; i++) { \
2578 t.tfld = stp##_to_##ttp(xb->sfld, &env->fp_status); \
2579 if (unlikely(stp##_is_signaling_nan(xb->sfld, \
2580 &env->fp_status))) { \
2581 float_invalid_op_vxsnan(env, GETPC()); \
2582 t.tfld = ttp##_snan_to_qnan(t.tfld); \
2585 helper_compute_fprf_##ttp(env, t.tfld); \
2590 do_float_check_status(env, GETPC()); \
2593 VSX_CVT_FP_TO_FP(xscvdpsp
, 1, float64
, float32
, VsrD(0), VsrW(0), 1)
2594 VSX_CVT_FP_TO_FP(xscvspdp
, 1, float32
, float64
, VsrW(0), VsrD(0), 1)
2595 VSX_CVT_FP_TO_FP(xvcvdpsp
, 2, float64
, float32
, VsrD(i
), VsrW(2 * i
), 0)
2596 VSX_CVT_FP_TO_FP(xvcvspdp
, 2, float32
, float64
, VsrW(2 * i
), VsrD(i
), 0)
2599 * VSX_CVT_FP_TO_FP_VECTOR - VSX floating point/floating point conversion
2600 * op - instruction mnemonic
2601 * nels - number of elements (1, 2 or 4)
2602 * stp - source type (float32 or float64)
2603 * ttp - target type (float32 or float64)
2604 * sfld - source vsr_t field
2605 * tfld - target vsr_t field (f32 or f64)
2608 #define VSX_CVT_FP_TO_FP_VECTOR(op, nels, stp, ttp, sfld, tfld, sfprf) \
2609 void helper_##op(CPUPPCState *env, uint32_t opcode, \
2610 ppc_vsr_t *xt, ppc_vsr_t *xb) \
2612 ppc_vsr_t t = *xt; \
2615 for (i = 0; i < nels; i++) { \
2616 t.tfld = stp##_to_##ttp(xb->sfld, &env->fp_status); \
2617 if (unlikely(stp##_is_signaling_nan(xb->sfld, \
2618 &env->fp_status))) { \
2619 float_invalid_op_vxsnan(env, GETPC()); \
2620 t.tfld = ttp##_snan_to_qnan(t.tfld); \
2623 helper_compute_fprf_##ttp(env, t.tfld); \
2628 do_float_check_status(env, GETPC()); \
2631 VSX_CVT_FP_TO_FP_VECTOR(xscvdpqp
, 1, float64
, float128
, VsrD(0), f128
, 1)
2634 * VSX_CVT_FP_TO_FP_HP - VSX floating point/floating point conversion
2635 * involving one half precision value
2636 * op - instruction mnemonic
2637 * nels - number of elements (1, 2 or 4)
2640 * sfld - source vsr_t field
2641 * tfld - target vsr_t field
2644 #define VSX_CVT_FP_TO_FP_HP(op, nels, stp, ttp, sfld, tfld, sfprf) \
2645 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
2647 ppc_vsr_t t = { }; \
2650 for (i = 0; i < nels; i++) { \
2651 t.tfld = stp##_to_##ttp(xb->sfld, 1, &env->fp_status); \
2652 if (unlikely(stp##_is_signaling_nan(xb->sfld, \
2653 &env->fp_status))) { \
2654 float_invalid_op_vxsnan(env, GETPC()); \
2655 t.tfld = ttp##_snan_to_qnan(t.tfld); \
2658 helper_compute_fprf_##ttp(env, t.tfld); \
2663 do_float_check_status(env, GETPC()); \
2666 VSX_CVT_FP_TO_FP_HP(xscvdphp
, 1, float64
, float16
, VsrD(0), VsrH(3), 1)
2667 VSX_CVT_FP_TO_FP_HP(xscvhpdp
, 1, float16
, float64
, VsrH(3), VsrD(0), 1)
2668 VSX_CVT_FP_TO_FP_HP(xvcvsphp
, 4, float32
, float16
, VsrW(i
), VsrH(2 * i
+ 1), 0)
2669 VSX_CVT_FP_TO_FP_HP(xvcvhpsp
, 4, float16
, float32
, VsrH(2 * i
+ 1), VsrW(i
), 0)
2672 * xscvqpdp isn't using VSX_CVT_FP_TO_FP() because xscvqpdpo will be
2673 * added to this later.
2675 void helper_xscvqpdp(CPUPPCState
*env
, uint32_t opcode
,
2676 ppc_vsr_t
*xt
, ppc_vsr_t
*xb
)
2681 tstat
= env
->fp_status
;
2682 if (unlikely(Rc(opcode
) != 0)) {
2683 tstat
.float_rounding_mode
= float_round_to_odd
;
2686 t
.VsrD(0) = float128_to_float64(xb
->f128
, &tstat
);
2687 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
2688 if (unlikely(float128_is_signaling_nan(xb
->f128
, &tstat
))) {
2689 float_invalid_op_vxsnan(env
, GETPC());
2690 t
.VsrD(0) = float64_snan_to_qnan(t
.VsrD(0));
2692 helper_compute_fprf_float64(env
, t
.VsrD(0));
2695 do_float_check_status(env
, GETPC());
2698 uint64_t helper_xscvdpspn(CPUPPCState
*env
, uint64_t xb
)
2700 uint64_t result
, sign
, exp
, frac
;
2702 float_status tstat
= env
->fp_status
;
2703 set_float_exception_flags(0, &tstat
);
2705 sign
= extract64(xb
, 63, 1);
2706 exp
= extract64(xb
, 52, 11);
2707 frac
= extract64(xb
, 0, 52) | 0x10000000000000ULL
;
2709 if (unlikely(exp
== 0 && extract64(frac
, 0, 52) != 0)) {
2710 /* DP denormal operand. */
2711 /* Exponent override to DP min exp. */
2713 /* Implicit bit override to 0. */
2714 frac
= deposit64(frac
, 53, 1, 0);
2717 if (unlikely(exp
< 897 && frac
!= 0)) {
2718 /* SP tiny operand. */
2719 if (897 - exp
> 63) {
2722 /* Denormalize until exp = SP min exp. */
2723 frac
>>= (897 - exp
);
2725 /* Exponent override to SP min exp - 1. */
2729 result
= sign
<< 31;
2730 result
|= extract64(exp
, 10, 1) << 30;
2731 result
|= extract64(exp
, 0, 7) << 23;
2732 result
|= extract64(frac
, 29, 23);
2734 /* hardware replicates result to both words of the doubleword result. */
2735 return (result
<< 32) | result
;
2738 uint64_t helper_xscvspdpn(CPUPPCState
*env
, uint64_t xb
)
2740 float_status tstat
= env
->fp_status
;
2741 set_float_exception_flags(0, &tstat
);
2743 return float32_to_float64(xb
>> 32, &tstat
);
2747 * VSX_CVT_FP_TO_INT - VSX floating point to integer conversion
2748 * op - instruction mnemonic
2749 * nels - number of elements (1, 2 or 4)
2750 * stp - source type (float32 or float64)
2751 * ttp - target type (int32, uint32, int64 or uint64)
2752 * sfld - source vsr_t field
2753 * tfld - target vsr_t field
2754 * rnan - resulting NaN
2756 #define VSX_CVT_FP_TO_INT(op, nels, stp, ttp, sfld, tfld, rnan) \
2757 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
2759 int all_flags = env->fp_status.float_exception_flags, flags; \
2760 ppc_vsr_t t = *xt; \
2763 for (i = 0; i < nels; i++) { \
2764 env->fp_status.float_exception_flags = 0; \
2765 t.tfld = stp##_to_##ttp##_round_to_zero(xb->sfld, &env->fp_status); \
2766 flags = env->fp_status.float_exception_flags; \
2767 if (unlikely(flags & float_flag_invalid)) { \
2768 t.tfld = float_invalid_cvt(env, flags, t.tfld, rnan, 0, GETPC());\
2770 all_flags |= flags; \
2774 env->fp_status.float_exception_flags = all_flags; \
2775 do_float_check_status(env, GETPC()); \
2778 VSX_CVT_FP_TO_INT(xscvdpsxds
, 1, float64
, int64
, VsrD(0), VsrD(0), \
2779 0x8000000000000000ULL
)
2780 VSX_CVT_FP_TO_INT(xscvdpsxws
, 1, float64
, int32
, VsrD(0), VsrW(1), \
2782 VSX_CVT_FP_TO_INT(xscvdpuxds
, 1, float64
, uint64
, VsrD(0), VsrD(0), 0ULL)
2783 VSX_CVT_FP_TO_INT(xscvdpuxws
, 1, float64
, uint32
, VsrD(0), VsrW(1), 0U)
2784 VSX_CVT_FP_TO_INT(xvcvdpsxds
, 2, float64
, int64
, VsrD(i
), VsrD(i
), \
2785 0x8000000000000000ULL
)
2786 VSX_CVT_FP_TO_INT(xvcvdpsxws
, 2, float64
, int32
, VsrD(i
), VsrW(2 * i
), \
2788 VSX_CVT_FP_TO_INT(xvcvdpuxds
, 2, float64
, uint64
, VsrD(i
), VsrD(i
), 0ULL)
2789 VSX_CVT_FP_TO_INT(xvcvdpuxws
, 2, float64
, uint32
, VsrD(i
), VsrW(2 * i
), 0U)
2790 VSX_CVT_FP_TO_INT(xvcvspsxds
, 2, float32
, int64
, VsrW(2 * i
), VsrD(i
), \
2791 0x8000000000000000ULL
)
2792 VSX_CVT_FP_TO_INT(xvcvspsxws
, 4, float32
, int32
, VsrW(i
), VsrW(i
), 0x80000000U
)
2793 VSX_CVT_FP_TO_INT(xvcvspuxds
, 2, float32
, uint64
, VsrW(2 * i
), VsrD(i
), 0ULL)
2794 VSX_CVT_FP_TO_INT(xvcvspuxws
, 4, float32
, uint32
, VsrW(i
), VsrW(i
), 0U)
2797 * VSX_CVT_FP_TO_INT_VECTOR - VSX floating point to integer conversion
2798 * op - instruction mnemonic
2799 * stp - source type (float32 or float64)
2800 * ttp - target type (int32, uint32, int64 or uint64)
2801 * sfld - source vsr_t field
2802 * tfld - target vsr_t field
2803 * rnan - resulting NaN
2805 #define VSX_CVT_FP_TO_INT_VECTOR(op, stp, ttp, sfld, tfld, rnan) \
2806 void helper_##op(CPUPPCState *env, uint32_t opcode, \
2807 ppc_vsr_t *xt, ppc_vsr_t *xb) \
2809 ppc_vsr_t t = { }; \
2812 t.tfld = stp##_to_##ttp##_round_to_zero(xb->sfld, &env->fp_status); \
2813 flags = get_float_exception_flags(&env->fp_status); \
2814 if (flags & float_flag_invalid) { \
2815 t.tfld = float_invalid_cvt(env, flags, t.tfld, rnan, 0, GETPC()); \
2819 do_float_check_status(env, GETPC()); \
2822 VSX_CVT_FP_TO_INT_VECTOR(xscvqpsdz
, float128
, int64
, f128
, VsrD(0), \
2823 0x8000000000000000ULL
)
2825 VSX_CVT_FP_TO_INT_VECTOR(xscvqpswz
, float128
, int32
, f128
, VsrD(0), \
2826 0xffffffff80000000ULL
)
2827 VSX_CVT_FP_TO_INT_VECTOR(xscvqpudz
, float128
, uint64
, f128
, VsrD(0), 0x0ULL
)
2828 VSX_CVT_FP_TO_INT_VECTOR(xscvqpuwz
, float128
, uint32
, f128
, VsrD(0), 0x0ULL
)
2831 * VSX_CVT_INT_TO_FP - VSX integer to floating point conversion
2832 * op - instruction mnemonic
2833 * nels - number of elements (1, 2 or 4)
2834 * stp - source type (int32, uint32, int64 or uint64)
2835 * ttp - target type (float32 or float64)
2836 * sfld - source vsr_t field
2837 * tfld - target vsr_t field
2838 * jdef - definition of the j index (i or 2*i)
2841 #define VSX_CVT_INT_TO_FP(op, nels, stp, ttp, sfld, tfld, sfprf, r2sp) \
2842 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
2844 ppc_vsr_t t = *xt; \
2847 for (i = 0; i < nels; i++) { \
2848 t.tfld = stp##_to_##ttp(xb->sfld, &env->fp_status); \
2850 t.tfld = do_frsp(env, t.tfld, GETPC()); \
2853 helper_compute_fprf_float64(env, t.tfld); \
2858 do_float_check_status(env, GETPC()); \
2861 VSX_CVT_INT_TO_FP(xscvsxddp
, 1, int64
, float64
, VsrD(0), VsrD(0), 1, 0)
2862 VSX_CVT_INT_TO_FP(xscvuxddp
, 1, uint64
, float64
, VsrD(0), VsrD(0), 1, 0)
2863 VSX_CVT_INT_TO_FP(xscvsxdsp
, 1, int64
, float64
, VsrD(0), VsrD(0), 1, 1)
2864 VSX_CVT_INT_TO_FP(xscvuxdsp
, 1, uint64
, float64
, VsrD(0), VsrD(0), 1, 1)
2865 VSX_CVT_INT_TO_FP(xvcvsxddp
, 2, int64
, float64
, VsrD(i
), VsrD(i
), 0, 0)
2866 VSX_CVT_INT_TO_FP(xvcvuxddp
, 2, uint64
, float64
, VsrD(i
), VsrD(i
), 0, 0)
2867 VSX_CVT_INT_TO_FP(xvcvsxwdp
, 2, int32
, float64
, VsrW(2 * i
), VsrD(i
), 0, 0)
2868 VSX_CVT_INT_TO_FP(xvcvuxwdp
, 2, uint64
, float64
, VsrW(2 * i
), VsrD(i
), 0, 0)
2869 VSX_CVT_INT_TO_FP(xvcvsxdsp
, 2, int64
, float32
, VsrD(i
), VsrW(2 * i
), 0, 0)
2870 VSX_CVT_INT_TO_FP(xvcvuxdsp
, 2, uint64
, float32
, VsrD(i
), VsrW(2 * i
), 0, 0)
2871 VSX_CVT_INT_TO_FP(xvcvsxwsp
, 4, int32
, float32
, VsrW(i
), VsrW(i
), 0, 0)
2872 VSX_CVT_INT_TO_FP(xvcvuxwsp
, 4, uint32
, float32
, VsrW(i
), VsrW(i
), 0, 0)
2875 * VSX_CVT_INT_TO_FP_VECTOR - VSX integer to floating point conversion
2876 * op - instruction mnemonic
2877 * stp - source type (int32, uint32, int64 or uint64)
2878 * ttp - target type (float32 or float64)
2879 * sfld - source vsr_t field
2880 * tfld - target vsr_t field
2882 #define VSX_CVT_INT_TO_FP_VECTOR(op, stp, ttp, sfld, tfld) \
2883 void helper_##op(CPUPPCState *env, uint32_t opcode, \
2884 ppc_vsr_t *xt, ppc_vsr_t *xb) \
2886 ppc_vsr_t t = *xt; \
2888 t.tfld = stp##_to_##ttp(xb->sfld, &env->fp_status); \
2889 helper_compute_fprf_##ttp(env, t.tfld); \
2892 do_float_check_status(env, GETPC()); \
2895 VSX_CVT_INT_TO_FP_VECTOR(xscvsdqp
, int64
, float128
, VsrD(0), f128
)
2896 VSX_CVT_INT_TO_FP_VECTOR(xscvudqp
, uint64
, float128
, VsrD(0), f128
)
2899 * For "use current rounding mode", define a value that will not be
2900 * one of the existing rounding model enums.
2902 #define FLOAT_ROUND_CURRENT (float_round_nearest_even + float_round_down + \
2903 float_round_up + float_round_to_zero)
2906 * VSX_ROUND - VSX floating point round
2907 * op - instruction mnemonic
2908 * nels - number of elements (1, 2 or 4)
2909 * tp - type (float32 or float64)
2910 * fld - vsr_t field (VsrD(*) or VsrW(*))
2911 * rmode - rounding mode
2914 #define VSX_ROUND(op, nels, tp, fld, rmode, sfprf) \
2915 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
2917 ppc_vsr_t t = *xt; \
2919 FloatRoundMode curr_rounding_mode; \
2921 if (rmode != FLOAT_ROUND_CURRENT) { \
2922 curr_rounding_mode = get_float_rounding_mode(&env->fp_status); \
2923 set_float_rounding_mode(rmode, &env->fp_status); \
2926 for (i = 0; i < nels; i++) { \
2927 if (unlikely(tp##_is_signaling_nan(xb->fld, \
2928 &env->fp_status))) { \
2929 float_invalid_op_vxsnan(env, GETPC()); \
2930 t.fld = tp##_snan_to_qnan(xb->fld); \
2932 t.fld = tp##_round_to_int(xb->fld, &env->fp_status); \
2935 helper_compute_fprf_float64(env, t.fld); \
2940 * If this is not a "use current rounding mode" instruction, \
2941 * then inhibit setting of the XX bit and restore rounding \
2944 if (rmode != FLOAT_ROUND_CURRENT) { \
2945 set_float_rounding_mode(curr_rounding_mode, &env->fp_status); \
2946 env->fp_status.float_exception_flags &= ~float_flag_inexact; \
2950 do_float_check_status(env, GETPC()); \
2953 VSX_ROUND(xsrdpi
, 1, float64
, VsrD(0), float_round_ties_away
, 1)
2954 VSX_ROUND(xsrdpic
, 1, float64
, VsrD(0), FLOAT_ROUND_CURRENT
, 1)
2955 VSX_ROUND(xsrdpim
, 1, float64
, VsrD(0), float_round_down
, 1)
2956 VSX_ROUND(xsrdpip
, 1, float64
, VsrD(0), float_round_up
, 1)
2957 VSX_ROUND(xsrdpiz
, 1, float64
, VsrD(0), float_round_to_zero
, 1)
2959 VSX_ROUND(xvrdpi
, 2, float64
, VsrD(i
), float_round_ties_away
, 0)
2960 VSX_ROUND(xvrdpic
, 2, float64
, VsrD(i
), FLOAT_ROUND_CURRENT
, 0)
2961 VSX_ROUND(xvrdpim
, 2, float64
, VsrD(i
), float_round_down
, 0)
2962 VSX_ROUND(xvrdpip
, 2, float64
, VsrD(i
), float_round_up
, 0)
2963 VSX_ROUND(xvrdpiz
, 2, float64
, VsrD(i
), float_round_to_zero
, 0)
2965 VSX_ROUND(xvrspi
, 4, float32
, VsrW(i
), float_round_ties_away
, 0)
2966 VSX_ROUND(xvrspic
, 4, float32
, VsrW(i
), FLOAT_ROUND_CURRENT
, 0)
2967 VSX_ROUND(xvrspim
, 4, float32
, VsrW(i
), float_round_down
, 0)
2968 VSX_ROUND(xvrspip
, 4, float32
, VsrW(i
), float_round_up
, 0)
2969 VSX_ROUND(xvrspiz
, 4, float32
, VsrW(i
), float_round_to_zero
, 0)
2971 uint64_t helper_xsrsp(CPUPPCState
*env
, uint64_t xb
)
2973 helper_reset_fpstatus(env
);
2975 uint64_t xt
= do_frsp(env
, xb
, GETPC());
2977 helper_compute_fprf_float64(env
, xt
);
2978 do_float_check_status(env
, GETPC());
2982 #define VSX_XXPERM(op, indexed) \
2983 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
2984 ppc_vsr_t *xa, ppc_vsr_t *pcv) \
2986 ppc_vsr_t t = *xt; \
2989 for (i = 0; i < 16; i++) { \
2990 idx = pcv->VsrB(i) & 0x1F; \
2994 t.VsrB(i) = (idx <= 15) ? xa->VsrB(idx) \
2995 : xt->VsrB(idx - 16); \
3000 VSX_XXPERM(xxperm
, 0)
3001 VSX_XXPERM(xxpermr
, 1)
3003 void helper_xvxsigsp(CPUPPCState
*env
, ppc_vsr_t
*xt
, ppc_vsr_t
*xb
)
3006 uint32_t exp
, i
, fraction
;
3008 for (i
= 0; i
< 4; i
++) {
3009 exp
= (xb
->VsrW(i
) >> 23) & 0xFF;
3010 fraction
= xb
->VsrW(i
) & 0x7FFFFF;
3011 if (exp
!= 0 && exp
!= 255) {
3012 t
.VsrW(i
) = fraction
| 0x00800000;
3014 t
.VsrW(i
) = fraction
;
3021 * VSX_TEST_DC - VSX floating point test data class
3022 * op - instruction mnemonic
3023 * nels - number of elements (1, 2 or 4)
3024 * xbn - VSR register number
3025 * tp - type (float32 or float64)
3026 * fld - vsr_t field (VsrD(*) or VsrW(*))
3027 * tfld - target vsr_t field (VsrD(*) or VsrW(*))
3028 * fld_max - target field max
3029 * scrf - set result in CR and FPCC
3031 #define VSX_TEST_DC(op, nels, xbn, tp, fld, tfld, fld_max, scrf) \
3032 void helper_##op(CPUPPCState *env, uint32_t opcode) \
3034 ppc_vsr_t *xt = &env->vsr[xT(opcode)]; \
3035 ppc_vsr_t *xb = &env->vsr[xbn]; \
3036 ppc_vsr_t t = { }; \
3037 uint32_t i, sign, dcmx; \
3038 uint32_t cc, match = 0; \
3041 dcmx = DCMX_XV(opcode); \
3044 dcmx = DCMX(opcode); \
3047 for (i = 0; i < nels; i++) { \
3048 sign = tp##_is_neg(xb->fld); \
3049 if (tp##_is_any_nan(xb->fld)) { \
3050 match = extract32(dcmx, 6, 1); \
3051 } else if (tp##_is_infinity(xb->fld)) { \
3052 match = extract32(dcmx, 4 + !sign, 1); \
3053 } else if (tp##_is_zero(xb->fld)) { \
3054 match = extract32(dcmx, 2 + !sign, 1); \
3055 } else if (tp##_is_zero_or_denormal(xb->fld)) { \
3056 match = extract32(dcmx, 0 + !sign, 1); \
3060 cc = sign << CRF_LT_BIT | match << CRF_EQ_BIT; \
3061 env->fpscr &= ~FP_FPCC; \
3062 env->fpscr |= cc << FPSCR_FPCC; \
3063 env->crf[BF(opcode)] = cc; \
3065 t.tfld = match ? fld_max : 0; \
3074 VSX_TEST_DC(xvtstdcdp
, 2, xB(opcode
), float64
, VsrD(i
), VsrD(i
), UINT64_MAX
, 0)
3075 VSX_TEST_DC(xvtstdcsp
, 4, xB(opcode
), float32
, VsrW(i
), VsrW(i
), UINT32_MAX
, 0)
3076 VSX_TEST_DC(xststdcdp
, 1, xB(opcode
), float64
, VsrD(0), VsrD(0), 0, 1)
3077 VSX_TEST_DC(xststdcqp
, 1, (rB(opcode
) + 32), float128
, f128
, VsrD(0), 0, 1)
3079 void helper_xststdcsp(CPUPPCState
*env
, uint32_t opcode
, ppc_vsr_t
*xb
)
3081 uint32_t dcmx
, sign
, exp
;
3082 uint32_t cc
, match
= 0, not_sp
= 0;
3084 dcmx
= DCMX(opcode
);
3085 exp
= (xb
->VsrD(0) >> 52) & 0x7FF;
3087 sign
= float64_is_neg(xb
->VsrD(0));
3088 if (float64_is_any_nan(xb
->VsrD(0))) {
3089 match
= extract32(dcmx
, 6, 1);
3090 } else if (float64_is_infinity(xb
->VsrD(0))) {
3091 match
= extract32(dcmx
, 4 + !sign
, 1);
3092 } else if (float64_is_zero(xb
->VsrD(0))) {
3093 match
= extract32(dcmx
, 2 + !sign
, 1);
3094 } else if (float64_is_zero_or_denormal(xb
->VsrD(0)) ||
3095 (exp
> 0 && exp
< 0x381)) {
3096 match
= extract32(dcmx
, 0 + !sign
, 1);
3099 not_sp
= !float64_eq(xb
->VsrD(0),
3101 float64_to_float32(xb
->VsrD(0), &env
->fp_status
),
3102 &env
->fp_status
), &env
->fp_status
);
3104 cc
= sign
<< CRF_LT_BIT
| match
<< CRF_EQ_BIT
| not_sp
<< CRF_SO_BIT
;
3105 env
->fpscr
&= ~FP_FPCC
;
3106 env
->fpscr
|= cc
<< FPSCR_FPCC
;
3107 env
->crf
[BF(opcode
)] = cc
;
3110 void helper_xsrqpi(CPUPPCState
*env
, uint32_t opcode
,
3111 ppc_vsr_t
*xt
, ppc_vsr_t
*xb
)
3114 uint8_t r
= Rrm(opcode
);
3115 uint8_t ex
= Rc(opcode
);
3116 uint8_t rmc
= RMC(opcode
);
3120 helper_reset_fpstatus(env
);
3122 if (r
== 0 && rmc
== 0) {
3123 rmode
= float_round_ties_away
;
3124 } else if (r
== 0 && rmc
== 0x3) {
3126 } else if (r
== 1) {
3129 rmode
= float_round_nearest_even
;
3132 rmode
= float_round_to_zero
;
3135 rmode
= float_round_up
;
3138 rmode
= float_round_down
;
3145 tstat
= env
->fp_status
;
3146 set_float_exception_flags(0, &tstat
);
3147 set_float_rounding_mode(rmode
, &tstat
);
3148 t
.f128
= float128_round_to_int(xb
->f128
, &tstat
);
3149 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3151 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid_snan
)) {
3152 float_invalid_op_vxsnan(env
, GETPC());
3155 if (ex
== 0 && (tstat
.float_exception_flags
& float_flag_inexact
)) {
3156 env
->fp_status
.float_exception_flags
&= ~float_flag_inexact
;
3159 helper_compute_fprf_float128(env
, t
.f128
);
3160 do_float_check_status(env
, GETPC());
3164 void helper_xsrqpxp(CPUPPCState
*env
, uint32_t opcode
,
3165 ppc_vsr_t
*xt
, ppc_vsr_t
*xb
)
3168 uint8_t r
= Rrm(opcode
);
3169 uint8_t rmc
= RMC(opcode
);
3174 helper_reset_fpstatus(env
);
3176 if (r
== 0 && rmc
== 0) {
3177 rmode
= float_round_ties_away
;
3178 } else if (r
== 0 && rmc
== 0x3) {
3180 } else if (r
== 1) {
3183 rmode
= float_round_nearest_even
;
3186 rmode
= float_round_to_zero
;
3189 rmode
= float_round_up
;
3192 rmode
= float_round_down
;
3199 tstat
= env
->fp_status
;
3200 set_float_exception_flags(0, &tstat
);
3201 set_float_rounding_mode(rmode
, &tstat
);
3202 round_res
= float128_to_floatx80(xb
->f128
, &tstat
);
3203 t
.f128
= floatx80_to_float128(round_res
, &tstat
);
3204 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3206 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid_snan
)) {
3207 float_invalid_op_vxsnan(env
, GETPC());
3208 t
.f128
= float128_snan_to_qnan(t
.f128
);
3211 helper_compute_fprf_float128(env
, t
.f128
);
3213 do_float_check_status(env
, GETPC());
3216 void helper_xssqrtqp(CPUPPCState
*env
, uint32_t opcode
,
3217 ppc_vsr_t
*xt
, ppc_vsr_t
*xb
)
3222 helper_reset_fpstatus(env
);
3224 tstat
= env
->fp_status
;
3225 if (unlikely(Rc(opcode
) != 0)) {
3226 tstat
.float_rounding_mode
= float_round_to_odd
;
3229 set_float_exception_flags(0, &tstat
);
3230 t
.f128
= float128_sqrt(xb
->f128
, &tstat
);
3231 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3233 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
3234 float_invalid_op_sqrt(env
, tstat
.float_exception_flags
, 1, GETPC());
3237 helper_compute_fprf_float128(env
, t
.f128
);
3239 do_float_check_status(env
, GETPC());
3242 void helper_xssubqp(CPUPPCState
*env
, uint32_t opcode
,
3243 ppc_vsr_t
*xt
, ppc_vsr_t
*xa
, ppc_vsr_t
*xb
)
3248 helper_reset_fpstatus(env
);
3250 tstat
= env
->fp_status
;
3251 if (unlikely(Rc(opcode
) != 0)) {
3252 tstat
.float_rounding_mode
= float_round_to_odd
;
3255 set_float_exception_flags(0, &tstat
);
3256 t
.f128
= float128_sub(xa
->f128
, xb
->f128
, &tstat
);
3257 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3259 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
3260 float_invalid_op_addsub(env
, tstat
.float_exception_flags
, 1, GETPC());
3263 helper_compute_fprf_float128(env
, t
.f128
);
3265 do_float_check_status(env
, GETPC());