[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 13/21] target/xtensa: Factor out calls to set_use_first_nan()
From: |
Peter Maydell |
Subject: |
[PATCH 13/21] target/xtensa: Factor out calls to set_use_first_nan() |
Date: |
Fri, 25 Oct 2024 15:12:46 +0100 |
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>
---
target/xtensa/cpu.h | 6 ++++++
target/xtensa/cpu.c | 2 +-
target/xtensa/fpu_helper.c | 33 +++++++++++++++++++--------------
3 files changed, 26 insertions(+), 15 deletions(-)
diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h
index 9f2341d8563..77e48eef19c 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/cpu.c b/target/xtensa/cpu.c
index a08c7a0b1f2..6f9039abaee 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/fpu_helper.c b/target/xtensa/fpu_helper.c
index 381e83ded83..50a5efa65e2 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);
}
--
2.34.1
- Re: [PATCH 11/21] target/sparc: Move cpu_put_fsr(env, 0) call to reset, (continued)
- [PATCH 14/21] target/xtensa: Explicitly set 2-NaN propagation rule, Peter Maydell, 2024/10/25
- [PATCH 16/21] target/alpha: Explicitly set 2-NaN propagation rule, Peter Maydell, 2024/10/25
- [PATCH 13/21] target/xtensa: Factor out calls to set_use_first_nan(),
Peter Maydell <=
- [PATCH 12/21] target/sparc: Explicitly set 2-NaN propagation rule, Peter Maydell, 2024/10/25
- [PATCH 15/21] target/i386: Set 2-NaN propagation rule explicitly, Peter Maydell, 2024/10/25
- [PATCH 17/21] target/microblaze: Move setting of float rounding mode to reset, Peter Maydell, 2024/10/25
- [PATCH 19/21] target/openrisc: Explicitly set 2-NaN propagation rule, Peter Maydell, 2024/10/25