2011-08-01 07:37:45 +00:00
|
|
|
/*
|
|
|
|
* FPU op helpers
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2005 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2020-10-23 12:42:35 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2011-08-01 07:37:45 +00:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 18:16:59 +00:00
|
|
|
#include "qemu/osdep.h"
|
2011-08-01 07:37:45 +00:00
|
|
|
#include "cpu.h"
|
2015-09-09 18:34:28 +00:00
|
|
|
#include "exec/exec-all.h"
|
2014-04-08 05:31:41 +00:00
|
|
|
#include "exec/helper-proto.h"
|
2018-01-19 18:24:22 +00:00
|
|
|
#include "fpu/softfloat.h"
|
2011-08-01 07:37:45 +00:00
|
|
|
|
2023-11-03 17:38:25 +00:00
|
|
|
static inline float128 f128_in(Int128 i)
|
|
|
|
{
|
|
|
|
union {
|
|
|
|
Int128 i;
|
|
|
|
float128 f;
|
|
|
|
} u;
|
|
|
|
|
|
|
|
u.i = i;
|
|
|
|
return u.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline Int128 f128_ret(float128 f)
|
|
|
|
{
|
|
|
|
union {
|
|
|
|
Int128 i;
|
|
|
|
float128 f;
|
|
|
|
} u;
|
|
|
|
|
|
|
|
u.f = f;
|
|
|
|
return u.i;
|
|
|
|
}
|
|
|
|
|
2023-11-03 17:38:37 +00:00
|
|
|
static void check_ieee_exceptions(CPUSPARCState *env, uintptr_t ra)
|
2011-10-17 18:25:56 +00:00
|
|
|
{
|
2015-09-09 18:11:36 +00:00
|
|
|
target_ulong status = get_float_exception_flags(&env->fp_status);
|
2023-11-03 17:38:38 +00:00
|
|
|
uint32_t cexc = 0;
|
2023-11-03 17:38:36 +00:00
|
|
|
|
2015-09-09 18:11:36 +00:00
|
|
|
if (unlikely(status)) {
|
|
|
|
/* Keep exception flags clear for next time. */
|
|
|
|
set_float_exception_flags(0, &env->fp_status);
|
2011-10-17 18:25:56 +00:00
|
|
|
|
|
|
|
/* Copy IEEE 754 flags into FSR */
|
|
|
|
if (status & float_flag_invalid) {
|
2023-11-03 17:38:38 +00:00
|
|
|
cexc |= FSR_NVC;
|
2011-10-17 18:25:56 +00:00
|
|
|
}
|
|
|
|
if (status & float_flag_overflow) {
|
2023-11-03 17:38:38 +00:00
|
|
|
cexc |= FSR_OFC;
|
2011-10-17 18:25:56 +00:00
|
|
|
}
|
|
|
|
if (status & float_flag_underflow) {
|
2023-11-03 17:38:38 +00:00
|
|
|
cexc |= FSR_UFC;
|
2011-10-17 18:25:56 +00:00
|
|
|
}
|
|
|
|
if (status & float_flag_divbyzero) {
|
2023-11-03 17:38:38 +00:00
|
|
|
cexc |= FSR_DZC;
|
2011-10-17 18:25:56 +00:00
|
|
|
}
|
|
|
|
if (status & float_flag_inexact) {
|
2023-11-03 17:38:38 +00:00
|
|
|
cexc |= FSR_NXC;
|
2011-10-17 18:25:56 +00:00
|
|
|
}
|
|
|
|
|
2023-11-03 17:38:38 +00:00
|
|
|
if (cexc & (env->fsr >> FSR_TEM_SHIFT)) {
|
|
|
|
/* Unmasked exception, generate an IEEE trap. */
|
|
|
|
env->fsr_cexc_ftt = cexc | FSR_FTT_IEEE_EXCP;
|
|
|
|
cpu_raise_exception_ra(env, TT_FP_EXCP, ra);
|
2011-10-17 18:25:56 +00:00
|
|
|
}
|
2023-11-03 17:38:38 +00:00
|
|
|
|
|
|
|
/* Accumulate exceptions */
|
|
|
|
env->fsr |= cexc << FSR_AEXC_SHIFT;
|
2011-10-17 18:25:56 +00:00
|
|
|
}
|
|
|
|
|
2023-11-03 17:38:38 +00:00
|
|
|
/* No trap, so FTT is cleared. */
|
|
|
|
env->fsr_cexc_ftt = cexc;
|
2011-10-17 18:25:56 +00:00
|
|
|
}
|
|
|
|
|
2023-11-03 17:38:37 +00:00
|
|
|
float32 helper_fadds(CPUSPARCState *env, float32 src1, float32 src2)
|
2015-09-09 18:34:28 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
float32 ret = float32_add(src1, src2, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
2015-09-09 18:34:28 +00:00
|
|
|
}
|
|
|
|
|
2023-11-03 17:38:37 +00:00
|
|
|
float32 helper_fsubs(CPUSPARCState *env, float32 src1, float32 src2)
|
|
|
|
{
|
|
|
|
float32 ret = float32_sub(src1, src2, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
float32 helper_fmuls(CPUSPARCState *env, float32 src1, float32 src2)
|
|
|
|
{
|
|
|
|
float32 ret = float32_mul(src1, src2, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
float32 helper_fdivs(CPUSPARCState *env, float32 src1, float32 src2)
|
|
|
|
{
|
|
|
|
float32 ret = float32_div(src1, src2, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 helper_faddd(CPUSPARCState *env, float64 src1, float64 src2)
|
|
|
|
{
|
|
|
|
float64 ret = float64_add(src1, src2, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 helper_fsubd(CPUSPARCState *env, float64 src1, float64 src2)
|
|
|
|
{
|
|
|
|
float64 ret = float64_sub(src1, src2, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 helper_fmuld(CPUSPARCState *env, float64 src1, float64 src2)
|
|
|
|
{
|
|
|
|
float64 ret = float64_mul(src1, src2, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 helper_fdivd(CPUSPARCState *env, float64 src1, float64 src2)
|
|
|
|
{
|
|
|
|
float64 ret = float64_div(src1, src2, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
Int128 helper_faddq(CPUSPARCState *env, Int128 src1, Int128 src2)
|
|
|
|
{
|
|
|
|
float128 ret = float128_add(f128_in(src1), f128_in(src2), &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return f128_ret(ret);
|
|
|
|
}
|
2011-08-01 07:37:45 +00:00
|
|
|
|
2023-11-03 17:38:37 +00:00
|
|
|
Int128 helper_fsubq(CPUSPARCState *env, Int128 src1, Int128 src2)
|
|
|
|
{
|
|
|
|
float128 ret = float128_sub(f128_in(src1), f128_in(src2), &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return f128_ret(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
Int128 helper_fmulq(CPUSPARCState *env, Int128 src1, Int128 src2)
|
|
|
|
{
|
|
|
|
float128 ret = float128_mul(f128_in(src1), f128_in(src2), &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return f128_ret(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
Int128 helper_fdivq(CPUSPARCState *env, Int128 src1, Int128 src2)
|
|
|
|
{
|
|
|
|
float128 ret = float128_div(f128_in(src1), f128_in(src2), &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return f128_ret(ret);
|
|
|
|
}
|
2011-08-01 07:37:45 +00:00
|
|
|
|
2012-03-14 00:38:22 +00:00
|
|
|
float64 helper_fsmuld(CPUSPARCState *env, float32 src1, float32 src2)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
float64 ret = float64_mul(float32_to_float64(src1, &env->fp_status),
|
|
|
|
float32_to_float64(src2, &env->fp_status),
|
|
|
|
&env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
2023-11-03 17:38:32 +00:00
|
|
|
Int128 helper_fdmulq(CPUSPARCState *env, float64 src1, float64 src2)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
float128 ret = float128_mul(float64_to_float128(src1, &env->fp_status),
|
|
|
|
float64_to_float128(src2, &env->fp_status),
|
|
|
|
&env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return f128_ret(ret);
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Integer to float conversion. */
|
2012-03-14 00:38:22 +00:00
|
|
|
float32 helper_fitos(CPUSPARCState *env, int32_t src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
float32 ret = int32_to_float32(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
2012-03-14 00:38:22 +00:00
|
|
|
float64 helper_fitod(CPUSPARCState *env, int32_t src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
float64 ret = int32_to_float64(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
2023-11-03 17:38:30 +00:00
|
|
|
Int128 helper_fitoq(CPUSPARCState *env, int32_t src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
float128 ret = int32_to_float128(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return f128_ret(ret);
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TARGET_SPARC64
|
2012-03-14 00:38:22 +00:00
|
|
|
float32 helper_fxtos(CPUSPARCState *env, int64_t src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
float32 ret = int64_to_float32(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
2012-03-14 00:38:22 +00:00
|
|
|
float64 helper_fxtod(CPUSPARCState *env, int64_t src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
float64 ret = int64_to_float64(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
2023-11-03 17:38:31 +00:00
|
|
|
Int128 helper_fxtoq(CPUSPARCState *env, int64_t src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
float128 ret = int64_to_float128(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return f128_ret(ret);
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* floating point conversion */
|
2012-03-14 00:38:22 +00:00
|
|
|
float32 helper_fdtos(CPUSPARCState *env, float64 src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
float32 ret = float64_to_float32(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
2012-03-14 00:38:22 +00:00
|
|
|
float64 helper_fstod(CPUSPARCState *env, float32 src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
float64 ret = float32_to_float64(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
2023-11-03 17:38:27 +00:00
|
|
|
float32 helper_fqtos(CPUSPARCState *env, Int128 src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
float32 ret = float128_to_float32(f128_in(src), &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
2023-11-03 17:38:30 +00:00
|
|
|
Int128 helper_fstoq(CPUSPARCState *env, float32 src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
float128 ret = float32_to_float128(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return f128_ret(ret);
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
2023-11-03 17:38:28 +00:00
|
|
|
float64 helper_fqtod(CPUSPARCState *env, Int128 src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
float64 ret = float128_to_float64(f128_in(src), &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
2023-11-03 17:38:31 +00:00
|
|
|
Int128 helper_fdtoq(CPUSPARCState *env, float64 src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
float128 ret = float64_to_float128(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return f128_ret(ret);
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Float to integer conversion. */
|
2012-03-14 00:38:22 +00:00
|
|
|
int32_t helper_fstoi(CPUSPARCState *env, float32 src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
int32_t ret = float32_to_int32_round_to_zero(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
2012-03-14 00:38:22 +00:00
|
|
|
int32_t helper_fdtoi(CPUSPARCState *env, float64 src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
int32_t ret = float64_to_int32_round_to_zero(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
2023-11-03 17:38:27 +00:00
|
|
|
int32_t helper_fqtoi(CPUSPARCState *env, Int128 src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
int32_t ret = float128_to_int32_round_to_zero(f128_in(src),
|
|
|
|
&env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TARGET_SPARC64
|
2012-03-14 00:38:22 +00:00
|
|
|
int64_t helper_fstox(CPUSPARCState *env, float32 src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
int64_t ret = float32_to_int64_round_to_zero(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
2012-03-14 00:38:22 +00:00
|
|
|
int64_t helper_fdtox(CPUSPARCState *env, float64 src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
int64_t ret = float64_to_int64_round_to_zero(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
2023-11-03 17:38:28 +00:00
|
|
|
int64_t helper_fqtox(CPUSPARCState *env, Int128 src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
int64_t ret = float128_to_int64_round_to_zero(f128_in(src),
|
|
|
|
&env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-03-14 00:38:22 +00:00
|
|
|
float32 helper_fsqrts(CPUSPARCState *env, float32 src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
float32 ret = float32_sqrt(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
2012-03-14 00:38:22 +00:00
|
|
|
float64 helper_fsqrtd(CPUSPARCState *env, float64 src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
float64 ret = float64_sqrt(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return ret;
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
2023-11-03 17:38:25 +00:00
|
|
|
Int128 helper_fsqrtq(CPUSPARCState *env, Int128 src)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:37 +00:00
|
|
|
float128 ret = float128_sqrt(f128_in(src), &env->fp_status);
|
|
|
|
check_ieee_exceptions(env, GETPC());
|
|
|
|
return f128_ret(ret);
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
2023-11-03 17:38:29 +00:00
|
|
|
#define GEN_FCMP(name, size, FS, E) \
|
2023-11-03 17:38:39 +00:00
|
|
|
void glue(helper_, name)(CPUSPARCState *env, Int128 src1, Int128 src2) \
|
2011-08-01 07:37:45 +00:00
|
|
|
{ \
|
2023-11-03 17:38:29 +00:00
|
|
|
float128 reg1 = f128_in(src1); \
|
|
|
|
float128 reg2 = f128_in(src2); \
|
2020-05-05 17:22:05 +00:00
|
|
|
FloatRelation ret; \
|
2015-09-09 18:11:36 +00:00
|
|
|
target_ulong fsr; \
|
target-sparc: fix fcmp{s,d,q} instructions wrt exception
fcmp{s,d,q} instructions are supposed to ignore quiet NaN (contrary to
the fcmpe{s,d,q} instructions), but the current code is wrongly setting
the NV exception in that case. Moreover the current code is duplicated:
first the arguments are checked for NaN to generate an exception, and
later in case the comparison is unordered (which can only happens if one
of the argument is a NaN), the same check is done to generate an
exception.
Fix that by calling clear_float_exceptions() followed by
check_ieee_exceptions() as for the other floating point instructions.
Use the _compare_quiet functions for fcmp{s,d,q} and the _compare ones
for fcmpe{s,d,q}. Simplify the flag setting by not clearing a flag that
is set the line just below.
This fix allows the math glibc testsuite to pass.
Cc: Blue Swirl <blauwirbel@gmail.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2012-09-07 15:13:28 +00:00
|
|
|
if (E) { \
|
|
|
|
ret = glue(size, _compare)(reg1, reg2, &env->fp_status); \
|
|
|
|
} else { \
|
|
|
|
ret = glue(size, _compare_quiet)(reg1, reg2, \
|
|
|
|
&env->fp_status); \
|
2011-08-01 07:37:45 +00:00
|
|
|
} \
|
2023-11-03 17:38:37 +00:00
|
|
|
check_ieee_exceptions(env, GETPC()); \
|
|
|
|
fsr = env->fsr; \
|
target-sparc: fix fcmp{s,d,q} instructions wrt exception
fcmp{s,d,q} instructions are supposed to ignore quiet NaN (contrary to
the fcmpe{s,d,q} instructions), but the current code is wrongly setting
the NV exception in that case. Moreover the current code is duplicated:
first the arguments are checked for NaN to generate an exception, and
later in case the comparison is unordered (which can only happens if one
of the argument is a NaN), the same check is done to generate an
exception.
Fix that by calling clear_float_exceptions() followed by
check_ieee_exceptions() as for the other floating point instructions.
Use the _compare_quiet functions for fcmp{s,d,q} and the _compare ones
for fcmpe{s,d,q}. Simplify the flag setting by not clearing a flag that
is set the line just below.
This fix allows the math glibc testsuite to pass.
Cc: Blue Swirl <blauwirbel@gmail.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2012-09-07 15:13:28 +00:00
|
|
|
switch (ret) { \
|
2011-08-01 07:37:45 +00:00
|
|
|
case float_relation_unordered: \
|
2015-09-09 18:11:36 +00:00
|
|
|
fsr |= (FSR_FCC1 | FSR_FCC0) << FS; \
|
|
|
|
fsr |= FSR_NVA; \
|
2011-08-01 07:37:45 +00:00
|
|
|
break; \
|
|
|
|
case float_relation_less: \
|
2015-09-09 18:11:36 +00:00
|
|
|
fsr &= ~(FSR_FCC1) << FS; \
|
|
|
|
fsr |= FSR_FCC0 << FS; \
|
2011-08-01 07:37:45 +00:00
|
|
|
break; \
|
|
|
|
case float_relation_greater: \
|
2015-09-09 18:11:36 +00:00
|
|
|
fsr &= ~(FSR_FCC0) << FS; \
|
|
|
|
fsr |= FSR_FCC1 << FS; \
|
2011-08-01 07:37:45 +00:00
|
|
|
break; \
|
|
|
|
default: \
|
2015-09-09 18:11:36 +00:00
|
|
|
fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
|
2011-08-01 07:37:45 +00:00
|
|
|
break; \
|
|
|
|
} \
|
2023-11-03 17:38:39 +00:00
|
|
|
env->fsr = fsr; \
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
2011-10-15 17:20:20 +00:00
|
|
|
#define GEN_FCMP_T(name, size, FS, E) \
|
2023-11-03 17:38:39 +00:00
|
|
|
void glue(helper_, name)(CPUSPARCState *env, size src1, size src2) \
|
2011-08-01 07:37:45 +00:00
|
|
|
{ \
|
2020-05-05 17:22:05 +00:00
|
|
|
FloatRelation ret; \
|
2015-09-09 18:11:36 +00:00
|
|
|
target_ulong fsr; \
|
target-sparc: fix fcmp{s,d,q} instructions wrt exception
fcmp{s,d,q} instructions are supposed to ignore quiet NaN (contrary to
the fcmpe{s,d,q} instructions), but the current code is wrongly setting
the NV exception in that case. Moreover the current code is duplicated:
first the arguments are checked for NaN to generate an exception, and
later in case the comparison is unordered (which can only happens if one
of the argument is a NaN), the same check is done to generate an
exception.
Fix that by calling clear_float_exceptions() followed by
check_ieee_exceptions() as for the other floating point instructions.
Use the _compare_quiet functions for fcmp{s,d,q} and the _compare ones
for fcmpe{s,d,q}. Simplify the flag setting by not clearing a flag that
is set the line just below.
This fix allows the math glibc testsuite to pass.
Cc: Blue Swirl <blauwirbel@gmail.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2012-09-07 15:13:28 +00:00
|
|
|
if (E) { \
|
|
|
|
ret = glue(size, _compare)(src1, src2, &env->fp_status); \
|
|
|
|
} else { \
|
|
|
|
ret = glue(size, _compare_quiet)(src1, src2, \
|
|
|
|
&env->fp_status); \
|
2011-08-01 07:37:45 +00:00
|
|
|
} \
|
2023-11-03 17:38:37 +00:00
|
|
|
check_ieee_exceptions(env, GETPC()); \
|
|
|
|
fsr = env->fsr; \
|
target-sparc: fix fcmp{s,d,q} instructions wrt exception
fcmp{s,d,q} instructions are supposed to ignore quiet NaN (contrary to
the fcmpe{s,d,q} instructions), but the current code is wrongly setting
the NV exception in that case. Moreover the current code is duplicated:
first the arguments are checked for NaN to generate an exception, and
later in case the comparison is unordered (which can only happens if one
of the argument is a NaN), the same check is done to generate an
exception.
Fix that by calling clear_float_exceptions() followed by
check_ieee_exceptions() as for the other floating point instructions.
Use the _compare_quiet functions for fcmp{s,d,q} and the _compare ones
for fcmpe{s,d,q}. Simplify the flag setting by not clearing a flag that
is set the line just below.
This fix allows the math glibc testsuite to pass.
Cc: Blue Swirl <blauwirbel@gmail.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2012-09-07 15:13:28 +00:00
|
|
|
switch (ret) { \
|
2011-08-01 07:37:45 +00:00
|
|
|
case float_relation_unordered: \
|
2015-09-09 18:11:36 +00:00
|
|
|
fsr |= (FSR_FCC1 | FSR_FCC0) << FS; \
|
2011-08-01 07:37:45 +00:00
|
|
|
break; \
|
|
|
|
case float_relation_less: \
|
2015-09-09 18:11:36 +00:00
|
|
|
fsr &= ~(FSR_FCC1 << FS); \
|
|
|
|
fsr |= FSR_FCC0 << FS; \
|
2011-08-01 07:37:45 +00:00
|
|
|
break; \
|
|
|
|
case float_relation_greater: \
|
2015-09-09 18:11:36 +00:00
|
|
|
fsr &= ~(FSR_FCC0 << FS); \
|
|
|
|
fsr |= FSR_FCC1 << FS; \
|
2011-08-01 07:37:45 +00:00
|
|
|
break; \
|
|
|
|
default: \
|
2015-09-09 18:11:36 +00:00
|
|
|
fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
|
2011-08-01 07:37:45 +00:00
|
|
|
break; \
|
|
|
|
} \
|
2023-11-03 17:38:39 +00:00
|
|
|
env->fsr = fsr; \
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|
|
|
|
|
2011-10-15 17:20:20 +00:00
|
|
|
GEN_FCMP_T(fcmps, float32, 0, 0);
|
|
|
|
GEN_FCMP_T(fcmpd, float64, 0, 0);
|
2011-08-01 07:37:45 +00:00
|
|
|
|
2011-10-15 17:20:20 +00:00
|
|
|
GEN_FCMP_T(fcmpes, float32, 0, 1);
|
|
|
|
GEN_FCMP_T(fcmped, float64, 0, 1);
|
2011-08-01 07:37:45 +00:00
|
|
|
|
2023-11-03 17:38:29 +00:00
|
|
|
GEN_FCMP(fcmpq, float128, 0, 0);
|
|
|
|
GEN_FCMP(fcmpeq, float128, 0, 1);
|
2011-08-01 07:37:45 +00:00
|
|
|
|
|
|
|
#ifdef TARGET_SPARC64
|
2011-10-15 17:20:20 +00:00
|
|
|
GEN_FCMP_T(fcmps_fcc1, float32, 22, 0);
|
|
|
|
GEN_FCMP_T(fcmpd_fcc1, float64, 22, 0);
|
2023-11-03 17:38:29 +00:00
|
|
|
GEN_FCMP(fcmpq_fcc1, float128, 22, 0);
|
2011-08-01 07:37:45 +00:00
|
|
|
|
2011-10-15 17:20:20 +00:00
|
|
|
GEN_FCMP_T(fcmps_fcc2, float32, 24, 0);
|
|
|
|
GEN_FCMP_T(fcmpd_fcc2, float64, 24, 0);
|
2023-11-03 17:38:29 +00:00
|
|
|
GEN_FCMP(fcmpq_fcc2, float128, 24, 0);
|
2011-08-01 07:37:45 +00:00
|
|
|
|
2011-10-15 17:20:20 +00:00
|
|
|
GEN_FCMP_T(fcmps_fcc3, float32, 26, 0);
|
|
|
|
GEN_FCMP_T(fcmpd_fcc3, float64, 26, 0);
|
2023-11-03 17:38:29 +00:00
|
|
|
GEN_FCMP(fcmpq_fcc3, float128, 26, 0);
|
2011-08-01 07:37:45 +00:00
|
|
|
|
2011-10-15 17:20:20 +00:00
|
|
|
GEN_FCMP_T(fcmpes_fcc1, float32, 22, 1);
|
|
|
|
GEN_FCMP_T(fcmped_fcc1, float64, 22, 1);
|
2023-11-03 17:38:29 +00:00
|
|
|
GEN_FCMP(fcmpeq_fcc1, float128, 22, 1);
|
2011-08-01 07:37:45 +00:00
|
|
|
|
2011-10-15 17:20:20 +00:00
|
|
|
GEN_FCMP_T(fcmpes_fcc2, float32, 24, 1);
|
|
|
|
GEN_FCMP_T(fcmped_fcc2, float64, 24, 1);
|
2023-11-03 17:38:29 +00:00
|
|
|
GEN_FCMP(fcmpeq_fcc2, float128, 24, 1);
|
2011-08-01 07:37:45 +00:00
|
|
|
|
2011-10-15 17:20:20 +00:00
|
|
|
GEN_FCMP_T(fcmpes_fcc3, float32, 26, 1);
|
|
|
|
GEN_FCMP_T(fcmped_fcc3, float64, 26, 1);
|
2023-11-03 17:38:29 +00:00
|
|
|
GEN_FCMP(fcmpeq_fcc3, float128, 26, 1);
|
2011-08-01 07:37:45 +00:00
|
|
|
#endif
|
2011-10-15 17:20:20 +00:00
|
|
|
#undef GEN_FCMP_T
|
|
|
|
#undef GEN_FCMP
|
2011-08-01 07:37:45 +00:00
|
|
|
|
2023-11-03 17:38:34 +00:00
|
|
|
target_ulong cpu_get_fsr(CPUSPARCState *env)
|
|
|
|
{
|
2023-11-03 17:38:38 +00:00
|
|
|
target_ulong fsr = env->fsr | env->fsr_cexc_ftt;
|
2023-11-03 17:38:35 +00:00
|
|
|
|
|
|
|
/* VER is kept completely separate until re-assembly. */
|
|
|
|
fsr |= env->def.fpu_version;
|
|
|
|
|
|
|
|
return fsr;
|
2023-11-03 17:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
target_ulong helper_get_fsr(CPUSPARCState *env)
|
|
|
|
{
|
|
|
|
return cpu_get_fsr(env);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_fsr_nonsplit(CPUSPARCState *env, target_ulong fsr)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
|
|
|
int rnd_mode;
|
|
|
|
|
2023-11-03 17:38:38 +00:00
|
|
|
env->fsr = fsr & ~(FSR_VER_MASK | FSR_CEXC_MASK | FSR_FTT_MASK);
|
2023-11-03 17:38:34 +00:00
|
|
|
|
2015-09-09 18:11:36 +00:00
|
|
|
switch (fsr & FSR_RD_MASK) {
|
2011-08-01 07:37:45 +00:00
|
|
|
case FSR_RD_NEAREST:
|
|
|
|
rnd_mode = float_round_nearest_even;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case FSR_RD_ZERO:
|
|
|
|
rnd_mode = float_round_to_zero;
|
|
|
|
break;
|
|
|
|
case FSR_RD_POS:
|
|
|
|
rnd_mode = float_round_up;
|
|
|
|
break;
|
|
|
|
case FSR_RD_NEG:
|
|
|
|
rnd_mode = float_round_down;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
set_float_rounding_mode(rnd_mode, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
2023-11-03 17:38:34 +00:00
|
|
|
void cpu_put_fsr(CPUSPARCState *env, target_ulong fsr)
|
|
|
|
{
|
2023-11-03 17:38:38 +00:00
|
|
|
env->fsr_cexc_ftt = fsr & (FSR_CEXC_MASK | FSR_FTT_MASK);
|
2023-11-03 17:38:34 +00:00
|
|
|
set_fsr_nonsplit(env, fsr);
|
|
|
|
}
|
|
|
|
|
2023-11-03 17:38:38 +00:00
|
|
|
void helper_set_fsr_noftt(CPUSPARCState *env, target_ulong fsr)
|
2011-08-01 07:37:45 +00:00
|
|
|
{
|
2023-11-03 17:38:38 +00:00
|
|
|
env->fsr_cexc_ftt &= FSR_FTT_MASK;
|
|
|
|
env->fsr_cexc_ftt |= fsr & FSR_CEXC_MASK;
|
2023-11-03 17:38:34 +00:00
|
|
|
set_fsr_nonsplit(env, fsr);
|
2011-08-01 07:37:45 +00:00
|
|
|
}
|