summaryrefslogtreecommitdiffstats
path: root/target/tricore/fpu_helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'target/tricore/fpu_helper.c')
-rw-r--r--target/tricore/fpu_helper.c134
1 files changed, 133 insertions, 1 deletions
diff --git a/target/tricore/fpu_helper.c b/target/tricore/fpu_helper.c
index 98fe9472b1..7979bb6692 100644
--- a/target/tricore/fpu_helper.c
+++ b/target/tricore/fpu_helper.c
@@ -21,7 +21,8 @@
#include "cpu.h"
#include "exec/helper-proto.h"
-#define ADD_NAN 0x7cf00001
+#define QUIET_NAN 0x7fc00000
+#define ADD_NAN 0x7fc00001
#define DIV_NAN 0x7fc00008
#define MUL_NAN 0x7fc00002
#define FPU_FS PSW_USB_C
@@ -47,6 +48,42 @@ static inline bool f_is_denormal(float32 arg)
return float32_is_zero_or_denormal(arg) && !float32_is_zero(arg);
}
+static inline float32 f_maddsub_nan_result(float32 arg1, float32 arg2,
+ float32 arg3, float32 result,
+ uint32_t muladd_negate_c)
+{
+ uint32_t aSign, bSign, cSign;
+ uint32_t aExp, bExp, cExp;
+
+ if (float32_is_any_nan(arg1) || float32_is_any_nan(arg2) ||
+ float32_is_any_nan(arg3)) {
+ return QUIET_NAN;
+ } else if (float32_is_infinity(arg1) && float32_is_zero(arg2)) {
+ return MUL_NAN;
+ } else if (float32_is_zero(arg1) && float32_is_infinity(arg2)) {
+ return MUL_NAN;
+ } else {
+ aSign = arg1 >> 31;
+ bSign = arg2 >> 31;
+ cSign = arg3 >> 31;
+
+ aExp = (arg1 >> 23) & 0xff;
+ bExp = (arg2 >> 23) & 0xff;
+ cExp = (arg3 >> 23) & 0xff;
+
+ if (muladd_negate_c) {
+ cSign ^= 1;
+ }
+ if (((aExp == 0xff) || (bExp == 0xff)) && (cExp == 0xff)) {
+ if (aSign ^ bSign ^ cSign) {
+ return ADD_NAN;
+ }
+ }
+ }
+
+ return result;
+}
+
static void f_update_psw_flags(CPUTriCoreState *env, uint8_t flags)
{
uint8_t some_excp = 0;
@@ -159,6 +196,60 @@ uint32_t helper_fdiv(CPUTriCoreState *env, uint32_t r1, uint32_t r2)
return (uint32_t)f_result;
}
+uint32_t helper_fmadd(CPUTriCoreState *env, uint32_t r1,
+ uint32_t r2, uint32_t r3)
+{
+ uint32_t flags;
+ float32 arg1 = make_float32(r1);
+ float32 arg2 = make_float32(r2);
+ float32 arg3 = make_float32(r3);
+ float32 f_result;
+
+ f_result = float32_muladd(arg1, arg2, arg3, 0, &env->fp_status);
+
+ flags = f_get_excp_flags(env);
+ if (flags) {
+ if (flags & float_flag_invalid) {
+ arg1 = float32_squash_input_denormal(arg1, &env->fp_status);
+ arg2 = float32_squash_input_denormal(arg2, &env->fp_status);
+ arg3 = float32_squash_input_denormal(arg3, &env->fp_status);
+ f_result = f_maddsub_nan_result(arg1, arg2, arg3, f_result, 0);
+ }
+ f_update_psw_flags(env, flags);
+ } else {
+ env->FPU_FS = 0;
+ }
+ return (uint32_t)f_result;
+}
+
+uint32_t helper_fmsub(CPUTriCoreState *env, uint32_t r1,
+ uint32_t r2, uint32_t r3)
+{
+ uint32_t flags;
+ float32 arg1 = make_float32(r1);
+ float32 arg2 = make_float32(r2);
+ float32 arg3 = make_float32(r3);
+ float32 f_result;
+
+ f_result = float32_muladd(arg1, arg2, arg3, float_muladd_negate_product,
+ &env->fp_status);
+
+ flags = f_get_excp_flags(env);
+ if (flags) {
+ if (flags & float_flag_invalid) {
+ arg1 = float32_squash_input_denormal(arg1, &env->fp_status);
+ arg2 = float32_squash_input_denormal(arg2, &env->fp_status);
+ arg3 = float32_squash_input_denormal(arg3, &env->fp_status);
+
+ f_result = f_maddsub_nan_result(arg1, arg2, arg3, f_result, 1);
+ }
+ f_update_psw_flags(env, flags);
+ } else {
+ env->FPU_FS = 0;
+ }
+ return (uint32_t)f_result;
+}
+
uint32_t helper_fcmp(CPUTriCoreState *env, uint32_t r1, uint32_t r2)
{
uint32_t result, flags;
@@ -215,3 +306,44 @@ uint32_t helper_itof(CPUTriCoreState *env, uint32_t arg)
}
return (uint32_t)f_result;
}
+
+uint32_t helper_ftouz(CPUTriCoreState *env, uint32_t arg)
+{
+ float32 f_arg = make_float32(arg);
+ uint32_t result;
+ int32_t flags;
+
+ result = float32_to_uint32_round_to_zero(f_arg, &env->fp_status);
+
+ flags = f_get_excp_flags(env);
+ if (flags & float_flag_invalid) {
+ flags &= ~float_flag_inexact;
+ if (float32_is_any_nan(f_arg)) {
+ result = 0;
+ }
+ } else if (float32_lt_quiet(f_arg, 0, &env->fp_status)) {
+ flags = float_flag_invalid;
+ result = 0;
+ }
+
+ if (flags) {
+ f_update_psw_flags(env, flags);
+ } else {
+ env->FPU_FS = 0;
+ }
+ return result;
+}
+
+void helper_updfl(CPUTriCoreState *env, uint32_t arg)
+{
+ env->FPU_FS = extract32(arg, 7, 1) & extract32(arg, 15, 1);
+ env->FPU_FI = (extract32(arg, 6, 1) & extract32(arg, 14, 1)) << 31;
+ env->FPU_FV = (extract32(arg, 5, 1) & extract32(arg, 13, 1)) << 31;
+ env->FPU_FZ = (extract32(arg, 4, 1) & extract32(arg, 12, 1)) << 31;
+ env->FPU_FU = (extract32(arg, 3, 1) & extract32(arg, 11, 1)) << 31;
+ /* clear FX and RM */
+ env->PSW &= ~(extract32(arg, 10, 1) << 26);
+ env->PSW |= (extract32(arg, 2, 1) & extract32(arg, 10, 1)) << 26;
+
+ fpu_set_state(env);
+}