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 float32
bfp32_neg(float32 a
)
41 if (unlikely(float32_is_any_nan(a
))) {
44 return float32_chs(a
);
48 static inline bool fp_exceptions_enabled(CPUPPCState
*env
)
50 #ifdef CONFIG_USER_ONLY
53 return (env
->msr
& ((1U << MSR_FE0
) | (1U << MSR_FE1
))) != 0;
57 /*****************************************************************************/
58 /* Floating point operations helpers */
61 * This is the non-arithmatic conversion that happens e.g. on loads.
62 * In the Power ISA pseudocode, this is called DOUBLE.
64 uint64_t helper_todouble(uint32_t arg
)
66 uint32_t abs_arg
= arg
& 0x7fffffff;
69 if (likely(abs_arg
>= 0x00800000)) {
70 if (unlikely(extract32(arg
, 23, 8) == 0xff)) {
72 ret
= (uint64_t)extract32(arg
, 31, 1) << 63;
73 ret
|= (uint64_t)0x7ff << 52;
74 ret
|= (uint64_t)extract32(arg
, 0, 23) << 29;
76 /* Normalized operand. */
77 ret
= (uint64_t)extract32(arg
, 30, 2) << 62;
78 ret
|= ((extract32(arg
, 30, 1) ^ 1) * (uint64_t)7) << 59;
79 ret
|= (uint64_t)extract32(arg
, 0, 30) << 29;
82 /* Zero or Denormalized operand. */
83 ret
= (uint64_t)extract32(arg
, 31, 1) << 63;
84 if (unlikely(abs_arg
!= 0)) {
86 * Denormalized operand.
87 * Shift fraction so that the msb is in the implicit bit position.
88 * Thus, shift is in the range [1:23].
90 int shift
= clz32(abs_arg
) - 8;
92 * The first 3 terms compute the float64 exponent. We then bias
93 * this result by -1 so that we can swallow the implicit bit below.
95 int exp
= -126 - shift
+ 1023 - 1;
97 ret
|= (uint64_t)exp
<< 52;
98 ret
+= (uint64_t)abs_arg
<< (52 - 23 + shift
);
105 * This is the non-arithmatic conversion that happens e.g. on stores.
106 * In the Power ISA pseudocode, this is called SINGLE.
108 uint32_t helper_tosingle(uint64_t arg
)
110 int exp
= extract64(arg
, 52, 11);
113 if (likely(exp
> 896)) {
114 /* No denormalization required (includes Inf, NaN). */
115 ret
= extract64(arg
, 62, 2) << 30;
116 ret
|= extract64(arg
, 29, 30);
119 * Zero or Denormal result. If the exponent is in bounds for
120 * a single-precision denormal result, extract the proper
121 * bits. If the input is not zero, and the exponent is out of
122 * bounds, then the result is undefined; this underflows to
125 ret
= extract64(arg
, 63, 1) << 31;
126 if (unlikely(exp
>= 874)) {
127 /* Denormal result. */
128 ret
|= ((1ULL << 52) | extract64(arg
, 0, 52)) >> (896 + 30 - exp
);
134 static inline int ppc_float32_get_unbiased_exp(float32 f
)
136 return ((f
>> 23) & 0xFF) - 127;
139 static inline int ppc_float64_get_unbiased_exp(float64 f
)
141 return ((f
>> 52) & 0x7FF) - 1023;
144 #define COMPUTE_FPRF(tp) \
145 void helper_compute_fprf_##tp(CPUPPCState *env, tp arg) \
147 bool neg = tp##_is_neg(arg); \
149 if (likely(tp##_is_normal(arg))) { \
150 fprf = neg ? 0x08 << FPSCR_FPRF : 0x04 << FPSCR_FPRF; \
151 } else if (tp##_is_zero(arg)) { \
152 fprf = neg ? 0x12 << FPSCR_FPRF : 0x02 << FPSCR_FPRF; \
153 } else if (tp##_is_zero_or_denormal(arg)) { \
154 fprf = neg ? 0x18 << FPSCR_FPRF : 0x14 << FPSCR_FPRF; \
155 } else if (tp##_is_infinity(arg)) { \
156 fprf = neg ? 0x09 << FPSCR_FPRF : 0x05 << FPSCR_FPRF; \
158 float_status dummy = { }; /* snan_bit_is_one = 0 */ \
159 if (tp##_is_signaling_nan(arg, &dummy)) { \
160 fprf = 0x00 << FPSCR_FPRF; \
162 fprf = 0x11 << FPSCR_FPRF; \
165 env->fpscr = (env->fpscr & ~FP_FPRF) | fprf; \
168 COMPUTE_FPRF(float16
)
169 COMPUTE_FPRF(float32
)
170 COMPUTE_FPRF(float64
)
171 COMPUTE_FPRF(float128
)
173 /* Floating-point invalid operations exception */
174 static void finish_invalid_op_excp(CPUPPCState
*env
, int op
, uintptr_t retaddr
)
176 /* Update the floating-point invalid operation summary */
178 /* Update the floating-point exception summary */
180 if (env
->fpscr
& FP_VE
) {
181 /* Update the floating-point enabled exception summary */
182 env
->fpscr
|= FP_FEX
;
183 if (fp_exceptions_enabled(env
)) {
184 raise_exception_err_ra(env
, POWERPC_EXCP_PROGRAM
,
185 POWERPC_EXCP_FP
| op
, retaddr
);
190 static void finish_invalid_op_arith(CPUPPCState
*env
, int op
,
191 bool set_fpcc
, uintptr_t retaddr
)
193 env
->fpscr
&= ~(FP_FR
| FP_FI
);
194 if (!(env
->fpscr
& FP_VE
)) {
196 env
->fpscr
&= ~FP_FPCC
;
197 env
->fpscr
|= (FP_C
| FP_FU
);
200 finish_invalid_op_excp(env
, op
, retaddr
);
204 static void float_invalid_op_vxsnan(CPUPPCState
*env
, uintptr_t retaddr
)
206 env
->fpscr
|= FP_VXSNAN
;
207 finish_invalid_op_excp(env
, POWERPC_EXCP_FP_VXSNAN
, retaddr
);
210 /* Magnitude subtraction of infinities */
211 static void float_invalid_op_vxisi(CPUPPCState
*env
, bool set_fpcc
,
214 env
->fpscr
|= FP_VXISI
;
215 finish_invalid_op_arith(env
, POWERPC_EXCP_FP_VXISI
, set_fpcc
, retaddr
);
218 /* Division of infinity by infinity */
219 static void float_invalid_op_vxidi(CPUPPCState
*env
, bool set_fpcc
,
222 env
->fpscr
|= FP_VXIDI
;
223 finish_invalid_op_arith(env
, POWERPC_EXCP_FP_VXIDI
, set_fpcc
, retaddr
);
226 /* Division of zero by zero */
227 static void float_invalid_op_vxzdz(CPUPPCState
*env
, bool set_fpcc
,
230 env
->fpscr
|= FP_VXZDZ
;
231 finish_invalid_op_arith(env
, POWERPC_EXCP_FP_VXZDZ
, set_fpcc
, retaddr
);
234 /* Multiplication of zero by infinity */
235 static void float_invalid_op_vximz(CPUPPCState
*env
, bool set_fpcc
,
238 env
->fpscr
|= FP_VXIMZ
;
239 finish_invalid_op_arith(env
, POWERPC_EXCP_FP_VXIMZ
, set_fpcc
, retaddr
);
242 /* Square root of a negative number */
243 static void float_invalid_op_vxsqrt(CPUPPCState
*env
, bool set_fpcc
,
246 env
->fpscr
|= FP_VXSQRT
;
247 finish_invalid_op_arith(env
, POWERPC_EXCP_FP_VXSQRT
, set_fpcc
, retaddr
);
250 /* Ordered comparison of NaN */
251 static void float_invalid_op_vxvc(CPUPPCState
*env
, bool set_fpcc
,
254 env
->fpscr
|= FP_VXVC
;
256 env
->fpscr
&= ~FP_FPCC
;
257 env
->fpscr
|= (FP_C
| FP_FU
);
259 /* Update the floating-point invalid operation summary */
261 /* Update the floating-point exception summary */
263 /* We must update the target FPR before raising the exception */
264 if (env
->fpscr
& FP_VE
) {
265 CPUState
*cs
= env_cpu(env
);
267 cs
->exception_index
= POWERPC_EXCP_PROGRAM
;
268 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_VXVC
;
269 /* Update the floating-point enabled exception summary */
270 env
->fpscr
|= FP_FEX
;
271 /* Exception is deferred */
275 /* Invalid conversion */
276 static void float_invalid_op_vxcvi(CPUPPCState
*env
, bool set_fpcc
,
279 env
->fpscr
|= FP_VXCVI
;
280 env
->fpscr
&= ~(FP_FR
| FP_FI
);
281 if (!(env
->fpscr
& FP_VE
)) {
283 env
->fpscr
&= ~FP_FPCC
;
284 env
->fpscr
|= (FP_C
| FP_FU
);
287 finish_invalid_op_excp(env
, POWERPC_EXCP_FP_VXCVI
, retaddr
);
290 static inline void float_zero_divide_excp(CPUPPCState
*env
, uintptr_t raddr
)
293 env
->fpscr
&= ~(FP_FR
| FP_FI
);
294 /* Update the floating-point exception summary */
296 if (env
->fpscr
& FP_ZE
) {
297 /* Update the floating-point enabled exception summary */
298 env
->fpscr
|= FP_FEX
;
299 if (fp_exceptions_enabled(env
)) {
300 raise_exception_err_ra(env
, POWERPC_EXCP_PROGRAM
,
301 POWERPC_EXCP_FP
| POWERPC_EXCP_FP_ZX
,
307 static inline int float_overflow_excp(CPUPPCState
*env
)
309 CPUState
*cs
= env_cpu(env
);
312 /* Update the floating-point exception summary */
315 bool overflow_enabled
= !!(env
->fpscr
& FP_OE
);
316 if (overflow_enabled
) {
317 /* Update the floating-point enabled exception summary */
318 env
->fpscr
|= FP_FEX
;
319 /* We must update the target FPR before raising the exception */
320 cs
->exception_index
= POWERPC_EXCP_PROGRAM
;
321 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_OX
;
324 return overflow_enabled
? 0 : float_flag_inexact
;
327 static inline void float_underflow_excp(CPUPPCState
*env
)
329 CPUState
*cs
= env_cpu(env
);
332 /* Update the floating-point exception summary */
334 if (env
->fpscr
& FP_UE
) {
335 /* Update the floating-point enabled exception summary */
336 env
->fpscr
|= FP_FEX
;
337 /* We must update the target FPR before raising the exception */
338 cs
->exception_index
= POWERPC_EXCP_PROGRAM
;
339 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_UX
;
343 static inline void float_inexact_excp(CPUPPCState
*env
)
345 CPUState
*cs
= env_cpu(env
);
348 /* Update the floating-point exception summary */
350 if (env
->fpscr
& FP_XE
) {
351 /* Update the floating-point enabled exception summary */
352 env
->fpscr
|= FP_FEX
;
353 /* We must update the target FPR before raising the exception */
354 cs
->exception_index
= POWERPC_EXCP_PROGRAM
;
355 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_XX
;
359 void helper_fpscr_clrbit(CPUPPCState
*env
, uint32_t bit
)
361 uint32_t mask
= 1u << bit
;
362 if (env
->fpscr
& mask
) {
363 ppc_store_fpscr(env
, env
->fpscr
& ~(target_ulong
)mask
);
367 void helper_fpscr_setbit(CPUPPCState
*env
, uint32_t bit
)
369 uint32_t mask
= 1u << bit
;
370 if (!(env
->fpscr
& mask
)) {
371 ppc_store_fpscr(env
, env
->fpscr
| mask
);
375 void helper_store_fpscr(CPUPPCState
*env
, uint64_t val
, uint32_t nibbles
)
377 target_ulong mask
= 0;
380 /* TODO: push this extension back to translation time */
381 for (i
= 0; i
< sizeof(target_ulong
) * 2; i
++) {
382 if (nibbles
& (1 << i
)) {
383 mask
|= (target_ulong
) 0xf << (4 * i
);
386 val
= (val
& mask
) | (env
->fpscr
& ~mask
);
387 ppc_store_fpscr(env
, val
);
390 static void do_fpscr_check_status(CPUPPCState
*env
, uintptr_t raddr
)
392 CPUState
*cs
= env_cpu(env
);
393 target_ulong fpscr
= env
->fpscr
;
396 if ((fpscr
& FP_OX
) && (fpscr
& FP_OE
)) {
397 error
= POWERPC_EXCP_FP_OX
;
398 } else if ((fpscr
& FP_UX
) && (fpscr
& FP_UE
)) {
399 error
= POWERPC_EXCP_FP_UX
;
400 } else if ((fpscr
& FP_XX
) && (fpscr
& FP_XE
)) {
401 error
= POWERPC_EXCP_FP_XX
;
402 } else if ((fpscr
& FP_ZX
) && (fpscr
& FP_ZE
)) {
403 error
= POWERPC_EXCP_FP_ZX
;
404 } else if (fpscr
& FP_VE
) {
405 if (fpscr
& FP_VXSOFT
) {
406 error
= POWERPC_EXCP_FP_VXSOFT
;
407 } else if (fpscr
& FP_VXSNAN
) {
408 error
= POWERPC_EXCP_FP_VXSNAN
;
409 } else if (fpscr
& FP_VXISI
) {
410 error
= POWERPC_EXCP_FP_VXISI
;
411 } else if (fpscr
& FP_VXIDI
) {
412 error
= POWERPC_EXCP_FP_VXIDI
;
413 } else if (fpscr
& FP_VXZDZ
) {
414 error
= POWERPC_EXCP_FP_VXZDZ
;
415 } else if (fpscr
& FP_VXIMZ
) {
416 error
= POWERPC_EXCP_FP_VXIMZ
;
417 } else if (fpscr
& FP_VXVC
) {
418 error
= POWERPC_EXCP_FP_VXVC
;
419 } else if (fpscr
& FP_VXSQRT
) {
420 error
= POWERPC_EXCP_FP_VXSQRT
;
421 } else if (fpscr
& FP_VXCVI
) {
422 error
= POWERPC_EXCP_FP_VXCVI
;
429 cs
->exception_index
= POWERPC_EXCP_PROGRAM
;
430 env
->error_code
= error
| POWERPC_EXCP_FP
;
431 env
->fpscr
|= FP_FEX
;
432 /* Deferred floating-point exception after target FPSCR update */
433 if (fp_exceptions_enabled(env
)) {
434 raise_exception_err_ra(env
, cs
->exception_index
,
435 env
->error_code
, raddr
);
439 void helper_fpscr_check_status(CPUPPCState
*env
)
441 do_fpscr_check_status(env
, GETPC());
444 static void do_float_check_status(CPUPPCState
*env
, bool change_fi
,
447 CPUState
*cs
= env_cpu(env
);
448 int status
= get_float_exception_flags(&env
->fp_status
);
450 if (status
& float_flag_overflow
) {
451 status
|= float_overflow_excp(env
);
452 } else if (status
& float_flag_underflow
) {
453 float_underflow_excp(env
);
455 if (status
& float_flag_inexact
) {
456 float_inexact_excp(env
);
459 env
->fpscr
= FIELD_DP64(env
->fpscr
, FPSCR
, FI
,
460 !!(status
& float_flag_inexact
));
463 if (cs
->exception_index
== POWERPC_EXCP_PROGRAM
&&
464 (env
->error_code
& POWERPC_EXCP_FP
)) {
465 /* Deferred floating-point exception after target FPR update */
466 if (fp_exceptions_enabled(env
)) {
467 raise_exception_err_ra(env
, cs
->exception_index
,
468 env
->error_code
, raddr
);
473 void helper_float_check_status(CPUPPCState
*env
)
475 do_float_check_status(env
, true, GETPC());
478 void helper_reset_fpstatus(CPUPPCState
*env
)
480 set_float_exception_flags(0, &env
->fp_status
);
483 static void float_invalid_op_addsub(CPUPPCState
*env
, int flags
,
484 bool set_fpcc
, uintptr_t retaddr
)
486 if (flags
& float_flag_invalid_isi
) {
487 float_invalid_op_vxisi(env
, set_fpcc
, retaddr
);
488 } else if (flags
& float_flag_invalid_snan
) {
489 float_invalid_op_vxsnan(env
, retaddr
);
494 float64
helper_fadd(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
496 float64 ret
= float64_add(arg1
, arg2
, &env
->fp_status
);
497 int flags
= get_float_exception_flags(&env
->fp_status
);
499 if (unlikely(flags
& float_flag_invalid
)) {
500 float_invalid_op_addsub(env
, flags
, 1, GETPC());
507 float64
helper_fadds(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
509 float64 ret
= float64r32_add(arg1
, arg2
, &env
->fp_status
);
510 int flags
= get_float_exception_flags(&env
->fp_status
);
512 if (unlikely(flags
& float_flag_invalid
)) {
513 float_invalid_op_addsub(env
, flags
, 1, GETPC());
519 float64
helper_fsub(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
521 float64 ret
= float64_sub(arg1
, arg2
, &env
->fp_status
);
522 int flags
= get_float_exception_flags(&env
->fp_status
);
524 if (unlikely(flags
& float_flag_invalid
)) {
525 float_invalid_op_addsub(env
, flags
, 1, GETPC());
532 float64
helper_fsubs(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
534 float64 ret
= float64r32_sub(arg1
, arg2
, &env
->fp_status
);
535 int flags
= get_float_exception_flags(&env
->fp_status
);
537 if (unlikely(flags
& float_flag_invalid
)) {
538 float_invalid_op_addsub(env
, flags
, 1, GETPC());
543 static void float_invalid_op_mul(CPUPPCState
*env
, int flags
,
544 bool set_fprc
, uintptr_t retaddr
)
546 if (flags
& float_flag_invalid_imz
) {
547 float_invalid_op_vximz(env
, set_fprc
, retaddr
);
548 } else if (flags
& float_flag_invalid_snan
) {
549 float_invalid_op_vxsnan(env
, retaddr
);
554 float64
helper_fmul(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
556 float64 ret
= float64_mul(arg1
, arg2
, &env
->fp_status
);
557 int flags
= get_float_exception_flags(&env
->fp_status
);
559 if (unlikely(flags
& float_flag_invalid
)) {
560 float_invalid_op_mul(env
, flags
, 1, GETPC());
567 float64
helper_fmuls(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
569 float64 ret
= float64r32_mul(arg1
, arg2
, &env
->fp_status
);
570 int flags
= get_float_exception_flags(&env
->fp_status
);
572 if (unlikely(flags
& float_flag_invalid
)) {
573 float_invalid_op_mul(env
, flags
, 1, GETPC());
578 static void float_invalid_op_div(CPUPPCState
*env
, int flags
,
579 bool set_fprc
, uintptr_t retaddr
)
581 if (flags
& float_flag_invalid_idi
) {
582 float_invalid_op_vxidi(env
, set_fprc
, retaddr
);
583 } else if (flags
& float_flag_invalid_zdz
) {
584 float_invalid_op_vxzdz(env
, set_fprc
, retaddr
);
585 } else if (flags
& float_flag_invalid_snan
) {
586 float_invalid_op_vxsnan(env
, retaddr
);
591 float64
helper_fdiv(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
593 float64 ret
= float64_div(arg1
, arg2
, &env
->fp_status
);
594 int flags
= get_float_exception_flags(&env
->fp_status
);
596 if (unlikely(flags
& float_flag_invalid
)) {
597 float_invalid_op_div(env
, flags
, 1, GETPC());
599 if (unlikely(flags
& float_flag_divbyzero
)) {
600 float_zero_divide_excp(env
, GETPC());
607 float64
helper_fdivs(CPUPPCState
*env
, float64 arg1
, float64 arg2
)
609 float64 ret
= float64r32_div(arg1
, arg2
, &env
->fp_status
);
610 int flags
= get_float_exception_flags(&env
->fp_status
);
612 if (unlikely(flags
& float_flag_invalid
)) {
613 float_invalid_op_div(env
, flags
, 1, GETPC());
615 if (unlikely(flags
& float_flag_divbyzero
)) {
616 float_zero_divide_excp(env
, GETPC());
622 static uint64_t float_invalid_cvt(CPUPPCState
*env
, int flags
,
623 uint64_t ret
, uint64_t ret_nan
,
624 bool set_fprc
, uintptr_t retaddr
)
627 * VXCVI is different from most in that it sets two exception bits,
628 * VXCVI and VXSNAN for an SNaN input.
630 if (flags
& float_flag_invalid_snan
) {
631 env
->fpscr
|= FP_VXSNAN
;
633 float_invalid_op_vxcvi(env
, set_fprc
, retaddr
);
635 return flags
& float_flag_invalid_cvti
? ret
: ret_nan
;
638 #define FPU_FCTI(op, cvt, nanval) \
639 uint64_t helper_##op(CPUPPCState *env, float64 arg) \
641 uint64_t ret = float64_to_##cvt(arg, &env->fp_status); \
642 int flags = get_float_exception_flags(&env->fp_status); \
643 if (unlikely(flags & float_flag_invalid)) { \
644 ret = float_invalid_cvt(env, flags, ret, nanval, 1, GETPC()); \
649 FPU_FCTI(fctiw
, int32
, 0x80000000U
)
650 FPU_FCTI(fctiwz
, int32_round_to_zero
, 0x80000000U
)
651 FPU_FCTI(fctiwu
, uint32
, 0x00000000U
)
652 FPU_FCTI(fctiwuz
, uint32_round_to_zero
, 0x00000000U
)
653 FPU_FCTI(fctid
, int64
, 0x8000000000000000ULL
)
654 FPU_FCTI(fctidz
, int64_round_to_zero
, 0x8000000000000000ULL
)
655 FPU_FCTI(fctidu
, uint64
, 0x0000000000000000ULL
)
656 FPU_FCTI(fctiduz
, uint64_round_to_zero
, 0x0000000000000000ULL
)
658 #define FPU_FCFI(op, cvtr, is_single) \
659 uint64_t helper_##op(CPUPPCState *env, uint64_t arg) \
664 float32 tmp = cvtr(arg, &env->fp_status); \
665 farg.d = float32_to_float64(tmp, &env->fp_status); \
667 farg.d = cvtr(arg, &env->fp_status); \
669 do_float_check_status(env, true, GETPC()); \
673 FPU_FCFI(fcfid
, int64_to_float64
, 0)
674 FPU_FCFI(fcfids
, int64_to_float32
, 1)
675 FPU_FCFI(fcfidu
, uint64_to_float64
, 0)
676 FPU_FCFI(fcfidus
, uint64_to_float32
, 1)
678 static uint64_t do_fri(CPUPPCState
*env
, uint64_t arg
,
679 FloatRoundMode rounding_mode
)
681 FloatRoundMode old_rounding_mode
= get_float_rounding_mode(&env
->fp_status
);
684 set_float_rounding_mode(rounding_mode
, &env
->fp_status
);
685 arg
= float64_round_to_int(arg
, &env
->fp_status
);
686 set_float_rounding_mode(old_rounding_mode
, &env
->fp_status
);
688 flags
= get_float_exception_flags(&env
->fp_status
);
689 if (flags
& float_flag_invalid_snan
) {
690 float_invalid_op_vxsnan(env
, GETPC());
693 /* fri* does not set FPSCR[XX] */
694 set_float_exception_flags(flags
& ~float_flag_inexact
, &env
->fp_status
);
695 do_float_check_status(env
, true, GETPC());
700 uint64_t helper_frin(CPUPPCState
*env
, uint64_t arg
)
702 return do_fri(env
, arg
, float_round_ties_away
);
705 uint64_t helper_friz(CPUPPCState
*env
, uint64_t arg
)
707 return do_fri(env
, arg
, float_round_to_zero
);
710 uint64_t helper_frip(CPUPPCState
*env
, uint64_t arg
)
712 return do_fri(env
, arg
, float_round_up
);
715 uint64_t helper_frim(CPUPPCState
*env
, uint64_t arg
)
717 return do_fri(env
, arg
, float_round_down
);
720 static void float_invalid_op_madd(CPUPPCState
*env
, int flags
,
721 bool set_fpcc
, uintptr_t retaddr
)
723 if (flags
& float_flag_invalid_imz
) {
724 float_invalid_op_vximz(env
, set_fpcc
, retaddr
);
726 float_invalid_op_addsub(env
, flags
, set_fpcc
, retaddr
);
730 static float64
do_fmadd(CPUPPCState
*env
, float64 a
, float64 b
,
731 float64 c
, int madd_flags
, uintptr_t retaddr
)
733 float64 ret
= float64_muladd(a
, b
, c
, madd_flags
, &env
->fp_status
);
734 int flags
= get_float_exception_flags(&env
->fp_status
);
736 if (unlikely(flags
& float_flag_invalid
)) {
737 float_invalid_op_madd(env
, flags
, 1, retaddr
);
742 static uint64_t do_fmadds(CPUPPCState
*env
, float64 a
, float64 b
,
743 float64 c
, int madd_flags
, uintptr_t retaddr
)
745 float64 ret
= float64r32_muladd(a
, b
, c
, madd_flags
, &env
->fp_status
);
746 int flags
= get_float_exception_flags(&env
->fp_status
);
748 if (unlikely(flags
& float_flag_invalid
)) {
749 float_invalid_op_madd(env
, flags
, 1, retaddr
);
754 #define FPU_FMADD(op, madd_flags) \
755 uint64_t helper_##op(CPUPPCState *env, uint64_t arg1, \
756 uint64_t arg2, uint64_t arg3) \
757 { return do_fmadd(env, arg1, arg2, arg3, madd_flags, GETPC()); } \
758 uint64_t helper_##op##s(CPUPPCState *env, uint64_t arg1, \
759 uint64_t arg2, uint64_t arg3) \
760 { return do_fmadds(env, arg1, arg2, arg3, madd_flags, GETPC()); }
763 #define MSUB_FLGS float_muladd_negate_c
764 #define NMADD_FLGS float_muladd_negate_result
765 #define NMSUB_FLGS (float_muladd_negate_c | float_muladd_negate_result)
767 FPU_FMADD(fmadd
, MADD_FLGS
)
768 FPU_FMADD(fnmadd
, NMADD_FLGS
)
769 FPU_FMADD(fmsub
, MSUB_FLGS
)
770 FPU_FMADD(fnmsub
, NMSUB_FLGS
)
773 static uint64_t do_frsp(CPUPPCState
*env
, uint64_t arg
, uintptr_t retaddr
)
775 float32 f32
= float64_to_float32(arg
, &env
->fp_status
);
776 int flags
= get_float_exception_flags(&env
->fp_status
);
778 if (unlikely(flags
& float_flag_invalid_snan
)) {
779 float_invalid_op_vxsnan(env
, retaddr
);
781 return helper_todouble(f32
);
784 uint64_t helper_frsp(CPUPPCState
*env
, uint64_t arg
)
786 return do_frsp(env
, arg
, GETPC());
789 static void float_invalid_op_sqrt(CPUPPCState
*env
, int flags
,
790 bool set_fpcc
, uintptr_t retaddr
)
792 if (unlikely(flags
& float_flag_invalid_sqrt
)) {
793 float_invalid_op_vxsqrt(env
, set_fpcc
, retaddr
);
794 } else if (unlikely(flags
& float_flag_invalid_snan
)) {
795 float_invalid_op_vxsnan(env
, retaddr
);
799 #define FPU_FSQRT(name, op) \
800 float64 helper_##name(CPUPPCState *env, float64 arg) \
802 float64 ret = op(arg, &env->fp_status); \
803 int flags = get_float_exception_flags(&env->fp_status); \
805 if (unlikely(flags & float_flag_invalid)) { \
806 float_invalid_op_sqrt(env, flags, 1, GETPC()); \
812 FPU_FSQRT(FSQRT
, float64_sqrt
)
813 FPU_FSQRT(FSQRTS
, float64r32_sqrt
)
816 float64
helper_fre(CPUPPCState
*env
, float64 arg
)
818 /* "Estimate" the reciprocal with actual division. */
819 float64 ret
= float64_div(float64_one
, arg
, &env
->fp_status
);
820 int flags
= get_float_exception_flags(&env
->fp_status
);
822 if (unlikely(flags
& float_flag_invalid_snan
)) {
823 float_invalid_op_vxsnan(env
, GETPC());
825 if (unlikely(flags
& float_flag_divbyzero
)) {
826 float_zero_divide_excp(env
, GETPC());
827 /* For FPSCR.ZE == 0, the result is 1/2. */
828 ret
= float64_set_sign(float64_half
, float64_is_neg(arg
));
835 uint64_t helper_fres(CPUPPCState
*env
, uint64_t arg
)
837 /* "Estimate" the reciprocal with actual division. */
838 float64 ret
= float64r32_div(float64_one
, arg
, &env
->fp_status
);
839 int flags
= get_float_exception_flags(&env
->fp_status
);
841 if (unlikely(flags
& float_flag_invalid_snan
)) {
842 float_invalid_op_vxsnan(env
, GETPC());
844 if (unlikely(flags
& float_flag_divbyzero
)) {
845 float_zero_divide_excp(env
, GETPC());
846 /* For FPSCR.ZE == 0, the result is 1/2. */
847 ret
= float64_set_sign(float64_half
, float64_is_neg(arg
));
853 /* frsqrte - frsqrte. */
854 float64
helper_frsqrte(CPUPPCState
*env
, float64 arg
)
856 /* "Estimate" the reciprocal with actual division. */
857 float64 rets
= float64_sqrt(arg
, &env
->fp_status
);
858 float64 retd
= float64_div(float64_one
, rets
, &env
->fp_status
);
859 int flags
= get_float_exception_flags(&env
->fp_status
);
861 if (unlikely(flags
& float_flag_invalid
)) {
862 float_invalid_op_sqrt(env
, flags
, 1, GETPC());
864 if (unlikely(flags
& float_flag_divbyzero
)) {
865 /* Reciprocal of (square root of) zero. */
866 float_zero_divide_excp(env
, GETPC());
872 /* frsqrtes - frsqrtes. */
873 float64
helper_frsqrtes(CPUPPCState
*env
, float64 arg
)
875 /* "Estimate" the reciprocal with actual division. */
876 float64 rets
= float64_sqrt(arg
, &env
->fp_status
);
877 float64 retd
= float64r32_div(float64_one
, rets
, &env
->fp_status
);
878 int flags
= get_float_exception_flags(&env
->fp_status
);
880 if (unlikely(flags
& float_flag_invalid
)) {
881 float_invalid_op_sqrt(env
, flags
, 1, GETPC());
883 if (unlikely(flags
& float_flag_divbyzero
)) {
884 /* Reciprocal of (square root of) zero. */
885 float_zero_divide_excp(env
, GETPC());
892 uint64_t helper_FSEL(uint64_t a
, uint64_t b
, uint64_t c
)
898 if ((!float64_is_neg(fa
.d
) || float64_is_zero(fa
.d
)) &&
899 !float64_is_any_nan(fa
.d
)) {
906 uint32_t helper_ftdiv(uint64_t fra
, uint64_t frb
)
911 if (unlikely(float64_is_infinity(fra
) ||
912 float64_is_infinity(frb
) ||
913 float64_is_zero(frb
))) {
917 int e_a
= ppc_float64_get_unbiased_exp(fra
);
918 int e_b
= ppc_float64_get_unbiased_exp(frb
);
920 if (unlikely(float64_is_any_nan(fra
) ||
921 float64_is_any_nan(frb
))) {
923 } else if ((e_b
<= -1022) || (e_b
>= 1021)) {
925 } else if (!float64_is_zero(fra
) &&
926 (((e_a
- e_b
) >= 1023) ||
927 ((e_a
- e_b
) <= -1021) ||
932 if (unlikely(float64_is_zero_or_denormal(frb
))) {
933 /* XB is not zero because of the above check and */
934 /* so must be denormalized. */
939 return 0x8 | (fg_flag
? 4 : 0) | (fe_flag
? 2 : 0);
942 uint32_t helper_ftsqrt(uint64_t frb
)
947 if (unlikely(float64_is_infinity(frb
) || float64_is_zero(frb
))) {
951 int e_b
= ppc_float64_get_unbiased_exp(frb
);
953 if (unlikely(float64_is_any_nan(frb
))) {
955 } else if (unlikely(float64_is_zero(frb
))) {
957 } else if (unlikely(float64_is_neg(frb
))) {
959 } else if (!float64_is_zero(frb
) && (e_b
<= (-1022 + 52))) {
963 if (unlikely(float64_is_zero_or_denormal(frb
))) {
964 /* XB is not zero because of the above check and */
965 /* therefore must be denormalized. */
970 return 0x8 | (fg_flag
? 4 : 0) | (fe_flag
? 2 : 0);
973 void helper_fcmpu(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
976 CPU_DoubleU farg1
, farg2
;
982 if (unlikely(float64_is_any_nan(farg1
.d
) ||
983 float64_is_any_nan(farg2
.d
))) {
985 } else if (float64_lt(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
987 } else if (!float64_le(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
993 env
->fpscr
&= ~FP_FPCC
;
994 env
->fpscr
|= ret
<< FPSCR_FPCC
;
995 env
->crf
[crfD
] = ret
;
996 if (unlikely(ret
== 0x01UL
997 && (float64_is_signaling_nan(farg1
.d
, &env
->fp_status
) ||
998 float64_is_signaling_nan(farg2
.d
, &env
->fp_status
)))) {
999 /* sNaN comparison */
1000 float_invalid_op_vxsnan(env
, GETPC());
1004 void helper_fcmpo(CPUPPCState
*env
, uint64_t arg1
, uint64_t arg2
,
1007 CPU_DoubleU farg1
, farg2
;
1013 if (unlikely(float64_is_any_nan(farg1
.d
) ||
1014 float64_is_any_nan(farg2
.d
))) {
1016 } else if (float64_lt(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1018 } else if (!float64_le(farg1
.d
, farg2
.d
, &env
->fp_status
)) {
1024 env
->fpscr
&= ~FP_FPCC
;
1025 env
->fpscr
|= ret
<< FPSCR_FPCC
;
1026 env
->crf
[crfD
] = (uint32_t) ret
;
1027 if (unlikely(ret
== 0x01UL
)) {
1028 float_invalid_op_vxvc(env
, 1, GETPC());
1029 if (float64_is_signaling_nan(farg1
.d
, &env
->fp_status
) ||
1030 float64_is_signaling_nan(farg2
.d
, &env
->fp_status
)) {
1031 /* sNaN comparison */
1032 float_invalid_op_vxsnan(env
, GETPC());
1037 /* Single-precision floating-point conversions */
1038 static inline uint32_t efscfsi(CPUPPCState
*env
, uint32_t val
)
1042 u
.f
= int32_to_float32(val
, &env
->vec_status
);
1047 static inline uint32_t efscfui(CPUPPCState
*env
, uint32_t val
)
1051 u
.f
= uint32_to_float32(val
, &env
->vec_status
);
1056 static inline int32_t efsctsi(CPUPPCState
*env
, uint32_t val
)
1061 /* NaN are not treated the same way IEEE 754 does */
1062 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1066 return float32_to_int32(u
.f
, &env
->vec_status
);
1069 static inline uint32_t efsctui(CPUPPCState
*env
, uint32_t val
)
1074 /* NaN are not treated the same way IEEE 754 does */
1075 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1079 return float32_to_uint32(u
.f
, &env
->vec_status
);
1082 static inline uint32_t efsctsiz(CPUPPCState
*env
, uint32_t val
)
1087 /* NaN are not treated the same way IEEE 754 does */
1088 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1092 return float32_to_int32_round_to_zero(u
.f
, &env
->vec_status
);
1095 static inline uint32_t efsctuiz(CPUPPCState
*env
, uint32_t val
)
1100 /* NaN are not treated the same way IEEE 754 does */
1101 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1105 return float32_to_uint32_round_to_zero(u
.f
, &env
->vec_status
);
1108 static inline uint32_t efscfsf(CPUPPCState
*env
, uint32_t val
)
1113 u
.f
= int32_to_float32(val
, &env
->vec_status
);
1114 tmp
= int64_to_float32(1ULL << 32, &env
->vec_status
);
1115 u
.f
= float32_div(u
.f
, tmp
, &env
->vec_status
);
1120 static inline uint32_t efscfuf(CPUPPCState
*env
, uint32_t val
)
1125 u
.f
= uint32_to_float32(val
, &env
->vec_status
);
1126 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1127 u
.f
= float32_div(u
.f
, tmp
, &env
->vec_status
);
1132 static inline uint32_t efsctsf(CPUPPCState
*env
, uint32_t val
)
1138 /* NaN are not treated the same way IEEE 754 does */
1139 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1142 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1143 u
.f
= float32_mul(u
.f
, tmp
, &env
->vec_status
);
1145 return float32_to_int32(u
.f
, &env
->vec_status
);
1148 static inline uint32_t efsctuf(CPUPPCState
*env
, uint32_t val
)
1154 /* NaN are not treated the same way IEEE 754 does */
1155 if (unlikely(float32_is_quiet_nan(u
.f
, &env
->vec_status
))) {
1158 tmp
= uint64_to_float32(1ULL << 32, &env
->vec_status
);
1159 u
.f
= float32_mul(u
.f
, tmp
, &env
->vec_status
);
1161 return float32_to_uint32(u
.f
, &env
->vec_status
);
1164 #define HELPER_SPE_SINGLE_CONV(name) \
1165 uint32_t helper_e##name(CPUPPCState *env, uint32_t val) \
1167 return e##name(env, val); \
1170 HELPER_SPE_SINGLE_CONV(fscfsi
);
1172 HELPER_SPE_SINGLE_CONV(fscfui
);
1174 HELPER_SPE_SINGLE_CONV(fscfuf
);
1176 HELPER_SPE_SINGLE_CONV(fscfsf
);
1178 HELPER_SPE_SINGLE_CONV(fsctsi
);
1180 HELPER_SPE_SINGLE_CONV(fsctui
);
1182 HELPER_SPE_SINGLE_CONV(fsctsiz
);
1184 HELPER_SPE_SINGLE_CONV(fsctuiz
);
1186 HELPER_SPE_SINGLE_CONV(fsctsf
);
1188 HELPER_SPE_SINGLE_CONV(fsctuf
);
1190 #define HELPER_SPE_VECTOR_CONV(name) \
1191 uint64_t helper_ev##name(CPUPPCState *env, uint64_t val) \
1193 return ((uint64_t)e##name(env, val >> 32) << 32) | \
1194 (uint64_t)e##name(env, val); \
1197 HELPER_SPE_VECTOR_CONV(fscfsi
);
1199 HELPER_SPE_VECTOR_CONV(fscfui
);
1201 HELPER_SPE_VECTOR_CONV(fscfuf
);
1203 HELPER_SPE_VECTOR_CONV(fscfsf
);
1205 HELPER_SPE_VECTOR_CONV(fsctsi
);
1207 HELPER_SPE_VECTOR_CONV(fsctui
);
1209 HELPER_SPE_VECTOR_CONV(fsctsiz
);
1211 HELPER_SPE_VECTOR_CONV(fsctuiz
);
1213 HELPER_SPE_VECTOR_CONV(fsctsf
);
1215 HELPER_SPE_VECTOR_CONV(fsctuf
);
1217 /* Single-precision floating-point arithmetic */
1218 static inline uint32_t efsadd(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1224 u1
.f
= float32_add(u1
.f
, u2
.f
, &env
->vec_status
);
1228 static inline uint32_t efssub(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1234 u1
.f
= float32_sub(u1
.f
, u2
.f
, &env
->vec_status
);
1238 static inline uint32_t efsmul(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1244 u1
.f
= float32_mul(u1
.f
, u2
.f
, &env
->vec_status
);
1248 static inline uint32_t efsdiv(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1254 u1
.f
= float32_div(u1
.f
, u2
.f
, &env
->vec_status
);
1258 #define HELPER_SPE_SINGLE_ARITH(name) \
1259 uint32_t helper_e##name(CPUPPCState *env, uint32_t op1, uint32_t op2) \
1261 return e##name(env, op1, op2); \
1264 HELPER_SPE_SINGLE_ARITH(fsadd
);
1266 HELPER_SPE_SINGLE_ARITH(fssub
);
1268 HELPER_SPE_SINGLE_ARITH(fsmul
);
1270 HELPER_SPE_SINGLE_ARITH(fsdiv
);
1272 #define HELPER_SPE_VECTOR_ARITH(name) \
1273 uint64_t helper_ev##name(CPUPPCState *env, uint64_t op1, uint64_t op2) \
1275 return ((uint64_t)e##name(env, op1 >> 32, op2 >> 32) << 32) | \
1276 (uint64_t)e##name(env, op1, op2); \
1279 HELPER_SPE_VECTOR_ARITH(fsadd
);
1281 HELPER_SPE_VECTOR_ARITH(fssub
);
1283 HELPER_SPE_VECTOR_ARITH(fsmul
);
1285 HELPER_SPE_VECTOR_ARITH(fsdiv
);
1287 /* Single-precision floating-point comparisons */
1288 static inline uint32_t efscmplt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1294 return float32_lt(u1
.f
, u2
.f
, &env
->vec_status
) ? 4 : 0;
1297 static inline uint32_t efscmpgt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1303 return float32_le(u1
.f
, u2
.f
, &env
->vec_status
) ? 0 : 4;
1306 static inline uint32_t efscmpeq(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1312 return float32_eq(u1
.f
, u2
.f
, &env
->vec_status
) ? 4 : 0;
1315 static inline uint32_t efststlt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1317 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1318 return efscmplt(env
, op1
, op2
);
1321 static inline uint32_t efststgt(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1323 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1324 return efscmpgt(env
, op1
, op2
);
1327 static inline uint32_t efststeq(CPUPPCState
*env
, uint32_t op1
, uint32_t op2
)
1329 /* XXX: TODO: ignore special values (NaN, infinites, ...) */
1330 return efscmpeq(env
, op1
, op2
);
1333 #define HELPER_SINGLE_SPE_CMP(name) \
1334 uint32_t helper_e##name(CPUPPCState *env, uint32_t op1, uint32_t op2) \
1336 return e##name(env, op1, op2); \
1339 HELPER_SINGLE_SPE_CMP(fststlt
);
1341 HELPER_SINGLE_SPE_CMP(fststgt
);
1343 HELPER_SINGLE_SPE_CMP(fststeq
);
1345 HELPER_SINGLE_SPE_CMP(fscmplt
);
1347 HELPER_SINGLE_SPE_CMP(fscmpgt
);
1349 HELPER_SINGLE_SPE_CMP(fscmpeq
);
1351 static inline uint32_t evcmp_merge(int t0
, int t1
)
1353 return (t0
<< 3) | (t1
<< 2) | ((t0
| t1
) << 1) | (t0
& t1
);
1356 #define HELPER_VECTOR_SPE_CMP(name) \
1357 uint32_t helper_ev##name(CPUPPCState *env, uint64_t op1, uint64_t op2) \
1359 return evcmp_merge(e##name(env, op1 >> 32, op2 >> 32), \
1360 e##name(env, op1, op2)); \
1363 HELPER_VECTOR_SPE_CMP(fststlt
);
1365 HELPER_VECTOR_SPE_CMP(fststgt
);
1367 HELPER_VECTOR_SPE_CMP(fststeq
);
1369 HELPER_VECTOR_SPE_CMP(fscmplt
);
1371 HELPER_VECTOR_SPE_CMP(fscmpgt
);
1373 HELPER_VECTOR_SPE_CMP(fscmpeq
);
1375 /* Double-precision floating-point conversion */
1376 uint64_t helper_efdcfsi(CPUPPCState
*env
, uint32_t val
)
1380 u
.d
= int32_to_float64(val
, &env
->vec_status
);
1385 uint64_t helper_efdcfsid(CPUPPCState
*env
, uint64_t val
)
1389 u
.d
= int64_to_float64(val
, &env
->vec_status
);
1394 uint64_t helper_efdcfui(CPUPPCState
*env
, uint32_t val
)
1398 u
.d
= uint32_to_float64(val
, &env
->vec_status
);
1403 uint64_t helper_efdcfuid(CPUPPCState
*env
, uint64_t val
)
1407 u
.d
= uint64_to_float64(val
, &env
->vec_status
);
1412 uint32_t helper_efdctsi(CPUPPCState
*env
, uint64_t val
)
1417 /* NaN are not treated the same way IEEE 754 does */
1418 if (unlikely(float64_is_any_nan(u
.d
))) {
1422 return float64_to_int32(u
.d
, &env
->vec_status
);
1425 uint32_t helper_efdctui(CPUPPCState
*env
, uint64_t val
)
1430 /* NaN are not treated the same way IEEE 754 does */
1431 if (unlikely(float64_is_any_nan(u
.d
))) {
1435 return float64_to_uint32(u
.d
, &env
->vec_status
);
1438 uint32_t helper_efdctsiz(CPUPPCState
*env
, uint64_t val
)
1443 /* NaN are not treated the same way IEEE 754 does */
1444 if (unlikely(float64_is_any_nan(u
.d
))) {
1448 return float64_to_int32_round_to_zero(u
.d
, &env
->vec_status
);
1451 uint64_t helper_efdctsidz(CPUPPCState
*env
, uint64_t val
)
1456 /* NaN are not treated the same way IEEE 754 does */
1457 if (unlikely(float64_is_any_nan(u
.d
))) {
1461 return float64_to_int64_round_to_zero(u
.d
, &env
->vec_status
);
1464 uint32_t helper_efdctuiz(CPUPPCState
*env
, uint64_t val
)
1469 /* NaN are not treated the same way IEEE 754 does */
1470 if (unlikely(float64_is_any_nan(u
.d
))) {
1474 return float64_to_uint32_round_to_zero(u
.d
, &env
->vec_status
);
1477 uint64_t helper_efdctuidz(CPUPPCState
*env
, uint64_t val
)
1482 /* NaN are not treated the same way IEEE 754 does */
1483 if (unlikely(float64_is_any_nan(u
.d
))) {
1487 return float64_to_uint64_round_to_zero(u
.d
, &env
->vec_status
);
1490 uint64_t helper_efdcfsf(CPUPPCState
*env
, uint32_t val
)
1495 u
.d
= int32_to_float64(val
, &env
->vec_status
);
1496 tmp
= int64_to_float64(1ULL << 32, &env
->vec_status
);
1497 u
.d
= float64_div(u
.d
, tmp
, &env
->vec_status
);
1502 uint64_t helper_efdcfuf(CPUPPCState
*env
, uint32_t val
)
1507 u
.d
= uint32_to_float64(val
, &env
->vec_status
);
1508 tmp
= int64_to_float64(1ULL << 32, &env
->vec_status
);
1509 u
.d
= float64_div(u
.d
, tmp
, &env
->vec_status
);
1514 uint32_t helper_efdctsf(CPUPPCState
*env
, uint64_t val
)
1520 /* NaN are not treated the same way IEEE 754 does */
1521 if (unlikely(float64_is_any_nan(u
.d
))) {
1524 tmp
= uint64_to_float64(1ULL << 32, &env
->vec_status
);
1525 u
.d
= float64_mul(u
.d
, tmp
, &env
->vec_status
);
1527 return float64_to_int32(u
.d
, &env
->vec_status
);
1530 uint32_t helper_efdctuf(CPUPPCState
*env
, uint64_t val
)
1536 /* NaN are not treated the same way IEEE 754 does */
1537 if (unlikely(float64_is_any_nan(u
.d
))) {
1540 tmp
= uint64_to_float64(1ULL << 32, &env
->vec_status
);
1541 u
.d
= float64_mul(u
.d
, tmp
, &env
->vec_status
);
1543 return float64_to_uint32(u
.d
, &env
->vec_status
);
1546 uint32_t helper_efscfd(CPUPPCState
*env
, uint64_t val
)
1552 u2
.f
= float64_to_float32(u1
.d
, &env
->vec_status
);
1557 uint64_t helper_efdcfs(CPUPPCState
*env
, uint32_t val
)
1563 u2
.d
= float32_to_float64(u1
.f
, &env
->vec_status
);
1568 /* Double precision fixed-point arithmetic */
1569 uint64_t helper_efdadd(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1575 u1
.d
= float64_add(u1
.d
, u2
.d
, &env
->vec_status
);
1579 uint64_t helper_efdsub(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1585 u1
.d
= float64_sub(u1
.d
, u2
.d
, &env
->vec_status
);
1589 uint64_t helper_efdmul(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1595 u1
.d
= float64_mul(u1
.d
, u2
.d
, &env
->vec_status
);
1599 uint64_t helper_efddiv(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1605 u1
.d
= float64_div(u1
.d
, u2
.d
, &env
->vec_status
);
1609 /* Double precision floating point helpers */
1610 uint32_t helper_efdtstlt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1616 return float64_lt(u1
.d
, u2
.d
, &env
->vec_status
) ? 4 : 0;
1619 uint32_t helper_efdtstgt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1625 return float64_le(u1
.d
, u2
.d
, &env
->vec_status
) ? 0 : 4;
1628 uint32_t helper_efdtsteq(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1634 return float64_eq_quiet(u1
.d
, u2
.d
, &env
->vec_status
) ? 4 : 0;
1637 uint32_t helper_efdcmplt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1639 /* XXX: TODO: test special values (NaN, infinites, ...) */
1640 return helper_efdtstlt(env
, op1
, op2
);
1643 uint32_t helper_efdcmpgt(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1645 /* XXX: TODO: test special values (NaN, infinites, ...) */
1646 return helper_efdtstgt(env
, op1
, op2
);
1649 uint32_t helper_efdcmpeq(CPUPPCState
*env
, uint64_t op1
, uint64_t op2
)
1651 /* XXX: TODO: test special values (NaN, infinites, ...) */
1652 return helper_efdtsteq(env
, op1
, op2
);
1655 #define float64_to_float64(x, env) x
1659 * VSX_ADD_SUB - VSX floating point add/subtract
1660 * name - instruction mnemonic
1661 * op - operation (add or sub)
1662 * nels - number of elements (1, 2 or 4)
1663 * tp - type (float32 or float64)
1664 * fld - vsr_t field (VsrD(*) or VsrW(*))
1665 * sfifprf - set FI and FPRF
1667 #define VSX_ADD_SUB(name, op, nels, tp, fld, sfifprf, r2sp) \
1668 void helper_##name(CPUPPCState *env, ppc_vsr_t *xt, \
1669 ppc_vsr_t *xa, ppc_vsr_t *xb) \
1671 ppc_vsr_t t = { }; \
1674 helper_reset_fpstatus(env); \
1676 for (i = 0; i < nels; i++) { \
1677 float_status tstat = env->fp_status; \
1678 set_float_exception_flags(0, &tstat); \
1679 t.fld = tp##_##op(xa->fld, xb->fld, &tstat); \
1680 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1682 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1683 float_invalid_op_addsub(env, tstat.float_exception_flags, \
1684 sfifprf, GETPC()); \
1688 t.fld = do_frsp(env, t.fld, GETPC()); \
1692 helper_compute_fprf_float64(env, t.fld); \
1696 do_float_check_status(env, sfifprf, GETPC()); \
1699 VSX_ADD_SUB(xsadddp
, add
, 1, float64
, VsrD(0), 1, 0)
1700 VSX_ADD_SUB(xsaddsp
, add
, 1, float64
, VsrD(0), 1, 1)
1701 VSX_ADD_SUB(xvadddp
, add
, 2, float64
, VsrD(i
), 0, 0)
1702 VSX_ADD_SUB(xvaddsp
, add
, 4, float32
, VsrW(i
), 0, 0)
1703 VSX_ADD_SUB(xssubdp
, sub
, 1, float64
, VsrD(0), 1, 0)
1704 VSX_ADD_SUB(xssubsp
, sub
, 1, float64
, VsrD(0), 1, 1)
1705 VSX_ADD_SUB(xvsubdp
, sub
, 2, float64
, VsrD(i
), 0, 0)
1706 VSX_ADD_SUB(xvsubsp
, sub
, 4, float32
, VsrW(i
), 0, 0)
1708 void helper_xsaddqp(CPUPPCState
*env
, uint32_t opcode
,
1709 ppc_vsr_t
*xt
, ppc_vsr_t
*xa
, ppc_vsr_t
*xb
)
1714 helper_reset_fpstatus(env
);
1716 tstat
= env
->fp_status
;
1717 if (unlikely(Rc(opcode
) != 0)) {
1718 tstat
.float_rounding_mode
= float_round_to_odd
;
1721 set_float_exception_flags(0, &tstat
);
1722 t
.f128
= float128_add(xa
->f128
, xb
->f128
, &tstat
);
1723 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
1725 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
1726 float_invalid_op_addsub(env
, tstat
.float_exception_flags
, 1, GETPC());
1729 helper_compute_fprf_float128(env
, t
.f128
);
1732 do_float_check_status(env
, true, GETPC());
1736 * VSX_MUL - VSX floating point multiply
1737 * op - instruction mnemonic
1738 * nels - number of elements (1, 2 or 4)
1739 * tp - type (float32 or float64)
1740 * fld - vsr_t field (VsrD(*) or VsrW(*))
1741 * sfifprf - set FI and FPRF
1743 #define VSX_MUL(op, nels, tp, fld, sfifprf, r2sp) \
1744 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
1745 ppc_vsr_t *xa, ppc_vsr_t *xb) \
1747 ppc_vsr_t t = { }; \
1750 helper_reset_fpstatus(env); \
1752 for (i = 0; i < nels; i++) { \
1753 float_status tstat = env->fp_status; \
1754 set_float_exception_flags(0, &tstat); \
1755 t.fld = tp##_mul(xa->fld, xb->fld, &tstat); \
1756 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1758 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1759 float_invalid_op_mul(env, tstat.float_exception_flags, \
1760 sfifprf, GETPC()); \
1764 t.fld = do_frsp(env, t.fld, GETPC()); \
1768 helper_compute_fprf_float64(env, t.fld); \
1773 do_float_check_status(env, sfifprf, GETPC()); \
1776 VSX_MUL(xsmuldp
, 1, float64
, VsrD(0), 1, 0)
1777 VSX_MUL(xsmulsp
, 1, float64
, VsrD(0), 1, 1)
1778 VSX_MUL(xvmuldp
, 2, float64
, VsrD(i
), 0, 0)
1779 VSX_MUL(xvmulsp
, 4, float32
, VsrW(i
), 0, 0)
1781 void helper_xsmulqp(CPUPPCState
*env
, uint32_t opcode
,
1782 ppc_vsr_t
*xt
, ppc_vsr_t
*xa
, ppc_vsr_t
*xb
)
1787 helper_reset_fpstatus(env
);
1788 tstat
= env
->fp_status
;
1789 if (unlikely(Rc(opcode
) != 0)) {
1790 tstat
.float_rounding_mode
= float_round_to_odd
;
1793 set_float_exception_flags(0, &tstat
);
1794 t
.f128
= float128_mul(xa
->f128
, xb
->f128
, &tstat
);
1795 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
1797 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
1798 float_invalid_op_mul(env
, tstat
.float_exception_flags
, 1, GETPC());
1800 helper_compute_fprf_float128(env
, t
.f128
);
1803 do_float_check_status(env
, true, GETPC());
1807 * VSX_DIV - VSX floating point divide
1808 * op - instruction mnemonic
1809 * nels - number of elements (1, 2 or 4)
1810 * tp - type (float32 or float64)
1811 * fld - vsr_t field (VsrD(*) or VsrW(*))
1812 * sfifprf - set FI and FPRF
1814 #define VSX_DIV(op, nels, tp, fld, sfifprf, r2sp) \
1815 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
1816 ppc_vsr_t *xa, ppc_vsr_t *xb) \
1818 ppc_vsr_t t = { }; \
1821 helper_reset_fpstatus(env); \
1823 for (i = 0; i < nels; i++) { \
1824 float_status tstat = env->fp_status; \
1825 set_float_exception_flags(0, &tstat); \
1826 t.fld = tp##_div(xa->fld, xb->fld, &tstat); \
1827 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1829 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1830 float_invalid_op_div(env, tstat.float_exception_flags, \
1831 sfifprf, GETPC()); \
1833 if (unlikely(tstat.float_exception_flags & float_flag_divbyzero)) { \
1834 float_zero_divide_excp(env, GETPC()); \
1838 t.fld = do_frsp(env, t.fld, GETPC()); \
1842 helper_compute_fprf_float64(env, t.fld); \
1847 do_float_check_status(env, sfifprf, GETPC()); \
1850 VSX_DIV(xsdivdp
, 1, float64
, VsrD(0), 1, 0)
1851 VSX_DIV(xsdivsp
, 1, float64
, VsrD(0), 1, 1)
1852 VSX_DIV(xvdivdp
, 2, float64
, VsrD(i
), 0, 0)
1853 VSX_DIV(xvdivsp
, 4, float32
, VsrW(i
), 0, 0)
1855 void helper_xsdivqp(CPUPPCState
*env
, uint32_t opcode
,
1856 ppc_vsr_t
*xt
, ppc_vsr_t
*xa
, ppc_vsr_t
*xb
)
1861 helper_reset_fpstatus(env
);
1862 tstat
= env
->fp_status
;
1863 if (unlikely(Rc(opcode
) != 0)) {
1864 tstat
.float_rounding_mode
= float_round_to_odd
;
1867 set_float_exception_flags(0, &tstat
);
1868 t
.f128
= float128_div(xa
->f128
, xb
->f128
, &tstat
);
1869 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
1871 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
1872 float_invalid_op_div(env
, tstat
.float_exception_flags
, 1, GETPC());
1874 if (unlikely(tstat
.float_exception_flags
& float_flag_divbyzero
)) {
1875 float_zero_divide_excp(env
, GETPC());
1878 helper_compute_fprf_float128(env
, t
.f128
);
1880 do_float_check_status(env
, true, GETPC());
1884 * VSX_RE - VSX floating point reciprocal estimate
1885 * op - instruction mnemonic
1886 * nels - number of elements (1, 2 or 4)
1887 * tp - type (float32 or float64)
1888 * fld - vsr_t field (VsrD(*) or VsrW(*))
1889 * sfifprf - set FI and FPRF
1891 #define VSX_RE(op, nels, tp, fld, sfifprf, r2sp) \
1892 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
1894 ppc_vsr_t t = { }; \
1897 helper_reset_fpstatus(env); \
1899 for (i = 0; i < nels; i++) { \
1900 if (unlikely(tp##_is_signaling_nan(xb->fld, &env->fp_status))) { \
1901 float_invalid_op_vxsnan(env, GETPC()); \
1903 t.fld = tp##_div(tp##_one, xb->fld, &env->fp_status); \
1906 t.fld = do_frsp(env, t.fld, GETPC()); \
1910 helper_compute_fprf_float64(env, t.fld); \
1915 do_float_check_status(env, sfifprf, GETPC()); \
1918 VSX_RE(xsredp
, 1, float64
, VsrD(0), 1, 0)
1919 VSX_RE(xsresp
, 1, float64
, VsrD(0), 1, 1)
1920 VSX_RE(xvredp
, 2, float64
, VsrD(i
), 0, 0)
1921 VSX_RE(xvresp
, 4, float32
, VsrW(i
), 0, 0)
1924 * VSX_SQRT - VSX floating point square root
1925 * op - instruction mnemonic
1926 * nels - number of elements (1, 2 or 4)
1927 * tp - type (float32 or float64)
1928 * fld - vsr_t field (VsrD(*) or VsrW(*))
1929 * sfifprf - set FI and FPRF
1931 #define VSX_SQRT(op, nels, tp, fld, sfifprf, r2sp) \
1932 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
1934 ppc_vsr_t t = { }; \
1937 helper_reset_fpstatus(env); \
1939 for (i = 0; i < nels; i++) { \
1940 float_status tstat = env->fp_status; \
1941 set_float_exception_flags(0, &tstat); \
1942 t.fld = tp##_sqrt(xb->fld, &tstat); \
1943 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1945 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1946 float_invalid_op_sqrt(env, tstat.float_exception_flags, \
1947 sfifprf, GETPC()); \
1951 t.fld = do_frsp(env, t.fld, GETPC()); \
1955 helper_compute_fprf_float64(env, t.fld); \
1960 do_float_check_status(env, sfifprf, GETPC()); \
1963 VSX_SQRT(xssqrtdp
, 1, float64
, VsrD(0), 1, 0)
1964 VSX_SQRT(xssqrtsp
, 1, float64
, VsrD(0), 1, 1)
1965 VSX_SQRT(xvsqrtdp
, 2, float64
, VsrD(i
), 0, 0)
1966 VSX_SQRT(xvsqrtsp
, 4, float32
, VsrW(i
), 0, 0)
1969 *VSX_RSQRTE - VSX floating point reciprocal square root estimate
1970 * op - instruction mnemonic
1971 * nels - number of elements (1, 2 or 4)
1972 * tp - type (float32 or float64)
1973 * fld - vsr_t field (VsrD(*) or VsrW(*))
1974 * sfifprf - set FI and FPRF
1976 #define VSX_RSQRTE(op, nels, tp, fld, sfifprf, r2sp) \
1977 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
1979 ppc_vsr_t t = { }; \
1982 helper_reset_fpstatus(env); \
1984 for (i = 0; i < nels; i++) { \
1985 float_status tstat = env->fp_status; \
1986 set_float_exception_flags(0, &tstat); \
1987 t.fld = tp##_sqrt(xb->fld, &tstat); \
1988 t.fld = tp##_div(tp##_one, t.fld, &tstat); \
1989 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
1990 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
1991 float_invalid_op_sqrt(env, tstat.float_exception_flags, \
1992 sfifprf, GETPC()); \
1995 t.fld = do_frsp(env, t.fld, GETPC()); \
1999 helper_compute_fprf_float64(env, t.fld); \
2004 do_float_check_status(env, sfifprf, GETPC()); \
2007 VSX_RSQRTE(xsrsqrtedp
, 1, float64
, VsrD(0), 1, 0)
2008 VSX_RSQRTE(xsrsqrtesp
, 1, float64
, VsrD(0), 1, 1)
2009 VSX_RSQRTE(xvrsqrtedp
, 2, float64
, VsrD(i
), 0, 0)
2010 VSX_RSQRTE(xvrsqrtesp
, 4, float32
, VsrW(i
), 0, 0)
2013 * VSX_TDIV - VSX floating point test for divide
2014 * op - instruction mnemonic
2015 * nels - number of elements (1, 2 or 4)
2016 * tp - type (float32 or float64)
2017 * fld - vsr_t field (VsrD(*) or VsrW(*))
2018 * emin - minimum unbiased exponent
2019 * emax - maximum unbiased exponent
2020 * nbits - number of fraction bits
2022 #define VSX_TDIV(op, nels, tp, fld, emin, emax, nbits) \
2023 void helper_##op(CPUPPCState *env, uint32_t opcode, \
2024 ppc_vsr_t *xa, ppc_vsr_t *xb) \
2030 for (i = 0; i < nels; i++) { \
2031 if (unlikely(tp##_is_infinity(xa->fld) || \
2032 tp##_is_infinity(xb->fld) || \
2033 tp##_is_zero(xb->fld))) { \
2037 int e_a = ppc_##tp##_get_unbiased_exp(xa->fld); \
2038 int e_b = ppc_##tp##_get_unbiased_exp(xb->fld); \
2040 if (unlikely(tp##_is_any_nan(xa->fld) || \
2041 tp##_is_any_nan(xb->fld))) { \
2043 } else if ((e_b <= emin) || (e_b >= (emax - 2))) { \
2045 } else if (!tp##_is_zero(xa->fld) && \
2046 (((e_a - e_b) >= emax) || \
2047 ((e_a - e_b) <= (emin + 1)) || \
2048 (e_a <= (emin + nbits)))) { \
2052 if (unlikely(tp##_is_zero_or_denormal(xb->fld))) { \
2054 * XB is not zero because of the above check and so \
2055 * must be denormalized. \
2062 env->crf[BF(opcode)] = 0x8 | (fg_flag ? 4 : 0) | (fe_flag ? 2 : 0); \
2065 VSX_TDIV(xstdivdp
, 1, float64
, VsrD(0), -1022, 1023, 52)
2066 VSX_TDIV(xvtdivdp
, 2, float64
, VsrD(i
), -1022, 1023, 52)
2067 VSX_TDIV(xvtdivsp
, 4, float32
, VsrW(i
), -126, 127, 23)
2070 * VSX_TSQRT - VSX floating point test for square root
2071 * op - instruction mnemonic
2072 * nels - number of elements (1, 2 or 4)
2073 * tp - type (float32 or float64)
2074 * fld - vsr_t field (VsrD(*) or VsrW(*))
2075 * emin - minimum unbiased exponent
2076 * emax - maximum unbiased exponent
2077 * nbits - number of fraction bits
2079 #define VSX_TSQRT(op, nels, tp, fld, emin, nbits) \
2080 void helper_##op(CPUPPCState *env, uint32_t opcode, ppc_vsr_t *xb) \
2086 for (i = 0; i < nels; i++) { \
2087 if (unlikely(tp##_is_infinity(xb->fld) || \
2088 tp##_is_zero(xb->fld))) { \
2092 int e_b = ppc_##tp##_get_unbiased_exp(xb->fld); \
2094 if (unlikely(tp##_is_any_nan(xb->fld))) { \
2096 } else if (unlikely(tp##_is_zero(xb->fld))) { \
2098 } else if (unlikely(tp##_is_neg(xb->fld))) { \
2100 } else if (!tp##_is_zero(xb->fld) && \
2101 (e_b <= (emin + nbits))) { \
2105 if (unlikely(tp##_is_zero_or_denormal(xb->fld))) { \
2107 * XB is not zero because of the above check and \
2108 * therefore must be denormalized. \
2115 env->crf[BF(opcode)] = 0x8 | (fg_flag ? 4 : 0) | (fe_flag ? 2 : 0); \
2118 VSX_TSQRT(xstsqrtdp
, 1, float64
, VsrD(0), -1022, 52)
2119 VSX_TSQRT(xvtsqrtdp
, 2, float64
, VsrD(i
), -1022, 52)
2120 VSX_TSQRT(xvtsqrtsp
, 4, float32
, VsrW(i
), -126, 23)
2123 * VSX_MADD - VSX floating point muliply/add variations
2124 * op - instruction mnemonic
2125 * nels - number of elements (1, 2 or 4)
2126 * tp - type (float32 or float64)
2127 * fld - vsr_t field (VsrD(*) or VsrW(*))
2128 * maddflgs - flags for the float*muladd routine that control the
2129 * various forms (madd, msub, nmadd, nmsub)
2130 * sfifprf - set FI and FPRF
2132 #define VSX_MADD(op, nels, tp, fld, maddflgs, sfifprf) \
2133 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
2134 ppc_vsr_t *s1, ppc_vsr_t *s2, ppc_vsr_t *s3) \
2136 ppc_vsr_t t = { }; \
2139 helper_reset_fpstatus(env); \
2141 for (i = 0; i < nels; i++) { \
2142 float_status tstat = env->fp_status; \
2143 set_float_exception_flags(0, &tstat); \
2144 t.fld = tp##_muladd(s1->fld, s3->fld, s2->fld, maddflgs, &tstat); \
2145 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
2147 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
2148 float_invalid_op_madd(env, tstat.float_exception_flags, \
2149 sfifprf, GETPC()); \
2153 helper_compute_fprf_float64(env, t.fld); \
2157 do_float_check_status(env, sfifprf, GETPC()); \
2160 VSX_MADD(XSMADDDP
, 1, float64
, VsrD(0), MADD_FLGS
, 1)
2161 VSX_MADD(XSMSUBDP
, 1, float64
, VsrD(0), MSUB_FLGS
, 1)
2162 VSX_MADD(XSNMADDDP
, 1, float64
, VsrD(0), NMADD_FLGS
, 1)
2163 VSX_MADD(XSNMSUBDP
, 1, float64
, VsrD(0), NMSUB_FLGS
, 1)
2164 VSX_MADD(XSMADDSP
, 1, float64r32
, VsrD(0), MADD_FLGS
, 1)
2165 VSX_MADD(XSMSUBSP
, 1, float64r32
, VsrD(0), MSUB_FLGS
, 1)
2166 VSX_MADD(XSNMADDSP
, 1, float64r32
, VsrD(0), NMADD_FLGS
, 1)
2167 VSX_MADD(XSNMSUBSP
, 1, float64r32
, VsrD(0), NMSUB_FLGS
, 1)
2169 VSX_MADD(xvmadddp
, 2, float64
, VsrD(i
), MADD_FLGS
, 0)
2170 VSX_MADD(xvmsubdp
, 2, float64
, VsrD(i
), MSUB_FLGS
, 0)
2171 VSX_MADD(xvnmadddp
, 2, float64
, VsrD(i
), NMADD_FLGS
, 0)
2172 VSX_MADD(xvnmsubdp
, 2, float64
, VsrD(i
), NMSUB_FLGS
, 0)
2174 VSX_MADD(xvmaddsp
, 4, float32
, VsrW(i
), MADD_FLGS
, 0)
2175 VSX_MADD(xvmsubsp
, 4, float32
, VsrW(i
), MSUB_FLGS
, 0)
2176 VSX_MADD(xvnmaddsp
, 4, float32
, VsrW(i
), NMADD_FLGS
, 0)
2177 VSX_MADD(xvnmsubsp
, 4, float32
, VsrW(i
), NMSUB_FLGS
, 0)
2180 * VSX_MADDQ - VSX floating point quad-precision muliply/add
2181 * op - instruction mnemonic
2182 * maddflgs - flags for the float*muladd routine that control the
2183 * various forms (madd, msub, nmadd, nmsub)
2186 #define VSX_MADDQ(op, maddflgs, ro) \
2187 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *s1, ppc_vsr_t *s2,\
2190 ppc_vsr_t t = *xt; \
2192 helper_reset_fpstatus(env); \
2194 float_status tstat = env->fp_status; \
2195 set_float_exception_flags(0, &tstat); \
2197 tstat.float_rounding_mode = float_round_to_odd; \
2199 t.f128 = float128_muladd(s1->f128, s3->f128, s2->f128, maddflgs, &tstat); \
2200 env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
2202 if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
2203 float_invalid_op_madd(env, tstat.float_exception_flags, \
2207 helper_compute_fprf_float128(env, t.f128); \
2209 do_float_check_status(env, true, GETPC()); \
2212 VSX_MADDQ(XSMADDQP
, MADD_FLGS
, 0)
2213 VSX_MADDQ(XSMADDQPO
, MADD_FLGS
, 1)
2214 VSX_MADDQ(XSMSUBQP
, MSUB_FLGS
, 0)
2215 VSX_MADDQ(XSMSUBQPO
, MSUB_FLGS
, 1)
2216 VSX_MADDQ(XSNMADDQP
, NMADD_FLGS
, 0)
2217 VSX_MADDQ(XSNMADDQPO
, NMADD_FLGS
, 1)
2218 VSX_MADDQ(XSNMSUBQP
, NMSUB_FLGS
, 0)
2219 VSX_MADDQ(XSNMSUBQPO
, NMSUB_FLGS
, 0)
2222 * VSX_SCALAR_CMP - VSX scalar floating point compare
2223 * op - instruction mnemonic
2225 * cmp - comparison operation
2227 * svxvc - set VXVC bit
2229 #define VSX_SCALAR_CMP(op, tp, cmp, fld, svxvc) \
2230 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
2231 ppc_vsr_t *xa, ppc_vsr_t *xb) \
2236 helper_reset_fpstatus(env); \
2239 r = tp##_##cmp(xb->fld, xa->fld, &env->fp_status); \
2241 r = tp##_##cmp##_quiet(xb->fld, xa->fld, &env->fp_status); \
2244 flags = get_float_exception_flags(&env->fp_status); \
2245 if (unlikely(flags & float_flag_invalid)) { \
2247 if (flags & float_flag_invalid_snan) { \
2248 float_invalid_op_vxsnan(env, GETPC()); \
2249 vxvc &= !(env->fpscr & FP_VE); \
2252 float_invalid_op_vxvc(env, 0, GETPC()); \
2256 memset(xt, 0, sizeof(*xt)); \
2257 memset(&xt->fld, -r, sizeof(xt->fld)); \
2258 do_float_check_status(env, false, GETPC()); \
2261 VSX_SCALAR_CMP(XSCMPEQDP
, float64
, eq
, VsrD(0), 0)
2262 VSX_SCALAR_CMP(XSCMPGEDP
, float64
, le
, VsrD(0), 1)
2263 VSX_SCALAR_CMP(XSCMPGTDP
, float64
, lt
, VsrD(0), 1)
2264 VSX_SCALAR_CMP(XSCMPEQQP
, float128
, eq
, f128
, 0)
2265 VSX_SCALAR_CMP(XSCMPGEQP
, float128
, le
, f128
, 1)
2266 VSX_SCALAR_CMP(XSCMPGTQP
, float128
, lt
, f128
, 1)
2268 void helper_xscmpexpdp(CPUPPCState
*env
, uint32_t opcode
,
2269 ppc_vsr_t
*xa
, ppc_vsr_t
*xb
)
2271 int64_t exp_a
, exp_b
;
2274 exp_a
= extract64(xa
->VsrD(0), 52, 11);
2275 exp_b
= extract64(xb
->VsrD(0), 52, 11);
2277 if (unlikely(float64_is_any_nan(xa
->VsrD(0)) ||
2278 float64_is_any_nan(xb
->VsrD(0)))) {
2281 if (exp_a
< exp_b
) {
2283 } else if (exp_a
> exp_b
) {
2290 env
->fpscr
&= ~FP_FPCC
;
2291 env
->fpscr
|= cc
<< FPSCR_FPCC
;
2292 env
->crf
[BF(opcode
)] = cc
;
2294 do_float_check_status(env
, false, GETPC());
2297 void helper_xscmpexpqp(CPUPPCState
*env
, uint32_t opcode
,
2298 ppc_vsr_t
*xa
, ppc_vsr_t
*xb
)
2300 int64_t exp_a
, exp_b
;
2303 exp_a
= extract64(xa
->VsrD(0), 48, 15);
2304 exp_b
= extract64(xb
->VsrD(0), 48, 15);
2306 if (unlikely(float128_is_any_nan(xa
->f128
) ||
2307 float128_is_any_nan(xb
->f128
))) {
2310 if (exp_a
< exp_b
) {
2312 } else if (exp_a
> exp_b
) {
2319 env
->fpscr
&= ~FP_FPCC
;
2320 env
->fpscr
|= cc
<< FPSCR_FPCC
;
2321 env
->crf
[BF(opcode
)] = cc
;
2323 do_float_check_status(env
, false, GETPC());
2326 static inline void do_scalar_cmp(CPUPPCState
*env
, ppc_vsr_t
*xa
, ppc_vsr_t
*xb
,
2327 int crf_idx
, bool ordered
)
2330 bool vxsnan_flag
= false, vxvc_flag
= false;
2332 helper_reset_fpstatus(env
);
2334 switch (float64_compare(xa
->VsrD(0), xb
->VsrD(0), &env
->fp_status
)) {
2335 case float_relation_less
:
2338 case float_relation_equal
:
2341 case float_relation_greater
:
2344 case float_relation_unordered
:
2347 if (float64_is_signaling_nan(xa
->VsrD(0), &env
->fp_status
) ||
2348 float64_is_signaling_nan(xb
->VsrD(0), &env
->fp_status
)) {
2350 if (!(env
->fpscr
& FP_VE
) && ordered
) {
2353 } else if (float64_is_quiet_nan(xa
->VsrD(0), &env
->fp_status
) ||
2354 float64_is_quiet_nan(xb
->VsrD(0), &env
->fp_status
)) {
2362 g_assert_not_reached();
2365 env
->fpscr
&= ~FP_FPCC
;
2366 env
->fpscr
|= cc
<< FPSCR_FPCC
;
2367 env
->crf
[crf_idx
] = cc
;
2370 float_invalid_op_vxsnan(env
, GETPC());
2373 float_invalid_op_vxvc(env
, 0, GETPC());
2376 do_float_check_status(env
, false, GETPC());
2379 void helper_xscmpodp(CPUPPCState
*env
, uint32_t opcode
, ppc_vsr_t
*xa
,
2382 do_scalar_cmp(env
, xa
, xb
, BF(opcode
), true);
2385 void helper_xscmpudp(CPUPPCState
*env
, uint32_t opcode
, ppc_vsr_t
*xa
,
2388 do_scalar_cmp(env
, xa
, xb
, BF(opcode
), false);
2391 static inline void do_scalar_cmpq(CPUPPCState
*env
, ppc_vsr_t
*xa
,
2392 ppc_vsr_t
*xb
, int crf_idx
, bool ordered
)
2395 bool vxsnan_flag
= false, vxvc_flag
= false;
2397 helper_reset_fpstatus(env
);
2399 switch (float128_compare(xa
->f128
, xb
->f128
, &env
->fp_status
)) {
2400 case float_relation_less
:
2403 case float_relation_equal
:
2406 case float_relation_greater
:
2409 case float_relation_unordered
:
2412 if (float128_is_signaling_nan(xa
->f128
, &env
->fp_status
) ||
2413 float128_is_signaling_nan(xb
->f128
, &env
->fp_status
)) {
2415 if (!(env
->fpscr
& FP_VE
) && ordered
) {
2418 } else if (float128_is_quiet_nan(xa
->f128
, &env
->fp_status
) ||
2419 float128_is_quiet_nan(xb
->f128
, &env
->fp_status
)) {
2427 g_assert_not_reached();
2430 env
->fpscr
&= ~FP_FPCC
;
2431 env
->fpscr
|= cc
<< FPSCR_FPCC
;
2432 env
->crf
[crf_idx
] = cc
;
2435 float_invalid_op_vxsnan(env
, GETPC());
2438 float_invalid_op_vxvc(env
, 0, GETPC());
2441 do_float_check_status(env
, false, GETPC());
2444 void helper_xscmpoqp(CPUPPCState
*env
, uint32_t opcode
, ppc_vsr_t
*xa
,
2447 do_scalar_cmpq(env
, xa
, xb
, BF(opcode
), true);
2450 void helper_xscmpuqp(CPUPPCState
*env
, uint32_t opcode
, ppc_vsr_t
*xa
,
2453 do_scalar_cmpq(env
, xa
, xb
, BF(opcode
), false);
2457 * VSX_MAX_MIN - VSX floating point maximum/minimum
2458 * name - instruction mnemonic
2459 * op - operation (max or min)
2460 * nels - number of elements (1, 2 or 4)
2461 * tp - type (float32 or float64)
2462 * fld - vsr_t field (VsrD(*) or VsrW(*))
2464 #define VSX_MAX_MIN(name, op, nels, tp, fld) \
2465 void helper_##name(CPUPPCState *env, ppc_vsr_t *xt, \
2466 ppc_vsr_t *xa, ppc_vsr_t *xb) \
2468 ppc_vsr_t t = { }; \
2471 for (i = 0; i < nels; i++) { \
2472 t.fld = tp##_##op(xa->fld, xb->fld, &env->fp_status); \
2473 if (unlikely(tp##_is_signaling_nan(xa->fld, &env->fp_status) || \
2474 tp##_is_signaling_nan(xb->fld, &env->fp_status))) { \
2475 float_invalid_op_vxsnan(env, GETPC()); \
2480 do_float_check_status(env, false, GETPC()); \
2483 VSX_MAX_MIN(xsmaxdp
, maxnum
, 1, float64
, VsrD(0))
2484 VSX_MAX_MIN(xvmaxdp
, maxnum
, 2, float64
, VsrD(i
))
2485 VSX_MAX_MIN(xvmaxsp
, maxnum
, 4, float32
, VsrW(i
))
2486 VSX_MAX_MIN(xsmindp
, minnum
, 1, float64
, VsrD(0))
2487 VSX_MAX_MIN(xvmindp
, minnum
, 2, float64
, VsrD(i
))
2488 VSX_MAX_MIN(xvminsp
, minnum
, 4, float32
, VsrW(i
))
2490 #define VSX_MAX_MINC(name, max, tp, fld) \
2491 void helper_##name(CPUPPCState *env, \
2492 ppc_vsr_t *xt, ppc_vsr_t *xa, ppc_vsr_t *xb) \
2494 ppc_vsr_t t = { }; \
2497 helper_reset_fpstatus(env); \
2500 first = tp##_le_quiet(xb->fld, xa->fld, &env->fp_status); \
2502 first = tp##_lt_quiet(xa->fld, xb->fld, &env->fp_status); \
2509 if (env->fp_status.float_exception_flags & float_flag_invalid_snan) { \
2510 float_invalid_op_vxsnan(env, GETPC()); \
2517 VSX_MAX_MINC(XSMAXCDP
, true, float64
, VsrD(0));
2518 VSX_MAX_MINC(XSMINCDP
, false, float64
, VsrD(0));
2519 VSX_MAX_MINC(XSMAXCQP
, true, float128
, f128
);
2520 VSX_MAX_MINC(XSMINCQP
, false, float128
, f128
);
2522 #define VSX_MAX_MINJ(name, max) \
2523 void helper_##name(CPUPPCState *env, \
2524 ppc_vsr_t *xt, ppc_vsr_t *xa, ppc_vsr_t *xb) \
2526 ppc_vsr_t t = { }; \
2527 bool vxsnan_flag = false, vex_flag = false; \
2529 if (unlikely(float64_is_any_nan(xa->VsrD(0)))) { \
2530 if (float64_is_signaling_nan(xa->VsrD(0), &env->fp_status)) { \
2531 vxsnan_flag = true; \
2533 t.VsrD(0) = xa->VsrD(0); \
2534 } else if (unlikely(float64_is_any_nan(xb->VsrD(0)))) { \
2535 if (float64_is_signaling_nan(xb->VsrD(0), &env->fp_status)) { \
2536 vxsnan_flag = true; \
2538 t.VsrD(0) = xb->VsrD(0); \
2539 } else if (float64_is_zero(xa->VsrD(0)) && \
2540 float64_is_zero(xb->VsrD(0))) { \
2542 if (!float64_is_neg(xa->VsrD(0)) || \
2543 !float64_is_neg(xb->VsrD(0))) { \
2546 t.VsrD(0) = 0x8000000000000000ULL; \
2549 if (float64_is_neg(xa->VsrD(0)) || \
2550 float64_is_neg(xb->VsrD(0))) { \
2551 t.VsrD(0) = 0x8000000000000000ULL; \
2556 } else if ((max && \
2557 !float64_lt(xa->VsrD(0), xb->VsrD(0), &env->fp_status)) || \
2559 float64_lt(xa->VsrD(0), xb->VsrD(0), &env->fp_status))) { \
2560 t.VsrD(0) = xa->VsrD(0); \
2562 t.VsrD(0) = xb->VsrD(0); \
2565 vex_flag = (env->fpscr & FP_VE) && vxsnan_flag; \
2566 if (vxsnan_flag) { \
2567 float_invalid_op_vxsnan(env, GETPC()); \
2574 VSX_MAX_MINJ(XSMAXJDP, 1);
2575 VSX_MAX_MINJ(XSMINJDP
, 0);
2578 * VSX_CMP - VSX floating point compare
2579 * op - instruction mnemonic
2580 * nels - number of elements (1, 2 or 4)
2581 * tp - type (float32 or float64)
2582 * fld - vsr_t field (VsrD(*) or VsrW(*))
2583 * cmp - comparison operation
2584 * svxvc - set VXVC bit
2585 * exp - expected result of comparison
2587 #define VSX_CMP(op, nels, tp, fld, cmp, svxvc, exp) \
2588 uint32_t helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
2589 ppc_vsr_t *xa, ppc_vsr_t *xb) \
2591 ppc_vsr_t t = *xt; \
2592 uint32_t crf6 = 0; \
2595 int all_false = 1; \
2597 helper_reset_fpstatus(env); \
2599 for (i = 0; i < nels; i++) { \
2600 if (unlikely(tp##_is_any_nan(xa->fld) || \
2601 tp##_is_any_nan(xb->fld))) { \
2602 if (tp##_is_signaling_nan(xa->fld, &env->fp_status) || \
2603 tp##_is_signaling_nan(xb->fld, &env->fp_status)) { \
2604 float_invalid_op_vxsnan(env, GETPC()); \
2607 float_invalid_op_vxvc(env, 0, GETPC()); \
2612 if (tp##_##cmp(xb->fld, xa->fld, &env->fp_status) == exp) { \
2623 crf6 = (all_true ? 0x8 : 0) | (all_false ? 0x2 : 0); \
2627 VSX_CMP(xvcmpeqdp
, 2, float64
, VsrD(i
), eq
, 0, 1)
2628 VSX_CMP(xvcmpgedp
, 2, float64
, VsrD(i
), le
, 1, 1)
2629 VSX_CMP(xvcmpgtdp
, 2, float64
, VsrD(i
), lt
, 1, 1)
2630 VSX_CMP(xvcmpnedp
, 2, float64
, VsrD(i
), eq
, 0, 0)
2631 VSX_CMP(xvcmpeqsp
, 4, float32
, VsrW(i
), eq
, 0, 1)
2632 VSX_CMP(xvcmpgesp
, 4, float32
, VsrW(i
), le
, 1, 1)
2633 VSX_CMP(xvcmpgtsp
, 4, float32
, VsrW(i
), lt
, 1, 1)
2634 VSX_CMP(xvcmpnesp
, 4, float32
, VsrW(i
), eq
, 0, 0)
2637 * VSX_CVT_FP_TO_FP - VSX floating point/floating point conversion
2638 * op - instruction mnemonic
2639 * nels - number of elements (1, 2 or 4)
2640 * stp - source type (float32 or float64)
2641 * ttp - target type (float32 or float64)
2642 * sfld - source vsr_t field
2643 * tfld - target vsr_t field (f32 or f64)
2644 * sfifprf - set FI and FPRF
2646 #define VSX_CVT_FP_TO_FP(op, nels, stp, ttp, sfld, tfld, sfifprf) \
2647 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
2649 ppc_vsr_t t = { }; \
2652 helper_reset_fpstatus(env); \
2654 for (i = 0; i < nels; i++) { \
2655 t.tfld = stp##_to_##ttp(xb->sfld, &env->fp_status); \
2656 if (unlikely(stp##_is_signaling_nan(xb->sfld, \
2657 &env->fp_status))) { \
2658 float_invalid_op_vxsnan(env, GETPC()); \
2659 t.tfld = ttp##_snan_to_qnan(t.tfld); \
2662 helper_compute_fprf_##ttp(env, t.tfld); \
2667 do_float_check_status(env, sfifprf, GETPC()); \
2670 VSX_CVT_FP_TO_FP(xscvspdp
, 1, float32
, float64
, VsrW(0), VsrD(0), 1)
2671 VSX_CVT_FP_TO_FP(xvcvspdp
, 2, float32
, float64
, VsrW(2 * i
), VsrD(i
), 0)
2673 #define VSX_CVT_FP_TO_FP2(op, nels, stp, ttp, sfifprf) \
2674 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
2676 ppc_vsr_t t = { }; \
2679 helper_reset_fpstatus(env); \
2681 for (i = 0; i < nels; i++) { \
2682 t.VsrW(2 * i) = stp##_to_##ttp(xb->VsrD(i), &env->fp_status); \
2683 if (unlikely(stp##_is_signaling_nan(xb->VsrD(i), \
2684 &env->fp_status))) { \
2685 float_invalid_op_vxsnan(env, GETPC()); \
2686 t.VsrW(2 * i) = ttp##_snan_to_qnan(t.VsrW(2 * i)); \
2689 helper_compute_fprf_##ttp(env, t.VsrW(2 * i)); \
2691 t.VsrW(2 * i + 1) = t.VsrW(2 * i); \
2695 do_float_check_status(env, sfifprf, GETPC()); \
2698 VSX_CVT_FP_TO_FP2(xvcvdpsp
, 2, float64
, float32
, 0)
2699 VSX_CVT_FP_TO_FP2(xscvdpsp
, 1, float64
, float32
, 1)
2702 * VSX_CVT_FP_TO_FP_VECTOR - VSX floating point/floating point conversion
2703 * op - instruction mnemonic
2704 * nels - number of elements (1, 2 or 4)
2705 * stp - source type (float32 or float64)
2706 * ttp - target type (float32 or float64)
2707 * sfld - source vsr_t field
2708 * tfld - target vsr_t field (f32 or f64)
2711 #define VSX_CVT_FP_TO_FP_VECTOR(op, nels, stp, ttp, sfld, tfld, sfprf) \
2712 void helper_##op(CPUPPCState *env, uint32_t opcode, \
2713 ppc_vsr_t *xt, ppc_vsr_t *xb) \
2715 ppc_vsr_t t = *xt; \
2718 helper_reset_fpstatus(env); \
2720 for (i = 0; i < nels; i++) { \
2721 t.tfld = stp##_to_##ttp(xb->sfld, &env->fp_status); \
2722 if (unlikely(stp##_is_signaling_nan(xb->sfld, \
2723 &env->fp_status))) { \
2724 float_invalid_op_vxsnan(env, GETPC()); \
2725 t.tfld = ttp##_snan_to_qnan(t.tfld); \
2728 helper_compute_fprf_##ttp(env, t.tfld); \
2733 do_float_check_status(env, true, GETPC()); \
2736 VSX_CVT_FP_TO_FP_VECTOR(xscvdpqp
, 1, float64
, float128
, VsrD(0), f128
, 1)
2739 * VSX_CVT_FP_TO_FP_HP - VSX floating point/floating point conversion
2740 * involving one half precision value
2741 * op - instruction mnemonic
2742 * nels - number of elements (1, 2 or 4)
2745 * sfld - source vsr_t field
2746 * tfld - target vsr_t field
2747 * sfifprf - set FI and FPRF
2749 #define VSX_CVT_FP_TO_FP_HP(op, nels, stp, ttp, sfld, tfld, sfifprf) \
2750 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
2752 ppc_vsr_t t = { }; \
2755 helper_reset_fpstatus(env); \
2757 for (i = 0; i < nels; i++) { \
2758 t.tfld = stp##_to_##ttp(xb->sfld, 1, &env->fp_status); \
2759 if (unlikely(stp##_is_signaling_nan(xb->sfld, \
2760 &env->fp_status))) { \
2761 float_invalid_op_vxsnan(env, GETPC()); \
2762 t.tfld = ttp##_snan_to_qnan(t.tfld); \
2765 helper_compute_fprf_##ttp(env, t.tfld); \
2770 do_float_check_status(env, sfifprf, GETPC()); \
2773 VSX_CVT_FP_TO_FP_HP(xscvdphp
, 1, float64
, float16
, VsrD(0), VsrH(3), 1)
2774 VSX_CVT_FP_TO_FP_HP(xscvhpdp
, 1, float16
, float64
, VsrH(3), VsrD(0), 1)
2775 VSX_CVT_FP_TO_FP_HP(xvcvsphp
, 4, float32
, float16
, VsrW(i
), VsrH(2 * i
+ 1), 0)
2776 VSX_CVT_FP_TO_FP_HP(xvcvhpsp
, 4, float16
, float32
, VsrH(2 * i
+ 1), VsrW(i
), 0)
2778 void helper_XVCVSPBF16(CPUPPCState
*env
, ppc_vsr_t
*xt
, ppc_vsr_t
*xb
)
2783 helper_reset_fpstatus(env
);
2785 for (i
= 0; i
< 4; i
++) {
2786 t
.VsrH(2 * i
+ 1) = float32_to_bfloat16(xb
->VsrW(i
), &env
->fp_status
);
2789 status
= get_float_exception_flags(&env
->fp_status
);
2790 if (unlikely(status
& float_flag_invalid_snan
)) {
2791 float_invalid_op_vxsnan(env
, GETPC());
2795 do_float_check_status(env
, false, GETPC());
2798 void helper_XSCVQPDP(CPUPPCState
*env
, uint32_t ro
, ppc_vsr_t
*xt
,
2804 helper_reset_fpstatus(env
);
2806 tstat
= env
->fp_status
;
2808 tstat
.float_rounding_mode
= float_round_to_odd
;
2811 t
.VsrD(0) = float128_to_float64(xb
->f128
, &tstat
);
2812 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
2813 if (unlikely(float128_is_signaling_nan(xb
->f128
, &tstat
))) {
2814 float_invalid_op_vxsnan(env
, GETPC());
2815 t
.VsrD(0) = float64_snan_to_qnan(t
.VsrD(0));
2817 helper_compute_fprf_float64(env
, t
.VsrD(0));
2820 do_float_check_status(env
, true, GETPC());
2823 uint64_t helper_xscvdpspn(CPUPPCState
*env
, uint64_t xb
)
2825 uint64_t result
, sign
, exp
, frac
;
2827 helper_reset_fpstatus(env
);
2828 float_status tstat
= env
->fp_status
;
2829 set_float_exception_flags(0, &tstat
);
2831 sign
= extract64(xb
, 63, 1);
2832 exp
= extract64(xb
, 52, 11);
2833 frac
= extract64(xb
, 0, 52) | 0x10000000000000ULL
;
2835 if (unlikely(exp
== 0 && extract64(frac
, 0, 52) != 0)) {
2836 /* DP denormal operand. */
2837 /* Exponent override to DP min exp. */
2839 /* Implicit bit override to 0. */
2840 frac
= deposit64(frac
, 53, 1, 0);
2843 if (unlikely(exp
< 897 && frac
!= 0)) {
2844 /* SP tiny operand. */
2845 if (897 - exp
> 63) {
2848 /* Denormalize until exp = SP min exp. */
2849 frac
>>= (897 - exp
);
2851 /* Exponent override to SP min exp - 1. */
2855 result
= sign
<< 31;
2856 result
|= extract64(exp
, 10, 1) << 30;
2857 result
|= extract64(exp
, 0, 7) << 23;
2858 result
|= extract64(frac
, 29, 23);
2860 /* hardware replicates result to both words of the doubleword result. */
2861 return (result
<< 32) | result
;
2864 uint64_t helper_XSCVSPDPN(uint64_t xb
)
2866 return helper_todouble(xb
>> 32);
2870 * VSX_CVT_FP_TO_INT - VSX floating point to integer conversion
2871 * op - instruction mnemonic
2872 * nels - number of elements (1, 2 or 4)
2873 * stp - source type (float32 or float64)
2874 * ttp - target type (int32, uint32, int64 or uint64)
2875 * sfld - source vsr_t field
2876 * tfld - target vsr_t field
2878 * rnan - resulting NaN
2880 #define VSX_CVT_FP_TO_INT(op, nels, stp, ttp, sfld, tfld, sfi, rnan) \
2881 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
2883 ppc_vsr_t t = { }; \
2886 helper_reset_fpstatus(env); \
2888 for (i = 0; i < nels; i++) { \
2889 t.tfld = stp##_to_##ttp##_round_to_zero(xb->sfld, &env->fp_status); \
2890 flags = env->fp_status.float_exception_flags; \
2891 if (unlikely(flags & float_flag_invalid)) { \
2892 t.tfld = float_invalid_cvt(env, flags, t.tfld, rnan, 0, GETPC());\
2897 do_float_check_status(env, sfi, GETPC()); \
2900 VSX_CVT_FP_TO_INT(xscvdpsxds
, 1, float64
, int64
, VsrD(0), VsrD(0), true, \
2901 0x8000000000000000ULL
)
2902 VSX_CVT_FP_TO_INT(xscvdpuxds
, 1, float64
, uint64
, VsrD(0), VsrD(0), true, 0ULL)
2903 VSX_CVT_FP_TO_INT(xvcvdpsxds
, 2, float64
, int64
, VsrD(i
), VsrD(i
), false, \
2904 0x8000000000000000ULL
)
2905 VSX_CVT_FP_TO_INT(xvcvdpuxds
, 2, float64
, uint64
, VsrD(i
), VsrD(i
), false, \
2907 VSX_CVT_FP_TO_INT(xvcvspsxds
, 2, float32
, int64
, VsrW(2 * i
), VsrD(i
), false, \
2908 0x8000000000000000ULL
)
2909 VSX_CVT_FP_TO_INT(xvcvspsxws
, 4, float32
, int32
, VsrW(i
), VsrW(i
), false, \
2911 VSX_CVT_FP_TO_INT(xvcvspuxds
, 2, float32
, uint64
, VsrW(2 * i
), VsrD(i
), \
2913 VSX_CVT_FP_TO_INT(xvcvspuxws
, 4, float32
, uint32
, VsrW(i
), VsrW(i
), false, 0U)
2915 #define VSX_CVT_FP_TO_INT128(op, tp, rnan) \
2916 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
2921 helper_reset_fpstatus(env); \
2922 t.s128 = float128_to_##tp##_round_to_zero(xb->f128, &env->fp_status); \
2923 flags = get_float_exception_flags(&env->fp_status); \
2924 if (unlikely(flags & float_flag_invalid)) { \
2925 t.VsrD(0) = float_invalid_cvt(env, flags, t.VsrD(0), rnan, 0, GETPC());\
2926 t.VsrD(1) = -(t.VsrD(0) & 1); \
2930 do_float_check_status(env, true, GETPC()); \
2933 VSX_CVT_FP_TO_INT128(XSCVQPUQZ
, uint128
, 0)
2934 VSX_CVT_FP_TO_INT128(XSCVQPSQZ
, int128
, 0x8000000000000000ULL
);
2937 * Likewise, except that the result is duplicated into both subwords.
2938 * Power ISA v3.1 has Programming Notes for these insns:
2939 * Previous versions of the architecture allowed the contents of
2940 * word 0 of the result register to be undefined. However, all
2941 * processors that support this instruction write the result into
2942 * words 0 and 1 (and words 2 and 3) of the result register, as
2943 * is required by this version of the architecture.
2945 #define VSX_CVT_FP_TO_INT2(op, nels, stp, ttp, sfi, rnan) \
2946 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
2948 ppc_vsr_t t = { }; \
2951 helper_reset_fpstatus(env); \
2953 for (i = 0; i < nels; i++) { \
2954 t.VsrW(2 * i) = stp##_to_##ttp##_round_to_zero(xb->VsrD(i), \
2956 flags = env->fp_status.float_exception_flags; \
2957 if (unlikely(flags & float_flag_invalid)) { \
2958 t.VsrW(2 * i) = float_invalid_cvt(env, flags, t.VsrW(2 * i), \
2959 rnan, 0, GETPC()); \
2961 t.VsrW(2 * i + 1) = t.VsrW(2 * i); \
2965 do_float_check_status(env, sfi, GETPC()); \
2968 VSX_CVT_FP_TO_INT2(xscvdpsxws
, 1, float64
, int32
, true, 0x80000000U
)
2969 VSX_CVT_FP_TO_INT2(xscvdpuxws
, 1, float64
, uint32
, true, 0U)
2970 VSX_CVT_FP_TO_INT2(xvcvdpsxws
, 2, float64
, int32
, false, 0x80000000U
)
2971 VSX_CVT_FP_TO_INT2(xvcvdpuxws
, 2, float64
, uint32
, false, 0U)
2974 * VSX_CVT_FP_TO_INT_VECTOR - VSX floating point to integer conversion
2975 * op - instruction mnemonic
2976 * stp - source type (float32 or float64)
2977 * ttp - target type (int32, uint32, int64 or uint64)
2978 * sfld - source vsr_t field
2979 * tfld - target vsr_t field
2980 * rnan - resulting NaN
2982 #define VSX_CVT_FP_TO_INT_VECTOR(op, stp, ttp, sfld, tfld, rnan) \
2983 void helper_##op(CPUPPCState *env, uint32_t opcode, \
2984 ppc_vsr_t *xt, ppc_vsr_t *xb) \
2986 ppc_vsr_t t = { }; \
2989 helper_reset_fpstatus(env); \
2991 t.tfld = stp##_to_##ttp##_round_to_zero(xb->sfld, &env->fp_status); \
2992 flags = get_float_exception_flags(&env->fp_status); \
2993 if (flags & float_flag_invalid) { \
2994 t.tfld = float_invalid_cvt(env, flags, t.tfld, rnan, 0, GETPC()); \
2998 do_float_check_status(env, true, GETPC()); \
3001 VSX_CVT_FP_TO_INT_VECTOR(xscvqpsdz
, float128
, int64
, f128
, VsrD(0), \
3002 0x8000000000000000ULL
)
3003 VSX_CVT_FP_TO_INT_VECTOR(xscvqpswz
, float128
, int32
, f128
, VsrD(0), \
3004 0xffffffff80000000ULL
)
3005 VSX_CVT_FP_TO_INT_VECTOR(xscvqpudz
, float128
, uint64
, f128
, VsrD(0), 0x0ULL
)
3006 VSX_CVT_FP_TO_INT_VECTOR(xscvqpuwz
, float128
, uint32
, f128
, VsrD(0), 0x0ULL
)
3009 * VSX_CVT_INT_TO_FP - VSX integer to floating point conversion
3010 * op - instruction mnemonic
3011 * nels - number of elements (1, 2 or 4)
3012 * stp - source type (int32, uint32, int64 or uint64)
3013 * ttp - target type (float32 or float64)
3014 * sfld - source vsr_t field
3015 * tfld - target vsr_t field
3016 * jdef - definition of the j index (i or 2*i)
3017 * sfifprf - set FI and FPRF
3019 #define VSX_CVT_INT_TO_FP(op, nels, stp, ttp, sfld, tfld, sfifprf, r2sp)\
3020 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
3022 ppc_vsr_t t = { }; \
3025 helper_reset_fpstatus(env); \
3027 for (i = 0; i < nels; i++) { \
3028 t.tfld = stp##_to_##ttp(xb->sfld, &env->fp_status); \
3030 t.tfld = do_frsp(env, t.tfld, GETPC()); \
3033 helper_compute_fprf_float64(env, t.tfld); \
3038 do_float_check_status(env, sfifprf, GETPC()); \
3041 VSX_CVT_INT_TO_FP(xscvsxddp
, 1, int64
, float64
, VsrD(0), VsrD(0), 1, 0)
3042 VSX_CVT_INT_TO_FP(xscvuxddp
, 1, uint64
, float64
, VsrD(0), VsrD(0), 1, 0)
3043 VSX_CVT_INT_TO_FP(xscvsxdsp
, 1, int64
, float64
, VsrD(0), VsrD(0), 1, 1)
3044 VSX_CVT_INT_TO_FP(xscvuxdsp
, 1, uint64
, float64
, VsrD(0), VsrD(0), 1, 1)
3045 VSX_CVT_INT_TO_FP(xvcvsxddp
, 2, int64
, float64
, VsrD(i
), VsrD(i
), 0, 0)
3046 VSX_CVT_INT_TO_FP(xvcvuxddp
, 2, uint64
, float64
, VsrD(i
), VsrD(i
), 0, 0)
3047 VSX_CVT_INT_TO_FP(xvcvsxwdp
, 2, int32
, float64
, VsrW(2 * i
), VsrD(i
), 0, 0)
3048 VSX_CVT_INT_TO_FP(xvcvuxwdp
, 2, uint64
, float64
, VsrW(2 * i
), VsrD(i
), 0, 0)
3049 VSX_CVT_INT_TO_FP(xvcvsxwsp
, 4, int32
, float32
, VsrW(i
), VsrW(i
), 0, 0)
3050 VSX_CVT_INT_TO_FP(xvcvuxwsp
, 4, uint32
, float32
, VsrW(i
), VsrW(i
), 0, 0)
3052 #define VSX_CVT_INT_TO_FP2(op, stp, ttp) \
3053 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
3055 ppc_vsr_t t = { }; \
3058 for (i = 0; i < 2; i++) { \
3059 t.VsrW(2 * i) = stp##_to_##ttp(xb->VsrD(i), &env->fp_status); \
3060 t.VsrW(2 * i + 1) = t.VsrW(2 * i); \
3064 do_float_check_status(env, false, GETPC()); \
3067 VSX_CVT_INT_TO_FP2(xvcvsxdsp
, int64
, float32
)
3068 VSX_CVT_INT_TO_FP2(xvcvuxdsp
, uint64
, float32
)
3070 #define VSX_CVT_INT128_TO_FP(op, tp) \
3071 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb)\
3073 helper_reset_fpstatus(env); \
3074 xt->f128 = tp##_to_float128(xb->s128, &env->fp_status); \
3075 helper_compute_fprf_float128(env, xt->f128); \
3076 do_float_check_status(env, true, GETPC()); \
3079 VSX_CVT_INT128_TO_FP(XSCVUQQP
, uint128
);
3080 VSX_CVT_INT128_TO_FP(XSCVSQQP
, int128
);
3083 * VSX_CVT_INT_TO_FP_VECTOR - VSX integer to floating point conversion
3084 * op - instruction mnemonic
3085 * stp - source type (int32, uint32, int64 or uint64)
3086 * ttp - target type (float32 or float64)
3087 * sfld - source vsr_t field
3088 * tfld - target vsr_t field
3090 #define VSX_CVT_INT_TO_FP_VECTOR(op, stp, ttp, sfld, tfld) \
3091 void helper_##op(CPUPPCState *env, uint32_t opcode, \
3092 ppc_vsr_t *xt, ppc_vsr_t *xb) \
3094 ppc_vsr_t t = *xt; \
3096 helper_reset_fpstatus(env); \
3097 t.tfld = stp##_to_##ttp(xb->sfld, &env->fp_status); \
3098 helper_compute_fprf_##ttp(env, t.tfld); \
3101 do_float_check_status(env, true, GETPC()); \
3104 VSX_CVT_INT_TO_FP_VECTOR(xscvsdqp
, int64
, float128
, VsrD(0), f128
)
3105 VSX_CVT_INT_TO_FP_VECTOR(xscvudqp
, uint64
, float128
, VsrD(0), f128
)
3108 * For "use current rounding mode", define a value that will not be
3109 * one of the existing rounding model enums.
3111 #define FLOAT_ROUND_CURRENT (float_round_nearest_even + float_round_down + \
3112 float_round_up + float_round_to_zero)
3115 * VSX_ROUND - VSX floating point round
3116 * op - instruction mnemonic
3117 * nels - number of elements (1, 2 or 4)
3118 * tp - type (float32 or float64)
3119 * fld - vsr_t field (VsrD(*) or VsrW(*))
3120 * rmode - rounding mode
3121 * sfifprf - set FI and FPRF
3123 #define VSX_ROUND(op, nels, tp, fld, rmode, sfifprf) \
3124 void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
3126 ppc_vsr_t t = { }; \
3128 FloatRoundMode curr_rounding_mode; \
3130 helper_reset_fpstatus(env); \
3132 if (rmode != FLOAT_ROUND_CURRENT) { \
3133 curr_rounding_mode = get_float_rounding_mode(&env->fp_status); \
3134 set_float_rounding_mode(rmode, &env->fp_status); \
3137 for (i = 0; i < nels; i++) { \
3138 if (unlikely(tp##_is_signaling_nan(xb->fld, \
3139 &env->fp_status))) { \
3140 float_invalid_op_vxsnan(env, GETPC()); \
3141 t.fld = tp##_snan_to_qnan(xb->fld); \
3143 t.fld = tp##_round_to_int(xb->fld, &env->fp_status); \
3146 helper_compute_fprf_float64(env, t.fld); \
3151 * If this is not a "use current rounding mode" instruction, \
3152 * then inhibit setting of the XX bit and restore rounding \
3155 if (rmode != FLOAT_ROUND_CURRENT) { \
3156 set_float_rounding_mode(curr_rounding_mode, &env->fp_status); \
3157 env->fp_status.float_exception_flags &= ~float_flag_inexact; \
3161 do_float_check_status(env, sfifprf, GETPC()); \
3164 VSX_ROUND(xsrdpi
, 1, float64
, VsrD(0), float_round_ties_away
, 1)
3165 VSX_ROUND(xsrdpic
, 1, float64
, VsrD(0), FLOAT_ROUND_CURRENT
, 1)
3166 VSX_ROUND(xsrdpim
, 1, float64
, VsrD(0), float_round_down
, 1)
3167 VSX_ROUND(xsrdpip
, 1, float64
, VsrD(0), float_round_up
, 1)
3168 VSX_ROUND(xsrdpiz
, 1, float64
, VsrD(0), float_round_to_zero
, 1)
3170 VSX_ROUND(xvrdpi
, 2, float64
, VsrD(i
), float_round_ties_away
, 0)
3171 VSX_ROUND(xvrdpic
, 2, float64
, VsrD(i
), FLOAT_ROUND_CURRENT
, 0)
3172 VSX_ROUND(xvrdpim
, 2, float64
, VsrD(i
), float_round_down
, 0)
3173 VSX_ROUND(xvrdpip
, 2, float64
, VsrD(i
), float_round_up
, 0)
3174 VSX_ROUND(xvrdpiz
, 2, float64
, VsrD(i
), float_round_to_zero
, 0)
3176 VSX_ROUND(xvrspi
, 4, float32
, VsrW(i
), float_round_ties_away
, 0)
3177 VSX_ROUND(xvrspic
, 4, float32
, VsrW(i
), FLOAT_ROUND_CURRENT
, 0)
3178 VSX_ROUND(xvrspim
, 4, float32
, VsrW(i
), float_round_down
, 0)
3179 VSX_ROUND(xvrspip
, 4, float32
, VsrW(i
), float_round_up
, 0)
3180 VSX_ROUND(xvrspiz
, 4, float32
, VsrW(i
), float_round_to_zero
, 0)
3182 uint64_t helper_xsrsp(CPUPPCState
*env
, uint64_t xb
)
3184 helper_reset_fpstatus(env
);
3186 uint64_t xt
= do_frsp(env
, xb
, GETPC());
3188 helper_compute_fprf_float64(env
, xt
);
3189 do_float_check_status(env
, true, GETPC());
3193 void helper_XVXSIGSP(ppc_vsr_t
*xt
, ppc_vsr_t
*xb
)
3196 uint32_t exp
, i
, fraction
;
3198 for (i
= 0; i
< 4; i
++) {
3199 exp
= (xb
->VsrW(i
) >> 23) & 0xFF;
3200 fraction
= xb
->VsrW(i
) & 0x7FFFFF;
3201 if (exp
!= 0 && exp
!= 255) {
3202 t
.VsrW(i
) = fraction
| 0x00800000;
3204 t
.VsrW(i
) = fraction
;
3210 #define VSX_TSTDC(tp) \
3211 static int32_t tp##_tstdc(tp b, uint32_t dcmx) \
3213 uint32_t match = 0; \
3214 uint32_t sign = tp##_is_neg(b); \
3215 if (tp##_is_any_nan(b)) { \
3216 match = extract32(dcmx, 6, 1); \
3217 } else if (tp##_is_infinity(b)) { \
3218 match = extract32(dcmx, 4 + !sign, 1); \
3219 } else if (tp##_is_zero(b)) { \
3220 match = extract32(dcmx, 2 + !sign, 1); \
3221 } else if (tp##_is_zero_or_denormal(b)) { \
3222 match = extract32(dcmx, 0 + !sign, 1); \
3224 return (match != 0); \
3232 void helper_XVTSTDCDP(ppc_vsr_t
*t
, ppc_vsr_t
*b
, uint64_t dcmx
, uint32_t v
)
3235 for (i
= 0; i
< 2; i
++) {
3236 t
->s64
[i
] = (int64_t)-float64_tstdc(b
->f64
[i
], dcmx
);
3240 void helper_XVTSTDCSP(ppc_vsr_t
*t
, ppc_vsr_t
*b
, uint64_t dcmx
, uint32_t v
)
3243 for (i
= 0; i
< 4; i
++) {
3244 t
->s32
[i
] = (int32_t)-float32_tstdc(b
->f32
[i
], dcmx
);
3248 static bool not_SP_value(float64 val
)
3250 return val
!= helper_todouble(helper_tosingle(val
));
3254 * VSX_XS_TSTDC - VSX Scalar Test Data Class
3255 * NAME - instruction name
3256 * FLD - vsr_t field (VsrD(0) or f128)
3257 * TP - type (float64 or float128)
3259 #define VSX_XS_TSTDC(NAME, FLD, TP) \
3260 void helper_##NAME(CPUPPCState *env, uint32_t bf, \
3261 uint32_t dcmx, ppc_vsr_t *b) \
3263 uint32_t cc, match, sign = TP##_is_neg(b->FLD); \
3264 match = TP##_tstdc(b->FLD, dcmx); \
3265 cc = sign << CRF_LT_BIT | match << CRF_EQ_BIT; \
3266 env->fpscr &= ~FP_FPCC; \
3267 env->fpscr |= cc << FPSCR_FPCC; \
3268 env->crf[bf] = cc; \
3271 VSX_XS_TSTDC(XSTSTDCDP
, VsrD(0), float64
)
3272 VSX_XS_TSTDC(XSTSTDCQP
, f128
, float128
)
3275 void helper_XSTSTDCSP(CPUPPCState
*env
, uint32_t bf
,
3276 uint32_t dcmx
, ppc_vsr_t
*b
)
3278 uint32_t cc
, match
, sign
= float64_is_neg(b
->VsrD(0));
3279 uint32_t exp
= (b
->VsrD(0) >> 52) & 0x7FF;
3280 int not_sp
= (int)not_SP_value(b
->VsrD(0));
3281 match
= float64_tstdc(b
->VsrD(0), dcmx
) || (exp
> 0 && exp
< 0x381);
3282 cc
= sign
<< CRF_LT_BIT
| match
<< CRF_EQ_BIT
| not_sp
<< CRF_SO_BIT
;
3283 env
->fpscr
&= ~FP_FPCC
;
3284 env
->fpscr
|= cc
<< FPSCR_FPCC
;
3288 void helper_xsrqpi(CPUPPCState
*env
, uint32_t opcode
,
3289 ppc_vsr_t
*xt
, ppc_vsr_t
*xb
)
3292 uint8_t r
= Rrm(opcode
);
3293 uint8_t ex
= Rc(opcode
);
3294 uint8_t rmc
= RMC(opcode
);
3298 helper_reset_fpstatus(env
);
3300 if (r
== 0 && rmc
== 0) {
3301 rmode
= float_round_ties_away
;
3302 } else if (r
== 0 && rmc
== 0x3) {
3303 rmode
= env
->fpscr
& FP_RN
;
3304 } else if (r
== 1) {
3307 rmode
= float_round_nearest_even
;
3310 rmode
= float_round_to_zero
;
3313 rmode
= float_round_up
;
3316 rmode
= float_round_down
;
3323 tstat
= env
->fp_status
;
3324 set_float_exception_flags(0, &tstat
);
3325 set_float_rounding_mode(rmode
, &tstat
);
3326 t
.f128
= float128_round_to_int(xb
->f128
, &tstat
);
3327 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3329 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid_snan
)) {
3330 float_invalid_op_vxsnan(env
, GETPC());
3333 if (ex
== 0 && (tstat
.float_exception_flags
& float_flag_inexact
)) {
3334 env
->fp_status
.float_exception_flags
&= ~float_flag_inexact
;
3337 helper_compute_fprf_float128(env
, t
.f128
);
3338 do_float_check_status(env
, true, GETPC());
3342 void helper_xsrqpxp(CPUPPCState
*env
, uint32_t opcode
,
3343 ppc_vsr_t
*xt
, ppc_vsr_t
*xb
)
3346 uint8_t r
= Rrm(opcode
);
3347 uint8_t rmc
= RMC(opcode
);
3352 helper_reset_fpstatus(env
);
3354 if (r
== 0 && rmc
== 0) {
3355 rmode
= float_round_ties_away
;
3356 } else if (r
== 0 && rmc
== 0x3) {
3357 rmode
= env
->fpscr
& FP_RN
;
3358 } else if (r
== 1) {
3361 rmode
= float_round_nearest_even
;
3364 rmode
= float_round_to_zero
;
3367 rmode
= float_round_up
;
3370 rmode
= float_round_down
;
3377 tstat
= env
->fp_status
;
3378 set_float_exception_flags(0, &tstat
);
3379 set_float_rounding_mode(rmode
, &tstat
);
3380 round_res
= float128_to_floatx80(xb
->f128
, &tstat
);
3381 t
.f128
= floatx80_to_float128(round_res
, &tstat
);
3382 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3384 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid_snan
)) {
3385 float_invalid_op_vxsnan(env
, GETPC());
3386 t
.f128
= float128_snan_to_qnan(t
.f128
);
3389 helper_compute_fprf_float128(env
, t
.f128
);
3391 do_float_check_status(env
, true, GETPC());
3394 void helper_xssqrtqp(CPUPPCState
*env
, uint32_t opcode
,
3395 ppc_vsr_t
*xt
, ppc_vsr_t
*xb
)
3400 helper_reset_fpstatus(env
);
3402 tstat
= env
->fp_status
;
3403 if (unlikely(Rc(opcode
) != 0)) {
3404 tstat
.float_rounding_mode
= float_round_to_odd
;
3407 set_float_exception_flags(0, &tstat
);
3408 t
.f128
= float128_sqrt(xb
->f128
, &tstat
);
3409 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3411 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
3412 float_invalid_op_sqrt(env
, tstat
.float_exception_flags
, 1, GETPC());
3415 helper_compute_fprf_float128(env
, t
.f128
);
3417 do_float_check_status(env
, true, GETPC());
3420 void helper_xssubqp(CPUPPCState
*env
, uint32_t opcode
,
3421 ppc_vsr_t
*xt
, ppc_vsr_t
*xa
, ppc_vsr_t
*xb
)
3426 helper_reset_fpstatus(env
);
3428 tstat
= env
->fp_status
;
3429 if (unlikely(Rc(opcode
) != 0)) {
3430 tstat
.float_rounding_mode
= float_round_to_odd
;
3433 set_float_exception_flags(0, &tstat
);
3434 t
.f128
= float128_sub(xa
->f128
, xb
->f128
, &tstat
);
3435 env
->fp_status
.float_exception_flags
|= tstat
.float_exception_flags
;
3437 if (unlikely(tstat
.float_exception_flags
& float_flag_invalid
)) {
3438 float_invalid_op_addsub(env
, tstat
.float_exception_flags
, 1, GETPC());
3441 helper_compute_fprf_float128(env
, t
.f128
);
3443 do_float_check_status(env
, true, GETPC());
3446 static inline void vsxger_excp(CPUPPCState
*env
, uintptr_t retaddr
)
3449 * XV*GER instructions execute and set the FPSCR as if exceptions
3450 * are disabled and only at the end throw an exception
3452 target_ulong enable
;
3453 enable
= env
->fpscr
& (FP_ENABLES
| FP_FI
| FP_FR
);
3454 env
->fpscr
&= ~(FP_ENABLES
| FP_FI
| FP_FR
);
3455 int status
= get_float_exception_flags(&env
->fp_status
);
3456 if (unlikely(status
& float_flag_invalid
)) {
3457 if (status
& float_flag_invalid_snan
) {
3458 float_invalid_op_vxsnan(env
, 0);
3460 if (status
& float_flag_invalid_imz
) {
3461 float_invalid_op_vximz(env
, false, 0);
3463 if (status
& float_flag_invalid_isi
) {
3464 float_invalid_op_vxisi(env
, false, 0);
3467 do_float_check_status(env
, false, retaddr
);
3468 env
->fpscr
|= enable
;
3469 do_fpscr_check_status(env
, retaddr
);
3472 typedef float64
extract_f16(float16
, float_status
*);
3474 static float64
extract_hf16(float16 in
, float_status
*fp_status
)
3476 return float16_to_float64(in
, true, fp_status
);
3479 static float64
extract_bf16(bfloat16 in
, float_status
*fp_status
)
3481 return bfloat16_to_float64(in
, fp_status
);
3484 static void vsxger16(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3485 ppc_acc_t
*at
, uint32_t mask
, bool acc
,
3486 bool neg_mul
, bool neg_acc
, extract_f16 extract
)
3489 float64 psum
, va
, vb
, vc
, vd
;
3490 int i
, j
, xmsk_bit
, ymsk_bit
;
3491 uint8_t pmsk
= FIELD_EX32(mask
, GER_MSK
, PMSK
),
3492 xmsk
= FIELD_EX32(mask
, GER_MSK
, XMSK
),
3493 ymsk
= FIELD_EX32(mask
, GER_MSK
, YMSK
);
3494 float_status
*excp_ptr
= &env
->fp_status
;
3495 for (i
= 0, xmsk_bit
= 1 << 3; i
< 4; i
++, xmsk_bit
>>= 1) {
3496 for (j
= 0, ymsk_bit
= 1 << 3; j
< 4; j
++, ymsk_bit
>>= 1) {
3497 if ((xmsk_bit
& xmsk
) && (ymsk_bit
& ymsk
)) {
3498 va
= !(pmsk
& 2) ? float64_zero
:
3499 extract(a
->VsrHF(2 * i
), excp_ptr
);
3500 vb
= !(pmsk
& 2) ? float64_zero
:
3501 extract(b
->VsrHF(2 * j
), excp_ptr
);
3502 vc
= !(pmsk
& 1) ? float64_zero
:
3503 extract(a
->VsrHF(2 * i
+ 1), excp_ptr
);
3504 vd
= !(pmsk
& 1) ? float64_zero
:
3505 extract(b
->VsrHF(2 * j
+ 1), excp_ptr
);
3506 psum
= float64_mul(va
, vb
, excp_ptr
);
3507 psum
= float64r32_muladd(vc
, vd
, psum
, 0, excp_ptr
);
3508 r
= float64_to_float32(psum
, excp_ptr
);
3510 aux_acc
= at
[i
].VsrSF(j
);
3515 aux_acc
= bfp32_neg(aux_acc
);
3517 r
= float32_add(r
, aux_acc
, excp_ptr
);
3521 at
[i
].VsrSF(j
) = float32_zero
;
3525 vsxger_excp(env
, GETPC());
3528 typedef void vsxger_zero(ppc_vsr_t
*at
, int, int);
3530 typedef void vsxger_muladd_f(ppc_vsr_t
*, ppc_vsr_t
*, ppc_vsr_t
*, int, int,
3531 int flags
, float_status
*s
);
3533 static void vsxger_muladd32(ppc_vsr_t
*at
, ppc_vsr_t
*a
, ppc_vsr_t
*b
, int i
,
3534 int j
, int flags
, float_status
*s
)
3536 at
[i
].VsrSF(j
) = float32_muladd(a
->VsrSF(i
), b
->VsrSF(j
),
3537 at
[i
].VsrSF(j
), flags
, s
);
3540 static void vsxger_mul32(ppc_vsr_t
*at
, ppc_vsr_t
*a
, ppc_vsr_t
*b
, int i
,
3541 int j
, int flags
, float_status
*s
)
3543 at
[i
].VsrSF(j
) = float32_mul(a
->VsrSF(i
), b
->VsrSF(j
), s
);
3546 static void vsxger_zero32(ppc_vsr_t
*at
, int i
, int j
)
3548 at
[i
].VsrSF(j
) = float32_zero
;
3551 static void vsxger_muladd64(ppc_vsr_t
*at
, ppc_vsr_t
*a
, ppc_vsr_t
*b
, int i
,
3552 int j
, int flags
, float_status
*s
)
3556 at
[i
].VsrDF(j
) = float64_muladd(a
[i
/ 2].VsrDF(i
% 2), b
->VsrDF(j
),
3557 at
[i
].VsrDF(j
), flags
, s
);
3561 static void vsxger_mul64(ppc_vsr_t
*at
, ppc_vsr_t
*a
, ppc_vsr_t
*b
, int i
,
3562 int j
, int flags
, float_status
*s
)
3566 at
[i
].VsrDF(j
) = float64_mul(a
[i
/ 2].VsrDF(i
% 2), b
->VsrDF(j
), s
);
3570 static void vsxger_zero64(ppc_vsr_t
*at
, int i
, int j
)
3574 at
[i
].VsrDF(j
) = float64_zero
;
3578 static void vsxger(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3579 ppc_acc_t
*at
, uint32_t mask
, bool acc
, bool neg_mul
,
3580 bool neg_acc
, vsxger_muladd_f mul
, vsxger_muladd_f muladd
,
3583 int i
, j
, xmsk_bit
, ymsk_bit
, op_flags
;
3584 uint8_t xmsk
= mask
& 0x0F;
3585 uint8_t ymsk
= (mask
>> 4) & 0x0F;
3586 float_status
*excp_ptr
= &env
->fp_status
;
3587 op_flags
= (neg_acc
^ neg_mul
) ? float_muladd_negate_c
: 0;
3588 op_flags
|= (neg_mul
) ? float_muladd_negate_result
: 0;
3589 helper_reset_fpstatus(env
);
3590 for (i
= 0, xmsk_bit
= 1 << 3; i
< 4; i
++, xmsk_bit
>>= 1) {
3591 for (j
= 0, ymsk_bit
= 1 << 3; j
< 4; j
++, ymsk_bit
>>= 1) {
3592 if ((xmsk_bit
& xmsk
) && (ymsk_bit
& ymsk
)) {
3594 muladd(at
, a
, b
, i
, j
, op_flags
, excp_ptr
);
3596 mul(at
, a
, b
, i
, j
, op_flags
, excp_ptr
);
3603 vsxger_excp(env
, GETPC());
3607 void helper_XVBF16GER2(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3608 ppc_acc_t
*at
, uint32_t mask
)
3610 vsxger16(env
, a
, b
, at
, mask
, false, false, false, extract_bf16
);
3614 void helper_XVBF16GER2PP(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3615 ppc_acc_t
*at
, uint32_t mask
)
3617 vsxger16(env
, a
, b
, at
, mask
, true, false, false, extract_bf16
);
3621 void helper_XVBF16GER2PN(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3622 ppc_acc_t
*at
, uint32_t mask
)
3624 vsxger16(env
, a
, b
, at
, mask
, true, false, true, extract_bf16
);
3628 void helper_XVBF16GER2NP(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3629 ppc_acc_t
*at
, uint32_t mask
)
3631 vsxger16(env
, a
, b
, at
, mask
, true, true, false, extract_bf16
);
3635 void helper_XVBF16GER2NN(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3636 ppc_acc_t
*at
, uint32_t mask
)
3638 vsxger16(env
, a
, b
, at
, mask
, true, true, true, extract_bf16
);
3642 void helper_XVF16GER2(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3643 ppc_acc_t
*at
, uint32_t mask
)
3645 vsxger16(env
, a
, b
, at
, mask
, false, false, false, extract_hf16
);
3649 void helper_XVF16GER2PP(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3650 ppc_acc_t
*at
, uint32_t mask
)
3652 vsxger16(env
, a
, b
, at
, mask
, true, false, false, extract_hf16
);
3656 void helper_XVF16GER2PN(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3657 ppc_acc_t
*at
, uint32_t mask
)
3659 vsxger16(env
, a
, b
, at
, mask
, true, false, true, extract_hf16
);
3663 void helper_XVF16GER2NP(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3664 ppc_acc_t
*at
, uint32_t mask
)
3666 vsxger16(env
, a
, b
, at
, mask
, true, true, false, extract_hf16
);
3670 void helper_XVF16GER2NN(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3671 ppc_acc_t
*at
, uint32_t mask
)
3673 vsxger16(env
, a
, b
, at
, mask
, true, true, true, extract_hf16
);
3677 void helper_XVF32GER(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3678 ppc_acc_t
*at
, uint32_t mask
)
3680 vsxger(env
, a
, b
, at
, mask
, false, false, false, vsxger_mul32
,
3681 vsxger_muladd32
, vsxger_zero32
);
3685 void helper_XVF32GERPP(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3686 ppc_acc_t
*at
, uint32_t mask
)
3688 vsxger(env
, a
, b
, at
, mask
, true, false, false, vsxger_mul32
,
3689 vsxger_muladd32
, vsxger_zero32
);
3693 void helper_XVF32GERPN(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3694 ppc_acc_t
*at
, uint32_t mask
)
3696 vsxger(env
, a
, b
, at
, mask
, true, false, true, vsxger_mul32
,
3697 vsxger_muladd32
, vsxger_zero32
);
3701 void helper_XVF32GERNP(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3702 ppc_acc_t
*at
, uint32_t mask
)
3704 vsxger(env
, a
, b
, at
, mask
, true, true, false, vsxger_mul32
,
3705 vsxger_muladd32
, vsxger_zero32
);
3709 void helper_XVF32GERNN(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3710 ppc_acc_t
*at
, uint32_t mask
)
3712 vsxger(env
, a
, b
, at
, mask
, true, true, true, vsxger_mul32
,
3713 vsxger_muladd32
, vsxger_zero32
);
3717 void helper_XVF64GER(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3718 ppc_acc_t
*at
, uint32_t mask
)
3720 vsxger(env
, a
, b
, at
, mask
, false, false, false, vsxger_mul64
,
3721 vsxger_muladd64
, vsxger_zero64
);
3725 void helper_XVF64GERPP(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3726 ppc_acc_t
*at
, uint32_t mask
)
3728 vsxger(env
, a
, b
, at
, mask
, true, false, false, vsxger_mul64
,
3729 vsxger_muladd64
, vsxger_zero64
);
3733 void helper_XVF64GERPN(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3734 ppc_acc_t
*at
, uint32_t mask
)
3736 vsxger(env
, a
, b
, at
, mask
, true, false, true, vsxger_mul64
,
3737 vsxger_muladd64
, vsxger_zero64
);
3741 void helper_XVF64GERNP(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3742 ppc_acc_t
*at
, uint32_t mask
)
3744 vsxger(env
, a
, b
, at
, mask
, true, true, false, vsxger_mul64
,
3745 vsxger_muladd64
, vsxger_zero64
);
3749 void helper_XVF64GERNN(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
3750 ppc_acc_t
*at
, uint32_t mask
)
3752 vsxger(env
, a
, b
, at
, mask
, true, true, true, vsxger_mul64
,
3753 vsxger_muladd64
, vsxger_zero64
);