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 */
205 if (env
->fpscr
& FP_VE
) {
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
);
219 if (!(env
->fpscr
& FP_VE
)) {
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 */
289 if (env
->fpscr
& FP_VE
) {
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
);
306 if (!(env
->fpscr
& FP_VE
)) {
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 */
321 if (env
->fpscr
& FP_ZE
) {
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 */
339 if (env
->fpscr
& FP_OE
) {
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 */
359 if (env
->fpscr
& FP_UE
) {
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 */
377 if (env
->fpscr
& FP_XE
) {
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_fadds(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
527 float64 ret
= float64r32_add(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 float64
helper_fsub(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
539 float64 ret
= float64_sub(arg1
, arg2
, &env
->fp_status
);
540 int flags
= get_float_exception_flags(&env
->fp_status
);
542 if (unlikely(flags
& float_flag_invalid
)) {
543 float_invalid_op_addsub(env
, flags
, 1, GETPC());
550 float64
helper_fsubs(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
552 float64 ret
= float64r32_sub(arg1
, arg2
, &env
->fp_status
);
553 int flags
= get_float_exception_flags(&env
->fp_status
);
555 if (unlikely(flags
& float_flag_invalid
)) {
556 float_invalid_op_addsub(env
, flags
, 1, GETPC());
561 static void float_invalid_op_mul(CPUPPCState
*env
, int flags
,
562 bool set_fprc
, uintptr_t retaddr
)
564 if (flags
& float_flag_invalid_imz
) {
565 float_invalid_op_vximz(env
, set_fprc
, retaddr
);
566 } else if (flags
& float_flag_invalid_snan
) {
567 float_invalid_op_vxsnan(env
, retaddr
);
572 float64
helper_fmul(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
574 float64 ret
= float64_mul(arg1
, arg2
, &env
->fp_status
);
575 int flags
= get_float_exception_flags(&env
->fp_status
);
577 if (unlikely(flags
& float_flag_invalid
)) {
578 float_invalid_op_mul(env
, flags
, 1, GETPC());
585 float64
helper_fmuls(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
587 float64 ret
= float64r32_mul(arg1
, arg2
, &env
->fp_status
);
588 int flags
= get_float_exception_flags(&env
->fp_status
);
590 if (unlikely(flags
& float_flag_invalid
)) {
591 float_invalid_op_mul(env
, flags
, 1, GETPC());
596 static void float_invalid_op_div(CPUPPCState
*env
, int flags
,
597 bool set_fprc
, uintptr_t retaddr
)
599 if (flags
& float_flag_invalid_idi
) {
600 float_invalid_op_vxidi(env
, set_fprc
, retaddr
);
601 } else if (flags
& float_flag_invalid_zdz
) {
602 float_invalid_op_vxzdz(env
, set_fprc
, retaddr
);
603 } else if (flags
& float_flag_invalid_snan
) {
604 float_invalid_op_vxsnan(env
, retaddr
);
609 float64
helper_fdiv(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
611 float64 ret
= float64_div(arg1
, arg2
, &env
->fp_status
);
612 int flags
= get_float_exception_flags(&env
->fp_status
);
614 if (unlikely(flags
& float_flag_invalid
)) {
615 float_invalid_op_div(env
, flags
, 1, GETPC());
617 if (unlikely(flags
& float_flag_divbyzero
)) {
618 float_zero_divide_excp(env
, GETPC());
625 float64
helper_fdivs(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
627 float64 ret
= float64r32_div(arg1
, arg2
, &env
->fp_status
);
628 int flags
= get_float_exception_flags(&env
->fp_status
);
630 if (unlikely(flags
& float_flag_invalid
)) {
631 float_invalid_op_div(env
, flags
, 1, GETPC());
633 if (unlikely(flags
& float_flag_divbyzero
)) {
634 float_zero_divide_excp(env
, GETPC());
640 static uint64_t float_invalid_cvt(CPUPPCState
*env
, int flags
,
641 uint64_t ret
, uint64_t ret_nan
,
642 bool set_fprc
, uintptr_t retaddr
)
645 * VXCVI is different from most in that it sets two exception bits,
646 * VXCVI and VXSNAN for an SNaN input.
648 if (flags
& float_flag_invalid_snan
) {
649 env
->fpscr
|= FP_VXSNAN
;
651 float_invalid_op_vxcvi(env
, set_fprc
, retaddr
);
653 return flags
& float_flag_invalid_cvti
? ret
: ret_nan
;
656 #define FPU_FCTI(op, cvt, nanval) \
657 uint64_t helper_##op(CPUPPCState *env, float64 arg) \
659 uint64_t ret = float64_to_##cvt(arg, &env->fp_status); \
660 int flags = get_float_exception_flags(&env->fp_status); \
661 if (unlikely(flags & float_flag_invalid)) { \
662 ret = float_invalid_cvt(env, flags, ret, nanval, 1, GETPC()); \
667 FPU_FCTI(fctiw
, int32
, 0x80000000U
)
668 FPU_FCTI(fctiwz
, int32_round_to_zero
, 0x80000000U
)
669 FPU_FCTI(fctiwu
, uint32
, 0x00000000U
)
670 FPU_FCTI(fctiwuz
, uint32_round_to_zero
, 0x00000000U
)
671 FPU_FCTI(fctid
, int64
, 0x8000000000000000ULL
)
672 FPU_FCTI(fctidz
, int64_round_to_zero
, 0x8000000000000000ULL
)
673 FPU_FCTI(fctidu
, uint64
, 0x0000000000000000ULL
)
674 FPU_FCTI(fctiduz
, uint64_round_to_zero
, 0x0000000000000000ULL
)
676 #define FPU_FCFI(op, cvtr, is_single) \
677 uint64_t helper_##op(CPUPPCState *env, uint64_t arg) \
682 float32 tmp = cvtr(arg, &env->fp_status); \
683 farg.d = float32_to_float64(tmp, &env->fp_status); \
685 farg.d = cvtr(arg, &env->fp_status); \
687 do_float_check_status(env, GETPC()); \
691 FPU_FCFI(fcfid
, int64_to_float64
, 0)
692 FPU_FCFI(fcfids
, int64_to_float32
, 1)
693 FPU_FCFI(fcfidu
, uint64_to_float64
, 0)
694 FPU_FCFI(fcfidus
, uint64_to_float32
, 1)
696 static uint64_t do_fri(CPUPPCState
*env
, uint64_t arg
,
697 FloatRoundMode rounding_mode
)
699 FloatRoundMode old_rounding_mode
= get_float_rounding_mode(&env
->fp_status
);
702 set_float_rounding_mode(rounding_mode
, &env
->fp_status
);
703 arg
= float64_round_to_int(arg
, &env
->fp_status
);
704 set_float_rounding_mode(old_rounding_mode
, &env
->fp_status
);
706 flags
= get_float_exception_flags(&env
->fp_status
);
707 if (flags
& float_flag_invalid_snan
) {
708 float_invalid_op_vxsnan(env
, GETPC());
711 /* fri* does not set FPSCR[XX] */
712 set_float_exception_flags(flags
& ~float_flag_inexact
, &env
->fp_status
);
713 do_float_check_status(env
, GETPC());
718 uint64_t helper_frin(CPUPPCState
*env
, uint64_t arg
)
720 return do_fri(env
, arg
, float_round_ties_away
);
723 uint64_t helper_friz(CPUPPCState
*env
, uint64_t arg
)
725 return do_fri(env
, arg
, float_round_to_zero
);
728 uint64_t helper_frip(CPUPPCState
*env
, uint64_t arg
)
730 return do_fri(env
, arg
, float_round_up
);
733 uint64_t helper_frim(CPUPPCState
*env
, uint64_t arg
)
735 return do_fri(env
, arg
, float_round_down
);
738 static void float_invalid_op_madd(CPUPPCState
*env
, int flags
,
739 bool set_fpcc
, uintptr_t retaddr
)
741 if (flags
& float_flag_invalid_imz
) {
742 float_invalid_op_vximz(env
, set_fpcc
, retaddr
);
744 float_invalid_op_addsub(env
, flags
, set_fpcc
, retaddr
);
748 static float64
do_fmadd(CPUPPCState
*env
, float64 a
, float64 b
,
749 float64 c
, int madd_flags
, uintptr_t retaddr
)
751 float64 ret
= float64_muladd(a
, b
, c
, madd_flags
, &env
->fp_status
);
752 int flags
= get_float_exception_flags(&env
->fp_status
);
754 if (unlikely(flags
& float_flag_invalid
)) {
755 float_invalid_op_madd(env
, flags
, 1, retaddr
);
760 static uint64_t do_fmadds(CPUPPCState
*env
, float64 a
, float64 b
,
761 float64 c
, int madd_flags
, uintptr_t retaddr
)
763 float64 ret
= float64r32_muladd(a
, b
, c
, madd_flags
, &env
->fp_status
);
764 int flags
= get_float_exception_flags(&env
->fp_status
);
766 if (unlikely(flags
& float_flag_invalid
)) {
767 float_invalid_op_madd(env
, flags
, 1, retaddr
);
772 #define FPU_FMADD(op, madd_flags) \
773 uint64_t helper_##op(CPUPPCState *env, uint64_t arg1, \
774 uint64_t arg2, uint64_t arg3) \
775 { return do_fmadd(env, arg1, arg2, arg3, madd_flags, GETPC()); } \
776 uint64_t helper_##op##s(CPUPPCState *env, uint64_t arg1, \
777 uint64_t arg2, uint64_t arg3) \
778 { return do_fmadds(env, arg1, arg2, arg3, madd_flags, GETPC()); }
781 #define MSUB_FLGS float_muladd_negate_c
782 #define NMADD_FLGS float_muladd_negate_result
783 #define NMSUB_FLGS (float_muladd_negate_c | float_muladd_negate_result)
785 FPU_FMADD(fmadd
, MADD_FLGS
)
786 FPU_FMADD(fnmadd
, NMADD_FLGS
)
787 FPU_FMADD(fmsub
, MSUB_FLGS
)
788 FPU_FMADD(fnmsub
, NMSUB_FLGS
)
791 static uint64_t do_frsp(CPUPPCState
*env
, uint64_t arg
, uintptr_t retaddr
)
793 float32 f32
= float64_to_float32(arg
, &env
->fp_status
);
794 int flags
= get_float_exception_flags(&env
->fp_status
);
796 if (unlikely(flags
& float_flag_invalid_snan
)) {
797 float_invalid_op_vxsnan(env
, retaddr
);
799 return helper_todouble(f32
);
802 uint64_t helper_frsp(CPUPPCState
*env
, uint64_t arg
)
804 return do_frsp(env
, arg
, GETPC());
807 static void float_invalid_op_sqrt(CPUPPCState
*env
, int flags
,
808 bool set_fpcc
, uintptr_t retaddr
)
810 if (unlikely(flags
& float_flag_invalid_sqrt
)) {
811 float_invalid_op_vxsqrt(env
, set_fpcc
, retaddr
);
812 } else if (unlikely(flags
& float_flag_invalid_snan
)) {
813 float_invalid_op_vxsnan(env
, retaddr
);
818 float64
helper_fsqrt(CPUPPCState
*env
, float64 arg
)
820 float64 ret
= float64_sqrt(arg
, &env
->fp_status
);
821 int flags
= get_float_exception_flags(&env
->fp_status
);
823 if (unlikely(flags
& float_flag_invalid
)) {
824 float_invalid_op_sqrt(env
, flags
, 1, GETPC());
830 /* fsqrts - fsqrts. */
831 float64
helper_fsqrts(CPUPPCState
*env
, float64 arg
)
833 float64 ret
= float64r32_sqrt(arg
, &env
->fp_status
);
834 int flags
= get_float_exception_flags(&env
->fp_status
);
836 if (unlikely(flags
& float_flag_invalid
)) {
837 float_invalid_op_sqrt(env
, flags
, 1, GETPC());
843 float64
helper_fre(CPUPPCState
*env
, float64 arg
)
845 /* "Estimate" the reciprocal with actual division. */
846 float64 ret
= float64_div(float64_one
, arg
, &env
->fp_status
);
847 int flags
= get_float_exception_flags(&env
->fp_status
);
849 if (unlikely(flags
& float_flag_invalid_snan
)) {
850 float_invalid_op_vxsnan(env
, GETPC());
852 if (unlikely(flags
& float_flag_divbyzero
)) {
853 float_zero_divide_excp(env
, GETPC());
854 /* For FPSCR.ZE == 0, the result is 1/2. */
855 ret
= float64_set_sign(float64_half
, float64_is_neg(arg
));
862 uint64_t helper_fres(CPUPPCState
*env
, uint64_t arg
)
864 /* "Estimate" the reciprocal with actual division. */
865 float64 ret
= float64r32_div(float64_one
, arg
, &env
->fp_status
);
866 int flags
= get_float_exception_flags(&env
->fp_status
);
868 if (unlikely(flags
& float_flag_invalid_snan
)) {
869 float_invalid_op_vxsnan(env
, GETPC());
871 if (unlikely(flags
& float_flag_divbyzero
)) {
872 float_zero_divide_excp(env
, GETPC());
873 /* For FPSCR.ZE == 0, the result is 1/2. */
874 ret
= float64_set_sign(float64_half
, float64_is_neg(arg
));
880 /* frsqrte - frsqrte. */
881 float64
helper_frsqrte(CPUPPCState
*env
, float64 arg
)
883 /* "Estimate" the reciprocal with actual division. */
884 float64 rets
= float64_sqrt(arg
, &env
->fp_status
);
885 float64 retd
= float64_div(float64_one
, rets
, &env
->fp_status
);
886 int flags
= get_float_exception_flags(&env
->fp_status
);
888 if (unlikely(flags
& float_flag_invalid
)) {
889 float_invalid_op_sqrt(env
, flags
, 1, GETPC());
891 if (unlikely(flags
& float_flag_divbyzero
)) {
892 /* Reciprocal of (square root of) zero. */
893 float_zero_divide_excp(env
, GETPC());
899 /* frsqrtes - frsqrtes. */
900 float64
helper_frsqrtes(CPUPPCState
*env
, float64 arg
)
902 /* "Estimate" the reciprocal with actual division. */
903 float64 rets
= float64_sqrt(arg
, &env
->fp_status
);
904 float64 retd
= float64r32_div(float64_one
, rets
, &env
->fp_status
);
905 int flags
= get_float_exception_flags(&env
->fp_status
);
907 if (unlikely(flags
& float_flag_invalid
)) {
908 float_invalid_op_sqrt(env
, flags
, 1, GETPC());
910 if (unlikely(flags
& float_flag_divbyzero
)) {
911 /* Reciprocal of (square root of) zero. */
912 float_zero_divide_excp(env
, GETPC());
919 uint64_t helper_fsel(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
926 if ((!float64_is_neg(farg1
.d
) || float64_is_zero(farg1
.d
)) &&
927 !float64_is_any_nan(farg1
.d
)) {
934 uint32_t helper_ftdiv(uint64_t fra
, uint64_t frb
)
939 if (unlikely(float64_is_infinity(fra
) ||
940 float64_is_infinity(frb
) ||
941 float64_is_zero(frb
))) {
945 int e_a
= ppc_float64_get_unbiased_exp(fra
);
946 int e_b
= ppc_float64_get_unbiased_exp(frb
);
948 if (unlikely(float64_is_any_nan(fra
) ||
949 float64_is_any_nan(frb
))) {
951 } else if ((e_b
<= -1022) || (e_b
>= 1021)) {
953 } else if (!float64_is_zero(fra
) &&
954 (((e_a
- e_b
) >= 1023) ||
955 ((e_a
- e_b
) <= -1021) ||
960 if (unlikely(float64_is_zero_or_denormal(frb
))) {
961 /* XB is not zero because of the above check and */
962 /* so must be denormalized. */
967 return 0x8 | (fg_flag
? 4 : 0) | (fe_flag
? 2 : 0);
970 uint32_t helper_ftsqrt(uint64_t frb
)
975 if (unlikely(float64_is_infinity(frb
) || float64_is_zero(frb
))) {
979 int e_b
= ppc_float64_get_unbiased_exp(frb
);
981 if (unlikely(float64_is_any_nan(frb
))) {
983 } else if (unlikely(float64_is_zero(frb
))) {
985 } else if (unlikely(float64_is_neg(frb
))) {
987 } else if (!float64_is_zero(frb
) && (e_b
<= (-1022 + 52))) {
991 if (unlikely(float64_is_zero_or_denormal(frb
))) {
992 /* XB is not zero because of the above check and */
993 /* therefore must be denormalized. */
998 return 0x8 | (fg_flag
? 4 : 0) | (fe_flag
? 2 : 0);
1001 void helper_fcmpu(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
1004 CPU_DoubleU farg1
, farg2
;
1010 if (unlikely(float64_is_any_nan(farg1
.d
) ||
1011 float64_is_any_nan(farg2
.d
))) {
1013 } else if (float64_lt(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1015 } else if (!float64_le(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1021 env
->fpscr
&= ~FP_FPCC
;
1022 env
->fpscr
|= ret
<< FPSCR_FPCC
;
1023 env
->crf
[crfD
] = ret
;
1024 if (unlikely(ret
== 0x01UL
1025 && (float64_is_signaling_nan(farg1
.d
, &env
->fp_status
) ||
1026 float64_is_signaling_nan(farg2
.d
, &env
->fp_status
)))) {
1027 /* sNaN comparison */
1028 float_invalid_op_vxsnan(env
, GETPC());
1032 void helper_fcmpo(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
1035 CPU_DoubleU farg1
, farg2
;
1041 if (unlikely(float64_is_any_nan(farg1
.d
) ||
1042 float64_is_any_nan(farg2
.d
))) {
1044 } else if (float64_lt(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1046 } else if (!float64_le(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1052 env
->fpscr
&= ~FP_FPCC
;
1053 env
->fpscr
|= ret
<< FPSCR_FPCC
;
1054 env
->crf
[crfD
] = (uint32_t) ret
;
1055 if (unlikely(ret
== 0x01UL
)) {
1056 float_invalid_op_vxvc(env
, 1, GETPC());
1057 if (float64_is_signaling_nan(farg1
.d
, &env
->fp_status
) ||
1058 float64_is_signaling_nan(farg2
.d
, &env
->fp_status
)) {
1059 /* sNaN comparison */
1060 float_invalid_op_vxsnan(env
, GETPC());
1065 /* Single-precision floating-point conversions */
1066 static inline uint32_t efscfsi(CPUPPCState
*env
, uint32_t val
)
1070 u
.f
= int32_to_float32(val
, &env
->vec_status
);
1075 static inline uint32_t efscfui(CPUPPCState
*env
, uint32_t val
)
1079 u
.f
= uint32_to_float32(val
, &env
->vec_status
);
1084 static inline int32_t efsctsi(CPUPPCState
*env
, uint32_t val
)
1089 /* NaN are not treated the same way IEEE 754 does */
1090 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1094 return float32_to_int32(u
.f
, &env
->vec_status
);
1097 static inline uint32_t efsctui(CPUPPCState
*env
, uint32_t val
)
1102 /* NaN are not treated the same way IEEE 754 does */
1103 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1107 return float32_to_uint32(u
.f
, &env
->vec_status
);
1110 static inline uint32_t efsctsiz(CPUPPCState
*env
, uint32_t val
)
1115 /* NaN are not treated the same way IEEE 754 does */
1116 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1120 return float32_to_int32_round_to_zero(u
.f
, &env
->vec_status
);
1123 static inline uint32_t efsctuiz(CPUPPCState
*env
, uint32_t val
)
1128 /* NaN are not treated the same way IEEE 754 does */
1129 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1133 return float32_to_uint32_round_to_zero(u
.f
, &env
->vec_status
);
1136 static inline uint32_t efscfsf(CPUPPCState
*env
, uint32_t val
)
1141 u
.f
= int32_to_float32(val
, &env
->vec_status
);
1142 tmp
= int64_to_float32(1ULL << 32, &env
->vec_status
);
1143 u
.f
= float32_div(u
.f
, tmp
, &env
->vec_status
);
1148 static inline uint32_t efscfuf(CPUPPCState
*env
, uint32_t val
)
1153 u
.f
= uint32_to_float32(val
, &env
->vec_status
);
1154 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1155 u
.f
= float32_div(u
.f
, tmp
, &env
->vec_status
);
1160 static inline uint32_t efsctsf(CPUPPCState
*env
, uint32_t val
)
1166 /* NaN are not treated the same way IEEE 754 does */
1167 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1170 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1171 u
.f
= float32_mul(u
.f
, tmp
, &env
->vec_status
);
1173 return float32_to_int32(u
.f
, &env
->vec_status
);
1176 static inline uint32_t efsctuf(CPUPPCState
*env
, uint32_t val
)
1182 /* NaN are not treated the same way IEEE 754 does */
1183 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1186 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1187 u
.f
= float32_mul(u
.f
, tmp
, &env
->vec_status
);
1189 return float32_to_uint32(u
.f
, &env
->vec_status
);
1192 #define HELPER_SPE_SINGLE_CONV(name) \
1193 uint32_t helper_e##name(CPUPPCState *env, uint32_t val) \
1195 return e##name(env, val); \
1198 HELPER_SPE_SINGLE_CONV(fscfsi
);
1200 HELPER_SPE_SINGLE_CONV(fscfui
);
1202 HELPER_SPE_SINGLE_CONV(fscfuf
);
1204 HELPER_SPE_SINGLE_CONV(fscfsf
);
1206 HELPER_SPE_SINGLE_CONV(fsctsi
);
1208 HELPER_SPE_SINGLE_CONV(fsctui
);
1210 HELPER_SPE_SINGLE_CONV(fsctsiz
);
1212 HELPER_SPE_SINGLE_CONV(fsctuiz
);
1214 HELPER_SPE_SINGLE_CONV(fsctsf
);
1216 HELPER_SPE_SINGLE_CONV(fsctuf
);
1218 #define HELPER_SPE_VECTOR_CONV(name) \
1219 uint64_t helper_ev##name(CPUPPCState *env, uint64_t val) \
1221 return ((uint64_t)e##name(env, val >> 32) << 32) | \
1222 (uint64_t)e##name(env, val); \
1225 HELPER_SPE_VECTOR_CONV(fscfsi
);
1227 HELPER_SPE_VECTOR_CONV(fscfui
);
1229 HELPER_SPE_VECTOR_CONV(fscfuf
);
1231 HELPER_SPE_VECTOR_CONV(fscfsf
);
1233 HELPER_SPE_VECTOR_CONV(fsctsi
);
1235 HELPER_SPE_VECTOR_CONV(fsctui
);
1237 HELPER_SPE_VECTOR_CONV(fsctsiz
);
1239 HELPER_SPE_VECTOR_CONV(fsctuiz
);
1241 HELPER_SPE_VECTOR_CONV(fsctsf
);
1243 HELPER_SPE_VECTOR_CONV(fsctuf
);
1245 /* Single-precision floating-point arithmetic */
1246 static inline uint32_t efsadd(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1252 u1
.f
= float32_add(u1
.f
, u2
.f
, &env
->vec_status
);
1256 static inline uint32_t efssub(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1262 u1
.f
= float32_sub(u1
.f
, u2
.f
, &env
->vec_status
);
1266 static inline uint32_t efsmul(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1272 u1
.f
= float32_mul(u1
.f
, u2
.f
, &env
->vec_status
);
1276 static inline uint32_t efsdiv(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1282 u1
.f
= float32_div(u1
.f
, u2
.f
, &env
->vec_status
);
1286 #define HELPER_SPE_SINGLE_ARITH(name) \
1287 uint32_t helper_e##name(CPUPPCState *env, uint32_t op1, uint32_t op2) \
1289 return e##name(env, op1, op2); \
1292 HELPER_SPE_SINGLE_ARITH(fsadd
);
1294 HELPER_SPE_SINGLE_ARITH(fssub
);
1296 HELPER_SPE_SINGLE_ARITH(fsmul
);
1298 HELPER_SPE_SINGLE_ARITH(fsdiv
);
1300 #define HELPER_SPE_VECTOR_ARITH(name) \
1301 uint64_t helper_ev##name(CPUPPCState *env, uint64_t op1, uint64_t op2) \
1303 return ((uint64_t)e##name(env, op1 >> 32, op2 >> 32) << 32) | \
1304 (uint64_t)e##name(env, op1, op2); \
1307 HELPER_SPE_VECTOR_ARITH(fsadd
);
1309 HELPER_SPE_VECTOR_ARITH(fssub
);
1311 HELPER_SPE_VECTOR_ARITH(fsmul
);
1313 HELPER_SPE_VECTOR_ARITH(fsdiv
);
1315 /* Single-precision floating-point comparisons */
1316 static inline uint32_t efscmplt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1322 return float32_lt(u1
.f
, u2
.f
, &env
->vec_status
) ? 4 : 0;
1325 static inline uint32_t efscmpgt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1331 return float32_le(u1
.f
, u2
.f
, &env
->vec_status
) ? 0 : 4;
1334 static inline uint32_t efscmpeq(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1340 return float32_eq(u1
.f
, u2
.f
, &env
->vec_status
) ? 4 : 0;
1343 static inline uint32_t efststlt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1345 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1346 return efscmplt(env
, op1
, op2
);
1349 static inline uint32_t efststgt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1351 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1352 return efscmpgt(env
, op1
, op2
);
1355 static inline uint32_t efststeq(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1357 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1358 return efscmpeq(env
, op1
, op2
);
1361 #define HELPER_SINGLE_SPE_CMP(name) \
1362 uint32_t helper_e##name(CPUPPCState *env, uint32_t op1, uint32_t op2) \
1364 return e##name(env, op1, op2); \
1367 HELPER_SINGLE_SPE_CMP(fststlt
);
1369 HELPER_SINGLE_SPE_CMP(fststgt
);
1371 HELPER_SINGLE_SPE_CMP(fststeq
);
1373 HELPER_SINGLE_SPE_CMP(fscmplt
);
1375 HELPER_SINGLE_SPE_CMP(fscmpgt
);
1377 HELPER_SINGLE_SPE_CMP(fscmpeq
);
1379 static inline uint32_t evcmp_merge(int t0
, int t1
)
1381 return (t0
<< 3) | (t1
<< 2) | ((t0
| t1
) << 1) | (t0
& t1
);
1384 #define HELPER_VECTOR_SPE_CMP(name) \
1385 uint32_t helper_ev##name(CPUPPCState *env, uint64_t op1, uint64_t op2) \
1387 return evcmp_merge(e##name(env, op1 >> 32, op2 >> 32), \
1388 e##name(env, op1, op2)); \
1391 HELPER_VECTOR_SPE_CMP(fststlt
);
1393 HELPER_VECTOR_SPE_CMP(fststgt
);
1395 HELPER_VECTOR_SPE_CMP(fststeq
);
1397 HELPER_VECTOR_SPE_CMP(fscmplt
);
1399 HELPER_VECTOR_SPE_CMP(fscmpgt
);
1401 HELPER_VECTOR_SPE_CMP(fscmpeq
);
1403 /* Double-precision floating-point conversion */
1404 uint64_t helper_efdcfsi(CPUPPCState
*env
, uint32_t val
)
1408 u
.d
= int32_to_float64(val
, &env
->vec_status
);
1413 uint64_t helper_efdcfsid(CPUPPCState
*env
, uint64_t val
)
1417 u
.d
= int64_to_float64(val
, &env
->vec_status
);
1422 uint64_t helper_efdcfui(CPUPPCState
*env
, uint32_t val
)
1426 u
.d
= uint32_to_float64(val
, &env
->vec_status
);
1431 uint64_t helper_efdcfuid(CPUPPCState
*env
, uint64_t val
)
1435 u
.d
= uint64_to_float64(val
, &env
->vec_status
);
1440 uint32_t helper_efdctsi(CPUPPCState
*env
, uint64_t val
)
1445 /* NaN are not treated the same way IEEE 754 does */
1446 if (unlikely(float64_is_any_nan(u
.d
))) {
1450 return float64_to_int32(u
.d
, &env
->vec_status
);
1453 uint32_t helper_efdctui(CPUPPCState
*env
, uint64_t val
)
1458 /* NaN are not treated the same way IEEE 754 does */
1459 if (unlikely(float64_is_any_nan(u
.d
))) {
1463 return float64_to_uint32(u
.d
, &env
->vec_status
);
1466 uint32_t helper_efdctsiz(CPUPPCState
*env
, uint64_t val
)
1471 /* NaN are not treated the same way IEEE 754 does */
1472 if (unlikely(float64_is_any_nan(u
.d
))) {
1476 return float64_to_int32_round_to_zero(u
.d
, &env
->vec_status
);
1479 uint64_t helper_efdctsidz(CPUPPCState
*env
, uint64_t val
)
1484 /* NaN are not treated the same way IEEE 754 does */
1485 if (unlikely(float64_is_any_nan(u
.d
))) {
1489 return float64_to_int64_round_to_zero(u
.d
, &env
->vec_status
);
1492 uint32_t helper_efdctuiz(CPUPPCState
*env
, uint64_t val
)
1497 /* NaN are not treated the same way IEEE 754 does */
1498 if (unlikely(float64_is_any_nan(u
.d
))) {
1502 return float64_to_uint32_round_to_zero(u
.d
, &env
->vec_status
);
1505 uint64_t helper_efdctuidz(CPUPPCState
*env
, uint64_t val
)
1510 /* NaN are not treated the same way IEEE 754 does */
1511 if (unlikely(float64_is_any_nan(u
.d
))) {
1515 return float64_to_uint64_round_to_zero(u
.d
, &env
->vec_status
);
1518 uint64_t helper_efdcfsf(CPUPPCState
*env
, uint32_t val
)
1523 u
.d
= int32_to_float64(val
, &env
->vec_status
);
1524 tmp
= int64_to_float64(1ULL << 32, &env
->vec_status
);
1525 u
.d
= float64_div(u
.d
, tmp
, &env
->vec_status
);
1530 uint64_t helper_efdcfuf(CPUPPCState
*env
, uint32_t val
)
1535 u
.d
= uint32_to_float64(val
, &env
->vec_status
);
1536 tmp
= int64_to_float64(1ULL << 32, &env
->vec_status
);
1537 u
.d
= float64_div(u
.d
, tmp
, &env
->vec_status
);
1542 uint32_t helper_efdctsf(CPUPPCState
*env
, uint64_t val
)
1548 /* NaN are not treated the same way IEEE 754 does */
1549 if (unlikely(float64_is_any_nan(u
.d
))) {
1552 tmp
= uint64_to_float64(1ULL << 32, &env
->vec_status
);
1553 u
.d
= float64_mul(u
.d
, tmp
, &env
->vec_status
);
1555 return float64_to_int32(u
.d
, &env
->vec_status
);
1558 uint32_t helper_efdctuf(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
))) {
1568 tmp
= uint64_to_float64(1ULL << 32, &env
->vec_status
);
1569 u
.d
= float64_mul(u
.d
, tmp
, &env
->vec_status
);
1571 return float64_to_uint32(u
.d
, &env
->vec_status
);
1574 uint32_t helper_efscfd(CPUPPCState
*env
, uint64_t val
)
1580 u2
.f
= float64_to_float32(u1
.d
, &env
->vec_status
);
1585 uint64_t helper_efdcfs(CPUPPCState
*env
, uint32_t val
)
1591 u2
.d
= float32_to_float64(u1
.f
, &env
->vec_status
);
1596 /* Double precision fixed-point arithmetic */
1597 uint64_t helper_efdadd(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1603 u1
.d
= float64_add(u1
.d
, u2
.d
, &env
->vec_status
);
1607 uint64_t helper_efdsub(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1613 u1
.d
= float64_sub(u1
.d
, u2
.d
, &env
->vec_status
);
1617 uint64_t helper_efdmul(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1623 u1
.d
= float64_mul(u1
.d
, u2
.d
, &env
->vec_status
);
1627 uint64_t helper_efddiv(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1633 u1
.d
= float64_div(u1
.d
, u2
.d
, &env
->vec_status
);
1637 /* Double precision floating point helpers */
1638 uint32_t helper_efdtstlt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1644 return float64_lt(u1
.d
, u2
.d
, &env
->vec_status
) ? 4 : 0;
1647 uint32_t helper_efdtstgt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1653 return float64_le(u1
.d
, u2
.d
, &env
->vec_status
) ? 0 : 4;
1656 uint32_t helper_efdtsteq(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1662 return float64_eq_quiet(u1
.d
, u2
.d
, &env
->vec_status
) ? 4 : 0;
1665 uint32_t helper_efdcmplt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1667 /* XXX: TODO: test special values (NaN, infinites, ...) */
1668 return helper_efdtstlt(env
, op1
, op2
);
1671 uint32_t helper_efdcmpgt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1673 /* XXX: TODO: test special values (NaN, infinites, ...) */
1674 return helper_efdtstgt(env
, op1
, op2
);
1677 uint32_t helper_efdcmpeq(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1679 /* XXX: TODO: test special values (NaN, infinites, ...) */
1680 return helper_efdtsteq(env
, op1
, op2
);
1683 #define float64_to_float64(x, env) x
1687 * VSX_ADD_SUB - VSX floating point add/subtract
1688 * name - instruction mnemonic
1689 * op - operation (add or sub)
1690 * nels - number of elements (1, 2 or 4)
1691 * tp - type (float32 or float64)
1692 * fld - vsr_t field (VsrD(*) or VsrW(*))
1695 #define VSX_ADD_SUB(name, op, nels, tp, fld, sfprf, r2sp) \
1696 void helper_##name(CPUPPCState *env, ppc_vsr_t *xt, \
1697 ppc_vsr_t *xa, ppc_vsr_t *xb) \
1699 ppc_vsr_t t = { }; \
1702 helper_reset_fpstatus(env); \
1704 for (i = 0; i < nels; i++) { \
1705 float_status tstat = env->fp_status; \
1706 set_float_exception_flags(0, &tstat); \
1707 t.fld = tp##_##op(xa->fld, xb->fld, &tstat); \
1708 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1710 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1711 float_invalid_op_addsub(env, tstat.float_exception_flags, \
1716 t.fld = do_frsp(env, t.fld, GETPC()); \
1720 helper_compute_fprf_float64(env, t.fld); \
1724 do_float_check_status(env, GETPC()); \
1727 VSX_ADD_SUB(xsadddp
, add
, 1, float64
, VsrD(0), 1, 0)
1728 VSX_ADD_SUB(xsaddsp
, add
, 1, float64
, VsrD(0), 1, 1)
1729 VSX_ADD_SUB(xvadddp
, add
, 2, float64
, VsrD(i
), 0, 0)
1730 VSX_ADD_SUB(xvaddsp
, add
, 4, float32
, VsrW(i
), 0, 0)
1731 VSX_ADD_SUB(xssubdp
, sub
, 1, float64
, VsrD(0), 1, 0)
1732 VSX_ADD_SUB(xssubsp
, sub
, 1, float64
, VsrD(0), 1, 1)
1733 VSX_ADD_SUB(xvsubdp
, sub
, 2, float64
, VsrD(i
), 0, 0)
1734 VSX_ADD_SUB(xvsubsp
, sub
, 4, float32
, VsrW(i
), 0, 0)
1736 void helper_xsaddqp(CPUPPCState
*env
, uint32_t opcode
,
1737 ppc_vsr_t
*xt
, ppc_vsr_t
*xa
, ppc_vsr_t
*xb
)
1742 helper_reset_fpstatus(env
);
1744 tstat
= env
->fp_status
;
1745 if (unlikely(Rc(opcode
) != 0)) {
1746 tstat
.float_rounding_mode
= float_round_to_odd
;
1749 set_float_exception_flags(0, &tstat
);
1750 t
.f128
= float128_add(xa
->f128
, xb
->f128
, &tstat
);
1751 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
1753 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
1754 float_invalid_op_addsub(env
, tstat
.float_exception_flags
, 1, GETPC());
1757 helper_compute_fprf_float128(env
, t
.f128
);
1760 do_float_check_status(env
, GETPC());
1764 * VSX_MUL - VSX floating point multiply
1765 * op - instruction mnemonic
1766 * nels - number of elements (1, 2 or 4)
1767 * tp - type (float32 or float64)
1768 * fld - vsr_t field (VsrD(*) or VsrW(*))
1771 #define VSX_MUL(op, nels, tp, fld, sfprf, r2sp) \
1772 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
1773 ppc_vsr_t *xa, ppc_vsr_t *xb) \
1775 ppc_vsr_t t = { }; \
1778 helper_reset_fpstatus(env); \
1780 for (i = 0; i < nels; i++) { \
1781 float_status tstat = env->fp_status; \
1782 set_float_exception_flags(0, &tstat); \
1783 t.fld = tp##_mul(xa->fld, xb->fld, &tstat); \
1784 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1786 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1787 float_invalid_op_mul(env, tstat.float_exception_flags, \
1792 t.fld = do_frsp(env, t.fld, GETPC()); \
1796 helper_compute_fprf_float64(env, t.fld); \
1801 do_float_check_status(env, GETPC()); \
1804 VSX_MUL(xsmuldp
, 1, float64
, VsrD(0), 1, 0)
1805 VSX_MUL(xsmulsp
, 1, float64
, VsrD(0), 1, 1)
1806 VSX_MUL(xvmuldp
, 2, float64
, VsrD(i
), 0, 0)
1807 VSX_MUL(xvmulsp
, 4, float32
, VsrW(i
), 0, 0)
1809 void helper_xsmulqp(CPUPPCState
*env
, uint32_t opcode
,
1810 ppc_vsr_t
*xt
, ppc_vsr_t
*xa
, ppc_vsr_t
*xb
)
1815 helper_reset_fpstatus(env
);
1816 tstat
= env
->fp_status
;
1817 if (unlikely(Rc(opcode
) != 0)) {
1818 tstat
.float_rounding_mode
= float_round_to_odd
;
1821 set_float_exception_flags(0, &tstat
);
1822 t
.f128
= float128_mul(xa
->f128
, xb
->f128
, &tstat
);
1823 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
1825 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
1826 float_invalid_op_mul(env
, tstat
.float_exception_flags
, 1, GETPC());
1828 helper_compute_fprf_float128(env
, t
.f128
);
1831 do_float_check_status(env
, GETPC());
1835 * VSX_DIV - VSX floating point divide
1836 * op - instruction mnemonic
1837 * nels - number of elements (1, 2 or 4)
1838 * tp - type (float32 or float64)
1839 * fld - vsr_t field (VsrD(*) or VsrW(*))
1842 #define VSX_DIV(op, nels, tp, fld, sfprf, r2sp) \
1843 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
1844 ppc_vsr_t *xa, ppc_vsr_t *xb) \
1846 ppc_vsr_t t = { }; \
1849 helper_reset_fpstatus(env); \
1851 for (i = 0; i < nels; i++) { \
1852 float_status tstat = env->fp_status; \
1853 set_float_exception_flags(0, &tstat); \
1854 t.fld = tp##_div(xa->fld, xb->fld, &tstat); \
1855 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1857 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1858 float_invalid_op_div(env, tstat.float_exception_flags, \
1861 if (unlikely(tstat.float_exception_flags & float_flag_divbyzero)) { \
1862 float_zero_divide_excp(env, GETPC()); \
1866 t.fld = do_frsp(env, t.fld, GETPC()); \
1870 helper_compute_fprf_float64(env, t.fld); \
1875 do_float_check_status(env, GETPC()); \
1878 VSX_DIV(xsdivdp
, 1, float64
, VsrD(0), 1, 0)
1879 VSX_DIV(xsdivsp
, 1, float64
, VsrD(0), 1, 1)
1880 VSX_DIV(xvdivdp
, 2, float64
, VsrD(i
), 0, 0)
1881 VSX_DIV(xvdivsp
, 4, float32
, VsrW(i
), 0, 0)
1883 void helper_xsdivqp(CPUPPCState
*env
, uint32_t opcode
,
1884 ppc_vsr_t
*xt
, ppc_vsr_t
*xa
, ppc_vsr_t
*xb
)
1889 helper_reset_fpstatus(env
);
1890 tstat
= env
->fp_status
;
1891 if (unlikely(Rc(opcode
) != 0)) {
1892 tstat
.float_rounding_mode
= float_round_to_odd
;
1895 set_float_exception_flags(0, &tstat
);
1896 t
.f128
= float128_div(xa
->f128
, xb
->f128
, &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_div(env
, tstat
.float_exception_flags
, 1, GETPC());
1902 if (unlikely(tstat
.float_exception_flags
& float_flag_divbyzero
)) {
1903 float_zero_divide_excp(env
, GETPC());
1906 helper_compute_fprf_float128(env
, t
.f128
);
1908 do_float_check_status(env
, GETPC());
1912 * VSX_RE - VSX floating point reciprocal estimate
1913 * op - instruction mnemonic
1914 * nels - number of elements (1, 2 or 4)
1915 * tp - type (float32 or float64)
1916 * fld - vsr_t field (VsrD(*) or VsrW(*))
1919 #define VSX_RE(op, nels, tp, fld, sfprf, r2sp) \
1920 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
1922 ppc_vsr_t t = { }; \
1925 helper_reset_fpstatus(env); \
1927 for (i = 0; i < nels; i++) { \
1928 if (unlikely(tp##_is_signaling_nan(xb->fld, &env->fp_status))) { \
1929 float_invalid_op_vxsnan(env, GETPC()); \
1931 t.fld = tp##_div(tp##_one, xb->fld, &env->fp_status); \
1934 t.fld = do_frsp(env, t.fld, GETPC()); \
1938 helper_compute_fprf_float64(env, t.fld); \
1943 do_float_check_status(env, GETPC()); \
1946 VSX_RE(xsredp
, 1, float64
, VsrD(0), 1, 0)
1947 VSX_RE(xsresp
, 1, float64
, VsrD(0), 1, 1)
1948 VSX_RE(xvredp
, 2, float64
, VsrD(i
), 0, 0)
1949 VSX_RE(xvresp
, 4, float32
, VsrW(i
), 0, 0)
1952 * VSX_SQRT - VSX floating point square root
1953 * op - instruction mnemonic
1954 * nels - number of elements (1, 2 or 4)
1955 * tp - type (float32 or float64)
1956 * fld - vsr_t field (VsrD(*) or VsrW(*))
1959 #define VSX_SQRT(op, nels, tp, fld, sfprf, r2sp) \
1960 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
1962 ppc_vsr_t t = { }; \
1965 helper_reset_fpstatus(env); \
1967 for (i = 0; i < nels; i++) { \
1968 float_status tstat = env->fp_status; \
1969 set_float_exception_flags(0, &tstat); \
1970 t.fld = tp##_sqrt(xb->fld, &tstat); \
1971 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1973 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1974 float_invalid_op_sqrt(env, tstat.float_exception_flags, \
1979 t.fld = do_frsp(env, t.fld, GETPC()); \
1983 helper_compute_fprf_float64(env, t.fld); \
1988 do_float_check_status(env, GETPC()); \
1991 VSX_SQRT(xssqrtdp
, 1, float64
, VsrD(0), 1, 0)
1992 VSX_SQRT(xssqrtsp
, 1, float64
, VsrD(0), 1, 1)
1993 VSX_SQRT(xvsqrtdp
, 2, float64
, VsrD(i
), 0, 0)
1994 VSX_SQRT(xvsqrtsp
, 4, float32
, VsrW(i
), 0, 0)
1997 *VSX_RSQRTE - VSX floating point reciprocal square root estimate
1998 * op - instruction mnemonic
1999 * nels - number of elements (1, 2 or 4)
2000 * tp - type (float32 or float64)
2001 * fld - vsr_t field (VsrD(*) or VsrW(*))
2004 #define VSX_RSQRTE(op, nels, tp, fld, sfprf, r2sp) \
2005 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
2007 ppc_vsr_t t = { }; \
2010 helper_reset_fpstatus(env); \
2012 for (i = 0; i < nels; i++) { \
2013 float_status tstat = env->fp_status; \
2014 set_float_exception_flags(0, &tstat); \
2015 t.fld = tp##_sqrt(xb->fld, &tstat); \
2016 t.fld = tp##_div(tp##_one, t.fld, &tstat); \
2017 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
2018 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
2019 float_invalid_op_sqrt(env, tstat.float_exception_flags, \
2023 t.fld = do_frsp(env, t.fld, GETPC()); \
2027 helper_compute_fprf_float64(env, t.fld); \
2032 do_float_check_status(env, GETPC()); \
2035 VSX_RSQRTE(xsrsqrtedp
, 1, float64
, VsrD(0), 1, 0)
2036 VSX_RSQRTE(xsrsqrtesp
, 1, float64
, VsrD(0), 1, 1)
2037 VSX_RSQRTE(xvrsqrtedp
, 2, float64
, VsrD(i
), 0, 0)
2038 VSX_RSQRTE(xvrsqrtesp
, 4, float32
, VsrW(i
), 0, 0)
2041 * VSX_TDIV - VSX floating point test for divide
2042 * op - instruction mnemonic
2043 * nels - number of elements (1, 2 or 4)
2044 * tp - type (float32 or float64)
2045 * fld - vsr_t field (VsrD(*) or VsrW(*))
2046 * emin - minimum unbiased exponent
2047 * emax - maximum unbiased exponent
2048 * nbits - number of fraction bits
2050 #define VSX_TDIV(op, nels, tp, fld, emin, emax, nbits) \
2051 void helper_##op(CPUPPCState *env, uint32_t opcode, \
2052 ppc_vsr_t *xa, ppc_vsr_t *xb) \
2058 for (i = 0; i < nels; i++) { \
2059 if (unlikely(tp##_is_infinity(xa->fld) || \
2060 tp##_is_infinity(xb->fld) || \
2061 tp##_is_zero(xb->fld))) { \
2065 int e_a = ppc_##tp##_get_unbiased_exp(xa->fld); \
2066 int e_b = ppc_##tp##_get_unbiased_exp(xb->fld); \
2068 if (unlikely(tp##_is_any_nan(xa->fld) || \
2069 tp##_is_any_nan(xb->fld))) { \
2071 } else if ((e_b <= emin) || (e_b >= (emax - 2))) { \
2073 } else if (!tp##_is_zero(xa->fld) && \
2074 (((e_a - e_b) >= emax) || \
2075 ((e_a - e_b) <= (emin + 1)) || \
2076 (e_a <= (emin + nbits)))) { \
2080 if (unlikely(tp##_is_zero_or_denormal(xb->fld))) { \
2082 * XB is not zero because of the above check and so \
2083 * must be denormalized. \
2090 env->crf[BF(opcode)] = 0x8 | (fg_flag ? 4 : 0) | (fe_flag ? 2 : 0); \
2093 VSX_TDIV(xstdivdp
, 1, float64
, VsrD(0), -1022, 1023, 52)
2094 VSX_TDIV(xvtdivdp
, 2, float64
, VsrD(i
), -1022, 1023, 52)
2095 VSX_TDIV(xvtdivsp
, 4, float32
, VsrW(i
), -126, 127, 23)
2098 * VSX_TSQRT - VSX floating point test for square root
2099 * op - instruction mnemonic
2100 * nels - number of elements (1, 2 or 4)
2101 * tp - type (float32 or float64)
2102 * fld - vsr_t field (VsrD(*) or VsrW(*))
2103 * emin - minimum unbiased exponent
2104 * emax - maximum unbiased exponent
2105 * nbits - number of fraction bits
2107 #define VSX_TSQRT(op, nels, tp, fld, emin, nbits) \
2108 void helper_##op(CPUPPCState *env, uint32_t opcode, ppc_vsr_t *xb) \
2114 for (i = 0; i < nels; i++) { \
2115 if (unlikely(tp##_is_infinity(xb->fld) || \
2116 tp##_is_zero(xb->fld))) { \
2120 int e_b = ppc_##tp##_get_unbiased_exp(xb->fld); \
2122 if (unlikely(tp##_is_any_nan(xb->fld))) { \
2124 } else if (unlikely(tp##_is_zero(xb->fld))) { \
2126 } else if (unlikely(tp##_is_neg(xb->fld))) { \
2128 } else if (!tp##_is_zero(xb->fld) && \
2129 (e_b <= (emin + nbits))) { \
2133 if (unlikely(tp##_is_zero_or_denormal(xb->fld))) { \
2135 * XB is not zero because of the above check and \
2136 * therefore must be denormalized. \
2143 env->crf[BF(opcode)] = 0x8 | (fg_flag ? 4 : 0) | (fe_flag ? 2 : 0); \
2146 VSX_TSQRT(xstsqrtdp
, 1, float64
, VsrD(0), -1022, 52)
2147 VSX_TSQRT(xvtsqrtdp
, 2, float64
, VsrD(i
), -1022, 52)
2148 VSX_TSQRT(xvtsqrtsp
, 4, float32
, VsrW(i
), -126, 23)
2151 * VSX_MADD - VSX floating point muliply/add variations
2152 * op - instruction mnemonic
2153 * nels - number of elements (1, 2 or 4)
2154 * tp - type (float32 or float64)
2155 * fld - vsr_t field (VsrD(*) or VsrW(*))
2156 * maddflgs - flags for the float*muladd routine that control the
2157 * various forms (madd, msub, nmadd, nmsub)
2160 #define VSX_MADD(op, nels, tp, fld, maddflgs, sfprf) \
2161 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
2162 ppc_vsr_t *s1, ppc_vsr_t *s2, ppc_vsr_t *s3) \
2164 ppc_vsr_t t = *xt; \
2167 helper_reset_fpstatus(env); \
2169 for (i = 0; i < nels; i++) { \
2170 float_status tstat = env->fp_status; \
2171 set_float_exception_flags(0, &tstat); \
2172 t.fld = tp##_muladd(s1->fld, s3->fld, s2->fld, maddflgs, &tstat); \
2173 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
2175 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
2176 float_invalid_op_madd(env, tstat.float_exception_flags, \
2181 helper_compute_fprf_float64(env, t.fld); \
2185 do_float_check_status(env, GETPC()); \
2188 VSX_MADD(XSMADDDP
, 1, float64
, VsrD(0), MADD_FLGS
, 1)
2189 VSX_MADD(XSMSUBDP
, 1, float64
, VsrD(0), MSUB_FLGS
, 1)
2190 VSX_MADD(XSNMADDDP
, 1, float64
, VsrD(0), NMADD_FLGS
, 1)
2191 VSX_MADD(XSNMSUBDP
, 1, float64
, VsrD(0), NMSUB_FLGS
, 1)
2192 VSX_MADD(XSMADDSP
, 1, float64r32
, VsrD(0), MADD_FLGS
, 1)
2193 VSX_MADD(XSMSUBSP
, 1, float64r32
, VsrD(0), MSUB_FLGS
, 1)
2194 VSX_MADD(XSNMADDSP
, 1, float64r32
, VsrD(0), NMADD_FLGS
, 1)
2195 VSX_MADD(XSNMSUBSP
, 1, float64r32
, VsrD(0), NMSUB_FLGS
, 1)
2197 VSX_MADD(xvmadddp
, 2, float64
, VsrD(i
), MADD_FLGS
, 0)
2198 VSX_MADD(xvmsubdp
, 2, float64
, VsrD(i
), MSUB_FLGS
, 0)
2199 VSX_MADD(xvnmadddp
, 2, float64
, VsrD(i
), NMADD_FLGS
, 0)
2200 VSX_MADD(xvnmsubdp
, 2, float64
, VsrD(i
), NMSUB_FLGS
, 0)
2202 VSX_MADD(xvmaddsp
, 4, float32
, VsrW(i
), MADD_FLGS
, 0)
2203 VSX_MADD(xvmsubsp
, 4, float32
, VsrW(i
), MSUB_FLGS
, 0)
2204 VSX_MADD(xvnmaddsp
, 4, float32
, VsrW(i
), NMADD_FLGS
, 0)
2205 VSX_MADD(xvnmsubsp
, 4, float32
, VsrW(i
), NMSUB_FLGS
, 0)
2208 * VSX_MADDQ - VSX floating point quad-precision muliply/add
2209 * op - instruction mnemonic
2210 * maddflgs - flags for the float*muladd routine that control the
2211 * various forms (madd, msub, nmadd, nmsub)
2214 #define VSX_MADDQ(op, maddflgs, ro) \
2215 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *s1, ppc_vsr_t *s2,\
2218 ppc_vsr_t t = *xt; \
2220 helper_reset_fpstatus(env); \
2222 float_status tstat = env->fp_status; \
2223 set_float_exception_flags(0, &tstat); \
2225 tstat.float_rounding_mode = float_round_to_odd; \
2227 t.f128 = float128_muladd(s1->f128, s3->f128, s2->f128, maddflgs, &tstat); \
2228 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
2230 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
2231 float_invalid_op_madd(env, tstat.float_exception_flags, \
2235 helper_compute_fprf_float128(env, t.f128); \
2237 do_float_check_status(env, GETPC()); \
2240 VSX_MADDQ(XSMADDQP
, MADD_FLGS
, 0)
2241 VSX_MADDQ(XSMADDQPO
, MADD_FLGS
, 1)
2242 VSX_MADDQ(XSMSUBQP
, MSUB_FLGS
, 0)
2243 VSX_MADDQ(XSMSUBQPO
, MSUB_FLGS
, 1)
2244 VSX_MADDQ(XSNMADDQP
, NMADD_FLGS
, 0)
2245 VSX_MADDQ(XSNMADDQPO
, NMADD_FLGS
, 1)
2246 VSX_MADDQ(XSNMSUBQP
, NMSUB_FLGS
, 0)
2247 VSX_MADDQ(XSNMSUBQPO
, NMSUB_FLGS
, 0)
2250 * VSX_SCALAR_CMP - VSX scalar floating point compare
2251 * op - instruction mnemonic
2253 * cmp - comparison operation
2255 * svxvc - set VXVC bit
2257 #define VSX_SCALAR_CMP(op, tp, cmp, fld, svxvc) \
2258 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
2259 ppc_vsr_t *xa, ppc_vsr_t *xb) \
2264 helper_reset_fpstatus(env); \
2267 r = tp##_##cmp(xb->fld, xa->fld, &env->fp_status); \
2269 r = tp##_##cmp##_quiet(xb->fld, xa->fld, &env->fp_status); \
2272 flags = get_float_exception_flags(&env->fp_status); \
2273 if (unlikely(flags & float_flag_invalid)) { \
2275 if (flags & float_flag_invalid_snan) { \
2276 float_invalid_op_vxsnan(env, GETPC()); \
2277 vxvc &= !(env->fpscr & FP_VE); \
2280 float_invalid_op_vxvc(env, 0, GETPC()); \
2284 memset(xt, 0, sizeof(*xt)); \
2285 memset(&xt->fld, -r, sizeof(xt->fld)); \
2286 do_float_check_status(env, GETPC()); \
2289 VSX_SCALAR_CMP(XSCMPEQDP
, float64
, eq
, VsrD(0), 0)
2290 VSX_SCALAR_CMP(XSCMPGEDP
, float64
, le
, VsrD(0), 1)
2291 VSX_SCALAR_CMP(XSCMPGTDP
, float64
, lt
, VsrD(0), 1)
2292 VSX_SCALAR_CMP(XSCMPEQQP
, float128
, eq
, f128
, 0)
2293 VSX_SCALAR_CMP(XSCMPGEQP
, float128
, le
, f128
, 1)
2294 VSX_SCALAR_CMP(XSCMPGTQP
, float128
, lt
, f128
, 1)
2296 void helper_xscmpexpdp(CPUPPCState
*env
, uint32_t opcode
,
2297 ppc_vsr_t
*xa
, ppc_vsr_t
*xb
)
2299 int64_t exp_a
, exp_b
;
2302 exp_a
= extract64(xa
->VsrD(0), 52, 11);
2303 exp_b
= extract64(xb
->VsrD(0), 52, 11);
2305 if (unlikely(float64_is_any_nan(xa
->VsrD(0)) ||
2306 float64_is_any_nan(xb
->VsrD(0)))) {
2309 if (exp_a
< exp_b
) {
2311 } else if (exp_a
> exp_b
) {
2318 env
->fpscr
&= ~FP_FPCC
;
2319 env
->fpscr
|= cc
<< FPSCR_FPCC
;
2320 env
->crf
[BF(opcode
)] = cc
;
2322 do_float_check_status(env
, GETPC());
2325 void helper_xscmpexpqp(CPUPPCState
*env
, uint32_t opcode
,
2326 ppc_vsr_t
*xa
, ppc_vsr_t
*xb
)
2328 int64_t exp_a
, exp_b
;
2331 exp_a
= extract64(xa
->VsrD(0), 48, 15);
2332 exp_b
= extract64(xb
->VsrD(0), 48, 15);
2334 if (unlikely(float128_is_any_nan(xa
->f128
) ||
2335 float128_is_any_nan(xb
->f128
))) {
2338 if (exp_a
< exp_b
) {
2340 } else if (exp_a
> exp_b
) {
2347 env
->fpscr
&= ~FP_FPCC
;
2348 env
->fpscr
|= cc
<< FPSCR_FPCC
;
2349 env
->crf
[BF(opcode
)] = cc
;
2351 do_float_check_status(env
, GETPC());
2354 static inline void do_scalar_cmp(CPUPPCState
*env
, ppc_vsr_t
*xa
, ppc_vsr_t
*xb
,
2355 int crf_idx
, bool ordered
)
2358 bool vxsnan_flag
= false, vxvc_flag
= false;
2360 helper_reset_fpstatus(env
);
2362 switch (float64_compare(xa
->VsrD(0), xb
->VsrD(0), &env
->fp_status
)) {
2363 case float_relation_less
:
2366 case float_relation_equal
:
2369 case float_relation_greater
:
2372 case float_relation_unordered
:
2375 if (float64_is_signaling_nan(xa
->VsrD(0), &env
->fp_status
) ||
2376 float64_is_signaling_nan(xb
->VsrD(0), &env
->fp_status
)) {
2378 if (!(env
->fpscr
& FP_VE
) && ordered
) {
2381 } else if (float64_is_quiet_nan(xa
->VsrD(0), &env
->fp_status
) ||
2382 float64_is_quiet_nan(xb
->VsrD(0), &env
->fp_status
)) {
2390 g_assert_not_reached();
2393 env
->fpscr
&= ~FP_FPCC
;
2394 env
->fpscr
|= cc
<< FPSCR_FPCC
;
2395 env
->crf
[crf_idx
] = cc
;
2398 float_invalid_op_vxsnan(env
, GETPC());
2401 float_invalid_op_vxvc(env
, 0, GETPC());
2404 do_float_check_status(env
, GETPC());
2407 void helper_xscmpodp(CPUPPCState
*env
, uint32_t opcode
, ppc_vsr_t
*xa
,
2410 do_scalar_cmp(env
, xa
, xb
, BF(opcode
), true);
2413 void helper_xscmpudp(CPUPPCState
*env
, uint32_t opcode
, ppc_vsr_t
*xa
,
2416 do_scalar_cmp(env
, xa
, xb
, BF(opcode
), false);
2419 static inline void do_scalar_cmpq(CPUPPCState
*env
, ppc_vsr_t
*xa
,
2420 ppc_vsr_t
*xb
, int crf_idx
, bool ordered
)
2423 bool vxsnan_flag
= false, vxvc_flag
= false;
2425 helper_reset_fpstatus(env
);
2427 switch (float128_compare(xa
->f128
, xb
->f128
, &env
->fp_status
)) {
2428 case float_relation_less
:
2431 case float_relation_equal
:
2434 case float_relation_greater
:
2437 case float_relation_unordered
:
2440 if (float128_is_signaling_nan(xa
->f128
, &env
->fp_status
) ||
2441 float128_is_signaling_nan(xb
->f128
, &env
->fp_status
)) {
2443 if (!(env
->fpscr
& FP_VE
) && ordered
) {
2446 } else if (float128_is_quiet_nan(xa
->f128
, &env
->fp_status
) ||
2447 float128_is_quiet_nan(xb
->f128
, &env
->fp_status
)) {
2455 g_assert_not_reached();
2458 env
->fpscr
&= ~FP_FPCC
;
2459 env
->fpscr
|= cc
<< FPSCR_FPCC
;
2460 env
->crf
[crf_idx
] = cc
;
2463 float_invalid_op_vxsnan(env
, GETPC());
2466 float_invalid_op_vxvc(env
, 0, GETPC());
2469 do_float_check_status(env
, GETPC());
2472 void helper_xscmpoqp(CPUPPCState
*env
, uint32_t opcode
, ppc_vsr_t
*xa
,
2475 do_scalar_cmpq(env
, xa
, xb
, BF(opcode
), true);
2478 void helper_xscmpuqp(CPUPPCState
*env
, uint32_t opcode
, ppc_vsr_t
*xa
,
2481 do_scalar_cmpq(env
, xa
, xb
, BF(opcode
), false);
2485 * VSX_MAX_MIN - VSX floating point maximum/minimum
2486 * name - instruction mnemonic
2487 * op - operation (max or min)
2488 * nels - number of elements (1, 2 or 4)
2489 * tp - type (float32 or float64)
2490 * fld - vsr_t field (VsrD(*) or VsrW(*))
2492 #define VSX_MAX_MIN(name, op, nels, tp, fld) \
2493 void helper_##name(CPUPPCState *env, ppc_vsr_t *xt, \
2494 ppc_vsr_t *xa, ppc_vsr_t *xb) \
2496 ppc_vsr_t t = { }; \
2499 for (i = 0; i < nels; i++) { \
2500 t.fld = tp##_##op(xa->fld, xb->fld, &env->fp_status); \
2501 if (unlikely(tp##_is_signaling_nan(xa->fld, &env->fp_status) || \
2502 tp##_is_signaling_nan(xb->fld, &env->fp_status))) { \
2503 float_invalid_op_vxsnan(env, GETPC()); \
2508 do_float_check_status(env, GETPC()); \
2511 VSX_MAX_MIN(xsmaxdp
, maxnum
, 1, float64
, VsrD(0))
2512 VSX_MAX_MIN(xvmaxdp
, maxnum
, 2, float64
, VsrD(i
))
2513 VSX_MAX_MIN(xvmaxsp
, maxnum
, 4, float32
, VsrW(i
))
2514 VSX_MAX_MIN(xsmindp
, minnum
, 1, float64
, VsrD(0))
2515 VSX_MAX_MIN(xvmindp
, minnum
, 2, float64
, VsrD(i
))
2516 VSX_MAX_MIN(xvminsp
, minnum
, 4, float32
, VsrW(i
))
2518 #define VSX_MAX_MINC(name, max, tp, fld) \
2519 void helper_##name(CPUPPCState *env, \
2520 ppc_vsr_t *xt, ppc_vsr_t *xa, ppc_vsr_t *xb) \
2522 ppc_vsr_t t = { }; \
2525 helper_reset_fpstatus(env); \
2528 first = tp##_le_quiet(xb->fld, xa->fld, &env->fp_status); \
2530 first = tp##_lt_quiet(xa->fld, xb->fld, &env->fp_status); \
2537 if (env->fp_status.float_exception_flags & float_flag_invalid_snan) { \
2538 float_invalid_op_vxsnan(env, GETPC()); \
2545 VSX_MAX_MINC(XSMAXCDP
, true, float64
, VsrD(0));
2546 VSX_MAX_MINC(XSMINCDP
, false, float64
, VsrD(0));
2547 VSX_MAX_MINC(XSMAXCQP
, true, float128
, f128
);
2548 VSX_MAX_MINC(XSMINCQP
, false, float128
, f128
);
2550 #define VSX_MAX_MINJ(name, max) \
2551 void helper_##name(CPUPPCState *env, \
2552 ppc_vsr_t *xt, ppc_vsr_t *xa, ppc_vsr_t *xb) \
2554 ppc_vsr_t t = { }; \
2555 bool vxsnan_flag = false, vex_flag = false; \
2557 if (unlikely(float64_is_any_nan(xa->VsrD(0)))) { \
2558 if (float64_is_signaling_nan(xa->VsrD(0), &env->fp_status)) { \
2559 vxsnan_flag = true; \
2561 t.VsrD(0) = xa->VsrD(0); \
2562 } else if (unlikely(float64_is_any_nan(xb->VsrD(0)))) { \
2563 if (float64_is_signaling_nan(xb->VsrD(0), &env->fp_status)) { \
2564 vxsnan_flag = true; \
2566 t.VsrD(0) = xb->VsrD(0); \
2567 } else if (float64_is_zero(xa->VsrD(0)) && \
2568 float64_is_zero(xb->VsrD(0))) { \
2570 if (!float64_is_neg(xa->VsrD(0)) || \
2571 !float64_is_neg(xb->VsrD(0))) { \
2574 t.VsrD(0) = 0x8000000000000000ULL; \
2577 if (float64_is_neg(xa->VsrD(0)) || \
2578 float64_is_neg(xb->VsrD(0))) { \
2579 t.VsrD(0) = 0x8000000000000000ULL; \
2584 } else if ((max && \
2585 !float64_lt(xa->VsrD(0), xb->VsrD(0), &env->fp_status)) || \
2587 float64_lt(xa->VsrD(0), xb->VsrD(0), &env->fp_status))) { \
2588 t.VsrD(0) = xa->VsrD(0); \
2590 t.VsrD(0) = xb->VsrD(0); \
2593 vex_flag = (env->fpscr & FP_VE) && vxsnan_flag; \
2594 if (vxsnan_flag) { \
2595 float_invalid_op_vxsnan(env, GETPC()); \
2602 VSX_MAX_MINJ(XSMAXJDP, 1);
2603 VSX_MAX_MINJ(XSMINJDP
, 0);
2606 * VSX_CMP - VSX floating point compare
2607 * op - instruction mnemonic
2608 * nels - number of elements (1, 2 or 4)
2609 * tp - type (float32 or float64)
2610 * fld - vsr_t field (VsrD(*) or VsrW(*))
2611 * cmp - comparison operation
2612 * svxvc - set VXVC bit
2613 * exp - expected result of comparison
2615 #define VSX_CMP(op, nels, tp, fld, cmp, svxvc, exp) \
2616 uint32_t helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
2617 ppc_vsr_t *xa, ppc_vsr_t *xb) \
2619 ppc_vsr_t t = *xt; \
2620 uint32_t crf6 = 0; \
2623 int all_false = 1; \
2625 for (i = 0; i < nels; i++) { \
2626 if (unlikely(tp##_is_any_nan(xa->fld) || \
2627 tp##_is_any_nan(xb->fld))) { \
2628 if (tp##_is_signaling_nan(xa->fld, &env->fp_status) || \
2629 tp##_is_signaling_nan(xb->fld, &env->fp_status)) { \
2630 float_invalid_op_vxsnan(env, GETPC()); \
2633 float_invalid_op_vxvc(env, 0, GETPC()); \
2638 if (tp##_##cmp(xb->fld, xa->fld, &env->fp_status) == exp) { \
2649 crf6 = (all_true ? 0x8 : 0) | (all_false ? 0x2 : 0); \
2653 VSX_CMP(xvcmpeqdp
, 2, float64
, VsrD(i
), eq
, 0, 1)
2654 VSX_CMP(xvcmpgedp
, 2, float64
, VsrD(i
), le
, 1, 1)
2655 VSX_CMP(xvcmpgtdp
, 2, float64
, VsrD(i
), lt
, 1, 1)
2656 VSX_CMP(xvcmpnedp
, 2, float64
, VsrD(i
), eq
, 0, 0)
2657 VSX_CMP(xvcmpeqsp
, 4, float32
, VsrW(i
), eq
, 0, 1)
2658 VSX_CMP(xvcmpgesp
, 4, float32
, VsrW(i
), le
, 1, 1)
2659 VSX_CMP(xvcmpgtsp
, 4, float32
, VsrW(i
), lt
, 1, 1)
2660 VSX_CMP(xvcmpnesp
, 4, float32
, VsrW(i
), eq
, 0, 0)
2663 * VSX_CVT_FP_TO_FP - VSX floating point/floating point conversion
2664 * op - instruction mnemonic
2665 * nels - number of elements (1, 2 or 4)
2666 * stp - source type (float32 or float64)
2667 * ttp - target type (float32 or float64)
2668 * sfld - source vsr_t field
2669 * tfld - target vsr_t field (f32 or f64)
2672 #define VSX_CVT_FP_TO_FP(op, nels, stp, ttp, sfld, tfld, sfprf) \
2673 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
2675 ppc_vsr_t t = { }; \
2678 for (i = 0; i < nels; i++) { \
2679 t.tfld = stp##_to_##ttp(xb->sfld, &env->fp_status); \
2680 if (unlikely(stp##_is_signaling_nan(xb->sfld, \
2681 &env->fp_status))) { \
2682 float_invalid_op_vxsnan(env, GETPC()); \
2683 t.tfld = ttp##_snan_to_qnan(t.tfld); \
2686 helper_compute_fprf_##ttp(env, t.tfld); \
2691 do_float_check_status(env, GETPC()); \
2694 VSX_CVT_FP_TO_FP(xscvspdp
, 1, float32
, float64
, VsrW(0), VsrD(0), 1)
2695 VSX_CVT_FP_TO_FP(xvcvspdp
, 2, float32
, float64
, VsrW(2 * i
), VsrD(i
), 0)
2697 #define VSX_CVT_FP_TO_FP2(op, nels, stp, ttp, sfprf) \
2698 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
2700 ppc_vsr_t t = { }; \
2703 for (i = 0; i < nels; i++) { \
2704 t.VsrW(2 * i) = stp##_to_##ttp(xb->VsrD(i), &env->fp_status); \
2705 if (unlikely(stp##_is_signaling_nan(xb->VsrD(i), \
2706 &env->fp_status))) { \
2707 float_invalid_op_vxsnan(env, GETPC()); \
2708 t.VsrW(2 * i) = ttp##_snan_to_qnan(t.VsrW(2 * i)); \
2711 helper_compute_fprf_##ttp(env, t.VsrW(2 * i)); \
2713 t.VsrW(2 * i + 1) = t.VsrW(2 * i); \
2717 do_float_check_status(env, GETPC()); \
2720 VSX_CVT_FP_TO_FP2(xvcvdpsp
, 2, float64
, float32
, 0)
2721 VSX_CVT_FP_TO_FP2(xscvdpsp
, 1, float64
, float32
, 1)
2724 * VSX_CVT_FP_TO_FP_VECTOR - VSX floating point/floating point conversion
2725 * op - instruction mnemonic
2726 * nels - number of elements (1, 2 or 4)
2727 * stp - source type (float32 or float64)
2728 * ttp - target type (float32 or float64)
2729 * sfld - source vsr_t field
2730 * tfld - target vsr_t field (f32 or f64)
2733 #define VSX_CVT_FP_TO_FP_VECTOR(op, nels, stp, ttp, sfld, tfld, sfprf) \
2734 void helper_##op(CPUPPCState *env, uint32_t opcode, \
2735 ppc_vsr_t *xt, ppc_vsr_t *xb) \
2737 ppc_vsr_t t = *xt; \
2740 for (i = 0; i < nels; i++) { \
2741 t.tfld = stp##_to_##ttp(xb->sfld, &env->fp_status); \
2742 if (unlikely(stp##_is_signaling_nan(xb->sfld, \
2743 &env->fp_status))) { \
2744 float_invalid_op_vxsnan(env, GETPC()); \
2745 t.tfld = ttp##_snan_to_qnan(t.tfld); \
2748 helper_compute_fprf_##ttp(env, t.tfld); \
2753 do_float_check_status(env, GETPC()); \
2756 VSX_CVT_FP_TO_FP_VECTOR(xscvdpqp
, 1, float64
, float128
, VsrD(0), f128
, 1)
2759 * VSX_CVT_FP_TO_FP_HP - VSX floating point/floating point conversion
2760 * involving one half precision value
2761 * op - instruction mnemonic
2762 * nels - number of elements (1, 2 or 4)
2765 * sfld - source vsr_t field
2766 * tfld - target vsr_t field
2769 #define VSX_CVT_FP_TO_FP_HP(op, nels, stp, ttp, sfld, tfld, sfprf) \
2770 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
2772 ppc_vsr_t t = { }; \
2775 for (i = 0; i < nels; i++) { \
2776 t.tfld = stp##_to_##ttp(xb->sfld, 1, &env->fp_status); \
2777 if (unlikely(stp##_is_signaling_nan(xb->sfld, \
2778 &env->fp_status))) { \
2779 float_invalid_op_vxsnan(env, GETPC()); \
2780 t.tfld = ttp##_snan_to_qnan(t.tfld); \
2783 helper_compute_fprf_##ttp(env, t.tfld); \
2788 do_float_check_status(env, GETPC()); \
2791 VSX_CVT_FP_TO_FP_HP(xscvdphp
, 1, float64
, float16
, VsrD(0), VsrH(3), 1)
2792 VSX_CVT_FP_TO_FP_HP(xscvhpdp
, 1, float16
, float64
, VsrH(3), VsrD(0), 1)
2793 VSX_CVT_FP_TO_FP_HP(xvcvsphp
, 4, float32
, float16
, VsrW(i
), VsrH(2 * i
+ 1), 0)
2794 VSX_CVT_FP_TO_FP_HP(xvcvhpsp
, 4, float16
, float32
, VsrH(2 * i
+ 1), VsrW(i
), 0)
2796 void helper_XVCVSPBF16(CPUPPCState
*env
, ppc_vsr_t
*xt
, ppc_vsr_t
*xb
)
2801 helper_reset_fpstatus(env
);
2803 for (i
= 0; i
< 4; i
++) {
2804 t
.VsrH(2 * i
+ 1) = float32_to_bfloat16(xb
->VsrW(i
), &env
->fp_status
);
2807 status
= get_float_exception_flags(&env
->fp_status
);
2808 if (unlikely(status
& float_flag_invalid_snan
)) {
2809 float_invalid_op_vxsnan(env
, GETPC());
2813 do_float_check_status(env
, GETPC());
2816 void helper_XSCVQPDP(CPUPPCState
*env
, uint32_t ro
, ppc_vsr_t
*xt
,
2822 tstat
= env
->fp_status
;
2824 tstat
.float_rounding_mode
= float_round_to_odd
;
2827 t
.VsrD(0) = float128_to_float64(xb
->f128
, &tstat
);
2828 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
2829 if (unlikely(float128_is_signaling_nan(xb
->f128
, &tstat
))) {
2830 float_invalid_op_vxsnan(env
, GETPC());
2831 t
.VsrD(0) = float64_snan_to_qnan(t
.VsrD(0));
2833 helper_compute_fprf_float64(env
, t
.VsrD(0));
2836 do_float_check_status(env
, GETPC());
2839 uint64_t helper_xscvdpspn(CPUPPCState
*env
, uint64_t xb
)
2841 uint64_t result
, sign
, exp
, frac
;
2843 float_status tstat
= env
->fp_status
;
2844 set_float_exception_flags(0, &tstat
);
2846 sign
= extract64(xb
, 63, 1);
2847 exp
= extract64(xb
, 52, 11);
2848 frac
= extract64(xb
, 0, 52) | 0x10000000000000ULL
;
2850 if (unlikely(exp
== 0 && extract64(frac
, 0, 52) != 0)) {
2851 /* DP denormal operand. */
2852 /* Exponent override to DP min exp. */
2854 /* Implicit bit override to 0. */
2855 frac
= deposit64(frac
, 53, 1, 0);
2858 if (unlikely(exp
< 897 && frac
!= 0)) {
2859 /* SP tiny operand. */
2860 if (897 - exp
> 63) {
2863 /* Denormalize until exp = SP min exp. */
2864 frac
>>= (897 - exp
);
2866 /* Exponent override to SP min exp - 1. */
2870 result
= sign
<< 31;
2871 result
|= extract64(exp
, 10, 1) << 30;
2872 result
|= extract64(exp
, 0, 7) << 23;
2873 result
|= extract64(frac
, 29, 23);
2875 /* hardware replicates result to both words of the doubleword result. */
2876 return (result
<< 32) | result
;
2879 uint64_t helper_xscvspdpn(CPUPPCState
*env
, uint64_t xb
)
2881 return helper_todouble(xb
>> 32);
2885 * VSX_CVT_FP_TO_INT - VSX floating point to integer conversion
2886 * op - instruction mnemonic
2887 * nels - number of elements (1, 2 or 4)
2888 * stp - source type (float32 or float64)
2889 * ttp - target type (int32, uint32, int64 or uint64)
2890 * sfld - source vsr_t field
2891 * tfld - target vsr_t field
2892 * rnan - resulting NaN
2894 #define VSX_CVT_FP_TO_INT(op, nels, stp, ttp, sfld, tfld, rnan) \
2895 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
2897 int all_flags = env->fp_status.float_exception_flags, flags; \
2898 ppc_vsr_t t = { }; \
2901 for (i = 0; i < nels; i++) { \
2902 env->fp_status.float_exception_flags = 0; \
2903 t.tfld = stp##_to_##ttp##_round_to_zero(xb->sfld, &env->fp_status); \
2904 flags = env->fp_status.float_exception_flags; \
2905 if (unlikely(flags & float_flag_invalid)) { \
2906 t.tfld = float_invalid_cvt(env, flags, t.tfld, rnan, 0, GETPC());\
2908 all_flags |= flags; \
2912 env->fp_status.float_exception_flags = all_flags; \
2913 do_float_check_status(env, GETPC()); \
2916 VSX_CVT_FP_TO_INT(xscvdpsxds
, 1, float64
, int64
, VsrD(0), VsrD(0), \
2917 0x8000000000000000ULL
)
2918 VSX_CVT_FP_TO_INT(xscvdpuxds
, 1, float64
, uint64
, VsrD(0), VsrD(0), 0ULL)
2919 VSX_CVT_FP_TO_INT(xvcvdpsxds
, 2, float64
, int64
, VsrD(i
), VsrD(i
), \
2920 0x8000000000000000ULL
)
2921 VSX_CVT_FP_TO_INT(xvcvdpuxds
, 2, float64
, uint64
, VsrD(i
), VsrD(i
), 0ULL)
2922 VSX_CVT_FP_TO_INT(xvcvspsxds
, 2, float32
, int64
, VsrW(2 * i
), VsrD(i
), \
2923 0x8000000000000000ULL
)
2924 VSX_CVT_FP_TO_INT(xvcvspsxws
, 4, float32
, int32
, VsrW(i
), VsrW(i
), 0x80000000U
)
2925 VSX_CVT_FP_TO_INT(xvcvspuxds
, 2, float32
, uint64
, VsrW(2 * i
), VsrD(i
), 0ULL)
2926 VSX_CVT_FP_TO_INT(xvcvspuxws
, 4, float32
, uint32
, VsrW(i
), VsrW(i
), 0U)
2928 #define VSX_CVT_FP_TO_INT128(op, tp, rnan) \
2929 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
2934 helper_reset_fpstatus(env); \
2935 t.s128 = float128_to_##tp##_round_to_zero(xb->f128, &env->fp_status); \
2936 flags = get_float_exception_flags(&env->fp_status); \
2937 if (unlikely(flags & float_flag_invalid)) { \
2938 t.VsrD(0) = float_invalid_cvt(env, flags, t.VsrD(0), rnan, 0, GETPC());\
2939 t.VsrD(1) = -(t.VsrD(0) & 1); \
2943 do_float_check_status(env, GETPC()); \
2946 VSX_CVT_FP_TO_INT128(XSCVQPUQZ
, uint128
, 0)
2947 VSX_CVT_FP_TO_INT128(XSCVQPSQZ
, int128
, 0x8000000000000000ULL
);
2950 * Likewise, except that the result is duplicated into both subwords.
2951 * Power ISA v3.1 has Programming Notes for these insns:
2952 * Previous versions of the architecture allowed the contents of
2953 * word 0 of the result register to be undefined. However, all
2954 * processors that support this instruction write the result into
2955 * words 0 and 1 (and words 2 and 3) of the result register, as
2956 * is required by this version of the architecture.
2958 #define VSX_CVT_FP_TO_INT2(op, nels, stp, ttp, rnan) \
2959 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
2961 int all_flags = env->fp_status.float_exception_flags, flags; \
2962 ppc_vsr_t t = { }; \
2965 for (i = 0; i < nels; i++) { \
2966 env->fp_status.float_exception_flags = 0; \
2967 t.VsrW(2 * i) = stp##_to_##ttp##_round_to_zero(xb->VsrD(i), \
2969 flags = env->fp_status.float_exception_flags; \
2970 if (unlikely(flags & float_flag_invalid)) { \
2971 t.VsrW(2 * i) = float_invalid_cvt(env, flags, t.VsrW(2 * i), \
2972 rnan, 0, GETPC()); \
2974 t.VsrW(2 * i + 1) = t.VsrW(2 * i); \
2975 all_flags |= flags; \
2979 env->fp_status.float_exception_flags = all_flags; \
2980 do_float_check_status(env, GETPC()); \
2983 VSX_CVT_FP_TO_INT2(xscvdpsxws
, 1, float64
, int32
, 0x80000000U
)
2984 VSX_CVT_FP_TO_INT2(xscvdpuxws
, 1, float64
, uint32
, 0U)
2985 VSX_CVT_FP_TO_INT2(xvcvdpsxws
, 2, float64
, int32
, 0x80000000U
)
2986 VSX_CVT_FP_TO_INT2(xvcvdpuxws
, 2, float64
, uint32
, 0U)
2989 * VSX_CVT_FP_TO_INT_VECTOR - VSX floating point to integer conversion
2990 * op - instruction mnemonic
2991 * stp - source type (float32 or float64)
2992 * ttp - target type (int32, uint32, int64 or uint64)
2993 * sfld - source vsr_t field
2994 * tfld - target vsr_t field
2995 * rnan - resulting NaN
2997 #define VSX_CVT_FP_TO_INT_VECTOR(op, stp, ttp, sfld, tfld, rnan) \
2998 void helper_##op(CPUPPCState *env, uint32_t opcode, \
2999 ppc_vsr_t *xt, ppc_vsr_t *xb) \
3001 ppc_vsr_t t = { }; \
3004 t.tfld = stp##_to_##ttp##_round_to_zero(xb->sfld, &env->fp_status); \
3005 flags = get_float_exception_flags(&env->fp_status); \
3006 if (flags & float_flag_invalid) { \
3007 t.tfld = float_invalid_cvt(env, flags, t.tfld, rnan, 0, GETPC()); \
3011 do_float_check_status(env, GETPC()); \
3014 VSX_CVT_FP_TO_INT_VECTOR(xscvqpsdz
, float128
, int64
, f128
, VsrD(0), \
3015 0x8000000000000000ULL
)
3017 VSX_CVT_FP_TO_INT_VECTOR(xscvqpswz
, float128
, int32
, f128
, VsrD(0), \
3018 0xffffffff80000000ULL
)
3019 VSX_CVT_FP_TO_INT_VECTOR(xscvqpudz
, float128
, uint64
, f128
, VsrD(0), 0x0ULL
)
3020 VSX_CVT_FP_TO_INT_VECTOR(xscvqpuwz
, float128
, uint32
, f128
, VsrD(0), 0x0ULL
)
3023 * VSX_CVT_INT_TO_FP - VSX integer to floating point conversion
3024 * op - instruction mnemonic
3025 * nels - number of elements (1, 2 or 4)
3026 * stp - source type (int32, uint32, int64 or uint64)
3027 * ttp - target type (float32 or float64)
3028 * sfld - source vsr_t field
3029 * tfld - target vsr_t field
3030 * jdef - definition of the j index (i or 2*i)
3033 #define VSX_CVT_INT_TO_FP(op, nels, stp, ttp, sfld, tfld, sfprf, r2sp) \
3034 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
3036 ppc_vsr_t t = { }; \
3039 for (i = 0; i < nels; i++) { \
3040 t.tfld = stp##_to_##ttp(xb->sfld, &env->fp_status); \
3042 t.tfld = do_frsp(env, t.tfld, GETPC()); \
3045 helper_compute_fprf_float64(env, t.tfld); \
3050 do_float_check_status(env, GETPC()); \
3053 VSX_CVT_INT_TO_FP(xscvsxddp
, 1, int64
, float64
, VsrD(0), VsrD(0), 1, 0)
3054 VSX_CVT_INT_TO_FP(xscvuxddp
, 1, uint64
, float64
, VsrD(0), VsrD(0), 1, 0)
3055 VSX_CVT_INT_TO_FP(xscvsxdsp
, 1, int64
, float64
, VsrD(0), VsrD(0), 1, 1)
3056 VSX_CVT_INT_TO_FP(xscvuxdsp
, 1, uint64
, float64
, VsrD(0), VsrD(0), 1, 1)
3057 VSX_CVT_INT_TO_FP(xvcvsxddp
, 2, int64
, float64
, VsrD(i
), VsrD(i
), 0, 0)
3058 VSX_CVT_INT_TO_FP(xvcvuxddp
, 2, uint64
, float64
, VsrD(i
), VsrD(i
), 0, 0)
3059 VSX_CVT_INT_TO_FP(xvcvsxwdp
, 2, int32
, float64
, VsrW(2 * i
), VsrD(i
), 0, 0)
3060 VSX_CVT_INT_TO_FP(xvcvuxwdp
, 2, uint64
, float64
, VsrW(2 * i
), VsrD(i
), 0, 0)
3061 VSX_CVT_INT_TO_FP(xvcvsxwsp
, 4, int32
, float32
, VsrW(i
), VsrW(i
), 0, 0)
3062 VSX_CVT_INT_TO_FP(xvcvuxwsp
, 4, uint32
, float32
, VsrW(i
), VsrW(i
), 0, 0)
3064 #define VSX_CVT_INT_TO_FP2(op, stp, ttp) \
3065 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
3067 ppc_vsr_t t = { }; \
3070 for (i = 0; i < 2; i++) { \
3071 t.VsrW(2 * i) = stp##_to_##ttp(xb->VsrD(i), &env->fp_status); \
3072 t.VsrW(2 * i + 1) = t.VsrW(2 * i); \
3076 do_float_check_status(env, GETPC()); \
3079 VSX_CVT_INT_TO_FP2(xvcvsxdsp
, int64
, float32
)
3080 VSX_CVT_INT_TO_FP2(xvcvuxdsp
, uint64
, float32
)
3082 #define VSX_CVT_INT128_TO_FP(op, tp) \
3083 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb)\
3085 helper_reset_fpstatus(env); \
3086 xt->f128 = tp##_to_float128(xb->s128, &env->fp_status); \
3087 helper_compute_fprf_float128(env, xt->f128); \
3088 do_float_check_status(env, GETPC()); \
3091 VSX_CVT_INT128_TO_FP(XSCVUQQP
, uint128
);
3092 VSX_CVT_INT128_TO_FP(XSCVSQQP
, int128
);
3095 * VSX_CVT_INT_TO_FP_VECTOR - VSX integer to floating point conversion
3096 * op - instruction mnemonic
3097 * stp - source type (int32, uint32, int64 or uint64)
3098 * ttp - target type (float32 or float64)
3099 * sfld - source vsr_t field
3100 * tfld - target vsr_t field
3102 #define VSX_CVT_INT_TO_FP_VECTOR(op, stp, ttp, sfld, tfld) \
3103 void helper_##op(CPUPPCState *env, uint32_t opcode, \
3104 ppc_vsr_t *xt, ppc_vsr_t *xb) \
3106 ppc_vsr_t t = *xt; \
3108 t.tfld = stp##_to_##ttp(xb->sfld, &env->fp_status); \
3109 helper_compute_fprf_##ttp(env, t.tfld); \
3112 do_float_check_status(env, GETPC()); \
3115 VSX_CVT_INT_TO_FP_VECTOR(xscvsdqp
, int64
, float128
, VsrD(0), f128
)
3116 VSX_CVT_INT_TO_FP_VECTOR(xscvudqp
, uint64
, float128
, VsrD(0), f128
)
3119 * For "use current rounding mode", define a value that will not be
3120 * one of the existing rounding model enums.
3122 #define FLOAT_ROUND_CURRENT (float_round_nearest_even + float_round_down + \
3123 float_round_up + float_round_to_zero)
3126 * VSX_ROUND - VSX floating point round
3127 * op - instruction mnemonic
3128 * nels - number of elements (1, 2 or 4)
3129 * tp - type (float32 or float64)
3130 * fld - vsr_t field (VsrD(*) or VsrW(*))
3131 * rmode - rounding mode
3134 #define VSX_ROUND(op, nels, tp, fld, rmode, sfprf) \
3135 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
3137 ppc_vsr_t t = { }; \
3139 FloatRoundMode curr_rounding_mode; \
3141 if (rmode != FLOAT_ROUND_CURRENT) { \
3142 curr_rounding_mode = get_float_rounding_mode(&env->fp_status); \
3143 set_float_rounding_mode(rmode, &env->fp_status); \
3146 for (i = 0; i < nels; i++) { \
3147 if (unlikely(tp##_is_signaling_nan(xb->fld, \
3148 &env->fp_status))) { \
3149 float_invalid_op_vxsnan(env, GETPC()); \
3150 t.fld = tp##_snan_to_qnan(xb->fld); \
3152 t.fld = tp##_round_to_int(xb->fld, &env->fp_status); \
3155 helper_compute_fprf_float64(env, t.fld); \
3160 * If this is not a "use current rounding mode" instruction, \
3161 * then inhibit setting of the XX bit and restore rounding \
3164 if (rmode != FLOAT_ROUND_CURRENT) { \
3165 set_float_rounding_mode(curr_rounding_mode, &env->fp_status); \
3166 env->fp_status.float_exception_flags &= ~float_flag_inexact; \
3170 do_float_check_status(env, GETPC()); \
3173 VSX_ROUND(xsrdpi
, 1, float64
, VsrD(0), float_round_ties_away
, 1)
3174 VSX_ROUND(xsrdpic
, 1, float64
, VsrD(0), FLOAT_ROUND_CURRENT
, 1)
3175 VSX_ROUND(xsrdpim
, 1, float64
, VsrD(0), float_round_down
, 1)
3176 VSX_ROUND(xsrdpip
, 1, float64
, VsrD(0), float_round_up
, 1)
3177 VSX_ROUND(xsrdpiz
, 1, float64
, VsrD(0), float_round_to_zero
, 1)
3179 VSX_ROUND(xvrdpi
, 2, float64
, VsrD(i
), float_round_ties_away
, 0)
3180 VSX_ROUND(xvrdpic
, 2, float64
, VsrD(i
), FLOAT_ROUND_CURRENT
, 0)
3181 VSX_ROUND(xvrdpim
, 2, float64
, VsrD(i
), float_round_down
, 0)
3182 VSX_ROUND(xvrdpip
, 2, float64
, VsrD(i
), float_round_up
, 0)
3183 VSX_ROUND(xvrdpiz
, 2, float64
, VsrD(i
), float_round_to_zero
, 0)
3185 VSX_ROUND(xvrspi
, 4, float32
, VsrW(i
), float_round_ties_away
, 0)
3186 VSX_ROUND(xvrspic
, 4, float32
, VsrW(i
), FLOAT_ROUND_CURRENT
, 0)
3187 VSX_ROUND(xvrspim
, 4, float32
, VsrW(i
), float_round_down
, 0)
3188 VSX_ROUND(xvrspip
, 4, float32
, VsrW(i
), float_round_up
, 0)
3189 VSX_ROUND(xvrspiz
, 4, float32
, VsrW(i
), float_round_to_zero
, 0)
3191 uint64_t helper_xsrsp(CPUPPCState
*env
, uint64_t xb
)
3193 helper_reset_fpstatus(env
);
3195 uint64_t xt
= do_frsp(env
, xb
, GETPC());
3197 helper_compute_fprf_float64(env
, xt
);
3198 do_float_check_status(env
, GETPC());
3202 void helper_xvxsigsp(CPUPPCState
*env
, ppc_vsr_t
*xt
, ppc_vsr_t
*xb
)
3205 uint32_t exp
, i
, fraction
;
3207 for (i
= 0; i
< 4; i
++) {
3208 exp
= (xb
->VsrW(i
) >> 23) & 0xFF;
3209 fraction
= xb
->VsrW(i
) & 0x7FFFFF;
3210 if (exp
!= 0 && exp
!= 255) {
3211 t
.VsrW(i
) = fraction
| 0x00800000;
3213 t
.VsrW(i
) = fraction
;
3220 * VSX_TEST_DC - VSX floating point test data class
3221 * op - instruction mnemonic
3222 * nels - number of elements (1, 2 or 4)
3223 * xbn - VSR register number
3224 * tp - type (float32 or float64)
3225 * fld - vsr_t field (VsrD(*) or VsrW(*))
3226 * tfld - target vsr_t field (VsrD(*) or VsrW(*))
3227 * fld_max - target field max
3228 * scrf - set result in CR and FPCC
3230 #define VSX_TEST_DC(op, nels, xbn, tp, fld, tfld, fld_max, scrf) \
3231 void helper_##op(CPUPPCState *env, uint32_t opcode) \
3233 ppc_vsr_t *xt = &env->vsr[xT(opcode)]; \
3234 ppc_vsr_t *xb = &env->vsr[xbn]; \
3235 ppc_vsr_t t = { }; \
3236 uint32_t i, sign, dcmx; \
3237 uint32_t cc, match = 0; \
3240 dcmx = DCMX_XV(opcode); \
3243 dcmx = DCMX(opcode); \
3246 for (i = 0; i < nels; i++) { \
3247 sign = tp##_is_neg(xb->fld); \
3248 if (tp##_is_any_nan(xb->fld)) { \
3249 match = extract32(dcmx, 6, 1); \
3250 } else if (tp##_is_infinity(xb->fld)) { \
3251 match = extract32(dcmx, 4 + !sign, 1); \
3252 } else if (tp##_is_zero(xb->fld)) { \
3253 match = extract32(dcmx, 2 + !sign, 1); \
3254 } else if (tp##_is_zero_or_denormal(xb->fld)) { \
3255 match = extract32(dcmx, 0 + !sign, 1); \
3259 cc = sign << CRF_LT_BIT | match << CRF_EQ_BIT; \
3260 env->fpscr &= ~FP_FPCC; \
3261 env->fpscr |= cc << FPSCR_FPCC; \
3262 env->crf[BF(opcode)] = cc; \
3264 t.tfld = match ? fld_max : 0; \
3273 VSX_TEST_DC(xvtstdcdp
, 2, xB(opcode
), float64
, VsrD(i
), VsrD(i
), UINT64_MAX
, 0)
3274 VSX_TEST_DC(xvtstdcsp
, 4, xB(opcode
), float32
, VsrW(i
), VsrW(i
), UINT32_MAX
, 0)
3275 VSX_TEST_DC(xststdcdp
, 1, xB(opcode
), float64
, VsrD(0), VsrD(0), 0, 1)
3276 VSX_TEST_DC(xststdcqp
, 1, (rB(opcode
) + 32), float128
, f128
, VsrD(0), 0, 1)
3278 void helper_xststdcsp(CPUPPCState
*env
, uint32_t opcode
, ppc_vsr_t
*xb
)
3280 uint32_t dcmx
, sign
, exp
;
3281 uint32_t cc
, match
= 0, not_sp
= 0;
3282 float64 arg
= xb
->VsrD(0);
3285 dcmx
= DCMX(opcode
);
3286 exp
= (arg
>> 52) & 0x7FF;
3287 sign
= float64_is_neg(arg
);
3289 if (float64_is_any_nan(arg
)) {
3290 match
= extract32(dcmx
, 6, 1);
3291 } else if (float64_is_infinity(arg
)) {
3292 match
= extract32(dcmx
, 4 + !sign
, 1);
3293 } else if (float64_is_zero(arg
)) {
3294 match
= extract32(dcmx
, 2 + !sign
, 1);
3295 } else if (float64_is_zero_or_denormal(arg
) || (exp
> 0 && exp
< 0x381)) {
3296 match
= extract32(dcmx
, 0 + !sign
, 1);
3299 arg_sp
= helper_todouble(helper_tosingle(arg
));
3300 not_sp
= arg
!= arg_sp
;
3302 cc
= sign
<< CRF_LT_BIT
| match
<< CRF_EQ_BIT
| not_sp
<< CRF_SO_BIT
;
3303 env
->fpscr
&= ~FP_FPCC
;
3304 env
->fpscr
|= cc
<< FPSCR_FPCC
;
3305 env
->crf
[BF(opcode
)] = cc
;
3308 void helper_xsrqpi(CPUPPCState
*env
, uint32_t opcode
,
3309 ppc_vsr_t
*xt
, ppc_vsr_t
*xb
)
3312 uint8_t r
= Rrm(opcode
);
3313 uint8_t ex
= Rc(opcode
);
3314 uint8_t rmc
= RMC(opcode
);
3318 helper_reset_fpstatus(env
);
3320 if (r
== 0 && rmc
== 0) {
3321 rmode
= float_round_ties_away
;
3322 } else if (r
== 0 && rmc
== 0x3) {
3323 rmode
= env
->fpscr
& FP_RN
;
3324 } else if (r
== 1) {
3327 rmode
= float_round_nearest_even
;
3330 rmode
= float_round_to_zero
;
3333 rmode
= float_round_up
;
3336 rmode
= float_round_down
;
3343 tstat
= env
->fp_status
;
3344 set_float_exception_flags(0, &tstat
);
3345 set_float_rounding_mode(rmode
, &tstat
);
3346 t
.f128
= float128_round_to_int(xb
->f128
, &tstat
);
3347 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3349 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid_snan
)) {
3350 float_invalid_op_vxsnan(env
, GETPC());
3353 if (ex
== 0 && (tstat
.float_exception_flags
& float_flag_inexact
)) {
3354 env
->fp_status
.float_exception_flags
&= ~float_flag_inexact
;
3357 helper_compute_fprf_float128(env
, t
.f128
);
3358 do_float_check_status(env
, GETPC());
3362 void helper_xsrqpxp(CPUPPCState
*env
, uint32_t opcode
,
3363 ppc_vsr_t
*xt
, ppc_vsr_t
*xb
)
3366 uint8_t r
= Rrm(opcode
);
3367 uint8_t rmc
= RMC(opcode
);
3372 helper_reset_fpstatus(env
);
3374 if (r
== 0 && rmc
== 0) {
3375 rmode
= float_round_ties_away
;
3376 } else if (r
== 0 && rmc
== 0x3) {
3377 rmode
= env
->fpscr
& FP_RN
;
3378 } else if (r
== 1) {
3381 rmode
= float_round_nearest_even
;
3384 rmode
= float_round_to_zero
;
3387 rmode
= float_round_up
;
3390 rmode
= float_round_down
;
3397 tstat
= env
->fp_status
;
3398 set_float_exception_flags(0, &tstat
);
3399 set_float_rounding_mode(rmode
, &tstat
);
3400 round_res
= float128_to_floatx80(xb
->f128
, &tstat
);
3401 t
.f128
= floatx80_to_float128(round_res
, &tstat
);
3402 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3404 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid_snan
)) {
3405 float_invalid_op_vxsnan(env
, GETPC());
3406 t
.f128
= float128_snan_to_qnan(t
.f128
);
3409 helper_compute_fprf_float128(env
, t
.f128
);
3411 do_float_check_status(env
, GETPC());
3414 void helper_xssqrtqp(CPUPPCState
*env
, uint32_t opcode
,
3415 ppc_vsr_t
*xt
, ppc_vsr_t
*xb
)
3420 helper_reset_fpstatus(env
);
3422 tstat
= env
->fp_status
;
3423 if (unlikely(Rc(opcode
) != 0)) {
3424 tstat
.float_rounding_mode
= float_round_to_odd
;
3427 set_float_exception_flags(0, &tstat
);
3428 t
.f128
= float128_sqrt(xb
->f128
, &tstat
);
3429 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3431 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
3432 float_invalid_op_sqrt(env
, tstat
.float_exception_flags
, 1, GETPC());
3435 helper_compute_fprf_float128(env
, t
.f128
);
3437 do_float_check_status(env
, GETPC());
3440 void helper_xssubqp(CPUPPCState
*env
, uint32_t opcode
,
3441 ppc_vsr_t
*xt
, ppc_vsr_t
*xa
, ppc_vsr_t
*xb
)
3446 helper_reset_fpstatus(env
);
3448 tstat
= env
->fp_status
;
3449 if (unlikely(Rc(opcode
) != 0)) {
3450 tstat
.float_rounding_mode
= float_round_to_odd
;
3453 set_float_exception_flags(0, &tstat
);
3454 t
.f128
= float128_sub(xa
->f128
, xb
->f128
, &tstat
);
3455 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3457 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
3458 float_invalid_op_addsub(env
, tstat
.float_exception_flags
, 1, GETPC());
3461 helper_compute_fprf_float128(env
, t
.f128
);
3463 do_float_check_status(env
, GETPC());