2011-08-01 09:37:45 +02: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
|
|
|
|
* 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-26 19:16:59 +01:00
|
|
|
#include "qemu/osdep.h"
|
2011-08-01 09:37:45 +02:00
|
|
|
#include "cpu.h"
|
2014-04-08 07:31:41 +02:00
|
|
|
#include "exec/helper-proto.h"
|
2011-08-01 09:37:45 +02:00
|
|
|
|
|
|
|
#define QT0 (env->qt0)
|
|
|
|
#define QT1 (env->qt1)
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
static void check_ieee_exceptions(CPUSPARCState *env)
|
2011-10-17 20:25:56 +02:00
|
|
|
{
|
|
|
|
target_ulong status;
|
|
|
|
|
|
|
|
status = get_float_exception_flags(&env->fp_status);
|
|
|
|
if (status) {
|
|
|
|
/* Copy IEEE 754 flags into FSR */
|
|
|
|
if (status & float_flag_invalid) {
|
|
|
|
env->fsr |= FSR_NVC;
|
|
|
|
}
|
|
|
|
if (status & float_flag_overflow) {
|
|
|
|
env->fsr |= FSR_OFC;
|
|
|
|
}
|
|
|
|
if (status & float_flag_underflow) {
|
|
|
|
env->fsr |= FSR_UFC;
|
|
|
|
}
|
|
|
|
if (status & float_flag_divbyzero) {
|
|
|
|
env->fsr |= FSR_DZC;
|
|
|
|
}
|
|
|
|
if (status & float_flag_inexact) {
|
|
|
|
env->fsr |= FSR_NXC;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((env->fsr & FSR_CEXC_MASK) & ((env->fsr & FSR_TEM_MASK) >> 23)) {
|
|
|
|
/* Unmasked exception, generate a trap */
|
|
|
|
env->fsr |= FSR_FTT_IEEE_EXCP;
|
|
|
|
helper_raise_exception(env, TT_FP_EXCP);
|
|
|
|
} else {
|
|
|
|
/* Accumulate exceptions */
|
|
|
|
env->fsr |= (env->fsr & FSR_CEXC_MASK) << 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
static inline void clear_float_exceptions(CPUSPARCState *env)
|
2011-10-17 20:25:56 +02:00
|
|
|
{
|
|
|
|
set_float_exception_flags(0, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
#define F_HELPER(name, p) void helper_f##name##p(CPUSPARCState *env)
|
2011-08-01 09:37:45 +02:00
|
|
|
|
|
|
|
#define F_BINOP(name) \
|
2012-03-14 01:38:22 +01:00
|
|
|
float32 helper_f ## name ## s (CPUSPARCState *env, float32 src1, \
|
2011-07-03 12:42:23 +02:00
|
|
|
float32 src2) \
|
2011-08-01 09:37:45 +02:00
|
|
|
{ \
|
2011-10-17 20:25:56 +02:00
|
|
|
float32 ret; \
|
|
|
|
clear_float_exceptions(env); \
|
|
|
|
ret = float32_ ## name (src1, src2, &env->fp_status); \
|
|
|
|
check_ieee_exceptions(env); \
|
|
|
|
return ret; \
|
2011-08-01 09:37:45 +02:00
|
|
|
} \
|
2012-03-14 01:38:22 +01:00
|
|
|
float64 helper_f ## name ## d (CPUSPARCState * env, float64 src1,\
|
2011-10-15 19:20:20 +02:00
|
|
|
float64 src2) \
|
2011-08-01 09:37:45 +02:00
|
|
|
{ \
|
2011-10-17 20:25:56 +02:00
|
|
|
float64 ret; \
|
|
|
|
clear_float_exceptions(env); \
|
|
|
|
ret = float64_ ## name (src1, src2, &env->fp_status); \
|
|
|
|
check_ieee_exceptions(env); \
|
|
|
|
return ret; \
|
2011-08-01 09:37:45 +02:00
|
|
|
} \
|
|
|
|
F_HELPER(name, q) \
|
|
|
|
{ \
|
2011-10-17 20:25:56 +02:00
|
|
|
clear_float_exceptions(env); \
|
2011-08-01 09:37:45 +02:00
|
|
|
QT0 = float128_ ## name (QT0, QT1, &env->fp_status); \
|
2011-10-17 20:25:56 +02:00
|
|
|
check_ieee_exceptions(env); \
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
F_BINOP(add);
|
|
|
|
F_BINOP(sub);
|
|
|
|
F_BINOP(mul);
|
|
|
|
F_BINOP(div);
|
|
|
|
#undef F_BINOP
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
float64 helper_fsmuld(CPUSPARCState *env, float32 src1, float32 src2)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
float64 ret;
|
|
|
|
clear_float_exceptions(env);
|
|
|
|
ret = float64_mul(float32_to_float64(src1, &env->fp_status),
|
|
|
|
float32_to_float64(src2, &env->fp_status),
|
|
|
|
&env->fp_status);
|
|
|
|
check_ieee_exceptions(env);
|
|
|
|
return ret;
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
void helper_fdmulq(CPUSPARCState *env, float64 src1, float64 src2)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
clear_float_exceptions(env);
|
2011-10-15 19:20:20 +02:00
|
|
|
QT0 = float128_mul(float64_to_float128(src1, &env->fp_status),
|
|
|
|
float64_to_float128(src2, &env->fp_status),
|
2011-08-01 09:37:45 +02:00
|
|
|
&env->fp_status);
|
2011-10-17 20:25:56 +02:00
|
|
|
check_ieee_exceptions(env);
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
float32 helper_fnegs(float32 src)
|
|
|
|
{
|
|
|
|
return float32_chs(src);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TARGET_SPARC64
|
2011-10-15 19:20:20 +02:00
|
|
|
float64 helper_fnegd(float64 src)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-15 19:20:20 +02:00
|
|
|
return float64_chs(src);
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
F_HELPER(neg, q)
|
|
|
|
{
|
|
|
|
QT0 = float128_chs(QT1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Integer to float conversion. */
|
2012-03-14 01:38:22 +01:00
|
|
|
float32 helper_fitos(CPUSPARCState *env, int32_t src)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
/* Inexact error possible converting int to float. */
|
|
|
|
float32 ret;
|
|
|
|
clear_float_exceptions(env);
|
|
|
|
ret = int32_to_float32(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env);
|
|
|
|
return ret;
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
float64 helper_fitod(CPUSPARCState *env, int32_t src)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
/* No possible exceptions converting int to double. */
|
2011-10-15 19:20:20 +02:00
|
|
|
return int32_to_float64(src, &env->fp_status);
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
void helper_fitoq(CPUSPARCState *env, int32_t src)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
/* No possible exceptions converting int to long double. */
|
2011-08-01 09:37:45 +02:00
|
|
|
QT0 = int32_to_float128(src, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TARGET_SPARC64
|
2012-03-14 01:38:22 +01:00
|
|
|
float32 helper_fxtos(CPUSPARCState *env, int64_t src)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
float32 ret;
|
|
|
|
clear_float_exceptions(env);
|
|
|
|
ret = int64_to_float32(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env);
|
|
|
|
return ret;
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
float64 helper_fxtod(CPUSPARCState *env, int64_t src)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
float64 ret;
|
|
|
|
clear_float_exceptions(env);
|
|
|
|
ret = int64_to_float64(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env);
|
|
|
|
return ret;
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
void helper_fxtoq(CPUSPARCState *env, int64_t src)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
/* No possible exceptions converting long long to long double. */
|
2011-10-15 19:20:20 +02:00
|
|
|
QT0 = int64_to_float128(src, &env->fp_status);
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#undef F_HELPER
|
|
|
|
|
|
|
|
/* floating point conversion */
|
2012-03-14 01:38:22 +01:00
|
|
|
float32 helper_fdtos(CPUSPARCState *env, float64 src)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
float32 ret;
|
|
|
|
clear_float_exceptions(env);
|
|
|
|
ret = float64_to_float32(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env);
|
|
|
|
return ret;
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
float64 helper_fstod(CPUSPARCState *env, float32 src)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
float64 ret;
|
|
|
|
clear_float_exceptions(env);
|
|
|
|
ret = float32_to_float64(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env);
|
|
|
|
return ret;
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
float32 helper_fqtos(CPUSPARCState *env)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
float32 ret;
|
|
|
|
clear_float_exceptions(env);
|
|
|
|
ret = float128_to_float32(QT1, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env);
|
|
|
|
return ret;
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
void helper_fstoq(CPUSPARCState *env, float32 src)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
clear_float_exceptions(env);
|
2011-08-01 09:37:45 +02:00
|
|
|
QT0 = float32_to_float128(src, &env->fp_status);
|
2011-10-17 20:25:56 +02:00
|
|
|
check_ieee_exceptions(env);
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
float64 helper_fqtod(CPUSPARCState *env)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
float64 ret;
|
|
|
|
clear_float_exceptions(env);
|
|
|
|
ret = float128_to_float64(QT1, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env);
|
|
|
|
return ret;
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
void helper_fdtoq(CPUSPARCState *env, float64 src)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
clear_float_exceptions(env);
|
2011-10-15 19:20:20 +02:00
|
|
|
QT0 = float64_to_float128(src, &env->fp_status);
|
2011-10-17 20:25:56 +02:00
|
|
|
check_ieee_exceptions(env);
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Float to integer conversion. */
|
2012-03-14 01:38:22 +01:00
|
|
|
int32_t helper_fstoi(CPUSPARCState *env, float32 src)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
int32_t ret;
|
|
|
|
clear_float_exceptions(env);
|
|
|
|
ret = float32_to_int32_round_to_zero(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env);
|
|
|
|
return ret;
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
int32_t helper_fdtoi(CPUSPARCState *env, float64 src)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
int32_t ret;
|
|
|
|
clear_float_exceptions(env);
|
|
|
|
ret = float64_to_int32_round_to_zero(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env);
|
|
|
|
return ret;
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
int32_t helper_fqtoi(CPUSPARCState *env)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
int32_t ret;
|
|
|
|
clear_float_exceptions(env);
|
|
|
|
ret = float128_to_int32_round_to_zero(QT1, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env);
|
|
|
|
return ret;
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TARGET_SPARC64
|
2012-03-14 01:38:22 +01:00
|
|
|
int64_t helper_fstox(CPUSPARCState *env, float32 src)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
int64_t ret;
|
|
|
|
clear_float_exceptions(env);
|
|
|
|
ret = float32_to_int64_round_to_zero(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env);
|
|
|
|
return ret;
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
int64_t helper_fdtox(CPUSPARCState *env, float64 src)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
int64_t ret;
|
|
|
|
clear_float_exceptions(env);
|
|
|
|
ret = float64_to_int64_round_to_zero(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env);
|
|
|
|
return ret;
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
int64_t helper_fqtox(CPUSPARCState *env)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
int64_t ret;
|
|
|
|
clear_float_exceptions(env);
|
|
|
|
ret = float128_to_int64_round_to_zero(QT1, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env);
|
|
|
|
return ret;
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
float32 helper_fabss(float32 src)
|
|
|
|
{
|
|
|
|
return float32_abs(src);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TARGET_SPARC64
|
2011-10-19 23:56:43 +02:00
|
|
|
float64 helper_fabsd(float64 src)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-15 19:20:20 +02:00
|
|
|
return float64_abs(src);
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
void helper_fabsq(CPUSPARCState *env)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
|
|
|
QT0 = float128_abs(QT1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
float32 helper_fsqrts(CPUSPARCState *env, float32 src)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
float32 ret;
|
|
|
|
clear_float_exceptions(env);
|
|
|
|
ret = float32_sqrt(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env);
|
|
|
|
return ret;
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
float64 helper_fsqrtd(CPUSPARCState *env, float64 src)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
float64 ret;
|
|
|
|
clear_float_exceptions(env);
|
|
|
|
ret = float64_sqrt(src, &env->fp_status);
|
|
|
|
check_ieee_exceptions(env);
|
|
|
|
return ret;
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
void helper_fsqrtq(CPUSPARCState *env)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
2011-10-17 20:25:56 +02:00
|
|
|
clear_float_exceptions(env);
|
2011-08-01 09:37:45 +02:00
|
|
|
QT0 = float128_sqrt(QT1, &env->fp_status);
|
2011-10-17 20:25:56 +02:00
|
|
|
check_ieee_exceptions(env);
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#define GEN_FCMP(name, size, reg1, reg2, FS, E) \
|
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 17:13:28 +02:00
|
|
|
void glue(helper_, name) (CPUSPARCState *env) \
|
2011-08-01 09:37:45 +02:00
|
|
|
{ \
|
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 17:13:28 +02:00
|
|
|
int ret; \
|
|
|
|
clear_float_exceptions(env); \
|
|
|
|
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 09:37:45 +02:00
|
|
|
} \
|
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 17:13:28 +02:00
|
|
|
check_ieee_exceptions(env); \
|
|
|
|
switch (ret) { \
|
2011-08-01 09:37:45 +02:00
|
|
|
case float_relation_unordered: \
|
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 17:13:28 +02:00
|
|
|
env->fsr |= (FSR_FCC1 | FSR_FCC0) << FS; \
|
|
|
|
env->fsr |= FSR_NVA; \
|
2011-08-01 09:37:45 +02:00
|
|
|
break; \
|
|
|
|
case float_relation_less: \
|
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 17:13:28 +02:00
|
|
|
env->fsr &= ~(FSR_FCC1) << FS; \
|
2011-08-01 09:37:45 +02:00
|
|
|
env->fsr |= FSR_FCC0 << FS; \
|
|
|
|
break; \
|
|
|
|
case float_relation_greater: \
|
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 17:13:28 +02:00
|
|
|
env->fsr &= ~(FSR_FCC0) << FS; \
|
2011-08-01 09:37:45 +02:00
|
|
|
env->fsr |= FSR_FCC1 << FS; \
|
|
|
|
break; \
|
|
|
|
default: \
|
|
|
|
env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
}
|
2011-10-15 19:20:20 +02:00
|
|
|
#define GEN_FCMP_T(name, size, FS, E) \
|
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 17:13:28 +02:00
|
|
|
void glue(helper_, name)(CPUSPARCState *env, size src1, size src2) \
|
2011-08-01 09:37:45 +02:00
|
|
|
{ \
|
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 17:13:28 +02:00
|
|
|
int ret; \
|
|
|
|
clear_float_exceptions(env); \
|
|
|
|
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 09:37:45 +02:00
|
|
|
} \
|
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 17:13:28 +02:00
|
|
|
check_ieee_exceptions(env); \
|
|
|
|
switch (ret) { \
|
2011-08-01 09:37:45 +02:00
|
|
|
case float_relation_unordered: \
|
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 17:13:28 +02:00
|
|
|
env->fsr |= (FSR_FCC1 | FSR_FCC0) << FS; \
|
2011-08-01 09:37:45 +02:00
|
|
|
break; \
|
|
|
|
case float_relation_less: \
|
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 17:13:28 +02:00
|
|
|
env->fsr &= ~(FSR_FCC1 << FS); \
|
2011-08-01 09:37:45 +02:00
|
|
|
env->fsr |= FSR_FCC0 << FS; \
|
|
|
|
break; \
|
|
|
|
case float_relation_greater: \
|
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 17:13:28 +02:00
|
|
|
env->fsr &= ~(FSR_FCC0 << FS); \
|
2011-08-01 09:37:45 +02:00
|
|
|
env->fsr |= FSR_FCC1 << FS; \
|
|
|
|
break; \
|
|
|
|
default: \
|
|
|
|
env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2011-10-15 19:20:20 +02:00
|
|
|
GEN_FCMP_T(fcmps, float32, 0, 0);
|
|
|
|
GEN_FCMP_T(fcmpd, float64, 0, 0);
|
2011-08-01 09:37:45 +02:00
|
|
|
|
2011-10-15 19:20:20 +02:00
|
|
|
GEN_FCMP_T(fcmpes, float32, 0, 1);
|
|
|
|
GEN_FCMP_T(fcmped, float64, 0, 1);
|
2011-08-01 09:37:45 +02:00
|
|
|
|
|
|
|
GEN_FCMP(fcmpq, float128, QT0, QT1, 0, 0);
|
|
|
|
GEN_FCMP(fcmpeq, float128, QT0, QT1, 0, 1);
|
|
|
|
|
|
|
|
#ifdef TARGET_SPARC64
|
2011-10-15 19:20:20 +02:00
|
|
|
GEN_FCMP_T(fcmps_fcc1, float32, 22, 0);
|
|
|
|
GEN_FCMP_T(fcmpd_fcc1, float64, 22, 0);
|
2011-08-01 09:37:45 +02:00
|
|
|
GEN_FCMP(fcmpq_fcc1, float128, QT0, QT1, 22, 0);
|
|
|
|
|
2011-10-15 19:20:20 +02:00
|
|
|
GEN_FCMP_T(fcmps_fcc2, float32, 24, 0);
|
|
|
|
GEN_FCMP_T(fcmpd_fcc2, float64, 24, 0);
|
2011-08-01 09:37:45 +02:00
|
|
|
GEN_FCMP(fcmpq_fcc2, float128, QT0, QT1, 24, 0);
|
|
|
|
|
2011-10-15 19:20:20 +02:00
|
|
|
GEN_FCMP_T(fcmps_fcc3, float32, 26, 0);
|
|
|
|
GEN_FCMP_T(fcmpd_fcc3, float64, 26, 0);
|
2011-08-01 09:37:45 +02:00
|
|
|
GEN_FCMP(fcmpq_fcc3, float128, QT0, QT1, 26, 0);
|
|
|
|
|
2011-10-15 19:20:20 +02:00
|
|
|
GEN_FCMP_T(fcmpes_fcc1, float32, 22, 1);
|
|
|
|
GEN_FCMP_T(fcmped_fcc1, float64, 22, 1);
|
2011-08-01 09:37:45 +02:00
|
|
|
GEN_FCMP(fcmpeq_fcc1, float128, QT0, QT1, 22, 1);
|
|
|
|
|
2011-10-15 19:20:20 +02:00
|
|
|
GEN_FCMP_T(fcmpes_fcc2, float32, 24, 1);
|
|
|
|
GEN_FCMP_T(fcmped_fcc2, float64, 24, 1);
|
2011-08-01 09:37:45 +02:00
|
|
|
GEN_FCMP(fcmpeq_fcc2, float128, QT0, QT1, 24, 1);
|
|
|
|
|
2011-10-15 19:20:20 +02:00
|
|
|
GEN_FCMP_T(fcmpes_fcc3, float32, 26, 1);
|
|
|
|
GEN_FCMP_T(fcmped_fcc3, float64, 26, 1);
|
2011-08-01 09:37:45 +02:00
|
|
|
GEN_FCMP(fcmpeq_fcc3, float128, QT0, QT1, 26, 1);
|
|
|
|
#endif
|
2011-10-15 19:20:20 +02:00
|
|
|
#undef GEN_FCMP_T
|
|
|
|
#undef GEN_FCMP
|
2011-08-01 09:37:45 +02:00
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
static inline void set_fsr(CPUSPARCState *env)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
|
|
|
int rnd_mode;
|
|
|
|
|
|
|
|
switch (env->fsr & FSR_RD_MASK) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:22 +01:00
|
|
|
void helper_ldfsr(CPUSPARCState *env, uint32_t new_fsr)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
|
|
|
env->fsr = (new_fsr & FSR_LDFSR_MASK) | (env->fsr & FSR_LDFSR_OLDMASK);
|
2011-07-03 12:42:23 +02:00
|
|
|
set_fsr(env);
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TARGET_SPARC64
|
2012-03-14 01:38:22 +01:00
|
|
|
void helper_ldxfsr(CPUSPARCState *env, uint64_t new_fsr)
|
2011-08-01 09:37:45 +02:00
|
|
|
{
|
|
|
|
env->fsr = (new_fsr & FSR_LDXFSR_MASK) | (env->fsr & FSR_LDXFSR_OLDMASK);
|
2011-07-03 12:42:23 +02:00
|
|
|
set_fsr(env);
|
2011-08-01 09:37:45 +02:00
|
|
|
}
|
|
|
|
#endif
|