aboutsummaryrefslogtreecommitdiff
path: root/target/xtensa
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2024-11-05 10:09:55 +0000
committerPeter Maydell <peter.maydell@linaro.org>2024-11-05 10:09:55 +0000
commit80de5f24e09cd9885a5e8d72cc01c097c23bf227 (patch)
tree59d2f6bf0ec61918434e11d75e31cbb360b64a4f /target/xtensa
parent4482f32dcd1faa035e03ded557fa980e8b528c31 (diff)
target/xtensa: Factor out calls to set_use_first_nan()
In xtensa we currently call set_use_first_nan() in a lot of places where we want to switch the NaN-propagation handling. We're about to change the softfloat API we use to do that, so start by factoring all the calls out into a single xtensa_use_first_nan() function. The bulk of this change was done with sed -i -e 's/set_use_first_nan(\([^,]*\),[^)]*)/xtensa_use_first_nan(env, \1)/' target/xtensa/fpu_helper.c Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Max Filippov <jcmvbkbc@gmail.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20241025141254.2141506-14-peter.maydell@linaro.org
Diffstat (limited to 'target/xtensa')
-rw-r--r--target/xtensa/cpu.c2
-rw-r--r--target/xtensa/cpu.h6
-rw-r--r--target/xtensa/fpu_helper.c33
3 files changed, 26 insertions, 15 deletions
diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c
index a08c7a0b1f..6f9039abae 100644
--- a/target/xtensa/cpu.c
+++ b/target/xtensa/cpu.c
@@ -134,7 +134,7 @@ static void xtensa_cpu_reset_hold(Object *obj, ResetType type)
cs->halted = env->runstall;
#endif
set_no_signaling_nans(!dfpu, &env->fp_status);
- set_use_first_nan(!dfpu, &env->fp_status);
+ xtensa_use_first_nan(env, !dfpu);
}
static ObjectClass *xtensa_cpu_class_by_name(const char *cpu_model)
diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h
index 9f2341d856..77e48eef19 100644
--- a/target/xtensa/cpu.h
+++ b/target/xtensa/cpu.h
@@ -802,4 +802,10 @@ static inline void cpu_get_tb_cpu_state(CPUXtensaState *env, vaddr *pc,
XtensaCPU *xtensa_cpu_create_with_clock(const char *cpu_type,
Clock *cpu_refclk);
+/*
+ * Set the NaN propagation rule for future FPU operations:
+ * use_first is true to pick the first NaN as the result if both
+ * inputs are NaNs, false to pick the second.
+ */
+void xtensa_use_first_nan(CPUXtensaState *env, bool use_first);
#endif
diff --git a/target/xtensa/fpu_helper.c b/target/xtensa/fpu_helper.c
index 381e83ded8..50a5efa65e 100644
--- a/target/xtensa/fpu_helper.c
+++ b/target/xtensa/fpu_helper.c
@@ -57,6 +57,11 @@ static const struct {
{ XTENSA_FP_V, float_flag_invalid, },
};
+void xtensa_use_first_nan(CPUXtensaState *env, bool use_first)
+{
+ set_use_first_nan(use_first, &env->fp_status);
+}
+
void HELPER(wur_fpu2k_fcr)(CPUXtensaState *env, uint32_t v)
{
static const int rounding_mode[] = {
@@ -171,87 +176,87 @@ float32 HELPER(fpu2k_msub_s)(CPUXtensaState *env,
float64 HELPER(add_d)(CPUXtensaState *env, float64 a, float64 b)
{
- set_use_first_nan(true, &env->fp_status);
+ xtensa_use_first_nan(env, true);
return float64_add(a, b, &env->fp_status);
}
float32 HELPER(add_s)(CPUXtensaState *env, float32 a, float32 b)
{
- set_use_first_nan(env->config->use_first_nan, &env->fp_status);
+ xtensa_use_first_nan(env, env->config->use_first_nan);
return float32_add(a, b, &env->fp_status);
}
float64 HELPER(sub_d)(CPUXtensaState *env, float64 a, float64 b)
{
- set_use_first_nan(true, &env->fp_status);
+ xtensa_use_first_nan(env, true);
return float64_sub(a, b, &env->fp_status);
}
float32 HELPER(sub_s)(CPUXtensaState *env, float32 a, float32 b)
{
- set_use_first_nan(env->config->use_first_nan, &env->fp_status);
+ xtensa_use_first_nan(env, env->config->use_first_nan);
return float32_sub(a, b, &env->fp_status);
}
float64 HELPER(mul_d)(CPUXtensaState *env, float64 a, float64 b)
{
- set_use_first_nan(true, &env->fp_status);
+ xtensa_use_first_nan(env, true);
return float64_mul(a, b, &env->fp_status);
}
float32 HELPER(mul_s)(CPUXtensaState *env, float32 a, float32 b)
{
- set_use_first_nan(env->config->use_first_nan, &env->fp_status);
+ xtensa_use_first_nan(env, env->config->use_first_nan);
return float32_mul(a, b, &env->fp_status);
}
float64 HELPER(madd_d)(CPUXtensaState *env, float64 a, float64 b, float64 c)
{
- set_use_first_nan(env->config->use_first_nan, &env->fp_status);
+ xtensa_use_first_nan(env, env->config->use_first_nan);
return float64_muladd(b, c, a, 0, &env->fp_status);
}
float32 HELPER(madd_s)(CPUXtensaState *env, float32 a, float32 b, float32 c)
{
- set_use_first_nan(env->config->use_first_nan, &env->fp_status);
+ xtensa_use_first_nan(env, env->config->use_first_nan);
return float32_muladd(b, c, a, 0, &env->fp_status);
}
float64 HELPER(msub_d)(CPUXtensaState *env, float64 a, float64 b, float64 c)
{
- set_use_first_nan(env->config->use_first_nan, &env->fp_status);
+ xtensa_use_first_nan(env, env->config->use_first_nan);
return float64_muladd(b, c, a, float_muladd_negate_product,
&env->fp_status);
}
float32 HELPER(msub_s)(CPUXtensaState *env, float32 a, float32 b, float32 c)
{
- set_use_first_nan(env->config->use_first_nan, &env->fp_status);
+ xtensa_use_first_nan(env, env->config->use_first_nan);
return float32_muladd(b, c, a, float_muladd_negate_product,
&env->fp_status);
}
float64 HELPER(mkdadj_d)(CPUXtensaState *env, float64 a, float64 b)
{
- set_use_first_nan(true, &env->fp_status);
+ xtensa_use_first_nan(env, true);
return float64_div(b, a, &env->fp_status);
}
float32 HELPER(mkdadj_s)(CPUXtensaState *env, float32 a, float32 b)
{
- set_use_first_nan(env->config->use_first_nan, &env->fp_status);
+ xtensa_use_first_nan(env, env->config->use_first_nan);
return float32_div(b, a, &env->fp_status);
}
float64 HELPER(mksadj_d)(CPUXtensaState *env, float64 v)
{
- set_use_first_nan(true, &env->fp_status);
+ xtensa_use_first_nan(env, true);
return float64_sqrt(v, &env->fp_status);
}
float32 HELPER(mksadj_s)(CPUXtensaState *env, float32 v)
{
- set_use_first_nan(env->config->use_first_nan, &env->fp_status);
+ xtensa_use_first_nan(env, env->config->use_first_nan);
return float32_sqrt(v, &env->fp_status);
}