2012-05-30 12:23:26 +08: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
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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-27 02:16:58 +08:00
|
|
|
#include "qemu/osdep.h"
|
2012-05-30 12:23:26 +08:00
|
|
|
#include "cpu.h"
|
2014-04-08 13:31:41 +08:00
|
|
|
#include "exec/helper-proto.h"
|
2016-07-27 14:56:26 +08:00
|
|
|
#include "exec/exec-all.h"
|
2016-11-23 19:37:10 +08:00
|
|
|
#include "internal.h"
|
2012-05-30 12:23:26 +08:00
|
|
|
|
2014-11-13 05:45:59 +08:00
|
|
|
#define float64_snan_to_qnan(x) ((x) | 0x0008000000000000ULL)
|
|
|
|
#define float32_snan_to_qnan(x) ((x) | 0x00400000)
|
|
|
|
|
2012-05-30 12:23:26 +08:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Floating point operations helpers */
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_float32_to_float64(CPUPPCState *env, uint32_t arg)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_FloatU f;
|
|
|
|
CPU_DoubleU d;
|
|
|
|
|
|
|
|
f.l = arg;
|
|
|
|
d.d = float32_to_float64(f.f, &env->fp_status);
|
|
|
|
return d.ll;
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
uint32_t helper_float64_to_float32(CPUPPCState *env, uint64_t arg)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_FloatU f;
|
|
|
|
CPU_DoubleU d;
|
|
|
|
|
|
|
|
d.ll = arg;
|
|
|
|
f.f = float64_to_float32(d.d, &env->fp_status);
|
|
|
|
return f.l;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int isden(float64 d)
|
|
|
|
{
|
|
|
|
CPU_DoubleU u;
|
|
|
|
|
|
|
|
u.d = d;
|
|
|
|
|
|
|
|
return ((u.ll >> 52) & 0x7FF) == 0;
|
|
|
|
}
|
|
|
|
|
2014-01-08 00:06:07 +08: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;
|
|
|
|
}
|
|
|
|
|
2014-11-13 05:46:04 +08:00
|
|
|
void helper_compute_fprf(CPUPPCState *env, uint64_t arg)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU farg;
|
|
|
|
int isneg;
|
2014-11-13 05:46:04 +08:00
|
|
|
int fprf;
|
2012-05-30 12:23:26 +08:00
|
|
|
|
|
|
|
farg.ll = arg;
|
|
|
|
isneg = float64_is_neg(farg.d);
|
|
|
|
if (unlikely(float64_is_any_nan(farg.d))) {
|
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 17:57:28 +08:00
|
|
|
if (float64_is_signaling_nan(farg.d, &env->fp_status)) {
|
2012-05-30 12:23:26 +08:00
|
|
|
/* Signaling NaN: flags are undefined */
|
2014-11-13 05:46:04 +08:00
|
|
|
fprf = 0x00;
|
2012-05-30 12:23:26 +08:00
|
|
|
} else {
|
|
|
|
/* Quiet NaN */
|
2014-11-13 05:46:04 +08:00
|
|
|
fprf = 0x11;
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
} else if (unlikely(float64_is_infinity(farg.d))) {
|
|
|
|
/* +/- infinity */
|
|
|
|
if (isneg) {
|
2014-11-13 05:46:04 +08:00
|
|
|
fprf = 0x09;
|
2012-05-30 12:23:26 +08:00
|
|
|
} else {
|
2014-11-13 05:46:04 +08:00
|
|
|
fprf = 0x05;
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (float64_is_zero(farg.d)) {
|
|
|
|
/* +/- zero */
|
|
|
|
if (isneg) {
|
2014-11-13 05:46:04 +08:00
|
|
|
fprf = 0x12;
|
2012-05-30 12:23:26 +08:00
|
|
|
} else {
|
2014-11-13 05:46:04 +08:00
|
|
|
fprf = 0x02;
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isden(farg.d)) {
|
|
|
|
/* Denormalized numbers */
|
2014-11-13 05:46:04 +08:00
|
|
|
fprf = 0x10;
|
2012-05-30 12:23:26 +08:00
|
|
|
} else {
|
|
|
|
/* Normalized numbers */
|
2014-11-13 05:46:04 +08:00
|
|
|
fprf = 0x00;
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
if (isneg) {
|
2014-11-13 05:46:04 +08:00
|
|
|
fprf |= 0x08;
|
2012-05-30 12:23:26 +08:00
|
|
|
} else {
|
2014-11-13 05:46:04 +08:00
|
|
|
fprf |= 0x04;
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-13 05:46:04 +08:00
|
|
|
/* We update FPSCR_FPRF */
|
|
|
|
env->fpscr &= ~(0x1F << FPSCR_FPRF);
|
|
|
|
env->fpscr |= fprf << FPSCR_FPRF;
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Floating-point invalid operations exception */
|
2016-07-27 14:56:27 +08:00
|
|
|
static inline __attribute__((__always_inline__))
|
|
|
|
uint64_t float_invalid_op_excp(CPUPPCState *env, int op, int set_fpcc)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
2013-08-26 14:31:06 +08:00
|
|
|
CPUState *cs = CPU(ppc_env_get_cpu(env));
|
2012-05-30 12:23:26 +08:00
|
|
|
uint64_t ret = 0;
|
|
|
|
int ve;
|
|
|
|
|
|
|
|
ve = fpscr_ve;
|
|
|
|
switch (op) {
|
|
|
|
case POWERPC_EXCP_FP_VXSNAN:
|
|
|
|
env->fpscr |= 1 << FPSCR_VXSNAN;
|
|
|
|
break;
|
|
|
|
case POWERPC_EXCP_FP_VXSOFT:
|
|
|
|
env->fpscr |= 1 << FPSCR_VXSOFT;
|
|
|
|
break;
|
|
|
|
case POWERPC_EXCP_FP_VXISI:
|
|
|
|
/* Magnitude subtraction of infinities */
|
|
|
|
env->fpscr |= 1 << FPSCR_VXISI;
|
|
|
|
goto update_arith;
|
|
|
|
case POWERPC_EXCP_FP_VXIDI:
|
|
|
|
/* Division of infinity by infinity */
|
|
|
|
env->fpscr |= 1 << FPSCR_VXIDI;
|
|
|
|
goto update_arith;
|
|
|
|
case POWERPC_EXCP_FP_VXZDZ:
|
|
|
|
/* Division of zero by zero */
|
|
|
|
env->fpscr |= 1 << FPSCR_VXZDZ;
|
|
|
|
goto update_arith;
|
|
|
|
case POWERPC_EXCP_FP_VXIMZ:
|
|
|
|
/* Multiplication of zero by infinity */
|
|
|
|
env->fpscr |= 1 << FPSCR_VXIMZ;
|
|
|
|
goto update_arith;
|
|
|
|
case POWERPC_EXCP_FP_VXVC:
|
|
|
|
/* Ordered comparison of NaN */
|
|
|
|
env->fpscr |= 1 << FPSCR_VXVC;
|
2014-01-03 06:21:19 +08:00
|
|
|
if (set_fpcc) {
|
|
|
|
env->fpscr &= ~(0xF << FPSCR_FPCC);
|
|
|
|
env->fpscr |= 0x11 << FPSCR_FPCC;
|
|
|
|
}
|
2012-05-30 12:23:26 +08:00
|
|
|
/* We must update the target FPR before raising the exception */
|
|
|
|
if (ve != 0) {
|
2013-08-26 14:31:06 +08:00
|
|
|
cs->exception_index = POWERPC_EXCP_PROGRAM;
|
2012-05-30 12:23:26 +08:00
|
|
|
env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_VXVC;
|
|
|
|
/* Update the floating-point enabled exception summary */
|
|
|
|
env->fpscr |= 1 << FPSCR_FEX;
|
|
|
|
/* Exception is differed */
|
|
|
|
ve = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case POWERPC_EXCP_FP_VXSQRT:
|
|
|
|
/* Square root of a negative number */
|
|
|
|
env->fpscr |= 1 << FPSCR_VXSQRT;
|
|
|
|
update_arith:
|
|
|
|
env->fpscr &= ~((1 << FPSCR_FR) | (1 << FPSCR_FI));
|
|
|
|
if (ve == 0) {
|
|
|
|
/* Set the result to quiet NaN */
|
|
|
|
ret = 0x7FF8000000000000ULL;
|
2014-01-03 06:21:19 +08:00
|
|
|
if (set_fpcc) {
|
|
|
|
env->fpscr &= ~(0xF << FPSCR_FPCC);
|
|
|
|
env->fpscr |= 0x11 << FPSCR_FPCC;
|
|
|
|
}
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case POWERPC_EXCP_FP_VXCVI:
|
|
|
|
/* Invalid conversion */
|
|
|
|
env->fpscr |= 1 << FPSCR_VXCVI;
|
|
|
|
env->fpscr &= ~((1 << FPSCR_FR) | (1 << FPSCR_FI));
|
|
|
|
if (ve == 0) {
|
|
|
|
/* Set the result to quiet NaN */
|
|
|
|
ret = 0x7FF8000000000000ULL;
|
2014-01-03 06:21:19 +08:00
|
|
|
if (set_fpcc) {
|
|
|
|
env->fpscr &= ~(0xF << FPSCR_FPCC);
|
|
|
|
env->fpscr |= 0x11 << FPSCR_FPCC;
|
|
|
|
}
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Update the floating-point invalid operation summary */
|
|
|
|
env->fpscr |= 1 << FPSCR_VX;
|
|
|
|
/* Update the floating-point exception summary */
|
2015-11-20 19:31:48 +08:00
|
|
|
env->fpscr |= FP_FX;
|
2012-05-30 12:23:26 +08:00
|
|
|
if (ve != 0) {
|
|
|
|
/* Update the floating-point enabled exception summary */
|
|
|
|
env->fpscr |= 1 << FPSCR_FEX;
|
|
|
|
if (msr_fe0 != 0 || msr_fe1 != 0) {
|
2016-07-27 14:56:26 +08:00
|
|
|
/* GETPC() works here because this is inline */
|
|
|
|
raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM,
|
|
|
|
POWERPC_EXCP_FP | op, GETPC());
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-07-27 14:56:27 +08:00
|
|
|
static inline void float_zero_divide_excp(CPUPPCState *env, uintptr_t raddr)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
env->fpscr |= 1 << FPSCR_ZX;
|
|
|
|
env->fpscr &= ~((1 << FPSCR_FR) | (1 << FPSCR_FI));
|
|
|
|
/* Update the floating-point exception summary */
|
2015-11-20 19:31:48 +08:00
|
|
|
env->fpscr |= FP_FX;
|
2012-05-30 12:23:26 +08:00
|
|
|
if (fpscr_ze != 0) {
|
|
|
|
/* Update the floating-point enabled exception summary */
|
|
|
|
env->fpscr |= 1 << FPSCR_FEX;
|
|
|
|
if (msr_fe0 != 0 || msr_fe1 != 0) {
|
2016-07-27 14:56:27 +08:00
|
|
|
raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM,
|
|
|
|
POWERPC_EXCP_FP | POWERPC_EXCP_FP_ZX,
|
|
|
|
raddr);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
static inline void float_overflow_excp(CPUPPCState *env)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
2013-08-26 14:31:06 +08:00
|
|
|
CPUState *cs = CPU(ppc_env_get_cpu(env));
|
|
|
|
|
2012-05-30 12:23:26 +08:00
|
|
|
env->fpscr |= 1 << FPSCR_OX;
|
|
|
|
/* Update the floating-point exception summary */
|
2015-11-20 19:31:48 +08:00
|
|
|
env->fpscr |= FP_FX;
|
2012-05-30 12:23:26 +08:00
|
|
|
if (fpscr_oe != 0) {
|
|
|
|
/* XXX: should adjust the result */
|
|
|
|
/* Update the floating-point enabled exception summary */
|
|
|
|
env->fpscr |= 1 << FPSCR_FEX;
|
|
|
|
/* We must update the target FPR before raising the exception */
|
2013-08-26 14:31:06 +08:00
|
|
|
cs->exception_index = POWERPC_EXCP_PROGRAM;
|
2012-05-30 12:23:26 +08:00
|
|
|
env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_OX;
|
|
|
|
} else {
|
|
|
|
env->fpscr |= 1 << FPSCR_XX;
|
|
|
|
env->fpscr |= 1 << FPSCR_FI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
static inline void float_underflow_excp(CPUPPCState *env)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
2013-08-26 14:31:06 +08:00
|
|
|
CPUState *cs = CPU(ppc_env_get_cpu(env));
|
|
|
|
|
2012-05-30 12:23:26 +08:00
|
|
|
env->fpscr |= 1 << FPSCR_UX;
|
|
|
|
/* Update the floating-point exception summary */
|
2015-11-20 19:31:48 +08:00
|
|
|
env->fpscr |= FP_FX;
|
2012-05-30 12:23:26 +08:00
|
|
|
if (fpscr_ue != 0) {
|
|
|
|
/* XXX: should adjust the result */
|
|
|
|
/* Update the floating-point enabled exception summary */
|
|
|
|
env->fpscr |= 1 << FPSCR_FEX;
|
|
|
|
/* We must update the target FPR before raising the exception */
|
2013-08-26 14:31:06 +08:00
|
|
|
cs->exception_index = POWERPC_EXCP_PROGRAM;
|
2012-05-30 12:23:26 +08:00
|
|
|
env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_UX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
static inline void float_inexact_excp(CPUPPCState *env)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
2013-08-26 14:31:06 +08:00
|
|
|
CPUState *cs = CPU(ppc_env_get_cpu(env));
|
|
|
|
|
2012-05-30 12:23:26 +08:00
|
|
|
env->fpscr |= 1 << FPSCR_XX;
|
|
|
|
/* Update the floating-point exception summary */
|
2015-11-20 19:31:48 +08:00
|
|
|
env->fpscr |= FP_FX;
|
2012-05-30 12:23:26 +08:00
|
|
|
if (fpscr_xe != 0) {
|
|
|
|
/* Update the floating-point enabled exception summary */
|
|
|
|
env->fpscr |= 1 << FPSCR_FEX;
|
|
|
|
/* We must update the target FPR before raising the exception */
|
2013-08-26 14:31:06 +08:00
|
|
|
cs->exception_index = POWERPC_EXCP_PROGRAM;
|
2012-05-30 12:23:26 +08:00
|
|
|
env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_XX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
static inline void fpscr_set_rounding_mode(CPUPPCState *env)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
int rnd_type;
|
|
|
|
|
|
|
|
/* Set rounding mode */
|
|
|
|
switch (fpscr_rn) {
|
|
|
|
case 0:
|
|
|
|
/* Best approximation (round to nearest) */
|
|
|
|
rnd_type = float_round_nearest_even;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/* Smaller magnitude (round toward zero) */
|
|
|
|
rnd_type = float_round_to_zero;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
/* Round toward +infinite */
|
|
|
|
rnd_type = float_round_up;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 3:
|
|
|
|
/* Round toward -infinite */
|
|
|
|
rnd_type = float_round_down;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
set_float_rounding_mode(rnd_type, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
void helper_fpscr_clrbit(CPUPPCState *env, uint32_t bit)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
int prev;
|
|
|
|
|
|
|
|
prev = (env->fpscr >> bit) & 1;
|
|
|
|
env->fpscr &= ~(1 << bit);
|
|
|
|
if (prev == 1) {
|
|
|
|
switch (bit) {
|
|
|
|
case FPSCR_RN1:
|
|
|
|
case FPSCR_RN:
|
2012-05-30 12:23:27 +08:00
|
|
|
fpscr_set_rounding_mode(env);
|
2012-05-30 12:23:26 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
void helper_fpscr_setbit(CPUPPCState *env, uint32_t bit)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
2013-08-26 14:31:06 +08:00
|
|
|
CPUState *cs = CPU(ppc_env_get_cpu(env));
|
2012-05-30 12:23:26 +08:00
|
|
|
int prev;
|
|
|
|
|
|
|
|
prev = (env->fpscr >> bit) & 1;
|
|
|
|
env->fpscr |= 1 << bit;
|
|
|
|
if (prev == 0) {
|
|
|
|
switch (bit) {
|
|
|
|
case FPSCR_VX:
|
2015-11-20 19:31:48 +08:00
|
|
|
env->fpscr |= FP_FX;
|
2012-05-30 12:23:26 +08:00
|
|
|
if (fpscr_ve) {
|
|
|
|
goto raise_ve;
|
|
|
|
}
|
2012-05-30 12:23:41 +08:00
|
|
|
break;
|
2012-05-30 12:23:26 +08:00
|
|
|
case FPSCR_OX:
|
2015-11-20 19:31:48 +08:00
|
|
|
env->fpscr |= FP_FX;
|
2012-05-30 12:23:26 +08:00
|
|
|
if (fpscr_oe) {
|
|
|
|
goto raise_oe;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FPSCR_UX:
|
2015-11-20 19:31:48 +08:00
|
|
|
env->fpscr |= FP_FX;
|
2012-05-30 12:23:26 +08:00
|
|
|
if (fpscr_ue) {
|
|
|
|
goto raise_ue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FPSCR_ZX:
|
2015-11-20 19:31:48 +08:00
|
|
|
env->fpscr |= FP_FX;
|
2012-05-30 12:23:26 +08:00
|
|
|
if (fpscr_ze) {
|
|
|
|
goto raise_ze;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FPSCR_XX:
|
2015-11-20 19:31:48 +08:00
|
|
|
env->fpscr |= FP_FX;
|
2012-05-30 12:23:26 +08:00
|
|
|
if (fpscr_xe) {
|
|
|
|
goto raise_xe;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FPSCR_VXSNAN:
|
|
|
|
case FPSCR_VXISI:
|
|
|
|
case FPSCR_VXIDI:
|
|
|
|
case FPSCR_VXZDZ:
|
|
|
|
case FPSCR_VXIMZ:
|
|
|
|
case FPSCR_VXVC:
|
|
|
|
case FPSCR_VXSOFT:
|
|
|
|
case FPSCR_VXSQRT:
|
|
|
|
case FPSCR_VXCVI:
|
|
|
|
env->fpscr |= 1 << FPSCR_VX;
|
2015-11-20 19:31:48 +08:00
|
|
|
env->fpscr |= FP_FX;
|
2012-05-30 12:23:26 +08:00
|
|
|
if (fpscr_ve != 0) {
|
|
|
|
goto raise_ve;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FPSCR_VE:
|
|
|
|
if (fpscr_vx != 0) {
|
|
|
|
raise_ve:
|
|
|
|
env->error_code = POWERPC_EXCP_FP;
|
|
|
|
if (fpscr_vxsnan) {
|
|
|
|
env->error_code |= POWERPC_EXCP_FP_VXSNAN;
|
|
|
|
}
|
|
|
|
if (fpscr_vxisi) {
|
|
|
|
env->error_code |= POWERPC_EXCP_FP_VXISI;
|
|
|
|
}
|
|
|
|
if (fpscr_vxidi) {
|
|
|
|
env->error_code |= POWERPC_EXCP_FP_VXIDI;
|
|
|
|
}
|
|
|
|
if (fpscr_vxzdz) {
|
|
|
|
env->error_code |= POWERPC_EXCP_FP_VXZDZ;
|
|
|
|
}
|
|
|
|
if (fpscr_vximz) {
|
|
|
|
env->error_code |= POWERPC_EXCP_FP_VXIMZ;
|
|
|
|
}
|
|
|
|
if (fpscr_vxvc) {
|
|
|
|
env->error_code |= POWERPC_EXCP_FP_VXVC;
|
|
|
|
}
|
|
|
|
if (fpscr_vxsoft) {
|
|
|
|
env->error_code |= POWERPC_EXCP_FP_VXSOFT;
|
|
|
|
}
|
|
|
|
if (fpscr_vxsqrt) {
|
|
|
|
env->error_code |= POWERPC_EXCP_FP_VXSQRT;
|
|
|
|
}
|
|
|
|
if (fpscr_vxcvi) {
|
|
|
|
env->error_code |= POWERPC_EXCP_FP_VXCVI;
|
|
|
|
}
|
|
|
|
goto raise_excp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FPSCR_OE:
|
|
|
|
if (fpscr_ox != 0) {
|
|
|
|
raise_oe:
|
|
|
|
env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_OX;
|
|
|
|
goto raise_excp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FPSCR_UE:
|
|
|
|
if (fpscr_ux != 0) {
|
|
|
|
raise_ue:
|
|
|
|
env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_UX;
|
|
|
|
goto raise_excp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FPSCR_ZE:
|
|
|
|
if (fpscr_zx != 0) {
|
|
|
|
raise_ze:
|
|
|
|
env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_ZX;
|
|
|
|
goto raise_excp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FPSCR_XE:
|
|
|
|
if (fpscr_xx != 0) {
|
|
|
|
raise_xe:
|
|
|
|
env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_XX;
|
|
|
|
goto raise_excp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FPSCR_RN1:
|
|
|
|
case FPSCR_RN:
|
2012-05-30 12:23:27 +08:00
|
|
|
fpscr_set_rounding_mode(env);
|
2012-05-30 12:23:26 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
raise_excp:
|
|
|
|
/* Update the floating-point enabled exception summary */
|
|
|
|
env->fpscr |= 1 << FPSCR_FEX;
|
|
|
|
/* We have to update Rc1 before raising the exception */
|
2013-08-26 14:31:06 +08:00
|
|
|
cs->exception_index = POWERPC_EXCP_PROGRAM;
|
2012-05-30 12:23:26 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
void helper_store_fpscr(CPUPPCState *env, uint64_t arg, uint32_t mask)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
2013-08-26 14:31:06 +08:00
|
|
|
CPUState *cs = CPU(ppc_env_get_cpu(env));
|
2013-04-20 16:56:22 +08:00
|
|
|
target_ulong prev, new;
|
2012-05-30 12:23:26 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
prev = env->fpscr;
|
2013-04-20 16:56:22 +08:00
|
|
|
new = (target_ulong)arg;
|
|
|
|
new &= ~0x60000000LL;
|
|
|
|
new |= prev & 0x60000000LL;
|
|
|
|
for (i = 0; i < sizeof(target_ulong) * 2; i++) {
|
2012-05-30 12:23:26 +08:00
|
|
|
if (mask & (1 << i)) {
|
2013-04-20 16:56:22 +08:00
|
|
|
env->fpscr &= ~(0xFLL << (4 * i));
|
|
|
|
env->fpscr |= new & (0xFLL << (4 * i));
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Update VX and FEX */
|
|
|
|
if (fpscr_ix != 0) {
|
|
|
|
env->fpscr |= 1 << FPSCR_VX;
|
|
|
|
} else {
|
|
|
|
env->fpscr &= ~(1 << FPSCR_VX);
|
|
|
|
}
|
|
|
|
if ((fpscr_ex & fpscr_eex) != 0) {
|
|
|
|
env->fpscr |= 1 << FPSCR_FEX;
|
2013-08-26 14:31:06 +08:00
|
|
|
cs->exception_index = POWERPC_EXCP_PROGRAM;
|
2012-05-30 12:23:26 +08:00
|
|
|
/* XXX: we should compute it properly */
|
|
|
|
env->error_code = POWERPC_EXCP_FP;
|
|
|
|
} else {
|
|
|
|
env->fpscr &= ~(1 << FPSCR_FEX);
|
|
|
|
}
|
2012-05-30 12:23:27 +08:00
|
|
|
fpscr_set_rounding_mode(env);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
|
2013-03-19 15:41:53 +08:00
|
|
|
void store_fpscr(CPUPPCState *env, uint64_t arg, uint32_t mask)
|
|
|
|
{
|
|
|
|
helper_store_fpscr(env, arg, mask);
|
|
|
|
}
|
|
|
|
|
2016-07-27 14:56:27 +08:00
|
|
|
static void do_float_check_status(CPUPPCState *env, uintptr_t raddr)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
2013-08-26 14:31:06 +08:00
|
|
|
CPUState *cs = CPU(ppc_env_get_cpu(env));
|
2013-04-09 13:00:55 +08:00
|
|
|
int status = get_float_exception_flags(&env->fp_status);
|
|
|
|
|
|
|
|
if (status & float_flag_divbyzero) {
|
2016-07-27 14:56:27 +08:00
|
|
|
float_zero_divide_excp(env, raddr);
|
2013-04-09 13:00:55 +08:00
|
|
|
} else if (status & float_flag_overflow) {
|
|
|
|
float_overflow_excp(env);
|
|
|
|
} else if (status & float_flag_underflow) {
|
|
|
|
float_underflow_excp(env);
|
|
|
|
} else if (status & float_flag_inexact) {
|
|
|
|
float_inexact_excp(env);
|
|
|
|
}
|
|
|
|
|
2013-08-26 14:31:06 +08:00
|
|
|
if (cs->exception_index == POWERPC_EXCP_PROGRAM &&
|
2012-05-30 12:23:26 +08:00
|
|
|
(env->error_code & POWERPC_EXCP_FP)) {
|
|
|
|
/* Differred floating-point exception after target FPR update */
|
|
|
|
if (msr_fe0 != 0 || msr_fe1 != 0) {
|
2016-07-27 14:56:27 +08:00
|
|
|
raise_exception_err_ra(env, cs->exception_index,
|
|
|
|
env->error_code, raddr);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-27 14:56:27 +08:00
|
|
|
static inline __attribute__((__always_inline__))
|
|
|
|
void float_check_status(CPUPPCState *env)
|
|
|
|
{
|
|
|
|
/* GETPC() works here because this is inline */
|
|
|
|
do_float_check_status(env, GETPC());
|
|
|
|
}
|
|
|
|
|
|
|
|
void helper_float_check_status(CPUPPCState *env)
|
|
|
|
{
|
|
|
|
do_float_check_status(env, GETPC());
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
void helper_reset_fpstatus(CPUPPCState *env)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
set_float_exception_flags(0, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fadd - fadd. */
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_fadd(CPUPPCState *env, uint64_t arg1, uint64_t arg2)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU farg1, farg2;
|
|
|
|
|
|
|
|
farg1.ll = arg1;
|
|
|
|
farg2.ll = arg2;
|
|
|
|
|
|
|
|
if (unlikely(float64_is_infinity(farg1.d) && float64_is_infinity(farg2.d) &&
|
|
|
|
float64_is_neg(farg1.d) != float64_is_neg(farg2.d))) {
|
|
|
|
/* Magnitude subtraction of infinities */
|
2016-07-27 14:56:25 +08:00
|
|
|
farg1.ll = float_invalid_op_excp(env, POWERPC_EXCP_FP_VXISI, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
} else {
|
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 17:57:28 +08:00
|
|
|
if (unlikely(float64_is_signaling_nan(farg1.d, &env->fp_status) ||
|
|
|
|
float64_is_signaling_nan(farg2.d, &env->fp_status))) {
|
2012-05-30 12:23:26 +08:00
|
|
|
/* sNaN addition */
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
farg1.d = float64_add(farg1.d, farg2.d, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return farg1.ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fsub - fsub. */
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_fsub(CPUPPCState *env, uint64_t arg1, uint64_t arg2)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU farg1, farg2;
|
|
|
|
|
|
|
|
farg1.ll = arg1;
|
|
|
|
farg2.ll = arg2;
|
|
|
|
|
|
|
|
if (unlikely(float64_is_infinity(farg1.d) && float64_is_infinity(farg2.d) &&
|
|
|
|
float64_is_neg(farg1.d) == float64_is_neg(farg2.d))) {
|
|
|
|
/* Magnitude subtraction of infinities */
|
2016-07-27 14:56:25 +08:00
|
|
|
farg1.ll = float_invalid_op_excp(env, POWERPC_EXCP_FP_VXISI, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
} else {
|
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 17:57:28 +08:00
|
|
|
if (unlikely(float64_is_signaling_nan(farg1.d, &env->fp_status) ||
|
|
|
|
float64_is_signaling_nan(farg2.d, &env->fp_status))) {
|
2012-05-30 12:23:26 +08:00
|
|
|
/* sNaN subtraction */
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
farg1.d = float64_sub(farg1.d, farg2.d, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return farg1.ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fmul - fmul. */
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_fmul(CPUPPCState *env, uint64_t arg1, uint64_t arg2)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU farg1, farg2;
|
|
|
|
|
|
|
|
farg1.ll = arg1;
|
|
|
|
farg2.ll = arg2;
|
|
|
|
|
|
|
|
if (unlikely((float64_is_infinity(farg1.d) && float64_is_zero(farg2.d)) ||
|
|
|
|
(float64_is_zero(farg1.d) && float64_is_infinity(farg2.d)))) {
|
|
|
|
/* Multiplication of zero by infinity */
|
2016-07-27 14:56:25 +08:00
|
|
|
farg1.ll = float_invalid_op_excp(env, POWERPC_EXCP_FP_VXIMZ, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
} else {
|
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 17:57:28 +08:00
|
|
|
if (unlikely(float64_is_signaling_nan(farg1.d, &env->fp_status) ||
|
|
|
|
float64_is_signaling_nan(farg2.d, &env->fp_status))) {
|
2012-05-30 12:23:26 +08:00
|
|
|
/* sNaN multiplication */
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
farg1.d = float64_mul(farg1.d, farg2.d, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return farg1.ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fdiv - fdiv. */
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_fdiv(CPUPPCState *env, uint64_t arg1, uint64_t arg2)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU farg1, farg2;
|
|
|
|
|
|
|
|
farg1.ll = arg1;
|
|
|
|
farg2.ll = arg2;
|
|
|
|
|
|
|
|
if (unlikely(float64_is_infinity(farg1.d) &&
|
|
|
|
float64_is_infinity(farg2.d))) {
|
|
|
|
/* Division of infinity by infinity */
|
2016-07-27 14:56:25 +08:00
|
|
|
farg1.ll = float_invalid_op_excp(env, POWERPC_EXCP_FP_VXIDI, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
} else if (unlikely(float64_is_zero(farg1.d) && float64_is_zero(farg2.d))) {
|
|
|
|
/* Division of zero by zero */
|
2016-07-27 14:56:25 +08:00
|
|
|
farg1.ll = float_invalid_op_excp(env, POWERPC_EXCP_FP_VXZDZ, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
} else {
|
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 17:57:28 +08:00
|
|
|
if (unlikely(float64_is_signaling_nan(farg1.d, &env->fp_status) ||
|
|
|
|
float64_is_signaling_nan(farg2.d, &env->fp_status))) {
|
2012-05-30 12:23:26 +08:00
|
|
|
/* sNaN division */
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
farg1.d = float64_div(farg1.d, farg2.d, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return farg1.ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-08 00:05:59 +08:00
|
|
|
#define FPU_FCTI(op, cvt, nanval) \
|
|
|
|
uint64_t helper_##op(CPUPPCState *env, uint64_t arg) \
|
|
|
|
{ \
|
|
|
|
CPU_DoubleU farg; \
|
|
|
|
\
|
|
|
|
farg.ll = arg; \
|
|
|
|
farg.ll = float64_to_##cvt(farg.d, &env->fp_status); \
|
|
|
|
\
|
|
|
|
if (unlikely(env->fp_status.float_exception_flags)) { \
|
|
|
|
if (float64_is_any_nan(arg)) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXCVI, 1); \
|
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 17:57:28 +08:00
|
|
|
if (float64_is_signaling_nan(arg, &env->fp_status)) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1); \
|
2014-01-08 00:05:59 +08:00
|
|
|
} \
|
|
|
|
farg.ll = nanval; \
|
|
|
|
} else if (env->fp_status.float_exception_flags & \
|
|
|
|
float_flag_invalid) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXCVI, 1); \
|
2014-01-08 00:05:59 +08:00
|
|
|
} \
|
2016-07-27 14:56:27 +08:00
|
|
|
float_check_status(env); \
|
2014-01-08 00:05:59 +08:00
|
|
|
} \
|
|
|
|
return farg.ll; \
|
|
|
|
}
|
|
|
|
|
2014-02-24 22:12:13 +08: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 12:23:26 +08:00
|
|
|
|
2014-01-08 00:06:00 +08: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); \
|
|
|
|
} \
|
2016-07-27 14:56:27 +08:00
|
|
|
float_check_status(env); \
|
2014-01-08 00:06:00 +08:00
|
|
|
return farg.ll; \
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
|
2014-01-08 00:06:00 +08: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 12:23:26 +08:00
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
static inline uint64_t do_fri(CPUPPCState *env, uint64_t arg,
|
|
|
|
int rounding_mode)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU farg;
|
|
|
|
|
|
|
|
farg.ll = arg;
|
|
|
|
|
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 17:57:28 +08:00
|
|
|
if (unlikely(float64_is_signaling_nan(farg.d, &env->fp_status))) {
|
2012-05-30 12:23:26 +08:00
|
|
|
/* sNaN round */
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1);
|
2014-02-24 22:12:13 +08:00
|
|
|
farg.ll = arg | 0x0008000000000000ULL;
|
2012-05-30 12:23:26 +08:00
|
|
|
} else {
|
2014-01-08 00:06:05 +08:00
|
|
|
int inexact = get_float_exception_flags(&env->fp_status) &
|
|
|
|
float_flag_inexact;
|
2012-05-30 12:23:26 +08:00
|
|
|
set_float_rounding_mode(rounding_mode, &env->fp_status);
|
|
|
|
farg.ll = float64_round_to_int(farg.d, &env->fp_status);
|
|
|
|
/* Restore rounding mode from FPSCR */
|
2012-05-30 12:23:27 +08:00
|
|
|
fpscr_set_rounding_mode(env);
|
2014-01-08 00:06:05 +08:00
|
|
|
|
|
|
|
/* fri* does not set FPSCR[XX] */
|
|
|
|
if (!inexact) {
|
|
|
|
env->fp_status.float_exception_flags &= ~float_flag_inexact;
|
|
|
|
}
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
2016-07-27 14:56:27 +08:00
|
|
|
float_check_status(env);
|
2012-05-30 12:23:26 +08:00
|
|
|
return farg.ll;
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_frin(CPUPPCState *env, uint64_t arg)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
2014-01-08 00:06:05 +08:00
|
|
|
return do_fri(env, arg, float_round_ties_away);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_friz(CPUPPCState *env, uint64_t arg)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
2012-05-30 12:23:27 +08:00
|
|
|
return do_fri(env, arg, float_round_to_zero);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_frip(CPUPPCState *env, uint64_t arg)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
2012-05-30 12:23:27 +08:00
|
|
|
return do_fri(env, arg, float_round_up);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_frim(CPUPPCState *env, uint64_t arg)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
2012-05-30 12:23:27 +08:00
|
|
|
return do_fri(env, arg, float_round_down);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* fmadd - fmadd. */
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_fmadd(CPUPPCState *env, uint64_t arg1, uint64_t arg2,
|
|
|
|
uint64_t arg3)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU farg1, farg2, farg3;
|
|
|
|
|
|
|
|
farg1.ll = arg1;
|
|
|
|
farg2.ll = arg2;
|
|
|
|
farg3.ll = arg3;
|
|
|
|
|
|
|
|
if (unlikely((float64_is_infinity(farg1.d) && float64_is_zero(farg2.d)) ||
|
|
|
|
(float64_is_zero(farg1.d) && float64_is_infinity(farg2.d)))) {
|
|
|
|
/* Multiplication of zero by infinity */
|
2016-07-27 14:56:25 +08:00
|
|
|
farg1.ll = float_invalid_op_excp(env, POWERPC_EXCP_FP_VXIMZ, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
} else {
|
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 17:57:28 +08:00
|
|
|
if (unlikely(float64_is_signaling_nan(farg1.d, &env->fp_status) ||
|
|
|
|
float64_is_signaling_nan(farg2.d, &env->fp_status) ||
|
|
|
|
float64_is_signaling_nan(farg3.d, &env->fp_status))) {
|
2012-05-30 12:23:26 +08:00
|
|
|
/* sNaN operation */
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
/* This is the way the PowerPC specification defines it */
|
|
|
|
float128 ft0_128, ft1_128;
|
|
|
|
|
|
|
|
ft0_128 = float64_to_float128(farg1.d, &env->fp_status);
|
|
|
|
ft1_128 = float64_to_float128(farg2.d, &env->fp_status);
|
|
|
|
ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status);
|
|
|
|
if (unlikely(float128_is_infinity(ft0_128) &&
|
|
|
|
float64_is_infinity(farg3.d) &&
|
|
|
|
float128_is_neg(ft0_128) != float64_is_neg(farg3.d))) {
|
|
|
|
/* Magnitude subtraction of infinities */
|
2016-07-27 14:56:25 +08:00
|
|
|
farg1.ll = float_invalid_op_excp(env, POWERPC_EXCP_FP_VXISI, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
} else {
|
|
|
|
ft1_128 = float64_to_float128(farg3.d, &env->fp_status);
|
|
|
|
ft0_128 = float128_add(ft0_128, ft1_128, &env->fp_status);
|
|
|
|
farg1.d = float128_to_float64(ft0_128, &env->fp_status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return farg1.ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fmsub - fmsub. */
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_fmsub(CPUPPCState *env, uint64_t arg1, uint64_t arg2,
|
|
|
|
uint64_t arg3)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU farg1, farg2, farg3;
|
|
|
|
|
|
|
|
farg1.ll = arg1;
|
|
|
|
farg2.ll = arg2;
|
|
|
|
farg3.ll = arg3;
|
|
|
|
|
|
|
|
if (unlikely((float64_is_infinity(farg1.d) && float64_is_zero(farg2.d)) ||
|
|
|
|
(float64_is_zero(farg1.d) &&
|
|
|
|
float64_is_infinity(farg2.d)))) {
|
|
|
|
/* Multiplication of zero by infinity */
|
2016-07-27 14:56:25 +08:00
|
|
|
farg1.ll = float_invalid_op_excp(env, POWERPC_EXCP_FP_VXIMZ, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
} else {
|
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 17:57:28 +08:00
|
|
|
if (unlikely(float64_is_signaling_nan(farg1.d, &env->fp_status) ||
|
|
|
|
float64_is_signaling_nan(farg2.d, &env->fp_status) ||
|
|
|
|
float64_is_signaling_nan(farg3.d, &env->fp_status))) {
|
2012-05-30 12:23:26 +08:00
|
|
|
/* sNaN operation */
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
/* This is the way the PowerPC specification defines it */
|
|
|
|
float128 ft0_128, ft1_128;
|
|
|
|
|
|
|
|
ft0_128 = float64_to_float128(farg1.d, &env->fp_status);
|
|
|
|
ft1_128 = float64_to_float128(farg2.d, &env->fp_status);
|
|
|
|
ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status);
|
|
|
|
if (unlikely(float128_is_infinity(ft0_128) &&
|
|
|
|
float64_is_infinity(farg3.d) &&
|
|
|
|
float128_is_neg(ft0_128) == float64_is_neg(farg3.d))) {
|
|
|
|
/* Magnitude subtraction of infinities */
|
2016-07-27 14:56:25 +08:00
|
|
|
farg1.ll = float_invalid_op_excp(env, POWERPC_EXCP_FP_VXISI, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
} else {
|
|
|
|
ft1_128 = float64_to_float128(farg3.d, &env->fp_status);
|
|
|
|
ft0_128 = float128_sub(ft0_128, ft1_128, &env->fp_status);
|
|
|
|
farg1.d = float128_to_float64(ft0_128, &env->fp_status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return farg1.ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fnmadd - fnmadd. */
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_fnmadd(CPUPPCState *env, uint64_t arg1, uint64_t arg2,
|
|
|
|
uint64_t arg3)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU farg1, farg2, farg3;
|
|
|
|
|
|
|
|
farg1.ll = arg1;
|
|
|
|
farg2.ll = arg2;
|
|
|
|
farg3.ll = arg3;
|
|
|
|
|
|
|
|
if (unlikely((float64_is_infinity(farg1.d) && float64_is_zero(farg2.d)) ||
|
|
|
|
(float64_is_zero(farg1.d) && float64_is_infinity(farg2.d)))) {
|
|
|
|
/* Multiplication of zero by infinity */
|
2016-07-27 14:56:25 +08:00
|
|
|
farg1.ll = float_invalid_op_excp(env, POWERPC_EXCP_FP_VXIMZ, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
} else {
|
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 17:57:28 +08:00
|
|
|
if (unlikely(float64_is_signaling_nan(farg1.d, &env->fp_status) ||
|
|
|
|
float64_is_signaling_nan(farg2.d, &env->fp_status) ||
|
|
|
|
float64_is_signaling_nan(farg3.d, &env->fp_status))) {
|
2012-05-30 12:23:26 +08:00
|
|
|
/* sNaN operation */
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
/* This is the way the PowerPC specification defines it */
|
|
|
|
float128 ft0_128, ft1_128;
|
|
|
|
|
|
|
|
ft0_128 = float64_to_float128(farg1.d, &env->fp_status);
|
|
|
|
ft1_128 = float64_to_float128(farg2.d, &env->fp_status);
|
|
|
|
ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status);
|
|
|
|
if (unlikely(float128_is_infinity(ft0_128) &&
|
|
|
|
float64_is_infinity(farg3.d) &&
|
|
|
|
float128_is_neg(ft0_128) != float64_is_neg(farg3.d))) {
|
|
|
|
/* Magnitude subtraction of infinities */
|
2016-07-27 14:56:25 +08:00
|
|
|
farg1.ll = float_invalid_op_excp(env, POWERPC_EXCP_FP_VXISI, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
} else {
|
|
|
|
ft1_128 = float64_to_float128(farg3.d, &env->fp_status);
|
|
|
|
ft0_128 = float128_add(ft0_128, ft1_128, &env->fp_status);
|
|
|
|
farg1.d = float128_to_float64(ft0_128, &env->fp_status);
|
|
|
|
}
|
|
|
|
if (likely(!float64_is_any_nan(farg1.d))) {
|
|
|
|
farg1.d = float64_chs(farg1.d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return farg1.ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fnmsub - fnmsub. */
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_fnmsub(CPUPPCState *env, uint64_t arg1, uint64_t arg2,
|
|
|
|
uint64_t arg3)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU farg1, farg2, farg3;
|
|
|
|
|
|
|
|
farg1.ll = arg1;
|
|
|
|
farg2.ll = arg2;
|
|
|
|
farg3.ll = arg3;
|
|
|
|
|
|
|
|
if (unlikely((float64_is_infinity(farg1.d) && float64_is_zero(farg2.d)) ||
|
|
|
|
(float64_is_zero(farg1.d) &&
|
|
|
|
float64_is_infinity(farg2.d)))) {
|
|
|
|
/* Multiplication of zero by infinity */
|
2016-07-27 14:56:25 +08:00
|
|
|
farg1.ll = float_invalid_op_excp(env, POWERPC_EXCP_FP_VXIMZ, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
} else {
|
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 17:57:28 +08:00
|
|
|
if (unlikely(float64_is_signaling_nan(farg1.d, &env->fp_status) ||
|
|
|
|
float64_is_signaling_nan(farg2.d, &env->fp_status) ||
|
|
|
|
float64_is_signaling_nan(farg3.d, &env->fp_status))) {
|
2012-05-30 12:23:26 +08:00
|
|
|
/* sNaN operation */
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
/* This is the way the PowerPC specification defines it */
|
|
|
|
float128 ft0_128, ft1_128;
|
|
|
|
|
|
|
|
ft0_128 = float64_to_float128(farg1.d, &env->fp_status);
|
|
|
|
ft1_128 = float64_to_float128(farg2.d, &env->fp_status);
|
|
|
|
ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status);
|
|
|
|
if (unlikely(float128_is_infinity(ft0_128) &&
|
|
|
|
float64_is_infinity(farg3.d) &&
|
|
|
|
float128_is_neg(ft0_128) == float64_is_neg(farg3.d))) {
|
|
|
|
/* Magnitude subtraction of infinities */
|
2016-07-27 14:56:25 +08:00
|
|
|
farg1.ll = float_invalid_op_excp(env, POWERPC_EXCP_FP_VXISI, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
} else {
|
|
|
|
ft1_128 = float64_to_float128(farg3.d, &env->fp_status);
|
|
|
|
ft0_128 = float128_sub(ft0_128, ft1_128, &env->fp_status);
|
|
|
|
farg1.d = float128_to_float64(ft0_128, &env->fp_status);
|
|
|
|
}
|
|
|
|
if (likely(!float64_is_any_nan(farg1.d))) {
|
|
|
|
farg1.d = float64_chs(farg1.d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return farg1.ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* frsp - frsp. */
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_frsp(CPUPPCState *env, uint64_t arg)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU farg;
|
|
|
|
float32 f32;
|
|
|
|
|
|
|
|
farg.ll = arg;
|
|
|
|
|
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 17:57:28 +08:00
|
|
|
if (unlikely(float64_is_signaling_nan(farg.d, &env->fp_status))) {
|
2012-05-30 12:23:26 +08:00
|
|
|
/* sNaN square root */
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
f32 = float64_to_float32(farg.d, &env->fp_status);
|
|
|
|
farg.d = float32_to_float64(f32, &env->fp_status);
|
|
|
|
|
|
|
|
return farg.ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fsqrt - fsqrt. */
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_fsqrt(CPUPPCState *env, uint64_t arg)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU farg;
|
|
|
|
|
|
|
|
farg.ll = arg;
|
|
|
|
|
2014-11-13 05:45:59 +08:00
|
|
|
if (unlikely(float64_is_any_nan(farg.d))) {
|
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 17:57:28 +08:00
|
|
|
if (unlikely(float64_is_signaling_nan(farg.d, &env->fp_status))) {
|
2014-11-13 05:45:59 +08:00
|
|
|
/* sNaN reciprocal square root */
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1);
|
2014-11-13 05:45:59 +08:00
|
|
|
farg.ll = float64_snan_to_qnan(farg.ll);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
2014-11-13 05:45:59 +08:00
|
|
|
} else if (unlikely(float64_is_neg(farg.d) && !float64_is_zero(farg.d))) {
|
|
|
|
/* Square root of a negative nonzero number */
|
2016-07-27 14:56:25 +08:00
|
|
|
farg.ll = float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSQRT, 1);
|
2014-11-13 05:45:59 +08:00
|
|
|
} else {
|
2012-05-30 12:23:26 +08:00
|
|
|
farg.d = float64_sqrt(farg.d, &env->fp_status);
|
|
|
|
}
|
|
|
|
return farg.ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fre - fre. */
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_fre(CPUPPCState *env, uint64_t arg)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU farg;
|
|
|
|
|
|
|
|
farg.ll = arg;
|
|
|
|
|
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 17:57:28 +08:00
|
|
|
if (unlikely(float64_is_signaling_nan(farg.d, &env->fp_status))) {
|
2012-05-30 12:23:26 +08:00
|
|
|
/* sNaN reciprocal */
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
farg.d = float64_div(float64_one, farg.d, &env->fp_status);
|
|
|
|
return farg.d;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fres - fres. */
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_fres(CPUPPCState *env, uint64_t arg)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU farg;
|
|
|
|
float32 f32;
|
|
|
|
|
|
|
|
farg.ll = arg;
|
|
|
|
|
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 17:57:28 +08:00
|
|
|
if (unlikely(float64_is_signaling_nan(farg.d, &env->fp_status))) {
|
2012-05-30 12:23:26 +08:00
|
|
|
/* sNaN reciprocal */
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
farg.d = float64_div(float64_one, farg.d, &env->fp_status);
|
|
|
|
f32 = float64_to_float32(farg.d, &env->fp_status);
|
|
|
|
farg.d = float32_to_float64(f32, &env->fp_status);
|
|
|
|
|
|
|
|
return farg.ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* frsqrte - frsqrte. */
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_frsqrte(CPUPPCState *env, uint64_t arg)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU farg;
|
|
|
|
|
|
|
|
farg.ll = arg;
|
|
|
|
|
2014-11-13 05:45:59 +08:00
|
|
|
if (unlikely(float64_is_any_nan(farg.d))) {
|
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 17:57:28 +08:00
|
|
|
if (unlikely(float64_is_signaling_nan(farg.d, &env->fp_status))) {
|
2012-05-30 12:23:26 +08:00
|
|
|
/* sNaN reciprocal square root */
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1);
|
2014-11-13 05:45:59 +08:00
|
|
|
farg.ll = float64_snan_to_qnan(farg.ll);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
2014-11-13 05:45:59 +08:00
|
|
|
} else if (unlikely(float64_is_neg(farg.d) && !float64_is_zero(farg.d))) {
|
|
|
|
/* Reciprocal square root of a negative nonzero number */
|
2016-07-27 14:56:25 +08:00
|
|
|
farg.ll = float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSQRT, 1);
|
2014-11-13 05:45:59 +08:00
|
|
|
} else {
|
2012-05-30 12:23:26 +08:00
|
|
|
farg.d = float64_sqrt(farg.d, &env->fp_status);
|
|
|
|
farg.d = float64_div(float64_one, farg.d, &env->fp_status);
|
|
|
|
}
|
2014-11-13 05:45:59 +08:00
|
|
|
|
2012-05-30 12:23:26 +08:00
|
|
|
return farg.ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fsel - fsel. */
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_fsel(CPUPPCState *env, uint64_t arg1, uint64_t arg2,
|
|
|
|
uint64_t arg3)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU farg1;
|
|
|
|
|
|
|
|
farg1.ll = arg1;
|
|
|
|
|
|
|
|
if ((!float64_is_neg(farg1.d) || float64_is_zero(farg1.d)) &&
|
|
|
|
!float64_is_any_nan(farg1.d)) {
|
|
|
|
return arg2;
|
|
|
|
} else {
|
|
|
|
return arg3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-08 00:06:07 +08: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-08 00:06:08 +08: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;
|
|
|
|
} else if (!float64_is_zero(frb) && (e_b <= (-1022+52))) {
|
|
|
|
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-08 00:06:07 +08:00
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
void helper_fcmpu(CPUPPCState *env, uint64_t arg1, uint64_t arg2,
|
|
|
|
uint32_t crfD)
|
2012-05-30 12:23:26 +08: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
env->fpscr &= ~(0x0F << FPSCR_FPRF);
|
|
|
|
env->fpscr |= ret << FPSCR_FPRF;
|
|
|
|
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 17:57:28 +08:00
|
|
|
&& (float64_is_signaling_nan(farg1.d, &env->fp_status) ||
|
|
|
|
float64_is_signaling_nan(farg2.d, &env->fp_status)))) {
|
2012-05-30 12:23:26 +08:00
|
|
|
/* sNaN comparison */
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
void helper_fcmpo(CPUPPCState *env, uint64_t arg1, uint64_t arg2,
|
|
|
|
uint32_t crfD)
|
2012-05-30 12:23:26 +08: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
env->fpscr &= ~(0x0F << FPSCR_FPRF);
|
|
|
|
env->fpscr |= ret << FPSCR_FPRF;
|
|
|
|
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 17:57:28 +08:00
|
|
|
if (float64_is_signaling_nan(farg1.d, &env->fp_status) ||
|
|
|
|
float64_is_signaling_nan(farg2.d, &env->fp_status)) {
|
2012-05-30 12:23:26 +08:00
|
|
|
/* sNaN comparison */
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN |
|
2014-01-03 06:21:19 +08:00
|
|
|
POWERPC_EXCP_FP_VXVC, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
} else {
|
|
|
|
/* qNaN comparison */
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXVC, 1);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Single-precision floating-point conversions */
|
2012-05-30 12:23:27 +08:00
|
|
|
static inline uint32_t efscfsi(CPUPPCState *env, uint32_t val)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_FloatU u;
|
|
|
|
|
|
|
|
u.f = int32_to_float32(val, &env->vec_status);
|
|
|
|
|
|
|
|
return u.l;
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
static inline uint32_t efscfui(CPUPPCState *env, uint32_t val)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_FloatU u;
|
|
|
|
|
|
|
|
u.f = uint32_to_float32(val, &env->vec_status);
|
|
|
|
|
|
|
|
return u.l;
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
static inline int32_t efsctsi(CPUPPCState *env, uint32_t val)
|
2012-05-30 12:23:26 +08: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 17:57:28 +08:00
|
|
|
if (unlikely(float32_is_quiet_nan(u.f, &env->vec_status))) {
|
2012-05-30 12:23:26 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return float32_to_int32(u.f, &env->vec_status);
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
static inline uint32_t efsctui(CPUPPCState *env, uint32_t val)
|
2012-05-30 12:23:26 +08: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 17:57:28 +08:00
|
|
|
if (unlikely(float32_is_quiet_nan(u.f, &env->vec_status))) {
|
2012-05-30 12:23:26 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return float32_to_uint32(u.f, &env->vec_status);
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
static inline uint32_t efsctsiz(CPUPPCState *env, uint32_t val)
|
2012-05-30 12:23:26 +08: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 17:57:28 +08:00
|
|
|
if (unlikely(float32_is_quiet_nan(u.f, &env->vec_status))) {
|
2012-05-30 12:23:26 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return float32_to_int32_round_to_zero(u.f, &env->vec_status);
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
static inline uint32_t efsctuiz(CPUPPCState *env, uint32_t val)
|
2012-05-30 12:23:26 +08: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 17:57:28 +08:00
|
|
|
if (unlikely(float32_is_quiet_nan(u.f, &env->vec_status))) {
|
2012-05-30 12:23:26 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return float32_to_uint32_round_to_zero(u.f, &env->vec_status);
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
static inline uint32_t efscfsf(CPUPPCState *env, uint32_t val)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
static inline uint32_t efscfuf(CPUPPCState *env, uint32_t val)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
static inline uint32_t efsctsf(CPUPPCState *env, uint32_t val)
|
2012-05-30 12:23:26 +08: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 17:57:28 +08:00
|
|
|
if (unlikely(float32_is_quiet_nan(u.f, &env->vec_status))) {
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
static inline uint32_t efsctuf(CPUPPCState *env, uint32_t val)
|
2012-05-30 12:23:26 +08: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 17:57:28 +08:00
|
|
|
if (unlikely(float32_is_quiet_nan(u.f, &env->vec_status))) {
|
2012-05-30 12:23:26 +08: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 12:23:27 +08: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 12:23:26 +08: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 12:23:27 +08: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 12:23:26 +08: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 12:23:27 +08:00
|
|
|
static inline uint32_t efsadd(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
static inline uint32_t efssub(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
static inline uint32_t efsmul(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
static inline uint32_t efsdiv(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08: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 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint64_t helper_ev##name(CPUPPCState *env, uint64_t op1, uint64_t op2) \
|
2012-05-30 12:23:26 +08:00
|
|
|
{ \
|
2012-05-30 12:23:27 +08:00
|
|
|
return ((uint64_t)e##name(env, op1 >> 32, op2 >> 32) << 32) | \
|
|
|
|
(uint64_t)e##name(env, op1, op2); \
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
static inline uint32_t efscmplt(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
static inline uint32_t efscmpgt(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
static inline uint32_t efscmpeq(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
static inline uint32_t efststlt(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
/* XXX: TODO: ignore special values (NaN, infinites, ...) */
|
2012-05-30 12:23:27 +08:00
|
|
|
return efscmplt(env, op1, op2);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
static inline uint32_t efststgt(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
/* XXX: TODO: ignore special values (NaN, infinites, ...) */
|
2012-05-30 12:23:27 +08:00
|
|
|
return efscmpgt(env, op1, op2);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
static inline uint32_t efststeq(CPUPPCState *env, uint32_t op1, uint32_t op2)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
/* XXX: TODO: ignore special values (NaN, infinites, ...) */
|
2012-05-30 12:23:27 +08:00
|
|
|
return efscmpeq(env, op1, op2);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08: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 20:11:35 +08:00
|
|
|
return e##name(env, op1, op2); \
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint32_t helper_ev##name(CPUPPCState *env, uint64_t op1, uint64_t op2) \
|
2012-05-30 12:23:26 +08:00
|
|
|
{ \
|
2012-05-30 12:23:27 +08:00
|
|
|
return evcmp_merge(e##name(env, op1 >> 32, op2 >> 32), \
|
|
|
|
e##name(env, op1, op2)); \
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint64_t helper_efdcfsi(CPUPPCState *env, uint32_t val)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU u;
|
|
|
|
|
|
|
|
u.d = int32_to_float64(val, &env->vec_status);
|
|
|
|
|
|
|
|
return u.ll;
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_efdcfsid(CPUPPCState *env, uint64_t val)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU u;
|
|
|
|
|
|
|
|
u.d = int64_to_float64(val, &env->vec_status);
|
|
|
|
|
|
|
|
return u.ll;
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_efdcfui(CPUPPCState *env, uint32_t val)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU u;
|
|
|
|
|
|
|
|
u.d = uint32_to_float64(val, &env->vec_status);
|
|
|
|
|
|
|
|
return u.ll;
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
uint64_t helper_efdcfuid(CPUPPCState *env, uint64_t val)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
CPU_DoubleU u;
|
|
|
|
|
|
|
|
u.d = uint64_to_float64(val, &env->vec_status);
|
|
|
|
|
|
|
|
return u.ll;
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
uint32_t helper_efdctsi(CPUPPCState *env, uint64_t val)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint32_t helper_efdctui(CPUPPCState *env, uint64_t val)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint32_t helper_efdctsiz(CPUPPCState *env, uint64_t val)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint64_t helper_efdctsidz(CPUPPCState *env, uint64_t val)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint32_t helper_efdctuiz(CPUPPCState *env, uint64_t val)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint64_t helper_efdctuidz(CPUPPCState *env, uint64_t val)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint64_t helper_efdcfsf(CPUPPCState *env, uint32_t val)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint64_t helper_efdcfuf(CPUPPCState *env, uint32_t val)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint32_t helper_efdctsf(CPUPPCState *env, uint64_t val)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint32_t helper_efdctuf(CPUPPCState *env, uint64_t val)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint32_t helper_efscfd(CPUPPCState *env, uint64_t val)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint64_t helper_efdcfs(CPUPPCState *env, uint32_t val)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint64_t helper_efdadd(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint64_t helper_efdsub(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint64_t helper_efdmul(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint64_t helper_efddiv(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint32_t helper_efdtstlt(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint32_t helper_efdtstgt(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint32_t helper_efdtsteq(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 12:23:26 +08: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 12:23:27 +08:00
|
|
|
uint32_t helper_efdcmplt(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
/* XXX: TODO: test special values (NaN, infinites, ...) */
|
2012-05-30 12:23:27 +08:00
|
|
|
return helper_efdtstlt(env, op1, op2);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
uint32_t helper_efdcmpgt(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
/* XXX: TODO: test special values (NaN, infinites, ...) */
|
2012-05-30 12:23:27 +08:00
|
|
|
return helper_efdtstgt(env, op1, op2);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:27 +08:00
|
|
|
uint32_t helper_efdcmpeq(CPUPPCState *env, uint64_t op1, uint64_t op2)
|
2012-05-30 12:23:26 +08:00
|
|
|
{
|
|
|
|
/* XXX: TODO: test special values (NaN, infinites, ...) */
|
2012-05-30 12:23:27 +08:00
|
|
|
return helper_efdtsteq(env, op1, op2);
|
2012-05-30 12:23:26 +08:00
|
|
|
}
|
2014-01-03 06:21:20 +08:00
|
|
|
|
|
|
|
typedef union _ppc_vsr_t {
|
|
|
|
uint64_t u64[2];
|
|
|
|
uint32_t u32[4];
|
|
|
|
float32 f32[4];
|
|
|
|
float64 f64[2];
|
|
|
|
} ppc_vsr_t;
|
|
|
|
|
2014-04-01 05:03:57 +08:00
|
|
|
#if defined(HOST_WORDS_BIGENDIAN)
|
|
|
|
#define VsrW(i) u32[i]
|
|
|
|
#define VsrD(i) u64[i]
|
|
|
|
#else
|
|
|
|
#define VsrW(i) u32[3-(i)]
|
|
|
|
#define VsrD(i) u64[1-(i)]
|
|
|
|
#endif
|
|
|
|
|
2014-01-03 06:21:20 +08:00
|
|
|
static void getVSR(int n, ppc_vsr_t *vsr, CPUPPCState *env)
|
|
|
|
{
|
|
|
|
if (n < 32) {
|
2014-04-01 05:03:58 +08:00
|
|
|
vsr->VsrD(0) = env->fpr[n];
|
|
|
|
vsr->VsrD(1) = env->vsr[n];
|
2014-01-03 06:21:20 +08:00
|
|
|
} else {
|
|
|
|
vsr->u64[0] = env->avr[n-32].u64[0];
|
|
|
|
vsr->u64[1] = env->avr[n-32].u64[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void putVSR(int n, ppc_vsr_t *vsr, CPUPPCState *env)
|
|
|
|
{
|
|
|
|
if (n < 32) {
|
2014-04-01 05:03:58 +08:00
|
|
|
env->fpr[n] = vsr->VsrD(0);
|
|
|
|
env->vsr[n] = vsr->VsrD(1);
|
2014-01-03 06:21:20 +08:00
|
|
|
} else {
|
|
|
|
env->avr[n-32].u64[0] = vsr->u64[0];
|
|
|
|
env->avr[n-32].u64[1] = vsr->u64[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define float64_to_float64(x, env) x
|
2014-01-03 06:21:21 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* VSX_ADD_SUB - VSX floating point add/subract
|
|
|
|
* name - instruction mnemonic
|
|
|
|
* op - operation (add or sub)
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 05:03:59 +08:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2014-01-03 06:21:21 +08:00
|
|
|
* sfprf - set FPRF
|
|
|
|
*/
|
2014-01-15 22:10:33 +08:00
|
|
|
#define VSX_ADD_SUB(name, op, nels, tp, fld, sfprf, r2sp) \
|
2014-01-03 06:21:21 +08:00
|
|
|
void helper_##name(CPUPPCState *env, uint32_t opcode) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t xt, xa, xb; \
|
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
getVSR(xA(opcode), &xa, env); \
|
|
|
|
getVSR(xB(opcode), &xb, env); \
|
|
|
|
getVSR(xT(opcode), &xt, env); \
|
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
|
|
|
float_status tstat = env->fp_status; \
|
|
|
|
set_float_exception_flags(0, &tstat); \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt.fld = tp##_##op(xa.fld, xb.fld, &tstat); \
|
2014-01-03 06:21:21 +08:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
|
|
|
|
\
|
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
|
2014-04-01 05:03:59 +08:00
|
|
|
if (tp##_is_infinity(xa.fld) && tp##_is_infinity(xb.fld)) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXISI, sfprf); \
|
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 17:57:28 +08:00
|
|
|
} else if (tp##_is_signaling_nan(xa.fld, &tstat) || \
|
|
|
|
tp##_is_signaling_nan(xb.fld, &tstat)) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, sfprf); \
|
2014-01-03 06:21:21 +08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2014-01-15 22:10:33 +08:00
|
|
|
if (r2sp) { \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt.fld = helper_frsp(env, xt.fld); \
|
2014-01-15 22:10:33 +08:00
|
|
|
} \
|
|
|
|
\
|
2014-01-03 06:21:21 +08:00
|
|
|
if (sfprf) { \
|
2014-11-13 05:46:04 +08:00
|
|
|
helper_compute_fprf(env, xt.fld); \
|
2014-01-03 06:21:21 +08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
putVSR(xT(opcode), &xt, env); \
|
2016-07-27 14:56:27 +08:00
|
|
|
float_check_status(env); \
|
2014-01-03 06:21:21 +08:00
|
|
|
}
|
|
|
|
|
2014-04-01 05:03:59 +08: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 06:21:22 +08:00
|
|
|
|
|
|
|
/* VSX_MUL - VSX floating point multiply
|
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 05:03:59 +08:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2014-01-03 06:21:22 +08:00
|
|
|
* sfprf - set FPRF
|
|
|
|
*/
|
2014-01-15 22:10:34 +08:00
|
|
|
#define VSX_MUL(op, nels, tp, fld, sfprf, r2sp) \
|
2014-01-03 06:21:22 +08:00
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t xt, xa, xb; \
|
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
getVSR(xA(opcode), &xa, env); \
|
|
|
|
getVSR(xB(opcode), &xb, env); \
|
|
|
|
getVSR(xT(opcode), &xt, env); \
|
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
|
|
|
float_status tstat = env->fp_status; \
|
|
|
|
set_float_exception_flags(0, &tstat); \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt.fld = tp##_mul(xa.fld, xb.fld, &tstat); \
|
2014-01-03 06:21:22 +08:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
|
|
|
|
\
|
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
|
2014-04-01 05:03:59 +08:00
|
|
|
if ((tp##_is_infinity(xa.fld) && tp##_is_zero(xb.fld)) || \
|
|
|
|
(tp##_is_infinity(xb.fld) && tp##_is_zero(xa.fld))) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXIMZ, sfprf); \
|
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 17:57:28 +08:00
|
|
|
} else if (tp##_is_signaling_nan(xa.fld, &tstat) || \
|
|
|
|
tp##_is_signaling_nan(xb.fld, &tstat)) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, sfprf); \
|
2014-01-03 06:21:22 +08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2014-01-15 22:10:34 +08:00
|
|
|
if (r2sp) { \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt.fld = helper_frsp(env, xt.fld); \
|
2014-01-15 22:10:34 +08:00
|
|
|
} \
|
|
|
|
\
|
2014-01-03 06:21:22 +08:00
|
|
|
if (sfprf) { \
|
2014-11-13 05:46:04 +08:00
|
|
|
helper_compute_fprf(env, xt.fld); \
|
2014-01-03 06:21:22 +08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
putVSR(xT(opcode), &xt, env); \
|
2016-07-27 14:56:27 +08:00
|
|
|
float_check_status(env); \
|
2014-01-03 06:21:22 +08:00
|
|
|
}
|
|
|
|
|
2014-04-01 05:03:59 +08: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 06:21:23 +08:00
|
|
|
|
|
|
|
/* VSX_DIV - VSX floating point divide
|
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 05:03:59 +08:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2014-01-03 06:21:23 +08:00
|
|
|
* sfprf - set FPRF
|
|
|
|
*/
|
2014-01-15 22:10:35 +08:00
|
|
|
#define VSX_DIV(op, nels, tp, fld, sfprf, r2sp) \
|
2014-01-03 06:21:23 +08:00
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t xt, xa, xb; \
|
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
getVSR(xA(opcode), &xa, env); \
|
|
|
|
getVSR(xB(opcode), &xb, env); \
|
|
|
|
getVSR(xT(opcode), &xt, env); \
|
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
|
|
|
float_status tstat = env->fp_status; \
|
|
|
|
set_float_exception_flags(0, &tstat); \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt.fld = tp##_div(xa.fld, xb.fld, &tstat); \
|
2014-01-03 06:21:23 +08:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
|
|
|
|
\
|
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
|
2014-04-01 05:03:59 +08:00
|
|
|
if (tp##_is_infinity(xa.fld) && tp##_is_infinity(xb.fld)) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXIDI, sfprf); \
|
2014-04-01 05:03:59 +08:00
|
|
|
} else if (tp##_is_zero(xa.fld) && \
|
|
|
|
tp##_is_zero(xb.fld)) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXZDZ, sfprf); \
|
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 17:57:28 +08:00
|
|
|
} else if (tp##_is_signaling_nan(xa.fld, &tstat) || \
|
|
|
|
tp##_is_signaling_nan(xb.fld, &tstat)) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, sfprf); \
|
2014-01-03 06:21:23 +08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2014-01-15 22:10:35 +08:00
|
|
|
if (r2sp) { \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt.fld = helper_frsp(env, xt.fld); \
|
2014-01-15 22:10:35 +08:00
|
|
|
} \
|
|
|
|
\
|
2014-01-03 06:21:23 +08:00
|
|
|
if (sfprf) { \
|
2014-11-13 05:46:04 +08:00
|
|
|
helper_compute_fprf(env, xt.fld); \
|
2014-01-03 06:21:23 +08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
putVSR(xT(opcode), &xt, env); \
|
2016-07-27 14:56:27 +08:00
|
|
|
float_check_status(env); \
|
2014-01-03 06:21:23 +08:00
|
|
|
}
|
|
|
|
|
2014-04-01 05:03:59 +08: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 06:21:24 +08:00
|
|
|
|
|
|
|
/* VSX_RE - VSX floating point reciprocal estimate
|
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 05:03:59 +08:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2014-01-03 06:21:24 +08:00
|
|
|
* sfprf - set FPRF
|
|
|
|
*/
|
2014-01-15 22:10:36 +08:00
|
|
|
#define VSX_RE(op, nels, tp, fld, sfprf, r2sp) \
|
2014-01-03 06:21:24 +08:00
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t xt, xb; \
|
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
getVSR(xB(opcode), &xb, env); \
|
|
|
|
getVSR(xT(opcode), &xt, env); \
|
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
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 17:57:28 +08:00
|
|
|
if (unlikely(tp##_is_signaling_nan(xb.fld, &env->fp_status))) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, sfprf); \
|
2014-01-03 06:21:24 +08:00
|
|
|
} \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt.fld = tp##_div(tp##_one, xb.fld, &env->fp_status); \
|
2014-01-15 22:10:36 +08:00
|
|
|
\
|
|
|
|
if (r2sp) { \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt.fld = helper_frsp(env, xt.fld); \
|
2014-01-15 22:10:36 +08:00
|
|
|
} \
|
|
|
|
\
|
2014-01-03 06:21:24 +08:00
|
|
|
if (sfprf) { \
|
2014-11-13 05:46:04 +08:00
|
|
|
helper_compute_fprf(env, xt.fld); \
|
2014-01-03 06:21:24 +08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
putVSR(xT(opcode), &xt, env); \
|
2016-07-27 14:56:27 +08:00
|
|
|
float_check_status(env); \
|
2014-01-03 06:21:24 +08:00
|
|
|
}
|
|
|
|
|
2014-04-01 05:03:59 +08: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 06:21:25 +08:00
|
|
|
|
|
|
|
/* VSX_SQRT - VSX floating point square root
|
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 05:03:59 +08:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2014-01-03 06:21:25 +08:00
|
|
|
* sfprf - set FPRF
|
|
|
|
*/
|
2014-01-15 22:10:37 +08:00
|
|
|
#define VSX_SQRT(op, nels, tp, fld, sfprf, r2sp) \
|
2014-01-03 06:21:25 +08:00
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t xt, xb; \
|
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
getVSR(xB(opcode), &xb, env); \
|
|
|
|
getVSR(xT(opcode), &xt, env); \
|
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
|
|
|
float_status tstat = env->fp_status; \
|
|
|
|
set_float_exception_flags(0, &tstat); \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt.fld = tp##_sqrt(xb.fld, &tstat); \
|
2014-01-03 06:21:25 +08:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
|
|
|
|
\
|
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
|
2014-04-01 05:03:59 +08:00
|
|
|
if (tp##_is_neg(xb.fld) && !tp##_is_zero(xb.fld)) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSQRT, sfprf); \
|
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 17:57:28 +08:00
|
|
|
} else if (tp##_is_signaling_nan(xb.fld, &tstat)) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, sfprf); \
|
2014-01-03 06:21:25 +08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2014-01-15 22:10:37 +08:00
|
|
|
if (r2sp) { \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt.fld = helper_frsp(env, xt.fld); \
|
2014-01-15 22:10:37 +08:00
|
|
|
} \
|
|
|
|
\
|
2014-01-03 06:21:25 +08:00
|
|
|
if (sfprf) { \
|
2014-11-13 05:46:04 +08:00
|
|
|
helper_compute_fprf(env, xt.fld); \
|
2014-01-03 06:21:25 +08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
putVSR(xT(opcode), &xt, env); \
|
2016-07-27 14:56:27 +08:00
|
|
|
float_check_status(env); \
|
2014-01-03 06:21:25 +08:00
|
|
|
}
|
|
|
|
|
2014-04-01 05:03:59 +08: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 06:21:26 +08:00
|
|
|
|
|
|
|
/* VSX_RSQRTE - VSX floating point reciprocal square root estimate
|
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 05:03:59 +08:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2014-01-03 06:21:26 +08:00
|
|
|
* sfprf - set FPRF
|
|
|
|
*/
|
2014-01-15 22:10:38 +08:00
|
|
|
#define VSX_RSQRTE(op, nels, tp, fld, sfprf, r2sp) \
|
2014-01-03 06:21:26 +08:00
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t xt, xb; \
|
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
getVSR(xB(opcode), &xb, env); \
|
|
|
|
getVSR(xT(opcode), &xt, env); \
|
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
|
|
|
float_status tstat = env->fp_status; \
|
|
|
|
set_float_exception_flags(0, &tstat); \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt.fld = tp##_sqrt(xb.fld, &tstat); \
|
|
|
|
xt.fld = tp##_div(tp##_one, xt.fld, &tstat); \
|
2014-01-03 06:21:26 +08:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
|
|
|
|
\
|
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
|
2014-04-01 05:03:59 +08:00
|
|
|
if (tp##_is_neg(xb.fld) && !tp##_is_zero(xb.fld)) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSQRT, sfprf); \
|
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 17:57:28 +08:00
|
|
|
} else if (tp##_is_signaling_nan(xb.fld, &tstat)) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, sfprf); \
|
2014-01-03 06:21:26 +08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2014-01-15 22:10:38 +08:00
|
|
|
if (r2sp) { \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt.fld = helper_frsp(env, xt.fld); \
|
2014-01-15 22:10:38 +08:00
|
|
|
} \
|
|
|
|
\
|
2014-01-03 06:21:26 +08:00
|
|
|
if (sfprf) { \
|
2014-11-13 05:46:04 +08:00
|
|
|
helper_compute_fprf(env, xt.fld); \
|
2014-01-03 06:21:26 +08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
putVSR(xT(opcode), &xt, env); \
|
2016-07-27 14:56:27 +08:00
|
|
|
float_check_status(env); \
|
2014-01-03 06:21:26 +08:00
|
|
|
}
|
|
|
|
|
2014-04-01 05:03:59 +08: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 06:21:27 +08:00
|
|
|
|
|
|
|
/* VSX_TDIV - VSX floating point test for divide
|
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 05:03:59 +08:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2014-01-03 06:21:27 +08:00
|
|
|
* emin - minimum unbiased exponent
|
|
|
|
* emax - maximum unbiased exponent
|
|
|
|
* nbits - number of fraction bits
|
|
|
|
*/
|
|
|
|
#define VSX_TDIV(op, nels, tp, fld, emin, emax, nbits) \
|
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t xa, xb; \
|
|
|
|
int i; \
|
|
|
|
int fe_flag = 0; \
|
|
|
|
int fg_flag = 0; \
|
|
|
|
\
|
|
|
|
getVSR(xA(opcode), &xa, env); \
|
|
|
|
getVSR(xB(opcode), &xb, env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
2014-04-01 05:03:59 +08:00
|
|
|
if (unlikely(tp##_is_infinity(xa.fld) || \
|
|
|
|
tp##_is_infinity(xb.fld) || \
|
|
|
|
tp##_is_zero(xb.fld))) { \
|
2014-01-03 06:21:27 +08:00
|
|
|
fe_flag = 1; \
|
|
|
|
fg_flag = 1; \
|
|
|
|
} else { \
|
2014-04-01 05:03:59 +08:00
|
|
|
int e_a = ppc_##tp##_get_unbiased_exp(xa.fld); \
|
|
|
|
int e_b = ppc_##tp##_get_unbiased_exp(xb.fld); \
|
2014-01-03 06:21:27 +08:00
|
|
|
\
|
2014-04-01 05:03:59 +08:00
|
|
|
if (unlikely(tp##_is_any_nan(xa.fld) || \
|
|
|
|
tp##_is_any_nan(xb.fld))) { \
|
2014-01-03 06:21:27 +08:00
|
|
|
fe_flag = 1; \
|
|
|
|
} else if ((e_b <= emin) || (e_b >= (emax-2))) { \
|
|
|
|
fe_flag = 1; \
|
2014-04-01 05:03:59 +08:00
|
|
|
} else if (!tp##_is_zero(xa.fld) && \
|
2014-01-03 06:21:27 +08:00
|
|
|
(((e_a - e_b) >= emax) || \
|
|
|
|
((e_a - e_b) <= (emin+1)) || \
|
|
|
|
(e_a <= (emin+nbits)))) { \
|
|
|
|
fe_flag = 1; \
|
|
|
|
} \
|
|
|
|
\
|
2014-04-01 05:03:59 +08:00
|
|
|
if (unlikely(tp##_is_zero_or_denormal(xb.fld))) { \
|
2014-01-03 06:21:27 +08:00
|
|
|
/* XB is not zero because of the above check and */ \
|
|
|
|
/* so must be denormalized. */ \
|
|
|
|
fg_flag = 1; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
env->crf[BF(opcode)] = 0x8 | (fg_flag ? 4 : 0) | (fe_flag ? 2 : 0); \
|
|
|
|
}
|
|
|
|
|
2014-04-01 05:03:59 +08: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 06:21:28 +08:00
|
|
|
|
|
|
|
/* VSX_TSQRT - VSX floating point test for square root
|
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 05:03:59 +08:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2014-01-03 06:21:28 +08:00
|
|
|
* emin - minimum unbiased exponent
|
|
|
|
* emax - maximum unbiased exponent
|
|
|
|
* nbits - number of fraction bits
|
|
|
|
*/
|
|
|
|
#define VSX_TSQRT(op, nels, tp, fld, emin, nbits) \
|
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t xa, xb; \
|
|
|
|
int i; \
|
|
|
|
int fe_flag = 0; \
|
|
|
|
int fg_flag = 0; \
|
|
|
|
\
|
|
|
|
getVSR(xA(opcode), &xa, env); \
|
|
|
|
getVSR(xB(opcode), &xb, env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
2014-04-01 05:03:59 +08:00
|
|
|
if (unlikely(tp##_is_infinity(xb.fld) || \
|
|
|
|
tp##_is_zero(xb.fld))) { \
|
2014-01-03 06:21:28 +08:00
|
|
|
fe_flag = 1; \
|
|
|
|
fg_flag = 1; \
|
|
|
|
} else { \
|
2014-04-01 05:03:59 +08:00
|
|
|
int e_b = ppc_##tp##_get_unbiased_exp(xb.fld); \
|
2014-01-03 06:21:28 +08:00
|
|
|
\
|
2014-04-01 05:03:59 +08:00
|
|
|
if (unlikely(tp##_is_any_nan(xb.fld))) { \
|
2014-01-03 06:21:28 +08:00
|
|
|
fe_flag = 1; \
|
2014-04-01 05:03:59 +08:00
|
|
|
} else if (unlikely(tp##_is_zero(xb.fld))) { \
|
2014-01-03 06:21:28 +08:00
|
|
|
fe_flag = 1; \
|
2014-04-01 05:03:59 +08:00
|
|
|
} else if (unlikely(tp##_is_neg(xb.fld))) { \
|
2014-01-03 06:21:28 +08:00
|
|
|
fe_flag = 1; \
|
2014-04-01 05:03:59 +08:00
|
|
|
} else if (!tp##_is_zero(xb.fld) && \
|
2014-01-03 06:21:28 +08:00
|
|
|
(e_b <= (emin+nbits))) { \
|
|
|
|
fe_flag = 1; \
|
|
|
|
} \
|
|
|
|
\
|
2014-04-01 05:03:59 +08:00
|
|
|
if (unlikely(tp##_is_zero_or_denormal(xb.fld))) { \
|
2014-01-03 06:21:28 +08:00
|
|
|
/* XB is not zero because of the above check and */ \
|
|
|
|
/* therefore must be denormalized. */ \
|
|
|
|
fg_flag = 1; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
env->crf[BF(opcode)] = 0x8 | (fg_flag ? 4 : 0) | (fe_flag ? 2 : 0); \
|
|
|
|
}
|
|
|
|
|
2014-04-01 05:03:59 +08: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 06:21:29 +08:00
|
|
|
|
|
|
|
/* VSX_MADD - VSX floating point muliply/add variations
|
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 05:03:59 +08: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 06:21:29 +08:00
|
|
|
* maddflgs - flags for the float*muladd routine that control the
|
|
|
|
* various forms (madd, msub, nmadd, nmsub)
|
|
|
|
* afrm - A form (1=A, 0=M)
|
|
|
|
* sfprf - set FPRF
|
|
|
|
*/
|
2014-01-15 22:10:39 +08:00
|
|
|
#define VSX_MADD(op, nels, tp, fld, maddflgs, afrm, sfprf, r2sp) \
|
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 06:21:29 +08:00
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t xt_in, xa, xb, xt_out; \
|
|
|
|
ppc_vsr_t *b, *c; \
|
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
if (afrm) { /* AxB + T */ \
|
|
|
|
b = &xb; \
|
|
|
|
c = &xt_in; \
|
|
|
|
} else { /* AxT + B */ \
|
|
|
|
b = &xt_in; \
|
|
|
|
c = &xb; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
getVSR(xA(opcode), &xa, env); \
|
|
|
|
getVSR(xB(opcode), &xb, env); \
|
|
|
|
getVSR(xT(opcode), &xt_in, env); \
|
|
|
|
\
|
|
|
|
xt_out = xt_in; \
|
|
|
|
\
|
|
|
|
helper_reset_fpstatus(env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
|
|
|
float_status tstat = env->fp_status; \
|
|
|
|
set_float_exception_flags(0, &tstat); \
|
2014-01-15 22:10:39 +08:00
|
|
|
if (r2sp && (tstat.float_rounding_mode == float_round_nearest_even)) {\
|
|
|
|
/* Avoid double rounding errors by rounding the intermediate */ \
|
|
|
|
/* result to odd. */ \
|
|
|
|
set_float_rounding_mode(float_round_to_zero, &tstat); \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt_out.fld = tp##_muladd(xa.fld, b->fld, c->fld, \
|
2014-01-15 22:10:39 +08:00
|
|
|
maddflgs, &tstat); \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt_out.fld |= (get_float_exception_flags(&tstat) & \
|
2014-01-15 22:10:39 +08:00
|
|
|
float_flag_inexact) != 0; \
|
|
|
|
} else { \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt_out.fld = tp##_muladd(xa.fld, b->fld, c->fld, \
|
2014-01-15 22:10:39 +08:00
|
|
|
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 06:21:29 +08:00
|
|
|
env->fp_status.float_exception_flags |= tstat.float_exception_flags; \
|
|
|
|
\
|
|
|
|
if (unlikely(tstat.float_exception_flags & float_flag_invalid)) { \
|
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 17:57:28 +08:00
|
|
|
if (tp##_is_signaling_nan(xa.fld, &tstat) || \
|
|
|
|
tp##_is_signaling_nan(b->fld, &tstat) || \
|
|
|
|
tp##_is_signaling_nan(c->fld, &tstat)) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, sfprf); \
|
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 06:21:29 +08:00
|
|
|
tstat.float_exception_flags &= ~float_flag_invalid; \
|
|
|
|
} \
|
2014-04-01 05:03:59 +08:00
|
|
|
if ((tp##_is_infinity(xa.fld) && tp##_is_zero(b->fld)) || \
|
|
|
|
(tp##_is_zero(xa.fld) && tp##_is_infinity(b->fld))) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
xt_out.fld = float64_to_##tp(float_invalid_op_excp(env, \
|
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 06:21:29 +08:00
|
|
|
POWERPC_EXCP_FP_VXIMZ, sfprf), &env->fp_status); \
|
|
|
|
tstat.float_exception_flags &= ~float_flag_invalid; \
|
|
|
|
} \
|
|
|
|
if ((tstat.float_exception_flags & float_flag_invalid) && \
|
2014-04-01 05:03:59 +08:00
|
|
|
((tp##_is_infinity(xa.fld) || \
|
|
|
|
tp##_is_infinity(b->fld)) && \
|
|
|
|
tp##_is_infinity(c->fld))) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXISI, sfprf); \
|
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 06:21:29 +08:00
|
|
|
} \
|
|
|
|
} \
|
2014-01-15 22:10:39 +08:00
|
|
|
\
|
|
|
|
if (r2sp) { \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt_out.fld = helper_frsp(env, xt_out.fld); \
|
2014-01-15 22:10:39 +08:00
|
|
|
} \
|
|
|
|
\
|
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 06:21:29 +08:00
|
|
|
if (sfprf) { \
|
2014-11-13 05:46:04 +08:00
|
|
|
helper_compute_fprf(env, xt_out.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 06:21:29 +08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
putVSR(xT(opcode), &xt_out, env); \
|
2016-07-27 14:56:27 +08:00
|
|
|
float_check_status(env); \
|
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 06:21:29 +08: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)
|
|
|
|
|
2014-04-01 05:03:59 +08:00
|
|
|
VSX_MADD(xsmaddadp, 1, float64, VsrD(0), MADD_FLGS, 1, 1, 0)
|
|
|
|
VSX_MADD(xsmaddmdp, 1, float64, VsrD(0), MADD_FLGS, 0, 1, 0)
|
|
|
|
VSX_MADD(xsmsubadp, 1, float64, VsrD(0), MSUB_FLGS, 1, 1, 0)
|
|
|
|
VSX_MADD(xsmsubmdp, 1, float64, VsrD(0), MSUB_FLGS, 0, 1, 0)
|
|
|
|
VSX_MADD(xsnmaddadp, 1, float64, VsrD(0), NMADD_FLGS, 1, 1, 0)
|
|
|
|
VSX_MADD(xsnmaddmdp, 1, float64, VsrD(0), NMADD_FLGS, 0, 1, 0)
|
|
|
|
VSX_MADD(xsnmsubadp, 1, float64, VsrD(0), NMSUB_FLGS, 1, 1, 0)
|
|
|
|
VSX_MADD(xsnmsubmdp, 1, float64, VsrD(0), NMSUB_FLGS, 0, 1, 0)
|
|
|
|
|
|
|
|
VSX_MADD(xsmaddasp, 1, float64, VsrD(0), MADD_FLGS, 1, 1, 1)
|
|
|
|
VSX_MADD(xsmaddmsp, 1, float64, VsrD(0), MADD_FLGS, 0, 1, 1)
|
|
|
|
VSX_MADD(xsmsubasp, 1, float64, VsrD(0), MSUB_FLGS, 1, 1, 1)
|
|
|
|
VSX_MADD(xsmsubmsp, 1, float64, VsrD(0), MSUB_FLGS, 0, 1, 1)
|
|
|
|
VSX_MADD(xsnmaddasp, 1, float64, VsrD(0), NMADD_FLGS, 1, 1, 1)
|
|
|
|
VSX_MADD(xsnmaddmsp, 1, float64, VsrD(0), NMADD_FLGS, 0, 1, 1)
|
|
|
|
VSX_MADD(xsnmsubasp, 1, float64, VsrD(0), NMSUB_FLGS, 1, 1, 1)
|
|
|
|
VSX_MADD(xsnmsubmsp, 1, float64, VsrD(0), NMSUB_FLGS, 0, 1, 1)
|
|
|
|
|
|
|
|
VSX_MADD(xvmaddadp, 2, float64, VsrD(i), MADD_FLGS, 1, 0, 0)
|
|
|
|
VSX_MADD(xvmaddmdp, 2, float64, VsrD(i), MADD_FLGS, 0, 0, 0)
|
|
|
|
VSX_MADD(xvmsubadp, 2, float64, VsrD(i), MSUB_FLGS, 1, 0, 0)
|
|
|
|
VSX_MADD(xvmsubmdp, 2, float64, VsrD(i), MSUB_FLGS, 0, 0, 0)
|
|
|
|
VSX_MADD(xvnmaddadp, 2, float64, VsrD(i), NMADD_FLGS, 1, 0, 0)
|
|
|
|
VSX_MADD(xvnmaddmdp, 2, float64, VsrD(i), NMADD_FLGS, 0, 0, 0)
|
|
|
|
VSX_MADD(xvnmsubadp, 2, float64, VsrD(i), NMSUB_FLGS, 1, 0, 0)
|
|
|
|
VSX_MADD(xvnmsubmdp, 2, float64, VsrD(i), NMSUB_FLGS, 0, 0, 0)
|
|
|
|
|
|
|
|
VSX_MADD(xvmaddasp, 4, float32, VsrW(i), MADD_FLGS, 1, 0, 0)
|
|
|
|
VSX_MADD(xvmaddmsp, 4, float32, VsrW(i), MADD_FLGS, 0, 0, 0)
|
|
|
|
VSX_MADD(xvmsubasp, 4, float32, VsrW(i), MSUB_FLGS, 1, 0, 0)
|
|
|
|
VSX_MADD(xvmsubmsp, 4, float32, VsrW(i), MSUB_FLGS, 0, 0, 0)
|
|
|
|
VSX_MADD(xvnmaddasp, 4, float32, VsrW(i), NMADD_FLGS, 1, 0, 0)
|
|
|
|
VSX_MADD(xvnmaddmsp, 4, float32, VsrW(i), NMADD_FLGS, 0, 0, 0)
|
|
|
|
VSX_MADD(xvnmsubasp, 4, float32, VsrW(i), NMSUB_FLGS, 1, 0, 0)
|
|
|
|
VSX_MADD(xvnmsubmsp, 4, float32, VsrW(i), NMSUB_FLGS, 0, 0, 0)
|
2014-01-03 06:21:30 +08:00
|
|
|
|
2016-10-26 14:26:24 +08:00
|
|
|
/* VSX_SCALAR_CMP_DP - VSX scalar floating point compare double precision
|
|
|
|
* op - instruction mnemonic
|
|
|
|
* cmp - comparison operation
|
|
|
|
* exp - expected result of comparison
|
|
|
|
* svxvc - set VXVC bit
|
|
|
|
*/
|
|
|
|
#define VSX_SCALAR_CMP_DP(op, cmp, exp, svxvc) \
|
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t xt, xa, xb; \
|
|
|
|
bool vxsnan_flag = false, vxvc_flag = false, vex_flag = false; \
|
|
|
|
\
|
|
|
|
getVSR(xA(opcode), &xa, env); \
|
|
|
|
getVSR(xB(opcode), &xb, env); \
|
|
|
|
getVSR(xT(opcode), &xt, env); \
|
|
|
|
\
|
|
|
|
if (float64_is_signaling_nan(xa.VsrD(0), &env->fp_status) || \
|
|
|
|
float64_is_signaling_nan(xb.VsrD(0), &env->fp_status)) { \
|
|
|
|
vxsnan_flag = true; \
|
|
|
|
if (fpscr_ve == 0 && svxvc) { \
|
|
|
|
vxvc_flag = true; \
|
|
|
|
} \
|
|
|
|
} else if (svxvc) { \
|
|
|
|
vxvc_flag = float64_is_quiet_nan(xa.VsrD(0), &env->fp_status) || \
|
|
|
|
float64_is_quiet_nan(xb.VsrD(0), &env->fp_status); \
|
|
|
|
} \
|
|
|
|
if (vxsnan_flag) { \
|
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 0); \
|
|
|
|
} \
|
|
|
|
if (vxvc_flag) { \
|
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXVC, 0); \
|
|
|
|
} \
|
|
|
|
vex_flag = fpscr_ve && (vxvc_flag || vxsnan_flag); \
|
|
|
|
\
|
|
|
|
if (!vex_flag) { \
|
|
|
|
if (float64_##cmp(xb.VsrD(0), xa.VsrD(0), &env->fp_status) == exp) { \
|
|
|
|
xt.VsrD(0) = -1; \
|
|
|
|
xt.VsrD(1) = 0; \
|
|
|
|
} else { \
|
|
|
|
xt.VsrD(0) = 0; \
|
|
|
|
xt.VsrD(1) = 0; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
putVSR(xT(opcode), &xt, env); \
|
|
|
|
helper_float_check_status(env); \
|
|
|
|
}
|
|
|
|
|
|
|
|
VSX_SCALAR_CMP_DP(xscmpeqdp, eq, 1, 0)
|
|
|
|
VSX_SCALAR_CMP_DP(xscmpgedp, le, 1, 1)
|
|
|
|
VSX_SCALAR_CMP_DP(xscmpgtdp, lt, 1, 1)
|
|
|
|
VSX_SCALAR_CMP_DP(xscmpnedp, eq, 0, 0)
|
|
|
|
|
2014-01-03 06:21:30 +08:00
|
|
|
#define VSX_SCALAR_CMP(op, ordered) \
|
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t xa, xb; \
|
|
|
|
uint32_t cc = 0; \
|
|
|
|
\
|
|
|
|
getVSR(xA(opcode), &xa, env); \
|
|
|
|
getVSR(xB(opcode), &xb, env); \
|
|
|
|
\
|
2014-04-01 05:04:00 +08:00
|
|
|
if (unlikely(float64_is_any_nan(xa.VsrD(0)) || \
|
|
|
|
float64_is_any_nan(xb.VsrD(0)))) { \
|
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 17:57:28 +08:00
|
|
|
if (float64_is_signaling_nan(xa.VsrD(0), &env->fp_status) || \
|
|
|
|
float64_is_signaling_nan(xb.VsrD(0), &env->fp_status)) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 0); \
|
2014-01-03 06:21:30 +08:00
|
|
|
} \
|
|
|
|
if (ordered) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXVC, 0); \
|
2014-01-03 06:21:30 +08:00
|
|
|
} \
|
|
|
|
cc = 1; \
|
|
|
|
} else { \
|
2014-04-01 05:04:00 +08:00
|
|
|
if (float64_lt(xa.VsrD(0), xb.VsrD(0), &env->fp_status)) { \
|
2014-01-03 06:21:30 +08:00
|
|
|
cc = 8; \
|
2014-04-01 05:04:00 +08:00
|
|
|
} else if (!float64_le(xa.VsrD(0), xb.VsrD(0), \
|
|
|
|
&env->fp_status)) { \
|
2014-01-03 06:21:30 +08:00
|
|
|
cc = 4; \
|
|
|
|
} else { \
|
|
|
|
cc = 2; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
env->fpscr &= ~(0x0F << FPSCR_FPRF); \
|
|
|
|
env->fpscr |= cc << FPSCR_FPRF; \
|
|
|
|
env->crf[BF(opcode)] = cc; \
|
|
|
|
\
|
2016-07-27 14:56:27 +08:00
|
|
|
float_check_status(env); \
|
2014-01-03 06:21:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
VSX_SCALAR_CMP(xscmpodp, 1)
|
|
|
|
VSX_SCALAR_CMP(xscmpudp, 0)
|
2014-01-03 06:21:31 +08:00
|
|
|
|
|
|
|
/* VSX_MAX_MIN - VSX floating point maximum/minimum
|
|
|
|
* name - instruction mnemonic
|
|
|
|
* op - operation (max or min)
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 05:03:59 +08:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2014-01-03 06:21:31 +08:00
|
|
|
*/
|
|
|
|
#define VSX_MAX_MIN(name, op, nels, tp, fld) \
|
|
|
|
void helper_##name(CPUPPCState *env, uint32_t opcode) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t xt, xa, xb; \
|
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
getVSR(xA(opcode), &xa, env); \
|
|
|
|
getVSR(xB(opcode), &xb, env); \
|
|
|
|
getVSR(xT(opcode), &xt, env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt.fld = tp##_##op(xa.fld, xb.fld, &env->fp_status); \
|
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 17:57:28 +08:00
|
|
|
if (unlikely(tp##_is_signaling_nan(xa.fld, &env->fp_status) || \
|
|
|
|
tp##_is_signaling_nan(xb.fld, &env->fp_status))) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 0); \
|
2014-01-03 06:21:31 +08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
putVSR(xT(opcode), &xt, env); \
|
2016-07-27 14:56:27 +08:00
|
|
|
float_check_status(env); \
|
2014-01-03 06:21:31 +08:00
|
|
|
}
|
|
|
|
|
2014-04-01 05:03:59 +08: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 06:21:32 +08:00
|
|
|
|
|
|
|
/* VSX_CMP - VSX floating point compare
|
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 05:03:59 +08:00
|
|
|
* fld - vsr_t field (VsrD(*) or VsrW(*))
|
2014-01-03 06:21:32 +08:00
|
|
|
* cmp - comparison operation
|
|
|
|
* svxvc - set VXVC bit
|
2016-10-26 14:26:29 +08:00
|
|
|
* exp - expected result of comparison
|
2014-01-03 06:21:32 +08:00
|
|
|
*/
|
2016-10-26 14:26:29 +08:00
|
|
|
#define VSX_CMP(op, nels, tp, fld, cmp, svxvc, exp) \
|
2014-01-03 06:21:32 +08:00
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t xt, xa, xb; \
|
|
|
|
int i; \
|
|
|
|
int all_true = 1; \
|
|
|
|
int all_false = 1; \
|
|
|
|
\
|
|
|
|
getVSR(xA(opcode), &xa, env); \
|
|
|
|
getVSR(xB(opcode), &xb, env); \
|
|
|
|
getVSR(xT(opcode), &xt, env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
2014-04-01 05:03:59 +08:00
|
|
|
if (unlikely(tp##_is_any_nan(xa.fld) || \
|
|
|
|
tp##_is_any_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 17:57:28 +08:00
|
|
|
if (tp##_is_signaling_nan(xa.fld, &env->fp_status) || \
|
|
|
|
tp##_is_signaling_nan(xb.fld, &env->fp_status)) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 0); \
|
2014-01-03 06:21:32 +08:00
|
|
|
} \
|
|
|
|
if (svxvc) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXVC, 0); \
|
2014-01-03 06:21:32 +08:00
|
|
|
} \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt.fld = 0; \
|
2014-01-03 06:21:32 +08:00
|
|
|
all_true = 0; \
|
|
|
|
} else { \
|
2016-10-26 14:26:29 +08:00
|
|
|
if (tp##_##cmp(xb.fld, xa.fld, &env->fp_status) == exp) { \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt.fld = -1; \
|
2014-01-03 06:21:32 +08:00
|
|
|
all_false = 0; \
|
|
|
|
} else { \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt.fld = 0; \
|
2014-01-03 06:21:32 +08:00
|
|
|
all_true = 0; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
putVSR(xT(opcode), &xt, env); \
|
|
|
|
if ((opcode >> (31-21)) & 1) { \
|
|
|
|
env->crf[6] = (all_true ? 0x8 : 0) | (all_false ? 0x2 : 0); \
|
|
|
|
} \
|
2016-07-27 14:56:27 +08:00
|
|
|
float_check_status(env); \
|
2014-01-03 06:21:32 +08:00
|
|
|
}
|
|
|
|
|
2016-10-26 14:26:29 +08: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 06:21:33 +08:00
|
|
|
|
|
|
|
/* VSX_CVT_FP_TO_FP - VSX floating point/floating point conversion
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
#define VSX_CVT_FP_TO_FP(op, nels, stp, ttp, sfld, tfld, sfprf) \
|
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t xt, xb; \
|
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
getVSR(xB(opcode), &xb, env); \
|
|
|
|
getVSR(xT(opcode), &xt, env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
|
|
|
xt.tfld = stp##_to_##ttp(xb.sfld, &env->fp_status); \
|
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 17:57:28 +08:00
|
|
|
if (unlikely(stp##_is_signaling_nan(xb.sfld, \
|
|
|
|
&env->fp_status))) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 0); \
|
2014-01-03 06:21:33 +08:00
|
|
|
xt.tfld = ttp##_snan_to_qnan(xt.tfld); \
|
|
|
|
} \
|
|
|
|
if (sfprf) { \
|
|
|
|
helper_compute_fprf(env, ttp##_to_float64(xt.tfld, \
|
2014-11-13 05:46:04 +08:00
|
|
|
&env->fp_status)); \
|
2014-01-03 06:21:33 +08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
putVSR(xT(opcode), &xt, env); \
|
2016-07-27 14:56:27 +08:00
|
|
|
float_check_status(env); \
|
2014-01-03 06:21:33 +08:00
|
|
|
}
|
|
|
|
|
2014-04-01 05:04:01 +08:00
|
|
|
VSX_CVT_FP_TO_FP(xscvdpsp, 1, float64, float32, VsrD(0), VsrW(0), 1)
|
|
|
|
VSX_CVT_FP_TO_FP(xscvspdp, 1, float32, float64, VsrW(0), VsrD(0), 1)
|
|
|
|
VSX_CVT_FP_TO_FP(xvcvdpsp, 2, float64, float32, VsrD(i), VsrW(2*i), 0)
|
|
|
|
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 06:21:34 +08:00
|
|
|
|
2014-01-15 22:10:45 +08:00
|
|
|
uint64_t helper_xscvdpspn(CPUPPCState *env, uint64_t xb)
|
|
|
|
{
|
|
|
|
float_status tstat = env->fp_status;
|
|
|
|
set_float_exception_flags(0, &tstat);
|
|
|
|
|
|
|
|
return (uint64_t)float64_to_float32(xb, &tstat) << 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t helper_xscvspdpn(CPUPPCState *env, uint64_t xb)
|
|
|
|
{
|
|
|
|
float_status tstat = env->fp_status;
|
|
|
|
set_float_exception_flags(0, &tstat);
|
|
|
|
|
|
|
|
return float32_to_float64(xb >> 32, &tstat);
|
|
|
|
}
|
|
|
|
|
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 06:21:34 +08:00
|
|
|
/* VSX_CVT_FP_TO_INT - VSX floating point to integer conversion
|
|
|
|
* 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
|
|
|
|
* rnan - resulting NaN
|
|
|
|
*/
|
2014-04-01 05:04:02 +08:00
|
|
|
#define VSX_CVT_FP_TO_INT(op, nels, stp, ttp, sfld, tfld, rnan) \
|
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 06:21:34 +08:00
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t xt, xb; \
|
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
getVSR(xB(opcode), &xb, env); \
|
|
|
|
getVSR(xT(opcode), &xt, env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
|
|
|
if (unlikely(stp##_is_any_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 17:57:28 +08:00
|
|
|
if (stp##_is_signaling_nan(xb.sfld, &env->fp_status)) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 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 06:21:34 +08:00
|
|
|
} \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXCVI, 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 06:21:34 +08:00
|
|
|
xt.tfld = rnan; \
|
|
|
|
} else { \
|
2014-04-01 05:03:56 +08:00
|
|
|
xt.tfld = stp##_to_##ttp##_round_to_zero(xb.sfld, \
|
|
|
|
&env->fp_status); \
|
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 06:21:34 +08:00
|
|
|
if (env->fp_status.float_exception_flags & float_flag_invalid) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXCVI, 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 06:21:34 +08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
putVSR(xT(opcode), &xt, env); \
|
2016-07-27 14:56:27 +08:00
|
|
|
float_check_status(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 06:21:34 +08:00
|
|
|
}
|
|
|
|
|
2014-04-01 05:04:02 +08:00
|
|
|
VSX_CVT_FP_TO_INT(xscvdpsxds, 1, float64, int64, VsrD(0), VsrD(0), \
|
2014-02-24 22:12:13 +08:00
|
|
|
0x8000000000000000ULL)
|
2014-04-01 05:04:02 +08:00
|
|
|
VSX_CVT_FP_TO_INT(xscvdpsxws, 1, float64, int32, VsrD(0), VsrW(1), \
|
|
|
|
0x80000000U)
|
|
|
|
VSX_CVT_FP_TO_INT(xscvdpuxds, 1, float64, uint64, VsrD(0), VsrD(0), 0ULL)
|
|
|
|
VSX_CVT_FP_TO_INT(xscvdpuxws, 1, float64, uint32, VsrD(0), VsrW(1), 0U)
|
|
|
|
VSX_CVT_FP_TO_INT(xvcvdpsxds, 2, float64, int64, VsrD(i), VsrD(i), \
|
2014-02-24 22:12:13 +08:00
|
|
|
0x8000000000000000ULL)
|
2014-04-01 05:04:02 +08:00
|
|
|
VSX_CVT_FP_TO_INT(xvcvdpsxws, 2, float64, int32, VsrD(i), VsrW(2*i), \
|
2014-02-24 22:12:13 +08:00
|
|
|
0x80000000U)
|
2014-04-01 05:04:02 +08:00
|
|
|
VSX_CVT_FP_TO_INT(xvcvdpuxds, 2, float64, uint64, VsrD(i), VsrD(i), 0ULL)
|
|
|
|
VSX_CVT_FP_TO_INT(xvcvdpuxws, 2, float64, uint32, VsrD(i), VsrW(2*i), 0U)
|
|
|
|
VSX_CVT_FP_TO_INT(xvcvspsxds, 2, float32, int64, VsrW(2*i), VsrD(i), \
|
|
|
|
0x8000000000000000ULL)
|
|
|
|
VSX_CVT_FP_TO_INT(xvcvspsxws, 4, float32, int32, VsrW(i), VsrW(i), 0x80000000U)
|
|
|
|
VSX_CVT_FP_TO_INT(xvcvspuxds, 2, float32, uint64, VsrW(2*i), VsrD(i), 0ULL)
|
|
|
|
VSX_CVT_FP_TO_INT(xvcvspuxws, 4, float32, uint32, VsrW(i), VsrW(i), 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 06:21:34 +08:00
|
|
|
|
|
|
|
/* VSX_CVT_INT_TO_FP - VSX integer to floating point conversion
|
|
|
|
* 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)
|
|
|
|
* sfprf - set FPRF
|
|
|
|
*/
|
2014-04-01 05:04:03 +08:00
|
|
|
#define VSX_CVT_INT_TO_FP(op, nels, stp, ttp, sfld, tfld, sfprf, r2sp) \
|
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 06:21:34 +08:00
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t xt, xb; \
|
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
getVSR(xB(opcode), &xb, env); \
|
|
|
|
getVSR(xT(opcode), &xt, env); \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
|
|
|
xt.tfld = stp##_to_##ttp(xb.sfld, &env->fp_status); \
|
2014-01-15 22:10:40 +08:00
|
|
|
if (r2sp) { \
|
|
|
|
xt.tfld = helper_frsp(env, xt.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 06:21:34 +08:00
|
|
|
if (sfprf) { \
|
2014-11-13 05:46:04 +08:00
|
|
|
helper_compute_fprf(env, xt.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 06:21:34 +08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
putVSR(xT(opcode), &xt, env); \
|
2016-07-27 14:56:27 +08:00
|
|
|
float_check_status(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 06:21:34 +08:00
|
|
|
}
|
|
|
|
|
2014-04-01 05:04:03 +08: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)
|
|
|
|
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)
|
|
|
|
VSX_CVT_INT_TO_FP(xvcvsxdsp, 2, int64, float32, VsrD(i), VsrW(2*i), 0, 0)
|
|
|
|
VSX_CVT_INT_TO_FP(xvcvuxdsp, 2, uint64, float32, VsrD(i), VsrW(2*i), 0, 0)
|
|
|
|
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 06:21:35 +08:00
|
|
|
|
|
|
|
/* For "use current rounding mode", define a value that will not be one of
|
|
|
|
* the existing rounding model enums.
|
|
|
|
*/
|
|
|
|
#define FLOAT_ROUND_CURRENT (float_round_nearest_even + float_round_down + \
|
|
|
|
float_round_up + float_round_to_zero)
|
|
|
|
|
|
|
|
/* VSX_ROUND - VSX floating point round
|
|
|
|
* op - instruction mnemonic
|
|
|
|
* nels - number of elements (1, 2 or 4)
|
|
|
|
* tp - type (float32 or float64)
|
2014-04-01 05:03:59 +08: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 06:21:35 +08:00
|
|
|
* rmode - rounding mode
|
|
|
|
* sfprf - set FPRF
|
|
|
|
*/
|
|
|
|
#define VSX_ROUND(op, nels, tp, fld, rmode, sfprf) \
|
|
|
|
void helper_##op(CPUPPCState *env, uint32_t opcode) \
|
|
|
|
{ \
|
|
|
|
ppc_vsr_t xt, xb; \
|
|
|
|
int i; \
|
|
|
|
getVSR(xB(opcode), &xb, env); \
|
|
|
|
getVSR(xT(opcode), &xt, env); \
|
|
|
|
\
|
|
|
|
if (rmode != FLOAT_ROUND_CURRENT) { \
|
|
|
|
set_float_rounding_mode(rmode, &env->fp_status); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
for (i = 0; i < nels; i++) { \
|
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 17:57:28 +08:00
|
|
|
if (unlikely(tp##_is_signaling_nan(xb.fld, \
|
|
|
|
&env->fp_status))) { \
|
2016-07-27 14:56:25 +08:00
|
|
|
float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 0); \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt.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 06:21:35 +08:00
|
|
|
} else { \
|
2014-04-01 05:03:59 +08:00
|
|
|
xt.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 06:21:35 +08:00
|
|
|
} \
|
|
|
|
if (sfprf) { \
|
2014-11-13 05:46:04 +08:00
|
|
|
helper_compute_fprf(env, xt.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 06:21:35 +08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
/* If this is not a "use current rounding mode" instruction, \
|
|
|
|
* then inhibit setting of the XX bit and restore rounding \
|
|
|
|
* mode from FPSCR */ \
|
|
|
|
if (rmode != FLOAT_ROUND_CURRENT) { \
|
|
|
|
fpscr_set_rounding_mode(env); \
|
|
|
|
env->fp_status.float_exception_flags &= ~float_flag_inexact; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
putVSR(xT(opcode), &xt, env); \
|
2016-07-27 14:56:27 +08:00
|
|
|
float_check_status(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 06:21:35 +08:00
|
|
|
}
|
|
|
|
|
2016-07-04 07:20:12 +08:00
|
|
|
VSX_ROUND(xsrdpi, 1, float64, VsrD(0), float_round_ties_away, 1)
|
2014-04-01 05:03:59 +08: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 06:21:35 +08:00
|
|
|
|
2016-07-04 07:20:12 +08:00
|
|
|
VSX_ROUND(xvrdpi, 2, float64, VsrD(i), float_round_ties_away, 0)
|
2014-04-01 05:03:59 +08: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 06:21:35 +08:00
|
|
|
|
2016-07-04 07:20:12 +08:00
|
|
|
VSX_ROUND(xvrspi, 4, float32, VsrW(i), float_round_ties_away, 0)
|
2014-04-01 05:03:59 +08: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 22:10:44 +08:00
|
|
|
|
|
|
|
uint64_t helper_xsrsp(CPUPPCState *env, uint64_t xb)
|
|
|
|
{
|
|
|
|
helper_reset_fpstatus(env);
|
|
|
|
|
|
|
|
uint64_t xt = helper_frsp(env, xb);
|
|
|
|
|
2014-11-13 05:46:04 +08:00
|
|
|
helper_compute_fprf(env, xt);
|
2016-07-27 14:56:27 +08:00
|
|
|
float_check_status(env);
|
2014-01-15 22:10:44 +08:00
|
|
|
return xt;
|
|
|
|
}
|