2012-07-20 11:50:44 +04:00
|
|
|
/*
|
|
|
|
* OpenRISC float helper routines
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011-2012 Jia Liu <proljc@gmail.com>
|
|
|
|
* Feng Gao <gf91597@gmail.com>
|
|
|
|
*
|
|
|
|
* 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
|
2019-02-13 16:46:50 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2012-07-20 11:50:44 +04:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:22 +03:00
|
|
|
#include "qemu/osdep.h"
|
2012-07-20 11:50:44 +04:00
|
|
|
#include "cpu.h"
|
2014-04-08 09:31:41 +04:00
|
|
|
#include "exec/helper-proto.h"
|
2012-07-20 11:50:44 +04:00
|
|
|
#include "exception.h"
|
2018-01-19 21:24:22 +03:00
|
|
|
#include "fpu/softfloat.h"
|
2012-07-20 11:50:44 +04:00
|
|
|
|
2015-02-19 07:40:38 +03:00
|
|
|
static int ieee_ex_to_openrisc(int fexcp)
|
2012-07-20 11:50:44 +04:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2015-02-19 07:40:38 +03:00
|
|
|
if (fexcp & float_flag_invalid) {
|
|
|
|
ret |= FPCSR_IVF;
|
|
|
|
}
|
|
|
|
if (fexcp & float_flag_overflow) {
|
|
|
|
ret |= FPCSR_OVF;
|
|
|
|
}
|
|
|
|
if (fexcp & float_flag_underflow) {
|
|
|
|
ret |= FPCSR_UNF;
|
|
|
|
}
|
|
|
|
if (fexcp & float_flag_divbyzero) {
|
|
|
|
ret |= FPCSR_DZF;
|
|
|
|
}
|
|
|
|
if (fexcp & float_flag_inexact) {
|
|
|
|
ret |= FPCSR_IXF;
|
2012-07-20 11:50:44 +04:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-02-19 07:40:38 +03:00
|
|
|
void HELPER(update_fpcsr)(CPUOpenRISCState *env)
|
2012-07-20 11:50:44 +04:00
|
|
|
{
|
2015-02-19 07:40:38 +03:00
|
|
|
int tmp = get_float_exception_flags(&env->fp_status);
|
|
|
|
|
|
|
|
if (tmp) {
|
|
|
|
set_float_exception_flags(0, &env->fp_status);
|
|
|
|
tmp = ieee_ex_to_openrisc(tmp);
|
|
|
|
if (tmp) {
|
|
|
|
env->fpcsr |= tmp;
|
|
|
|
if (env->fpcsr & FPCSR_FPEE) {
|
|
|
|
helper_exception(env, EXCP_FPE);
|
|
|
|
}
|
|
|
|
}
|
2012-07-20 11:50:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-27 01:10:10 +03:00
|
|
|
void cpu_set_fpcsr(CPUOpenRISCState *env, uint32_t val)
|
|
|
|
{
|
|
|
|
static const int rm_to_sf[] = {
|
|
|
|
float_round_nearest_even,
|
|
|
|
float_round_to_zero,
|
|
|
|
float_round_up,
|
|
|
|
float_round_down
|
|
|
|
};
|
|
|
|
|
2020-01-11 00:28:43 +03:00
|
|
|
env->fpcsr = val & 0xfff;
|
2019-08-27 01:10:10 +03:00
|
|
|
set_float_rounding_mode(rm_to_sf[extract32(val, 1, 2)], &env->fp_status);
|
|
|
|
}
|
|
|
|
|
2012-07-20 11:50:44 +04:00
|
|
|
uint64_t HELPER(itofd)(CPUOpenRISCState *env, uint64_t val)
|
|
|
|
{
|
2019-05-07 00:49:25 +03:00
|
|
|
return int64_to_float64(val, &env->fp_status);
|
2012-07-20 11:50:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HELPER(itofs)(CPUOpenRISCState *env, uint32_t val)
|
|
|
|
{
|
2015-02-19 07:40:38 +03:00
|
|
|
return int32_to_float32(val, &env->fp_status);
|
2012-07-20 11:50:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t HELPER(ftoid)(CPUOpenRISCState *env, uint64_t val)
|
|
|
|
{
|
2019-05-07 00:49:25 +03:00
|
|
|
return float64_to_int64_round_to_zero(val, &env->fp_status);
|
2012-07-20 11:50:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HELPER(ftois)(CPUOpenRISCState *env, uint32_t val)
|
|
|
|
{
|
2019-08-27 01:15:05 +03:00
|
|
|
return float32_to_int32_round_to_zero(val, &env->fp_status);
|
2012-07-20 11:50:44 +04:00
|
|
|
}
|
|
|
|
|
2019-05-07 00:49:25 +03:00
|
|
|
uint64_t HELPER(stod)(CPUOpenRISCState *env, uint32_t val)
|
|
|
|
{
|
|
|
|
return float32_to_float64(val, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HELPER(dtos)(CPUOpenRISCState *env, uint64_t val)
|
|
|
|
{
|
|
|
|
return float64_to_float32(val, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
2012-07-20 11:50:44 +04:00
|
|
|
#define FLOAT_CALC(name) \
|
|
|
|
uint64_t helper_float_ ## name ## _d(CPUOpenRISCState *env, \
|
|
|
|
uint64_t fdt0, uint64_t fdt1) \
|
2015-02-19 07:40:38 +03:00
|
|
|
{ return float64_ ## name(fdt0, fdt1, &env->fp_status); } \
|
2012-07-20 11:50:44 +04:00
|
|
|
uint32_t helper_float_ ## name ## _s(CPUOpenRISCState *env, \
|
|
|
|
uint32_t fdt0, uint32_t fdt1) \
|
2015-02-19 07:40:38 +03:00
|
|
|
{ return float32_ ## name(fdt0, fdt1, &env->fp_status); }
|
2012-07-20 11:50:44 +04:00
|
|
|
|
|
|
|
FLOAT_CALC(add)
|
|
|
|
FLOAT_CALC(sub)
|
|
|
|
FLOAT_CALC(mul)
|
|
|
|
FLOAT_CALC(div)
|
|
|
|
FLOAT_CALC(rem)
|
|
|
|
#undef FLOAT_CALC
|
|
|
|
|
2015-02-19 05:47:35 +03:00
|
|
|
|
|
|
|
uint64_t helper_float_madd_d(CPUOpenRISCState *env, uint64_t a,
|
|
|
|
uint64_t b, uint64_t c)
|
|
|
|
{
|
2015-02-19 07:40:38 +03:00
|
|
|
/* Note that or1ksim doesn't use fused operation. */
|
|
|
|
b = float64_mul(b, c, &env->fp_status);
|
|
|
|
return float64_add(a, b, &env->fp_status);
|
2012-07-20 11:50:44 +04:00
|
|
|
}
|
|
|
|
|
2015-02-19 05:47:35 +03:00
|
|
|
uint32_t helper_float_madd_s(CPUOpenRISCState *env, uint32_t a,
|
|
|
|
uint32_t b, uint32_t c)
|
|
|
|
{
|
2015-02-19 07:40:38 +03:00
|
|
|
/* Note that or1ksim doesn't use fused operation. */
|
|
|
|
b = float32_mul(b, c, &env->fp_status);
|
|
|
|
return float32_add(a, b, &env->fp_status);
|
2015-02-19 05:47:35 +03:00
|
|
|
}
|
2012-07-20 11:50:44 +04:00
|
|
|
|
|
|
|
|
2015-02-19 07:40:38 +03:00
|
|
|
#define FLOAT_CMP(name, impl) \
|
|
|
|
target_ulong helper_float_ ## name ## _d(CPUOpenRISCState *env, \
|
|
|
|
uint64_t fdt0, uint64_t fdt1) \
|
|
|
|
{ return float64_ ## impl(fdt0, fdt1, &env->fp_status); } \
|
|
|
|
target_ulong helper_float_ ## name ## _s(CPUOpenRISCState *env, \
|
|
|
|
uint32_t fdt0, uint32_t fdt1) \
|
|
|
|
{ return float32_ ## impl(fdt0, fdt1, &env->fp_status); }
|
2012-07-20 11:50:44 +04:00
|
|
|
|
2015-02-19 07:40:38 +03:00
|
|
|
FLOAT_CMP(le, le)
|
|
|
|
FLOAT_CMP(lt, lt)
|
|
|
|
FLOAT_CMP(eq, eq_quiet)
|
2019-05-14 16:39:47 +03:00
|
|
|
FLOAT_CMP(un, unordered_quiet)
|
2012-07-20 11:50:44 +04:00
|
|
|
#undef FLOAT_CMP
|
2019-05-14 16:39:47 +03:00
|
|
|
|
|
|
|
#define FLOAT_UCMP(name, expr) \
|
|
|
|
target_ulong helper_float_ ## name ## _d(CPUOpenRISCState *env, \
|
|
|
|
uint64_t fdt0, uint64_t fdt1) \
|
|
|
|
{ \
|
|
|
|
int r = float64_compare_quiet(fdt0, fdt1, &env->fp_status); \
|
|
|
|
return expr; \
|
|
|
|
} \
|
|
|
|
target_ulong helper_float_ ## name ## _s(CPUOpenRISCState *env, \
|
|
|
|
uint32_t fdt0, uint32_t fdt1) \
|
|
|
|
{ \
|
|
|
|
int r = float32_compare_quiet(fdt0, fdt1, &env->fp_status); \
|
|
|
|
return expr; \
|
|
|
|
}
|
|
|
|
|
|
|
|
FLOAT_UCMP(ueq, r == float_relation_equal || r == float_relation_unordered)
|
|
|
|
FLOAT_UCMP(ult, r == float_relation_less || r == float_relation_unordered)
|
|
|
|
FLOAT_UCMP(ule, r != float_relation_greater)
|
|
|
|
#undef FLOAT_UCMP
|