qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [PULL 13/31] target/xtensa: Factor out calls to set_use_first_nan()
Date: Tue,  5 Nov 2024 11:19:17 +0000	[thread overview]
Message-ID: <20241105111935.2747034-14-peter.maydell@linaro.org> (raw)
In-Reply-To: <20241105111935.2747034-1-peter.maydell@linaro.org>

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
---
 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



  parent reply	other threads:[~2024-11-05 11:23 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-05 11:19 [PULL 00/31] target-arm queue Peter Maydell
2024-11-05 11:19 ` [PULL 01/31] softfloat: Allow 2-operand NaN propagation rule to be set at runtime Peter Maydell
2024-11-05 11:19 ` [PULL 02/31] tests/fp: Explicitly set 2-NaN propagation rule Peter Maydell
2024-11-05 11:19 ` [PULL 03/31] target/arm: " Peter Maydell
2024-11-05 11:19 ` [PULL 04/31] target/mips: " Peter Maydell
2024-11-05 11:19 ` [PULL 05/31] target/loongarch: " Peter Maydell
2024-11-05 11:19 ` [PULL 06/31] target/hppa: " Peter Maydell
2024-11-05 11:19 ` [PULL 07/31] target/s390x: " Peter Maydell
2024-11-05 11:19 ` [PULL 08/31] target/ppc: " Peter Maydell
2024-11-05 11:19 ` [PULL 09/31] target/m68k: " Peter Maydell
2024-11-05 11:19 ` [PULL 10/31] target/m68k: Initialize float_status fields in gdb set/get functions Peter Maydell
2024-11-05 11:19 ` [PULL 11/31] target/sparc: Move cpu_put_fsr(env, 0) call to reset Peter Maydell
2024-11-05 11:19 ` [PULL 12/31] target/sparc: Explicitly set 2-NaN propagation rule Peter Maydell
2024-11-05 11:19 ` Peter Maydell [this message]
2024-11-05 11:19 ` [PULL 14/31] target/xtensa: " Peter Maydell
2024-11-05 11:19 ` [PULL 15/31] target/i386: Set 2-NaN propagation rule explicitly Peter Maydell
2024-11-05 11:19 ` [PULL 16/31] target/alpha: Explicitly set 2-NaN propagation rule Peter Maydell
2024-11-05 11:19 ` [PULL 17/31] target/microblaze: Move setting of float rounding mode to reset Peter Maydell
2024-11-05 11:19 ` [PULL 18/31] target/microblaze: Explicitly set 2-NaN propagation rule Peter Maydell
2024-11-05 11:19 ` [PULL 19/31] target/openrisc: " Peter Maydell
2024-11-05 11:19 ` [PULL 20/31] target/rx: " Peter Maydell
2024-11-05 11:19 ` [PULL 21/31] softfloat: Remove fallback rule from pickNaN() Peter Maydell
2024-11-05 11:19 ` [PULL 22/31] Revert "target/arm: Fix usage of MMU indexes when EL3 is AArch32" Peter Maydell
2024-11-05 11:19 ` [PULL 23/31] target/arm: Add new MMU indexes for AArch32 Secure PL1&0 Peter Maydell
2024-11-05 11:19 ` [PULL 24/31] target/arm: Fix SVE SDOT/UDOT/USDOT (4-way, indexed) Peter Maydell
2024-11-05 11:19 ` [PULL 25/31] disas: Fix build against Capstone v6 (again) Peter Maydell
2024-11-05 11:19 ` [PULL 26/31] hw/rtc/ds1338: Trace send and receive operations Peter Maydell
2024-11-05 11:19 ` [PULL 27/31] hw/timer/imx_gpt: Convert DPRINTF to trace events Peter Maydell
2024-11-05 11:19 ` [PULL 28/31] hw/watchdog/wdt_imx2: Remove redundant assignment Peter Maydell
2024-11-05 11:19 ` [PULL 29/31] hw/sensor/tmp105: Convert printf() to trace event, add tracing for read/write access Peter Maydell
2024-11-05 11:19 ` [PULL 30/31] hw/net/npcm_gmac: Change error log to trace event Peter Maydell
2024-11-05 11:19 ` [PULL 31/31] target/arm: Enable FEAT_CMOW for -cpu max Peter Maydell
2024-11-06 11:15 ` [PULL 00/31] target-arm queue Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241105111935.2747034-14-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).