2012-05-30 08:23:26 +04:00
|
|
|
/*
|
|
|
|
* PowerPC floating point and SPE emulation helpers for QEMU.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2007 Jocelyn Mayer
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2020-10-19 09:11:26 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2012-05-30 08:23:26 +04:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2016-01-26 21:16:58 +03:00
|
|
|
#include "qemu/osdep.h"
|
2012-05-30 08:23:26 +04:00
|
|
|
#include "cpu.h"
|
2014-04-08 09:31:41 +04:00
|
|
|
#include "exec/helper-proto.h"
|
2016-07-27 09:56:26 +03:00
|
|
|
#include "exec/exec-all.h"
|
2016-11-23 14:37:10 +03:00
|
|
|
#include "internal.h"
|
2018-01-19 21:24:22 +03:00
|
|
|
#include "fpu/softfloat.h"
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2017-01-09 17:26:14 +03:00
|
|
|
static inline float128 float128_snan_to_qnan(float128 x)
|
|
|
|
{
|
|
|
|
float128 r;
|
|
|
|
|
|
|
|
r.high = x.high | 0x0000800000000000;
|
|
|
|
r.low = x.low;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2014-11-13 00:45:59 +03:00
|
|
|
#define float64_snan_to_qnan(x) ((x) | 0x0008000000000000ULL)
|
|
|
|
#define float32_snan_to_qnan(x) ((x) | 0x00400000)
|
2017-01-06 09:14:49 +03:00
|
|
|
#define float16_snan_to_qnan(x) ((x) | 0x0200)
|
2014-11-13 00:45:59 +03:00
|
|
|
|
2022-05-24 17:05:34 +03:00
|
|
|
static inline float32 bfp32_neg(float32 a)
|
|
|
|
{
|
|
|
|
if (unlikely(float32_is_any_nan(a))) {
|
|
|
|
return a;
|
|
|
|
} else {
|
|
|
|
return float32_chs(a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-03 18:17:26 +03:00
|
|
|
static inline bool fp_exceptions_enabled(CPUPPCState *env)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_USER_ONLY
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return (env->msr & ((1U << MSR_FE0) | (1U << MSR_FE1))) != 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:26 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Floating point operations helpers */
|
2018-07-03 18:17:32 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the non-arithmatic conversion that happens e.g. on loads.
|
|
|
|
* In the Power ISA pseudocode, this is called DOUBLE.
|
|
|
|
*/
|
|
|
|
uint64_t helper_todouble(uint32_t arg)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2018-07-03 18:17:32 +03:00
|
|
|
uint32_t abs_arg = arg & 0x7fffffff;
|
|
|
|
uint64_t ret;
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2018-07-03 18:17:32 +03:00
|
|
|
if (likely(abs_arg >= 0x00800000)) {
|
2019-08-19 22:19:48 +03:00
|
|
|
if (unlikely(extract32(arg, 23, 8) == 0xff)) {
|
|
|
|
/* Inf or NAN. */
|
|
|
|
ret = (uint64_t)extract32(arg, 31, 1) << 63;
|
|
|
|
ret |= (uint64_t)0x7ff << 52;
|
|
|
|
ret |= (uint64_t)extract32(arg, 0, 23) << 29;
|
|
|
|
} else {
|
|
|
|
/* Normalized operand. */
|
|
|
|
ret = (uint64_t)extract32(arg, 30, 2) << 62;
|
|
|
|
ret |= ((extract32(arg, 30, 1) ^ 1) * (uint64_t)7) << 59;
|
|
|
|
ret |= (uint64_t)extract32(arg, 0, 30) << 29;
|
|
|
|
}
|
2018-07-03 18:17:32 +03:00
|
|
|
} else {
|
|
|
|
/* Zero or Denormalized operand. */
|
|
|
|
ret = (uint64_t)extract32(arg, 31, 1) << 63;
|
|
|
|
if (unlikely(abs_arg != 0)) {
|
2019-08-20 00:42:16 +03:00
|
|
|
/*
|
|
|
|
* Denormalized operand.
|
|
|
|
* Shift fraction so that the msb is in the implicit bit position.
|
|
|
|
* Thus, shift is in the range [1:23].
|
|
|
|
*/
|
|
|
|
int shift = clz32(abs_arg) - 8;
|
|
|
|
/*
|
|
|
|
* The first 3 terms compute the float64 exponent. We then bias
|
|
|
|
* this result by -1 so that we can swallow the implicit bit below.
|
|
|
|
*/
|
|
|
|
int exp = -126 - shift + 1023 - 1;
|
|
|
|
|
2018-07-03 18:17:32 +03:00
|
|
|
ret |= (uint64_t)exp << 52;
|
2019-08-20 00:42:16 +03:00
|
|
|
ret += (uint64_t)abs_arg << (52 - 23 + shift);
|
2018-07-03 18:17:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2018-07-03 18:17:32 +03:00
|
|
|
/*
|
|
|
|
* This is the non-arithmatic conversion that happens e.g. on stores.
|
|
|
|
* In the Power ISA pseudocode, this is called SINGLE.
|
|
|
|
*/
|
|
|
|
uint32_t helper_tosingle(uint64_t arg)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2018-07-03 18:17:32 +03:00
|
|
|
int exp = extract64(arg, 52, 11);
|
|
|
|
uint32_t ret;
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2018-07-03 18:17:32 +03:00
|
|
|
if (likely(exp > 896)) {
|
|
|
|
/* No denormalization required (includes Inf, NaN). */
|
|
|
|
ret = extract64(arg, 62, 2) << 30;
|
|
|
|
ret |= extract64(arg, 29, 30);
|
|
|
|
} else {
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
* Zero or Denormal result. If the exponent is in bounds for
|
|
|
|
* a single-precision denormal result, extract the proper
|
|
|
|
* bits. If the input is not zero, and the exponent is out of
|
|
|
|
* bounds, then the result is undefined; this underflows to
|
|
|
|
* zero.
|
2018-07-03 18:17:32 +03:00
|
|
|
*/
|
|
|
|
ret = extract64(arg, 63, 1) << 31;
|
|
|
|
if (unlikely(exp >= 874)) {
|
|
|
|
/* Denormal result. */
|
|
|
|
ret |= ((1ULL << 52) | extract64(arg, 0, 52)) >> (896 + 30 - exp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2014-01-07 20:06:07 +04:00
|
|
|
static inline int ppc_float32_get_unbiased_exp(float32 f)
|
|
|
|
{
|
|
|
|
return ((f >> 23) & 0xFF) - 127;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int ppc_float64_get_unbiased_exp(float64 f)
|
|
|
|
{
|
|
|
|
return ((f >> 52) & 0x7FF) - 1023;
|
|
|
|
}
|
|
|
|
|
2018-10-12 02:41:55 +03:00
|
|
|
/* Classify a floating-point number. */
|
|
|
|
enum {
|
|
|
|
is_normal = 1,
|
|
|
|
is_zero = 2,
|
|
|
|
is_denormal = 4,
|
|
|
|
is_inf = 8,
|
|
|
|
is_qnan = 16,
|
|
|
|
is_snan = 32,
|
|
|
|
is_neg = 64,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define COMPUTE_CLASS(tp) \
|
|
|
|
static int tp##_classify(tp arg) \
|
2017-01-06 09:14:47 +03:00
|
|
|
{ \
|
2018-10-12 02:41:55 +03:00
|
|
|
int ret = tp##_is_neg(arg) * is_neg; \
|
2017-01-06 09:14:47 +03:00
|
|
|
if (unlikely(tp##_is_any_nan(arg))) { \
|
2018-10-12 02:41:55 +03:00
|
|
|
float_status dummy = { }; /* snan_bit_is_one = 0 */ \
|
|
|
|
ret |= (tp##_is_signaling_nan(arg, &dummy) \
|
|
|
|
? is_snan : is_qnan); \
|
2017-01-06 09:14:47 +03:00
|
|
|
} else if (unlikely(tp##_is_infinity(arg))) { \
|
2018-10-12 02:41:55 +03:00
|
|
|
ret |= is_inf; \
|
|
|
|
} else if (tp##_is_zero(arg)) { \
|
|
|
|
ret |= is_zero; \
|
|
|
|
} else if (tp##_is_zero_or_denormal(arg)) { \
|
|
|
|
ret |= is_denormal; \
|
2017-01-06 09:14:47 +03:00
|
|
|
} else { \
|
2018-10-12 02:41:55 +03:00
|
|
|
ret |= is_normal; \
|
2017-01-06 09:14:47 +03:00
|
|
|
} \
|
2018-10-12 02:41:55 +03:00
|
|
|
return ret; \
|
|
|
|
}
|
|
|
|
|
|
|
|
COMPUTE_CLASS(float16)
|
|
|
|
COMPUTE_CLASS(float32)
|
|
|
|
COMPUTE_CLASS(float64)
|
|
|
|
COMPUTE_CLASS(float128)
|
|
|
|
|
|
|
|
static void set_fprf_from_class(CPUPPCState *env, int class)
|
|
|
|
{
|
|
|
|
static const uint8_t fprf[6][2] = {
|
|
|
|
{ 0x04, 0x08 }, /* normalized */
|
|
|
|
{ 0x02, 0x12 }, /* zero */
|
|
|
|
{ 0x14, 0x18 }, /* denormalized */
|
|
|
|
{ 0x05, 0x09 }, /* infinity */
|
|
|
|
{ 0x11, 0x11 }, /* qnan */
|
|
|
|
{ 0x00, 0x00 }, /* snan -- flags are undefined */
|
|
|
|
};
|
|
|
|
bool isneg = class & is_neg;
|
|
|
|
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr &= ~FP_FPRF;
|
2018-10-12 02:41:55 +03:00
|
|
|
env->fpscr |= fprf[ctz32(class)][isneg] << FPSCR_FPRF;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define COMPUTE_FPRF(tp) \
|
|
|
|
void helper_compute_fprf_##tp(CPUPPCState *env, tp arg) \
|
|
|
|
{ \
|
|
|
|
set_fprf_from_class(env, tp##_classify(arg)); \
|
2017-01-06 09:14:47 +03:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:14:49 +03:00
|
|
|
COMPUTE_FPRF(float16)
|
2017-01-06 09:14:50 +03:00
|
|
|
COMPUTE_FPRF(float32)
|
2017-01-06 09:14:47 +03:00
|
|
|
COMPUTE_FPRF(float64)
|
2017-01-09 17:26:13 +03:00
|
|
|
COMPUTE_FPRF(float128)
|
2012-05-30 08:23:26 +04:00
|
|
|
|
|
|
|
/* Floating-point invalid operations exception */
|
2018-10-12 02:41:53 +03:00
|
|
|
static void finish_invalid_op_excp(CPUPPCState *env, int op, uintptr_t retaddr)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2018-10-12 02:41:53 +03:00
|
|
|
/* Update the floating-point invalid operation summary */
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_VX;
|
2018-10-12 02:41:53 +03:00
|
|
|
/* Update the floating-point exception summary */
|
|
|
|
env->fpscr |= FP_FX;
|
2022-05-05 00:05:20 +03:00
|
|
|
if (env->fpscr & FP_VE) {
|
2018-10-12 02:41:53 +03:00
|
|
|
/* Update the floating-point enabled exception summary */
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_FEX;
|
2018-10-12 02:41:53 +03:00
|
|
|
if (fp_exceptions_enabled(env)) {
|
|
|
|
raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM,
|
|
|
|
POWERPC_EXCP_FP | op, retaddr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2018-10-12 02:41:53 +03:00
|
|
|
static void finish_invalid_op_arith(CPUPPCState *env, int op,
|
|
|
|
bool set_fpcc, uintptr_t retaddr)
|
|
|
|
{
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr &= ~(FP_FR | FP_FI);
|
2022-05-05 00:05:20 +03:00
|
|
|
if (!(env->fpscr & FP_VE)) {
|
2014-01-03 02:21:19 +04:00
|
|
|
if (set_fpcc) {
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr &= ~FP_FPCC;
|
|
|
|
env->fpscr |= (FP_C | FP_FU);
|
2014-01-03 02:21:19 +04:00
|
|
|
}
|
2018-10-12 02:41:53 +03:00
|
|
|
}
|
|
|
|
finish_invalid_op_excp(env, op, retaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Signalling NaN */
|
|
|
|
static void float_invalid_op_vxsnan(CPUPPCState *env, uintptr_t retaddr)
|
|
|
|
{
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_VXSNAN;
|
2018-10-12 02:41:53 +03:00
|
|
|
finish_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, retaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Magnitude subtraction of infinities */
|
|
|
|
static void float_invalid_op_vxisi(CPUPPCState *env, bool set_fpcc,
|
|
|
|
uintptr_t retaddr)
|
|
|
|
{
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_VXISI;
|
2018-10-12 02:41:53 +03:00
|
|
|
finish_invalid_op_arith(env, POWERPC_EXCP_FP_VXISI, set_fpcc, retaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Division of infinity by infinity */
|
|
|
|
static void float_invalid_op_vxidi(CPUPPCState *env, bool set_fpcc,
|
|
|
|
uintptr_t retaddr)
|
|
|
|
{
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_VXIDI;
|
2018-10-12 02:41:53 +03:00
|
|
|
finish_invalid_op_arith(env, POWERPC_EXCP_FP_VXIDI, set_fpcc, retaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Division of zero by zero */
|
|
|
|
static void float_invalid_op_vxzdz(CPUPPCState *env, bool set_fpcc,
|
|
|
|
uintptr_t retaddr)
|
|
|
|
{
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_VXZDZ;
|
2018-10-12 02:41:53 +03:00
|
|
|
finish_invalid_op_arith(env, POWERPC_EXCP_FP_VXZDZ, set_fpcc, retaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Multiplication of zero by infinity */
|
|
|
|
static void float_invalid_op_vximz(CPUPPCState *env, bool set_fpcc,
|
|
|
|
uintptr_t retaddr)
|
|
|
|
{
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_VXIMZ;
|
2018-10-12 02:41:53 +03:00
|
|
|
finish_invalid_op_arith(env, POWERPC_EXCP_FP_VXIMZ, set_fpcc, retaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Square root of a negative number */
|
|
|
|
static void float_invalid_op_vxsqrt(CPUPPCState *env, bool set_fpcc,
|
|
|
|
uintptr_t retaddr)
|
|
|
|
{
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_VXSQRT;
|
2018-10-12 02:41:53 +03:00
|
|
|
finish_invalid_op_arith(env, POWERPC_EXCP_FP_VXSQRT, set_fpcc, retaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ordered comparison of NaN */
|
|
|
|
static void float_invalid_op_vxvc(CPUPPCState *env, bool set_fpcc,
|
|
|
|
uintptr_t retaddr)
|
|
|
|
{
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_VXVC;
|
2018-10-12 02:41:53 +03:00
|
|
|
if (set_fpcc) {
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr &= ~FP_FPCC;
|
|
|
|
env->fpscr |= (FP_C | FP_FU);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
/* Update the floating-point invalid operation summary */
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_VX;
|
2012-05-30 08:23:26 +04:00
|
|
|
/* Update the floating-point exception summary */
|
2015-11-20 14:31:48 +03:00
|
|
|
env->fpscr |= FP_FX;
|
2018-10-12 02:41:53 +03:00
|
|
|
/* We must update the target FPR before raising the exception */
|
2022-05-05 00:05:20 +03:00
|
|
|
if (env->fpscr & FP_VE) {
|
2019-03-23 05:07:57 +03:00
|
|
|
CPUState *cs = env_cpu(env);
|
2018-10-12 02:41:53 +03:00
|
|
|
|
|
|
|
cs->exception_index = POWERPC_EXCP_PROGRAM;
|
|
|
|
env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_VXVC;
|
2012-05-30 08:23:26 +04:00
|
|
|
/* Update the floating-point enabled exception summary */
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_FEX;
|
2020-02-14 02:57:34 +03:00
|
|
|
/* Exception is deferred */
|
2018-10-12 02:41:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Invalid conversion */
|
|
|
|
static void float_invalid_op_vxcvi(CPUPPCState *env, bool set_fpcc,
|
|
|
|
uintptr_t retaddr)
|
|
|
|
{
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_VXCVI;
|
|
|
|
env->fpscr &= ~(FP_FR | FP_FI);
|
2022-05-05 00:05:20 +03:00
|
|
|
if (!(env->fpscr & FP_VE)) {
|
2018-10-12 02:41:53 +03:00
|
|
|
if (set_fpcc) {
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr &= ~FP_FPCC;
|
|
|
|
env->fpscr |= (FP_C | FP_FU);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
}
|
2018-10-12 02:41:53 +03:00
|
|
|
finish_invalid_op_excp(env, POWERPC_EXCP_FP_VXCVI, retaddr);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2016-07-27 09:56:27 +03:00
|
|
|
static inline void float_zero_divide_excp(CPUPPCState *env, uintptr_t raddr)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_ZX;
|
|
|
|
env->fpscr &= ~(FP_FR | FP_FI);
|
2012-05-30 08:23:26 +04:00
|
|
|
/* Update the floating-point exception summary */
|
2015-11-20 14:31:48 +03:00
|
|
|
env->fpscr |= FP_FX;
|
2022-05-05 00:05:20 +03:00
|
|
|
if (env->fpscr & FP_ZE) {
|
2012-05-30 08:23:26 +04:00
|
|
|
/* Update the floating-point enabled exception summary */
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_FEX;
|
2018-07-03 18:17:26 +03:00
|
|
|
if (fp_exceptions_enabled(env)) {
|
2016-07-27 09:56:27 +03:00
|
|
|
raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM,
|
|
|
|
POWERPC_EXCP_FP | POWERPC_EXCP_FP_ZX,
|
|
|
|
raddr);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-17 19:15:21 +03:00
|
|
|
static inline int float_overflow_excp(CPUPPCState *env)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2019-03-23 05:07:57 +03:00
|
|
|
CPUState *cs = env_cpu(env);
|
2013-08-26 10:31:06 +04:00
|
|
|
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_OX;
|
2012-05-30 08:23:26 +04:00
|
|
|
/* Update the floating-point exception summary */
|
2015-11-20 14:31:48 +03:00
|
|
|
env->fpscr |= FP_FX;
|
2022-05-17 19:15:21 +03:00
|
|
|
|
|
|
|
bool overflow_enabled = !!(env->fpscr & FP_OE);
|
|
|
|
if (overflow_enabled) {
|
2012-05-30 08:23:26 +04:00
|
|
|
/* Update the floating-point enabled exception summary */
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_FEX;
|
2012-05-30 08:23:26 +04:00
|
|
|
/* We must update the target FPR before raising the exception */
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = POWERPC_EXCP_PROGRAM;
|
2012-05-30 08:23:26 +04:00
|
|
|
env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_OX;
|
|
|
|
}
|
2022-05-17 19:15:21 +03:00
|
|
|
|
|
|
|
return overflow_enabled ? 0 : float_flag_inexact;
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline void float_underflow_excp(CPUPPCState *env)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2019-03-23 05:07:57 +03:00
|
|
|
CPUState *cs = env_cpu(env);
|
2013-08-26 10:31:06 +04:00
|
|
|
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_UX;
|
2012-05-30 08:23:26 +04:00
|
|
|
/* Update the floating-point exception summary */
|
2015-11-20 14:31:48 +03:00
|
|
|
env->fpscr |= FP_FX;
|
2022-05-05 00:05:20 +03:00
|
|
|
if (env->fpscr & FP_UE) {
|
2012-05-30 08:23:26 +04:00
|
|
|
/* Update the floating-point enabled exception summary */
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_FEX;
|
2012-05-30 08:23:26 +04:00
|
|
|
/* We must update the target FPR before raising the exception */
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = POWERPC_EXCP_PROGRAM;
|
2012-05-30 08:23:26 +04:00
|
|
|
env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_UX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline void float_inexact_excp(CPUPPCState *env)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2019-03-23 05:07:57 +03:00
|
|
|
CPUState *cs = env_cpu(env);
|
2013-08-26 10:31:06 +04:00
|
|
|
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_XX;
|
2012-05-30 08:23:26 +04:00
|
|
|
/* Update the floating-point exception summary */
|
2015-11-20 14:31:48 +03:00
|
|
|
env->fpscr |= FP_FX;
|
2022-05-05 00:05:20 +03:00
|
|
|
if (env->fpscr & FP_XE) {
|
2012-05-30 08:23:26 +04:00
|
|
|
/* Update the floating-point enabled exception summary */
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr |= FP_FEX;
|
2012-05-30 08:23:26 +04:00
|
|
|
/* We must update the target FPR before raising the exception */
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = POWERPC_EXCP_PROGRAM;
|
2012-05-30 08:23:26 +04:00
|
|
|
env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_XX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
void helper_fpscr_clrbit(CPUPPCState *env, uint32_t bit)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2021-05-27 19:35:22 +03:00
|
|
|
uint32_t mask = 1u << bit;
|
|
|
|
if (env->fpscr & mask) {
|
|
|
|
ppc_store_fpscr(env, env->fpscr & ~(target_ulong)mask);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
void helper_fpscr_setbit(CPUPPCState *env, uint32_t bit)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2021-05-27 19:35:22 +03:00
|
|
|
uint32_t mask = 1u << bit;
|
|
|
|
if (!(env->fpscr & mask)) {
|
|
|
|
ppc_store_fpscr(env, env->fpscr | mask);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-27 19:35:22 +03:00
|
|
|
void helper_store_fpscr(CPUPPCState *env, uint64_t val, uint32_t nibbles)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2021-05-27 19:35:22 +03:00
|
|
|
target_ulong mask = 0;
|
2012-05-30 08:23:26 +04:00
|
|
|
int i;
|
|
|
|
|
2021-05-27 19:35:22 +03:00
|
|
|
/* TODO: push this extension back to translation time */
|
2013-04-20 12:56:22 +04:00
|
|
|
for (i = 0; i < sizeof(target_ulong) * 2; i++) {
|
2021-05-27 19:35:22 +03:00
|
|
|
if (nibbles & (1 << i)) {
|
|
|
|
mask |= (target_ulong) 0xf << (4 * i);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
}
|
2021-05-27 19:35:22 +03:00
|
|
|
val = (val & mask) | (env->fpscr & ~mask);
|
|
|
|
ppc_store_fpscr(env, val);
|
2013-03-19 11:41:53 +04:00
|
|
|
}
|
|
|
|
|
2022-05-24 17:05:33 +03:00
|
|
|
static void do_fpscr_check_status(CPUPPCState *env, uintptr_t raddr)
|
2021-12-17 19:57:12 +03:00
|
|
|
{
|
|
|
|
CPUState *cs = env_cpu(env);
|
|
|
|
target_ulong fpscr = env->fpscr;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
if ((fpscr & FP_OX) && (fpscr & FP_OE)) {
|
|
|
|
error = POWERPC_EXCP_FP_OX;
|
|
|
|
} else if ((fpscr & FP_UX) && (fpscr & FP_UE)) {
|
|
|
|
error = POWERPC_EXCP_FP_UX;
|
|
|
|
} else if ((fpscr & FP_XX) && (fpscr & FP_XE)) {
|
|
|
|
error = POWERPC_EXCP_FP_XX;
|
|
|
|
} else if ((fpscr & FP_ZX) && (fpscr & FP_ZE)) {
|
|
|
|
error = POWERPC_EXCP_FP_ZX;
|
|
|
|
} else if (fpscr & FP_VE) {
|
|
|
|
if (fpscr & FP_VXSOFT) {
|
|
|
|
error = POWERPC_EXCP_FP_VXSOFT;
|
|
|
|
} else if (fpscr & FP_VXSNAN) {
|
|
|
|
error = POWERPC_EXCP_FP_VXSNAN;
|
|
|
|
} else if (fpscr & FP_VXISI) {
|
|
|
|
error = POWERPC_EXCP_FP_VXISI;
|
|
|
|
} else if (fpscr & FP_VXIDI) {
|
|
|
|
error = POWERPC_EXCP_FP_VXIDI;
|
|
|
|
} else if (fpscr & FP_VXZDZ) {
|
|
|
|
error = POWERPC_EXCP_FP_VXZDZ;
|
|
|
|
} else if (fpscr & FP_VXIMZ) {
|
|
|
|
error = POWERPC_EXCP_FP_VXIMZ;
|
|
|
|
} else if (fpscr & FP_VXVC) {
|
|
|
|
error = POWERPC_EXCP_FP_VXVC;
|
|
|
|
} else if (fpscr & FP_VXSQRT) {
|
|
|
|
error = POWERPC_EXCP_FP_VXSQRT;
|
|
|
|
} else if (fpscr & FP_VXCVI) {
|
|
|
|
error = POWERPC_EXCP_FP_VXCVI;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cs->exception_index = POWERPC_EXCP_PROGRAM;
|
|
|
|
env->error_code = error | POWERPC_EXCP_FP;
|
2022-06-02 22:10:48 +03:00
|
|
|
env->fpscr |= FP_FEX;
|
2021-12-17 19:57:12 +03:00
|
|
|
/* Deferred floating-point exception after target FPSCR update */
|
|
|
|
if (fp_exceptions_enabled(env)) {
|
|
|
|
raise_exception_err_ra(env, cs->exception_index,
|
2022-05-24 17:05:33 +03:00
|
|
|
env->error_code, raddr);
|
2021-12-17 19:57:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-24 17:05:33 +03:00
|
|
|
void helper_fpscr_check_status(CPUPPCState *env)
|
|
|
|
{
|
|
|
|
do_fpscr_check_status(env, GETPC());
|
|
|
|
}
|
|
|
|
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
static void do_float_check_status(CPUPPCState *env, bool change_fi,
|
|
|
|
uintptr_t raddr)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2019-03-23 05:07:57 +03:00
|
|
|
CPUState *cs = env_cpu(env);
|
2013-04-09 09:00:55 +04:00
|
|
|
int status = get_float_exception_flags(&env->fp_status);
|
|
|
|
|
2018-07-03 18:17:27 +03:00
|
|
|
if (status & float_flag_overflow) {
|
2022-05-17 19:15:21 +03:00
|
|
|
status |= float_overflow_excp(env);
|
2013-04-09 09:00:55 +04:00
|
|
|
} else if (status & float_flag_underflow) {
|
|
|
|
float_underflow_excp(env);
|
2018-06-25 02:12:48 +03:00
|
|
|
}
|
2019-08-26 19:54:34 +03:00
|
|
|
if (status & float_flag_inexact) {
|
|
|
|
float_inexact_excp(env);
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
}
|
|
|
|
if (change_fi) {
|
|
|
|
env->fpscr = FIELD_DP64(env->fpscr, FPSCR, FI,
|
|
|
|
!!(status & float_flag_inexact));
|
2013-04-09 09:00:55 +04:00
|
|
|
}
|
|
|
|
|
2013-08-26 10:31:06 +04:00
|
|
|
if (cs->exception_index == POWERPC_EXCP_PROGRAM &&
|
2012-05-30 08:23:26 +04:00
|
|
|
(env->error_code & POWERPC_EXCP_FP)) {
|
2020-02-14 02:57:34 +03:00
|
|
|
/* Deferred floating-point exception after target FPR update */
|
2018-07-03 18:17:26 +03:00
|
|
|
if (fp_exceptions_enabled(env)) {
|
2016-07-27 09:56:27 +03:00
|
|
|
raise_exception_err_ra(env, cs->exception_index,
|
|
|
|
env->error_code, raddr);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-27 09:56:27 +03:00
|
|
|
void helper_float_check_status(CPUPPCState *env)
|
|
|
|
{
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, true, GETPC());
|
2016-07-27 09:56:27 +03:00
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
void helper_reset_fpstatus(CPUPPCState *env)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
set_float_exception_flags(0, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
2021-12-17 19:57:14 +03:00
|
|
|
static void float_invalid_op_addsub(CPUPPCState *env, int flags,
|
|
|
|
bool set_fpcc, uintptr_t retaddr)
|
2018-10-12 02:41:56 +03:00
|
|
|
{
|
2021-12-17 19:57:14 +03:00
|
|
|
if (flags & float_flag_invalid_isi) {
|
2018-10-12 02:41:56 +03:00
|
|
|
float_invalid_op_vxisi(env, set_fpcc, retaddr);
|
2021-12-17 19:57:14 +03:00
|
|
|
} else if (flags & float_flag_invalid_snan) {
|
2018-10-12 02:41:56 +03:00
|
|
|
float_invalid_op_vxsnan(env, retaddr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:26 +04:00
|
|
|
/* fadd - fadd. */
|
2018-07-03 18:17:29 +03:00
|
|
|
float64 helper_fadd(CPUPPCState *env, float64 arg1, float64 arg2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2018-07-03 18:17:29 +03:00
|
|
|
float64 ret = float64_add(arg1, arg2, &env->fp_status);
|
2021-12-17 19:57:14 +03:00
|
|
|
int flags = get_float_exception_flags(&env->fp_status);
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2021-12-17 19:57:14 +03:00
|
|
|
if (unlikely(flags & float_flag_invalid)) {
|
|
|
|
float_invalid_op_addsub(env, flags, 1, GETPC());
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2018-07-03 18:17:29 +03:00
|
|
|
return ret;
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2021-12-17 19:57:16 +03:00
|
|
|
/* fadds - fadds. */
|
|
|
|
float64 helper_fadds(CPUPPCState *env, float64 arg1, float64 arg2)
|
|
|
|
{
|
|
|
|
float64 ret = float64r32_add(arg1, arg2, &env->fp_status);
|
|
|
|
int flags = get_float_exception_flags(&env->fp_status);
|
|
|
|
|
|
|
|
if (unlikely(flags & float_flag_invalid)) {
|
|
|
|
float_invalid_op_addsub(env, flags, 1, GETPC());
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:26 +04:00
|
|
|
/* fsub - fsub. */
|
2018-07-03 18:17:29 +03:00
|
|
|
float64 helper_fsub(CPUPPCState *env, float64 arg1, float64 arg2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2018-07-03 18:17:29 +03:00
|
|
|
float64 ret = float64_sub(arg1, arg2, &env->fp_status);
|
2021-12-17 19:57:14 +03:00
|
|
|
int flags = get_float_exception_flags(&env->fp_status);
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2021-12-17 19:57:14 +03:00
|
|
|
if (unlikely(flags & float_flag_invalid)) {
|
|
|
|
float_invalid_op_addsub(env, flags, 1, GETPC());
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2018-07-03 18:17:29 +03:00
|
|
|
return ret;
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2021-12-17 19:57:16 +03:00
|
|
|
/* fsubs - fsubs. */
|
|
|
|
float64 helper_fsubs(CPUPPCState *env, float64 arg1, float64 arg2)
|
|
|
|
{
|
|
|
|
float64 ret = float64r32_sub(arg1, arg2, &env->fp_status);
|
|
|
|
int flags = get_float_exception_flags(&env->fp_status);
|
|
|
|
|
|
|
|
if (unlikely(flags & float_flag_invalid)) {
|
|
|
|
float_invalid_op_addsub(env, flags, 1, GETPC());
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-12-17 19:57:14 +03:00
|
|
|
static void float_invalid_op_mul(CPUPPCState *env, int flags,
|
|
|
|
bool set_fprc, uintptr_t retaddr)
|
2018-10-12 02:41:57 +03:00
|
|
|
{
|
2021-12-17 19:57:14 +03:00
|
|
|
if (flags & float_flag_invalid_imz) {
|
2018-10-12 02:41:57 +03:00
|
|
|
float_invalid_op_vximz(env, set_fprc, retaddr);
|
2021-12-17 19:57:14 +03:00
|
|
|
} else if (flags & float_flag_invalid_snan) {
|
2018-10-12 02:41:57 +03:00
|
|
|
float_invalid_op_vxsnan(env, retaddr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:26 +04:00
|
|
|
/* fmul - fmul. */
|
2018-07-03 18:17:28 +03:00
|
|
|
float64 helper_fmul(CPUPPCState *env, float64 arg1, float64 arg2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2018-07-03 18:17:28 +03:00
|
|
|
float64 ret = float64_mul(arg1, arg2, &env->fp_status);
|
2021-12-17 19:57:14 +03:00
|
|
|
int flags = get_float_exception_flags(&env->fp_status);
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2021-12-17 19:57:14 +03:00
|
|
|
if (unlikely(flags & float_flag_invalid)) {
|
|
|
|
float_invalid_op_mul(env, flags, 1, GETPC());
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2018-07-03 18:17:28 +03:00
|
|
|
return ret;
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2021-12-17 19:57:16 +03:00
|
|
|
/* fmuls - fmuls. */
|
|
|
|
float64 helper_fmuls(CPUPPCState *env, float64 arg1, float64 arg2)
|
|
|
|
{
|
|
|
|
float64 ret = float64r32_mul(arg1, arg2, &env->fp_status);
|
|
|
|
int flags = get_float_exception_flags(&env->fp_status);
|
|
|
|
|
|
|
|
if (unlikely(flags & float_flag_invalid)) {
|
|
|
|
float_invalid_op_mul(env, flags, 1, GETPC());
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-12-17 19:57:14 +03:00
|
|
|
static void float_invalid_op_div(CPUPPCState *env, int flags,
|
|
|
|
bool set_fprc, uintptr_t retaddr)
|
2018-10-12 02:41:58 +03:00
|
|
|
{
|
2021-12-17 19:57:14 +03:00
|
|
|
if (flags & float_flag_invalid_idi) {
|
2018-10-12 02:41:58 +03:00
|
|
|
float_invalid_op_vxidi(env, set_fprc, retaddr);
|
2021-12-17 19:57:14 +03:00
|
|
|
} else if (flags & float_flag_invalid_zdz) {
|
2018-10-12 02:41:58 +03:00
|
|
|
float_invalid_op_vxzdz(env, set_fprc, retaddr);
|
2021-12-17 19:57:14 +03:00
|
|
|
} else if (flags & float_flag_invalid_snan) {
|
2018-10-12 02:41:58 +03:00
|
|
|
float_invalid_op_vxsnan(env, retaddr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:26 +04:00
|
|
|
/* fdiv - fdiv. */
|
2018-07-03 18:17:27 +03:00
|
|
|
float64 helper_fdiv(CPUPPCState *env, float64 arg1, float64 arg2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2018-07-03 18:17:27 +03:00
|
|
|
float64 ret = float64_div(arg1, arg2, &env->fp_status);
|
2021-12-17 19:57:14 +03:00
|
|
|
int flags = get_float_exception_flags(&env->fp_status);
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2021-12-17 19:57:14 +03:00
|
|
|
if (unlikely(flags & float_flag_invalid)) {
|
|
|
|
float_invalid_op_div(env, flags, 1, GETPC());
|
|
|
|
}
|
|
|
|
if (unlikely(flags & float_flag_divbyzero)) {
|
|
|
|
float_zero_divide_excp(env, GETPC());
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2018-07-03 18:17:27 +03:00
|
|
|
return ret;
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2021-12-17 19:57:16 +03:00
|
|
|
/* fdivs - fdivs. */
|
|
|
|
float64 helper_fdivs(CPUPPCState *env, float64 arg1, float64 arg2)
|
|
|
|
{
|
|
|
|
float64 ret = float64r32_div(arg1, arg2, &env->fp_status);
|
|
|
|
int flags = get_float_exception_flags(&env->fp_status);
|
|
|
|
|
|
|
|
if (unlikely(flags & float_flag_invalid)) {
|
|
|
|
float_invalid_op_div(env, flags, 1, GETPC());
|
|
|
|
}
|
|
|
|
if (unlikely(flags & float_flag_divbyzero)) {
|
|
|
|
float_zero_divide_excp(env, GETPC());
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-12-17 19:57:14 +03:00
|
|
|
static uint64_t float_invalid_cvt(CPUPPCState *env, int flags,
|
|
|
|
uint64_t ret, uint64_t ret_nan,
|
|
|
|
bool set_fprc, uintptr_t retaddr)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* VXCVI is different from most in that it sets two exception bits,
|
|
|
|
* VXCVI and VXSNAN for an SNaN input.
|
|
|
|
*/
|
2021-12-17 19:57:14 +03:00
|
|
|
if (flags & float_flag_invalid_snan) {
|
2021-12-17 19:57:14 +03:00
|
|
|
env->fpscr |= FP_VXSNAN;
|
2018-10-12 02:41:59 +03:00
|
|
|
}
|
2021-12-17 19:57:14 +03:00
|
|
|
float_invalid_op_vxcvi(env, set_fprc, retaddr);
|
|
|
|
|
|
|
|
return flags & float_flag_invalid_cvti ? ret : ret_nan;
|
2018-10-12 02:41:59 +03:00
|
|
|
}
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2014-01-07 20:05:59 +04:00
|
|
|
#define FPU_FCTI(op, cvt, nanval) \
|
2018-10-12 02:41:59 +03:00
|
|
|
uint64_t helper_##op(CPUPPCState *env, float64 arg) \
|
2014-01-07 20:05:59 +04:00
|
|
|
{ \
|
2018-10-12 02:41:59 +03:00
|
|
|
uint64_t ret = float64_to_##cvt(arg, &env->fp_status); \
|
2021-12-17 19:57:14 +03:00
|
|
|
int flags = get_float_exception_flags(&env->fp_status); \
|
|
|
|
if (unlikely(flags & float_flag_invalid)) { \
|
2021-12-17 19:57:14 +03:00
|
|
|
ret = float_invalid_cvt(env, flags, ret, nanval, 1, GETPC()); \
|
2014-01-07 20:05:59 +04:00
|
|
|
} \
|
2018-10-12 02:41:59 +03:00
|
|
|
return ret; \
|
|
|
|
}
|
2014-01-07 20:05:59 +04:00
|
|
|
|
2014-02-24 18:12:13 +04:00
|
|
|
FPU_FCTI(fctiw, int32, 0x80000000U)
|
|
|
|
FPU_FCTI(fctiwz, int32_round_to_zero, 0x80000000U)
|
|
|
|
FPU_FCTI(fctiwu, uint32, 0x00000000U)
|
|
|
|
FPU_FCTI(fctiwuz, uint32_round_to_zero, 0x00000000U)
|
|
|
|
FPU_FCTI(fctid, int64, 0x8000000000000000ULL)
|
|
|
|
FPU_FCTI(fctidz, int64_round_to_zero, 0x8000000000000000ULL)
|
|
|
|
FPU_FCTI(fctidu, uint64, 0x0000000000000000ULL)
|
|
|
|
FPU_FCTI(fctiduz, uint64_round_to_zero, 0x0000000000000000ULL)
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2014-01-07 20:06:00 +04:00
|
|
|
#define FPU_FCFI(op, cvtr, is_single) \
|
|
|
|
uint64_t helper_##op(CPUPPCState *env, uint64_t arg) \
|
|
|
|
{ \
|
|
|
|
CPU_DoubleU farg; \
|
|
|
|
\
|
|
|
|
if (is_single) { \
|
|
|
|
float32 tmp = cvtr(arg, &env->fp_status); \
|
|
|
|
farg.d = float32_to_float64(tmp, &env->fp_status); \
|
|
|
|
} else { \
|
|
|
|
farg.d = cvtr(arg, &env->fp_status); \
|
|
|
|
} \
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, true, GETPC()); \
|
2014-01-07 20:06:00 +04:00
|
|
|
return farg.ll; \
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2014-01-07 20:06:00 +04:00
|
|
|
FPU_FCFI(fcfid, int64_to_float64, 0)
|
|
|
|
FPU_FCFI(fcfids, int64_to_float32, 1)
|
|
|
|
FPU_FCFI(fcfidu, uint64_to_float64, 0)
|
|
|
|
FPU_FCFI(fcfidus, uint64_to_float32, 1)
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2021-12-17 19:57:15 +03:00
|
|
|
static uint64_t do_fri(CPUPPCState *env, uint64_t arg,
|
2021-12-17 19:57:15 +03:00
|
|
|
FloatRoundMode rounding_mode)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2021-05-21 23:17:53 +03:00
|
|
|
FloatRoundMode old_rounding_mode = get_float_rounding_mode(&env->fp_status);
|
2021-12-17 19:57:15 +03:00
|
|
|
int flags;
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2021-12-17 19:57:15 +03:00
|
|
|
set_float_rounding_mode(rounding_mode, &env->fp_status);
|
|
|
|
arg = float64_round_to_int(arg, &env->fp_status);
|
|
|
|
set_float_rounding_mode(old_rounding_mode, &env->fp_status);
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2021-12-17 19:57:15 +03:00
|
|
|
flags = get_float_exception_flags(&env->fp_status);
|
|
|
|
if (flags & float_flag_invalid_snan) {
|
2018-10-12 02:41:53 +03:00
|
|
|
float_invalid_op_vxsnan(env, GETPC());
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
2021-12-17 19:57:15 +03:00
|
|
|
|
|
|
|
/* fri* does not set FPSCR[XX] */
|
|
|
|
set_float_exception_flags(flags & ~float_flag_inexact, &env->fp_status);
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, true, GETPC());
|
2021-12-17 19:57:15 +03:00
|
|
|
|
|
|
|
return arg;
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint64_t helper_frin(CPUPPCState *env, uint64_t arg)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2014-01-07 20:06:05 +04:00
|
|
|
return do_fri(env, arg, float_round_ties_away);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint64_t helper_friz(CPUPPCState *env, uint64_t arg)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2012-05-30 08:23:27 +04:00
|
|
|
return do_fri(env, arg, float_round_to_zero);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint64_t helper_frip(CPUPPCState *env, uint64_t arg)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2012-05-30 08:23:27 +04:00
|
|
|
return do_fri(env, arg, float_round_up);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint64_t helper_frim(CPUPPCState *env, uint64_t arg)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2012-05-30 08:23:27 +04:00
|
|
|
return do_fri(env, arg, float_round_down);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2021-12-17 19:57:15 +03:00
|
|
|
static void float_invalid_op_madd(CPUPPCState *env, int flags,
|
|
|
|
bool set_fpcc, uintptr_t retaddr)
|
|
|
|
{
|
|
|
|
if (flags & float_flag_invalid_imz) {
|
|
|
|
float_invalid_op_vximz(env, set_fpcc, retaddr);
|
|
|
|
} else {
|
|
|
|
float_invalid_op_addsub(env, flags, set_fpcc, retaddr);
|
|
|
|
}
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2021-12-17 19:57:15 +03:00
|
|
|
static float64 do_fmadd(CPUPPCState *env, float64 a, float64 b,
|
|
|
|
float64 c, int madd_flags, uintptr_t retaddr)
|
|
|
|
{
|
|
|
|
float64 ret = float64_muladd(a, b, c, madd_flags, &env->fp_status);
|
|
|
|
int flags = get_float_exception_flags(&env->fp_status);
|
|
|
|
|
2021-12-17 19:57:15 +03:00
|
|
|
if (unlikely(flags & float_flag_invalid)) {
|
|
|
|
float_invalid_op_madd(env, flags, 1, retaddr);
|
2021-12-17 19:57:15 +03:00
|
|
|
}
|
|
|
|
return ret;
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2021-12-17 19:57:16 +03:00
|
|
|
static uint64_t do_fmadds(CPUPPCState *env, float64 a, float64 b,
|
|
|
|
float64 c, int madd_flags, uintptr_t retaddr)
|
|
|
|
{
|
|
|
|
float64 ret = float64r32_muladd(a, b, c, madd_flags, &env->fp_status);
|
|
|
|
int flags = get_float_exception_flags(&env->fp_status);
|
|
|
|
|
|
|
|
if (unlikely(flags & float_flag_invalid)) {
|
|
|
|
float_invalid_op_madd(env, flags, 1, retaddr);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-12-17 19:57:15 +03:00
|
|
|
#define FPU_FMADD(op, madd_flags) \
|
|
|
|
uint64_t helper_##op(CPUPPCState *env, uint64_t arg1, \
|
|
|
|
uint64_t arg2, uint64_t arg3) \
|
2021-12-17 19:57:16 +03:00
|
|
|
{ return do_fmadd(env, arg1, arg2, arg3, madd_flags, GETPC()); } \
|
|
|
|
uint64_t helper_##op##s(CPUPPCState *env, uint64_t arg1, \
|
|
|
|
uint64_t arg2, uint64_t arg3) \
|
|
|
|
{ return do_fmadds(env, arg1, arg2, arg3, madd_flags, GETPC()); }
|
2021-12-17 19:57:15 +03:00
|
|
|
|
2017-03-02 17:10:29 +03:00
|
|
|
#define MADD_FLGS 0
|
|
|
|
#define MSUB_FLGS float_muladd_negate_c
|
|
|
|
#define NMADD_FLGS float_muladd_negate_result
|
|
|
|
#define NMSUB_FLGS (float_muladd_negate_c | float_muladd_negate_result)
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2017-03-02 17:10:29 +03:00
|
|
|
FPU_FMADD(fmadd, MADD_FLGS)
|
|
|
|
FPU_FMADD(fnmadd, NMADD_FLGS)
|
|
|
|
FPU_FMADD(fmsub, MSUB_FLGS)
|
|
|
|
FPU_FMADD(fnmsub, NMSUB_FLGS)
|
2012-05-30 08:23:26 +04:00
|
|
|
|
|
|
|
/* frsp - frsp. */
|
2021-12-17 19:57:15 +03:00
|
|
|
static uint64_t do_frsp(CPUPPCState *env, uint64_t arg, uintptr_t retaddr)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2021-12-17 19:57:15 +03:00
|
|
|
float32 f32 = float64_to_float32(arg, &env->fp_status);
|
|
|
|
int flags = get_float_exception_flags(&env->fp_status);
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2021-12-17 19:57:15 +03:00
|
|
|
if (unlikely(flags & float_flag_invalid_snan)) {
|
2021-12-17 19:57:15 +03:00
|
|
|
float_invalid_op_vxsnan(env, retaddr);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
2021-12-17 19:57:15 +03:00
|
|
|
return helper_todouble(f32);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2021-12-17 19:57:15 +03:00
|
|
|
uint64_t helper_frsp(CPUPPCState *env, uint64_t arg)
|
|
|
|
{
|
|
|
|
return do_frsp(env, arg, GETPC());
|
|
|
|
}
|
|
|
|
|
2021-12-17 19:57:15 +03:00
|
|
|
static void float_invalid_op_sqrt(CPUPPCState *env, int flags,
|
|
|
|
bool set_fpcc, uintptr_t retaddr)
|
|
|
|
{
|
|
|
|
if (unlikely(flags & float_flag_invalid_sqrt)) {
|
|
|
|
float_invalid_op_vxsqrt(env, set_fpcc, retaddr);
|
|
|
|
} else if (unlikely(flags & float_flag_invalid_snan)) {
|
|
|
|
float_invalid_op_vxsnan(env, retaddr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-05 15:37:46 +03:00
|
|
|
#define FPU_FSQRT(name, op) \
|
|
|
|
float64 helper_##name(CPUPPCState *env, float64 arg) \
|
|
|
|
{ \
|
|
|
|
float64 ret = op(arg, &env->fp_status); \
|
|
|
|
int flags = get_float_exception_flags(&env->fp_status); \
|
|
|
|
\
|
|
|
|
if (unlikely(flags & float_flag_invalid)) { \
|
|
|
|
float_invalid_op_sqrt(env, flags, 1, GETPC()); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
return ret; \
|
|
|
|
}
|
|
|
|
|
|
|
|
FPU_FSQRT(FSQRT, float64_sqrt)
|
|
|
|
FPU_FSQRT(FSQRTS, float64r32_sqrt)
|
2021-12-17 19:57:16 +03:00
|
|
|
|
2012-05-30 08:23:26 +04:00
|
|
|
/* fre - fre. */
|
2018-07-03 18:17:31 +03:00
|
|
|
float64 helper_fre(CPUPPCState *env, float64 arg)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2018-07-03 18:17:31 +03:00
|
|
|
/* "Estimate" the reciprocal with actual division. */
|
|
|
|
float64 ret = float64_div(float64_one, arg, &env->fp_status);
|
2021-12-17 19:57:15 +03:00
|
|
|
int flags = get_float_exception_flags(&env->fp_status);
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2021-12-17 19:57:15 +03:00
|
|
|
if (unlikely(flags & float_flag_invalid_snan)) {
|
|
|
|
float_invalid_op_vxsnan(env, GETPC());
|
|
|
|
}
|
|
|
|
if (unlikely(flags & float_flag_divbyzero)) {
|
|
|
|
float_zero_divide_excp(env, GETPC());
|
|
|
|
/* For FPSCR.ZE == 0, the result is 1/2. */
|
|
|
|
ret = float64_set_sign(float64_half, float64_is_neg(arg));
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
2018-07-03 18:17:31 +03:00
|
|
|
|
|
|
|
return ret;
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* fres - fres. */
|
2012-05-30 08:23:27 +04:00
|
|
|
uint64_t helper_fres(CPUPPCState *env, uint64_t arg)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2021-12-17 19:57:16 +03:00
|
|
|
/* "Estimate" the reciprocal with actual division. */
|
|
|
|
float64 ret = float64r32_div(float64_one, arg, &env->fp_status);
|
|
|
|
int flags = get_float_exception_flags(&env->fp_status);
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2021-12-17 19:57:16 +03:00
|
|
|
if (unlikely(flags & float_flag_invalid_snan)) {
|
2018-10-12 02:41:53 +03:00
|
|
|
float_invalid_op_vxsnan(env, GETPC());
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
2021-12-17 19:57:16 +03:00
|
|
|
if (unlikely(flags & float_flag_divbyzero)) {
|
|
|
|
float_zero_divide_excp(env, GETPC());
|
|
|
|
/* For FPSCR.ZE == 0, the result is 1/2. */
|
|
|
|
ret = float64_set_sign(float64_half, float64_is_neg(arg));
|
|
|
|
}
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2021-12-17 19:57:16 +03:00
|
|
|
return ret;
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* frsqrte - frsqrte. */
|
2018-07-03 18:17:31 +03:00
|
|
|
float64 helper_frsqrte(CPUPPCState *env, float64 arg)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2018-07-03 18:17:31 +03:00
|
|
|
/* "Estimate" the reciprocal with actual division. */
|
|
|
|
float64 rets = float64_sqrt(arg, &env->fp_status);
|
|
|
|
float64 retd = float64_div(float64_one, rets, &env->fp_status);
|
2021-12-17 19:57:15 +03:00
|
|
|
int flags = get_float_exception_flags(&env->fp_status);
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2021-12-17 19:57:15 +03:00
|
|
|
if (unlikely(flags & float_flag_invalid)) {
|
|
|
|
float_invalid_op_sqrt(env, flags, 1, GETPC());
|
|
|
|
}
|
|
|
|
if (unlikely(flags & float_flag_divbyzero)) {
|
2021-12-17 19:57:16 +03:00
|
|
|
/* Reciprocal of (square root of) zero. */
|
|
|
|
float_zero_divide_excp(env, GETPC());
|
|
|
|
}
|
|
|
|
|
|
|
|
return retd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* frsqrtes - frsqrtes. */
|
|
|
|
float64 helper_frsqrtes(CPUPPCState *env, float64 arg)
|
|
|
|
{
|
|
|
|
/* "Estimate" the reciprocal with actual division. */
|
|
|
|
float64 rets = float64_sqrt(arg, &env->fp_status);
|
|
|
|
float64 retd = float64r32_div(float64_one, rets, &env->fp_status);
|
|
|
|
int flags = get_float_exception_flags(&env->fp_status);
|
|
|
|
|
|
|
|
if (unlikely(flags & float_flag_invalid)) {
|
|
|
|
float_invalid_op_sqrt(env, flags, 1, GETPC());
|
|
|
|
}
|
|
|
|
if (unlikely(flags & float_flag_divbyzero)) {
|
2021-12-17 19:57:15 +03:00
|
|
|
/* Reciprocal of (square root of) zero. */
|
|
|
|
float_zero_divide_excp(env, GETPC());
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
2014-11-13 00:45:59 +03:00
|
|
|
|
2018-07-03 18:17:31 +03:00
|
|
|
return retd;
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* fsel - fsel. */
|
2022-05-17 15:39:22 +03:00
|
|
|
uint64_t helper_FSEL(uint64_t a, uint64_t b, uint64_t c)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
2022-05-17 15:39:22 +03:00
|
|
|
CPU_DoubleU fa;
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2022-05-17 15:39:22 +03:00
|
|
|
fa.ll = a;
|
2012-05-30 08:23:26 +04:00
|
|
|
|
2022-05-17 15:39:22 +03:00
|
|
|
if ((!float64_is_neg(fa.d) || float64_is_zero(fa.d)) &&
|
|
|
|
!float64_is_any_nan(fa.d)) {
|
|
|
|
return c;
|
2012-05-30 08:23:26 +04:00
|
|
|
} else {
|
2022-05-17 15:39:22 +03:00
|
|
|
return b;
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-07 20:06:07 +04:00
|
|
|
uint32_t helper_ftdiv(uint64_t fra, uint64_t frb)
|
|
|
|
{
|
|
|
|
int fe_flag = 0;
|
|
|
|
int fg_flag = 0;
|
|
|
|
|
|
|
|
if (unlikely(float64_is_infinity(fra) ||
|
|
|
|
float64_is_infinity(frb) ||
|
|
|
|
float64_is_zero(frb))) {
|
|
|
|
fe_flag = 1;
|
|
|
|
fg_flag = 1;
|
|
|
|
} else {
|
|
|
|
int e_a = ppc_float64_get_unbiased_exp(fra);
|
|
|
|
int e_b = ppc_float64_get_unbiased_exp(frb);
|
|
|
|
|
|
|
|
if (unlikely(float64_is_any_nan(fra) ||
|
|
|
|
float64_is_any_nan(frb))) {
|
|
|
|
fe_flag = 1;
|
|
|
|
} else if ((e_b <= -1022) || (e_b >= 1021)) {
|
|
|
|
fe_flag = 1;
|
|
|
|
} else if (!float64_is_zero(fra) &&
|
|
|
|
(((e_a - e_b) >= 1023) ||
|
|
|
|
((e_a - e_b) <= -1021) ||
|
|
|
|
(e_a <= -970))) {
|
|
|
|
fe_flag = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlikely(float64_is_zero_or_denormal(frb))) {
|
|
|
|
/* XB is not zero because of the above check and */
|
|
|
|
/* so must be denormalized. */
|
|
|
|
fg_flag = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0x8 | (fg_flag ? 4 : 0) | (fe_flag ? 2 : 0);
|
|
|
|
}
|
2014-01-07 20:06:08 +04:00
|
|
|
|
|
|
|
uint32_t helper_ftsqrt(uint64_t frb)
|
|
|
|
{
|
|
|
|
int fe_flag = 0;
|
|
|
|
int fg_flag = 0;
|
|
|
|
|
|
|
|
if (unlikely(float64_is_infinity(frb) || float64_is_zero(frb))) {
|
|
|
|
fe_flag = 1;
|
|
|
|
fg_flag = 1;
|
|
|
|
} else {
|
|
|
|
int e_b = ppc_float64_get_unbiased_exp(frb);
|
|
|
|
|
|
|
|
if (unlikely(float64_is_any_nan(frb))) {
|
|
|
|
fe_flag = 1;
|
|
|
|
} else if (unlikely(float64_is_zero(frb))) {
|
|
|
|
fe_flag = 1;
|
|
|
|
} else if (unlikely(float64_is_neg(frb))) {
|
|
|
|
fe_flag = 1;
|
2019-03-21 09:01:06 +03:00
|
|
|
} else if (!float64_is_zero(frb) && (e_b <= (-1022 + 52))) {
|
2014-01-07 20:06:08 +04:00
|
|
|
fe_flag = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlikely(float64_is_zero_or_denormal(frb))) {
|
|
|
|
/* XB is not zero because of the above check and */
|
|
|
|
/* therefore must be denormalized. */
|
|
|
|
fg_flag = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0x8 | (fg_flag ? 4 : 0) | (fe_flag ? 2 : 0);
|
|
|
|
}
|
2014-01-07 20:06:07 +04:00
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
void helper_fcmpu(CPUPPCState *env, uint64_t arg1, uint64_t arg2,
|
|
|
|
uint32_t crfD)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU farg1, farg2;
|
|
|
|
uint32_t ret = 0;
|
|
|
|
|
|
|
|
farg1.ll = arg1;
|
|
|
|
farg2.ll = arg2;
|
|
|
|
|
|
|
|
if (unlikely(float64_is_any_nan(farg1.d) ||
|
|
|
|
float64_is_any_nan(farg2.d))) {
|
|
|
|
ret = 0x01UL;
|
|
|
|
} else if (float64_lt(farg1.d, farg2.d, &env->fp_status)) {
|
|
|
|
ret = 0x08UL;
|
|
|
|
} else if (!float64_le(farg1.d, farg2.d, &env->fp_status)) {
|
|
|
|
ret = 0x04UL;
|
|
|
|
} else {
|
|
|
|
ret = 0x02UL;
|
|
|
|
}
|
|
|
|
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr &= ~FP_FPCC;
|
|
|
|
env->fpscr |= ret << FPSCR_FPCC;
|
2012-05-30 08:23:26 +04:00
|
|
|
env->crf[crfD] = ret;
|
|
|
|
if (unlikely(ret == 0x01UL
|
softfloat: Implement run-time-configurable meaning of signaling NaN bit
This patch modifies SoftFloat library so that it can be configured in
run-time in relation to the meaning of signaling NaN bit, while, at the
same time, strictly preserving its behavior on all existing platforms.
Background:
In floating-point calculations, there is a need for denoting undefined or
unrepresentable values. This is achieved by defining certain floating-point
numerical values to be NaNs (which stands for "not a number"). For additional
reasons, virtually all modern floating-point unit implementations use two
kinds of NaNs: quiet and signaling. The binary representations of these two
kinds of NaNs, as a rule, differ only in one bit (that bit is, traditionally,
the first bit of mantissa).
Up to 2008, standards for floating-point did not specify all details about
binary representation of NaNs. More specifically, the meaning of the bit
that is used for distinguishing between signaling and quiet NaNs was not
strictly prescribed. (IEEE 754-2008 was the first floating-point standard
that defined that meaning clearly, see [1], p. 35) As a result, different
platforms took different approaches, and that presented considerable
challenge for multi-platform emulators like QEMU.
Mips platform represents the most complex case among QEMU-supported
platforms regarding signaling NaN bit. Up to the Release 6 of Mips
architecture, "1" in signaling NaN bit denoted signaling NaN, which is
opposite to IEEE 754-2008 standard. From Release 6 on, Mips architecture
adopted IEEE standard prescription, and "0" denotes signaling NaN. On top of
that, Mips architecture for SIMD (also known as MSA, or vector instructions)
also specifies signaling bit in accordance to IEEE standard. MSA unit can be
implemented with both pre-Release 6 and Release 6 main processor units.
QEMU uses SoftFloat library to implement various floating-point-related
instructions on all platforms. The current QEMU implementation allows for
defining meaning of signaling NaN bit during build time, and is implemented
via preprocessor macro called SNAN_BIT_IS_ONE.
On the other hand, the change in this patch enables SoftFloat library to be
configured in run-time. This configuration is meant to occur during CPU
initialization, at the moment when it is definitely known what desired
behavior for particular CPU (or any additional FPUs) is.
The change is implemented so that it is consistent with existing
implementation of similar cases. This means that structure float_status is
used for passing the information about desired signaling NaN bit on each
invocation of SoftFloat functions. The additional field in float_status is
called snan_bit_is_one, which supersedes macro SNAN_BIT_IS_ONE.
IMPORTANT:
This change is not meant to create any change in emulator behavior or
functionality on any platform. It just provides the means for SoftFloat
library to be used in a more flexible way - in other words, it will just
prepare SoftFloat library for usage related to Mips platform and its
specifics regarding signaling bit meaning, which is done in some of
subsequent patches from this series.
Further break down of changes:
1) Added field snan_bit_is_one to the structure float_status, and
correspondent setter function set_snan_bit_is_one().
2) Constants <float16|float32|float64|floatx80|float128>_default_nan
(used both internally and externally) converted to functions
<float16|float32|float64|floatx80|float128>_default_nan(float_status*).
This is necessary since they are dependent on signaling bit meaning.
At the same time, for the sake of code cleanup and simplicity, constants
<floatx80|float128>_default_nan_<low|high> (used only internally within
SoftFloat library) are removed, as not needed.
3) Added a float_status* argument to SoftFloat library functions
XXX_is_quiet_nan(XXX a_), XXX_is_signaling_nan(XXX a_),
XXX_maybe_silence_nan(XXX a_). This argument must be present in
order to enable correct invocation of new version of functions
XXX_default_nan(). (XXX is <float16|float32|float64|floatx80|float128>
here)
4) Updated code for all platforms to reflect changes in SoftFloat library.
This change is twofolds: it includes modifications of SoftFloat library
functions invocations, and an addition of invocation of function
set_snan_bit_is_one() during CPU initialization, with arguments that
are appropriate for each particular platform. It was established that
all platforms zero their main CPU data structures, so snan_bit_is_one(0)
in appropriate places is not added, as it is not needed.
[1] "IEEE Standard for Floating-Point Arithmetic",
IEEE Computer Society, August 29, 2008.
Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
Signed-off-by: Maciej W. Rozycki <macro@codesourcery.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Tested-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
Reviewed-by: Leon Alrae <leon.alrae@imgtec.com>
Tested-by: Leon Alrae <leon.alrae@imgtec.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
[leon.alrae@imgtec.com:
* cherry-picked 2 chunks from patch #2 to fix compilation warnings]
Signed-off-by: Leon Alrae <leon.alrae@imgtec.com>
2016-06-10 12:57:28 +03:00
|
|
|
&& (float64_is_signaling_nan(farg1.d, &env->fp_status) ||
|
|
|
|
float64_is_signaling_nan(farg2.d, &env->fp_status)))) {
|
2012-05-30 08:23:26 +04:00
|
|
|
/* sNaN comparison */
|
2018-10-12 02:41:53 +03:00
|
|
|
float_invalid_op_vxsnan(env, GETPC());
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
void helper_fcmpo(CPUPPCState *env, uint64_t arg1, uint64_t arg2,
|
|
|
|
uint32_t crfD)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU farg1, farg2;
|
|
|
|
uint32_t ret = 0;
|
|
|
|
|
|
|
|
farg1.ll = arg1;
|
|
|
|
farg2.ll = arg2;
|
|
|
|
|
|
|
|
if (unlikely(float64_is_any_nan(farg1.d) ||
|
|
|
|
float64_is_any_nan(farg2.d))) {
|
|
|
|
ret = 0x01UL;
|
|
|
|
} else if (float64_lt(farg1.d, farg2.d, &env->fp_status)) {
|
|
|
|
ret = 0x08UL;
|
|
|
|
} else if (!float64_le(farg1.d, farg2.d, &env->fp_status)) {
|
|
|
|
ret = 0x04UL;
|
|
|
|
} else {
|
|
|
|
ret = 0x02UL;
|
|
|
|
}
|
|
|
|
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr &= ~FP_FPCC;
|
|
|
|
env->fpscr |= ret << FPSCR_FPCC;
|
|
|
|
env->crf[crfD] = (uint32_t) ret;
|
2012-05-30 08:23:26 +04:00
|
|
|
if (unlikely(ret == 0x01UL)) {
|
2018-10-12 02:41:53 +03:00
|
|
|
float_invalid_op_vxvc(env, 1, GETPC());
|
softfloat: Implement run-time-configurable meaning of signaling NaN bit
This patch modifies SoftFloat library so that it can be configured in
run-time in relation to the meaning of signaling NaN bit, while, at the
same time, strictly preserving its behavior on all existing platforms.
Background:
In floating-point calculations, there is a need for denoting undefined or
unrepresentable values. This is achieved by defining certain floating-point
numerical values to be NaNs (which stands for "not a number"). For additional
reasons, virtually all modern floating-point unit implementations use two
kinds of NaNs: quiet and signaling. The binary representations of these two
kinds of NaNs, as a rule, differ only in one bit (that bit is, traditionally,
the first bit of mantissa).
Up to 2008, standards for floating-point did not specify all details about
binary representation of NaNs. More specifically, the meaning of the bit
that is used for distinguishing between signaling and quiet NaNs was not
strictly prescribed. (IEEE 754-2008 was the first floating-point standard
that defined that meaning clearly, see [1], p. 35) As a result, different
platforms took different approaches, and that presented considerable
challenge for multi-platform emulators like QEMU.
Mips platform represents the most complex case among QEMU-supported
platforms regarding signaling NaN bit. Up to the Release 6 of Mips
architecture, "1" in signaling NaN bit denoted signaling NaN, which is
opposite to IEEE 754-2008 standard. From Release 6 on, Mips architecture
adopted IEEE standard prescription, and "0" denotes signaling NaN. On top of
that, Mips architecture for SIMD (also known as MSA, or vector instructions)
also specifies signaling bit in accordance to IEEE standard. MSA unit can be
implemented with both pre-Release 6 and Release 6 main processor units.
QEMU uses SoftFloat library to implement various floating-point-related
instructions on all platforms. The current QEMU implementation allows for
defining meaning of signaling NaN bit during build time, and is implemented
via preprocessor macro called SNAN_BIT_IS_ONE.
On the other hand, the change in this patch enables SoftFloat library to be
configured in run-time. This configuration is meant to occur during CPU
initialization, at the moment when it is definitely known what desired
behavior for particular CPU (or any additional FPUs) is.
The change is implemented so that it is consistent with existing
implementation of similar cases. This means that structure float_status is
used for passing the information about desired signaling NaN bit on each
invocation of SoftFloat functions. The additional field in float_status is
called snan_bit_is_one, which supersedes macro SNAN_BIT_IS_ONE.
IMPORTANT:
This change is not meant to create any change in emulator behavior or
functionality on any platform. It just provides the means for SoftFloat
library to be used in a more flexible way - in other words, it will just
prepare SoftFloat library for usage related to Mips platform and its
specifics regarding signaling bit meaning, which is done in some of
subsequent patches from this series.
Further break down of changes:
1) Added field snan_bit_is_one to the structure float_status, and
correspondent setter function set_snan_bit_is_one().
2) Constants <float16|float32|float64|floatx80|float128>_default_nan
(used both internally and externally) converted to functions
<float16|float32|float64|floatx80|float128>_default_nan(float_status*).
This is necessary since they are dependent on signaling bit meaning.
At the same time, for the sake of code cleanup and simplicity, constants
<floatx80|float128>_default_nan_<low|high> (used only internally within
SoftFloat library) are removed, as not needed.
3) Added a float_status* argument to SoftFloat library functions
XXX_is_quiet_nan(XXX a_), XXX_is_signaling_nan(XXX a_),
XXX_maybe_silence_nan(XXX a_). This argument must be present in
order to enable correct invocation of new version of functions
XXX_default_nan(). (XXX is <float16|float32|float64|floatx80|float128>
here)
4) Updated code for all platforms to reflect changes in SoftFloat library.
This change is twofolds: it includes modifications of SoftFloat library
functions invocations, and an addition of invocation of function
set_snan_bit_is_one() during CPU initialization, with arguments that
are appropriate for each particular platform. It was established that
all platforms zero their main CPU data structures, so snan_bit_is_one(0)
in appropriate places is not added, as it is not needed.
[1] "IEEE Standard for Floating-Point Arithmetic",
IEEE Computer Society, August 29, 2008.
Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
Signed-off-by: Maciej W. Rozycki <macro@codesourcery.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Tested-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
Reviewed-by: Leon Alrae <leon.alrae@imgtec.com>
Tested-by: Leon Alrae <leon.alrae@imgtec.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
[leon.alrae@imgtec.com:
* cherry-picked 2 chunks from patch #2 to fix compilation warnings]
Signed-off-by: Leon Alrae <leon.alrae@imgtec.com>
2016-06-10 12:57:28 +03:00
|
|
|
if (float64_is_signaling_nan(farg1.d, &env->fp_status) ||
|
|
|
|
float64_is_signaling_nan(farg2.d, &env->fp_status)) {
|
2012-05-30 08:23:26 +04:00
|
|
|
/* sNaN comparison */
|
2018-10-12 02:41:53 +03:00
|
|
|
float_invalid_op_vxsnan(env, GETPC());
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Single-precision floating-point conversions */
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline uint32_t efscfsi(CPUPPCState *env, uint32_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_FloatU u;
|
|
|
|
|
|
|
|
u.f = int32_to_float32(val, &env->vec_status);
|
|
|
|
|
|
|
|
return u.l;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline uint32_t efscfui(CPUPPCState *env, uint32_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_FloatU u;
|
|
|
|
|
|
|
|
u.f = uint32_to_float32(val, &env->vec_status);
|
|
|
|
|
|
|
|
return u.l;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline int32_t efsctsi(CPUPPCState *env, uint32_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_FloatU u;
|
|
|
|
|
|
|
|
u.l = val;
|
|
|
|
/* NaN are not treated the same way IEEE 754 does */
|
softfloat: Implement run-time-configurable meaning of signaling NaN bit
This patch modifies SoftFloat library so that it can be configured in
run-time in relation to the meaning of signaling NaN bit, while, at the
same time, strictly preserving its behavior on all existing platforms.
Background:
In floating-point calculations, there is a need for denoting undefined or
unrepresentable values. This is achieved by defining certain floating-point
numerical values to be NaNs (which stands for "not a number"). For additional
reasons, virtually all modern floating-point unit implementations use two
kinds of NaNs: quiet and signaling. The binary representations of these two
kinds of NaNs, as a rule, differ only in one bit (that bit is, traditionally,
the first bit of mantissa).
Up to 2008, standards for floating-point did not specify all details about
binary representation of NaNs. More specifically, the meaning of the bit
that is used for distinguishing between signaling and quiet NaNs was not
strictly prescribed. (IEEE 754-2008 was the first floating-point standard
that defined that meaning clearly, see [1], p. 35) As a result, different
platforms took different approaches, and that presented considerable
challenge for multi-platform emulators like QEMU.
Mips platform represents the most complex case among QEMU-supported
platforms regarding signaling NaN bit. Up to the Release 6 of Mips
architecture, "1" in signaling NaN bit denoted signaling NaN, which is
opposite to IEEE 754-2008 standard. From Release 6 on, Mips architecture
adopted IEEE standard prescription, and "0" denotes signaling NaN. On top of
that, Mips architecture for SIMD (also known as MSA, or vector instructions)
also specifies signaling bit in accordance to IEEE standard. MSA unit can be
implemented with both pre-Release 6 and Release 6 main processor units.
QEMU uses SoftFloat library to implement various floating-point-related
instructions on all platforms. The current QEMU implementation allows for
defining meaning of signaling NaN bit during build time, and is implemented
via preprocessor macro called SNAN_BIT_IS_ONE.
On the other hand, the change in this patch enables SoftFloat library to be
configured in run-time. This configuration is meant to occur during CPU
initialization, at the moment when it is definitely known what desired
behavior for particular CPU (or any additional FPUs) is.
The change is implemented so that it is consistent with existing
implementation of similar cases. This means that structure float_status is
used for passing the information about desired signaling NaN bit on each
invocation of SoftFloat functions. The additional field in float_status is
called snan_bit_is_one, which supersedes macro SNAN_BIT_IS_ONE.
IMPORTANT:
This change is not meant to create any change in emulator behavior or
functionality on any platform. It just provides the means for SoftFloat
library to be used in a more flexible way - in other words, it will just
prepare SoftFloat library for usage related to Mips platform and its
specifics regarding signaling bit meaning, which is done in some of
subsequent patches from this series.
Further break down of changes:
1) Added field snan_bit_is_one to the structure float_status, and
correspondent setter function set_snan_bit_is_one().
2) Constants <float16|float32|float64|floatx80|float128>_default_nan
(used both internally and externally) converted to functions
<float16|float32|float64|floatx80|float128>_default_nan(float_status*).
This is necessary since they are dependent on signaling bit meaning.
At the same time, for the sake of code cleanup and simplicity, constants
<floatx80|float128>_default_nan_<low|high> (used only internally within
SoftFloat library) are removed, as not needed.
3) Added a float_status* argument to SoftFloat library functions
XXX_is_quiet_nan(XXX a_), XXX_is_signaling_nan(XXX a_),
XXX_maybe_silence_nan(XXX a_). This argument must be present in
order to enable correct invocation of new version of functions
XXX_default_nan(). (XXX is <float16|float32|float64|floatx80|float128>
here)
4) Updated code for all platforms to reflect changes in SoftFloat library.
This change is twofolds: it includes modifications of SoftFloat library
functions invocations, and an addition of invocation of function
set_snan_bit_is_one() during CPU initialization, with arguments that
are appropriate for each particular platform. It was established that
all platforms zero their main CPU data structures, so snan_bit_is_one(0)
in appropriate places is not added, as it is not needed.
[1] "IEEE Standard for Floating-Point Arithmetic",
IEEE Computer Society, August 29, 2008.
Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
Signed-off-by: Maciej W. Rozycki <macro@codesourcery.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Tested-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
Reviewed-by: Leon Alrae <leon.alrae@imgtec.com>
Tested-by: Leon Alrae <leon.alrae@imgtec.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
[leon.alrae@imgtec.com:
* cherry-picked 2 chunks from patch #2 to fix compilation warnings]
Signed-off-by: Leon Alrae <leon.alrae@imgtec.com>
2016-06-10 12:57:28 +03:00
|
|
|
if (unlikely(float32_is_quiet_nan(u.f, &env->vec_status))) {
|
2012-05-30 08:23:26 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return float32_to_int32(u.f, &env->vec_status);
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline uint32_t efsctui(CPUPPCState *env, uint32_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_FloatU u;
|
|
|
|
|
|
|
|
u.l = val;
|
|
|
|
/* NaN are not treated the same way IEEE 754 does */
|
softfloat: Implement run-time-configurable meaning of signaling NaN bit
This patch modifies SoftFloat library so that it can be configured in
run-time in relation to the meaning of signaling NaN bit, while, at the
same time, strictly preserving its behavior on all existing platforms.
Background:
In floating-point calculations, there is a need for denoting undefined or
unrepresentable values. This is achieved by defining certain floating-point
numerical values to be NaNs (which stands for "not a number"). For additional
reasons, virtually all modern floating-point unit implementations use two
kinds of NaNs: quiet and signaling. The binary representations of these two
kinds of NaNs, as a rule, differ only in one bit (that bit is, traditionally,
the first bit of mantissa).
Up to 2008, standards for floating-point did not specify all details about
binary representation of NaNs. More specifically, the meaning of the bit
that is used for distinguishing between signaling and quiet NaNs was not
strictly prescribed. (IEEE 754-2008 was the first floating-point standard
that defined that meaning clearly, see [1], p. 35) As a result, different
platforms took different approaches, and that presented considerable
challenge for multi-platform emulators like QEMU.
Mips platform represents the most complex case among QEMU-supported
platforms regarding signaling NaN bit. Up to the Release 6 of Mips
architecture, "1" in signaling NaN bit denoted signaling NaN, which is
opposite to IEEE 754-2008 standard. From Release 6 on, Mips architecture
adopted IEEE standard prescription, and "0" denotes signaling NaN. On top of
that, Mips architecture for SIMD (also known as MSA, or vector instructions)
also specifies signaling bit in accordance to IEEE standard. MSA unit can be
implemented with both pre-Release 6 and Release 6 main processor units.
QEMU uses SoftFloat library to implement various floating-point-related
instructions on all platforms. The current QEMU implementation allows for
defining meaning of signaling NaN bit during build time, and is implemented
via preprocessor macro called SNAN_BIT_IS_ONE.
On the other hand, the change in this patch enables SoftFloat library to be
configured in run-time. This configuration is meant to occur during CPU
initialization, at the moment when it is definitely known what desired
behavior for particular CPU (or any additional FPUs) is.
The change is implemented so that it is consistent with existing
implementation of similar cases. This means that structure float_status is
used for passing the information about desired signaling NaN bit on each
invocation of SoftFloat functions. The additional field in float_status is
called snan_bit_is_one, which supersedes macro SNAN_BIT_IS_ONE.
IMPORTANT:
This change is not meant to create any change in emulator behavior or
functionality on any platform. It just provides the means for SoftFloat
library to be used in a more flexible way - in other words, it will just
prepare SoftFloat library for usage related to Mips platform and its
specifics regarding signaling bit meaning, which is done in some of
subsequent patches from this series.
Further break down of changes:
1) Added field snan_bit_is_one to the structure float_status, and
correspondent setter function set_snan_bit_is_one().
2) Constants <float16|float32|float64|floatx80|float128>_default_nan
(used both internally and externally) converted to functions
<float16|float32|float64|floatx80|float128>_default_nan(float_status*).
This is necessary since they are dependent on signaling bit meaning.
At the same time, for the sake of code cleanup and simplicity, constants
<floatx80|float128>_default_nan_<low|high> (used only internally within
SoftFloat library) are removed, as not needed.
3) Added a float_status* argument to SoftFloat library functions
XXX_is_quiet_nan(XXX a_), XXX_is_signaling_nan(XXX a_),
XXX_maybe_silence_nan(XXX a_). This argument must be present in
order to enable correct invocation of new version of functions
XXX_default_nan(). (XXX is <float16|float32|float64|floatx80|float128>
here)
4) Updated code for all platforms to reflect changes in SoftFloat library.
This change is twofolds: it includes modifications of SoftFloat library
functions invocations, and an addition of invocation of function
set_snan_bit_is_one() during CPU initialization, with arguments that
are appropriate for each particular platform. It was established that
all platforms zero their main CPU data structures, so snan_bit_is_one(0)
in appropriate places is not added, as it is not needed.
[1] "IEEE Standard for Floating-Point Arithmetic",
IEEE Computer Society, August 29, 2008.
Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
Signed-off-by: Maciej W. Rozycki <macro@codesourcery.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Tested-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
Reviewed-by: Leon Alrae <leon.alrae@imgtec.com>
Tested-by: Leon Alrae <leon.alrae@imgtec.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
[leon.alrae@imgtec.com:
* cherry-picked 2 chunks from patch #2 to fix compilation warnings]
Signed-off-by: Leon Alrae <leon.alrae@imgtec.com>
2016-06-10 12:57:28 +03:00
|
|
|
if (unlikely(float32_is_quiet_nan(u.f, &env->vec_status))) {
|
2012-05-30 08:23:26 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return float32_to_uint32(u.f, &env->vec_status);
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline uint32_t efsctsiz(CPUPPCState *env, uint32_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_FloatU u;
|
|
|
|
|
|
|
|
u.l = val;
|
|
|
|
/* NaN are not treated the same way IEEE 754 does */
|
softfloat: Implement run-time-configurable meaning of signaling NaN bit
This patch modifies SoftFloat library so that it can be configured in
run-time in relation to the meaning of signaling NaN bit, while, at the
same time, strictly preserving its behavior on all existing platforms.
Background:
In floating-point calculations, there is a need for denoting undefined or
unrepresentable values. This is achieved by defining certain floating-point
numerical values to be NaNs (which stands for "not a number"). For additional
reasons, virtually all modern floating-point unit implementations use two
kinds of NaNs: quiet and signaling. The binary representations of these two
kinds of NaNs, as a rule, differ only in one bit (that bit is, traditionally,
the first bit of mantissa).
Up to 2008, standards for floating-point did not specify all details about
binary representation of NaNs. More specifically, the meaning of the bit
that is used for distinguishing between signaling and quiet NaNs was not
strictly prescribed. (IEEE 754-2008 was the first floating-point standard
that defined that meaning clearly, see [1], p. 35) As a result, different
platforms took different approaches, and that presented considerable
challenge for multi-platform emulators like QEMU.
Mips platform represents the most complex case among QEMU-supported
platforms regarding signaling NaN bit. Up to the Release 6 of Mips
architecture, "1" in signaling NaN bit denoted signaling NaN, which is
opposite to IEEE 754-2008 standard. From Release 6 on, Mips architecture
adopted IEEE standard prescription, and "0" denotes signaling NaN. On top of
that, Mips architecture for SIMD (also known as MSA, or vector instructions)
also specifies signaling bit in accordance to IEEE standard. MSA unit can be
implemented with both pre-Release 6 and Release 6 main processor units.
QEMU uses SoftFloat library to implement various floating-point-related
instructions on all platforms. The current QEMU implementation allows for
defining meaning of signaling NaN bit during build time, and is implemented
via preprocessor macro called SNAN_BIT_IS_ONE.
On the other hand, the change in this patch enables SoftFloat library to be
configured in run-time. This configuration is meant to occur during CPU
initialization, at the moment when it is definitely known what desired
behavior for particular CPU (or any additional FPUs) is.
The change is implemented so that it is consistent with existing
implementation of similar cases. This means that structure float_status is
used for passing the information about desired signaling NaN bit on each
invocation of SoftFloat functions. The additional field in float_status is
called snan_bit_is_one, which supersedes macro SNAN_BIT_IS_ONE.
IMPORTANT:
This change is not meant to create any change in emulator behavior or
functionality on any platform. It just provides the means for SoftFloat
library to be used in a more flexible way - in other words, it will just
prepare SoftFloat library for usage related to Mips platform and its
specifics regarding signaling bit meaning, which is done in some of
subsequent patches from this series.
Further break down of changes:
1) Added field snan_bit_is_one to the structure float_status, and
correspondent setter function set_snan_bit_is_one().
2) Constants <float16|float32|float64|floatx80|float128>_default_nan
(used both internally and externally) converted to functions
<float16|float32|float64|floatx80|float128>_default_nan(float_status*).
This is necessary since they are dependent on signaling bit meaning.
At the same time, for the sake of code cleanup and simplicity, constants
<floatx80|float128>_default_nan_<low|high> (used only internally within
SoftFloat library) are removed, as not needed.
3) Added a float_status* argument to SoftFloat library functions
XXX_is_quiet_nan(XXX a_), XXX_is_signaling_nan(XXX a_),
XXX_maybe_silence_nan(XXX a_). This argument must be present in
order to enable correct invocation of new version of functions
XXX_default_nan(). (XXX is <float16|float32|float64|floatx80|float128>
here)
4) Updated code for all platforms to reflect changes in SoftFloat library.
This change is twofolds: it includes modifications of SoftFloat library
functions invocations, and an addition of invocation of function
set_snan_bit_is_one() during CPU initialization, with arguments that
are appropriate for each particular platform. It was established that
all platforms zero their main CPU data structures, so snan_bit_is_one(0)
in appropriate places is not added, as it is not needed.
[1] "IEEE Standard for Floating-Point Arithmetic",
IEEE Computer Society, August 29, 2008.
Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
Signed-off-by: Maciej W. Rozycki <macro@codesourcery.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Tested-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
Reviewed-by: Leon Alrae <leon.alrae@imgtec.com>
Tested-by: Leon Alrae <leon.alrae@imgtec.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
[leon.alrae@imgtec.com:
* cherry-picked 2 chunks from patch #2 to fix compilation warnings]
Signed-off-by: Leon Alrae <leon.alrae@imgtec.com>
2016-06-10 12:57:28 +03:00
|
|
|
if (unlikely(float32_is_quiet_nan(u.f, &env->vec_status))) {
|
2012-05-30 08:23:26 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return float32_to_int32_round_to_zero(u.f, &env->vec_status);
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline uint32_t efsctuiz(CPUPPCState *env, uint32_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_FloatU u;
|
|
|
|
|
|
|
|
u.l = val;
|
|
|
|
/* NaN are not treated the same way IEEE 754 does */
|
softfloat: Implement run-time-configurable meaning of signaling NaN bit
This patch modifies SoftFloat library so that it can be configured in
run-time in relation to the meaning of signaling NaN bit, while, at the
same time, strictly preserving its behavior on all existing platforms.
Background:
In floating-point calculations, there is a need for denoting undefined or
unrepresentable values. This is achieved by defining certain floating-point
numerical values to be NaNs (which stands for "not a number"). For additional
reasons, virtually all modern floating-point unit implementations use two
kinds of NaNs: quiet and signaling. The binary representations of these two
kinds of NaNs, as a rule, differ only in one bit (that bit is, traditionally,
the first bit of mantissa).
Up to 2008, standards for floating-point did not specify all details about
binary representation of NaNs. More specifically, the meaning of the bit
that is used for distinguishing between signaling and quiet NaNs was not
strictly prescribed. (IEEE 754-2008 was the first floating-point standard
that defined that meaning clearly, see [1], p. 35) As a result, different
platforms took different approaches, and that presented considerable
challenge for multi-platform emulators like QEMU.
Mips platform represents the most complex case among QEMU-supported
platforms regarding signaling NaN bit. Up to the Release 6 of Mips
architecture, "1" in signaling NaN bit denoted signaling NaN, which is
opposite to IEEE 754-2008 standard. From Release 6 on, Mips architecture
adopted IEEE standard prescription, and "0" denotes signaling NaN. On top of
that, Mips architecture for SIMD (also known as MSA, or vector instructions)
also specifies signaling bit in accordance to IEEE standard. MSA unit can be
implemented with both pre-Release 6 and Release 6 main processor units.
QEMU uses SoftFloat library to implement various floating-point-related
instructions on all platforms. The current QEMU implementation allows for
defining meaning of signaling NaN bit during build time, and is implemented
via preprocessor macro called SNAN_BIT_IS_ONE.
On the other hand, the change in this patch enables SoftFloat library to be
configured in run-time. This configuration is meant to occur during CPU
initialization, at the moment when it is definitely known what desired
behavior for particular CPU (or any additional FPUs) is.
The change is implemented so that it is consistent with existing
implementation of similar cases. This means that structure float_status is
used for passing the information about desired signaling NaN bit on each
invocation of SoftFloat functions. The additional field in float_status is
called snan_bit_is_one, which supersedes macro SNAN_BIT_IS_ONE.
IMPORTANT:
This change is not meant to create any change in emulator behavior or
functionality on any platform. It just provides the means for SoftFloat
library to be used in a more flexible way - in other words, it will just
prepare SoftFloat library for usage related to Mips platform and its
specifics regarding signaling bit meaning, which is done in some of
subsequent patches from this series.
Further break down of changes:
1) Added field snan_bit_is_one to the structure float_status, and
correspondent setter function set_snan_bit_is_one().
2) Constants <float16|float32|float64|floatx80|float128>_default_nan
(used both internally and externally) converted to functions
<float16|float32|float64|floatx80|float128>_default_nan(float_status*).
This is necessary since they are dependent on signaling bit meaning.
At the same time, for the sake of code cleanup and simplicity, constants
<floatx80|float128>_default_nan_<low|high> (used only internally within
SoftFloat library) are removed, as not needed.
3) Added a float_status* argument to SoftFloat library functions
XXX_is_quiet_nan(XXX a_), XXX_is_signaling_nan(XXX a_),
XXX_maybe_silence_nan(XXX a_). This argument must be present in
order to enable correct invocation of new version of functions
XXX_default_nan(). (XXX is <float16|float32|float64|floatx80|float128>
here)
4) Updated code for all platforms to reflect changes in SoftFloat library.
This change is twofolds: it includes modifications of SoftFloat library
functions invocations, and an addition of invocation of function
set_snan_bit_is_one() during CPU initialization, with arguments that
are appropriate for each particular platform. It was established that
all platforms zero their main CPU data structures, so snan_bit_is_one(0)
in appropriate places is not added, as it is not needed.
[1] "IEEE Standard for Floating-Point Arithmetic",
IEEE Computer Society, August 29, 2008.
Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
Signed-off-by: Maciej W. Rozycki <macro@codesourcery.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Tested-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
Reviewed-by: Leon Alrae <leon.alrae@imgtec.com>
Tested-by: Leon Alrae <leon.alrae@imgtec.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
[leon.alrae@imgtec.com:
* cherry-picked 2 chunks from patch #2 to fix compilation warnings]
Signed-off-by: Leon Alrae <leon.alrae@imgtec.com>
2016-06-10 12:57:28 +03:00
|
|
|
if (unlikely(float32_is_quiet_nan(u.f, &env->vec_status))) {
|
2012-05-30 08:23:26 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return float32_to_uint32_round_to_zero(u.f, &env->vec_status);
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline uint32_t efscfsf(CPUPPCState *env, uint32_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_FloatU u;
|
|
|
|
float32 tmp;
|
|
|
|
|
|
|
|
u.f = int32_to_float32(val, &env->vec_status);
|
|
|
|
tmp = int64_to_float32(1ULL << 32, &env->vec_status);
|
|
|
|
u.f = float32_div(u.f, tmp, &env->vec_status);
|
|
|
|
|
|
|
|
return u.l;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline uint32_t efscfuf(CPUPPCState *env, uint32_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_FloatU u;
|
|
|
|
float32 tmp;
|
|
|
|
|
|
|
|
u.f = uint32_to_float32(val, &env->vec_status);
|
|
|
|
tmp = uint64_to_float32(1ULL << 32, &env->vec_status);
|
|
|
|
u.f = float32_div(u.f, tmp, &env->vec_status);
|
|
|
|
|
|
|
|
return u.l;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline uint32_t efsctsf(CPUPPCState *env, uint32_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_FloatU u;
|
|
|
|
float32 tmp;
|
|
|
|
|
|
|
|
u.l = val;
|
|
|
|
/* NaN are not treated the same way IEEE 754 does */
|
softfloat: Implement run-time-configurable meaning of signaling NaN bit
This patch modifies SoftFloat library so that it can be configured in
run-time in relation to the meaning of signaling NaN bit, while, at the
same time, strictly preserving its behavior on all existing platforms.
Background:
In floating-point calculations, there is a need for denoting undefined or
unrepresentable values. This is achieved by defining certain floating-point
numerical values to be NaNs (which stands for "not a number"). For additional
reasons, virtually all modern floating-point unit implementations use two
kinds of NaNs: quiet and signaling. The binary representations of these two
kinds of NaNs, as a rule, differ only in one bit (that bit is, traditionally,
the first bit of mantissa).
Up to 2008, standards for floating-point did not specify all details about
binary representation of NaNs. More specifically, the meaning of the bit
that is used for distinguishing between signaling and quiet NaNs was not
strictly prescribed. (IEEE 754-2008 was the first floating-point standard
that defined that meaning clearly, see [1], p. 35) As a result, different
platforms took different approaches, and that presented considerable
challenge for multi-platform emulators like QEMU.
Mips platform represents the most complex case among QEMU-supported
platforms regarding signaling NaN bit. Up to the Release 6 of Mips
architecture, "1" in signaling NaN bit denoted signaling NaN, which is
opposite to IEEE 754-2008 standard. From Release 6 on, Mips architecture
adopted IEEE standard prescription, and "0" denotes signaling NaN. On top of
that, Mips architecture for SIMD (also known as MSA, or vector instructions)
also specifies signaling bit in accordance to IEEE standard. MSA unit can be
implemented with both pre-Release 6 and Release 6 main processor units.
QEMU uses SoftFloat library to implement various floating-point-related
instructions on all platforms. The current QEMU implementation allows for
defining meaning of signaling NaN bit during build time, and is implemented
via preprocessor macro called SNAN_BIT_IS_ONE.
On the other hand, the change in this patch enables SoftFloat library to be
configured in run-time. This configuration is meant to occur during CPU
initialization, at the moment when it is definitely known what desired
behavior for particular CPU (or any additional FPUs) is.
The change is implemented so that it is consistent with existing
implementation of similar cases. This means that structure float_status is
used for passing the information about desired signaling NaN bit on each
invocation of SoftFloat functions. The additional field in float_status is
called snan_bit_is_one, which supersedes macro SNAN_BIT_IS_ONE.
IMPORTANT:
This change is not meant to create any change in emulator behavior or
functionality on any platform. It just provides the means for SoftFloat
library to be used in a more flexible way - in other words, it will just
prepare SoftFloat library for usage related to Mips platform and its
specifics regarding signaling bit meaning, which is done in some of
subsequent patches from this series.
Further break down of changes:
1) Added field snan_bit_is_one to the structure float_status, and
correspondent setter function set_snan_bit_is_one().
2) Constants <float16|float32|float64|floatx80|float128>_default_nan
(used both internally and externally) converted to functions
<float16|float32|float64|floatx80|float128>_default_nan(float_status*).
This is necessary since they are dependent on signaling bit meaning.
At the same time, for the sake of code cleanup and simplicity, constants
<floatx80|float128>_default_nan_<low|high> (used only internally within
SoftFloat library) are removed, as not needed.
3) Added a float_status* argument to SoftFloat library functions
XXX_is_quiet_nan(XXX a_), XXX_is_signaling_nan(XXX a_),
XXX_maybe_silence_nan(XXX a_). This argument must be present in
order to enable correct invocation of new version of functions
XXX_default_nan(). (XXX is <float16|float32|float64|floatx80|float128>
here)
4) Updated code for all platforms to reflect changes in SoftFloat library.
This change is twofolds: it includes modifications of SoftFloat library
functions invocations, and an addition of invocation of function
set_snan_bit_is_one() during CPU initialization, with arguments that
are appropriate for each particular platform. It was established that
all platforms zero their main CPU data structures, so snan_bit_is_one(0)
in appropriate places is not added, as it is not needed.
[1] "IEEE Standard for Floating-Point Arithmetic",
IEEE Computer Society, August 29, 2008.
Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
Signed-off-by: Maciej W. Rozycki <macro@codesourcery.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Tested-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
Reviewed-by: Leon Alrae <leon.alrae@imgtec.com>
Tested-by: Leon Alrae <leon.alrae@imgtec.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
[leon.alrae@imgtec.com:
* cherry-picked 2 chunks from patch #2 to fix compilation warnings]
Signed-off-by: Leon Alrae <leon.alrae@imgtec.com>
2016-06-10 12:57:28 +03:00
|
|
|
if (unlikely(float32_is_quiet_nan(u.f, &env->vec_status))) {
|
2012-05-30 08:23:26 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
tmp = uint64_to_float32(1ULL << 32, &env->vec_status);
|
|
|
|
u.f = float32_mul(u.f, tmp, &env->vec_status);
|
|
|
|
|
|
|
|
return float32_to_int32(u.f, &env->vec_status);
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline uint32_t efsctuf(CPUPPCState *env, uint32_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_FloatU u;
|
|
|
|
float32 tmp;
|
|
|
|
|
|
|
|
u.l = val;
|
|
|
|
/* NaN are not treated the same way IEEE 754 does */
|
softfloat: Implement run-time-configurable meaning of signaling NaN bit
This patch modifies SoftFloat library so that it can be configured in
run-time in relation to the meaning of signaling NaN bit, while, at the
same time, strictly preserving its behavior on all existing platforms.
Background:
In floating-point calculations, there is a need for denoting undefined or
unrepresentable values. This is achieved by defining certain floating-point
numerical values to be NaNs (which stands for "not a number"). For additional
reasons, virtually all modern floating-point unit implementations use two
kinds of NaNs: quiet and signaling. The binary representations of these two
kinds of NaNs, as a rule, differ only in one bit (that bit is, traditionally,
the first bit of mantissa).
Up to 2008, standards for floating-point did not specify all details about
binary representation of NaNs. More specifically, the meaning of the bit
that is used for distinguishing between signaling and quiet NaNs was not
strictly prescribed. (IEEE 754-2008 was the first floating-point standard
that defined that meaning clearly, see [1], p. 35) As a result, different
platforms took different approaches, and that presented considerable
challenge for multi-platform emulators like QEMU.
Mips platform represents the most complex case among QEMU-supported
platforms regarding signaling NaN bit. Up to the Release 6 of Mips
architecture, "1" in signaling NaN bit denoted signaling NaN, which is
opposite to IEEE 754-2008 standard. From Release 6 on, Mips architecture
adopted IEEE standard prescription, and "0" denotes signaling NaN. On top of
that, Mips architecture for SIMD (also known as MSA, or vector instructions)
also specifies signaling bit in accordance to IEEE standard. MSA unit can be
implemented with both pre-Release 6 and Release 6 main processor units.
QEMU uses SoftFloat library to implement various floating-point-related
instructions on all platforms. The current QEMU implementation allows for
defining meaning of signaling NaN bit during build time, and is implemented
via preprocessor macro called SNAN_BIT_IS_ONE.
On the other hand, the change in this patch enables SoftFloat library to be
configured in run-time. This configuration is meant to occur during CPU
initialization, at the moment when it is definitely known what desired
behavior for particular CPU (or any additional FPUs) is.
The change is implemented so that it is consistent with existing
implementation of similar cases. This means that structure float_status is
used for passing the information about desired signaling NaN bit on each
invocation of SoftFloat functions. The additional field in float_status is
called snan_bit_is_one, which supersedes macro SNAN_BIT_IS_ONE.
IMPORTANT:
This change is not meant to create any change in emulator behavior or
functionality on any platform. It just provides the means for SoftFloat
library to be used in a more flexible way - in other words, it will just
prepare SoftFloat library for usage related to Mips platform and its
specifics regarding signaling bit meaning, which is done in some of
subsequent patches from this series.
Further break down of changes:
1) Added field snan_bit_is_one to the structure float_status, and
correspondent setter function set_snan_bit_is_one().
2) Constants <float16|float32|float64|floatx80|float128>_default_nan
(used both internally and externally) converted to functions
<float16|float32|float64|floatx80|float128>_default_nan(float_status*).
This is necessary since they are dependent on signaling bit meaning.
At the same time, for the sake of code cleanup and simplicity, constants
<floatx80|float128>_default_nan_<low|high> (used only internally within
SoftFloat library) are removed, as not needed.
3) Added a float_status* argument to SoftFloat library functions
XXX_is_quiet_nan(XXX a_), XXX_is_signaling_nan(XXX a_),
XXX_maybe_silence_nan(XXX a_). This argument must be present in
order to enable correct invocation of new version of functions
XXX_default_nan(). (XXX is <float16|float32|float64|floatx80|float128>
here)
4) Updated code for all platforms to reflect changes in SoftFloat library.
This change is twofolds: it includes modifications of SoftFloat library
functions invocations, and an addition of invocation of function
set_snan_bit_is_one() during CPU initialization, with arguments that
are appropriate for each particular platform. It was established that
all platforms zero their main CPU data structures, so snan_bit_is_one(0)
in appropriate places is not added, as it is not needed.
[1] "IEEE Standard for Floating-Point Arithmetic",
IEEE Computer Society, August 29, 2008.
Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
Signed-off-by: Maciej W. Rozycki <macro@codesourcery.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Tested-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
Reviewed-by: Leon Alrae <leon.alrae@imgtec.com>
Tested-by: Leon Alrae <leon.alrae@imgtec.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
[leon.alrae@imgtec.com:
* cherry-picked 2 chunks from patch #2 to fix compilation warnings]
Signed-off-by: Leon Alrae <leon.alrae@imgtec.com>
2016-06-10 12:57:28 +03:00
|
|
|
if (unlikely(float32_is_quiet_nan(u.f, &env->vec_status))) {
|
2012-05-30 08:23:26 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
tmp = uint64_to_float32(1ULL << 32, &env->vec_status);
|
|
|
|
u.f = float32_mul(u.f, tmp, &env->vec_status);
|
|
|
|
|
|
|
|
return float32_to_uint32(u.f, &env->vec_status);
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
#define HELPER_SPE_SINGLE_CONV(name) \
|
|
|
|
uint32_t helper_e##name(CPUPPCState *env, uint32_t val) \
|
|
|
|
{ \
|
|
|
|
return e##name(env, val); \
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
/* efscfsi */
|
|
|
|
HELPER_SPE_SINGLE_CONV(fscfsi);
|
|
|
|
/* efscfui */
|
|
|
|
HELPER_SPE_SINGLE_CONV(fscfui);
|
|
|
|
/* efscfuf */
|
|
|
|
HELPER_SPE_SINGLE_CONV(fscfuf);
|
|
|
|
/* efscfsf */
|
|
|
|
HELPER_SPE_SINGLE_CONV(fscfsf);
|
|
|
|
/* efsctsi */
|
|
|
|
HELPER_SPE_SINGLE_CONV(fsctsi);
|
|
|
|
/* efsctui */
|
|
|
|
HELPER_SPE_SINGLE_CONV(fsctui);
|
|
|
|
/* efsctsiz */
|
|
|
|
HELPER_SPE_SINGLE_CONV(fsctsiz);
|
|
|
|
/* efsctuiz */
|
|
|
|
HELPER_SPE_SINGLE_CONV(fsctuiz);
|
|
|
|
/* efsctsf */
|
|
|
|
HELPER_SPE_SINGLE_CONV(fsctsf);
|
|
|
|
/* efsctuf */
|
|
|
|
HELPER_SPE_SINGLE_CONV(fsctuf);
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
#define HELPER_SPE_VECTOR_CONV(name) \
|
|
|
|
uint64_t helper_ev##name(CPUPPCState *env, uint64_t val) \
|
|
|
|
{ \
|
|
|
|
return ((uint64_t)e##name(env, val >> 32) << 32) | \
|
|
|
|
(uint64_t)e##name(env, val); \
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
/* evfscfsi */
|
|
|
|
HELPER_SPE_VECTOR_CONV(fscfsi);
|
|
|
|
/* evfscfui */
|
|
|
|
HELPER_SPE_VECTOR_CONV(fscfui);
|
|
|
|
/* evfscfuf */
|
|
|
|
HELPER_SPE_VECTOR_CONV(fscfuf);
|
|
|
|
/* evfscfsf */
|
|
|
|
HELPER_SPE_VECTOR_CONV(fscfsf);
|
|
|
|
/* evfsctsi */
|
|
|
|
HELPER_SPE_VECTOR_CONV(fsctsi);
|
|
|
|
/* evfsctui */
|
|
|
|
HELPER_SPE_VECTOR_CONV(fsctui);
|
|
|
|
/* evfsctsiz */
|
|
|
|
HELPER_SPE_VECTOR_CONV(fsctsiz);
|
|
|
|
/* evfsctuiz */
|
|
|
|
HELPER_SPE_VECTOR_CONV(fsctuiz);
|
|
|
|
/* evfsctsf */
|
|
|
|
HELPER_SPE_VECTOR_CONV(fsctsf);
|
|
|
|
/* evfsctuf */
|
|
|
|
HELPER_SPE_VECTOR_CONV(fsctuf);
|
|
|
|
|
|
|
|
/* Single-precision floating-point arithmetic */
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline uint32_t efsadd(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_FloatU u1, u2;
|
|
|
|
|
|
|
|
u1.l = op1;
|
|
|
|
u2.l = op2;
|
|
|
|
u1.f = float32_add(u1.f, u2.f, &env->vec_status);
|
|
|
|
return u1.l;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline uint32_t efssub(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_FloatU u1, u2;
|
|
|
|
|
|
|
|
u1.l = op1;
|
|
|
|
u2.l = op2;
|
|
|
|
u1.f = float32_sub(u1.f, u2.f, &env->vec_status);
|
|
|
|
return u1.l;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline uint32_t efsmul(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_FloatU u1, u2;
|
|
|
|
|
|
|
|
u1.l = op1;
|
|
|
|
u2.l = op2;
|
|
|
|
u1.f = float32_mul(u1.f, u2.f, &env->vec_status);
|
|
|
|
return u1.l;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline uint32_t efsdiv(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_FloatU u1, u2;
|
|
|
|
|
|
|
|
u1.l = op1;
|
|
|
|
u2.l = op2;
|
|
|
|
u1.f = float32_div(u1.f, u2.f, &env->vec_status);
|
|
|
|
return u1.l;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
#define HELPER_SPE_SINGLE_ARITH(name) \
|
|
|
|
uint32_t helper_e##name(CPUPPCState *env, uint32_t op1, uint32_t op2) \
|
|
|
|
{ \
|
|
|
|
return e##name(env, op1, op2); \
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
/* efsadd */
|
|
|
|
HELPER_SPE_SINGLE_ARITH(fsadd);
|
|
|
|
/* efssub */
|
|
|
|
HELPER_SPE_SINGLE_ARITH(fssub);
|
|
|
|
/* efsmul */
|
|
|
|
HELPER_SPE_SINGLE_ARITH(fsmul);
|
|
|
|
/* efsdiv */
|
|
|
|
HELPER_SPE_SINGLE_ARITH(fsdiv);
|
|
|
|
|
|
|
|
#define HELPER_SPE_VECTOR_ARITH(name) \
|
2012-05-30 08:23:27 +04:00
|
|
|
uint64_t helper_ev##name(CPUPPCState *env, uint64_t op1, uint64_t op2) \
|
2012-05-30 08:23:26 +04:00
|
|
|
{ \
|
2012-05-30 08:23:27 +04:00
|
|
|
return ((uint64_t)e##name(env, op1 >> 32, op2 >> 32) << 32) | \
|
|
|
|
(uint64_t)e##name(env, op1, op2); \
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
/* evfsadd */
|
|
|
|
HELPER_SPE_VECTOR_ARITH(fsadd);
|
|
|
|
/* evfssub */
|
|
|
|
HELPER_SPE_VECTOR_ARITH(fssub);
|
|
|
|
/* evfsmul */
|
|
|
|
HELPER_SPE_VECTOR_ARITH(fsmul);
|
|
|
|
/* evfsdiv */
|
|
|
|
HELPER_SPE_VECTOR_ARITH(fsdiv);
|
|
|
|
|
|
|
|
/* Single-precision floating-point comparisons */
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline uint32_t efscmplt(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_FloatU u1, u2;
|
|
|
|
|
|
|
|
u1.l = op1;
|
|
|
|
u2.l = op2;
|
|
|
|
return float32_lt(u1.f, u2.f, &env->vec_status) ? 4 : 0;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline uint32_t efscmpgt(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_FloatU u1, u2;
|
|
|
|
|
|
|
|
u1.l = op1;
|
|
|
|
u2.l = op2;
|
|
|
|
return float32_le(u1.f, u2.f, &env->vec_status) ? 0 : 4;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline uint32_t efscmpeq(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_FloatU u1, u2;
|
|
|
|
|
|
|
|
u1.l = op1;
|
|
|
|
u2.l = op2;
|
|
|
|
return float32_eq(u1.f, u2.f, &env->vec_status) ? 4 : 0;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline uint32_t efststlt(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
/* XXX: TODO: ignore special values (NaN, infinites, ...) */
|
2012-05-30 08:23:27 +04:00
|
|
|
return efscmplt(env, op1, op2);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline uint32_t efststgt(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
/* XXX: TODO: ignore special values (NaN, infinites, ...) */
|
2012-05-30 08:23:27 +04:00
|
|
|
return efscmpgt(env, op1, op2);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
static inline uint32_t efststeq(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
/* XXX: TODO: ignore special values (NaN, infinites, ...) */
|
2012-05-30 08:23:27 +04:00
|
|
|
return efscmpeq(env, op1, op2);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
#define HELPER_SINGLE_SPE_CMP(name) \
|
|
|
|
uint32_t helper_e##name(CPUPPCState *env, uint32_t op1, uint32_t op2) \
|
|
|
|
{ \
|
target-ppc/fpu_helper: Fix efscmp* instructions handling
With specification at hand from the reference manual from Freescale
http://cache.nxp.com/files/32bit/doc/ref_manual/SPEPEM.pdf , I have found a fix
to efscmp* instructions handling in QEMU.
efscmp* instructions in QEMU set crD (Condition Register nibble) values as
(0b0100 << 2) = 0b10000 (consider the HELPER_SINGLE_SPE_CMP macro which left
shifts the value returned by efscmp* handler by 2 bits). A value of 0b10000 is
not correct according the to the reference manual.
The reference manual expects efscmp* instructions to return a value of 0bx1xx.
Please find attached a patch which disables left shifting in
HELPER_SINGLE_SPE_CMP macro. This macro is used by efscmp* and efstst*
instructions only. efstst* instruction handlers, in turn, call efscmp* handlers
too.
*Explanation:*
Traditionally, each crD (condition register nibble) consist of 4 bits, which is
set by comparisons as follows:
crD = W X Y Z
where
W = Less than
X = Greater than
Y = Equal to
However, efscmp* instructions being a special case return a binary result.
(efscmpeq will set the crD = 0bx1xx iff when op1 == op2 and 0bx0xx otherwise;
i.e. there is no notion of different crD values based on Less than, Greater
than and Equal to).
This effectively means that crD will store a "Greater than" comparison result
iff efscmp* instruction comparison is TRUE. Compiler exploits this feature by
checking for "Branch if Less than or Equal to" (ble instruction) OR "Branch if
Greater than" (bgt instruction) for Branch if FALSE OR Branch if TRUE
respectively after an efscmp* instruction. This can be seen in a assembly code
snippet below:
27 if (__real__ x != 3.0f || __imag__ x != 4.0f)
10000498: lwz r10,8(r31)
1000049c: lis r9,16448
100004a0: efscmpeq cr7,r10,r9
100004a4: ble- cr7,0x100004b8 <bar+60> //jump to abort() call
100004a8: lwz r10,12(r31)
100004ac: lis r9,16512
100004b0: efscmpeq cr7,r10,r9
100004b4: bgt- cr7,0x100004bc <bar+64> //skip abort() call
28 abort ();
100004b8: bl 0x10000808 <abort>
Signed-off-by: Talha Imran <talha_imran@mentor.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-05-19 15:11:35 +03:00
|
|
|
return e##name(env, op1, op2); \
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
/* efststlt */
|
|
|
|
HELPER_SINGLE_SPE_CMP(fststlt);
|
|
|
|
/* efststgt */
|
|
|
|
HELPER_SINGLE_SPE_CMP(fststgt);
|
|
|
|
/* efststeq */
|
|
|
|
HELPER_SINGLE_SPE_CMP(fststeq);
|
|
|
|
/* efscmplt */
|
|
|
|
HELPER_SINGLE_SPE_CMP(fscmplt);
|
|
|
|
/* efscmpgt */
|
|
|
|
HELPER_SINGLE_SPE_CMP(fscmpgt);
|
|
|
|
/* efscmpeq */
|
|
|
|
HELPER_SINGLE_SPE_CMP(fscmpeq);
|
|
|
|
|
|
|
|
static inline uint32_t evcmp_merge(int t0, int t1)
|
|
|
|
{
|
|
|
|
return (t0 << 3) | (t1 << 2) | ((t0 | t1) << 1) | (t0 & t1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define HELPER_VECTOR_SPE_CMP(name) \
|
2012-05-30 08:23:27 +04:00
|
|
|
uint32_t helper_ev##name(CPUPPCState *env, uint64_t op1, uint64_t op2) \
|
2012-05-30 08:23:26 +04:00
|
|
|
{ \
|
2012-05-30 08:23:27 +04:00
|
|
|
return evcmp_merge(e##name(env, op1 >> 32, op2 >> 32), \
|
|
|
|
e##name(env, op1, op2)); \
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
/* evfststlt */
|
|
|
|
HELPER_VECTOR_SPE_CMP(fststlt);
|
|
|
|
/* evfststgt */
|
|
|
|
HELPER_VECTOR_SPE_CMP(fststgt);
|
|
|
|
/* evfststeq */
|
|
|
|
HELPER_VECTOR_SPE_CMP(fststeq);
|
|
|
|
/* evfscmplt */
|
|
|
|
HELPER_VECTOR_SPE_CMP(fscmplt);
|
|
|
|
/* evfscmpgt */
|
|
|
|
HELPER_VECTOR_SPE_CMP(fscmpgt);
|
|
|
|
/* evfscmpeq */
|
|
|
|
HELPER_VECTOR_SPE_CMP(fscmpeq);
|
|
|
|
|
|
|
|
/* Double-precision floating-point conversion */
|
2012-05-30 08:23:27 +04:00
|
|
|
uint64_t helper_efdcfsi(CPUPPCState *env, uint32_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u;
|
|
|
|
|
|
|
|
u.d = int32_to_float64(val, &env->vec_status);
|
|
|
|
|
|
|
|
return u.ll;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint64_t helper_efdcfsid(CPUPPCState *env, uint64_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u;
|
|
|
|
|
|
|
|
u.d = int64_to_float64(val, &env->vec_status);
|
|
|
|
|
|
|
|
return u.ll;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint64_t helper_efdcfui(CPUPPCState *env, uint32_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u;
|
|
|
|
|
|
|
|
u.d = uint32_to_float64(val, &env->vec_status);
|
|
|
|
|
|
|
|
return u.ll;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint64_t helper_efdcfuid(CPUPPCState *env, uint64_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u;
|
|
|
|
|
|
|
|
u.d = uint64_to_float64(val, &env->vec_status);
|
|
|
|
|
|
|
|
return u.ll;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint32_t helper_efdctsi(CPUPPCState *env, uint64_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u;
|
|
|
|
|
|
|
|
u.ll = val;
|
|
|
|
/* NaN are not treated the same way IEEE 754 does */
|
|
|
|
if (unlikely(float64_is_any_nan(u.d))) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return float64_to_int32(u.d, &env->vec_status);
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint32_t helper_efdctui(CPUPPCState *env, uint64_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u;
|
|
|
|
|
|
|
|
u.ll = val;
|
|
|
|
/* NaN are not treated the same way IEEE 754 does */
|
|
|
|
if (unlikely(float64_is_any_nan(u.d))) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return float64_to_uint32(u.d, &env->vec_status);
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint32_t helper_efdctsiz(CPUPPCState *env, uint64_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u;
|
|
|
|
|
|
|
|
u.ll = val;
|
|
|
|
/* NaN are not treated the same way IEEE 754 does */
|
|
|
|
if (unlikely(float64_is_any_nan(u.d))) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return float64_to_int32_round_to_zero(u.d, &env->vec_status);
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint64_t helper_efdctsidz(CPUPPCState *env, uint64_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u;
|
|
|
|
|
|
|
|
u.ll = val;
|
|
|
|
/* NaN are not treated the same way IEEE 754 does */
|
|
|
|
if (unlikely(float64_is_any_nan(u.d))) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return float64_to_int64_round_to_zero(u.d, &env->vec_status);
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint32_t helper_efdctuiz(CPUPPCState *env, uint64_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u;
|
|
|
|
|
|
|
|
u.ll = val;
|
|
|
|
/* NaN are not treated the same way IEEE 754 does */
|
|
|
|
if (unlikely(float64_is_any_nan(u.d))) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return float64_to_uint32_round_to_zero(u.d, &env->vec_status);
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint64_t helper_efdctuidz(CPUPPCState *env, uint64_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u;
|
|
|
|
|
|
|
|
u.ll = val;
|
|
|
|
/* NaN are not treated the same way IEEE 754 does */
|
|
|
|
if (unlikely(float64_is_any_nan(u.d))) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return float64_to_uint64_round_to_zero(u.d, &env->vec_status);
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint64_t helper_efdcfsf(CPUPPCState *env, uint32_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u;
|
|
|
|
float64 tmp;
|
|
|
|
|
|
|
|
u.d = int32_to_float64(val, &env->vec_status);
|
|
|
|
tmp = int64_to_float64(1ULL << 32, &env->vec_status);
|
|
|
|
u.d = float64_div(u.d, tmp, &env->vec_status);
|
|
|
|
|
|
|
|
return u.ll;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint64_t helper_efdcfuf(CPUPPCState *env, uint32_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u;
|
|
|
|
float64 tmp;
|
|
|
|
|
|
|
|
u.d = uint32_to_float64(val, &env->vec_status);
|
|
|
|
tmp = int64_to_float64(1ULL << 32, &env->vec_status);
|
|
|
|
u.d = float64_div(u.d, tmp, &env->vec_status);
|
|
|
|
|
|
|
|
return u.ll;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint32_t helper_efdctsf(CPUPPCState *env, uint64_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u;
|
|
|
|
float64 tmp;
|
|
|
|
|
|
|
|
u.ll = val;
|
|
|
|
/* NaN are not treated the same way IEEE 754 does */
|
|
|
|
if (unlikely(float64_is_any_nan(u.d))) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
tmp = uint64_to_float64(1ULL << 32, &env->vec_status);
|
|
|
|
u.d = float64_mul(u.d, tmp, &env->vec_status);
|
|
|
|
|
|
|
|
return float64_to_int32(u.d, &env->vec_status);
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint32_t helper_efdctuf(CPUPPCState *env, uint64_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u;
|
|
|
|
float64 tmp;
|
|
|
|
|
|
|
|
u.ll = val;
|
|
|
|
/* NaN are not treated the same way IEEE 754 does */
|
|
|
|
if (unlikely(float64_is_any_nan(u.d))) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
tmp = uint64_to_float64(1ULL << 32, &env->vec_status);
|
|
|
|
u.d = float64_mul(u.d, tmp, &env->vec_status);
|
|
|
|
|
|
|
|
return float64_to_uint32(u.d, &env->vec_status);
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint32_t helper_efscfd(CPUPPCState *env, uint64_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u1;
|
|
|
|
CPU_FloatU u2;
|
|
|
|
|
|
|
|
u1.ll = val;
|
|
|
|
u2.f = float64_to_float32(u1.d, &env->vec_status);
|
|
|
|
|
|
|
|
return u2.l;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint64_t helper_efdcfs(CPUPPCState *env, uint32_t val)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u2;
|
|
|
|
CPU_FloatU u1;
|
|
|
|
|
|
|
|
u1.l = val;
|
|
|
|
u2.d = float32_to_float64(u1.f, &env->vec_status);
|
|
|
|
|
|
|
|
return u2.ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Double precision fixed-point arithmetic */
|
2012-05-30 08:23:27 +04:00
|
|
|
uint64_t helper_efdadd(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u1, u2;
|
|
|
|
|
|
|
|
u1.ll = op1;
|
|
|
|
u2.ll = op2;
|
|
|
|
u1.d = float64_add(u1.d, u2.d, &env->vec_status);
|
|
|
|
return u1.ll;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint64_t helper_efdsub(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u1, u2;
|
|
|
|
|
|
|
|
u1.ll = op1;
|
|
|
|
u2.ll = op2;
|
|
|
|
u1.d = float64_sub(u1.d, u2.d, &env->vec_status);
|
|
|
|
return u1.ll;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint64_t helper_efdmul(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u1, u2;
|
|
|
|
|
|
|
|
u1.ll = op1;
|
|
|
|
u2.ll = op2;
|
|
|
|
u1.d = float64_mul(u1.d, u2.d, &env->vec_status);
|
|
|
|
return u1.ll;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint64_t helper_efddiv(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u1, u2;
|
|
|
|
|
|
|
|
u1.ll = op1;
|
|
|
|
u2.ll = op2;
|
|
|
|
u1.d = float64_div(u1.d, u2.d, &env->vec_status);
|
|
|
|
return u1.ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Double precision floating point helpers */
|
2012-05-30 08:23:27 +04:00
|
|
|
uint32_t helper_efdtstlt(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u1, u2;
|
|
|
|
|
|
|
|
u1.ll = op1;
|
|
|
|
u2.ll = op2;
|
|
|
|
return float64_lt(u1.d, u2.d, &env->vec_status) ? 4 : 0;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint32_t helper_efdtstgt(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u1, u2;
|
|
|
|
|
|
|
|
u1.ll = op1;
|
|
|
|
u2.ll = op2;
|
|
|
|
return float64_le(u1.d, u2.d, &env->vec_status) ? 0 : 4;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint32_t helper_efdtsteq(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
CPU_DoubleU u1, u2;
|
|
|
|
|
|
|
|
u1.ll = op1;
|
|
|
|
u2.ll = op2;
|
|
|
|
return float64_eq_quiet(u1.d, u2.d, &env->vec_status) ? 4 : 0;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint32_t helper_efdcmplt(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
/* XXX: TODO: test special values (NaN, infinites, ...) */
|
2012-05-30 08:23:27 +04:00
|
|
|
return helper_efdtstlt(env, op1, op2);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint32_t helper_efdcmpgt(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
/* XXX: TODO: test special values (NaN, infinites, ...) */
|
2012-05-30 08:23:27 +04:00
|
|
|
return helper_efdtstgt(env, op1, op2);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:27 +04:00
|
|
|
uint32_t helper_efdcmpeq(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 08:23:26 +04:00
|
|
|
{
|
|
|
|
/* XXX: TODO: test special values (NaN, infinites, ...) */
|
2012-05-30 08:23:27 +04:00
|
|
|
return helper_efdtsteq(env, op1, op2);
|
2012-05-30 08:23:26 +04:00
|
|
|
}
|
2014-01-03 02:21:20 +04:00
|
|
|
|
|
|
|
#define float64_to_float64(x, env) x
|
2014-01-03 02:21:21 +04:00
|
|
|
|
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
2020-10-09 09:44:37 +03:00
|
|
|
* VSX_ADD_SUB - VSX floating point add/subtract
|
2014-01-03 02:21:21 +04:00
|
|
|
* name - instruction mnemonic
|
|
|
|
* op - operation (add or sub)
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 01:03:59 +04:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2022-05-17 19:15:22 +03:00
|
|
|
* sfifprf - set FI and FPRF
|
2014-01-03 02:21:21 +04:00
|
|
|
*/
|
2022-05-17 19:15:22 +03:00
|
|
|
#define VSX_ADD_SUB(name, op, nels, tp, fld, sfifprf, r2sp) \
|
2019-06-16 15:37:41 +03:00
|
|
|
void helper_##name(CPUPPCState *env, ppc_vsr_t *xt, \
|
|
|
|
ppc_vsr_t *xa, ppc_vsr_t *xb) \
|
2014-01-03 02:21:21 +04:00
|
|
|
{ \
|
2022-02-09 11:08:56 +03:00
|
|
|
ppc_vsr_t t = { }; \
|
2014-01-03 02:21:21 +04:00
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
|
|
|
float_status tstat = env->fp_status; \
|
|
|
|
set_float_exception_flags(0, &tstat); \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.fld = tp##_##op(xa->fld, xb->fld, &tstat); \
|
2014-01-03 02:21:21 +04:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
|
|
|
|
\
|
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
|
2021-12-17 19:57:14 +03:00
|
|
|
float_invalid_op_addsub(env, tstat.float_exception_flags, \
|
2022-05-17 19:15:22 +03:00
|
|
|
sfifprf, GETPC()); \
|
2014-01-03 02:21:21 +04:00
|
|
|
} \
|
|
|
|
\
|
2014-01-15 18:10:33 +04:00
|
|
|
if (r2sp) { \
|
2021-12-17 19:57:15 +03:00
|
|
|
t.fld = do_frsp(env, t.fld, GETPC()); \
|
2014-01-15 18:10:33 +04:00
|
|
|
} \
|
|
|
|
\
|
2022-05-17 19:15:22 +03:00
|
|
|
if (sfifprf) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_float64(env, t.fld); \
|
2014-01-03 02:21:21 +04:00
|
|
|
} \
|
|
|
|
} \
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t; \
|
2022-05-17 19:15:22 +03:00
|
|
|
do_float_check_status(env, sfifprf, GETPC()); \
|
2014-01-03 02:21:21 +04:00
|
|
|
}
|
|
|
|
|
2014-04-01 01:03:59 +04:00
|
|
|
VSX_ADD_SUB(xsadddp, add, 1, float64, VsrD(0), 1, 0)
|
|
|
|
VSX_ADD_SUB(xsaddsp, add, 1, float64, VsrD(0), 1, 1)
|
|
|
|
VSX_ADD_SUB(xvadddp, add, 2, float64, VsrD(i), 0, 0)
|
|
|
|
VSX_ADD_SUB(xvaddsp, add, 4, float32, VsrW(i), 0, 0)
|
|
|
|
VSX_ADD_SUB(xssubdp, sub, 1, float64, VsrD(0), 1, 0)
|
|
|
|
VSX_ADD_SUB(xssubsp, sub, 1, float64, VsrD(0), 1, 1)
|
|
|
|
VSX_ADD_SUB(xvsubdp, sub, 2, float64, VsrD(i), 0, 0)
|
|
|
|
VSX_ADD_SUB(xvsubsp, sub, 4, float32, VsrW(i), 0, 0)
|
2014-01-03 02:21:22 +04:00
|
|
|
|
2019-06-16 15:37:46 +03:00
|
|
|
void helper_xsaddqp(CPUPPCState *env, uint32_t opcode,
|
|
|
|
ppc_vsr_t *xt, ppc_vsr_t *xa, ppc_vsr_t *xb)
|
2017-01-09 17:26:13 +03:00
|
|
|
{
|
2019-06-16 15:37:37 +03:00
|
|
|
ppc_vsr_t t = *xt;
|
2017-01-09 17:26:13 +03:00
|
|
|
float_status tstat;
|
|
|
|
|
|
|
|
helper_reset_fpstatus(env);
|
|
|
|
|
2017-02-10 10:23:08 +03:00
|
|
|
tstat = env->fp_status;
|
2017-01-09 17:26:13 +03:00
|
|
|
if (unlikely(Rc(opcode) != 0)) {
|
2017-02-10 10:23:08 +03:00
|
|
|
tstat.float_rounding_mode = float_round_to_odd;
|
2017-01-09 17:26:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
set_float_exception_flags(0, &tstat);
|
2019-06-16 15:37:37 +03:00
|
|
|
t.f128 = float128_add(xa->f128, xb->f128, &tstat);
|
2017-01-09 17:26:13 +03:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags;
|
|
|
|
|
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid)) {
|
2021-12-17 19:57:14 +03:00
|
|
|
float_invalid_op_addsub(env, tstat.float_exception_flags, 1, GETPC());
|
2017-01-09 17:26:13 +03:00
|
|
|
}
|
|
|
|
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_float128(env, t.f128);
|
2017-01-09 17:26:13 +03:00
|
|
|
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t;
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, true, GETPC());
|
2017-01-09 17:26:13 +03:00
|
|
|
}
|
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
* VSX_MUL - VSX floating point multiply
|
2014-01-03 02:21:22 +04:00
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 01:03:59 +04:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2022-05-17 19:15:22 +03:00
|
|
|
* sfifprf - set FI and FPRF
|
2014-01-03 02:21:22 +04:00
|
|
|
*/
|
2022-05-17 19:15:22 +03:00
|
|
|
#define VSX_MUL(op, nels, tp, fld, sfifprf, r2sp) \
|
2019-06-16 15:37:41 +03:00
|
|
|
void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
|
|
|
|
ppc_vsr_t *xa, ppc_vsr_t *xb) \
|
2014-01-03 02:21:22 +04:00
|
|
|
{ \
|
2022-02-09 11:08:56 +03:00
|
|
|
ppc_vsr_t t = { }; \
|
2014-01-03 02:21:22 +04:00
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
|
|
|
float_status tstat = env->fp_status; \
|
|
|
|
set_float_exception_flags(0, &tstat); \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.fld = tp##_mul(xa->fld, xb->fld, &tstat); \
|
2014-01-03 02:21:22 +04:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
|
|
|
|
\
|
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
|
2021-12-17 19:57:14 +03:00
|
|
|
float_invalid_op_mul(env, tstat.float_exception_flags, \
|
2022-05-17 19:15:22 +03:00
|
|
|
sfifprf, GETPC()); \
|
2014-01-03 02:21:22 +04:00
|
|
|
} \
|
|
|
|
\
|
2014-01-15 18:10:34 +04:00
|
|
|
if (r2sp) { \
|
2021-12-17 19:57:15 +03:00
|
|
|
t.fld = do_frsp(env, t.fld, GETPC()); \
|
2014-01-15 18:10:34 +04:00
|
|
|
} \
|
|
|
|
\
|
2022-05-17 19:15:22 +03:00
|
|
|
if (sfifprf) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_float64(env, t.fld); \
|
2014-01-03 02:21:22 +04:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t; \
|
2022-05-17 19:15:22 +03:00
|
|
|
do_float_check_status(env, sfifprf, GETPC()); \
|
2014-01-03 02:21:22 +04:00
|
|
|
}
|
|
|
|
|
2014-04-01 01:03:59 +04:00
|
|
|
VSX_MUL(xsmuldp, 1, float64, VsrD(0), 1, 0)
|
|
|
|
VSX_MUL(xsmulsp, 1, float64, VsrD(0), 1, 1)
|
|
|
|
VSX_MUL(xvmuldp, 2, float64, VsrD(i), 0, 0)
|
|
|
|
VSX_MUL(xvmulsp, 4, float32, VsrW(i), 0, 0)
|
2014-01-03 02:21:23 +04:00
|
|
|
|
2019-06-16 15:37:46 +03:00
|
|
|
void helper_xsmulqp(CPUPPCState *env, uint32_t opcode,
|
|
|
|
ppc_vsr_t *xt, ppc_vsr_t *xa, ppc_vsr_t *xb)
|
2017-01-12 19:24:08 +03:00
|
|
|
{
|
2019-06-16 15:37:37 +03:00
|
|
|
ppc_vsr_t t = *xt;
|
2017-02-10 10:23:08 +03:00
|
|
|
float_status tstat;
|
2017-01-12 19:24:08 +03:00
|
|
|
|
2017-02-10 10:23:08 +03:00
|
|
|
helper_reset_fpstatus(env);
|
|
|
|
tstat = env->fp_status;
|
2017-01-12 19:24:08 +03:00
|
|
|
if (unlikely(Rc(opcode) != 0)) {
|
2017-02-10 10:23:08 +03:00
|
|
|
tstat.float_rounding_mode = float_round_to_odd;
|
2017-01-12 19:24:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
set_float_exception_flags(0, &tstat);
|
2019-06-16 15:37:37 +03:00
|
|
|
t.f128 = float128_mul(xa->f128, xb->f128, &tstat);
|
2017-01-12 19:24:08 +03:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags;
|
|
|
|
|
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid)) {
|
2021-12-17 19:57:14 +03:00
|
|
|
float_invalid_op_mul(env, tstat.float_exception_flags, 1, GETPC());
|
2017-01-12 19:24:08 +03:00
|
|
|
}
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_float128(env, t.f128);
|
2017-01-12 19:24:08 +03:00
|
|
|
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t;
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, true, GETPC());
|
2017-01-12 19:24:08 +03:00
|
|
|
}
|
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
* VSX_DIV - VSX floating point divide
|
2014-01-03 02:21:23 +04:00
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 01:03:59 +04:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2022-05-17 19:15:22 +03:00
|
|
|
* sfifprf - set FI and FPRF
|
2014-01-03 02:21:23 +04:00
|
|
|
*/
|
2022-05-17 19:15:22 +03:00
|
|
|
#define VSX_DIV(op, nels, tp, fld, sfifprf, r2sp) \
|
2019-06-16 15:37:41 +03:00
|
|
|
void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
|
|
|
|
ppc_vsr_t *xa, ppc_vsr_t *xb) \
|
2014-01-03 02:21:23 +04:00
|
|
|
{ \
|
2022-02-09 11:08:56 +03:00
|
|
|
ppc_vsr_t t = { }; \
|
2014-01-03 02:21:23 +04:00
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
|
|
|
float_status tstat = env->fp_status; \
|
|
|
|
set_float_exception_flags(0, &tstat); \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.fld = tp##_div(xa->fld, xb->fld, &tstat); \
|
2014-01-03 02:21:23 +04:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
|
|
|
|
\
|
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
|
2021-12-17 19:57:14 +03:00
|
|
|
float_invalid_op_div(env, tstat.float_exception_flags, \
|
2022-05-17 19:15:22 +03:00
|
|
|
sfifprf, GETPC()); \
|
2018-07-03 18:17:27 +03:00
|
|
|
} \
|
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_divbyzero)) { \
|
|
|
|
float_zero_divide_excp(env, GETPC()); \
|
2014-01-03 02:21:23 +04:00
|
|
|
} \
|
|
|
|
\
|
2014-01-15 18:10:35 +04:00
|
|
|
if (r2sp) { \
|
2021-12-17 19:57:15 +03:00
|
|
|
t.fld = do_frsp(env, t.fld, GETPC()); \
|
2014-01-15 18:10:35 +04:00
|
|
|
} \
|
|
|
|
\
|
2022-05-17 19:15:22 +03:00
|
|
|
if (sfifprf) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_float64(env, t.fld); \
|
2014-01-03 02:21:23 +04:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t; \
|
2022-05-17 19:15:22 +03:00
|
|
|
do_float_check_status(env, sfifprf, GETPC()); \
|
2014-01-03 02:21:23 +04:00
|
|
|
}
|
|
|
|
|
2014-04-01 01:03:59 +04:00
|
|
|
VSX_DIV(xsdivdp, 1, float64, VsrD(0), 1, 0)
|
|
|
|
VSX_DIV(xsdivsp, 1, float64, VsrD(0), 1, 1)
|
|
|
|
VSX_DIV(xvdivdp, 2, float64, VsrD(i), 0, 0)
|
|
|
|
VSX_DIV(xvdivsp, 4, float32, VsrW(i), 0, 0)
|
2014-01-03 02:21:24 +04:00
|
|
|
|
2019-06-16 15:37:46 +03:00
|
|
|
void helper_xsdivqp(CPUPPCState *env, uint32_t opcode,
|
|
|
|
ppc_vsr_t *xt, ppc_vsr_t *xa, ppc_vsr_t *xb)
|
2017-01-12 19:24:07 +03:00
|
|
|
{
|
2019-06-16 15:37:37 +03:00
|
|
|
ppc_vsr_t t = *xt;
|
2017-02-10 10:23:08 +03:00
|
|
|
float_status tstat;
|
2017-01-12 19:24:07 +03:00
|
|
|
|
2017-02-10 10:23:08 +03:00
|
|
|
helper_reset_fpstatus(env);
|
|
|
|
tstat = env->fp_status;
|
2017-01-12 19:24:07 +03:00
|
|
|
if (unlikely(Rc(opcode) != 0)) {
|
2017-02-10 10:23:08 +03:00
|
|
|
tstat.float_rounding_mode = float_round_to_odd;
|
2017-01-12 19:24:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
set_float_exception_flags(0, &tstat);
|
2019-06-16 15:37:37 +03:00
|
|
|
t.f128 = float128_div(xa->f128, xb->f128, &tstat);
|
2017-01-12 19:24:07 +03:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags;
|
|
|
|
|
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid)) {
|
2021-12-17 19:57:14 +03:00
|
|
|
float_invalid_op_div(env, tstat.float_exception_flags, 1, GETPC());
|
2017-01-12 19:24:07 +03:00
|
|
|
}
|
2018-07-03 18:17:27 +03:00
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_divbyzero)) {
|
|
|
|
float_zero_divide_excp(env, GETPC());
|
|
|
|
}
|
2017-01-12 19:24:07 +03:00
|
|
|
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_float128(env, t.f128);
|
|
|
|
*xt = t;
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, true, GETPC());
|
2017-01-12 19:24:07 +03:00
|
|
|
}
|
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
* VSX_RE - VSX floating point reciprocal estimate
|
2014-01-03 02:21:24 +04:00
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 01:03:59 +04:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2022-05-17 19:15:22 +03:00
|
|
|
* sfifprf - set FI and FPRF
|
2014-01-03 02:21:24 +04:00
|
|
|
*/
|
2022-05-17 19:15:22 +03:00
|
|
|
#define VSX_RE(op, nels, tp, fld, sfifprf, r2sp) \
|
2019-06-16 15:37:43 +03:00
|
|
|
void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
|
2014-01-03 02:21:24 +04:00
|
|
|
{ \
|
2022-02-09 11:08:56 +03:00
|
|
|
ppc_vsr_t t = { }; \
|
2014-01-03 02:21:24 +04:00
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
if (unlikely(tp##_is_signaling_nan(xb->fld, &env->fp_status))) { \
|
2018-10-12 02:41:53 +03:00
|
|
|
float_invalid_op_vxsnan(env, GETPC()); \
|
2014-01-03 02:21:24 +04:00
|
|
|
} \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.fld = tp##_div(tp##_one, xb->fld, &env->fp_status); \
|
2014-01-15 18:10:36 +04:00
|
|
|
\
|
|
|
|
if (r2sp) { \
|
2021-12-17 19:57:15 +03:00
|
|
|
t.fld = do_frsp(env, t.fld, GETPC()); \
|
2014-01-15 18:10:36 +04:00
|
|
|
} \
|
|
|
|
\
|
2022-05-17 19:15:22 +03:00
|
|
|
if (sfifprf) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_float64(env, t.fld); \
|
2014-01-03 02:21:24 +04:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t; \
|
2022-05-17 19:15:22 +03:00
|
|
|
do_float_check_status(env, sfifprf, GETPC()); \
|
2014-01-03 02:21:24 +04:00
|
|
|
}
|
|
|
|
|
2014-04-01 01:03:59 +04:00
|
|
|
VSX_RE(xsredp, 1, float64, VsrD(0), 1, 0)
|
|
|
|
VSX_RE(xsresp, 1, float64, VsrD(0), 1, 1)
|
|
|
|
VSX_RE(xvredp, 2, float64, VsrD(i), 0, 0)
|
|
|
|
VSX_RE(xvresp, 4, float32, VsrW(i), 0, 0)
|
2014-01-03 02:21:25 +04:00
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
* VSX_SQRT - VSX floating point square root
|
2014-01-03 02:21:25 +04:00
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 01:03:59 +04:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2022-05-17 19:15:22 +03:00
|
|
|
* sfifprf - set FI and FPRF
|
2014-01-03 02:21:25 +04:00
|
|
|
*/
|
2022-05-17 19:15:22 +03:00
|
|
|
#define VSX_SQRT(op, nels, tp, fld, sfifprf, r2sp) \
|
2019-06-16 15:37:43 +03:00
|
|
|
void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
|
2014-01-03 02:21:25 +04:00
|
|
|
{ \
|
2022-02-09 11:08:56 +03:00
|
|
|
ppc_vsr_t t = { }; \
|
2014-01-03 02:21:25 +04:00
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
|
|
|
float_status tstat = env->fp_status; \
|
|
|
|
set_float_exception_flags(0, &tstat); \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.fld = tp##_sqrt(xb->fld, &tstat); \
|
2014-01-03 02:21:25 +04:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
|
|
|
|
\
|
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
|
2021-12-17 19:57:15 +03:00
|
|
|
float_invalid_op_sqrt(env, tstat.float_exception_flags, \
|
2022-05-17 19:15:22 +03:00
|
|
|
sfifprf, GETPC()); \
|
2014-01-03 02:21:25 +04:00
|
|
|
} \
|
|
|
|
\
|
2014-01-15 18:10:37 +04:00
|
|
|
if (r2sp) { \
|
2021-12-17 19:57:15 +03:00
|
|
|
t.fld = do_frsp(env, t.fld, GETPC()); \
|
2014-01-15 18:10:37 +04:00
|
|
|
} \
|
|
|
|
\
|
2022-05-17 19:15:22 +03:00
|
|
|
if (sfifprf) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_float64(env, t.fld); \
|
2014-01-03 02:21:25 +04:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t; \
|
2022-05-17 19:15:22 +03:00
|
|
|
do_float_check_status(env, sfifprf, GETPC()); \
|
2014-01-03 02:21:25 +04:00
|
|
|
}
|
|
|
|
|
2014-04-01 01:03:59 +04:00
|
|
|
VSX_SQRT(xssqrtdp, 1, float64, VsrD(0), 1, 0)
|
|
|
|
VSX_SQRT(xssqrtsp, 1, float64, VsrD(0), 1, 1)
|
|
|
|
VSX_SQRT(xvsqrtdp, 2, float64, VsrD(i), 0, 0)
|
|
|
|
VSX_SQRT(xvsqrtsp, 4, float32, VsrW(i), 0, 0)
|
2014-01-03 02:21:26 +04:00
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
*VSX_RSQRTE - VSX floating point reciprocal square root estimate
|
2014-01-03 02:21:26 +04:00
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 01:03:59 +04:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2022-05-17 19:15:22 +03:00
|
|
|
* sfifprf - set FI and FPRF
|
2014-01-03 02:21:26 +04:00
|
|
|
*/
|
2022-05-17 19:15:22 +03:00
|
|
|
#define VSX_RSQRTE(op, nels, tp, fld, sfifprf, r2sp) \
|
2019-06-16 15:37:43 +03:00
|
|
|
void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
|
2014-01-03 02:21:26 +04:00
|
|
|
{ \
|
2022-02-09 11:08:56 +03:00
|
|
|
ppc_vsr_t t = { }; \
|
2014-01-03 02:21:26 +04:00
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
|
|
|
float_status tstat = env->fp_status; \
|
|
|
|
set_float_exception_flags(0, &tstat); \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.fld = tp##_sqrt(xb->fld, &tstat); \
|
|
|
|
t.fld = tp##_div(tp##_one, t.fld, &tstat); \
|
2014-01-03 02:21:26 +04:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
|
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
|
2021-12-17 19:57:15 +03:00
|
|
|
float_invalid_op_sqrt(env, tstat.float_exception_flags, \
|
2022-05-17 19:15:22 +03:00
|
|
|
sfifprf, GETPC()); \
|
2014-01-03 02:21:26 +04:00
|
|
|
} \
|
2014-01-15 18:10:38 +04:00
|
|
|
if (r2sp) { \
|
2021-12-17 19:57:15 +03:00
|
|
|
t.fld = do_frsp(env, t.fld, GETPC()); \
|
2014-01-15 18:10:38 +04:00
|
|
|
} \
|
|
|
|
\
|
2022-05-17 19:15:22 +03:00
|
|
|
if (sfifprf) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_float64(env, t.fld); \
|
2014-01-03 02:21:26 +04:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t; \
|
2022-05-17 19:15:22 +03:00
|
|
|
do_float_check_status(env, sfifprf, GETPC()); \
|
2014-01-03 02:21:26 +04:00
|
|
|
}
|
|
|
|
|
2014-04-01 01:03:59 +04:00
|
|
|
VSX_RSQRTE(xsrsqrtedp, 1, float64, VsrD(0), 1, 0)
|
|
|
|
VSX_RSQRTE(xsrsqrtesp, 1, float64, VsrD(0), 1, 1)
|
|
|
|
VSX_RSQRTE(xvrsqrtedp, 2, float64, VsrD(i), 0, 0)
|
|
|
|
VSX_RSQRTE(xvrsqrtesp, 4, float32, VsrW(i), 0, 0)
|
2014-01-03 02:21:27 +04:00
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
* VSX_TDIV - VSX floating point test for divide
|
2014-01-03 02:21:27 +04:00
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 01:03:59 +04:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2014-01-03 02:21:27 +04:00
|
|
|
* emin - minimum unbiased exponent
|
|
|
|
* emax - maximum unbiased exponent
|
|
|
|
* nbits - number of fraction bits
|
|
|
|
*/
|
|
|
|
#define VSX_TDIV(op, nels, tp, fld, emin, emax, nbits) \
|
2019-06-16 15:37:44 +03:00
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode, \
|
|
|
|
ppc_vsr_t *xa, ppc_vsr_t *xb) \
|
2014-01-03 02:21:27 +04:00
|
|
|
{ \
|
|
|
|
int i; \
|
|
|
|
int fe_flag = 0; \
|
|
|
|
int fg_flag = 0; \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
if (unlikely(tp##_is_infinity(xa->fld) || \
|
|
|
|
tp##_is_infinity(xb->fld) || \
|
|
|
|
tp##_is_zero(xb->fld))) { \
|
2014-01-03 02:21:27 +04:00
|
|
|
fe_flag = 1; \
|
|
|
|
fg_flag = 1; \
|
|
|
|
} else { \
|
2019-06-16 15:37:37 +03:00
|
|
|
int e_a = ppc_##tp##_get_unbiased_exp(xa->fld); \
|
|
|
|
int e_b = ppc_##tp##_get_unbiased_exp(xb->fld); \
|
2014-01-03 02:21:27 +04:00
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
if (unlikely(tp##_is_any_nan(xa->fld) || \
|
|
|
|
tp##_is_any_nan(xb->fld))) { \
|
2014-01-03 02:21:27 +04:00
|
|
|
fe_flag = 1; \
|
2019-03-21 09:01:06 +03:00
|
|
|
} else if ((e_b <= emin) || (e_b >= (emax - 2))) { \
|
2014-01-03 02:21:27 +04:00
|
|
|
fe_flag = 1; \
|
2019-06-16 15:37:37 +03:00
|
|
|
} else if (!tp##_is_zero(xa->fld) && \
|
2014-01-03 02:21:27 +04:00
|
|
|
(((e_a - e_b) >= emax) || \
|
2019-03-21 09:01:06 +03:00
|
|
|
((e_a - e_b) <= (emin + 1)) || \
|
|
|
|
(e_a <= (emin + nbits)))) { \
|
2014-01-03 02:21:27 +04:00
|
|
|
fe_flag = 1; \
|
|
|
|
} \
|
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
if (unlikely(tp##_is_zero_or_denormal(xb->fld))) { \
|
2019-03-21 09:01:06 +03:00
|
|
|
/* \
|
|
|
|
* XB is not zero because of the above check and so \
|
|
|
|
* must be denormalized. \
|
|
|
|
*/ \
|
2014-01-03 02:21:27 +04:00
|
|
|
fg_flag = 1; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
env->crf[BF(opcode)] = 0x8 | (fg_flag ? 4 : 0) | (fe_flag ? 2 : 0); \
|
|
|
|
}
|
|
|
|
|
2014-04-01 01:03:59 +04:00
|
|
|
VSX_TDIV(xstdivdp, 1, float64, VsrD(0), -1022, 1023, 52)
|
|
|
|
VSX_TDIV(xvtdivdp, 2, float64, VsrD(i), -1022, 1023, 52)
|
|
|
|
VSX_TDIV(xvtdivsp, 4, float32, VsrW(i), -126, 127, 23)
|
2014-01-03 02:21:28 +04:00
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
* VSX_TSQRT - VSX floating point test for square root
|
2014-01-03 02:21:28 +04:00
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 01:03:59 +04:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2014-01-03 02:21:28 +04:00
|
|
|
* emin - minimum unbiased exponent
|
|
|
|
* emax - maximum unbiased exponent
|
|
|
|
* nbits - number of fraction bits
|
|
|
|
*/
|
|
|
|
#define VSX_TSQRT(op, nels, tp, fld, emin, nbits) \
|
2019-06-16 15:37:45 +03:00
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode, ppc_vsr_t *xb) \
|
2014-01-03 02:21:28 +04:00
|
|
|
{ \
|
|
|
|
int i; \
|
|
|
|
int fe_flag = 0; \
|
|
|
|
int fg_flag = 0; \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
if (unlikely(tp##_is_infinity(xb->fld) || \
|
|
|
|
tp##_is_zero(xb->fld))) { \
|
2014-01-03 02:21:28 +04:00
|
|
|
fe_flag = 1; \
|
|
|
|
fg_flag = 1; \
|
|
|
|
} else { \
|
2019-06-16 15:37:37 +03:00
|
|
|
int e_b = ppc_##tp##_get_unbiased_exp(xb->fld); \
|
2014-01-03 02:21:28 +04:00
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
if (unlikely(tp##_is_any_nan(xb->fld))) { \
|
2014-01-03 02:21:28 +04:00
|
|
|
fe_flag = 1; \
|
2019-06-16 15:37:37 +03:00
|
|
|
} else if (unlikely(tp##_is_zero(xb->fld))) { \
|
2014-01-03 02:21:28 +04:00
|
|
|
fe_flag = 1; \
|
2019-06-16 15:37:37 +03:00
|
|
|
} else if (unlikely(tp##_is_neg(xb->fld))) { \
|
2014-01-03 02:21:28 +04:00
|
|
|
fe_flag = 1; \
|
2019-06-16 15:37:37 +03:00
|
|
|
} else if (!tp##_is_zero(xb->fld) && \
|
2019-03-21 09:01:06 +03:00
|
|
|
(e_b <= (emin + nbits))) { \
|
2014-01-03 02:21:28 +04:00
|
|
|
fe_flag = 1; \
|
|
|
|
} \
|
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
if (unlikely(tp##_is_zero_or_denormal(xb->fld))) { \
|
2019-03-21 09:01:06 +03:00
|
|
|
/* \
|
|
|
|
* XB is not zero because of the above check and \
|
|
|
|
* therefore must be denormalized. \
|
|
|
|
*/ \
|
2014-01-03 02:21:28 +04:00
|
|
|
fg_flag = 1; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
env->crf[BF(opcode)] = 0x8 | (fg_flag ? 4 : 0) | (fe_flag ? 2 : 0); \
|
|
|
|
}
|
|
|
|
|
2014-04-01 01:03:59 +04:00
|
|
|
VSX_TSQRT(xstsqrtdp, 1, float64, VsrD(0), -1022, 52)
|
|
|
|
VSX_TSQRT(xvtsqrtdp, 2, float64, VsrD(i), -1022, 52)
|
|
|
|
VSX_TSQRT(xvtsqrtsp, 4, float32, VsrW(i), -126, 23)
|
target-ppc: Add VSX ISA2.06 Multiply Add Instructions
This patch adds the VSX floating point multiply/add instructions
defined by V2.06 of the PowerPC ISA:
- xsmaddadp, xvmaddadp, xvmaddasp
- xsmaddmdp, xvmaddmdp, xvmaddmsp
- xsmsubadp, xvmsubadp, xvmsubasp
- xsmsubmdp, xvmsubmdp, xvmsubmsp
- xsnmaddadp, xvnmaddadp, xvnmaddasp
- xsnmaddmdp, xvnmaddmdp, xvnmaddmsp
- xsnmsubadp, xvnmsubadp, xvnmsubasp
- xsnmsubmdp, xvnmsubmdp, xvnmsubmsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:29 +04:00
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
* VSX_MADD - VSX floating point muliply/add variations
|
target-ppc: Add VSX ISA2.06 Multiply Add Instructions
This patch adds the VSX floating point multiply/add instructions
defined by V2.06 of the PowerPC ISA:
- xsmaddadp, xvmaddadp, xvmaddasp
- xsmaddmdp, xvmaddmdp, xvmaddmsp
- xsmsubadp, xvmsubadp, xvmsubasp
- xsmsubmdp, xvmsubmdp, xvmsubmsp
- xsnmaddadp, xvnmaddadp, xvnmaddasp
- xsnmaddmdp, xvnmaddmdp, xvnmaddmsp
- xsnmsubadp, xvnmsubadp, xvnmsubasp
- xsnmsubmdp, xvnmsubmdp, xvnmsubmsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:29 +04:00
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 01:03:59 +04:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
target-ppc: Add VSX ISA2.06 Multiply Add Instructions
This patch adds the VSX floating point multiply/add instructions
defined by V2.06 of the PowerPC ISA:
- xsmaddadp, xvmaddadp, xvmaddasp
- xsmaddmdp, xvmaddmdp, xvmaddmsp
- xsmsubadp, xvmsubadp, xvmsubasp
- xsmsubmdp, xvmsubmdp, xvmsubmsp
- xsnmaddadp, xvnmaddadp, xvnmaddasp
- xsnmaddmdp, xvnmaddmdp, xvnmaddmsp
- xsnmsubadp, xvnmsubadp, xvnmsubasp
- xsnmsubmdp, xvnmsubmdp, xvnmsubmsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:29 +04:00
|
|
|
* maddflgs - flags for the float*muladd routine that control the
|
|
|
|
* various forms (madd, msub, nmadd, nmsub)
|
2022-05-17 19:15:22 +03:00
|
|
|
* sfifprf - set FI and FPRF
|
target-ppc: Add VSX ISA2.06 Multiply Add Instructions
This patch adds the VSX floating point multiply/add instructions
defined by V2.06 of the PowerPC ISA:
- xsmaddadp, xvmaddadp, xvmaddasp
- xsmaddmdp, xvmaddmdp, xvmaddmsp
- xsmsubadp, xvmsubadp, xvmsubasp
- xsmsubmdp, xvmsubmdp, xvmsubmsp
- xsnmaddadp, xvnmaddadp, xvnmaddasp
- xsnmaddmdp, xvnmaddmdp, xvnmaddmsp
- xsnmsubadp, xvnmsubadp, xvnmsubasp
- xsnmsubmdp, xvnmsubmdp, xvnmsubmsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:29 +04:00
|
|
|
*/
|
2022-05-17 19:15:22 +03:00
|
|
|
#define VSX_MADD(op, nels, tp, fld, maddflgs, sfifprf) \
|
2019-06-16 15:37:41 +03:00
|
|
|
void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
|
2022-03-02 08:51:38 +03:00
|
|
|
ppc_vsr_t *s1, ppc_vsr_t *s2, ppc_vsr_t *s3) \
|
target-ppc: Add VSX ISA2.06 Multiply Add Instructions
This patch adds the VSX floating point multiply/add instructions
defined by V2.06 of the PowerPC ISA:
- xsmaddadp, xvmaddadp, xvmaddasp
- xsmaddmdp, xvmaddmdp, xvmaddmsp
- xsmsubadp, xvmsubadp, xvmsubasp
- xsmsubmdp, xvmsubmdp, xvmsubmsp
- xsnmaddadp, xvnmaddadp, xvnmaddasp
- xsnmaddmdp, xvnmaddmdp, xvnmaddmsp
- xsnmsubadp, xvnmsubadp, xvnmsubasp
- xsnmsubmdp, xvnmsubmdp, xvnmsubmsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:29 +04:00
|
|
|
{ \
|
2022-09-06 15:55:20 +03:00
|
|
|
ppc_vsr_t t = { }; \
|
target-ppc: Add VSX ISA2.06 Multiply Add Instructions
This patch adds the VSX floating point multiply/add instructions
defined by V2.06 of the PowerPC ISA:
- xsmaddadp, xvmaddadp, xvmaddasp
- xsmaddmdp, xvmaddmdp, xvmaddmsp
- xsmsubadp, xvmsubadp, xvmsubasp
- xsmsubmdp, xvmsubmdp, xvmsubmsp
- xsnmaddadp, xvnmaddadp, xvnmaddasp
- xsnmaddmdp, xvnmaddmdp, xvnmaddmsp
- xsnmsubadp, xvnmsubadp, xvnmsubasp
- xsnmsubmdp, xvnmsubmdp, xvnmsubmsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:29 +04:00
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
|
|
|
float_status tstat = env->fp_status; \
|
|
|
|
set_float_exception_flags(0, &tstat); \
|
2022-03-05 09:16:46 +03:00
|
|
|
t.fld = tp##_muladd(s1->fld, s3->fld, s2->fld, maddflgs, &tstat); \
|
target-ppc: Add VSX ISA2.06 Multiply Add Instructions
This patch adds the VSX floating point multiply/add instructions
defined by V2.06 of the PowerPC ISA:
- xsmaddadp, xvmaddadp, xvmaddasp
- xsmaddmdp, xvmaddmdp, xvmaddmsp
- xsmsubadp, xvmsubadp, xvmsubasp
- xsmsubmdp, xvmsubmdp, xvmsubmsp
- xsnmaddadp, xvnmaddadp, xvnmaddasp
- xsnmaddmdp, xvnmaddmdp, xvnmaddmsp
- xsnmsubadp, xvnmsubadp, xvnmsubasp
- xsnmsubmdp, xvnmsubmdp, xvnmsubmsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:29 +04:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
|
|
|
|
\
|
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
|
2021-12-17 19:57:15 +03:00
|
|
|
float_invalid_op_madd(env, tstat.float_exception_flags, \
|
2022-05-17 19:15:22 +03:00
|
|
|
sfifprf, GETPC()); \
|
target-ppc: Add VSX ISA2.06 Multiply Add Instructions
This patch adds the VSX floating point multiply/add instructions
defined by V2.06 of the PowerPC ISA:
- xsmaddadp, xvmaddadp, xvmaddasp
- xsmaddmdp, xvmaddmdp, xvmaddmsp
- xsmsubadp, xvmsubadp, xvmsubasp
- xsmsubmdp, xvmsubmdp, xvmsubmsp
- xsnmaddadp, xvnmaddadp, xvnmaddasp
- xsnmaddmdp, xvnmaddmdp, xvnmaddmsp
- xsnmsubadp, xvnmsubadp, xvnmsubasp
- xsnmsubmdp, xvnmsubmdp, xvnmsubmsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:29 +04:00
|
|
|
} \
|
2014-01-15 18:10:39 +04:00
|
|
|
\
|
2022-05-17 19:15:22 +03:00
|
|
|
if (sfifprf) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_float64(env, t.fld); \
|
target-ppc: Add VSX ISA2.06 Multiply Add Instructions
This patch adds the VSX floating point multiply/add instructions
defined by V2.06 of the PowerPC ISA:
- xsmaddadp, xvmaddadp, xvmaddasp
- xsmaddmdp, xvmaddmdp, xvmaddmsp
- xsmsubadp, xvmsubadp, xvmsubasp
- xsmsubmdp, xvmsubmdp, xvmsubmsp
- xsnmaddadp, xvnmaddadp, xvnmaddasp
- xsnmaddmdp, xvnmaddmdp, xvnmaddmsp
- xsnmsubadp, xvnmsubadp, xvnmsubasp
- xsnmsubmdp, xvnmsubmdp, xvnmsubmsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:29 +04:00
|
|
|
} \
|
|
|
|
} \
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t; \
|
2022-05-17 19:15:22 +03:00
|
|
|
do_float_check_status(env, sfifprf, GETPC()); \
|
target-ppc: Add VSX ISA2.06 Multiply Add Instructions
This patch adds the VSX floating point multiply/add instructions
defined by V2.06 of the PowerPC ISA:
- xsmaddadp, xvmaddadp, xvmaddasp
- xsmaddmdp, xvmaddmdp, xvmaddmsp
- xsmsubadp, xvmsubadp, xvmsubasp
- xsmsubmdp, xvmsubmdp, xvmsubmsp
- xsnmaddadp, xvnmaddadp, xvnmaddasp
- xsnmaddmdp, xvnmaddmdp, xvnmaddmsp
- xsnmsubadp, xvnmsubadp, xvnmsubasp
- xsnmsubmdp, xvnmsubmdp, xvnmsubmsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:29 +04:00
|
|
|
}
|
|
|
|
|
2022-03-05 09:16:46 +03:00
|
|
|
VSX_MADD(XSMADDDP, 1, float64, VsrD(0), MADD_FLGS, 1)
|
|
|
|
VSX_MADD(XSMSUBDP, 1, float64, VsrD(0), MSUB_FLGS, 1)
|
|
|
|
VSX_MADD(XSNMADDDP, 1, float64, VsrD(0), NMADD_FLGS, 1)
|
|
|
|
VSX_MADD(XSNMSUBDP, 1, float64, VsrD(0), NMSUB_FLGS, 1)
|
|
|
|
VSX_MADD(XSMADDSP, 1, float64r32, VsrD(0), MADD_FLGS, 1)
|
|
|
|
VSX_MADD(XSMSUBSP, 1, float64r32, VsrD(0), MSUB_FLGS, 1)
|
|
|
|
VSX_MADD(XSNMADDSP, 1, float64r32, VsrD(0), NMADD_FLGS, 1)
|
|
|
|
VSX_MADD(XSNMSUBSP, 1, float64r32, VsrD(0), NMSUB_FLGS, 1)
|
|
|
|
|
|
|
|
VSX_MADD(xvmadddp, 2, float64, VsrD(i), MADD_FLGS, 0)
|
|
|
|
VSX_MADD(xvmsubdp, 2, float64, VsrD(i), MSUB_FLGS, 0)
|
|
|
|
VSX_MADD(xvnmadddp, 2, float64, VsrD(i), NMADD_FLGS, 0)
|
|
|
|
VSX_MADD(xvnmsubdp, 2, float64, VsrD(i), NMSUB_FLGS, 0)
|
|
|
|
|
|
|
|
VSX_MADD(xvmaddsp, 4, float32, VsrW(i), MADD_FLGS, 0)
|
|
|
|
VSX_MADD(xvmsubsp, 4, float32, VsrW(i), MSUB_FLGS, 0)
|
|
|
|
VSX_MADD(xvnmaddsp, 4, float32, VsrW(i), NMADD_FLGS, 0)
|
|
|
|
VSX_MADD(xvnmsubsp, 4, float32, VsrW(i), NMSUB_FLGS, 0)
|
2014-01-03 02:21:30 +04:00
|
|
|
|
2022-03-02 08:51:38 +03:00
|
|
|
/*
|
|
|
|
* VSX_MADDQ - VSX floating point quad-precision muliply/add
|
|
|
|
* op - instruction mnemonic
|
|
|
|
* maddflgs - flags for the float*muladd routine that control the
|
|
|
|
* various forms (madd, msub, nmadd, nmsub)
|
|
|
|
* ro - round to odd
|
|
|
|
*/
|
|
|
|
#define VSX_MADDQ(op, maddflgs, ro) \
|
|
|
|
void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *s1, ppc_vsr_t *s2,\
|
|
|
|
ppc_vsr_t *s3) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t t = *xt; \
|
|
|
|
\
|
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
|
|
|
float_status tstat = env->fp_status; \
|
|
|
|
set_float_exception_flags(0, &tstat); \
|
|
|
|
if (ro) { \
|
|
|
|
tstat.float_rounding_mode = float_round_to_odd; \
|
|
|
|
} \
|
|
|
|
t.f128 = float128_muladd(s1->f128, s3->f128, s2->f128, maddflgs, &tstat); \
|
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
|
|
|
|
\
|
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
|
|
|
|
float_invalid_op_madd(env, tstat.float_exception_flags, \
|
|
|
|
false, GETPC()); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
helper_compute_fprf_float128(env, t.f128); \
|
|
|
|
*xt = t; \
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, true, GETPC()); \
|
2022-03-02 08:51:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VSX_MADDQ(XSMADDQP, MADD_FLGS, 0)
|
|
|
|
VSX_MADDQ(XSMADDQPO, MADD_FLGS, 1)
|
|
|
|
VSX_MADDQ(XSMSUBQP, MSUB_FLGS, 0)
|
|
|
|
VSX_MADDQ(XSMSUBQPO, MSUB_FLGS, 1)
|
|
|
|
VSX_MADDQ(XSNMADDQP, NMADD_FLGS, 0)
|
|
|
|
VSX_MADDQ(XSNMADDQPO, NMADD_FLGS, 1)
|
|
|
|
VSX_MADDQ(XSNMSUBQP, NMSUB_FLGS, 0)
|
|
|
|
VSX_MADDQ(XSNMSUBQPO, NMSUB_FLGS, 0)
|
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
2022-03-02 08:51:38 +03:00
|
|
|
* VSX_SCALAR_CMP - VSX scalar floating point compare
|
2016-10-26 09:26:24 +03:00
|
|
|
* op - instruction mnemonic
|
2022-03-02 08:51:38 +03:00
|
|
|
* tp - type
|
2016-10-26 09:26:24 +03:00
|
|
|
* cmp - comparison operation
|
2022-03-02 08:51:38 +03:00
|
|
|
* fld - vsr_t field
|
2016-10-26 09:26:24 +03:00
|
|
|
* svxvc - set VXVC bit
|
|
|
|
*/
|
2022-03-02 08:51:38 +03:00
|
|
|
#define VSX_SCALAR_CMP(op, tp, cmp, fld, svxvc) \
|
|
|
|
void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
|
|
|
|
ppc_vsr_t *xa, ppc_vsr_t *xb) \
|
2016-10-26 09:26:24 +03:00
|
|
|
{ \
|
2022-03-02 08:51:38 +03:00
|
|
|
int flags; \
|
|
|
|
bool r, vxvc; \
|
2016-10-26 09:26:24 +03:00
|
|
|
\
|
2022-03-02 08:51:38 +03:00
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
|
|
|
if (svxvc) { \
|
|
|
|
r = tp##_##cmp(xb->fld, xa->fld, &env->fp_status); \
|
|
|
|
} else { \
|
|
|
|
r = tp##_##cmp##_quiet(xb->fld, xa->fld, &env->fp_status); \
|
2016-10-26 09:26:24 +03:00
|
|
|
} \
|
|
|
|
\
|
2022-03-02 08:51:38 +03:00
|
|
|
flags = get_float_exception_flags(&env->fp_status); \
|
|
|
|
if (unlikely(flags & float_flag_invalid)) { \
|
|
|
|
vxvc = svxvc; \
|
|
|
|
if (flags & float_flag_invalid_snan) { \
|
|
|
|
float_invalid_op_vxsnan(env, GETPC()); \
|
2022-05-05 00:05:20 +03:00
|
|
|
vxvc &= !(env->fpscr & FP_VE); \
|
2022-03-02 08:51:38 +03:00
|
|
|
} \
|
|
|
|
if (vxvc) { \
|
|
|
|
float_invalid_op_vxvc(env, 0, GETPC()); \
|
2016-10-26 09:26:24 +03:00
|
|
|
} \
|
|
|
|
} \
|
2022-03-02 08:51:38 +03:00
|
|
|
\
|
|
|
|
memset(xt, 0, sizeof(*xt)); \
|
|
|
|
memset(&xt->fld, -r, sizeof(xt->fld)); \
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, false, GETPC()); \
|
2016-10-26 09:26:24 +03:00
|
|
|
}
|
|
|
|
|
2022-03-02 08:51:38 +03:00
|
|
|
VSX_SCALAR_CMP(XSCMPEQDP, float64, eq, VsrD(0), 0)
|
|
|
|
VSX_SCALAR_CMP(XSCMPGEDP, float64, le, VsrD(0), 1)
|
|
|
|
VSX_SCALAR_CMP(XSCMPGTDP, float64, lt, VsrD(0), 1)
|
2022-03-02 08:51:38 +03:00
|
|
|
VSX_SCALAR_CMP(XSCMPEQQP, float128, eq, f128, 0)
|
|
|
|
VSX_SCALAR_CMP(XSCMPGEQP, float128, le, f128, 1)
|
|
|
|
VSX_SCALAR_CMP(XSCMPGTQP, float128, lt, f128, 1)
|
2016-10-26 09:26:24 +03:00
|
|
|
|
2019-06-16 15:37:44 +03:00
|
|
|
void helper_xscmpexpdp(CPUPPCState *env, uint32_t opcode,
|
|
|
|
ppc_vsr_t *xa, ppc_vsr_t *xb)
|
2016-11-23 14:37:13 +03:00
|
|
|
{
|
|
|
|
int64_t exp_a, exp_b;
|
|
|
|
uint32_t cc;
|
|
|
|
|
2019-06-16 15:37:37 +03:00
|
|
|
exp_a = extract64(xa->VsrD(0), 52, 11);
|
|
|
|
exp_b = extract64(xb->VsrD(0), 52, 11);
|
2016-11-23 14:37:13 +03:00
|
|
|
|
2019-06-16 15:37:37 +03:00
|
|
|
if (unlikely(float64_is_any_nan(xa->VsrD(0)) ||
|
|
|
|
float64_is_any_nan(xb->VsrD(0)))) {
|
2016-11-23 14:37:13 +03:00
|
|
|
cc = CRF_SO;
|
|
|
|
} else {
|
|
|
|
if (exp_a < exp_b) {
|
|
|
|
cc = CRF_LT;
|
|
|
|
} else if (exp_a > exp_b) {
|
|
|
|
cc = CRF_GT;
|
|
|
|
} else {
|
|
|
|
cc = CRF_EQ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr &= ~FP_FPCC;
|
|
|
|
env->fpscr |= cc << FPSCR_FPCC;
|
2016-11-23 14:37:13 +03:00
|
|
|
env->crf[BF(opcode)] = cc;
|
|
|
|
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, false, GETPC());
|
2016-11-23 14:37:13 +03:00
|
|
|
}
|
|
|
|
|
2019-06-16 15:37:48 +03:00
|
|
|
void helper_xscmpexpqp(CPUPPCState *env, uint32_t opcode,
|
|
|
|
ppc_vsr_t *xa, ppc_vsr_t *xb)
|
2016-11-23 14:37:13 +03:00
|
|
|
{
|
|
|
|
int64_t exp_a, exp_b;
|
|
|
|
uint32_t cc;
|
|
|
|
|
2019-06-16 15:37:37 +03:00
|
|
|
exp_a = extract64(xa->VsrD(0), 48, 15);
|
|
|
|
exp_b = extract64(xb->VsrD(0), 48, 15);
|
2016-11-23 14:37:13 +03:00
|
|
|
|
2019-06-16 15:37:37 +03:00
|
|
|
if (unlikely(float128_is_any_nan(xa->f128) ||
|
|
|
|
float128_is_any_nan(xb->f128))) {
|
2016-11-23 14:37:13 +03:00
|
|
|
cc = CRF_SO;
|
|
|
|
} else {
|
|
|
|
if (exp_a < exp_b) {
|
|
|
|
cc = CRF_LT;
|
|
|
|
} else if (exp_a > exp_b) {
|
|
|
|
cc = CRF_GT;
|
|
|
|
} else {
|
|
|
|
cc = CRF_EQ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr &= ~FP_FPCC;
|
|
|
|
env->fpscr |= cc << FPSCR_FPCC;
|
2016-11-23 14:37:13 +03:00
|
|
|
env->crf[BF(opcode)] = cc;
|
|
|
|
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, false, GETPC());
|
2016-11-23 14:37:13 +03:00
|
|
|
}
|
|
|
|
|
2020-11-13 02:01:28 +03:00
|
|
|
static inline void do_scalar_cmp(CPUPPCState *env, ppc_vsr_t *xa, ppc_vsr_t *xb,
|
|
|
|
int crf_idx, bool ordered)
|
|
|
|
{
|
|
|
|
uint32_t cc;
|
|
|
|
bool vxsnan_flag = false, vxvc_flag = false;
|
|
|
|
|
|
|
|
helper_reset_fpstatus(env);
|
|
|
|
|
|
|
|
switch (float64_compare(xa->VsrD(0), xb->VsrD(0), &env->fp_status)) {
|
|
|
|
case float_relation_less:
|
|
|
|
cc = CRF_LT;
|
|
|
|
break;
|
|
|
|
case float_relation_equal:
|
|
|
|
cc = CRF_EQ;
|
|
|
|
break;
|
|
|
|
case float_relation_greater:
|
|
|
|
cc = CRF_GT;
|
|
|
|
break;
|
|
|
|
case float_relation_unordered:
|
|
|
|
cc = CRF_SO;
|
2020-11-13 02:01:29 +03:00
|
|
|
|
|
|
|
if (float64_is_signaling_nan(xa->VsrD(0), &env->fp_status) ||
|
|
|
|
float64_is_signaling_nan(xb->VsrD(0), &env->fp_status)) {
|
|
|
|
vxsnan_flag = true;
|
2022-05-05 00:05:20 +03:00
|
|
|
if (!(env->fpscr & FP_VE) && ordered) {
|
2020-11-13 02:01:29 +03:00
|
|
|
vxvc_flag = true;
|
|
|
|
}
|
|
|
|
} else if (float64_is_quiet_nan(xa->VsrD(0), &env->fp_status) ||
|
|
|
|
float64_is_quiet_nan(xb->VsrD(0), &env->fp_status)) {
|
|
|
|
if (ordered) {
|
|
|
|
vxvc_flag = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 02:01:28 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
|
|
|
|
env->fpscr &= ~FP_FPCC;
|
|
|
|
env->fpscr |= cc << FPSCR_FPCC;
|
|
|
|
env->crf[crf_idx] = cc;
|
|
|
|
|
2020-11-13 02:01:30 +03:00
|
|
|
if (vxsnan_flag) {
|
|
|
|
float_invalid_op_vxsnan(env, GETPC());
|
|
|
|
}
|
|
|
|
if (vxvc_flag) {
|
|
|
|
float_invalid_op_vxvc(env, 0, GETPC());
|
|
|
|
}
|
|
|
|
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, false, GETPC());
|
2016-11-23 14:37:14 +03:00
|
|
|
}
|
|
|
|
|
2020-11-13 02:01:28 +03:00
|
|
|
void helper_xscmpodp(CPUPPCState *env, uint32_t opcode, ppc_vsr_t *xa,
|
|
|
|
ppc_vsr_t *xb)
|
|
|
|
{
|
|
|
|
do_scalar_cmp(env, xa, xb, BF(opcode), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void helper_xscmpudp(CPUPPCState *env, uint32_t opcode, ppc_vsr_t *xa,
|
|
|
|
ppc_vsr_t *xb)
|
|
|
|
{
|
|
|
|
do_scalar_cmp(env, xa, xb, BF(opcode), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void do_scalar_cmpq(CPUPPCState *env, ppc_vsr_t *xa,
|
|
|
|
ppc_vsr_t *xb, int crf_idx, bool ordered)
|
|
|
|
{
|
|
|
|
uint32_t cc;
|
|
|
|
bool vxsnan_flag = false, vxvc_flag = false;
|
|
|
|
|
|
|
|
helper_reset_fpstatus(env);
|
|
|
|
|
|
|
|
switch (float128_compare(xa->f128, xb->f128, &env->fp_status)) {
|
|
|
|
case float_relation_less:
|
|
|
|
cc = CRF_LT;
|
|
|
|
break;
|
|
|
|
case float_relation_equal:
|
|
|
|
cc = CRF_EQ;
|
|
|
|
break;
|
|
|
|
case float_relation_greater:
|
|
|
|
cc = CRF_GT;
|
|
|
|
break;
|
|
|
|
case float_relation_unordered:
|
|
|
|
cc = CRF_SO;
|
2020-11-13 02:01:29 +03:00
|
|
|
|
|
|
|
if (float128_is_signaling_nan(xa->f128, &env->fp_status) ||
|
|
|
|
float128_is_signaling_nan(xb->f128, &env->fp_status)) {
|
|
|
|
vxsnan_flag = true;
|
2022-05-05 00:05:20 +03:00
|
|
|
if (!(env->fpscr & FP_VE) && ordered) {
|
2020-11-13 02:01:29 +03:00
|
|
|
vxvc_flag = true;
|
|
|
|
}
|
|
|
|
} else if (float128_is_quiet_nan(xa->f128, &env->fp_status) ||
|
|
|
|
float128_is_quiet_nan(xb->f128, &env->fp_status)) {
|
|
|
|
if (ordered) {
|
|
|
|
vxvc_flag = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 02:01:28 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
|
|
|
|
env->fpscr &= ~FP_FPCC;
|
|
|
|
env->fpscr |= cc << FPSCR_FPCC;
|
|
|
|
env->crf[crf_idx] = cc;
|
|
|
|
|
2020-11-13 02:01:30 +03:00
|
|
|
if (vxsnan_flag) {
|
|
|
|
float_invalid_op_vxsnan(env, GETPC());
|
|
|
|
}
|
|
|
|
if (vxvc_flag) {
|
|
|
|
float_invalid_op_vxvc(env, 0, GETPC());
|
|
|
|
}
|
|
|
|
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, false, GETPC());
|
2020-11-13 02:01:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void helper_xscmpoqp(CPUPPCState *env, uint32_t opcode, ppc_vsr_t *xa,
|
|
|
|
ppc_vsr_t *xb)
|
|
|
|
{
|
|
|
|
do_scalar_cmpq(env, xa, xb, BF(opcode), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void helper_xscmpuqp(CPUPPCState *env, uint32_t opcode, ppc_vsr_t *xa,
|
|
|
|
ppc_vsr_t *xb)
|
|
|
|
{
|
|
|
|
do_scalar_cmpq(env, xa, xb, BF(opcode), false);
|
|
|
|
}
|
2016-11-23 14:37:14 +03:00
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
* VSX_MAX_MIN - VSX floating point maximum/minimum
|
2014-01-03 02:21:31 +04:00
|
|
|
* name - instruction mnemonic
|
|
|
|
* op - operation (max or min)
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 01:03:59 +04:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2014-01-03 02:21:31 +04:00
|
|
|
*/
|
|
|
|
#define VSX_MAX_MIN(name, op, nels, tp, fld) \
|
2019-06-16 15:37:41 +03:00
|
|
|
void helper_##name(CPUPPCState *env, ppc_vsr_t *xt, \
|
|
|
|
ppc_vsr_t *xa, ppc_vsr_t *xb) \
|
2014-01-03 02:21:31 +04:00
|
|
|
{ \
|
2022-02-09 11:08:56 +03:00
|
|
|
ppc_vsr_t t = { }; \
|
2014-01-03 02:21:31 +04:00
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.fld = tp##_##op(xa->fld, xb->fld, &env->fp_status); \
|
|
|
|
if (unlikely(tp##_is_signaling_nan(xa->fld, &env->fp_status) || \
|
|
|
|
tp##_is_signaling_nan(xb->fld, &env->fp_status))) { \
|
2018-10-12 02:41:53 +03:00
|
|
|
float_invalid_op_vxsnan(env, GETPC()); \
|
2014-01-03 02:21:31 +04:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t; \
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, false, GETPC()); \
|
2014-01-03 02:21:31 +04:00
|
|
|
}
|
|
|
|
|
2014-04-01 01:03:59 +04:00
|
|
|
VSX_MAX_MIN(xsmaxdp, maxnum, 1, float64, VsrD(0))
|
|
|
|
VSX_MAX_MIN(xvmaxdp, maxnum, 2, float64, VsrD(i))
|
|
|
|
VSX_MAX_MIN(xvmaxsp, maxnum, 4, float32, VsrW(i))
|
|
|
|
VSX_MAX_MIN(xsmindp, minnum, 1, float64, VsrD(0))
|
|
|
|
VSX_MAX_MIN(xvmindp, minnum, 2, float64, VsrD(i))
|
|
|
|
VSX_MAX_MIN(xvminsp, minnum, 4, float32, VsrW(i))
|
2014-01-03 02:21:32 +04:00
|
|
|
|
2022-03-02 08:51:38 +03:00
|
|
|
#define VSX_MAX_MINC(name, max, tp, fld) \
|
2021-12-17 19:57:18 +03:00
|
|
|
void helper_##name(CPUPPCState *env, \
|
2019-06-16 15:37:46 +03:00
|
|
|
ppc_vsr_t *xt, ppc_vsr_t *xa, ppc_vsr_t *xb) \
|
2017-02-06 13:29:59 +03:00
|
|
|
{ \
|
2022-02-09 11:08:56 +03:00
|
|
|
ppc_vsr_t t = { }; \
|
2022-03-02 08:51:38 +03:00
|
|
|
bool first; \
|
2017-02-06 13:29:59 +03:00
|
|
|
\
|
2022-03-05 09:16:48 +03:00
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
2022-03-02 08:51:38 +03:00
|
|
|
if (max) { \
|
|
|
|
first = tp##_le_quiet(xb->fld, xa->fld, &env->fp_status); \
|
2017-02-06 13:29:59 +03:00
|
|
|
} else { \
|
2022-03-02 08:51:38 +03:00
|
|
|
first = tp##_lt_quiet(xa->fld, xb->fld, &env->fp_status); \
|
2017-02-06 13:29:59 +03:00
|
|
|
} \
|
|
|
|
\
|
2022-03-02 08:51:38 +03:00
|
|
|
if (first) { \
|
|
|
|
t.fld = xa->fld; \
|
|
|
|
} else { \
|
|
|
|
t.fld = xb->fld; \
|
|
|
|
if (env->fp_status.float_exception_flags & float_flag_invalid_snan) { \
|
|
|
|
float_invalid_op_vxsnan(env, GETPC()); \
|
|
|
|
} \
|
2017-02-06 13:29:59 +03:00
|
|
|
} \
|
2022-03-02 08:51:38 +03:00
|
|
|
\
|
|
|
|
*xt = t; \
|
|
|
|
}
|
2017-02-06 13:29:59 +03:00
|
|
|
|
2022-03-02 08:51:38 +03:00
|
|
|
VSX_MAX_MINC(XSMAXCDP, true, float64, VsrD(0));
|
|
|
|
VSX_MAX_MINC(XSMINCDP, false, float64, VsrD(0));
|
2022-03-02 08:51:38 +03:00
|
|
|
VSX_MAX_MINC(XSMAXCQP, true, float128, f128);
|
|
|
|
VSX_MAX_MINC(XSMINCQP, false, float128, f128);
|
2017-02-06 13:29:59 +03:00
|
|
|
|
2017-02-06 13:30:00 +03:00
|
|
|
#define VSX_MAX_MINJ(name, max) \
|
2021-12-17 19:57:18 +03:00
|
|
|
void helper_##name(CPUPPCState *env, \
|
2019-06-16 15:37:46 +03:00
|
|
|
ppc_vsr_t *xt, ppc_vsr_t *xa, ppc_vsr_t *xb) \
|
2017-02-06 13:30:00 +03:00
|
|
|
{ \
|
2022-02-09 11:08:56 +03:00
|
|
|
ppc_vsr_t t = { }; \
|
2017-02-06 13:30:00 +03:00
|
|
|
bool vxsnan_flag = false, vex_flag = false; \
|
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
if (unlikely(float64_is_any_nan(xa->VsrD(0)))) { \
|
|
|
|
if (float64_is_signaling_nan(xa->VsrD(0), &env->fp_status)) { \
|
2017-02-06 13:30:00 +03:00
|
|
|
vxsnan_flag = true; \
|
|
|
|
} \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.VsrD(0) = xa->VsrD(0); \
|
|
|
|
} else if (unlikely(float64_is_any_nan(xb->VsrD(0)))) { \
|
|
|
|
if (float64_is_signaling_nan(xb->VsrD(0), &env->fp_status)) { \
|
2017-02-06 13:30:00 +03:00
|
|
|
vxsnan_flag = true; \
|
|
|
|
} \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.VsrD(0) = xb->VsrD(0); \
|
|
|
|
} else if (float64_is_zero(xa->VsrD(0)) && \
|
|
|
|
float64_is_zero(xb->VsrD(0))) { \
|
2017-02-06 13:30:00 +03:00
|
|
|
if (max) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
if (!float64_is_neg(xa->VsrD(0)) || \
|
|
|
|
!float64_is_neg(xb->VsrD(0))) { \
|
|
|
|
t.VsrD(0) = 0ULL; \
|
2017-02-06 13:30:00 +03:00
|
|
|
} else { \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.VsrD(0) = 0x8000000000000000ULL; \
|
2017-02-06 13:30:00 +03:00
|
|
|
} \
|
|
|
|
} else { \
|
2019-06-16 15:37:37 +03:00
|
|
|
if (float64_is_neg(xa->VsrD(0)) || \
|
|
|
|
float64_is_neg(xb->VsrD(0))) { \
|
|
|
|
t.VsrD(0) = 0x8000000000000000ULL; \
|
2017-02-06 13:30:00 +03:00
|
|
|
} else { \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.VsrD(0) = 0ULL; \
|
2017-02-06 13:30:00 +03:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} else if ((max && \
|
2019-06-16 15:37:37 +03:00
|
|
|
!float64_lt(xa->VsrD(0), xb->VsrD(0), &env->fp_status)) || \
|
2017-02-06 13:30:00 +03:00
|
|
|
(!max && \
|
2019-06-16 15:37:37 +03:00
|
|
|
float64_lt(xa->VsrD(0), xb->VsrD(0), &env->fp_status))) { \
|
|
|
|
t.VsrD(0) = xa->VsrD(0); \
|
2017-02-06 13:30:00 +03:00
|
|
|
} else { \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.VsrD(0) = xb->VsrD(0); \
|
2017-02-06 13:30:00 +03:00
|
|
|
} \
|
|
|
|
\
|
2022-05-05 00:05:20 +03:00
|
|
|
vex_flag = (env->fpscr & FP_VE) && vxsnan_flag; \
|
2017-02-06 13:30:00 +03:00
|
|
|
if (vxsnan_flag) { \
|
2018-10-12 02:41:53 +03:00
|
|
|
float_invalid_op_vxsnan(env, GETPC()); \
|
2017-02-06 13:30:00 +03:00
|
|
|
} \
|
|
|
|
if (!vex_flag) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t; \
|
2017-02-06 13:30:00 +03:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
|
2022-03-02 08:51:38 +03:00
|
|
|
VSX_MAX_MINJ(XSMAXJDP, 1);
|
|
|
|
VSX_MAX_MINJ(XSMINJDP, 0);
|
2017-02-06 13:30:00 +03:00
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
* VSX_CMP - VSX floating point compare
|
2014-01-03 02:21:32 +04:00
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 01:03:59 +04:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2014-01-03 02:21:32 +04:00
|
|
|
* cmp - comparison operation
|
|
|
|
* svxvc - set VXVC bit
|
2016-10-26 09:26:29 +03:00
|
|
|
* exp - expected result of comparison
|
2014-01-03 02:21:32 +04:00
|
|
|
*/
|
2016-10-26 09:26:29 +03:00
|
|
|
#define VSX_CMP(op, nels, tp, fld, cmp, svxvc, exp) \
|
2019-06-16 15:37:40 +03:00
|
|
|
uint32_t helper_##op(CPUPPCState *env, ppc_vsr_t *xt, \
|
|
|
|
ppc_vsr_t *xa, ppc_vsr_t *xb) \
|
2014-01-03 02:21:32 +04:00
|
|
|
{ \
|
2019-06-16 15:37:37 +03:00
|
|
|
ppc_vsr_t t = *xt; \
|
2019-06-16 15:37:40 +03:00
|
|
|
uint32_t crf6 = 0; \
|
2014-01-03 02:21:32 +04:00
|
|
|
int i; \
|
|
|
|
int all_true = 1; \
|
|
|
|
int all_false = 1; \
|
|
|
|
\
|
2022-09-06 15:55:23 +03:00
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
2014-01-03 02:21:32 +04:00
|
|
|
for (i = 0; i < nels; i++) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
if (unlikely(tp##_is_any_nan(xa->fld) || \
|
|
|
|
tp##_is_any_nan(xb->fld))) { \
|
|
|
|
if (tp##_is_signaling_nan(xa->fld, &env->fp_status) || \
|
|
|
|
tp##_is_signaling_nan(xb->fld, &env->fp_status)) { \
|
2018-10-12 02:41:53 +03:00
|
|
|
float_invalid_op_vxsnan(env, GETPC()); \
|
2014-01-03 02:21:32 +04:00
|
|
|
} \
|
|
|
|
if (svxvc) { \
|
2018-10-12 02:41:53 +03:00
|
|
|
float_invalid_op_vxvc(env, 0, GETPC()); \
|
2014-01-03 02:21:32 +04:00
|
|
|
} \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.fld = 0; \
|
2014-01-03 02:21:32 +04:00
|
|
|
all_true = 0; \
|
|
|
|
} else { \
|
2019-06-16 15:37:37 +03:00
|
|
|
if (tp##_##cmp(xb->fld, xa->fld, &env->fp_status) == exp) { \
|
|
|
|
t.fld = -1; \
|
2014-01-03 02:21:32 +04:00
|
|
|
all_false = 0; \
|
|
|
|
} else { \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.fld = 0; \
|
2014-01-03 02:21:32 +04:00
|
|
|
all_true = 0; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t; \
|
2019-06-16 15:37:40 +03:00
|
|
|
crf6 = (all_true ? 0x8 : 0) | (all_false ? 0x2 : 0); \
|
|
|
|
return crf6; \
|
|
|
|
}
|
2014-01-03 02:21:32 +04:00
|
|
|
|
2016-10-26 09:26:29 +03:00
|
|
|
VSX_CMP(xvcmpeqdp, 2, float64, VsrD(i), eq, 0, 1)
|
|
|
|
VSX_CMP(xvcmpgedp, 2, float64, VsrD(i), le, 1, 1)
|
|
|
|
VSX_CMP(xvcmpgtdp, 2, float64, VsrD(i), lt, 1, 1)
|
|
|
|
VSX_CMP(xvcmpnedp, 2, float64, VsrD(i), eq, 0, 0)
|
|
|
|
VSX_CMP(xvcmpeqsp, 4, float32, VsrW(i), eq, 0, 1)
|
|
|
|
VSX_CMP(xvcmpgesp, 4, float32, VsrW(i), le, 1, 1)
|
|
|
|
VSX_CMP(xvcmpgtsp, 4, float32, VsrW(i), lt, 1, 1)
|
|
|
|
VSX_CMP(xvcmpnesp, 4, float32, VsrW(i), eq, 0, 0)
|
2014-01-03 02:21:33 +04:00
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
* VSX_CVT_FP_TO_FP - VSX floating point/floating point conversion
|
2014-01-03 02:21:33 +04:00
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* stp - source type (float32 or float64)
|
|
|
|
* ttp - target type (float32 or float64)
|
|
|
|
* sfld - source vsr_t field
|
|
|
|
* tfld - target vsr_t field (f32 or f64)
|
2022-05-17 19:15:22 +03:00
|
|
|
* sfifprf - set FI and FPRF
|
2014-01-03 02:21:33 +04:00
|
|
|
*/
|
2022-05-17 19:15:22 +03:00
|
|
|
#define VSX_CVT_FP_TO_FP(op, nels, stp, ttp, sfld, tfld, sfifprf) \
|
2019-06-16 15:37:43 +03:00
|
|
|
void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
|
2014-01-03 02:21:33 +04:00
|
|
|
{ \
|
2022-02-09 11:08:56 +03:00
|
|
|
ppc_vsr_t t = { }; \
|
2014-01-03 02:21:33 +04:00
|
|
|
int i; \
|
|
|
|
\
|
2022-09-06 15:55:23 +03:00
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
2014-01-03 02:21:33 +04:00
|
|
|
for (i = 0; i < nels; i++) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.tfld = stp##_to_##ttp(xb->sfld, &env->fp_status); \
|
|
|
|
if (unlikely(stp##_is_signaling_nan(xb->sfld, \
|
softfloat: Implement run-time-configurable meaning of signaling NaN bit
This patch modifies SoftFloat library so that it can be configured in
run-time in relation to the meaning of signaling NaN bit, while, at the
same time, strictly preserving its behavior on all existing platforms.
Background:
In floating-point calculations, there is a need for denoting undefined or
unrepresentable values. This is achieved by defining certain floating-point
numerical values to be NaNs (which stands for "not a number"). For additional
reasons, virtually all modern floating-point unit implementations use two
kinds of NaNs: quiet and signaling. The binary representations of these two
kinds of NaNs, as a rule, differ only in one bit (that bit is, traditionally,
the first bit of mantissa).
Up to 2008, standards for floating-point did not specify all details about
binary representation of NaNs. More specifically, the meaning of the bit
that is used for distinguishing between signaling and quiet NaNs was not
strictly prescribed. (IEEE 754-2008 was the first floating-point standard
that defined that meaning clearly, see [1], p. 35) As a result, different
platforms took different approaches, and that presented considerable
challenge for multi-platform emulators like QEMU.
Mips platform represents the most complex case among QEMU-supported
platforms regarding signaling NaN bit. Up to the Release 6 of Mips
architecture, "1" in signaling NaN bit denoted signaling NaN, which is
opposite to IEEE 754-2008 standard. From Release 6 on, Mips architecture
adopted IEEE standard prescription, and "0" denotes signaling NaN. On top of
that, Mips architecture for SIMD (also known as MSA, or vector instructions)
also specifies signaling bit in accordance to IEEE standard. MSA unit can be
implemented with both pre-Release 6 and Release 6 main processor units.
QEMU uses SoftFloat library to implement various floating-point-related
instructions on all platforms. The current QEMU implementation allows for
defining meaning of signaling NaN bit during build time, and is implemented
via preprocessor macro called SNAN_BIT_IS_ONE.
On the other hand, the change in this patch enables SoftFloat library to be
configured in run-time. This configuration is meant to occur during CPU
initialization, at the moment when it is definitely known what desired
behavior for particular CPU (or any additional FPUs) is.
The change is implemented so that it is consistent with existing
implementation of similar cases. This means that structure float_status is
used for passing the information about desired signaling NaN bit on each
invocation of SoftFloat functions. The additional field in float_status is
called snan_bit_is_one, which supersedes macro SNAN_BIT_IS_ONE.
IMPORTANT:
This change is not meant to create any change in emulator behavior or
functionality on any platform. It just provides the means for SoftFloat
library to be used in a more flexible way - in other words, it will just
prepare SoftFloat library for usage related to Mips platform and its
specifics regarding signaling bit meaning, which is done in some of
subsequent patches from this series.
Further break down of changes:
1) Added field snan_bit_is_one to the structure float_status, and
correspondent setter function set_snan_bit_is_one().
2) Constants <float16|float32|float64|floatx80|float128>_default_nan
(used both internally and externally) converted to functions
<float16|float32|float64|floatx80|float128>_default_nan(float_status*).
This is necessary since they are dependent on signaling bit meaning.
At the same time, for the sake of code cleanup and simplicity, constants
<floatx80|float128>_default_nan_<low|high> (used only internally within
SoftFloat library) are removed, as not needed.
3) Added a float_status* argument to SoftFloat library functions
XXX_is_quiet_nan(XXX a_), XXX_is_signaling_nan(XXX a_),
XXX_maybe_silence_nan(XXX a_). This argument must be present in
order to enable correct invocation of new version of functions
XXX_default_nan(). (XXX is <float16|float32|float64|floatx80|float128>
here)
4) Updated code for all platforms to reflect changes in SoftFloat library.
This change is twofolds: it includes modifications of SoftFloat library
functions invocations, and an addition of invocation of function
set_snan_bit_is_one() during CPU initialization, with arguments that
are appropriate for each particular platform. It was established that
all platforms zero their main CPU data structures, so snan_bit_is_one(0)
in appropriate places is not added, as it is not needed.
[1] "IEEE Standard for Floating-Point Arithmetic",
IEEE Computer Society, August 29, 2008.
Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
Signed-off-by: Maciej W. Rozycki <macro@codesourcery.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Tested-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
Reviewed-by: Leon Alrae <leon.alrae@imgtec.com>
Tested-by: Leon Alrae <leon.alrae@imgtec.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
[leon.alrae@imgtec.com:
* cherry-picked 2 chunks from patch #2 to fix compilation warnings]
Signed-off-by: Leon Alrae <leon.alrae@imgtec.com>
2016-06-10 12:57:28 +03:00
|
|
|
&env->fp_status))) { \
|
2018-10-12 02:41:53 +03:00
|
|
|
float_invalid_op_vxsnan(env, GETPC()); \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.tfld = ttp##_snan_to_qnan(t.tfld); \
|
2014-01-03 02:21:33 +04:00
|
|
|
} \
|
2022-05-17 19:15:22 +03:00
|
|
|
if (sfifprf) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_##ttp(env, t.tfld); \
|
2014-01-03 02:21:33 +04:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t; \
|
2022-05-17 19:15:22 +03:00
|
|
|
do_float_check_status(env, sfifprf, GETPC()); \
|
2014-01-03 02:21:33 +04:00
|
|
|
}
|
|
|
|
|
2014-04-01 01:04:01 +04:00
|
|
|
VSX_CVT_FP_TO_FP(xscvspdp, 1, float32, float64, VsrW(0), VsrD(0), 1)
|
2019-03-21 09:01:06 +03:00
|
|
|
VSX_CVT_FP_TO_FP(xvcvspdp, 2, float32, float64, VsrW(2 * i), VsrD(i), 0)
|
target-ppc: Add VSX ISA2.06 Integer Conversion Instructions
This patch adds the VSX Integer Conversion instructions defined by
V2.06 of the PowerPC ISA:
- xscvdpsxds, xscvdpsxws, xscvdpuxds, xscvdpuxws
- xvcvdpsxds, xvcvdpsxws, xvcvdpuxds, xvcvdpuxws
- xvcvspsxds, xvcvspsxws, xvcvspuxds, xvcvspuxws
- xscvsxddp, xscvuxddp
- xvcvsxddp, xscvsxwdp, xvcvuxddp, xvcvuxwdp
- xvcvsxdsp, xscvsxwsp, xvcvuxdsp, xvcvuxwsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:34 +04:00
|
|
|
|
2022-05-17 19:15:22 +03:00
|
|
|
#define VSX_CVT_FP_TO_FP2(op, nels, stp, ttp, sfifprf) \
|
2022-03-21 01:35:27 +03:00
|
|
|
void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t t = { }; \
|
|
|
|
int i; \
|
|
|
|
\
|
2022-09-06 15:55:23 +03:00
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
2022-03-21 01:35:27 +03:00
|
|
|
for (i = 0; i < nels; i++) { \
|
|
|
|
t.VsrW(2 * i) = stp##_to_##ttp(xb->VsrD(i), &env->fp_status); \
|
|
|
|
if (unlikely(stp##_is_signaling_nan(xb->VsrD(i), \
|
|
|
|
&env->fp_status))) { \
|
|
|
|
float_invalid_op_vxsnan(env, GETPC()); \
|
|
|
|
t.VsrW(2 * i) = ttp##_snan_to_qnan(t.VsrW(2 * i)); \
|
|
|
|
} \
|
2022-05-17 19:15:22 +03:00
|
|
|
if (sfifprf) { \
|
2022-03-21 01:35:27 +03:00
|
|
|
helper_compute_fprf_##ttp(env, t.VsrW(2 * i)); \
|
|
|
|
} \
|
|
|
|
t.VsrW(2 * i + 1) = t.VsrW(2 * i); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
*xt = t; \
|
2022-05-17 19:15:22 +03:00
|
|
|
do_float_check_status(env, sfifprf, GETPC()); \
|
2022-03-21 01:35:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VSX_CVT_FP_TO_FP2(xvcvdpsp, 2, float64, float32, 0)
|
|
|
|
VSX_CVT_FP_TO_FP2(xscvdpsp, 1, float64, float32, 1)
|
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
* VSX_CVT_FP_TO_FP_VECTOR - VSX floating point/floating point conversion
|
2017-01-09 17:26:14 +03:00
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* stp - source type (float32 or float64)
|
|
|
|
* ttp - target type (float32 or float64)
|
|
|
|
* sfld - source vsr_t field
|
|
|
|
* tfld - target vsr_t field (f32 or f64)
|
|
|
|
* sfprf - set FPRF
|
|
|
|
*/
|
2022-05-17 19:15:22 +03:00
|
|
|
#define VSX_CVT_FP_TO_FP_VECTOR(op, nels, stp, ttp, sfld, tfld, sfprf) \
|
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode, \
|
|
|
|
ppc_vsr_t *xt, ppc_vsr_t *xb) \
|
2017-01-09 17:26:14 +03:00
|
|
|
{ \
|
2019-06-16 15:37:37 +03:00
|
|
|
ppc_vsr_t t = *xt; \
|
2017-01-09 17:26:14 +03:00
|
|
|
int i; \
|
|
|
|
\
|
2022-09-06 15:55:23 +03:00
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
2017-01-09 17:26:14 +03:00
|
|
|
for (i = 0; i < nels; i++) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.tfld = stp##_to_##ttp(xb->sfld, &env->fp_status); \
|
|
|
|
if (unlikely(stp##_is_signaling_nan(xb->sfld, \
|
2017-01-09 17:26:14 +03:00
|
|
|
&env->fp_status))) { \
|
2018-10-12 02:41:53 +03:00
|
|
|
float_invalid_op_vxsnan(env, GETPC()); \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.tfld = ttp##_snan_to_qnan(t.tfld); \
|
2017-01-09 17:26:14 +03:00
|
|
|
} \
|
|
|
|
if (sfprf) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_##ttp(env, t.tfld); \
|
2017-01-09 17:26:14 +03:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t; \
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, true, GETPC()); \
|
2017-01-09 17:26:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VSX_CVT_FP_TO_FP_VECTOR(xscvdpqp, 1, float64, float128, VsrD(0), f128, 1)
|
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
* VSX_CVT_FP_TO_FP_HP - VSX floating point/floating point conversion
|
2017-01-06 09:14:49 +03:00
|
|
|
* involving one half precision value
|
|
|
|
* op - instruction mnemonic
|
2017-01-12 19:24:09 +03:00
|
|
|
* nels - number of elements (1, 2 or 4)
|
2017-01-06 09:14:49 +03:00
|
|
|
* stp - source type
|
|
|
|
* ttp - target type
|
|
|
|
* sfld - source vsr_t field
|
|
|
|
* tfld - target vsr_t field
|
2022-05-17 19:15:22 +03:00
|
|
|
* sfifprf - set FI and FPRF
|
2017-01-06 09:14:49 +03:00
|
|
|
*/
|
2022-05-17 19:15:22 +03:00
|
|
|
#define VSX_CVT_FP_TO_FP_HP(op, nels, stp, ttp, sfld, tfld, sfifprf) \
|
2019-06-16 15:37:43 +03:00
|
|
|
void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
|
2017-01-06 09:14:49 +03:00
|
|
|
{ \
|
2019-06-16 15:37:37 +03:00
|
|
|
ppc_vsr_t t = { }; \
|
2017-01-12 19:24:09 +03:00
|
|
|
int i; \
|
2017-01-06 09:14:49 +03:00
|
|
|
\
|
2022-09-06 15:55:23 +03:00
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
2017-01-12 19:24:09 +03:00
|
|
|
for (i = 0; i < nels; i++) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.tfld = stp##_to_##ttp(xb->sfld, 1, &env->fp_status); \
|
|
|
|
if (unlikely(stp##_is_signaling_nan(xb->sfld, \
|
2017-01-12 19:24:09 +03:00
|
|
|
&env->fp_status))) { \
|
2018-10-12 02:41:53 +03:00
|
|
|
float_invalid_op_vxsnan(env, GETPC()); \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.tfld = ttp##_snan_to_qnan(t.tfld); \
|
2017-01-12 19:24:09 +03:00
|
|
|
} \
|
2022-05-17 19:15:22 +03:00
|
|
|
if (sfifprf) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_##ttp(env, t.tfld); \
|
2017-01-12 19:24:09 +03:00
|
|
|
} \
|
2017-01-06 09:14:49 +03:00
|
|
|
} \
|
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t; \
|
2022-05-17 19:15:22 +03:00
|
|
|
do_float_check_status(env, sfifprf, GETPC()); \
|
2017-01-06 09:14:49 +03:00
|
|
|
}
|
|
|
|
|
2017-01-12 19:24:09 +03:00
|
|
|
VSX_CVT_FP_TO_FP_HP(xscvdphp, 1, float64, float16, VsrD(0), VsrH(3), 1)
|
|
|
|
VSX_CVT_FP_TO_FP_HP(xscvhpdp, 1, float16, float64, VsrH(3), VsrD(0), 1)
|
|
|
|
VSX_CVT_FP_TO_FP_HP(xvcvsphp, 4, float32, float16, VsrW(i), VsrH(2 * i + 1), 0)
|
|
|
|
VSX_CVT_FP_TO_FP_HP(xvcvhpsp, 4, float16, float32, VsrH(2 * i + 1), VsrW(i), 0)
|
2017-01-06 09:14:49 +03:00
|
|
|
|
2022-03-02 08:51:38 +03:00
|
|
|
void helper_XVCVSPBF16(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb)
|
|
|
|
{
|
|
|
|
ppc_vsr_t t = { };
|
|
|
|
int i, status;
|
|
|
|
|
2022-03-05 09:16:48 +03:00
|
|
|
helper_reset_fpstatus(env);
|
|
|
|
|
2022-03-02 08:51:38 +03:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
t.VsrH(2 * i + 1) = float32_to_bfloat16(xb->VsrW(i), &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
status = get_float_exception_flags(&env->fp_status);
|
|
|
|
if (unlikely(status & float_flag_invalid_snan)) {
|
|
|
|
float_invalid_op_vxsnan(env, GETPC());
|
|
|
|
}
|
|
|
|
|
|
|
|
*xt = t;
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, false, GETPC());
|
2022-03-02 08:51:38 +03:00
|
|
|
}
|
|
|
|
|
2021-12-17 19:57:18 +03:00
|
|
|
void helper_XSCVQPDP(CPUPPCState *env, uint32_t ro, ppc_vsr_t *xt,
|
|
|
|
ppc_vsr_t *xb)
|
2017-01-09 17:26:15 +03:00
|
|
|
{
|
2019-06-16 15:37:37 +03:00
|
|
|
ppc_vsr_t t = { };
|
2017-02-10 10:23:08 +03:00
|
|
|
float_status tstat;
|
2017-01-09 17:26:15 +03:00
|
|
|
|
2022-09-06 15:55:23 +03:00
|
|
|
helper_reset_fpstatus(env);
|
|
|
|
|
2017-02-10 10:23:08 +03:00
|
|
|
tstat = env->fp_status;
|
2021-12-17 19:57:18 +03:00
|
|
|
if (ro != 0) {
|
2017-02-10 10:23:08 +03:00
|
|
|
tstat.float_rounding_mode = float_round_to_odd;
|
2017-01-09 17:26:15 +03:00
|
|
|
}
|
|
|
|
|
2019-06-16 15:37:37 +03:00
|
|
|
t.VsrD(0) = float128_to_float64(xb->f128, &tstat);
|
2017-02-10 10:23:08 +03:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags;
|
2019-06-16 15:37:37 +03:00
|
|
|
if (unlikely(float128_is_signaling_nan(xb->f128, &tstat))) {
|
2018-10-12 02:41:53 +03:00
|
|
|
float_invalid_op_vxsnan(env, GETPC());
|
2019-06-16 15:37:37 +03:00
|
|
|
t.VsrD(0) = float64_snan_to_qnan(t.VsrD(0));
|
2017-01-09 17:26:15 +03:00
|
|
|
}
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_float64(env, t.VsrD(0));
|
2017-01-09 17:26:15 +03:00
|
|
|
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t;
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, true, GETPC());
|
2017-01-09 17:26:15 +03:00
|
|
|
}
|
|
|
|
|
2014-01-15 18:10:45 +04:00
|
|
|
uint64_t helper_xscvdpspn(CPUPPCState *env, uint64_t xb)
|
|
|
|
{
|
2019-08-20 20:26:04 +03:00
|
|
|
uint64_t result, sign, exp, frac;
|
ppc: conform to processor User's Manual for xscvdpspn
The POWER8 and POWER9 User's Manuals specify the implementation
behavior for what the ISA leaves "undefined" behavior for the
xscvdpspn and xscvdpsp instructions. This patch corrects the QEMU
implementation to match the hardware implementation for that case.
ISA 3.0B has xscvdpspn leaving its result in word 0 of the target register,
with the other words of the target register left "undefined".
The User's Manuals specify:
VSX scalar convert from double-precision to single-precision (xscvdpsp,
xscvdpspn).
VSR[32:63] is set to VSR[0:31].
So, words 0 and 1 both contain the result.
Note: this is important because GCC as of version 8 or so, assumes and takes
advantage of this behavior to optimize the following sequence:
xscvdpspn vs0,vs1
mffprwz r8,f0
ISA 3.0B has xscvdpspn leaving its result in word 0 of the target register,
and mffprwz expecting its input to come from word 1 of the source register.
This sequence fails with QEMU, as a shift is required between those two
instructions. However, since the hardware splats the result to both words 0
and 1 of its output register, the shift is not necessary.
Expect a future revision of the ISA to specify this behavior.
Signed-off-by: Paul A. Clarke <pc@us.ibm.com>
v2
- Splitting patch "ppc: Three floating point fixes"; this is just one part.
- Updated commit message to clarify behavior is documented in User's Manuals.
- Updated commit message to correct which words are in output and source of
xscvdpspn and mffprz.
- No source changes to this part of the original patch.
Message-Id: <1566236601-22954-1-git-send-email-pc@us.ibm.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-08-19 20:43:21 +03:00
|
|
|
|
2022-09-06 15:55:23 +03:00
|
|
|
helper_reset_fpstatus(env);
|
2014-01-15 18:10:45 +04:00
|
|
|
float_status tstat = env->fp_status;
|
|
|
|
set_float_exception_flags(0, &tstat);
|
|
|
|
|
2019-08-20 20:26:04 +03:00
|
|
|
sign = extract64(xb, 63, 1);
|
|
|
|
exp = extract64(xb, 52, 11);
|
|
|
|
frac = extract64(xb, 0, 52) | 0x10000000000000ULL;
|
|
|
|
|
|
|
|
if (unlikely(exp == 0 && extract64(frac, 0, 52) != 0)) {
|
|
|
|
/* DP denormal operand. */
|
|
|
|
/* Exponent override to DP min exp. */
|
|
|
|
exp = 1;
|
|
|
|
/* Implicit bit override to 0. */
|
|
|
|
frac = deposit64(frac, 53, 1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlikely(exp < 897 && frac != 0)) {
|
|
|
|
/* SP tiny operand. */
|
|
|
|
if (897 - exp > 63) {
|
|
|
|
frac = 0;
|
|
|
|
} else {
|
|
|
|
/* Denormalize until exp = SP min exp. */
|
|
|
|
frac >>= (897 - exp);
|
|
|
|
}
|
|
|
|
/* Exponent override to SP min exp - 1. */
|
|
|
|
exp = 896;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = sign << 31;
|
|
|
|
result |= extract64(exp, 10, 1) << 30;
|
|
|
|
result |= extract64(exp, 0, 7) << 23;
|
|
|
|
result |= extract64(frac, 29, 23);
|
|
|
|
|
ppc: conform to processor User's Manual for xscvdpspn
The POWER8 and POWER9 User's Manuals specify the implementation
behavior for what the ISA leaves "undefined" behavior for the
xscvdpspn and xscvdpsp instructions. This patch corrects the QEMU
implementation to match the hardware implementation for that case.
ISA 3.0B has xscvdpspn leaving its result in word 0 of the target register,
with the other words of the target register left "undefined".
The User's Manuals specify:
VSX scalar convert from double-precision to single-precision (xscvdpsp,
xscvdpspn).
VSR[32:63] is set to VSR[0:31].
So, words 0 and 1 both contain the result.
Note: this is important because GCC as of version 8 or so, assumes and takes
advantage of this behavior to optimize the following sequence:
xscvdpspn vs0,vs1
mffprwz r8,f0
ISA 3.0B has xscvdpspn leaving its result in word 0 of the target register,
and mffprwz expecting its input to come from word 1 of the source register.
This sequence fails with QEMU, as a shift is required between those two
instructions. However, since the hardware splats the result to both words 0
and 1 of its output register, the shift is not necessary.
Expect a future revision of the ISA to specify this behavior.
Signed-off-by: Paul A. Clarke <pc@us.ibm.com>
v2
- Splitting patch "ppc: Three floating point fixes"; this is just one part.
- Updated commit message to clarify behavior is documented in User's Manuals.
- Updated commit message to correct which words are in output and source of
xscvdpspn and mffprz.
- No source changes to this part of the original patch.
Message-Id: <1566236601-22954-1-git-send-email-pc@us.ibm.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-08-19 20:43:21 +03:00
|
|
|
/* hardware replicates result to both words of the doubleword result. */
|
|
|
|
return (result << 32) | result;
|
2014-01-15 18:10:45 +04:00
|
|
|
}
|
|
|
|
|
2022-05-17 15:39:23 +03:00
|
|
|
uint64_t helper_XSCVSPDPN(uint64_t xb)
|
2014-01-15 18:10:45 +04:00
|
|
|
{
|
2022-01-04 09:55:34 +03:00
|
|
|
return helper_todouble(xb >> 32);
|
2014-01-15 18:10:45 +04:00
|
|
|
}
|
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
* VSX_CVT_FP_TO_INT - VSX floating point to integer conversion
|
target-ppc: Add VSX ISA2.06 Integer Conversion Instructions
This patch adds the VSX Integer Conversion instructions defined by
V2.06 of the PowerPC ISA:
- xscvdpsxds, xscvdpsxws, xscvdpuxds, xscvdpuxws
- xvcvdpsxds, xvcvdpsxws, xvcvdpuxds, xvcvdpuxws
- xvcvspsxds, xvcvspsxws, xvcvspuxds, xvcvspuxws
- xscvsxddp, xscvuxddp
- xvcvsxddp, xscvsxwdp, xvcvuxddp, xvcvuxwdp
- xvcvsxdsp, xscvsxwsp, xvcvuxdsp, xvcvuxwsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:34 +04:00
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* stp - source type (float32 or float64)
|
|
|
|
* ttp - target type (int32, uint32, int64 or uint64)
|
|
|
|
* sfld - source vsr_t field
|
|
|
|
* tfld - target vsr_t field
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
* sfi - set FI
|
target-ppc: Add VSX ISA2.06 Integer Conversion Instructions
This patch adds the VSX Integer Conversion instructions defined by
V2.06 of the PowerPC ISA:
- xscvdpsxds, xscvdpsxws, xscvdpuxds, xscvdpuxws
- xvcvdpsxds, xvcvdpsxws, xvcvdpuxds, xvcvdpuxws
- xvcvspsxds, xvcvspsxws, xvcvspuxds, xvcvspuxws
- xscvsxddp, xscvuxddp
- xvcvsxddp, xscvsxwdp, xvcvuxddp, xvcvuxwdp
- xvcvsxdsp, xscvsxwsp, xvcvuxdsp, xvcvuxwsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:34 +04:00
|
|
|
* rnan - resulting NaN
|
|
|
|
*/
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
#define VSX_CVT_FP_TO_INT(op, nels, stp, ttp, sfld, tfld, sfi, rnan) \
|
2019-06-16 15:37:43 +03:00
|
|
|
void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
|
target-ppc: Add VSX ISA2.06 Integer Conversion Instructions
This patch adds the VSX Integer Conversion instructions defined by
V2.06 of the PowerPC ISA:
- xscvdpsxds, xscvdpsxws, xscvdpuxds, xscvdpuxws
- xvcvdpsxds, xvcvdpsxws, xvcvdpuxds, xvcvdpuxws
- xvcvspsxds, xvcvspsxws, xvcvspuxds, xvcvspuxws
- xscvsxddp, xscvuxddp
- xvcvsxddp, xscvsxwdp, xvcvuxddp, xvcvuxwdp
- xvcvsxdsp, xscvsxwsp, xvcvuxdsp, xvcvuxwsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:34 +04:00
|
|
|
{ \
|
2022-02-09 11:08:56 +03:00
|
|
|
ppc_vsr_t t = { }; \
|
2022-09-06 15:55:23 +03:00
|
|
|
int i, flags; \
|
|
|
|
\
|
|
|
|
helper_reset_fpstatus(env); \
|
target-ppc: Add VSX ISA2.06 Integer Conversion Instructions
This patch adds the VSX Integer Conversion instructions defined by
V2.06 of the PowerPC ISA:
- xscvdpsxds, xscvdpsxws, xscvdpuxds, xscvdpuxws
- xvcvdpsxds, xvcvdpsxws, xvcvdpuxds, xvcvdpuxws
- xvcvspsxds, xvcvspsxws, xvcvspuxds, xvcvspuxws
- xscvsxddp, xscvuxddp
- xvcvsxddp, xscvsxwdp, xvcvuxddp, xvcvuxwdp
- xvcvsxdsp, xscvsxwsp, xvcvuxdsp, xvcvuxwsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:34 +04:00
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.tfld = stp##_to_##ttp##_round_to_zero(xb->sfld, &env->fp_status); \
|
2018-10-12 02:41:59 +03:00
|
|
|
flags = env->fp_status.float_exception_flags; \
|
|
|
|
if (unlikely(flags & float_flag_invalid)) { \
|
2021-12-17 19:57:14 +03:00
|
|
|
t.tfld = float_invalid_cvt(env, flags, t.tfld, rnan, 0, GETPC());\
|
target-ppc: Add VSX ISA2.06 Integer Conversion Instructions
This patch adds the VSX Integer Conversion instructions defined by
V2.06 of the PowerPC ISA:
- xscvdpsxds, xscvdpsxws, xscvdpuxds, xscvdpuxws
- xvcvdpsxds, xvcvdpsxws, xvcvdpuxds, xvcvdpuxws
- xvcvspsxds, xvcvspsxws, xvcvspuxds, xvcvspuxws
- xscvsxddp, xscvuxddp
- xvcvsxddp, xscvsxwdp, xvcvuxddp, xvcvuxwdp
- xvcvsxdsp, xscvsxwsp, xvcvuxdsp, xvcvuxwsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:34 +04:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t; \
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, sfi, GETPC()); \
|
target-ppc: Add VSX ISA2.06 Integer Conversion Instructions
This patch adds the VSX Integer Conversion instructions defined by
V2.06 of the PowerPC ISA:
- xscvdpsxds, xscvdpsxws, xscvdpuxds, xscvdpuxws
- xvcvdpsxds, xvcvdpsxws, xvcvdpuxds, xvcvdpuxws
- xvcvspsxds, xvcvspsxws, xvcvspuxds, xvcvspuxws
- xscvsxddp, xscvuxddp
- xvcvsxddp, xscvsxwdp, xvcvuxddp, xvcvuxwdp
- xvcvsxdsp, xscvsxwsp, xvcvuxdsp, xvcvuxwsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:34 +04:00
|
|
|
}
|
|
|
|
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
VSX_CVT_FP_TO_INT(xscvdpsxds, 1, float64, int64, VsrD(0), VsrD(0), true, \
|
2014-02-24 18:12:13 +04:00
|
|
|
0x8000000000000000ULL)
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
VSX_CVT_FP_TO_INT(xscvdpuxds, 1, float64, uint64, VsrD(0), VsrD(0), true, 0ULL)
|
|
|
|
VSX_CVT_FP_TO_INT(xvcvdpsxds, 2, float64, int64, VsrD(i), VsrD(i), false, \
|
2014-02-24 18:12:13 +04:00
|
|
|
0x8000000000000000ULL)
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
VSX_CVT_FP_TO_INT(xvcvdpuxds, 2, float64, uint64, VsrD(i), VsrD(i), false, \
|
|
|
|
0ULL)
|
|
|
|
VSX_CVT_FP_TO_INT(xvcvspsxds, 2, float32, int64, VsrW(2 * i), VsrD(i), false, \
|
2014-04-01 01:04:02 +04:00
|
|
|
0x8000000000000000ULL)
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
VSX_CVT_FP_TO_INT(xvcvspsxws, 4, float32, int32, VsrW(i), VsrW(i), false, \
|
|
|
|
0x80000000ULL)
|
|
|
|
VSX_CVT_FP_TO_INT(xvcvspuxds, 2, float32, uint64, VsrW(2 * i), VsrD(i), \
|
|
|
|
false, 0ULL)
|
|
|
|
VSX_CVT_FP_TO_INT(xvcvspuxws, 4, float32, uint32, VsrW(i), VsrW(i), false, 0U)
|
target-ppc: Add VSX ISA2.06 Integer Conversion Instructions
This patch adds the VSX Integer Conversion instructions defined by
V2.06 of the PowerPC ISA:
- xscvdpsxds, xscvdpsxws, xscvdpuxds, xscvdpuxws
- xvcvdpsxds, xvcvdpsxws, xvcvdpuxds, xvcvdpuxws
- xvcvspsxds, xvcvspsxws, xvcvspuxds, xvcvspuxws
- xscvsxddp, xscvuxddp
- xvcvsxddp, xscvsxwdp, xvcvuxddp, xvcvuxwdp
- xvcvsxdsp, xscvsxwsp, xvcvuxdsp, xvcvuxwsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:34 +04:00
|
|
|
|
2022-03-30 20:59:32 +03:00
|
|
|
#define VSX_CVT_FP_TO_INT128(op, tp, rnan) \
|
|
|
|
void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t t; \
|
|
|
|
int flags; \
|
|
|
|
\
|
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
t.s128 = float128_to_##tp##_round_to_zero(xb->f128, &env->fp_status); \
|
|
|
|
flags = get_float_exception_flags(&env->fp_status); \
|
|
|
|
if (unlikely(flags & float_flag_invalid)) { \
|
|
|
|
t.VsrD(0) = float_invalid_cvt(env, flags, t.VsrD(0), rnan, 0, GETPC());\
|
|
|
|
t.VsrD(1) = -(t.VsrD(0) & 1); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
*xt = t; \
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, true, GETPC()); \
|
2022-03-30 20:59:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VSX_CVT_FP_TO_INT128(XSCVQPUQZ, uint128, 0)
|
|
|
|
VSX_CVT_FP_TO_INT128(XSCVQPSQZ, int128, 0x8000000000000000ULL);
|
|
|
|
|
2022-03-21 01:35:27 +03:00
|
|
|
/*
|
|
|
|
* Likewise, except that the result is duplicated into both subwords.
|
|
|
|
* Power ISA v3.1 has Programming Notes for these insns:
|
|
|
|
* Previous versions of the architecture allowed the contents of
|
|
|
|
* word 0 of the result register to be undefined. However, all
|
|
|
|
* processors that support this instruction write the result into
|
|
|
|
* words 0 and 1 (and words 2 and 3) of the result register, as
|
|
|
|
* is required by this version of the architecture.
|
|
|
|
*/
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
#define VSX_CVT_FP_TO_INT2(op, nels, stp, ttp, sfi, rnan) \
|
2022-03-21 01:35:27 +03:00
|
|
|
void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t t = { }; \
|
2022-09-06 15:55:23 +03:00
|
|
|
int i, flags; \
|
|
|
|
\
|
|
|
|
helper_reset_fpstatus(env); \
|
2022-03-21 01:35:27 +03:00
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
|
|
|
t.VsrW(2 * i) = stp##_to_##ttp##_round_to_zero(xb->VsrD(i), \
|
|
|
|
&env->fp_status); \
|
|
|
|
flags = env->fp_status.float_exception_flags; \
|
|
|
|
if (unlikely(flags & float_flag_invalid)) { \
|
|
|
|
t.VsrW(2 * i) = float_invalid_cvt(env, flags, t.VsrW(2 * i), \
|
|
|
|
rnan, 0, GETPC()); \
|
|
|
|
} \
|
|
|
|
t.VsrW(2 * i + 1) = t.VsrW(2 * i); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
*xt = t; \
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, sfi, GETPC()); \
|
2022-03-21 01:35:27 +03:00
|
|
|
}
|
|
|
|
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
VSX_CVT_FP_TO_INT2(xscvdpsxws, 1, float64, int32, true, 0x80000000U)
|
|
|
|
VSX_CVT_FP_TO_INT2(xscvdpuxws, 1, float64, uint32, true, 0U)
|
|
|
|
VSX_CVT_FP_TO_INT2(xvcvdpsxws, 2, float64, int32, false, 0x80000000U)
|
|
|
|
VSX_CVT_FP_TO_INT2(xvcvdpuxws, 2, float64, uint32, false, 0U)
|
2022-03-21 01:35:27 +03:00
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
* VSX_CVT_FP_TO_INT_VECTOR - VSX floating point to integer conversion
|
2017-01-10 11:50:43 +03:00
|
|
|
* op - instruction mnemonic
|
|
|
|
* stp - source type (float32 or float64)
|
|
|
|
* ttp - target type (int32, uint32, int64 or uint64)
|
|
|
|
* sfld - source vsr_t field
|
|
|
|
* tfld - target vsr_t field
|
|
|
|
* rnan - resulting NaN
|
|
|
|
*/
|
|
|
|
#define VSX_CVT_FP_TO_INT_VECTOR(op, stp, ttp, sfld, tfld, rnan) \
|
2019-06-16 15:37:47 +03:00
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode, \
|
|
|
|
ppc_vsr_t *xt, ppc_vsr_t *xb) \
|
2017-01-10 11:50:43 +03:00
|
|
|
{ \
|
2019-06-16 15:37:37 +03:00
|
|
|
ppc_vsr_t t = { }; \
|
2021-12-17 19:57:14 +03:00
|
|
|
int flags; \
|
2017-01-10 11:50:43 +03:00
|
|
|
\
|
2022-09-06 15:55:23 +03:00
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
t.tfld = stp##_to_##ttp##_round_to_zero(xb->sfld, &env->fp_status); \
|
2021-12-17 19:57:14 +03:00
|
|
|
flags = get_float_exception_flags(&env->fp_status); \
|
|
|
|
if (flags & float_flag_invalid) { \
|
2021-12-17 19:57:14 +03:00
|
|
|
t.tfld = float_invalid_cvt(env, flags, t.tfld, rnan, 0, GETPC()); \
|
2017-01-10 11:50:43 +03:00
|
|
|
} \
|
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t; \
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, true, GETPC()); \
|
2017-01-10 11:50:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VSX_CVT_FP_TO_INT_VECTOR(xscvqpsdz, float128, int64, f128, VsrD(0), \
|
|
|
|
0x8000000000000000ULL)
|
|
|
|
VSX_CVT_FP_TO_INT_VECTOR(xscvqpswz, float128, int32, f128, VsrD(0), \
|
|
|
|
0xffffffff80000000ULL)
|
2017-02-10 10:23:09 +03:00
|
|
|
VSX_CVT_FP_TO_INT_VECTOR(xscvqpudz, float128, uint64, f128, VsrD(0), 0x0ULL)
|
|
|
|
VSX_CVT_FP_TO_INT_VECTOR(xscvqpuwz, float128, uint32, f128, VsrD(0), 0x0ULL)
|
2017-01-10 11:50:43 +03:00
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
* VSX_CVT_INT_TO_FP - VSX integer to floating point conversion
|
target-ppc: Add VSX ISA2.06 Integer Conversion Instructions
This patch adds the VSX Integer Conversion instructions defined by
V2.06 of the PowerPC ISA:
- xscvdpsxds, xscvdpsxws, xscvdpuxds, xscvdpuxws
- xvcvdpsxds, xvcvdpsxws, xvcvdpuxds, xvcvdpuxws
- xvcvspsxds, xvcvspsxws, xvcvspuxds, xvcvspuxws
- xscvsxddp, xscvuxddp
- xvcvsxddp, xscvsxwdp, xvcvuxddp, xvcvuxwdp
- xvcvsxdsp, xscvsxwsp, xvcvuxdsp, xvcvuxwsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:34 +04:00
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* stp - source type (int32, uint32, int64 or uint64)
|
|
|
|
* ttp - target type (float32 or float64)
|
|
|
|
* sfld - source vsr_t field
|
|
|
|
* tfld - target vsr_t field
|
|
|
|
* jdef - definition of the j index (i or 2*i)
|
2022-05-17 19:15:22 +03:00
|
|
|
* sfifprf - set FI and FPRF
|
target-ppc: Add VSX ISA2.06 Integer Conversion Instructions
This patch adds the VSX Integer Conversion instructions defined by
V2.06 of the PowerPC ISA:
- xscvdpsxds, xscvdpsxws, xscvdpuxds, xscvdpuxws
- xvcvdpsxds, xvcvdpsxws, xvcvdpuxds, xvcvdpuxws
- xvcvspsxds, xvcvspsxws, xvcvspuxds, xvcvspuxws
- xscvsxddp, xscvuxddp
- xvcvsxddp, xscvsxwdp, xvcvuxddp, xvcvuxwdp
- xvcvsxdsp, xscvsxwsp, xvcvuxdsp, xvcvuxwsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:34 +04:00
|
|
|
*/
|
2022-05-17 19:15:22 +03:00
|
|
|
#define VSX_CVT_INT_TO_FP(op, nels, stp, ttp, sfld, tfld, sfifprf, r2sp)\
|
2019-06-16 15:37:43 +03:00
|
|
|
void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
|
target-ppc: Add VSX ISA2.06 Integer Conversion Instructions
This patch adds the VSX Integer Conversion instructions defined by
V2.06 of the PowerPC ISA:
- xscvdpsxds, xscvdpsxws, xscvdpuxds, xscvdpuxws
- xvcvdpsxds, xvcvdpsxws, xvcvdpuxds, xvcvdpuxws
- xvcvspsxds, xvcvspsxws, xvcvspuxds, xvcvspuxws
- xscvsxddp, xscvuxddp
- xvcvsxddp, xscvsxwdp, xvcvuxddp, xvcvuxwdp
- xvcvsxdsp, xscvsxwsp, xvcvuxdsp, xvcvuxwsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:34 +04:00
|
|
|
{ \
|
2022-02-09 11:08:56 +03:00
|
|
|
ppc_vsr_t t = { }; \
|
target-ppc: Add VSX ISA2.06 Integer Conversion Instructions
This patch adds the VSX Integer Conversion instructions defined by
V2.06 of the PowerPC ISA:
- xscvdpsxds, xscvdpsxws, xscvdpuxds, xscvdpuxws
- xvcvdpsxds, xvcvdpsxws, xvcvdpuxds, xvcvdpuxws
- xvcvspsxds, xvcvspsxws, xvcvspuxds, xvcvspuxws
- xscvsxddp, xscvuxddp
- xvcvsxddp, xscvsxwdp, xvcvuxddp, xvcvuxwdp
- xvcvsxdsp, xscvsxwsp, xvcvuxdsp, xvcvuxwsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:34 +04:00
|
|
|
int i; \
|
|
|
|
\
|
2022-09-06 15:55:23 +03:00
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
target-ppc: Add VSX ISA2.06 Integer Conversion Instructions
This patch adds the VSX Integer Conversion instructions defined by
V2.06 of the PowerPC ISA:
- xscvdpsxds, xscvdpsxws, xscvdpuxds, xscvdpuxws
- xvcvdpsxds, xvcvdpsxws, xvcvdpuxds, xvcvdpuxws
- xvcvspsxds, xvcvspsxws, xvcvspuxds, xvcvspuxws
- xscvsxddp, xscvuxddp
- xvcvsxddp, xscvsxwdp, xvcvuxddp, xvcvuxwdp
- xvcvsxdsp, xscvsxwsp, xvcvuxdsp, xvcvuxwsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:34 +04:00
|
|
|
for (i = 0; i < nels; i++) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.tfld = stp##_to_##ttp(xb->sfld, &env->fp_status); \
|
2014-01-15 18:10:40 +04:00
|
|
|
if (r2sp) { \
|
2021-12-17 19:57:15 +03:00
|
|
|
t.tfld = do_frsp(env, t.tfld, GETPC()); \
|
2014-01-15 18:10:40 +04:00
|
|
|
} \
|
2022-05-17 19:15:22 +03:00
|
|
|
if (sfifprf) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_float64(env, t.tfld); \
|
target-ppc: Add VSX ISA2.06 Integer Conversion Instructions
This patch adds the VSX Integer Conversion instructions defined by
V2.06 of the PowerPC ISA:
- xscvdpsxds, xscvdpsxws, xscvdpuxds, xscvdpuxws
- xvcvdpsxds, xvcvdpsxws, xvcvdpuxds, xvcvdpuxws
- xvcvspsxds, xvcvspsxws, xvcvspuxds, xvcvspuxws
- xscvsxddp, xscvuxddp
- xvcvsxddp, xscvsxwdp, xvcvuxddp, xvcvuxwdp
- xvcvsxdsp, xscvsxwsp, xvcvuxdsp, xvcvuxwsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:34 +04:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t; \
|
2022-05-17 19:15:22 +03:00
|
|
|
do_float_check_status(env, sfifprf, GETPC()); \
|
target-ppc: Add VSX ISA2.06 Integer Conversion Instructions
This patch adds the VSX Integer Conversion instructions defined by
V2.06 of the PowerPC ISA:
- xscvdpsxds, xscvdpsxws, xscvdpuxds, xscvdpuxws
- xvcvdpsxds, xvcvdpsxws, xvcvdpuxds, xvcvdpuxws
- xvcvspsxds, xvcvspsxws, xvcvspuxds, xvcvspuxws
- xscvsxddp, xscvuxddp
- xvcvsxddp, xscvsxwdp, xvcvuxddp, xvcvuxwdp
- xvcvsxdsp, xscvsxwsp, xvcvuxdsp, xvcvuxwsp
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:34 +04:00
|
|
|
}
|
|
|
|
|
2014-04-01 01:04:03 +04:00
|
|
|
VSX_CVT_INT_TO_FP(xscvsxddp, 1, int64, float64, VsrD(0), VsrD(0), 1, 0)
|
|
|
|
VSX_CVT_INT_TO_FP(xscvuxddp, 1, uint64, float64, VsrD(0), VsrD(0), 1, 0)
|
|
|
|
VSX_CVT_INT_TO_FP(xscvsxdsp, 1, int64, float64, VsrD(0), VsrD(0), 1, 1)
|
|
|
|
VSX_CVT_INT_TO_FP(xscvuxdsp, 1, uint64, float64, VsrD(0), VsrD(0), 1, 1)
|
|
|
|
VSX_CVT_INT_TO_FP(xvcvsxddp, 2, int64, float64, VsrD(i), VsrD(i), 0, 0)
|
|
|
|
VSX_CVT_INT_TO_FP(xvcvuxddp, 2, uint64, float64, VsrD(i), VsrD(i), 0, 0)
|
2019-03-21 09:01:06 +03:00
|
|
|
VSX_CVT_INT_TO_FP(xvcvsxwdp, 2, int32, float64, VsrW(2 * i), VsrD(i), 0, 0)
|
|
|
|
VSX_CVT_INT_TO_FP(xvcvuxwdp, 2, uint64, float64, VsrW(2 * i), VsrD(i), 0, 0)
|
2014-04-01 01:04:03 +04:00
|
|
|
VSX_CVT_INT_TO_FP(xvcvsxwsp, 4, int32, float32, VsrW(i), VsrW(i), 0, 0)
|
|
|
|
VSX_CVT_INT_TO_FP(xvcvuxwsp, 4, uint32, float32, VsrW(i), VsrW(i), 0, 0)
|
target-ppc: Add VSX Rounding Instructions
This patch adds the VSX Round to Floating Point Integer instructions:
- xsrdpi, xsrdpic, xsrdpim, xsrdpip, xsrdpiz
- xvrdpi, xvrdpic, xvrdpim, xvrdpip, xvrdpiz
- xvrspi, xvrspic, xvrspim, xvrspip, xvrspiz
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:35 +04:00
|
|
|
|
2022-03-21 01:35:27 +03:00
|
|
|
#define VSX_CVT_INT_TO_FP2(op, stp, ttp) \
|
|
|
|
void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t t = { }; \
|
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
for (i = 0; i < 2; i++) { \
|
|
|
|
t.VsrW(2 * i) = stp##_to_##ttp(xb->VsrD(i), &env->fp_status); \
|
|
|
|
t.VsrW(2 * i + 1) = t.VsrW(2 * i); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
*xt = t; \
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, false, GETPC()); \
|
2022-03-21 01:35:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VSX_CVT_INT_TO_FP2(xvcvsxdsp, int64, float32)
|
|
|
|
VSX_CVT_INT_TO_FP2(xvcvuxdsp, uint64, float32)
|
|
|
|
|
2022-03-30 20:59:31 +03:00
|
|
|
#define VSX_CVT_INT128_TO_FP(op, tp) \
|
|
|
|
void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb)\
|
|
|
|
{ \
|
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
xt->f128 = tp##_to_float128(xb->s128, &env->fp_status); \
|
|
|
|
helper_compute_fprf_float128(env, xt->f128); \
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, true, GETPC()); \
|
2022-03-30 20:59:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VSX_CVT_INT128_TO_FP(XSCVUQQP, uint128);
|
|
|
|
VSX_CVT_INT128_TO_FP(XSCVSQQP, int128);
|
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
* VSX_CVT_INT_TO_FP_VECTOR - VSX integer to floating point conversion
|
2017-01-12 19:24:06 +03:00
|
|
|
* op - instruction mnemonic
|
|
|
|
* stp - source type (int32, uint32, int64 or uint64)
|
|
|
|
* ttp - target type (float32 or float64)
|
|
|
|
* sfld - source vsr_t field
|
|
|
|
* tfld - target vsr_t field
|
|
|
|
*/
|
|
|
|
#define VSX_CVT_INT_TO_FP_VECTOR(op, stp, ttp, sfld, tfld) \
|
2019-06-16 15:37:47 +03:00
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode, \
|
|
|
|
ppc_vsr_t *xt, ppc_vsr_t *xb) \
|
2017-01-12 19:24:06 +03:00
|
|
|
{ \
|
2019-06-16 15:37:37 +03:00
|
|
|
ppc_vsr_t t = *xt; \
|
2017-01-12 19:24:06 +03:00
|
|
|
\
|
2022-09-06 15:55:23 +03:00
|
|
|
helper_reset_fpstatus(env); \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.tfld = stp##_to_##ttp(xb->sfld, &env->fp_status); \
|
|
|
|
helper_compute_fprf_##ttp(env, t.tfld); \
|
2017-01-12 19:24:06 +03:00
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t; \
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, true, GETPC()); \
|
2017-01-12 19:24:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VSX_CVT_INT_TO_FP_VECTOR(xscvsdqp, int64, float128, VsrD(0), f128)
|
|
|
|
VSX_CVT_INT_TO_FP_VECTOR(xscvudqp, uint64, float128, VsrD(0), f128)
|
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
* For "use current rounding mode", define a value that will not be
|
|
|
|
* one of the existing rounding model enums.
|
target-ppc: Add VSX Rounding Instructions
This patch adds the VSX Round to Floating Point Integer instructions:
- xsrdpi, xsrdpic, xsrdpim, xsrdpip, xsrdpiz
- xvrdpi, xvrdpic, xvrdpim, xvrdpip, xvrdpiz
- xvrspi, xvrspic, xvrspim, xvrspip, xvrspiz
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:35 +04:00
|
|
|
*/
|
|
|
|
#define FLOAT_ROUND_CURRENT (float_round_nearest_even + float_round_down + \
|
|
|
|
float_round_up + float_round_to_zero)
|
|
|
|
|
2019-03-21 09:01:06 +03:00
|
|
|
/*
|
|
|
|
* VSX_ROUND - VSX floating point round
|
target-ppc: Add VSX Rounding Instructions
This patch adds the VSX Round to Floating Point Integer instructions:
- xsrdpi, xsrdpic, xsrdpim, xsrdpip, xsrdpiz
- xvrdpi, xvrdpic, xvrdpim, xvrdpip, xvrdpiz
- xvrspi, xvrspic, xvrspim, xvrspip, xvrspiz
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:35 +04:00
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 01:03:59 +04:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
target-ppc: Add VSX Rounding Instructions
This patch adds the VSX Round to Floating Point Integer instructions:
- xsrdpi, xsrdpic, xsrdpim, xsrdpip, xsrdpiz
- xvrdpi, xvrdpic, xvrdpim, xvrdpip, xvrdpiz
- xvrspi, xvrspic, xvrspim, xvrspip, xvrspiz
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:35 +04:00
|
|
|
* rmode - rounding mode
|
2022-05-17 19:15:22 +03:00
|
|
|
* sfifprf - set FI and FPRF
|
target-ppc: Add VSX Rounding Instructions
This patch adds the VSX Round to Floating Point Integer instructions:
- xsrdpi, xsrdpic, xsrdpim, xsrdpip, xsrdpiz
- xvrdpi, xvrdpic, xvrdpim, xvrdpip, xvrdpiz
- xvrspi, xvrspic, xvrspim, xvrspip, xvrspiz
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:35 +04:00
|
|
|
*/
|
2022-05-17 19:15:22 +03:00
|
|
|
#define VSX_ROUND(op, nels, tp, fld, rmode, sfifprf) \
|
2019-06-16 15:37:43 +03:00
|
|
|
void helper_##op(CPUPPCState *env, ppc_vsr_t *xt, ppc_vsr_t *xb) \
|
target-ppc: Add VSX Rounding Instructions
This patch adds the VSX Round to Floating Point Integer instructions:
- xsrdpi, xsrdpic, xsrdpim, xsrdpip, xsrdpiz
- xvrdpi, xvrdpic, xvrdpim, xvrdpip, xvrdpiz
- xvrspi, xvrspic, xvrspim, xvrspip, xvrspiz
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:35 +04:00
|
|
|
{ \
|
2022-02-09 11:08:56 +03:00
|
|
|
ppc_vsr_t t = { }; \
|
target-ppc: Add VSX Rounding Instructions
This patch adds the VSX Round to Floating Point Integer instructions:
- xsrdpi, xsrdpic, xsrdpim, xsrdpip, xsrdpiz
- xvrdpi, xvrdpic, xvrdpim, xvrdpip, xvrdpiz
- xvrspi, xvrspic, xvrspim, xvrspip, xvrspiz
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:35 +04:00
|
|
|
int i; \
|
2021-05-21 23:17:53 +03:00
|
|
|
FloatRoundMode curr_rounding_mode; \
|
target-ppc: Add VSX Rounding Instructions
This patch adds the VSX Round to Floating Point Integer instructions:
- xsrdpi, xsrdpic, xsrdpim, xsrdpip, xsrdpiz
- xvrdpi, xvrdpic, xvrdpim, xvrdpip, xvrdpiz
- xvrspi, xvrspic, xvrspim, xvrspip, xvrspiz
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:35 +04:00
|
|
|
\
|
2022-09-06 15:55:23 +03:00
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
target-ppc: Add VSX Rounding Instructions
This patch adds the VSX Round to Floating Point Integer instructions:
- xsrdpi, xsrdpic, xsrdpim, xsrdpip, xsrdpiz
- xvrdpi, xvrdpic, xvrdpim, xvrdpip, xvrdpiz
- xvrspi, xvrspic, xvrspim, xvrspip, xvrspiz
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:35 +04:00
|
|
|
if (rmode != FLOAT_ROUND_CURRENT) { \
|
2021-05-21 23:17:53 +03:00
|
|
|
curr_rounding_mode = get_float_rounding_mode(&env->fp_status); \
|
target-ppc: Add VSX Rounding Instructions
This patch adds the VSX Round to Floating Point Integer instructions:
- xsrdpi, xsrdpic, xsrdpim, xsrdpip, xsrdpiz
- xvrdpi, xvrdpic, xvrdpim, xvrdpip, xvrdpiz
- xvrspi, xvrspic, xvrspim, xvrspip, xvrspiz
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:35 +04:00
|
|
|
set_float_rounding_mode(rmode, &env->fp_status); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
if (unlikely(tp##_is_signaling_nan(xb->fld, \
|
softfloat: Implement run-time-configurable meaning of signaling NaN bit
This patch modifies SoftFloat library so that it can be configured in
run-time in relation to the meaning of signaling NaN bit, while, at the
same time, strictly preserving its behavior on all existing platforms.
Background:
In floating-point calculations, there is a need for denoting undefined or
unrepresentable values. This is achieved by defining certain floating-point
numerical values to be NaNs (which stands for "not a number"). For additional
reasons, virtually all modern floating-point unit implementations use two
kinds of NaNs: quiet and signaling. The binary representations of these two
kinds of NaNs, as a rule, differ only in one bit (that bit is, traditionally,
the first bit of mantissa).
Up to 2008, standards for floating-point did not specify all details about
binary representation of NaNs. More specifically, the meaning of the bit
that is used for distinguishing between signaling and quiet NaNs was not
strictly prescribed. (IEEE 754-2008 was the first floating-point standard
that defined that meaning clearly, see [1], p. 35) As a result, different
platforms took different approaches, and that presented considerable
challenge for multi-platform emulators like QEMU.
Mips platform represents the most complex case among QEMU-supported
platforms regarding signaling NaN bit. Up to the Release 6 of Mips
architecture, "1" in signaling NaN bit denoted signaling NaN, which is
opposite to IEEE 754-2008 standard. From Release 6 on, Mips architecture
adopted IEEE standard prescription, and "0" denotes signaling NaN. On top of
that, Mips architecture for SIMD (also known as MSA, or vector instructions)
also specifies signaling bit in accordance to IEEE standard. MSA unit can be
implemented with both pre-Release 6 and Release 6 main processor units.
QEMU uses SoftFloat library to implement various floating-point-related
instructions on all platforms. The current QEMU implementation allows for
defining meaning of signaling NaN bit during build time, and is implemented
via preprocessor macro called SNAN_BIT_IS_ONE.
On the other hand, the change in this patch enables SoftFloat library to be
configured in run-time. This configuration is meant to occur during CPU
initialization, at the moment when it is definitely known what desired
behavior for particular CPU (or any additional FPUs) is.
The change is implemented so that it is consistent with existing
implementation of similar cases. This means that structure float_status is
used for passing the information about desired signaling NaN bit on each
invocation of SoftFloat functions. The additional field in float_status is
called snan_bit_is_one, which supersedes macro SNAN_BIT_IS_ONE.
IMPORTANT:
This change is not meant to create any change in emulator behavior or
functionality on any platform. It just provides the means for SoftFloat
library to be used in a more flexible way - in other words, it will just
prepare SoftFloat library for usage related to Mips platform and its
specifics regarding signaling bit meaning, which is done in some of
subsequent patches from this series.
Further break down of changes:
1) Added field snan_bit_is_one to the structure float_status, and
correspondent setter function set_snan_bit_is_one().
2) Constants <float16|float32|float64|floatx80|float128>_default_nan
(used both internally and externally) converted to functions
<float16|float32|float64|floatx80|float128>_default_nan(float_status*).
This is necessary since they are dependent on signaling bit meaning.
At the same time, for the sake of code cleanup and simplicity, constants
<floatx80|float128>_default_nan_<low|high> (used only internally within
SoftFloat library) are removed, as not needed.
3) Added a float_status* argument to SoftFloat library functions
XXX_is_quiet_nan(XXX a_), XXX_is_signaling_nan(XXX a_),
XXX_maybe_silence_nan(XXX a_). This argument must be present in
order to enable correct invocation of new version of functions
XXX_default_nan(). (XXX is <float16|float32|float64|floatx80|float128>
here)
4) Updated code for all platforms to reflect changes in SoftFloat library.
This change is twofolds: it includes modifications of SoftFloat library
functions invocations, and an addition of invocation of function
set_snan_bit_is_one() during CPU initialization, with arguments that
are appropriate for each particular platform. It was established that
all platforms zero their main CPU data structures, so snan_bit_is_one(0)
in appropriate places is not added, as it is not needed.
[1] "IEEE Standard for Floating-Point Arithmetic",
IEEE Computer Society, August 29, 2008.
Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
Signed-off-by: Maciej W. Rozycki <macro@codesourcery.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Tested-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
Reviewed-by: Leon Alrae <leon.alrae@imgtec.com>
Tested-by: Leon Alrae <leon.alrae@imgtec.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
[leon.alrae@imgtec.com:
* cherry-picked 2 chunks from patch #2 to fix compilation warnings]
Signed-off-by: Leon Alrae <leon.alrae@imgtec.com>
2016-06-10 12:57:28 +03:00
|
|
|
&env->fp_status))) { \
|
2018-10-12 02:41:53 +03:00
|
|
|
float_invalid_op_vxsnan(env, GETPC()); \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.fld = tp##_snan_to_qnan(xb->fld); \
|
target-ppc: Add VSX Rounding Instructions
This patch adds the VSX Round to Floating Point Integer instructions:
- xsrdpi, xsrdpic, xsrdpim, xsrdpip, xsrdpiz
- xvrdpi, xvrdpic, xvrdpim, xvrdpip, xvrdpiz
- xvrspi, xvrspic, xvrspim, xvrspip, xvrspiz
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:35 +04:00
|
|
|
} else { \
|
2019-06-16 15:37:37 +03:00
|
|
|
t.fld = tp##_round_to_int(xb->fld, &env->fp_status); \
|
target-ppc: Add VSX Rounding Instructions
This patch adds the VSX Round to Floating Point Integer instructions:
- xsrdpi, xsrdpic, xsrdpim, xsrdpip, xsrdpiz
- xvrdpi, xvrdpic, xvrdpim, xvrdpip, xvrdpiz
- xvrspi, xvrspic, xvrspim, xvrspip, xvrspiz
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:35 +04:00
|
|
|
} \
|
2022-05-17 19:15:22 +03:00
|
|
|
if (sfifprf) { \
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_float64(env, t.fld); \
|
target-ppc: Add VSX Rounding Instructions
This patch adds the VSX Round to Floating Point Integer instructions:
- xsrdpi, xsrdpic, xsrdpim, xsrdpip, xsrdpiz
- xvrdpi, xvrdpic, xvrdpim, xvrdpip, xvrdpiz
- xvrspi, xvrspic, xvrspim, xvrspip, xvrspiz
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:35 +04:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2019-03-21 09:01:06 +03:00
|
|
|
/* \
|
|
|
|
* If this is not a "use current rounding mode" instruction, \
|
target-ppc: Add VSX Rounding Instructions
This patch adds the VSX Round to Floating Point Integer instructions:
- xsrdpi, xsrdpic, xsrdpim, xsrdpip, xsrdpiz
- xvrdpi, xvrdpic, xvrdpim, xvrdpip, xvrdpiz
- xvrspi, xvrspic, xvrspim, xvrspip, xvrspiz
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:35 +04:00
|
|
|
* then inhibit setting of the XX bit and restore rounding \
|
2019-03-21 09:01:06 +03:00
|
|
|
* mode from FPSCR \
|
|
|
|
*/ \
|
target-ppc: Add VSX Rounding Instructions
This patch adds the VSX Round to Floating Point Integer instructions:
- xsrdpi, xsrdpic, xsrdpim, xsrdpip, xsrdpiz
- xvrdpi, xvrdpic, xvrdpim, xvrdpip, xvrdpiz
- xvrspi, xvrspic, xvrspim, xvrspip, xvrspiz
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:35 +04:00
|
|
|
if (rmode != FLOAT_ROUND_CURRENT) { \
|
2021-05-21 23:17:53 +03:00
|
|
|
set_float_rounding_mode(curr_rounding_mode, &env->fp_status); \
|
target-ppc: Add VSX Rounding Instructions
This patch adds the VSX Round to Floating Point Integer instructions:
- xsrdpi, xsrdpic, xsrdpim, xsrdpip, xsrdpiz
- xvrdpi, xvrdpic, xvrdpim, xvrdpip, xvrdpiz
- xvrspi, xvrspic, xvrspim, xvrspip, xvrspiz
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:35 +04:00
|
|
|
env->fp_status.float_exception_flags &= ~float_flag_inexact; \
|
|
|
|
} \
|
|
|
|
\
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t; \
|
2022-05-17 19:15:22 +03:00
|
|
|
do_float_check_status(env, sfifprf, GETPC()); \
|
target-ppc: Add VSX Rounding Instructions
This patch adds the VSX Round to Floating Point Integer instructions:
- xsrdpi, xsrdpic, xsrdpim, xsrdpip, xsrdpiz
- xvrdpi, xvrdpic, xvrdpim, xvrdpip, xvrdpiz
- xvrspi, xvrspic, xvrspim, xvrspip, xvrspiz
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:35 +04:00
|
|
|
}
|
|
|
|
|
2016-07-04 02:20:12 +03:00
|
|
|
VSX_ROUND(xsrdpi, 1, float64, VsrD(0), float_round_ties_away, 1)
|
2014-04-01 01:03:59 +04:00
|
|
|
VSX_ROUND(xsrdpic, 1, float64, VsrD(0), FLOAT_ROUND_CURRENT, 1)
|
|
|
|
VSX_ROUND(xsrdpim, 1, float64, VsrD(0), float_round_down, 1)
|
|
|
|
VSX_ROUND(xsrdpip, 1, float64, VsrD(0), float_round_up, 1)
|
|
|
|
VSX_ROUND(xsrdpiz, 1, float64, VsrD(0), float_round_to_zero, 1)
|
target-ppc: Add VSX Rounding Instructions
This patch adds the VSX Round to Floating Point Integer instructions:
- xsrdpi, xsrdpic, xsrdpim, xsrdpip, xsrdpiz
- xvrdpi, xvrdpic, xvrdpim, xvrdpip, xvrdpiz
- xvrspi, xvrspic, xvrspim, xvrspip, xvrspiz
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:35 +04:00
|
|
|
|
2016-07-04 02:20:12 +03:00
|
|
|
VSX_ROUND(xvrdpi, 2, float64, VsrD(i), float_round_ties_away, 0)
|
2014-04-01 01:03:59 +04:00
|
|
|
VSX_ROUND(xvrdpic, 2, float64, VsrD(i), FLOAT_ROUND_CURRENT, 0)
|
|
|
|
VSX_ROUND(xvrdpim, 2, float64, VsrD(i), float_round_down, 0)
|
|
|
|
VSX_ROUND(xvrdpip, 2, float64, VsrD(i), float_round_up, 0)
|
|
|
|
VSX_ROUND(xvrdpiz, 2, float64, VsrD(i), float_round_to_zero, 0)
|
target-ppc: Add VSX Rounding Instructions
This patch adds the VSX Round to Floating Point Integer instructions:
- xsrdpi, xsrdpic, xsrdpim, xsrdpip, xsrdpiz
- xvrdpi, xvrdpic, xvrdpim, xvrdpip, xvrdpiz
- xvrspi, xvrspic, xvrspim, xvrspip, xvrspiz
Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-03 02:21:35 +04:00
|
|
|
|
2016-07-04 02:20:12 +03:00
|
|
|
VSX_ROUND(xvrspi, 4, float32, VsrW(i), float_round_ties_away, 0)
|
2014-04-01 01:03:59 +04:00
|
|
|
VSX_ROUND(xvrspic, 4, float32, VsrW(i), FLOAT_ROUND_CURRENT, 0)
|
|
|
|
VSX_ROUND(xvrspim, 4, float32, VsrW(i), float_round_down, 0)
|
|
|
|
VSX_ROUND(xvrspip, 4, float32, VsrW(i), float_round_up, 0)
|
|
|
|
VSX_ROUND(xvrspiz, 4, float32, VsrW(i), float_round_to_zero, 0)
|
2014-01-15 18:10:44 +04:00
|
|
|
|
|
|
|
uint64_t helper_xsrsp(CPUPPCState *env, uint64_t xb)
|
|
|
|
{
|
|
|
|
helper_reset_fpstatus(env);
|
|
|
|
|
2021-12-17 19:57:15 +03:00
|
|
|
uint64_t xt = do_frsp(env, xb, GETPC());
|
2014-01-15 18:10:44 +04:00
|
|
|
|
2017-01-06 09:14:47 +03:00
|
|
|
helper_compute_fprf_float64(env, xt);
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, true, GETPC());
|
2014-01-15 18:10:44 +04:00
|
|
|
return xt;
|
|
|
|
}
|
2016-12-07 21:25:02 +03:00
|
|
|
|
2022-05-17 15:39:24 +03:00
|
|
|
void helper_XVXSIGSP(ppc_vsr_t *xt, ppc_vsr_t *xb)
|
2017-01-10 11:50:41 +03:00
|
|
|
{
|
2019-06-16 15:37:37 +03:00
|
|
|
ppc_vsr_t t = { };
|
2017-01-10 11:50:41 +03:00
|
|
|
uint32_t exp, i, fraction;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
2019-06-16 15:37:37 +03:00
|
|
|
exp = (xb->VsrW(i) >> 23) & 0xFF;
|
|
|
|
fraction = xb->VsrW(i) & 0x7FFFFF;
|
2017-01-10 11:50:41 +03:00
|
|
|
if (exp != 0 && exp != 255) {
|
2019-06-16 15:37:37 +03:00
|
|
|
t.VsrW(i) = fraction | 0x00800000;
|
2017-01-10 11:50:41 +03:00
|
|
|
} else {
|
2019-06-16 15:37:37 +03:00
|
|
|
t.VsrW(i) = fraction;
|
2017-01-10 11:50:41 +03:00
|
|
|
}
|
|
|
|
}
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t;
|
2017-01-10 11:50:41 +03:00
|
|
|
}
|
2017-01-13 12:23:39 +03:00
|
|
|
|
target/ppc: Moved XVTSTDC[DS]P to decodetree
Moved XVTSTDCSP and XVTSTDCDP to decodetree an restructured the helper
to be simpler and do all decoding in the decodetree (so XB, XT and DCMX
are all calculated outside the helper).
Obs: The tests in this one are slightly different, these are the sum of
these instructions with all possible immediate and those instructions
are repeated 10 times.
xvtstdcsp:
rept loop master patch
8 12500 2,76402100 2,70699100 (-2.1%)
25 4000 2,64867100 2,67884100 (+1.1%)
100 1000 2,73806300 2,78701000 (+1.8%)
500 200 3,44666500 3,61027600 (+4.7%)
2500 40 5,85790200 6,47475500 (+10.5%)
8000 12 15,22102100 17,46062900 (+14.7%)
xvtstdcdp:
rept loop master patch
8 12500 2,11818000 1,61065300 (-24.0%)
25 4000 2,04573400 1,60132200 (-21.7%)
100 1000 2,13834100 1,69988100 (-20.5%)
500 200 2,73977000 2,48631700 (-9.3%)
2500 40 5,05067000 5,25914100 (+4.1%)
8000 12 14,60507800 15,93704900 (+9.1%)
Signed-off-by: Lucas Mateus Castro (alqotel) <lucas.araujo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20221019125040.48028-11-lucas.araujo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-10-19 15:50:38 +03:00
|
|
|
#define VSX_TSTDC(tp) \
|
|
|
|
static int32_t tp##_tstdc(tp b, uint32_t dcmx) \
|
|
|
|
{ \
|
|
|
|
uint32_t match = 0; \
|
|
|
|
uint32_t sign = tp##_is_neg(b); \
|
|
|
|
if (tp##_is_any_nan(b)) { \
|
|
|
|
match = extract32(dcmx, 6, 1); \
|
|
|
|
} else if (tp##_is_infinity(b)) { \
|
|
|
|
match = extract32(dcmx, 4 + !sign, 1); \
|
|
|
|
} else if (tp##_is_zero(b)) { \
|
|
|
|
match = extract32(dcmx, 2 + !sign, 1); \
|
|
|
|
} else if (tp##_is_zero_or_denormal(b)) { \
|
|
|
|
match = extract32(dcmx, 0 + !sign, 1); \
|
|
|
|
} \
|
|
|
|
return (match != 0); \
|
|
|
|
}
|
|
|
|
|
|
|
|
VSX_TSTDC(float32)
|
|
|
|
VSX_TSTDC(float64)
|
target/ppc: Moved XSTSTDC[QDS]P to decodetree
Moved XSTSTDCSP, XSTSTDCDP and XSTSTDCQP to decodetree and moved some of
its decoding away from the helper as previously the DCMX, XB and BF were
calculated in the helper with the help of cpu_env, now that part was
moved to the decodetree with the rest.
xvtstdcsp:
rept loop master patch
8 12500 1,85393600 1,94683600 (+5.0%)
25 4000 1,78779800 1,92479000 (+7.7%)
100 1000 2,12775000 2,28895500 (+7.6%)
500 200 2,99655300 3,23102900 (+7.8%)
2500 40 6,89082200 7,44827500 (+8.1%)
8000 12 17,50585500 18,95152100 (+8.3%)
xvtstdcdp:
rept loop master patch
8 12500 1,39043100 1,33539800 (-4.0%)
25 4000 1,35731800 1,37347800 (+1.2%)
100 1000 1,51514800 1,56053000 (+3.0%)
500 200 2,21014400 2,47906000 (+12.2%)
2500 40 5,39488200 6,68766700 (+24.0%)
8000 12 13,98623900 18,17661900 (+30.0%)
xvtstdcdp:
rept loop master patch
8 12500 1,35123800 1,34455800 (-0.5%)
25 4000 1,36441200 1,36759600 (+0.2%)
100 1000 1,49763500 1,54138400 (+2.9%)
500 200 2,19020200 2,46196400 (+12.4%)
2500 40 5,39265700 6,68147900 (+23.9%)
8000 12 14,04163600 18,19669600 (+29.6%)
As some values are now decoded outside the helper and passed to it as an
argument the number of arguments of the helper increased, the number
of TCGop needed to load the arguments increased. I suspect that's why
the slow-down in the tests with a high REPT but low LOOP.
Signed-off-by: Lucas Mateus Castro (alqotel) <lucas.araujo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20221019125040.48028-12-lucas.araujo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-10-19 15:50:39 +03:00
|
|
|
VSX_TSTDC(float128)
|
target/ppc: Moved XVTSTDC[DS]P to decodetree
Moved XVTSTDCSP and XVTSTDCDP to decodetree an restructured the helper
to be simpler and do all decoding in the decodetree (so XB, XT and DCMX
are all calculated outside the helper).
Obs: The tests in this one are slightly different, these are the sum of
these instructions with all possible immediate and those instructions
are repeated 10 times.
xvtstdcsp:
rept loop master patch
8 12500 2,76402100 2,70699100 (-2.1%)
25 4000 2,64867100 2,67884100 (+1.1%)
100 1000 2,73806300 2,78701000 (+1.8%)
500 200 3,44666500 3,61027600 (+4.7%)
2500 40 5,85790200 6,47475500 (+10.5%)
8000 12 15,22102100 17,46062900 (+14.7%)
xvtstdcdp:
rept loop master patch
8 12500 2,11818000 1,61065300 (-24.0%)
25 4000 2,04573400 1,60132200 (-21.7%)
100 1000 2,13834100 1,69988100 (-20.5%)
500 200 2,73977000 2,48631700 (-9.3%)
2500 40 5,05067000 5,25914100 (+4.1%)
8000 12 14,60507800 15,93704900 (+9.1%)
Signed-off-by: Lucas Mateus Castro (alqotel) <lucas.araujo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20221019125040.48028-11-lucas.araujo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-10-19 15:50:38 +03:00
|
|
|
#undef VSX_TSTDC
|
|
|
|
|
|
|
|
void helper_XVTSTDCDP(ppc_vsr_t *t, ppc_vsr_t *b, uint64_t dcmx, uint32_t v)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
t->s64[i] = (int64_t)-float64_tstdc(b->f64[i], dcmx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void helper_XVTSTDCSP(ppc_vsr_t *t, ppc_vsr_t *b, uint64_t dcmx, uint32_t v)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
t->s32[i] = (int32_t)-float32_tstdc(b->f32[i], dcmx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
target/ppc: Moved XSTSTDC[QDS]P to decodetree
Moved XSTSTDCSP, XSTSTDCDP and XSTSTDCQP to decodetree and moved some of
its decoding away from the helper as previously the DCMX, XB and BF were
calculated in the helper with the help of cpu_env, now that part was
moved to the decodetree with the rest.
xvtstdcsp:
rept loop master patch
8 12500 1,85393600 1,94683600 (+5.0%)
25 4000 1,78779800 1,92479000 (+7.7%)
100 1000 2,12775000 2,28895500 (+7.6%)
500 200 2,99655300 3,23102900 (+7.8%)
2500 40 6,89082200 7,44827500 (+8.1%)
8000 12 17,50585500 18,95152100 (+8.3%)
xvtstdcdp:
rept loop master patch
8 12500 1,39043100 1,33539800 (-4.0%)
25 4000 1,35731800 1,37347800 (+1.2%)
100 1000 1,51514800 1,56053000 (+3.0%)
500 200 2,21014400 2,47906000 (+12.2%)
2500 40 5,39488200 6,68766700 (+24.0%)
8000 12 13,98623900 18,17661900 (+30.0%)
xvtstdcdp:
rept loop master patch
8 12500 1,35123800 1,34455800 (-0.5%)
25 4000 1,36441200 1,36759600 (+0.2%)
100 1000 1,49763500 1,54138400 (+2.9%)
500 200 2,19020200 2,46196400 (+12.4%)
2500 40 5,39265700 6,68147900 (+23.9%)
8000 12 14,04163600 18,19669600 (+29.6%)
As some values are now decoded outside the helper and passed to it as an
argument the number of arguments of the helper increased, the number
of TCGop needed to load the arguments increased. I suspect that's why
the slow-down in the tests with a high REPT but low LOOP.
Signed-off-by: Lucas Mateus Castro (alqotel) <lucas.araujo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20221019125040.48028-12-lucas.araujo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-10-19 15:50:39 +03:00
|
|
|
static bool not_SP_value(float64 val)
|
2017-01-13 12:23:40 +03:00
|
|
|
{
|
target/ppc: Moved XSTSTDC[QDS]P to decodetree
Moved XSTSTDCSP, XSTSTDCDP and XSTSTDCQP to decodetree and moved some of
its decoding away from the helper as previously the DCMX, XB and BF were
calculated in the helper with the help of cpu_env, now that part was
moved to the decodetree with the rest.
xvtstdcsp:
rept loop master patch
8 12500 1,85393600 1,94683600 (+5.0%)
25 4000 1,78779800 1,92479000 (+7.7%)
100 1000 2,12775000 2,28895500 (+7.6%)
500 200 2,99655300 3,23102900 (+7.8%)
2500 40 6,89082200 7,44827500 (+8.1%)
8000 12 17,50585500 18,95152100 (+8.3%)
xvtstdcdp:
rept loop master patch
8 12500 1,39043100 1,33539800 (-4.0%)
25 4000 1,35731800 1,37347800 (+1.2%)
100 1000 1,51514800 1,56053000 (+3.0%)
500 200 2,21014400 2,47906000 (+12.2%)
2500 40 5,39488200 6,68766700 (+24.0%)
8000 12 13,98623900 18,17661900 (+30.0%)
xvtstdcdp:
rept loop master patch
8 12500 1,35123800 1,34455800 (-0.5%)
25 4000 1,36441200 1,36759600 (+0.2%)
100 1000 1,49763500 1,54138400 (+2.9%)
500 200 2,19020200 2,46196400 (+12.4%)
2500 40 5,39265700 6,68147900 (+23.9%)
8000 12 14,04163600 18,19669600 (+29.6%)
As some values are now decoded outside the helper and passed to it as an
argument the number of arguments of the helper increased, the number
of TCGop needed to load the arguments increased. I suspect that's why
the slow-down in the tests with a high REPT but low LOOP.
Signed-off-by: Lucas Mateus Castro (alqotel) <lucas.araujo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20221019125040.48028-12-lucas.araujo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-10-19 15:50:39 +03:00
|
|
|
return val != helper_todouble(helper_tosingle(val));
|
|
|
|
}
|
2017-01-13 12:23:40 +03:00
|
|
|
|
target/ppc: Moved XSTSTDC[QDS]P to decodetree
Moved XSTSTDCSP, XSTSTDCDP and XSTSTDCQP to decodetree and moved some of
its decoding away from the helper as previously the DCMX, XB and BF were
calculated in the helper with the help of cpu_env, now that part was
moved to the decodetree with the rest.
xvtstdcsp:
rept loop master patch
8 12500 1,85393600 1,94683600 (+5.0%)
25 4000 1,78779800 1,92479000 (+7.7%)
100 1000 2,12775000 2,28895500 (+7.6%)
500 200 2,99655300 3,23102900 (+7.8%)
2500 40 6,89082200 7,44827500 (+8.1%)
8000 12 17,50585500 18,95152100 (+8.3%)
xvtstdcdp:
rept loop master patch
8 12500 1,39043100 1,33539800 (-4.0%)
25 4000 1,35731800 1,37347800 (+1.2%)
100 1000 1,51514800 1,56053000 (+3.0%)
500 200 2,21014400 2,47906000 (+12.2%)
2500 40 5,39488200 6,68766700 (+24.0%)
8000 12 13,98623900 18,17661900 (+30.0%)
xvtstdcdp:
rept loop master patch
8 12500 1,35123800 1,34455800 (-0.5%)
25 4000 1,36441200 1,36759600 (+0.2%)
100 1000 1,49763500 1,54138400 (+2.9%)
500 200 2,19020200 2,46196400 (+12.4%)
2500 40 5,39265700 6,68147900 (+23.9%)
8000 12 14,04163600 18,19669600 (+29.6%)
As some values are now decoded outside the helper and passed to it as an
argument the number of arguments of the helper increased, the number
of TCGop needed to load the arguments increased. I suspect that's why
the slow-down in the tests with a high REPT but low LOOP.
Signed-off-by: Lucas Mateus Castro (alqotel) <lucas.araujo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20221019125040.48028-12-lucas.araujo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-10-19 15:50:39 +03:00
|
|
|
/*
|
|
|
|
* VSX_XS_TSTDC - VSX Scalar Test Data Class
|
|
|
|
* NAME - instruction name
|
|
|
|
* FLD - vsr_t field (VsrD(0) or f128)
|
|
|
|
* TP - type (float64 or float128)
|
|
|
|
*/
|
|
|
|
#define VSX_XS_TSTDC(NAME, FLD, TP) \
|
|
|
|
void helper_##NAME(CPUPPCState *env, uint32_t bf, \
|
|
|
|
uint32_t dcmx, ppc_vsr_t *b) \
|
|
|
|
{ \
|
|
|
|
uint32_t cc, match, sign = TP##_is_neg(b->FLD); \
|
|
|
|
match = TP##_tstdc(b->FLD, dcmx); \
|
|
|
|
cc = sign << CRF_LT_BIT | match << CRF_EQ_BIT; \
|
|
|
|
env->fpscr &= ~FP_FPCC; \
|
|
|
|
env->fpscr |= cc << FPSCR_FPCC; \
|
|
|
|
env->crf[bf] = cc; \
|
|
|
|
}
|
|
|
|
|
|
|
|
VSX_XS_TSTDC(XSTSTDCDP, VsrD(0), float64)
|
|
|
|
VSX_XS_TSTDC(XSTSTDCQP, f128, float128)
|
|
|
|
#undef VSX_XS_TSTDC
|
|
|
|
|
|
|
|
void helper_XSTSTDCSP(CPUPPCState *env, uint32_t bf,
|
|
|
|
uint32_t dcmx, ppc_vsr_t *b)
|
|
|
|
{
|
|
|
|
uint32_t cc, match, sign = float64_is_neg(b->VsrD(0));
|
|
|
|
uint32_t exp = (b->VsrD(0) >> 52) & 0x7FF;
|
|
|
|
int not_sp = (int)not_SP_value(b->VsrD(0));
|
|
|
|
match = float64_tstdc(b->VsrD(0), dcmx) || (exp > 0 && exp < 0x381);
|
2017-01-13 12:23:40 +03:00
|
|
|
cc = sign << CRF_LT_BIT | match << CRF_EQ_BIT | not_sp << CRF_SO_BIT;
|
2019-09-18 17:32:49 +03:00
|
|
|
env->fpscr &= ~FP_FPCC;
|
|
|
|
env->fpscr |= cc << FPSCR_FPCC;
|
target/ppc: Moved XSTSTDC[QDS]P to decodetree
Moved XSTSTDCSP, XSTSTDCDP and XSTSTDCQP to decodetree and moved some of
its decoding away from the helper as previously the DCMX, XB and BF were
calculated in the helper with the help of cpu_env, now that part was
moved to the decodetree with the rest.
xvtstdcsp:
rept loop master patch
8 12500 1,85393600 1,94683600 (+5.0%)
25 4000 1,78779800 1,92479000 (+7.7%)
100 1000 2,12775000 2,28895500 (+7.6%)
500 200 2,99655300 3,23102900 (+7.8%)
2500 40 6,89082200 7,44827500 (+8.1%)
8000 12 17,50585500 18,95152100 (+8.3%)
xvtstdcdp:
rept loop master patch
8 12500 1,39043100 1,33539800 (-4.0%)
25 4000 1,35731800 1,37347800 (+1.2%)
100 1000 1,51514800 1,56053000 (+3.0%)
500 200 2,21014400 2,47906000 (+12.2%)
2500 40 5,39488200 6,68766700 (+24.0%)
8000 12 13,98623900 18,17661900 (+30.0%)
xvtstdcdp:
rept loop master patch
8 12500 1,35123800 1,34455800 (-0.5%)
25 4000 1,36441200 1,36759600 (+0.2%)
100 1000 1,49763500 1,54138400 (+2.9%)
500 200 2,19020200 2,46196400 (+12.4%)
2500 40 5,39265700 6,68147900 (+23.9%)
8000 12 14,04163600 18,19669600 (+29.6%)
As some values are now decoded outside the helper and passed to it as an
argument the number of arguments of the helper increased, the number
of TCGop needed to load the arguments increased. I suspect that's why
the slow-down in the tests with a high REPT but low LOOP.
Signed-off-by: Lucas Mateus Castro (alqotel) <lucas.araujo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20221019125040.48028-12-lucas.araujo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-10-19 15:50:39 +03:00
|
|
|
env->crf[bf] = cc;
|
2017-01-13 12:23:40 +03:00
|
|
|
}
|
2017-02-04 01:01:14 +03:00
|
|
|
|
2019-06-16 15:37:47 +03:00
|
|
|
void helper_xsrqpi(CPUPPCState *env, uint32_t opcode,
|
|
|
|
ppc_vsr_t *xt, ppc_vsr_t *xb)
|
2017-02-04 01:01:14 +03:00
|
|
|
{
|
2019-06-16 15:37:37 +03:00
|
|
|
ppc_vsr_t t = { };
|
2017-02-04 01:01:14 +03:00
|
|
|
uint8_t r = Rrm(opcode);
|
|
|
|
uint8_t ex = Rc(opcode);
|
|
|
|
uint8_t rmc = RMC(opcode);
|
|
|
|
uint8_t rmode = 0;
|
|
|
|
float_status tstat;
|
|
|
|
|
|
|
|
helper_reset_fpstatus(env);
|
|
|
|
|
|
|
|
if (r == 0 && rmc == 0) {
|
|
|
|
rmode = float_round_ties_away;
|
|
|
|
} else if (r == 0 && rmc == 0x3) {
|
2022-05-05 00:05:20 +03:00
|
|
|
rmode = env->fpscr & FP_RN;
|
2017-02-04 01:01:14 +03:00
|
|
|
} else if (r == 1) {
|
|
|
|
switch (rmc) {
|
|
|
|
case 0:
|
|
|
|
rmode = float_round_nearest_even;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
rmode = float_round_to_zero;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
rmode = float_round_up;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
rmode = float_round_down;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tstat = env->fp_status;
|
|
|
|
set_float_exception_flags(0, &tstat);
|
|
|
|
set_float_rounding_mode(rmode, &tstat);
|
2019-06-16 15:37:37 +03:00
|
|
|
t.f128 = float128_round_to_int(xb->f128, &tstat);
|
2017-02-04 01:01:14 +03:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags;
|
|
|
|
|
2021-12-17 19:57:15 +03:00
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid_snan)) {
|
|
|
|
float_invalid_op_vxsnan(env, GETPC());
|
2017-02-04 01:01:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ex == 0 && (tstat.float_exception_flags & float_flag_inexact)) {
|
|
|
|
env->fp_status.float_exception_flags &= ~float_flag_inexact;
|
|
|
|
}
|
|
|
|
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_float128(env, t.f128);
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, true, GETPC());
|
2019-06-16 15:37:37 +03:00
|
|
|
*xt = t;
|
2017-02-04 01:01:14 +03:00
|
|
|
}
|
2017-02-04 01:01:15 +03:00
|
|
|
|
2019-06-16 15:37:47 +03:00
|
|
|
void helper_xsrqpxp(CPUPPCState *env, uint32_t opcode,
|
|
|
|
ppc_vsr_t *xt, ppc_vsr_t *xb)
|
2017-02-04 01:01:15 +03:00
|
|
|
{
|
2019-06-16 15:37:37 +03:00
|
|
|
ppc_vsr_t t = { };
|
2017-02-04 01:01:15 +03:00
|
|
|
uint8_t r = Rrm(opcode);
|
|
|
|
uint8_t rmc = RMC(opcode);
|
|
|
|
uint8_t rmode = 0;
|
|
|
|
floatx80 round_res;
|
|
|
|
float_status tstat;
|
|
|
|
|
|
|
|
helper_reset_fpstatus(env);
|
|
|
|
|
|
|
|
if (r == 0 && rmc == 0) {
|
|
|
|
rmode = float_round_ties_away;
|
|
|
|
} else if (r == 0 && rmc == 0x3) {
|
2022-05-05 00:05:20 +03:00
|
|
|
rmode = env->fpscr & FP_RN;
|
2017-02-04 01:01:15 +03:00
|
|
|
} else if (r == 1) {
|
|
|
|
switch (rmc) {
|
|
|
|
case 0:
|
|
|
|
rmode = float_round_nearest_even;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
rmode = float_round_to_zero;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
rmode = float_round_up;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
rmode = float_round_down;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tstat = env->fp_status;
|
|
|
|
set_float_exception_flags(0, &tstat);
|
|
|
|
set_float_rounding_mode(rmode, &tstat);
|
2019-06-16 15:37:37 +03:00
|
|
|
round_res = float128_to_floatx80(xb->f128, &tstat);
|
|
|
|
t.f128 = floatx80_to_float128(round_res, &tstat);
|
2017-02-04 01:01:15 +03:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags;
|
|
|
|
|
2021-12-17 19:57:15 +03:00
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid_snan)) {
|
|
|
|
float_invalid_op_vxsnan(env, GETPC());
|
|
|
|
t.f128 = float128_snan_to_qnan(t.f128);
|
2017-02-04 01:01:15 +03:00
|
|
|
}
|
|
|
|
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_float128(env, t.f128);
|
|
|
|
*xt = t;
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, true, GETPC());
|
2017-02-04 01:01:15 +03:00
|
|
|
}
|
2017-02-04 01:01:16 +03:00
|
|
|
|
2019-06-16 15:37:47 +03:00
|
|
|
void helper_xssqrtqp(CPUPPCState *env, uint32_t opcode,
|
|
|
|
ppc_vsr_t *xt, ppc_vsr_t *xb)
|
2017-02-04 01:01:16 +03:00
|
|
|
{
|
2019-06-16 15:37:37 +03:00
|
|
|
ppc_vsr_t t = { };
|
2017-02-04 01:01:16 +03:00
|
|
|
float_status tstat;
|
|
|
|
|
|
|
|
helper_reset_fpstatus(env);
|
|
|
|
|
2017-02-10 10:23:08 +03:00
|
|
|
tstat = env->fp_status;
|
2017-02-04 01:01:16 +03:00
|
|
|
if (unlikely(Rc(opcode) != 0)) {
|
2017-02-10 10:23:08 +03:00
|
|
|
tstat.float_rounding_mode = float_round_to_odd;
|
2017-02-04 01:01:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
set_float_exception_flags(0, &tstat);
|
2019-06-16 15:37:37 +03:00
|
|
|
t.f128 = float128_sqrt(xb->f128, &tstat);
|
2017-02-04 01:01:16 +03:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags;
|
|
|
|
|
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid)) {
|
2021-12-17 19:57:15 +03:00
|
|
|
float_invalid_op_sqrt(env, tstat.float_exception_flags, 1, GETPC());
|
2017-02-04 01:01:16 +03:00
|
|
|
}
|
|
|
|
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_float128(env, t.f128);
|
|
|
|
*xt = t;
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, true, GETPC());
|
2017-02-04 01:01:16 +03:00
|
|
|
}
|
2017-02-04 01:01:17 +03:00
|
|
|
|
2019-06-16 15:37:46 +03:00
|
|
|
void helper_xssubqp(CPUPPCState *env, uint32_t opcode,
|
|
|
|
ppc_vsr_t *xt, ppc_vsr_t *xa, ppc_vsr_t *xb)
|
2017-02-04 01:01:17 +03:00
|
|
|
{
|
2019-06-16 15:37:37 +03:00
|
|
|
ppc_vsr_t t = *xt;
|
2017-02-04 01:01:17 +03:00
|
|
|
float_status tstat;
|
|
|
|
|
|
|
|
helper_reset_fpstatus(env);
|
|
|
|
|
2017-02-10 10:23:08 +03:00
|
|
|
tstat = env->fp_status;
|
2017-02-04 01:01:17 +03:00
|
|
|
if (unlikely(Rc(opcode) != 0)) {
|
2017-02-10 10:23:08 +03:00
|
|
|
tstat.float_rounding_mode = float_round_to_odd;
|
2017-02-04 01:01:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
set_float_exception_flags(0, &tstat);
|
2019-06-16 15:37:37 +03:00
|
|
|
t.f128 = float128_sub(xa->f128, xb->f128, &tstat);
|
2017-02-04 01:01:17 +03:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags;
|
|
|
|
|
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid)) {
|
2021-12-17 19:57:14 +03:00
|
|
|
float_invalid_op_addsub(env, tstat.float_exception_flags, 1, GETPC());
|
2017-02-04 01:01:17 +03:00
|
|
|
}
|
|
|
|
|
2019-06-16 15:37:37 +03:00
|
|
|
helper_compute_fprf_float128(env, t.f128);
|
|
|
|
*xt = t;
|
target/ppc: Fix FPSCR.FI bit being cleared when it shouldn't
According to Power ISA, the FI bit in FPSCR is non-sticky.
This means that if an instruction is said to modify the FI bit, then
it should be set or cleared depending on the result of the
instruction. Otherwise, it should be kept as was before.
However, the following inconsistency was found when comparing results
from the hardware (tested on both a Power 9 processor and in
Power 10 Mambo):
(FI bit is set before the execution of the instruction)
Hardware: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> SET
QEMU: xscmpeqdp(0xff..ff, 0xff..ff) = FI: SET -> CLEARED
As the FI bit is non-sticky, and xscmpeqdp does not list it as a field
that is changed by the instruction, it should not be changed after its
execution.
This is happening to multiple instructions in the vsx implementations.
If the ISA does not list the FI bit as altered for a particular
instruction, then it should be kept as it was before the instruction.
QEMU is not following this behavior. Affected instructions include:
- xv* (all vsx-vector instructions);
- xscmp*, xsmax*, xsmin*;
- xstdivdp and similars;
(to identify the affected instructions, just search in the ISA for
the instructions that does not list FI in "Special Registers Altered")
Most instructions use the function do_float_check_status() to commit
changes in the inexact flag. So the fix is to add a parameter to it
that will control if the bit FI should be changed or not.
All users of do_float_check_status() are then modified to provide this
argument, controlling if that specific instruction changes bit FI or
not.
Some macro helpers are responsible for both instructions that change
and instructions that aren't suposed to change FI. This seems to always
overlap with the sfprf flag. So, reuse this flag for this purpose when
applicable.
Signed-off-by: Víctor Colombo <victor.colombo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220517161522.36132-2-victor.colombo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-17 19:15:20 +03:00
|
|
|
do_float_check_status(env, true, GETPC());
|
2017-02-04 01:01:17 +03:00
|
|
|
}
|
2022-05-24 17:05:33 +03:00
|
|
|
|
|
|
|
static inline void vsxger_excp(CPUPPCState *env, uintptr_t retaddr)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* XV*GER instructions execute and set the FPSCR as if exceptions
|
|
|
|
* are disabled and only at the end throw an exception
|
|
|
|
*/
|
|
|
|
target_ulong enable;
|
|
|
|
enable = env->fpscr & (FP_ENABLES | FP_FI | FP_FR);
|
|
|
|
env->fpscr &= ~(FP_ENABLES | FP_FI | FP_FR);
|
|
|
|
int status = get_float_exception_flags(&env->fp_status);
|
|
|
|
if (unlikely(status & float_flag_invalid)) {
|
|
|
|
if (status & float_flag_invalid_snan) {
|
|
|
|
float_invalid_op_vxsnan(env, 0);
|
|
|
|
}
|
|
|
|
if (status & float_flag_invalid_imz) {
|
|
|
|
float_invalid_op_vximz(env, false, 0);
|
|
|
|
}
|
|
|
|
if (status & float_flag_invalid_isi) {
|
|
|
|
float_invalid_op_vxisi(env, false, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
do_float_check_status(env, false, retaddr);
|
|
|
|
env->fpscr |= enable;
|
|
|
|
do_fpscr_check_status(env, retaddr);
|
|
|
|
}
|
|
|
|
|
2022-05-24 17:05:34 +03:00
|
|
|
typedef float64 extract_f16(float16, float_status *);
|
|
|
|
|
|
|
|
static float64 extract_hf16(float16 in, float_status *fp_status)
|
|
|
|
{
|
|
|
|
return float16_to_float64(in, true, fp_status);
|
|
|
|
}
|
|
|
|
|
2022-05-24 17:05:36 +03:00
|
|
|
static float64 extract_bf16(bfloat16 in, float_status *fp_status)
|
|
|
|
{
|
|
|
|
return bfloat16_to_float64(in, fp_status);
|
|
|
|
}
|
|
|
|
|
2022-05-24 17:05:34 +03:00
|
|
|
static void vsxger16(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask, bool acc,
|
|
|
|
bool neg_mul, bool neg_acc, extract_f16 extract)
|
|
|
|
{
|
|
|
|
float32 r, aux_acc;
|
|
|
|
float64 psum, va, vb, vc, vd;
|
|
|
|
int i, j, xmsk_bit, ymsk_bit;
|
|
|
|
uint8_t pmsk = FIELD_EX32(mask, GER_MSK, PMSK),
|
|
|
|
xmsk = FIELD_EX32(mask, GER_MSK, XMSK),
|
|
|
|
ymsk = FIELD_EX32(mask, GER_MSK, YMSK);
|
|
|
|
float_status *excp_ptr = &env->fp_status;
|
|
|
|
for (i = 0, xmsk_bit = 1 << 3; i < 4; i++, xmsk_bit >>= 1) {
|
|
|
|
for (j = 0, ymsk_bit = 1 << 3; j < 4; j++, ymsk_bit >>= 1) {
|
|
|
|
if ((xmsk_bit & xmsk) && (ymsk_bit & ymsk)) {
|
|
|
|
va = !(pmsk & 2) ? float64_zero :
|
|
|
|
extract(a->VsrHF(2 * i), excp_ptr);
|
|
|
|
vb = !(pmsk & 2) ? float64_zero :
|
|
|
|
extract(b->VsrHF(2 * j), excp_ptr);
|
|
|
|
vc = !(pmsk & 1) ? float64_zero :
|
|
|
|
extract(a->VsrHF(2 * i + 1), excp_ptr);
|
|
|
|
vd = !(pmsk & 1) ? float64_zero :
|
|
|
|
extract(b->VsrHF(2 * j + 1), excp_ptr);
|
|
|
|
psum = float64_mul(va, vb, excp_ptr);
|
|
|
|
psum = float64r32_muladd(vc, vd, psum, 0, excp_ptr);
|
|
|
|
r = float64_to_float32(psum, excp_ptr);
|
|
|
|
if (acc) {
|
|
|
|
aux_acc = at[i].VsrSF(j);
|
|
|
|
if (neg_mul) {
|
|
|
|
r = bfp32_neg(r);
|
|
|
|
}
|
|
|
|
if (neg_acc) {
|
|
|
|
aux_acc = bfp32_neg(aux_acc);
|
|
|
|
}
|
|
|
|
r = float32_add(r, aux_acc, excp_ptr);
|
|
|
|
}
|
|
|
|
at[i].VsrSF(j) = r;
|
|
|
|
} else {
|
|
|
|
at[i].VsrSF(j) = float32_zero;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vsxger_excp(env, GETPC());
|
|
|
|
}
|
|
|
|
|
2022-05-24 17:05:33 +03:00
|
|
|
typedef void vsxger_zero(ppc_vsr_t *at, int, int);
|
|
|
|
|
|
|
|
typedef void vsxger_muladd_f(ppc_vsr_t *, ppc_vsr_t *, ppc_vsr_t *, int, int,
|
|
|
|
int flags, float_status *s);
|
|
|
|
|
|
|
|
static void vsxger_muladd32(ppc_vsr_t *at, ppc_vsr_t *a, ppc_vsr_t *b, int i,
|
|
|
|
int j, int flags, float_status *s)
|
|
|
|
{
|
|
|
|
at[i].VsrSF(j) = float32_muladd(a->VsrSF(i), b->VsrSF(j),
|
|
|
|
at[i].VsrSF(j), flags, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vsxger_mul32(ppc_vsr_t *at, ppc_vsr_t *a, ppc_vsr_t *b, int i,
|
|
|
|
int j, int flags, float_status *s)
|
|
|
|
{
|
|
|
|
at[i].VsrSF(j) = float32_mul(a->VsrSF(i), b->VsrSF(j), s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vsxger_zero32(ppc_vsr_t *at, int i, int j)
|
|
|
|
{
|
|
|
|
at[i].VsrSF(j) = float32_zero;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vsxger_muladd64(ppc_vsr_t *at, ppc_vsr_t *a, ppc_vsr_t *b, int i,
|
|
|
|
int j, int flags, float_status *s)
|
|
|
|
{
|
|
|
|
if (j >= 2) {
|
|
|
|
j -= 2;
|
|
|
|
at[i].VsrDF(j) = float64_muladd(a[i / 2].VsrDF(i % 2), b->VsrDF(j),
|
|
|
|
at[i].VsrDF(j), flags, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vsxger_mul64(ppc_vsr_t *at, ppc_vsr_t *a, ppc_vsr_t *b, int i,
|
|
|
|
int j, int flags, float_status *s)
|
|
|
|
{
|
|
|
|
if (j >= 2) {
|
|
|
|
j -= 2;
|
|
|
|
at[i].VsrDF(j) = float64_mul(a[i / 2].VsrDF(i % 2), b->VsrDF(j), s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vsxger_zero64(ppc_vsr_t *at, int i, int j)
|
|
|
|
{
|
|
|
|
if (j >= 2) {
|
|
|
|
j -= 2;
|
|
|
|
at[i].VsrDF(j) = float64_zero;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vsxger(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask, bool acc, bool neg_mul,
|
|
|
|
bool neg_acc, vsxger_muladd_f mul, vsxger_muladd_f muladd,
|
|
|
|
vsxger_zero zero)
|
|
|
|
{
|
|
|
|
int i, j, xmsk_bit, ymsk_bit, op_flags;
|
|
|
|
uint8_t xmsk = mask & 0x0F;
|
|
|
|
uint8_t ymsk = (mask >> 4) & 0x0F;
|
|
|
|
float_status *excp_ptr = &env->fp_status;
|
|
|
|
op_flags = (neg_acc ^ neg_mul) ? float_muladd_negate_c : 0;
|
|
|
|
op_flags |= (neg_mul) ? float_muladd_negate_result : 0;
|
|
|
|
helper_reset_fpstatus(env);
|
|
|
|
for (i = 0, xmsk_bit = 1 << 3; i < 4; i++, xmsk_bit >>= 1) {
|
|
|
|
for (j = 0, ymsk_bit = 1 << 3; j < 4; j++, ymsk_bit >>= 1) {
|
|
|
|
if ((xmsk_bit & xmsk) && (ymsk_bit & ymsk)) {
|
|
|
|
if (acc) {
|
|
|
|
muladd(at, a, b, i, j, op_flags, excp_ptr);
|
|
|
|
} else {
|
|
|
|
mul(at, a, b, i, j, op_flags, excp_ptr);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
zero(at, i, j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vsxger_excp(env, GETPC());
|
|
|
|
}
|
|
|
|
|
2022-05-24 17:05:36 +03:00
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVBF16GER2(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger16(env, a, b, at, mask, false, false, false, extract_bf16);
|
|
|
|
}
|
|
|
|
|
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVBF16GER2PP(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger16(env, a, b, at, mask, true, false, false, extract_bf16);
|
|
|
|
}
|
|
|
|
|
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVBF16GER2PN(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger16(env, a, b, at, mask, true, false, true, extract_bf16);
|
|
|
|
}
|
|
|
|
|
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVBF16GER2NP(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger16(env, a, b, at, mask, true, true, false, extract_bf16);
|
|
|
|
}
|
|
|
|
|
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVBF16GER2NN(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger16(env, a, b, at, mask, true, true, true, extract_bf16);
|
|
|
|
}
|
|
|
|
|
2022-05-24 17:05:34 +03:00
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVF16GER2(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger16(env, a, b, at, mask, false, false, false, extract_hf16);
|
|
|
|
}
|
|
|
|
|
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVF16GER2PP(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger16(env, a, b, at, mask, true, false, false, extract_hf16);
|
|
|
|
}
|
|
|
|
|
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVF16GER2PN(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger16(env, a, b, at, mask, true, false, true, extract_hf16);
|
|
|
|
}
|
|
|
|
|
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVF16GER2NP(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger16(env, a, b, at, mask, true, true, false, extract_hf16);
|
|
|
|
}
|
|
|
|
|
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVF16GER2NN(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger16(env, a, b, at, mask, true, true, true, extract_hf16);
|
|
|
|
}
|
|
|
|
|
2022-05-24 17:05:33 +03:00
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVF32GER(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger(env, a, b, at, mask, false, false, false, vsxger_mul32,
|
|
|
|
vsxger_muladd32, vsxger_zero32);
|
|
|
|
}
|
|
|
|
|
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVF32GERPP(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger(env, a, b, at, mask, true, false, false, vsxger_mul32,
|
|
|
|
vsxger_muladd32, vsxger_zero32);
|
|
|
|
}
|
|
|
|
|
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVF32GERPN(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger(env, a, b, at, mask, true, false, true, vsxger_mul32,
|
|
|
|
vsxger_muladd32, vsxger_zero32);
|
|
|
|
}
|
|
|
|
|
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVF32GERNP(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger(env, a, b, at, mask, true, true, false, vsxger_mul32,
|
|
|
|
vsxger_muladd32, vsxger_zero32);
|
|
|
|
}
|
|
|
|
|
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVF32GERNN(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger(env, a, b, at, mask, true, true, true, vsxger_mul32,
|
|
|
|
vsxger_muladd32, vsxger_zero32);
|
|
|
|
}
|
|
|
|
|
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVF64GER(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger(env, a, b, at, mask, false, false, false, vsxger_mul64,
|
|
|
|
vsxger_muladd64, vsxger_zero64);
|
|
|
|
}
|
|
|
|
|
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVF64GERPP(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger(env, a, b, at, mask, true, false, false, vsxger_mul64,
|
|
|
|
vsxger_muladd64, vsxger_zero64);
|
|
|
|
}
|
|
|
|
|
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVF64GERPN(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger(env, a, b, at, mask, true, false, true, vsxger_mul64,
|
|
|
|
vsxger_muladd64, vsxger_zero64);
|
|
|
|
}
|
|
|
|
|
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVF64GERNP(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger(env, a, b, at, mask, true, true, false, vsxger_mul64,
|
|
|
|
vsxger_muladd64, vsxger_zero64);
|
|
|
|
}
|
|
|
|
|
|
|
|
QEMU_FLATTEN
|
|
|
|
void helper_XVF64GERNN(CPUPPCState *env, ppc_vsr_t *a, ppc_vsr_t *b,
|
|
|
|
ppc_acc_t *at, uint32_t mask)
|
|
|
|
{
|
|
|
|
vsxger(env, a, b, at, mask, true, true, true, vsxger_mul64,
|
|
|
|
vsxger_muladd64, vsxger_zero64);
|
|
|
|
}
|