qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time
@ 2024-10-25 14:12 Peter Maydell
  2024-10-25 14:12 ` [PATCH 01/21] softfloat: Allow 2-operand NaN propagation rule to be set at runtime Peter Maydell
                   ` (21 more replies)
  0 siblings, 22 replies; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

IEEE 758 does not define a fixed rule for which NaN to pick as the
result if both operands of a 2-operand operation are NaNs.  As a
result different architectures have ended up with different rules for
propagating NaNs.

QEMU currently hardcodes the NaN propagation logic into the binary,
because pickNaN() has an ifdef ladder for different targets.  We want
to make the propagation rule instead be selectable at runtime,
because:
 * this will let us have multiple targets in one QEMU binary
 * the Arm FEAT_AFP architectural feature includes letting the guest
   select a NaN propagation rule at runtime
 * x86 specifies different propagation rules for x87 FPU ops and for
   SSE ops, and specifying the rule in the float_status would let us
   emulate this, instead of wrongly using the x87 rules everywhere
 * xtensa allows selection of NaN propagation rule at runtime;
   currently we implement this with the use_first_nan flag which
   is only used by xtensa; providing a general facility will let us
   remove this limited-purpose handling
                                                           
This series switches pickNaN away from the ifdef ladder. Instead
targets must always set a 2-NaN propagation rule via the new
set_float_2nan_prop_rule(), unless they are using default_nan_mode.
Patch 1 implements this in core softfloat (with a transitional
fallback to "use the old ifdef ladder logic" if the target doesn't
specify the propagation rule). Then subsequent patches convert
all the targets to set the rule explicitly. The final patch then
removes the remnants of the transitional logic.

I have included a couple of minor fixes for sparc, xtensa, m68k.
This is intended as a no-behaviour-change patchset, so although there
are a few places where I have noticed that the current behaviour
is not correct I have left these as TODO comments. A summary of
those TODOs and other oddities I have noticed but not tried to
tackle is:

 * hppa really ought to implement a CPU reset method
 * alpha also doesn't implement CPU reset
 * ppc sets tininess_before_rounding on fp_status but not on
   vec_status, so its behaviour there will vary between
   guest instructions; unclear to me if this is intended
 * x86 should set the float_2nan_prop_ab rule on env->sse_status
   (and maybe env->mmx_status, though 3DNow! insns don't handle
   NaNs in a documented way anyway)
 * alpha never had a case in the ifdef ladder so it uses the
   x87 propagation rule. It ought to use float_2nan_prop_ba.
 * openrisc didn't have an ifdef and also uses the x87 rule;
   this is probably wrong but I couldn't find anything documenting
   what it actually does
 * rx didn't have an ifdef and also uses the x87 rule;
   again, probably wrong

The next stage after this patchset, obviously, is to do the
same thing with pickNaNMulAdd(). That is a little trickier
because currently we ask it to do two things:
 * handle the "infinity * zero + NaN" corner case
 * pick a NaN when more than one operand is a NaN
My intention is to separate these out so that targets specify
both separately. This gives more orthogonality (e.g. Arm,
MIPS with !snan_bit_is_one and loongarch64 all have the same
"prefer SNaN over QNaN, prefer C over A over B" NaN selection
logic but they have different ideas about the infzero case).

(Once pickNaNMulAdd() is converted we will be able to remove
the current xtensa-specific use_first_nan flag.)

thanks
-- PMM

Peter Maydell (21):
  softfloat: Allow 2-operand NaN propagation rule to be set at runtime
  tests/fp: Explicitly set 2-NaN propagation rule
  target/arm: Explicitly set 2-NaN propagation rule
  target/mips: Explicitly set 2-NaN propagation rule
  target/loongarch: Explicitly set 2-NaN propagation rule
  target/hppa: Explicitly set 2-NaN propagation rule
  target/s390x: Explicitly set 2-NaN propagation rule
  target/ppc: Explicitly set 2-NaN propagation rule
  target/m68k: Explicitly set 2-NaN propagation rule
  target/m68k: Initialize float_status fields in gdb set/get functions
  target/sparc: Move cpu_put_fsr(env, 0) call to reset
  target/sparc: Explicitly set 2-NaN propagation rule
  target/xtensa: Factor out calls to set_use_first_nan()
  target/xtensa: Explicitly set 2-NaN propagation rule
  target/i386: Set 2-NaN propagation rule explicitly
  target/alpha: Explicitly set 2-NaN propagation rule
  target/microblaze: Move setting of float rounding mode to reset
  target/microblaze: Explicitly set 2-NaN propagation rule
  target/openrisc: Explicitly set 2-NaN propagation rule
  target/rx: Explicitly set 2-NaN propagation rule
  softfloat: Remove fallback rule from pickNaN()

 include/fpu/softfloat-helpers.h   |  11 +++
 include/fpu/softfloat-types.h     |  38 ++++++++
 target/i386/cpu.h                 |   3 +
 target/mips/fpu_helper.h          |  22 +++++
 target/xtensa/cpu.h               |   6 ++
 linux-user/arm/nwfpe/fpa11.c      |  18 ++++
 target/alpha/cpu.c                |  11 +++
 target/arm/cpu.c                  |  25 +++--
 target/hppa/fpu_helper.c          |   6 ++
 target/i386/cpu.c                 |   4 +
 target/i386/tcg/fpu_helper.c      |  40 ++++++++
 target/loongarch/tcg/fpu_helper.c |   1 +
 target/m68k/cpu.c                 |  16 +++
 target/m68k/fpu_helper.c          |   1 +
 target/m68k/helper.c              |   4 +-
 target/microblaze/cpu.c           |  10 +-
 target/mips/cpu.c                 |   2 +-
 target/mips/msa.c                 |  17 ++++
 target/openrisc/cpu.c             |   6 ++
 target/ppc/cpu_init.c             |   8 ++
 target/rx/cpu.c                   |   7 ++
 target/s390x/cpu.c                |   1 +
 target/sparc/cpu.c                |  10 +-
 target/sparc/fop_helper.c         |  10 +-
 target/xtensa/cpu.c               |   2 +-
 target/xtensa/fpu_helper.c        |  35 ++++---
 tests/fp/fp-bench.c               |   2 +
 tests/fp/fp-test-log2.c           |   1 +
 tests/fp/fp-test.c                |   2 +
 fpu/softfloat-specialize.c.inc    | 156 +++++++++++-------------------
 30 files changed, 346 insertions(+), 129 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH 01/21] softfloat: Allow 2-operand NaN propagation rule to be set at runtime
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-28 12:07   ` Richard Henderson
  2024-10-25 14:12 ` [PATCH 02/21] tests/fp: Explicitly set 2-NaN propagation rule Peter Maydell
                   ` (20 subsequent siblings)
  21 siblings, 1 reply; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

IEEE 758 does not define a fixed rule for which NaN to pick as the
result if both operands of a 2-operand operation are NaNs.  As a
result different architectures have ended up with different rules for
propagating NaNs.

QEMU currently hardcodes the NaN propagation logic into the binary
because pickNaN() has an ifdef ladder for different targets.  We want
to make the propagation rule instead be selectable at runtime,
because:
 * this will let us have multiple targets in one QEMU binary
 * the Arm FEAT_AFP architectural feature includes letting
   the guest select a NaN propagation rule at runtime
 * x86 specifies different propagation rules for x87 FPU ops
   and for SSE ops, and specifying the rule in the float_status
   would let us emulate this, instead of wrongly using the
   x87 rules everywhere

In this commit we add an enum for the propagation rule, the field in
float_status, and the corresponding getters and setters.  We change
pickNaN to honour this, but because all targets still leave this
field at its default 0 value, the fallback logic will pick the rule
type with the old ifdef ladder.

It's valid not to set a propagation rule if default_nan_mode is
enabled, because in that case there's no need to pick a NaN; all the
callers of pickNaN() catch this case and skip calling it.  So we can
already assert that we don't get into the "no rule defined" codepath
for our four targets which always set default_nan_mode: Hexagon,
RiscV, SH4 and Tricore, and for the one target which does not have FP
at all: avr.  These targets will not need to be updated to call
set_float_2nan_prop_rule().

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
Reindent means a couple of slightly long lines in comments,
but those will move again in a later patch, so seemed clearer to
not re-wrap the comment and then re-rewrap it later.
---
 include/fpu/softfloat-helpers.h |  11 ++
 include/fpu/softfloat-types.h   |  42 ++++++
 fpu/softfloat-specialize.c.inc  | 229 ++++++++++++++++++--------------
 3 files changed, 185 insertions(+), 97 deletions(-)

diff --git a/include/fpu/softfloat-helpers.h b/include/fpu/softfloat-helpers.h
index 94cbe073ec5..453188de70b 100644
--- a/include/fpu/softfloat-helpers.h
+++ b/include/fpu/softfloat-helpers.h
@@ -75,6 +75,12 @@ static inline void set_floatx80_rounding_precision(FloatX80RoundPrec val,
     status->floatx80_rounding_precision = val;
 }
 
+static inline void set_float_2nan_prop_rule(Float2NaNPropRule rule,
+                                            float_status *status)
+{
+    status->float_2nan_prop_rule = rule;
+}
+
 static inline void set_flush_to_zero(bool val, float_status *status)
 {
     status->flush_to_zero = val;
@@ -126,6 +132,11 @@ get_floatx80_rounding_precision(float_status *status)
     return status->floatx80_rounding_precision;
 }
 
+static inline Float2NaNPropRule get_float_2nan_prop_rule(float_status *status)
+{
+    return status->float_2nan_prop_rule;
+}
+
 static inline bool get_flush_to_zero(float_status *status)
 {
     return status->flush_to_zero;
diff --git a/include/fpu/softfloat-types.h b/include/fpu/softfloat-types.h
index 0884ec4ef7a..5cd5a0d0ae1 100644
--- a/include/fpu/softfloat-types.h
+++ b/include/fpu/softfloat-types.h
@@ -170,6 +170,47 @@ typedef enum __attribute__((__packed__)) {
     floatx80_precision_s,
 } FloatX80RoundPrec;
 
+/*
+ * 2-input NaN propagation rule. Individual architectures have
+ * different rules for which input NaN is propagated to the output
+ * when there is more than one NaN on the input.
+ *
+ * If default_nan_mode is enabled then it is valid not to set a
+ * NaN propagation rule, because the softfloat code guarantees
+ * not to try to pick a NaN to propagate in default NaN mode.
+ *
+ * For transition, currently the 'none' rule will cause us to
+ * fall back to picking the propagation rule based on the existing
+ * ifdef ladder. When all targets are converted it will be an error
+ * not to set the rule in float_status unless in default_nan_mode,
+ * and we will assert if we need to handle an input NaN and no
+ * rule was selected.
+ */
+typedef enum __attribute__((__packed__)) {
+    /* No propagation rule specified */
+    float_2nan_prop_none = 0,
+    /* Prefer SNaN over QNaN, then operand A over B */
+    float_2nan_prop_s_ab,
+    /* Prefer SNaN over QNaN, then operand B over A */
+    float_2nan_prop_s_ba,
+    /* Prefer A over B regardless of SNaN vs QNaN */
+    float_2nan_prop_ab,
+    /* Prefer B over A regardless of SNaN vs QNaN */
+    float_2nan_prop_ba,
+    /*
+     * This implements x87 NaN propagation rules:
+     * SNaN + QNaN => return the QNaN
+     * two SNaNs => return the one with the larger significand, silenced
+     * two QNaNs => return the one with the larger significand
+     * SNaN and a non-NaN => return the SNaN, silenced
+     * QNaN and a non-NaN => return the QNaN
+     *
+     * If we get down to comparing significands and they are the same,
+     * return the NaN with the positive sign bit (if any).
+     */
+    float_2nan_prop_x87,
+} Float2NaNPropRule;
+
 /*
  * Floating Point Status. Individual architectures may maintain
  * several versions of float_status for different functions. The
@@ -181,6 +222,7 @@ typedef struct float_status {
     uint16_t float_exception_flags;
     FloatRoundMode float_rounding_mode;
     FloatX80RoundPrec floatx80_rounding_precision;
+    Float2NaNPropRule float_2nan_prop_rule;
     bool tininess_before_rounding;
     /* should denormalised results go to zero and set the inexact flag? */
     bool flush_to_zero;
diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
index 4e279b9bc40..fae6794a152 100644
--- a/fpu/softfloat-specialize.c.inc
+++ b/fpu/softfloat-specialize.c.inc
@@ -390,118 +390,153 @@ bool float32_is_signaling_nan(float32 a_, float_status *status)
 static int pickNaN(FloatClass a_cls, FloatClass b_cls,
                    bool aIsLargerSignificand, float_status *status)
 {
-#if defined(TARGET_ARM) || defined(TARGET_MIPS) || defined(TARGET_HPPA) || \
-    defined(TARGET_LOONGARCH64) || defined(TARGET_S390X)
-    /* ARM mandated NaN propagation rules (see FPProcessNaNs()), take
-     * the first of:
-     *  1. A if it is signaling
-     *  2. B if it is signaling
-     *  3. A (quiet)
-     *  4. B (quiet)
-     * A signaling NaN is always quietened before returning it.
-     */
-    /* According to MIPS specifications, if one of the two operands is
-     * a sNaN, a new qNaN has to be generated. This is done in
-     * floatXX_silence_nan(). For qNaN inputs the specifications
-     * says: "When possible, this QNaN result is one of the operand QNaN
-     * values." In practice it seems that most implementations choose
-     * the first operand if both operands are qNaN. In short this gives
-     * the following rules:
-     *  1. A if it is signaling
-     *  2. B if it is signaling
-     *  3. A (quiet)
-     *  4. B (quiet)
-     * A signaling NaN is always silenced before returning it.
-     */
-    if (is_snan(a_cls)) {
-        return 0;
-    } else if (is_snan(b_cls)) {
-        return 1;
-    } else if (is_qnan(a_cls)) {
-        return 0;
-    } else {
-        return 1;
-    }
-#elif defined(TARGET_PPC) || defined(TARGET_M68K)
-    /* PowerPC propagation rules:
-     *  1. A if it sNaN or qNaN
-     *  2. B if it sNaN or qNaN
-     * A signaling NaN is always silenced before returning it.
-     */
-    /* M68000 FAMILY PROGRAMMER'S REFERENCE MANUAL
-     * 3.4 FLOATING-POINT INSTRUCTION DETAILS
-     * If either operand, but not both operands, of an operation is a
-     * nonsignaling NaN, then that NaN is returned as the result. If both
-     * operands are nonsignaling NaNs, then the destination operand
-     * nonsignaling NaN is returned as the result.
-     * If either operand to an operation is a signaling NaN (SNaN), then the
-     * SNaN bit is set in the FPSR EXC byte. If the SNaN exception enable bit
-     * is set in the FPCR ENABLE byte, then the exception is taken and the
-     * destination is not modified. If the SNaN exception enable bit is not
-     * set, setting the SNaN bit in the operand to a one converts the SNaN to
-     * a nonsignaling NaN. The operation then continues as described in the
-     * preceding paragraph for nonsignaling NaNs.
-     */
-    if (is_nan(a_cls)) {
-        return 0;
-    } else {
-        return 1;
-    }
-#elif defined(TARGET_SPARC)
-    /* Prefer SNaN over QNaN, order B then A. */
-    if (is_snan(b_cls)) {
-        return 1;
-    } else if (is_snan(a_cls)) {
-        return 0;
-    } else if (is_qnan(b_cls)) {
-        return 1;
-    } else {
-        return 0;
-    }
-#elif defined(TARGET_XTENSA)
+    Float2NaNPropRule rule = status->float_2nan_prop_rule;
+
     /*
-     * Xtensa has two NaN propagation modes.
-     * Which one is active is controlled by float_status::use_first_nan.
+     * We guarantee not to require the target to tell us how to
+     * pick a NaN if we're always returning the default NaN.
      */
-    if (status->use_first_nan) {
+    assert(!status->default_nan_mode);
+
+    if (rule == float_2nan_prop_none) {
+        /* target didn't set the rule: fall back to old ifdef choices */
+#if defined(TARGET_AVR) || defined(TARGET_HEXAGON) \
+    || defined(TARGET_RISCV) || defined(TARGET_SH4) \
+    || defined(TARGET_TRICORE)
+        g_assert_not_reached();
+#elif defined(TARGET_ARM) || defined(TARGET_MIPS) || defined(TARGET_HPPA) || \
+    defined(TARGET_LOONGARCH64) || defined(TARGET_S390X)
+        /*
+         * ARM mandated NaN propagation rules (see FPProcessNaNs()), take
+         * the first of:
+         *  1. A if it is signaling
+         *  2. B if it is signaling
+         *  3. A (quiet)
+         *  4. B (quiet)
+         * A signaling NaN is always quietened before returning it.
+         */
+        /*
+         * According to MIPS specifications, if one of the two operands is
+         * a sNaN, a new qNaN has to be generated. This is done in
+         * floatXX_silence_nan(). For qNaN inputs the specifications
+         * says: "When possible, this QNaN result is one of the operand QNaN
+         * values." In practice it seems that most implementations choose
+         * the first operand if both operands are qNaN. In short this gives
+         * the following rules:
+         *  1. A if it is signaling
+         *  2. B if it is signaling
+         *  3. A (quiet)
+         *  4. B (quiet)
+         * A signaling NaN is always silenced before returning it.
+         */
+        rule = float_2nan_prop_s_ab;
+#elif defined(TARGET_PPC) || defined(TARGET_M68K)
+        /*
+         * PowerPC propagation rules:
+         *  1. A if it sNaN or qNaN
+         *  2. B if it sNaN or qNaN
+         * A signaling NaN is always silenced before returning it.
+         */
+        /*
+         * M68000 FAMILY PROGRAMMER'S REFERENCE MANUAL
+         * 3.4 FLOATING-POINT INSTRUCTION DETAILS
+         * If either operand, but not both operands, of an operation is a
+         * nonsignaling NaN, then that NaN is returned as the result. If both
+         * operands are nonsignaling NaNs, then the destination operand
+         * nonsignaling NaN is returned as the result.
+         * If either operand to an operation is a signaling NaN (SNaN), then the
+         * SNaN bit is set in the FPSR EXC byte. If the SNaN exception enable bit
+         * is set in the FPCR ENABLE byte, then the exception is taken and the
+         * destination is not modified. If the SNaN exception enable bit is not
+         * set, setting the SNaN bit in the operand to a one converts the SNaN to
+         * a nonsignaling NaN. The operation then continues as described in the
+         * preceding paragraph for nonsignaling NaNs.
+         */
+        rule = float_2nan_prop_ab;
+#elif defined(TARGET_SPARC)
+        /* Prefer SNaN over QNaN, order B then A. */
+        rule = float_2nan_prop_s_ba;
+#elif defined(TARGET_XTENSA)
+        /*
+         * Xtensa has two NaN propagation modes.
+         * Which one is active is controlled by float_status::use_first_nan.
+         */
+        if (status->use_first_nan) {
+            rule = float_2nan_prop_ab;
+        } else {
+            rule = float_2nan_prop_ba;
+        }
+#else
+        rule = float_2nan_prop_x87;
+#endif
+    }
+
+    switch (rule) {
+    case float_2nan_prop_s_ab:
+        if (is_snan(a_cls)) {
+            return 0;
+        } else if (is_snan(b_cls)) {
+            return 1;
+        } else if (is_qnan(a_cls)) {
+            return 0;
+        } else {
+            return 1;
+        }
+        break;
+    case float_2nan_prop_s_ba:
+        if (is_snan(b_cls)) {
+            return 1;
+        } else if (is_snan(a_cls)) {
+            return 0;
+        } else if (is_qnan(b_cls)) {
+            return 1;
+        } else {
+            return 0;
+        }
+        break;
+    case float_2nan_prop_ab:
         if (is_nan(a_cls)) {
             return 0;
         } else {
             return 1;
         }
-    } else {
+        break;
+    case float_2nan_prop_ba:
         if (is_nan(b_cls)) {
             return 1;
         } else {
             return 0;
         }
-    }
-#else
-    /* This implements x87 NaN propagation rules:
-     * SNaN + QNaN => return the QNaN
-     * two SNaNs => return the one with the larger significand, silenced
-     * two QNaNs => return the one with the larger significand
-     * SNaN and a non-NaN => return the SNaN, silenced
-     * QNaN and a non-NaN => return the QNaN
-     *
-     * If we get down to comparing significands and they are the same,
-     * return the NaN with the positive sign bit (if any).
-     */
-    if (is_snan(a_cls)) {
-        if (is_snan(b_cls)) {
-            return aIsLargerSignificand ? 0 : 1;
-        }
-        return is_qnan(b_cls) ? 1 : 0;
-    } else if (is_qnan(a_cls)) {
-        if (is_snan(b_cls) || !is_qnan(b_cls)) {
-            return 0;
+        break;
+    case float_2nan_prop_x87:
+        /*
+         * This implements x87 NaN propagation rules:
+         * SNaN + QNaN => return the QNaN
+         * two SNaNs => return the one with the larger significand, silenced
+         * two QNaNs => return the one with the larger significand
+         * SNaN and a non-NaN => return the SNaN, silenced
+         * QNaN and a non-NaN => return the QNaN
+         *
+         * If we get down to comparing significands and they are the same,
+         * return the NaN with the positive sign bit (if any).
+         */
+        if (is_snan(a_cls)) {
+            if (is_snan(b_cls)) {
+                return aIsLargerSignificand ? 0 : 1;
+            }
+            return is_qnan(b_cls) ? 1 : 0;
+        } else if (is_qnan(a_cls)) {
+            if (is_snan(b_cls) || !is_qnan(b_cls)) {
+                return 0;
+            } else {
+                return aIsLargerSignificand ? 0 : 1;
+            }
         } else {
-            return aIsLargerSignificand ? 0 : 1;
+            return 1;
         }
-    } else {
-        return 1;
+    default:
+        g_assert_not_reached();
     }
-#endif
 }
 
 /*----------------------------------------------------------------------------
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 02/21] tests/fp: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
  2024-10-25 14:12 ` [PATCH 01/21] softfloat: Allow 2-operand NaN propagation rule to be set at runtime Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-25 19:27   ` Philippe Mathieu-Daudé
  2024-10-28 12:07   ` Richard Henderson
  2024-10-25 14:12 ` [PATCH 03/21] target/arm: " Peter Maydell
                   ` (19 subsequent siblings)
  21 siblings, 2 replies; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

Explicitly set a 2-NaN propagation rule in the softfloat tests.  In
meson.build we put -DTARGET_ARM in fpcflags, and so we should select
here the Arm propagation rule of float_2nan_prop_s_ab.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 tests/fp/fp-bench.c     | 2 ++
 tests/fp/fp-test-log2.c | 1 +
 tests/fp/fp-test.c      | 2 ++
 3 files changed, 5 insertions(+)

diff --git a/tests/fp/fp-bench.c b/tests/fp/fp-bench.c
index 8ce0ca1545d..75c07d5d1f1 100644
--- a/tests/fp/fp-bench.c
+++ b/tests/fp/fp-bench.c
@@ -488,6 +488,8 @@ static void run_bench(void)
 {
     bench_func_t f;
 
+    set_float_2nan_prop_rule(float_2nan_prop_s_ab, &soft_status);
+
     f = bench_funcs[operation][precision];
     g_assert(f);
     f();
diff --git a/tests/fp/fp-test-log2.c b/tests/fp/fp-test-log2.c
index 4eae93eb7cc..de702c4c80d 100644
--- a/tests/fp/fp-test-log2.c
+++ b/tests/fp/fp-test-log2.c
@@ -70,6 +70,7 @@ int main(int ac, char **av)
     float_status qsf = {0};
     int i;
 
+    set_float_2nan_prop_rule(float_2nan_prop_s_ab, &qsf);
     set_float_rounding_mode(float_round_nearest_even, &qsf);
 
     test.d = 0.0;
diff --git a/tests/fp/fp-test.c b/tests/fp/fp-test.c
index 36b5712cda0..5f6f25c8821 100644
--- a/tests/fp/fp-test.c
+++ b/tests/fp/fp-test.c
@@ -935,6 +935,8 @@ void run_test(void)
 {
     unsigned int i;
 
+    set_float_2nan_prop_rule(float_2nan_prop_s_ab, &qsf);
+
     genCases_setLevel(test_level);
     verCases_maxErrorCount = n_max_errors;
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 03/21] target/arm: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
  2024-10-25 14:12 ` [PATCH 01/21] softfloat: Allow 2-operand NaN propagation rule to be set at runtime Peter Maydell
  2024-10-25 14:12 ` [PATCH 02/21] tests/fp: Explicitly set 2-NaN propagation rule Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-28 12:10   ` Richard Henderson
  2024-10-25 14:12 ` [PATCH 04/21] target/mips: " Peter Maydell
                   ` (18 subsequent siblings)
  21 siblings, 1 reply; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

Set the 2-NaN propagation rule explicitly in the float_status words
we use.  We wrap this plus the pre-existing setting of the
tininess-before-rounding flag in a new function
arm_set_default_fp_behaviours() to avoid repetition, since we have a
lot of float_status words at this point.

The situation with FPA11 emulation in linux-user is a little odd, and
arguably "correct" behaviour there would be to exactly match a real
Linux kernel's FPA11 emulation.  However FPA11 emulation is
essentially dead at this point and so it seems better to continue
with QEMU's current behaviour and leave a comment describing the
situation.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 linux-user/arm/nwfpe/fpa11.c   | 18 ++++++++++++++++++
 target/arm/cpu.c               | 25 +++++++++++++++++--------
 fpu/softfloat-specialize.c.inc | 13 ++-----------
 3 files changed, 37 insertions(+), 19 deletions(-)

diff --git a/linux-user/arm/nwfpe/fpa11.c b/linux-user/arm/nwfpe/fpa11.c
index 9a93610d245..8356beb52c6 100644
--- a/linux-user/arm/nwfpe/fpa11.c
+++ b/linux-user/arm/nwfpe/fpa11.c
@@ -51,6 +51,24 @@ void resetFPA11(void)
 #ifdef MAINTAIN_FPCR
   fpa11->fpcr = MASK_RESET;
 #endif
+
+  /*
+   * Real FPA11 hardware does not handle NaNs, but always takes an
+   * exception for them to be software-emulated (ARM7500FE datasheet
+   * section 10.4). There is no documented architectural requirement
+   * for NaN propagation rules and it will depend on how the OS
+   * level software emulation opted to do it. We here use prop_s_ab
+   * which matches the later VFP hardware choice and how QEMU's
+   * fpa11 emulation has worked in the past. The real Linux kernel
+   * does something slightly different: arch/arm/nwfpe/softfloat-specialize
+   * propagateFloat64NaN() has the curious behaviour that it prefers
+   * the QNaN over the SNaN, but if both are QNaN it picks A and
+   * if both are SNaN it picks B. In theory we could add this as
+   * a NaN propagation rule, but in practice FPA11 emulation is so
+   * close to totally dead that it's not worth trying to match it at
+   * this late date.
+   */
+  set_float_2nan_prop_rule(float_2nan_prop_s_ab, &fpa11->fp_status);
 }
 
 void SetRoundingMode(const unsigned int opcode)
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 1320fd8c8fe..2fd286972a9 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -168,6 +168,18 @@ void arm_register_el_change_hook(ARMCPU *cpu, ARMELChangeHookFn *hook,
     QLIST_INSERT_HEAD(&cpu->el_change_hooks, entry, node);
 }
 
+/*
+ * Set the float_status behaviour to match the Arm defaults:
+ *  * tininess-before-rounding
+ *  * 2-input NaN propagation prefers SNaN over QNaN, and then
+ *    operand A over operand B (see FPProcessNaNs() pseudocode)
+ */
+static void arm_set_default_fp_behaviours(float_status *s)
+{
+    set_float_detect_tininess(float_tininess_before_rounding, s);
+    set_float_2nan_prop_rule(float_2nan_prop_s_ab, s);
+}
+
 static void cp_reg_reset(gpointer key, gpointer value, gpointer opaque)
 {
     /* Reset a single ARMCPRegInfo register */
@@ -549,14 +561,11 @@ static void arm_cpu_reset_hold(Object *obj, ResetType type)
     set_flush_inputs_to_zero(1, &env->vfp.standard_fp_status);
     set_default_nan_mode(1, &env->vfp.standard_fp_status);
     set_default_nan_mode(1, &env->vfp.standard_fp_status_f16);
-    set_float_detect_tininess(float_tininess_before_rounding,
-                              &env->vfp.fp_status);
-    set_float_detect_tininess(float_tininess_before_rounding,
-                              &env->vfp.standard_fp_status);
-    set_float_detect_tininess(float_tininess_before_rounding,
-                              &env->vfp.fp_status_f16);
-    set_float_detect_tininess(float_tininess_before_rounding,
-                              &env->vfp.standard_fp_status_f16);
+    arm_set_default_fp_behaviours(&env->vfp.fp_status);
+    arm_set_default_fp_behaviours(&env->vfp.standard_fp_status);
+    arm_set_default_fp_behaviours(&env->vfp.fp_status_f16);
+    arm_set_default_fp_behaviours(&env->vfp.standard_fp_status_f16);
+
 #ifndef CONFIG_USER_ONLY
     if (kvm_enabled()) {
         kvm_arm_reset_vcpu(cpu);
diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
index fae6794a152..70cd3628b54 100644
--- a/fpu/softfloat-specialize.c.inc
+++ b/fpu/softfloat-specialize.c.inc
@@ -402,19 +402,10 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls,
         /* target didn't set the rule: fall back to old ifdef choices */
 #if defined(TARGET_AVR) || defined(TARGET_HEXAGON) \
     || defined(TARGET_RISCV) || defined(TARGET_SH4) \
-    || defined(TARGET_TRICORE)
+    || defined(TARGET_TRICORE) || defined(TARGET_ARM)
         g_assert_not_reached();
-#elif defined(TARGET_ARM) || defined(TARGET_MIPS) || defined(TARGET_HPPA) || \
+#elif defined(TARGET_MIPS) || defined(TARGET_HPPA) || \
     defined(TARGET_LOONGARCH64) || defined(TARGET_S390X)
-        /*
-         * ARM mandated NaN propagation rules (see FPProcessNaNs()), take
-         * the first of:
-         *  1. A if it is signaling
-         *  2. B if it is signaling
-         *  3. A (quiet)
-         *  4. B (quiet)
-         * A signaling NaN is always quietened before returning it.
-         */
         /*
          * According to MIPS specifications, if one of the two operands is
          * a sNaN, a new qNaN has to be generated. This is done in
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 04/21] target/mips: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
                   ` (2 preceding siblings ...)
  2024-10-25 14:12 ` [PATCH 03/21] target/arm: " Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-25 19:46   ` Philippe Mathieu-Daudé
  2024-10-25 14:12 ` [PATCH 05/21] target/loongarch: " Peter Maydell
                   ` (17 subsequent siblings)
  21 siblings, 1 reply; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

Set the 2-NaN propagation rule explicitly in the float_status words
we use.

For active_fpu.fp_status, we do this in a new fp_reset() function
which mirrors the existing msa_reset() function in doing "first call
restore to set the fp status parts that depend on CPU state, then set
the fp status parts that are constant".

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/mips/fpu_helper.h       | 22 ++++++++++++++++++++++
 target/mips/cpu.c              |  2 +-
 target/mips/msa.c              | 17 +++++++++++++++++
 fpu/softfloat-specialize.c.inc | 18 ++----------------
 4 files changed, 42 insertions(+), 17 deletions(-)

diff --git a/target/mips/fpu_helper.h b/target/mips/fpu_helper.h
index ad1116e8c10..7c3c7897b45 100644
--- a/target/mips/fpu_helper.h
+++ b/target/mips/fpu_helper.h
@@ -44,6 +44,28 @@ static inline void restore_fp_status(CPUMIPSState *env)
     restore_snan_bit_mode(env);
 }
 
+static inline void fp_reset(CPUMIPSState *env)
+{
+    restore_fp_status(env);
+
+    /*
+     * According to MIPS specifications, if one of the two operands is
+     * a sNaN, a new qNaN has to be generated. This is done in
+     * floatXX_silence_nan(). For qNaN inputs the specifications
+     * says: "When possible, this QNaN result is one of the operand QNaN
+     * values." In practice it seems that most implementations choose
+     * the first operand if both operands are qNaN. In short this gives
+     * the following rules:
+     *  1. A if it is signaling
+     *  2. B if it is signaling
+     *  3. A (quiet)
+     *  4. B (quiet)
+     * A signaling NaN is always silenced before returning it.
+     */
+    set_float_2nan_prop_rule(float_2nan_prop_s_ab,
+                             &env->active_fpu.fp_status);
+}
+
 /* MSA */
 
 enum CPUMIPSMSADataFormat {
diff --git a/target/mips/cpu.c b/target/mips/cpu.c
index 9724e71a5e0..d0a43b6d5c7 100644
--- a/target/mips/cpu.c
+++ b/target/mips/cpu.c
@@ -407,9 +407,9 @@ static void mips_cpu_reset_hold(Object *obj, ResetType type)
     }
 
     msa_reset(env);
+    fp_reset(env);
 
     compute_hflags(env);
-    restore_fp_status(env);
     restore_pamask(env);
     cs->exception_index = EXCP_NONE;
 
diff --git a/target/mips/msa.c b/target/mips/msa.c
index 61f1a9a5936..9dffc428f5c 100644
--- a/target/mips/msa.c
+++ b/target/mips/msa.c
@@ -49,6 +49,23 @@ void msa_reset(CPUMIPSState *env)
     set_float_detect_tininess(float_tininess_after_rounding,
                               &env->active_tc.msa_fp_status);
 
+    /*
+     * According to MIPS specifications, if one of the two operands is
+     * a sNaN, a new qNaN has to be generated. This is done in
+     * floatXX_silence_nan(). For qNaN inputs the specifications
+     * says: "When possible, this QNaN result is one of the operand QNaN
+     * values." In practice it seems that most implementations choose
+     * the first operand if both operands are qNaN. In short this gives
+     * the following rules:
+     *  1. A if it is signaling
+     *  2. B if it is signaling
+     *  3. A (quiet)
+     *  4. B (quiet)
+     * A signaling NaN is always silenced before returning it.
+     */
+    set_float_2nan_prop_rule(float_2nan_prop_s_ab,
+                             &env->active_tc.msa_fp_status);
+
     /* clear float_status exception flags */
     set_float_exception_flags(0, &env->active_tc.msa_fp_status);
 
diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
index 70cd3628b54..c60b999aa3d 100644
--- a/fpu/softfloat-specialize.c.inc
+++ b/fpu/softfloat-specialize.c.inc
@@ -402,24 +402,10 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls,
         /* target didn't set the rule: fall back to old ifdef choices */
 #if defined(TARGET_AVR) || defined(TARGET_HEXAGON) \
     || defined(TARGET_RISCV) || defined(TARGET_SH4) \
-    || defined(TARGET_TRICORE) || defined(TARGET_ARM)
+    || defined(TARGET_TRICORE) || defined(TARGET_ARM) || defined(TARGET_MIPS)
         g_assert_not_reached();
-#elif defined(TARGET_MIPS) || defined(TARGET_HPPA) || \
+#elif defined(TARGET_HPPA) || \
     defined(TARGET_LOONGARCH64) || defined(TARGET_S390X)
-        /*
-         * According to MIPS specifications, if one of the two operands is
-         * a sNaN, a new qNaN has to be generated. This is done in
-         * floatXX_silence_nan(). For qNaN inputs the specifications
-         * says: "When possible, this QNaN result is one of the operand QNaN
-         * values." In practice it seems that most implementations choose
-         * the first operand if both operands are qNaN. In short this gives
-         * the following rules:
-         *  1. A if it is signaling
-         *  2. B if it is signaling
-         *  3. A (quiet)
-         *  4. B (quiet)
-         * A signaling NaN is always silenced before returning it.
-         */
         rule = float_2nan_prop_s_ab;
 #elif defined(TARGET_PPC) || defined(TARGET_M68K)
         /*
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 05/21] target/loongarch: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
                   ` (3 preceding siblings ...)
  2024-10-25 14:12 ` [PATCH 04/21] target/mips: " Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-28 12:13   ` Richard Henderson
  2024-10-25 14:12 ` [PATCH 06/21] target/hppa: " Peter Maydell
                   ` (16 subsequent siblings)
  21 siblings, 1 reply; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

Set the 2-NaN propagation rule explicitly in the float_status word we
use.

(There are a couple of places in fpu_helper.c where we create a
dummy float_status word with "float_status *s = { };", but these
are only used for calling float*_is_quiet_nan() so it doesn't
matter that we don't set a 2-NaN propagation rule there.)

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/loongarch/tcg/fpu_helper.c | 1 +
 fpu/softfloat-specialize.c.inc    | 6 +++---
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/target/loongarch/tcg/fpu_helper.c b/target/loongarch/tcg/fpu_helper.c
index f6753c5875b..21bc3b04a96 100644
--- a/target/loongarch/tcg/fpu_helper.c
+++ b/target/loongarch/tcg/fpu_helper.c
@@ -31,6 +31,7 @@ void restore_fp_status(CPULoongArchState *env)
     set_float_rounding_mode(ieee_rm[(env->fcsr0 >> FCSR0_RM) & 0x3],
                             &env->fp_status);
     set_flush_to_zero(0, &env->fp_status);
+    set_float_2nan_prop_rule(float_2nan_prop_s_ab, &env->fp_status);
 }
 
 int ieee_ex_to_loongarch(int xcpt)
diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
index c60b999aa3d..bbc3b70fa9d 100644
--- a/fpu/softfloat-specialize.c.inc
+++ b/fpu/softfloat-specialize.c.inc
@@ -402,10 +402,10 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls,
         /* target didn't set the rule: fall back to old ifdef choices */
 #if defined(TARGET_AVR) || defined(TARGET_HEXAGON) \
     || defined(TARGET_RISCV) || defined(TARGET_SH4) \
-    || defined(TARGET_TRICORE) || defined(TARGET_ARM) || defined(TARGET_MIPS)
+    || defined(TARGET_TRICORE) || defined(TARGET_ARM) || defined(TARGET_MIPS) \
+    || defined(TARGET_LOONGARCH64)
         g_assert_not_reached();
-#elif defined(TARGET_HPPA) || \
-    defined(TARGET_LOONGARCH64) || defined(TARGET_S390X)
+#elif defined(TARGET_HPPA) || defined(TARGET_S390X)
         rule = float_2nan_prop_s_ab;
 #elif defined(TARGET_PPC) || defined(TARGET_M68K)
         /*
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 06/21] target/hppa: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
                   ` (4 preceding siblings ...)
  2024-10-25 14:12 ` [PATCH 05/21] target/loongarch: " Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-28 12:14   ` Richard Henderson
  2024-10-25 14:12 ` [PATCH 07/21] target/s390x: " Peter Maydell
                   ` (15 subsequent siblings)
  21 siblings, 1 reply; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

Set the 2-NaN propagation rule explicitly in env->fp_status.

Really we only need to do this at CPU reset (after reset has zeroed
out most of the CPU state struct, which typically includes fp_status
fields).  However target/hppa does not currently implement CPU reset
at all, so leave a TODO comment to note that this could be moved if
we ever do implement reset.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/hppa/fpu_helper.c       | 6 ++++++
 fpu/softfloat-specialize.c.inc | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/target/hppa/fpu_helper.c b/target/hppa/fpu_helper.c
index deaed2b65d1..0e44074ba82 100644
--- a/target/hppa/fpu_helper.c
+++ b/target/hppa/fpu_helper.c
@@ -49,6 +49,12 @@ void HELPER(loaded_fr0)(CPUHPPAState *env)
     d = FIELD_EX32(shadow, FPSR, D);
     set_flush_to_zero(d, &env->fp_status);
     set_flush_inputs_to_zero(d, &env->fp_status);
+
+    /*
+     * TODO: we only need to do this at CPU reset, but currently
+     * HPPA does note implement a CPU reset method at all...
+     */
+    set_float_2nan_prop_rule(float_2nan_prop_s_ab, &env->fp_status);
 }
 
 void cpu_hppa_loaded_fr0(CPUHPPAState *env)
diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
index bbc3b70fa9d..4e51cf8d083 100644
--- a/fpu/softfloat-specialize.c.inc
+++ b/fpu/softfloat-specialize.c.inc
@@ -403,9 +403,9 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls,
 #if defined(TARGET_AVR) || defined(TARGET_HEXAGON) \
     || defined(TARGET_RISCV) || defined(TARGET_SH4) \
     || defined(TARGET_TRICORE) || defined(TARGET_ARM) || defined(TARGET_MIPS) \
-    || defined(TARGET_LOONGARCH64)
+    || defined(TARGET_LOONGARCH64) || defined(TARGET_HPPA)
         g_assert_not_reached();
-#elif defined(TARGET_HPPA) || defined(TARGET_S390X)
+#elif defined(TARGET_S390X)
         rule = float_2nan_prop_s_ab;
 #elif defined(TARGET_PPC) || defined(TARGET_M68K)
         /*
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 07/21] target/s390x: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
                   ` (5 preceding siblings ...)
  2024-10-25 14:12 ` [PATCH 06/21] target/hppa: " Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-25 17:45   ` Ilya Leoshkevich
                     ` (2 more replies)
  2024-10-25 14:12 ` [PATCH 08/21] target/ppc: " Peter Maydell
                   ` (14 subsequent siblings)
  21 siblings, 3 replies; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

Set the 2-NaN propagation rule explicitly in env->fpu_status.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/s390x/cpu.c             | 1 +
 fpu/softfloat-specialize.c.inc | 5 ++---
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c
index 4e41a3dff59..514c70f3010 100644
--- a/target/s390x/cpu.c
+++ b/target/s390x/cpu.c
@@ -205,6 +205,7 @@ static void s390_cpu_reset_hold(Object *obj, ResetType type)
         /* tininess for underflow is detected before rounding */
         set_float_detect_tininess(float_tininess_before_rounding,
                                   &env->fpu_status);
+        set_float_2nan_prop_rule(float_2nan_prop_s_ab, &env->fpu_status);
        /* fall through */
     case RESET_TYPE_S390_CPU_NORMAL:
         env->psw.mask &= ~PSW_MASK_RI;
diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
index 4e51cf8d083..a0c740e544d 100644
--- a/fpu/softfloat-specialize.c.inc
+++ b/fpu/softfloat-specialize.c.inc
@@ -403,10 +403,9 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls,
 #if defined(TARGET_AVR) || defined(TARGET_HEXAGON) \
     || defined(TARGET_RISCV) || defined(TARGET_SH4) \
     || defined(TARGET_TRICORE) || defined(TARGET_ARM) || defined(TARGET_MIPS) \
-    || defined(TARGET_LOONGARCH64) || defined(TARGET_HPPA)
+    || defined(TARGET_LOONGARCH64) || defined(TARGET_HPPA) \
+    || defined(TARGET_S390X)
         g_assert_not_reached();
-#elif defined(TARGET_S390X)
-        rule = float_2nan_prop_s_ab;
 #elif defined(TARGET_PPC) || defined(TARGET_M68K)
         /*
          * PowerPC propagation rules:
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 08/21] target/ppc: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
                   ` (6 preceding siblings ...)
  2024-10-25 14:12 ` [PATCH 07/21] target/s390x: " Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-28 12:16   ` Richard Henderson
  2024-10-25 14:12 ` [PATCH 09/21] target/m68k: " Peter Maydell
                   ` (13 subsequent siblings)
  21 siblings, 1 reply; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

Set the 2-NaN propagation rule explicitly in env->fp_status
and env->vec_status.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
As an aside, it looks a bit suspicious that we set
tininess_before_rounding on fp_status but not vec_status...
---
 target/ppc/cpu_init.c          |  8 ++++++++
 fpu/softfloat-specialize.c.inc | 10 ++--------
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
index 23881d09e9f..5c9dcd1f857 100644
--- a/target/ppc/cpu_init.c
+++ b/target/ppc/cpu_init.c
@@ -7326,6 +7326,14 @@ static void ppc_cpu_reset_hold(Object *obj, ResetType type)
     /* tininess for underflow is detected before rounding */
     set_float_detect_tininess(float_tininess_before_rounding,
                               &env->fp_status);
+    /*
+     * PowerPC propagation rules:
+     *  1. A if it sNaN or qNaN
+     *  2. B if it sNaN or qNaN
+     * A signaling NaN is always silenced before returning it.
+     */
+    set_float_2nan_prop_rule(float_2nan_prop_ab, &env->fp_status);
+    set_float_2nan_prop_rule(float_2nan_prop_ab, &env->vec_status);
 
     for (i = 0; i < ARRAY_SIZE(env->spr_cb); i++) {
         ppc_spr_t *spr = &env->spr_cb[i];
diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
index a0c740e544d..8e3124c11a6 100644
--- a/fpu/softfloat-specialize.c.inc
+++ b/fpu/softfloat-specialize.c.inc
@@ -404,15 +404,9 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls,
     || defined(TARGET_RISCV) || defined(TARGET_SH4) \
     || defined(TARGET_TRICORE) || defined(TARGET_ARM) || defined(TARGET_MIPS) \
     || defined(TARGET_LOONGARCH64) || defined(TARGET_HPPA) \
-    || defined(TARGET_S390X)
+    || defined(TARGET_S390X) || defined(TARGET_PPC)
         g_assert_not_reached();
-#elif defined(TARGET_PPC) || defined(TARGET_M68K)
-        /*
-         * PowerPC propagation rules:
-         *  1. A if it sNaN or qNaN
-         *  2. B if it sNaN or qNaN
-         * A signaling NaN is always silenced before returning it.
-         */
+#elif defined(TARGET_M68K)
         /*
          * M68000 FAMILY PROGRAMMER'S REFERENCE MANUAL
          * 3.4 FLOATING-POINT INSTRUCTION DETAILS
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 09/21] target/m68k: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
                   ` (7 preceding siblings ...)
  2024-10-25 14:12 ` [PATCH 08/21] target/ppc: " Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-26  4:36   ` Philippe Mathieu-Daudé
                     ` (2 more replies)
  2024-10-25 14:12 ` [PATCH 10/21] target/m68k: Initialize float_status fields in gdb set/get functions Peter Maydell
                   ` (12 subsequent siblings)
  21 siblings, 3 replies; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

Explicitly set the 2-NaN propagation rule on env->fp_status
and on the temporary fp_status that we use in frem (since
we pass that to a division operation function).
---
 target/m68k/cpu.c              | 16 ++++++++++++++++
 target/m68k/fpu_helper.c       |  1 +
 fpu/softfloat-specialize.c.inc | 19 +------------------
 3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
index 1d49f4cb238..5fe335558aa 100644
--- a/target/m68k/cpu.c
+++ b/target/m68k/cpu.c
@@ -93,6 +93,22 @@ static void m68k_cpu_reset_hold(Object *obj, ResetType type)
         env->fregs[i].d = nan;
     }
     cpu_m68k_set_fpcr(env, 0);
+    /*
+     * M68000 FAMILY PROGRAMMER'S REFERENCE MANUAL
+     * 3.4 FLOATING-POINT INSTRUCTION DETAILS
+     * If either operand, but not both operands, of an operation is a
+     * nonsignaling NaN, then that NaN is returned as the result. If both
+     * operands are nonsignaling NaNs, then the destination operand
+     * nonsignaling NaN is returned as the result.
+     * If either operand to an operation is a signaling NaN (SNaN), then the
+     * SNaN bit is set in the FPSR EXC byte. If the SNaN exception enable bit
+     * is set in the FPCR ENABLE byte, then the exception is taken and the
+     * destination is not modified. If the SNaN exception enable bit is not
+     * set, setting the SNaN bit in the operand to a one converts the SNaN to
+     * a nonsignaling NaN. The operation then continues as described in the
+     * preceding paragraph for nonsignaling NaNs.
+     */
+    set_float_2nan_prop_rule(float_2nan_prop_ab, &env->fp_status);
     env->fpsr = 0;
 
     /* TODO: We should set PC from the interrupt vector.  */
diff --git a/target/m68k/fpu_helper.c b/target/m68k/fpu_helper.c
index 8314791f504..a605162b71f 100644
--- a/target/m68k/fpu_helper.c
+++ b/target/m68k/fpu_helper.c
@@ -620,6 +620,7 @@ void HELPER(frem)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
         int sign;
 
         /* Calculate quotient directly using round to nearest mode */
+        set_float_2nan_prop_rule(float_2nan_prop_ab, &fp_status);
         set_float_rounding_mode(float_round_nearest_even, &fp_status);
         set_floatx80_rounding_precision(
             get_floatx80_rounding_precision(&env->fp_status), &fp_status);
diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
index 8e3124c11a6..226632a4d10 100644
--- a/fpu/softfloat-specialize.c.inc
+++ b/fpu/softfloat-specialize.c.inc
@@ -404,25 +404,8 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls,
     || defined(TARGET_RISCV) || defined(TARGET_SH4) \
     || defined(TARGET_TRICORE) || defined(TARGET_ARM) || defined(TARGET_MIPS) \
     || defined(TARGET_LOONGARCH64) || defined(TARGET_HPPA) \
-    || defined(TARGET_S390X) || defined(TARGET_PPC)
+    || defined(TARGET_S390X) || defined(TARGET_PPC) || defined(TARGET_M68K)
         g_assert_not_reached();
-#elif defined(TARGET_M68K)
-        /*
-         * M68000 FAMILY PROGRAMMER'S REFERENCE MANUAL
-         * 3.4 FLOATING-POINT INSTRUCTION DETAILS
-         * If either operand, but not both operands, of an operation is a
-         * nonsignaling NaN, then that NaN is returned as the result. If both
-         * operands are nonsignaling NaNs, then the destination operand
-         * nonsignaling NaN is returned as the result.
-         * If either operand to an operation is a signaling NaN (SNaN), then the
-         * SNaN bit is set in the FPSR EXC byte. If the SNaN exception enable bit
-         * is set in the FPCR ENABLE byte, then the exception is taken and the
-         * destination is not modified. If the SNaN exception enable bit is not
-         * set, setting the SNaN bit in the operand to a one converts the SNaN to
-         * a nonsignaling NaN. The operation then continues as described in the
-         * preceding paragraph for nonsignaling NaNs.
-         */
-        rule = float_2nan_prop_ab;
 #elif defined(TARGET_SPARC)
         /* Prefer SNaN over QNaN, order B then A. */
         rule = float_2nan_prop_s_ba;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 10/21] target/m68k: Initialize float_status fields in gdb set/get functions
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
                   ` (8 preceding siblings ...)
  2024-10-25 14:12 ` [PATCH 09/21] target/m68k: " Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-26  4:35   ` Philippe Mathieu-Daudé
  2024-10-28 12:19   ` Richard Henderson
  2024-10-25 14:12 ` [PATCH 11/21] target/sparc: Move cpu_put_fsr(env, 0) call to reset Peter Maydell
                   ` (11 subsequent siblings)
  21 siblings, 2 replies; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

In cf_fpu_gdb_get_reg() and cf_fpu_gdb_set_reg() we use a temporary
float_status variable to pass to floatx80_to_float64() and
float64_to_floatx80(), but we don't initialize it, meaning that those
functions could access uninitialized data.  Zero-init the structs.

(We don't need to set a NaN-propagation rule here because we
don't use these with a 2-argument fpu operation.)

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
Spotted by code-inspection while I was doing the 2-NaN propagation
patches.
---
 target/m68k/helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/m68k/helper.c b/target/m68k/helper.c
index 9d3db8419de..9bfc6ae97c0 100644
--- a/target/m68k/helper.c
+++ b/target/m68k/helper.c
@@ -36,7 +36,7 @@ static int cf_fpu_gdb_get_reg(CPUState *cs, GByteArray *mem_buf, int n)
     CPUM68KState *env = &cpu->env;
 
     if (n < 8) {
-        float_status s;
+        float_status s = {};
         return gdb_get_reg64(mem_buf, floatx80_to_float64(env->fregs[n].d, &s));
     }
     switch (n) {
@@ -56,7 +56,7 @@ static int cf_fpu_gdb_set_reg(CPUState *cs, uint8_t *mem_buf, int n)
     CPUM68KState *env = &cpu->env;
 
     if (n < 8) {
-        float_status s;
+        float_status s = {};
         env->fregs[n].d = float64_to_floatx80(ldq_be_p(mem_buf), &s);
         return 8;
     }
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 11/21] target/sparc: Move cpu_put_fsr(env, 0) call to reset
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
                   ` (9 preceding siblings ...)
  2024-10-25 14:12 ` [PATCH 10/21] target/m68k: Initialize float_status fields in gdb set/get functions Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-26  4:32   ` Philippe Mathieu-Daudé
                     ` (2 more replies)
  2024-10-25 14:12 ` [PATCH 12/21] target/sparc: Explicitly set 2-NaN propagation rule Peter Maydell
                   ` (10 subsequent siblings)
  21 siblings, 3 replies; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

Currently we call cpu_put_fsr(0) in sparc_cpu_realizefn(), which
initializes various fields in the CPU struct:
 * fsr_cexc_ftt
 * fcc[]
 * fsr_qne
 * fsr
It also sets the rounding mode in env->fp_status.

This is largely pointless, because when we later reset the CPU
this will zero out all the fields up until the "end_reset_fields"
label, which includes all of these (but not fp_status!)

Move the cpu_put_fsr(env, 0) call to reset, because that expresses
the logical requirement: we want to reset FSR to 0 on every reset.
This isn't a behaviour change because the fields are all zero anyway.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/sparc/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
index 54cb269e0af..e7f4068a162 100644
--- a/target/sparc/cpu.c
+++ b/target/sparc/cpu.c
@@ -76,6 +76,7 @@ static void sparc_cpu_reset_hold(Object *obj, ResetType type)
     env->npc = env->pc + 4;
 #endif
     env->cache_control = 0;
+    cpu_put_fsr(env, 0);
 }
 
 #ifndef CONFIG_USER_ONLY
@@ -805,7 +806,6 @@ static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)
     env->version |= env->def.maxtl << 8;
     env->version |= env->def.nwindows - 1;
 #endif
-    cpu_put_fsr(env, 0);
 
     cpu_exec_realizefn(cs, &local_err);
     if (local_err != NULL) {
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 12/21] target/sparc: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
                   ` (10 preceding siblings ...)
  2024-10-25 14:12 ` [PATCH 11/21] target/sparc: Move cpu_put_fsr(env, 0) call to reset Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-26 20:03   ` Mark Cave-Ayland
  2024-10-28 12:20   ` Richard Henderson
  2024-10-25 14:12 ` [PATCH 13/21] target/xtensa: Factor out calls to set_use_first_nan() Peter Maydell
                   ` (9 subsequent siblings)
  21 siblings, 2 replies; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

Set the NaN propagation rule explicitly in the float_status
words we use.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/sparc/cpu.c             |  8 ++++++++
 target/sparc/fop_helper.c      | 10 ++++++++--
 fpu/softfloat-specialize.c.inc |  6 ++----
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
index e7f4068a162..dd7af86de73 100644
--- a/target/sparc/cpu.c
+++ b/target/sparc/cpu.c
@@ -26,6 +26,7 @@
 #include "hw/qdev-properties.h"
 #include "qapi/visitor.h"
 #include "tcg/tcg.h"
+#include "fpu/softfloat.h"
 
 //#define DEBUG_FEATURES
 
@@ -807,6 +808,13 @@ static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)
     env->version |= env->def.nwindows - 1;
 #endif
 
+    /*
+     * Prefer SNaN over QNaN, order B then A. It's OK to do this in realize
+     * rather than reset, because fp_status is after 'end_reset_fields' in
+     * the CPU state struct so it won't get zeroed on reset.
+     */
+    set_float_2nan_prop_rule(float_2nan_prop_s_ba, &env->fp_status);
+
     cpu_exec_realizefn(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
diff --git a/target/sparc/fop_helper.c b/target/sparc/fop_helper.c
index b6692382b3b..6f9ccc008a0 100644
--- a/target/sparc/fop_helper.c
+++ b/target/sparc/fop_helper.c
@@ -497,7 +497,10 @@ uint32_t helper_flcmps(float32 src1, float32 src2)
      * Perform the comparison with a dummy fp environment.
      */
     float_status discard = { };
-    FloatRelation r = float32_compare_quiet(src1, src2, &discard);
+    FloatRelation r;
+
+    set_float_2nan_prop_rule(float_2nan_prop_s_ba, &discard);
+    r = float32_compare_quiet(src1, src2, &discard);
 
     switch (r) {
     case float_relation_equal:
@@ -518,7 +521,10 @@ uint32_t helper_flcmps(float32 src1, float32 src2)
 uint32_t helper_flcmpd(float64 src1, float64 src2)
 {
     float_status discard = { };
-    FloatRelation r = float64_compare_quiet(src1, src2, &discard);
+    FloatRelation r;
+
+    set_float_2nan_prop_rule(float_2nan_prop_s_ba, &discard);
+    r = float64_compare_quiet(src1, src2, &discard);
 
     switch (r) {
     case float_relation_equal:
diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
index 226632a4d10..8bc95187178 100644
--- a/fpu/softfloat-specialize.c.inc
+++ b/fpu/softfloat-specialize.c.inc
@@ -404,11 +404,9 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls,
     || defined(TARGET_RISCV) || defined(TARGET_SH4) \
     || defined(TARGET_TRICORE) || defined(TARGET_ARM) || defined(TARGET_MIPS) \
     || defined(TARGET_LOONGARCH64) || defined(TARGET_HPPA) \
-    || defined(TARGET_S390X) || defined(TARGET_PPC) || defined(TARGET_M68K)
+    || defined(TARGET_S390X) || defined(TARGET_PPC) || defined(TARGET_M68K) \
+    || defined(TARGET_SPARC)
         g_assert_not_reached();
-#elif defined(TARGET_SPARC)
-        /* Prefer SNaN over QNaN, order B then A. */
-        rule = float_2nan_prop_s_ba;
 #elif defined(TARGET_XTENSA)
         /*
          * Xtensa has two NaN propagation modes.
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 13/21] target/xtensa: Factor out calls to set_use_first_nan()
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
                   ` (11 preceding siblings ...)
  2024-10-25 14:12 ` [PATCH 12/21] target/sparc: Explicitly set 2-NaN propagation rule Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-25 15:54   ` Max Filippov
  2024-10-28 12:21   ` Richard Henderson
  2024-10-25 14:12 ` [PATCH 14/21] target/xtensa: Explicitly set 2-NaN propagation rule Peter Maydell
                   ` (8 subsequent siblings)
  21 siblings, 2 replies; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

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



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 14/21] target/xtensa: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
                   ` (12 preceding siblings ...)
  2024-10-25 14:12 ` [PATCH 13/21] target/xtensa: Factor out calls to set_use_first_nan() Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-25 15:54   ` Max Filippov
                     ` (2 more replies)
  2024-10-25 14:12 ` [PATCH 15/21] target/i386: Set 2-NaN propagation rule explicitly Peter Maydell
                   ` (7 subsequent siblings)
  21 siblings, 3 replies; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

Set the NaN propagation rule explicitly in xtensa_use_first_nan().

(When we convert the softfloat pickNaNMulAdd routine to also
select a NaN propagation rule at runtime, we will be able to
remove the use_first_nan flag because the propagation rules
will handle everything.)

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/xtensa/fpu_helper.c     |  2 ++
 fpu/softfloat-specialize.c.inc | 12 +-----------
 2 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/target/xtensa/fpu_helper.c b/target/xtensa/fpu_helper.c
index 50a5efa65e2..f2d212d05df 100644
--- a/target/xtensa/fpu_helper.c
+++ b/target/xtensa/fpu_helper.c
@@ -60,6 +60,8 @@ static const struct {
 void xtensa_use_first_nan(CPUXtensaState *env, bool use_first)
 {
     set_use_first_nan(use_first, &env->fp_status);
+    set_float_2nan_prop_rule(use_first ? float_2nan_prop_ab : float_2nan_prop_ba,
+                             &env->fp_status);
 }
 
 void HELPER(wur_fpu2k_fcr)(CPUXtensaState *env, uint32_t v)
diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
index 8bc95187178..b050c5eb04a 100644
--- a/fpu/softfloat-specialize.c.inc
+++ b/fpu/softfloat-specialize.c.inc
@@ -405,18 +405,8 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls,
     || defined(TARGET_TRICORE) || defined(TARGET_ARM) || defined(TARGET_MIPS) \
     || defined(TARGET_LOONGARCH64) || defined(TARGET_HPPA) \
     || defined(TARGET_S390X) || defined(TARGET_PPC) || defined(TARGET_M68K) \
-    || defined(TARGET_SPARC)
+    || defined(TARGET_SPARC) || defined(TARGET_XTENSA)
         g_assert_not_reached();
-#elif defined(TARGET_XTENSA)
-        /*
-         * Xtensa has two NaN propagation modes.
-         * Which one is active is controlled by float_status::use_first_nan.
-         */
-        if (status->use_first_nan) {
-            rule = float_2nan_prop_ab;
-        } else {
-            rule = float_2nan_prop_ba;
-        }
 #else
         rule = float_2nan_prop_x87;
 #endif
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 15/21] target/i386: Set 2-NaN propagation rule explicitly
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
                   ` (13 preceding siblings ...)
  2024-10-25 14:12 ` [PATCH 14/21] target/xtensa: Explicitly set 2-NaN propagation rule Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-28 12:24   ` Richard Henderson
  2024-10-25 14:12 ` [PATCH 16/21] target/alpha: Explicitly set 2-NaN propagation rule Peter Maydell
                   ` (6 subsequent siblings)
  21 siblings, 1 reply; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

Set the NaN propagation rule explicitly for the float_status words
used in the x86 target.

This is a no-behaviour-change commit, so we retain the existing
behaviour of using the x87-style "prefer QNaN over SNaN, then prefer
the NaN with the larger significand" for MMX and SSE.  This is
however not the documented hardware behaviour, so we leave a TODO
note about what we should be doing instead.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/i386/cpu.h              |  3 +++
 target/i386/cpu.c              |  4 ++++
 target/i386/tcg/fpu_helper.c   | 40 ++++++++++++++++++++++++++++++++++
 fpu/softfloat-specialize.c.inc |  3 ++-
 4 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 74886d1580f..43ba62e92d3 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -2562,6 +2562,9 @@ static inline bool cpu_vmx_maybe_enabled(CPUX86State *env)
 int get_pg_mode(CPUX86State *env);
 
 /* fpu_helper.c */
+
+/* Set all non-runtime-variable float_status fields to x86 handling */
+void cpu_init_fp_statuses(CPUX86State *env);
 void update_fp_status(CPUX86State *env);
 void update_mxcsr_status(CPUX86State *env);
 void update_mxcsr_from_sse_status(CPUX86State *env);
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 1ff1af032ea..e9260fbc654 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -7083,6 +7083,10 @@ static void x86_cpu_reset_hold(Object *obj, ResetType type)
 
     memset(env, 0, offsetof(CPUX86State, end_reset_fields));
 
+    if (tcg_enabled()) {
+        cpu_init_fp_statuses(env);
+    }
+
     env->old_exception = -1;
 
     /* init to reset state */
diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c
index e1b850f3fc2..53b49bb2977 100644
--- a/target/i386/tcg/fpu_helper.c
+++ b/target/i386/tcg/fpu_helper.c
@@ -135,6 +135,46 @@ static void fpu_set_exception(CPUX86State *env, int mask)
     }
 }
 
+void cpu_init_fp_statuses(CPUX86State *env)
+{
+    /*
+     * Initialise the non-runtime-varying fields of the various
+     * float_status words to x86 behaviour. This must be called at
+     * CPU reset because the float_status words are in the
+     * "zeroed on reset" portion of the CPU state struct.
+     * Fields in float_status that vary under guest control are set
+     * via the codepath for setting that register, eg cpu_set_fpuc().
+     */
+    /*
+     * Use x87 NaN propagation rules:
+     * SNaN + QNaN => return the QNaN
+     * two SNaNs => return the one with the larger significand, silenced
+     * two QNaNs => return the one with the larger significand
+     * SNaN and a non-NaN => return the SNaN, silenced
+     * QNaN and a non-NaN => return the QNaN
+     *
+     * If we get down to comparing significands and they are the same,
+     * return the NaN with the positive sign bit (if any).
+     */
+    set_float_2nan_prop_rule(float_2nan_prop_x87, &env->fp_status);
+    /*
+     * TODO: These are incorrect: the x86 Software Developer's Manual vol 1
+     * section 4.8.3.5 "Operating on SNaNs and QNaNs" says that the
+     * "larger significand" behaviour is only used for x87 FPU operations.
+     * For SSE the required behaviour is to always return the first NaN,
+     * which is float_2nan_prop_ab.
+     *
+     * mmx_status is used only for the AMD 3DNow! instructions, which
+     * are documented in the "3DNow! Technology Manual" as not supporting
+     * NaNs or infinities as inputs. The result of passing two NaNs is
+     * documented as "undefined", so we can do what we choose.
+     * (Strictly there is some behaviour we don't implement correctly
+     * for these "unsupported" NaN and Inf values, like "NaN * 0 == 0".)
+     */
+    set_float_2nan_prop_rule(float_2nan_prop_x87, &env->mmx_status);
+    set_float_2nan_prop_rule(float_2nan_prop_x87, &env->sse_status);
+}
+
 static inline uint8_t save_exception_flags(CPUX86State *env)
 {
     uint8_t old_flags = get_float_exception_flags(&env->fp_status);
diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
index b050c5eb04a..77ebc8216f6 100644
--- a/fpu/softfloat-specialize.c.inc
+++ b/fpu/softfloat-specialize.c.inc
@@ -405,7 +405,8 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls,
     || defined(TARGET_TRICORE) || defined(TARGET_ARM) || defined(TARGET_MIPS) \
     || defined(TARGET_LOONGARCH64) || defined(TARGET_HPPA) \
     || defined(TARGET_S390X) || defined(TARGET_PPC) || defined(TARGET_M68K) \
-    || defined(TARGET_SPARC) || defined(TARGET_XTENSA)
+    || defined(TARGET_SPARC) || defined(TARGET_XTENSA) \
+    || defined(TARGET_I386)
         g_assert_not_reached();
 #else
         rule = float_2nan_prop_x87;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 16/21] target/alpha: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
                   ` (14 preceding siblings ...)
  2024-10-25 14:12 ` [PATCH 15/21] target/i386: Set 2-NaN propagation rule explicitly Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-26  4:39   ` Philippe Mathieu-Daudé
  2024-10-28 12:25   ` Richard Henderson
  2024-10-25 14:12 ` [PATCH 17/21] target/microblaze: Move setting of float rounding mode to reset Peter Maydell
                   ` (5 subsequent siblings)
  21 siblings, 2 replies; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

Set the NaN propagation rule explicitly for the float_status word
used in this target.

This is a no-behaviour-change commit, so we retain the existing
behaviour of x87-style pick-largest-significand NaN propagation.
This is however not the architecturally correct handling, so we leave
a TODO note to that effect.

We also leave a TODO note pointing out that all this code in the cpu
initfn (including the existing setting up of env->flags and the FPCR)
should be in a currently non-existent CPU reset function.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/alpha/cpu.c             | 11 +++++++++++
 fpu/softfloat-specialize.c.inc |  2 +-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c
index 9db1dffc03e..5d75c941f7a 100644
--- a/target/alpha/cpu.c
+++ b/target/alpha/cpu.c
@@ -24,6 +24,7 @@
 #include "qemu/qemu-print.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "fpu/softfloat.h"
 
 
 static void alpha_cpu_set_pc(CPUState *cs, vaddr value)
@@ -187,7 +188,17 @@ static void alpha_cpu_initfn(Object *obj)
 {
     CPUAlphaState *env = cpu_env(CPU(obj));
 
+    /* TODO all this should be done in reset, not init */
+
     env->lock_addr = -1;
+
+    /*
+     * TODO: this is incorrect. The Alpha Architecture Handbook version 4
+     * describes NaN propagation in section 4.7.10.4. We should prefer
+     * the operand in Fb (whether it is a QNaN or an SNaN), then the
+     * operand in Fa. That is float_2nan_prop_ba.
+     */
+    set_float_2nan_prop_rule(float_2nan_prop_x87, &env->fp_status);
 #if defined(CONFIG_USER_ONLY)
     env->flags = ENV_FLAG_PS_USER | ENV_FLAG_FEN;
     cpu_alpha_store_fpcr(env, (uint64_t)(FPCR_INVD | FPCR_DZED | FPCR_OVFD
diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
index 77ebc8216f6..a5c3e2b8de5 100644
--- a/fpu/softfloat-specialize.c.inc
+++ b/fpu/softfloat-specialize.c.inc
@@ -406,7 +406,7 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls,
     || defined(TARGET_LOONGARCH64) || defined(TARGET_HPPA) \
     || defined(TARGET_S390X) || defined(TARGET_PPC) || defined(TARGET_M68K) \
     || defined(TARGET_SPARC) || defined(TARGET_XTENSA) \
-    || defined(TARGET_I386)
+    || defined(TARGET_I386) || defined(TARGET_ALPHA)
         g_assert_not_reached();
 #else
         rule = float_2nan_prop_x87;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 17/21] target/microblaze: Move setting of float rounding mode to reset
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
                   ` (15 preceding siblings ...)
  2024-10-25 14:12 ` [PATCH 16/21] target/alpha: Explicitly set 2-NaN propagation rule Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-28 12:25   ` Richard Henderson
  2024-10-25 14:12 ` [PATCH 18/21] target/microblaze: Explicitly set 2-NaN propagation rule Peter Maydell
                   ` (4 subsequent siblings)
  21 siblings, 1 reply; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

Although the floating point rounding mode for Microblaze is always
nearest-even, we cannot set it just once in the CPU initfn.  This is
because env->fp_status is in the part of the CPU state struct that is
zeroed on reset.

Move the call to set_float_rounding_mode() into the reset fn.

(This had no guest-visible effects because it happens that the
float_round_nearest_even enum value is 0, so when the struct was
zeroed it didn't corrupt the setting.)

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/microblaze/cpu.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c
index 135947ee800..6329a774331 100644
--- a/target/microblaze/cpu.c
+++ b/target/microblaze/cpu.c
@@ -201,6 +201,8 @@ static void mb_cpu_reset_hold(Object *obj, ResetType type)
 
     env->pc = cpu->cfg.base_vectors;
 
+    set_float_rounding_mode(float_round_nearest_even, &env->fp_status);
+
 #if defined(CONFIG_USER_ONLY)
     /* start in user mode with interrupts enabled.  */
     mb_cpu_write_msr(env, MSR_EE | MSR_IE | MSR_VM | MSR_UM);
@@ -311,15 +313,12 @@ static void mb_cpu_realizefn(DeviceState *dev, Error **errp)
 static void mb_cpu_initfn(Object *obj)
 {
     MicroBlazeCPU *cpu = MICROBLAZE_CPU(obj);
-    CPUMBState *env = &cpu->env;
 
     gdb_register_coprocessor(CPU(cpu), mb_cpu_gdb_read_stack_protect,
                              mb_cpu_gdb_write_stack_protect,
                              gdb_find_static_feature("microblaze-stack-protect.xml"),
                              0);
 
-    set_float_rounding_mode(float_round_nearest_even, &env->fp_status);
-
 #ifndef CONFIG_USER_ONLY
     /* Inbound IRQ and FIR lines */
     qdev_init_gpio_in(DEVICE(cpu), microblaze_cpu_set_irq, 2);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 18/21] target/microblaze: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
                   ` (16 preceding siblings ...)
  2024-10-25 14:12 ` [PATCH 17/21] target/microblaze: Move setting of float rounding mode to reset Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-26  4:39   ` Philippe Mathieu-Daudé
  2024-10-28 12:26   ` Richard Henderson
  2024-10-25 14:12 ` [PATCH 19/21] target/openrisc: " Peter Maydell
                   ` (3 subsequent siblings)
  21 siblings, 2 replies; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

Set the NaN propagation rule explicitly for the float_status word
used in the microblaze target.

This is probably not the architecturally correct behaviour,
but since this is a no-behaviour-change patch, we leave a
TODO note to that effect.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/microblaze/cpu.c        | 5 +++++
 fpu/softfloat-specialize.c.inc | 3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c
index 6329a774331..14286deead9 100644
--- a/target/microblaze/cpu.c
+++ b/target/microblaze/cpu.c
@@ -202,6 +202,11 @@ static void mb_cpu_reset_hold(Object *obj, ResetType type)
     env->pc = cpu->cfg.base_vectors;
 
     set_float_rounding_mode(float_round_nearest_even, &env->fp_status);
+    /*
+     * TODO: this is probably not the correct NaN propagation rule for
+     * this architecture.
+     */
+    set_float_2nan_prop_rule(float_2nan_prop_x87, &env->fp_status);
 
 #if defined(CONFIG_USER_ONLY)
     /* start in user mode with interrupts enabled.  */
diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
index a5c3e2b8de5..40cbb1ab73b 100644
--- a/fpu/softfloat-specialize.c.inc
+++ b/fpu/softfloat-specialize.c.inc
@@ -406,7 +406,8 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls,
     || defined(TARGET_LOONGARCH64) || defined(TARGET_HPPA) \
     || defined(TARGET_S390X) || defined(TARGET_PPC) || defined(TARGET_M68K) \
     || defined(TARGET_SPARC) || defined(TARGET_XTENSA) \
-    || defined(TARGET_I386) || defined(TARGET_ALPHA)
+    || defined(TARGET_I386) || defined(TARGET_ALPHA) \
+    || defined(TARGET_MICROBLAZE)
         g_assert_not_reached();
 #else
         rule = float_2nan_prop_x87;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 19/21] target/openrisc: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
                   ` (17 preceding siblings ...)
  2024-10-25 14:12 ` [PATCH 18/21] target/microblaze: Explicitly set 2-NaN propagation rule Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-26  4:40   ` Philippe Mathieu-Daudé
  2024-10-28 12:26   ` Richard Henderson
  2024-10-25 14:12 ` [PATCH 20/21] target/rx: " Peter Maydell
                   ` (2 subsequent siblings)
  21 siblings, 2 replies; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

Set the NaN propagation rule explicitly for the float_status word
used in the openrisc target.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/openrisc/cpu.c          | 6 ++++++
 fpu/softfloat-specialize.c.inc | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c
index 6ec54ad7a6c..b96561d1f26 100644
--- a/target/openrisc/cpu.c
+++ b/target/openrisc/cpu.c
@@ -105,6 +105,12 @@ static void openrisc_cpu_reset_hold(Object *obj, ResetType type)
 
     set_float_detect_tininess(float_tininess_before_rounding,
                               &cpu->env.fp_status);
+    /*
+     * TODO: this is probably not the correct NaN propagation rule for
+     * this architecture.
+     */
+    set_float_2nan_prop_rule(float_2nan_prop_x87, &cpu->env.fp_status);
+
 
 #ifndef CONFIG_USER_ONLY
     cpu->env.picmr = 0x00000000;
diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
index 40cbb1ab73b..ee5c73cad46 100644
--- a/fpu/softfloat-specialize.c.inc
+++ b/fpu/softfloat-specialize.c.inc
@@ -407,7 +407,7 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls,
     || defined(TARGET_S390X) || defined(TARGET_PPC) || defined(TARGET_M68K) \
     || defined(TARGET_SPARC) || defined(TARGET_XTENSA) \
     || defined(TARGET_I386) || defined(TARGET_ALPHA) \
-    || defined(TARGET_MICROBLAZE)
+    || defined(TARGET_MICROBLAZE) || defined(TARGET_OPENRISC)
         g_assert_not_reached();
 #else
         rule = float_2nan_prop_x87;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 20/21] target/rx: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
                   ` (18 preceding siblings ...)
  2024-10-25 14:12 ` [PATCH 19/21] target/openrisc: " Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-26  4:29   ` Philippe Mathieu-Daudé
  2024-10-28 12:27   ` Richard Henderson
  2024-10-25 14:12 ` [PATCH 21/21] softfloat: Remove fallback rule from pickNaN() Peter Maydell
  2024-10-25 14:49 ` [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Helge Deller
  21 siblings, 2 replies; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

Set the NaN propagation rule explicitly for the float_status word
used in the rx target.

This not the architecturally correct behaviour, but since this is a
no-behaviour-change patch, we leave a TODO note to that effect.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/rx/cpu.c                | 7 +++++++
 fpu/softfloat-specialize.c.inc | 3 ++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/target/rx/cpu.c b/target/rx/cpu.c
index 36d2a6f1890..65a74ce720f 100644
--- a/target/rx/cpu.c
+++ b/target/rx/cpu.c
@@ -93,6 +93,13 @@ static void rx_cpu_reset_hold(Object *obj, ResetType type)
     env->fpsw = 0;
     set_flush_to_zero(1, &env->fp_status);
     set_flush_inputs_to_zero(1, &env->fp_status);
+    /*
+     * TODO: this is not the correct NaN propagation rule for this
+     * architecture. The "RX Family User's Manual: Software" table 1.6
+     * defines the propagation rules as "prefer SNaN over QNaN;
+     * then prefer dest over source", which is float_2nan_prop_s_ab.
+     */
+    set_float_2nan_prop_rule(float_2nan_prop_x87, &env->fp_status);
 }
 
 static ObjectClass *rx_cpu_class_by_name(const char *cpu_model)
diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
index ee5c73cad46..254bbd67168 100644
--- a/fpu/softfloat-specialize.c.inc
+++ b/fpu/softfloat-specialize.c.inc
@@ -407,7 +407,8 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls,
     || defined(TARGET_S390X) || defined(TARGET_PPC) || defined(TARGET_M68K) \
     || defined(TARGET_SPARC) || defined(TARGET_XTENSA) \
     || defined(TARGET_I386) || defined(TARGET_ALPHA) \
-    || defined(TARGET_MICROBLAZE) || defined(TARGET_OPENRISC)
+    || defined(TARGET_MICROBLAZE) || defined(TARGET_OPENRISC) \
+    || defined(TARGET_RX)
         g_assert_not_reached();
 #else
         rule = float_2nan_prop_x87;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH 21/21] softfloat: Remove fallback rule from pickNaN()
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
                   ` (19 preceding siblings ...)
  2024-10-25 14:12 ` [PATCH 20/21] target/rx: " Peter Maydell
@ 2024-10-25 14:12 ` Peter Maydell
  2024-10-26  4:31   ` Philippe Mathieu-Daudé
  2024-10-28 12:28   ` Richard Henderson
  2024-10-25 14:49 ` [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Helge Deller
  21 siblings, 2 replies; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

Now that all targets have been converted to explicitly set a NaN
propagation rule, we can remove the set of target ifdefs (which now
list every target) and clean up the references to fallback behaviour
for float_2nan_prop_none.

The "default" case in the switch will catch any remaining places
where status->float_2nan_prop_rule was not set by the target.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 include/fpu/softfloat-types.h  | 10 +++-------
 fpu/softfloat-specialize.c.inc | 23 +++--------------------
 2 files changed, 6 insertions(+), 27 deletions(-)

diff --git a/include/fpu/softfloat-types.h b/include/fpu/softfloat-types.h
index 5cd5a0d0ae1..8f39691dfd0 100644
--- a/include/fpu/softfloat-types.h
+++ b/include/fpu/softfloat-types.h
@@ -178,13 +178,9 @@ typedef enum __attribute__((__packed__)) {
  * If default_nan_mode is enabled then it is valid not to set a
  * NaN propagation rule, because the softfloat code guarantees
  * not to try to pick a NaN to propagate in default NaN mode.
- *
- * For transition, currently the 'none' rule will cause us to
- * fall back to picking the propagation rule based on the existing
- * ifdef ladder. When all targets are converted it will be an error
- * not to set the rule in float_status unless in default_nan_mode,
- * and we will assert if we need to handle an input NaN and no
- * rule was selected.
+ * When not in default-NaN mode, it is an error for the target
+ * not to set the rule in float_status, and we will assert if
+ * we need to handle an input NaN and no rule was selected.
  */
 typedef enum __attribute__((__packed__)) {
     /* No propagation rule specified */
diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
index 254bbd67168..b5a32080505 100644
--- a/fpu/softfloat-specialize.c.inc
+++ b/fpu/softfloat-specialize.c.inc
@@ -390,32 +390,15 @@ bool float32_is_signaling_nan(float32 a_, float_status *status)
 static int pickNaN(FloatClass a_cls, FloatClass b_cls,
                    bool aIsLargerSignificand, float_status *status)
 {
-    Float2NaNPropRule rule = status->float_2nan_prop_rule;
-
     /*
      * We guarantee not to require the target to tell us how to
      * pick a NaN if we're always returning the default NaN.
+     * But if we're not in default-NaN mode then the target must
+     * specify via set_float_2nan_prop_rule().
      */
     assert(!status->default_nan_mode);
 
-    if (rule == float_2nan_prop_none) {
-        /* target didn't set the rule: fall back to old ifdef choices */
-#if defined(TARGET_AVR) || defined(TARGET_HEXAGON) \
-    || defined(TARGET_RISCV) || defined(TARGET_SH4) \
-    || defined(TARGET_TRICORE) || defined(TARGET_ARM) || defined(TARGET_MIPS) \
-    || defined(TARGET_LOONGARCH64) || defined(TARGET_HPPA) \
-    || defined(TARGET_S390X) || defined(TARGET_PPC) || defined(TARGET_M68K) \
-    || defined(TARGET_SPARC) || defined(TARGET_XTENSA) \
-    || defined(TARGET_I386) || defined(TARGET_ALPHA) \
-    || defined(TARGET_MICROBLAZE) || defined(TARGET_OPENRISC) \
-    || defined(TARGET_RX)
-        g_assert_not_reached();
-#else
-        rule = float_2nan_prop_x87;
-#endif
-    }
-
-    switch (rule) {
+    switch (status->float_2nan_prop_rule) {
     case float_2nan_prop_s_ab:
         if (is_snan(a_cls)) {
             return 0;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 63+ messages in thread

* Re: [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time
  2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
                   ` (20 preceding siblings ...)
  2024-10-25 14:12 ` [PATCH 21/21] softfloat: Remove fallback rule from pickNaN() Peter Maydell
@ 2024-10-25 14:49 ` Helge Deller
  2024-10-25 14:59   ` Peter Maydell
  21 siblings, 1 reply; 63+ messages in thread
From: Helge Deller @ 2024-10-25 14:49 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel


On 10/25/24 16:12, Peter Maydell wrote:
> A summary of those TODOs and other oddities I have noticed but not
> tried to tackle is:>
>   * hppa really ought to implement a CPU reset method
>   * alpha also doesn't implement CPU reset

I used the alpha code as template to implement the hppa machine.
That's probably why the CPU reset method is missing for both :-)

The TODO about implementing: ?
	resettable_class_set_parent_phases(rc, NULL, hppa_cpu_reset_hold, NULL,...)...

Helge


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time
  2024-10-25 14:49 ` [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Helge Deller
@ 2024-10-25 14:59   ` Peter Maydell
  2024-10-25 18:29     ` Helge Deller
  0 siblings, 1 reply; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:59 UTC (permalink / raw)
  To: Helge Deller; +Cc: qemu-devel

On Fri, 25 Oct 2024 at 15:49, Helge Deller <deller@gmx.de> wrote:
>
>
> On 10/25/24 16:12, Peter Maydell wrote:
> > A summary of those TODOs and other oddities I have noticed but not
> > tried to tackle is:>
> >   * hppa really ought to implement a CPU reset method
> >   * alpha also doesn't implement CPU reset
>
> I used the alpha code as template to implement the hppa machine.
> That's probably why the CPU reset method is missing for both :-)
>
> The TODO about implementing: ?
>         resettable_class_set_parent_phases(rc, NULL, hppa_cpu_reset_hold, NULL,...)...

Yes, basically. The reset method should restore all the
state of the CPU to what it was when QEMU started.
Typically you put an end_reset_fields marker in the
CPU state struct so you can memset() everything up to
that point to zero, and then manually reset anything
else that needs special handling.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 13/21] target/xtensa: Factor out calls to set_use_first_nan()
  2024-10-25 14:12 ` [PATCH 13/21] target/xtensa: Factor out calls to set_use_first_nan() Peter Maydell
@ 2024-10-25 15:54   ` Max Filippov
  2024-10-28 12:21   ` Richard Henderson
  1 sibling, 0 replies; 63+ messages in thread
From: Max Filippov @ 2024-10-25 15:54 UTC (permalink / raw)
  To: Peter Maydell
  Cc: qemu-arm, qemu-devel, Alex Bennée, Richard Henderson,
	Philippe Mathieu-Daudé, Song Gao, Eduardo Habkost,
	Edgar E. Iglesias, Jiaxun Yang, Aleksandar Rikalo, Stafford Horne,
	Nicholas Piggin, Daniel Henrique Barboza, Yoshinori Sato,
	David Hildenbrand, Ilya Leoshkevich, Thomas Huth,
	Mark Cave-Ayland, Artyom Tarasenko, qemu-ppc, qemu-s390x

On Fri, Oct 25, 2024 at 7:13 AM Peter Maydell <peter.maydell@linaro.org> wrote:
>
> 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(-)

Reviewed-by: Max Filippov <jcmvbkbc@gmail.com>

-- 
Thanks.
-- Max


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 14/21] target/xtensa: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 14/21] target/xtensa: Explicitly set 2-NaN propagation rule Peter Maydell
@ 2024-10-25 15:54   ` Max Filippov
  2024-10-26  4:38   ` Philippe Mathieu-Daudé
  2024-10-28 12:22   ` Richard Henderson
  2 siblings, 0 replies; 63+ messages in thread
From: Max Filippov @ 2024-10-25 15:54 UTC (permalink / raw)
  To: Peter Maydell
  Cc: qemu-arm, qemu-devel, Alex Bennée, Richard Henderson,
	Philippe Mathieu-Daudé, Song Gao, Eduardo Habkost,
	Edgar E. Iglesias, Jiaxun Yang, Aleksandar Rikalo, Stafford Horne,
	Nicholas Piggin, Daniel Henrique Barboza, Yoshinori Sato,
	David Hildenbrand, Ilya Leoshkevich, Thomas Huth,
	Mark Cave-Ayland, Artyom Tarasenko, qemu-ppc, qemu-s390x

On Fri, Oct 25, 2024 at 7:13 AM Peter Maydell <peter.maydell@linaro.org> wrote:
>
> Set the NaN propagation rule explicitly in xtensa_use_first_nan().
>
> (When we convert the softfloat pickNaNMulAdd routine to also
> select a NaN propagation rule at runtime, we will be able to
> remove the use_first_nan flag because the propagation rules
> will handle everything.)
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  target/xtensa/fpu_helper.c     |  2 ++
>  fpu/softfloat-specialize.c.inc | 12 +-----------
>  2 files changed, 3 insertions(+), 11 deletions(-)

Reviewed-by: Max Filippov <jcmvbkbc@gmail.com>

-- 
Thanks.
-- Max


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 07/21] target/s390x: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 07/21] target/s390x: " Peter Maydell
@ 2024-10-25 17:45   ` Ilya Leoshkevich
  2024-10-26  4:40   ` Philippe Mathieu-Daudé
  2024-10-28 12:15   ` Richard Henderson
  2 siblings, 0 replies; 63+ messages in thread
From: Ilya Leoshkevich @ 2024-10-25 17:45 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko, Max Filippov,
	qemu-ppc, qemu-s390x

On Fri, 2024-10-25 at 15:12 +0100, Peter Maydell wrote:
> Set the 2-NaN propagation rule explicitly in env->fpu_status.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  target/s390x/cpu.c             | 1 +
>  fpu/softfloat-specialize.c.inc | 5 ++---
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c
> index 4e41a3dff59..514c70f3010 100644
> --- a/target/s390x/cpu.c
> +++ b/target/s390x/cpu.c
> @@ -205,6 +205,7 @@ static void s390_cpu_reset_hold(Object *obj,
> ResetType type)
>          /* tininess for underflow is detected before rounding */
>          set_float_detect_tininess(float_tininess_before_rounding,
>                                    &env->fpu_status);
> +        set_float_2nan_prop_rule(float_2nan_prop_s_ab, &env-
> >fpu_status);
>         /* fall through */
>      case RESET_TYPE_S390_CPU_NORMAL:
>          env->psw.mask &= ~PSW_MASK_RI;
> diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-
> specialize.c.inc
> index 4e51cf8d083..a0c740e544d 100644
> --- a/fpu/softfloat-specialize.c.inc
> +++ b/fpu/softfloat-specialize.c.inc
> @@ -403,10 +403,9 @@ static int pickNaN(FloatClass a_cls, FloatClass
> b_cls,
>  #if defined(TARGET_AVR) || defined(TARGET_HEXAGON) \
>      || defined(TARGET_RISCV) || defined(TARGET_SH4) \
>      || defined(TARGET_TRICORE) || defined(TARGET_ARM) ||
> defined(TARGET_MIPS) \
> -    || defined(TARGET_LOONGARCH64) || defined(TARGET_HPPA)
> +    || defined(TARGET_LOONGARCH64) || defined(TARGET_HPPA) \
> +    || defined(TARGET_S390X)
>          g_assert_not_reached();
> -#elif defined(TARGET_S390X)
> -        rule = float_2nan_prop_s_ab;
>  #elif defined(TARGET_PPC) || defined(TARGET_M68K)
>          /*
>           * PowerPC propagation rules:

Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com>

Thanks!


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time
  2024-10-25 14:59   ` Peter Maydell
@ 2024-10-25 18:29     ` Helge Deller
  0 siblings, 0 replies; 63+ messages in thread
From: Helge Deller @ 2024-10-25 18:29 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel

On 10/25/24 16:59, Peter Maydell wrote:
> On Fri, 25 Oct 2024 at 15:49, Helge Deller <deller@gmx.de> wrote:
>>
>>
>> On 10/25/24 16:12, Peter Maydell wrote:
>>> A summary of those TODOs and other oddities I have noticed but not
>>> tried to tackle is:>
>>>    * hppa really ought to implement a CPU reset method
>>>    * alpha also doesn't implement CPU reset
>>
>> I used the alpha code as template to implement the hppa machine.
>> That's probably why the CPU reset method is missing for both :-)
>>
>> The TODO about implementing: ?
>>          resettable_class_set_parent_phases(rc, NULL, hppa_cpu_reset_hold, NULL,...)...
>
> Yes, basically. The reset method should restore all the
> state of the CPU to what it was when QEMU started.
> Typically you put an end_reset_fields marker in the
> CPU state struct so you can memset() everything up to
> that point to zero, and then manually reset anything
> else that needs special handling.

Thanks for the explanation!

I've just sent a patch to the mailing list:
[PATCH] target/hppa: Add CPU reset method

I tested it and it does work for me.
If OK for you, I'd happy if you could include it in your patch
series and adjust as needed to fix the FP initialization.

Helge


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 02/21] tests/fp: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 02/21] tests/fp: Explicitly set 2-NaN propagation rule Peter Maydell
@ 2024-10-25 19:27   ` Philippe Mathieu-Daudé
  2024-10-28 12:07   ` Richard Henderson
  1 sibling, 0 replies; 63+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-25 19:27 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Song Gao, Eduardo Habkost,
	Edgar E. Iglesias, Jiaxun Yang, Aleksandar Rikalo, Stafford Horne,
	Nicholas Piggin, Daniel Henrique Barboza, Yoshinori Sato,
	David Hildenbrand, Ilya Leoshkevich, Thomas Huth,
	Mark Cave-Ayland, Artyom Tarasenko, Max Filippov, qemu-ppc,
	qemu-s390x

On 25/10/24 11:12, Peter Maydell wrote:
> Explicitly set a 2-NaN propagation rule in the softfloat tests.  In
> meson.build we put -DTARGET_ARM in fpcflags, and so we should select
> here the Arm propagation rule of float_2nan_prop_s_ab.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   tests/fp/fp-bench.c     | 2 ++
>   tests/fp/fp-test-log2.c | 1 +
>   tests/fp/fp-test.c      | 2 ++
>   3 files changed, 5 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 04/21] target/mips: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 04/21] target/mips: " Peter Maydell
@ 2024-10-25 19:46   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 63+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-25 19:46 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Song Gao, Eduardo Habkost,
	Edgar E. Iglesias, Jiaxun Yang, Aleksandar Rikalo, Stafford Horne,
	Nicholas Piggin, Daniel Henrique Barboza, Yoshinori Sato,
	David Hildenbrand, Ilya Leoshkevich, Thomas Huth,
	Mark Cave-Ayland, Artyom Tarasenko, Max Filippov, qemu-ppc,
	qemu-s390x

On 25/10/24 11:12, Peter Maydell wrote:
> Set the 2-NaN propagation rule explicitly in the float_status words
> we use.
> 
> For active_fpu.fp_status, we do this in a new fp_reset() function
> which mirrors the existing msa_reset() function in doing "first call
> restore to set the fp status parts that depend on CPU state, then set
> the fp status parts that are constant".
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   target/mips/fpu_helper.h       | 22 ++++++++++++++++++++++
>   target/mips/cpu.c              |  2 +-
>   target/mips/msa.c              | 17 +++++++++++++++++
>   fpu/softfloat-specialize.c.inc | 18 ++----------------
>   4 files changed, 42 insertions(+), 17 deletions(-)
> 
> diff --git a/target/mips/fpu_helper.h b/target/mips/fpu_helper.h
> index ad1116e8c10..7c3c7897b45 100644
> --- a/target/mips/fpu_helper.h
> +++ b/target/mips/fpu_helper.h
> @@ -44,6 +44,28 @@ static inline void restore_fp_status(CPUMIPSState *env)
>       restore_snan_bit_mode(env);
>   }
>   
> +static inline void fp_reset(CPUMIPSState *env)
> +{
> +    restore_fp_status(env);
> +
> +    /*
> +     * According to MIPS specifications, if one of the two operands is
> +     * a sNaN, a new qNaN has to be generated. This is done in
> +     * floatXX_silence_nan(). For qNaN inputs the specifications
> +     * says: "When possible, this QNaN result is one of the operand QNaN
> +     * values." In practice it seems that most implementations choose
> +     * the first operand if both operands are qNaN. In short this gives
> +     * the following rules:
> +     *  1. A if it is signaling
> +     *  2. B if it is signaling
> +     *  3. A (quiet)
> +     *  4. B (quiet)
> +     * A signaling NaN is always silenced before returning it.
> +     */
> +    set_float_2nan_prop_rule(float_2nan_prop_s_ab,
> +                             &env->active_fpu.fp_status);
> +}
> +
>   /* MSA */
>   
>   enum CPUMIPSMSADataFormat {
> diff --git a/target/mips/cpu.c b/target/mips/cpu.c
> index 9724e71a5e0..d0a43b6d5c7 100644
> --- a/target/mips/cpu.c
> +++ b/target/mips/cpu.c
> @@ -407,9 +407,9 @@ static void mips_cpu_reset_hold(Object *obj, ResetType type)
>       }
>   
>       msa_reset(env);
> +    fp_reset(env);
>   
>       compute_hflags(env);
> -    restore_fp_status(env);
>       restore_pamask(env);
>       cs->exception_index = EXCP_NONE;
>   
> diff --git a/target/mips/msa.c b/target/mips/msa.c
> index 61f1a9a5936..9dffc428f5c 100644
> --- a/target/mips/msa.c
> +++ b/target/mips/msa.c
> @@ -49,6 +49,23 @@ void msa_reset(CPUMIPSState *env)
>       set_float_detect_tininess(float_tininess_after_rounding,
>                                 &env->active_tc.msa_fp_status);
>   
> +    /*
> +     * According to MIPS specifications, if one of the two operands is
> +     * a sNaN, a new qNaN has to be generated. This is done in
> +     * floatXX_silence_nan(). For qNaN inputs the specifications
> +     * says: "When possible, this QNaN result is one of the operand QNaN
> +     * values." In practice it seems that most implementations choose
> +     * the first operand if both operands are qNaN. In short this gives
> +     * the following rules:
> +     *  1. A if it is signaling
> +     *  2. B if it is signaling
> +     *  3. A (quiet)
> +     *  4. B (quiet)
> +     * A signaling NaN is always silenced before returning it.
> +     */
> +    set_float_2nan_prop_rule(float_2nan_prop_s_ab,
> +                             &env->active_tc.msa_fp_status);

Alternatively pass float_status* to fp_reset() and call it here as

        mips_fp_reset(&env->active_tc.msa_fp_status);

So we keep the comment in one place.

Regardless,

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 20/21] target/rx: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 20/21] target/rx: " Peter Maydell
@ 2024-10-26  4:29   ` Philippe Mathieu-Daudé
  2024-10-28 12:27   ` Richard Henderson
  1 sibling, 0 replies; 63+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-26  4:29 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Song Gao, Eduardo Habkost,
	Edgar E. Iglesias, Jiaxun Yang, Aleksandar Rikalo, Stafford Horne,
	Nicholas Piggin, Daniel Henrique Barboza, Yoshinori Sato,
	David Hildenbrand, Ilya Leoshkevich, Thomas Huth,
	Mark Cave-Ayland, Artyom Tarasenko, Max Filippov, qemu-ppc,
	qemu-s390x

On 25/10/24 11:12, Peter Maydell wrote:
> Set the NaN propagation rule explicitly for the float_status word
> used in the rx target.
> 
> This not the architecturally correct behaviour, but since this is a
> no-behaviour-change patch, we leave a TODO note to that effect.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   target/rx/cpu.c                | 7 +++++++
>   fpu/softfloat-specialize.c.inc | 3 ++-
>   2 files changed, 9 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 21/21] softfloat: Remove fallback rule from pickNaN()
  2024-10-25 14:12 ` [PATCH 21/21] softfloat: Remove fallback rule from pickNaN() Peter Maydell
@ 2024-10-26  4:31   ` Philippe Mathieu-Daudé
  2024-10-28 12:28   ` Richard Henderson
  1 sibling, 0 replies; 63+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-26  4:31 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Song Gao, Eduardo Habkost,
	Edgar E. Iglesias, Jiaxun Yang, Aleksandar Rikalo, Stafford Horne,
	Nicholas Piggin, Daniel Henrique Barboza, Yoshinori Sato,
	David Hildenbrand, Ilya Leoshkevich, Thomas Huth,
	Mark Cave-Ayland, Artyom Tarasenko, Max Filippov, qemu-ppc,
	qemu-s390x

On 25/10/24 11:12, Peter Maydell wrote:
> Now that all targets have been converted to explicitly set a NaN
> propagation rule, we can remove the set of target ifdefs (which now
> list every target) and clean up the references to fallback behaviour
> for float_2nan_prop_none.
> 
> The "default" case in the switch will catch any remaining places
> where status->float_2nan_prop_rule was not set by the target.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   include/fpu/softfloat-types.h  | 10 +++-------
>   fpu/softfloat-specialize.c.inc | 23 +++--------------------
>   2 files changed, 6 insertions(+), 27 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 11/21] target/sparc: Move cpu_put_fsr(env, 0) call to reset
  2024-10-25 14:12 ` [PATCH 11/21] target/sparc: Move cpu_put_fsr(env, 0) call to reset Peter Maydell
@ 2024-10-26  4:32   ` Philippe Mathieu-Daudé
  2024-10-26 20:00   ` Mark Cave-Ayland
  2024-10-28 12:20   ` Richard Henderson
  2 siblings, 0 replies; 63+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-26  4:32 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Song Gao, Eduardo Habkost,
	Edgar E. Iglesias, Jiaxun Yang, Aleksandar Rikalo, Stafford Horne,
	Nicholas Piggin, Daniel Henrique Barboza, Yoshinori Sato,
	David Hildenbrand, Ilya Leoshkevich, Thomas Huth,
	Mark Cave-Ayland, Artyom Tarasenko, Max Filippov, qemu-ppc,
	qemu-s390x

On 25/10/24 11:12, Peter Maydell wrote:
> Currently we call cpu_put_fsr(0) in sparc_cpu_realizefn(), which
> initializes various fields in the CPU struct:
>   * fsr_cexc_ftt
>   * fcc[]
>   * fsr_qne
>   * fsr
> It also sets the rounding mode in env->fp_status.
> 
> This is largely pointless, because when we later reset the CPU
> this will zero out all the fields up until the "end_reset_fields"
> label, which includes all of these (but not fp_status!)
> 
> Move the cpu_put_fsr(env, 0) call to reset, because that expresses
> the logical requirement: we want to reset FSR to 0 on every reset.
> This isn't a behaviour change because the fields are all zero anyway.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   target/sparc/cpu.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 10/21] target/m68k: Initialize float_status fields in gdb set/get functions
  2024-10-25 14:12 ` [PATCH 10/21] target/m68k: Initialize float_status fields in gdb set/get functions Peter Maydell
@ 2024-10-26  4:35   ` Philippe Mathieu-Daudé
  2024-10-28 12:19   ` Richard Henderson
  1 sibling, 0 replies; 63+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-26  4:35 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Song Gao, Eduardo Habkost,
	Edgar E. Iglesias, Jiaxun Yang, Aleksandar Rikalo, Stafford Horne,
	Nicholas Piggin, Daniel Henrique Barboza, Yoshinori Sato,
	David Hildenbrand, Ilya Leoshkevich, Thomas Huth,
	Mark Cave-Ayland, Artyom Tarasenko, Max Filippov, qemu-ppc,
	qemu-s390x

On 25/10/24 11:12, Peter Maydell wrote:
> In cf_fpu_gdb_get_reg() and cf_fpu_gdb_set_reg() we use a temporary
> float_status variable to pass to floatx80_to_float64() and
> float64_to_floatx80(), but we don't initialize it, meaning that those
> functions could access uninitialized data.  Zero-init the structs.
> 
> (We don't need to set a NaN-propagation rule here because we
> don't use these with a 2-argument fpu operation.)
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> Spotted by code-inspection while I was doing the 2-NaN propagation
> patches.
> ---
>   target/m68k/helper.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/target/m68k/helper.c b/target/m68k/helper.c
> index 9d3db8419de..9bfc6ae97c0 100644
> --- a/target/m68k/helper.c
> +++ b/target/m68k/helper.c
> @@ -36,7 +36,7 @@ static int cf_fpu_gdb_get_reg(CPUState *cs, GByteArray *mem_buf, int n)
>       CPUM68KState *env = &cpu->env;
>   
>       if (n < 8) {
> -        float_status s;
> +        float_status s = {};
>           return gdb_get_reg64(mem_buf, floatx80_to_float64(env->fregs[n].d, &s));

While here, could be renamed as 'discard' like SPARC. Regardless:

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

>       }
>       switch (n) {
> @@ -56,7 +56,7 @@ static int cf_fpu_gdb_set_reg(CPUState *cs, uint8_t *mem_buf, int n)
>       CPUM68KState *env = &cpu->env;
>   
>       if (n < 8) {
> -        float_status s;
> +        float_status s = {};
>           env->fregs[n].d = float64_to_floatx80(ldq_be_p(mem_buf), &s);
>           return 8;
>       }



^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 09/21] target/m68k: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 09/21] target/m68k: " Peter Maydell
@ 2024-10-26  4:36   ` Philippe Mathieu-Daudé
  2024-10-28 12:18   ` Richard Henderson
  2024-10-29 10:10   ` Peter Maydell
  2 siblings, 0 replies; 63+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-26  4:36 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Song Gao, Eduardo Habkost,
	Edgar E. Iglesias, Jiaxun Yang, Aleksandar Rikalo, Stafford Horne,
	Nicholas Piggin, Daniel Henrique Barboza, Yoshinori Sato,
	David Hildenbrand, Ilya Leoshkevich, Thomas Huth,
	Mark Cave-Ayland, Artyom Tarasenko, Max Filippov, qemu-ppc,
	qemu-s390x

On 25/10/24 11:12, Peter Maydell wrote:
> Explicitly set the 2-NaN propagation rule on env->fp_status
> and on the temporary fp_status that we use in frem (since
> we pass that to a division operation function).
> ---
>   target/m68k/cpu.c              | 16 ++++++++++++++++
>   target/m68k/fpu_helper.c       |  1 +
>   fpu/softfloat-specialize.c.inc | 19 +------------------
>   3 files changed, 18 insertions(+), 18 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 14/21] target/xtensa: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 14/21] target/xtensa: Explicitly set 2-NaN propagation rule Peter Maydell
  2024-10-25 15:54   ` Max Filippov
@ 2024-10-26  4:38   ` Philippe Mathieu-Daudé
  2024-10-28 12:22   ` Richard Henderson
  2 siblings, 0 replies; 63+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-26  4:38 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Song Gao, Eduardo Habkost,
	Edgar E. Iglesias, Jiaxun Yang, Aleksandar Rikalo, Stafford Horne,
	Nicholas Piggin, Daniel Henrique Barboza, Yoshinori Sato,
	David Hildenbrand, Ilya Leoshkevich, Thomas Huth,
	Mark Cave-Ayland, Artyom Tarasenko, Max Filippov, qemu-ppc,
	qemu-s390x

On 25/10/24 11:12, Peter Maydell wrote:
> Set the NaN propagation rule explicitly in xtensa_use_first_nan().
> 
> (When we convert the softfloat pickNaNMulAdd routine to also
> select a NaN propagation rule at runtime, we will be able to
> remove the use_first_nan flag because the propagation rules
> will handle everything.)
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   target/xtensa/fpu_helper.c     |  2 ++
>   fpu/softfloat-specialize.c.inc | 12 +-----------
>   2 files changed, 3 insertions(+), 11 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 16/21] target/alpha: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 16/21] target/alpha: Explicitly set 2-NaN propagation rule Peter Maydell
@ 2024-10-26  4:39   ` Philippe Mathieu-Daudé
  2024-10-28 12:25   ` Richard Henderson
  1 sibling, 0 replies; 63+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-26  4:39 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Song Gao, Eduardo Habkost,
	Edgar E. Iglesias, Jiaxun Yang, Aleksandar Rikalo, Stafford Horne,
	Nicholas Piggin, Daniel Henrique Barboza, Yoshinori Sato,
	David Hildenbrand, Ilya Leoshkevich, Thomas Huth,
	Mark Cave-Ayland, Artyom Tarasenko, Max Filippov, qemu-ppc,
	qemu-s390x

On 25/10/24 11:12, Peter Maydell wrote:
> Set the NaN propagation rule explicitly for the float_status word
> used in this target.
> 
> This is a no-behaviour-change commit, so we retain the existing
> behaviour of x87-style pick-largest-significand NaN propagation.
> This is however not the architecturally correct handling, so we leave
> a TODO note to that effect.
> 
> We also leave a TODO note pointing out that all this code in the cpu
> initfn (including the existing setting up of env->flags and the FPCR)
> should be in a currently non-existent CPU reset function.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   target/alpha/cpu.c             | 11 +++++++++++
>   fpu/softfloat-specialize.c.inc |  2 +-
>   2 files changed, 12 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 18/21] target/microblaze: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 18/21] target/microblaze: Explicitly set 2-NaN propagation rule Peter Maydell
@ 2024-10-26  4:39   ` Philippe Mathieu-Daudé
  2024-10-28 12:26   ` Richard Henderson
  1 sibling, 0 replies; 63+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-26  4:39 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Song Gao, Eduardo Habkost,
	Edgar E. Iglesias, Jiaxun Yang, Aleksandar Rikalo, Stafford Horne,
	Nicholas Piggin, Daniel Henrique Barboza, Yoshinori Sato,
	David Hildenbrand, Ilya Leoshkevich, Thomas Huth,
	Mark Cave-Ayland, Artyom Tarasenko, Max Filippov, qemu-ppc,
	qemu-s390x

On 25/10/24 11:12, Peter Maydell wrote:
> Set the NaN propagation rule explicitly for the float_status word
> used in the microblaze target.
> 
> This is probably not the architecturally correct behaviour,
> but since this is a no-behaviour-change patch, we leave a
> TODO note to that effect.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   target/microblaze/cpu.c        | 5 +++++
>   fpu/softfloat-specialize.c.inc | 3 ++-
>   2 files changed, 7 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 19/21] target/openrisc: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 19/21] target/openrisc: " Peter Maydell
@ 2024-10-26  4:40   ` Philippe Mathieu-Daudé
  2024-10-28 12:26   ` Richard Henderson
  1 sibling, 0 replies; 63+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-26  4:40 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Song Gao, Eduardo Habkost,
	Edgar E. Iglesias, Jiaxun Yang, Aleksandar Rikalo, Stafford Horne,
	Nicholas Piggin, Daniel Henrique Barboza, Yoshinori Sato,
	David Hildenbrand, Ilya Leoshkevich, Thomas Huth,
	Mark Cave-Ayland, Artyom Tarasenko, Max Filippov, qemu-ppc,
	qemu-s390x

On 25/10/24 11:12, Peter Maydell wrote:
> Set the NaN propagation rule explicitly for the float_status word
> used in the openrisc target.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   target/openrisc/cpu.c          | 6 ++++++
>   fpu/softfloat-specialize.c.inc | 2 +-
>   2 files changed, 7 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 07/21] target/s390x: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 07/21] target/s390x: " Peter Maydell
  2024-10-25 17:45   ` Ilya Leoshkevich
@ 2024-10-26  4:40   ` Philippe Mathieu-Daudé
  2024-10-28 12:15   ` Richard Henderson
  2 siblings, 0 replies; 63+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-26  4:40 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Song Gao, Eduardo Habkost,
	Edgar E. Iglesias, Jiaxun Yang, Aleksandar Rikalo, Stafford Horne,
	Nicholas Piggin, Daniel Henrique Barboza, Yoshinori Sato,
	David Hildenbrand, Ilya Leoshkevich, Thomas Huth,
	Mark Cave-Ayland, Artyom Tarasenko, Max Filippov, qemu-ppc,
	qemu-s390x

On 25/10/24 11:12, Peter Maydell wrote:
> Set the 2-NaN propagation rule explicitly in env->fpu_status.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   target/s390x/cpu.c             | 1 +
>   fpu/softfloat-specialize.c.inc | 5 ++---
>   2 files changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 11/21] target/sparc: Move cpu_put_fsr(env, 0) call to reset
  2024-10-25 14:12 ` [PATCH 11/21] target/sparc: Move cpu_put_fsr(env, 0) call to reset Peter Maydell
  2024-10-26  4:32   ` Philippe Mathieu-Daudé
@ 2024-10-26 20:00   ` Mark Cave-Ayland
  2024-10-28 12:20   ` Richard Henderson
  2 siblings, 0 replies; 63+ messages in thread
From: Mark Cave-Ayland @ 2024-10-26 20:00 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Artyom Tarasenko, Max Filippov,
	qemu-ppc, qemu-s390x

On 25/10/2024 15:12, Peter Maydell wrote:

> Currently we call cpu_put_fsr(0) in sparc_cpu_realizefn(), which
> initializes various fields in the CPU struct:
>   * fsr_cexc_ftt
>   * fcc[]
>   * fsr_qne
>   * fsr
> It also sets the rounding mode in env->fp_status.
> 
> This is largely pointless, because when we later reset the CPU
> this will zero out all the fields up until the "end_reset_fields"
> label, which includes all of these (but not fp_status!)
> 
> Move the cpu_put_fsr(env, 0) call to reset, because that expresses
> the logical requirement: we want to reset FSR to 0 on every reset.
> This isn't a behaviour change because the fields are all zero anyway.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   target/sparc/cpu.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
> index 54cb269e0af..e7f4068a162 100644
> --- a/target/sparc/cpu.c
> +++ b/target/sparc/cpu.c
> @@ -76,6 +76,7 @@ static void sparc_cpu_reset_hold(Object *obj, ResetType type)
>       env->npc = env->pc + 4;
>   #endif
>       env->cache_control = 0;
> +    cpu_put_fsr(env, 0);
>   }
>   
>   #ifndef CONFIG_USER_ONLY
> @@ -805,7 +806,6 @@ static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)
>       env->version |= env->def.maxtl << 8;
>       env->version |= env->def.nwindows - 1;
>   #endif
> -    cpu_put_fsr(env, 0);
>   
>       cpu_exec_realizefn(cs, &local_err);
>       if (local_err != NULL) {

Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>


ATB,

Mark.



^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 12/21] target/sparc: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 12/21] target/sparc: Explicitly set 2-NaN propagation rule Peter Maydell
@ 2024-10-26 20:03   ` Mark Cave-Ayland
  2024-10-28 12:20   ` Richard Henderson
  1 sibling, 0 replies; 63+ messages in thread
From: Mark Cave-Ayland @ 2024-10-26 20:03 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Artyom Tarasenko, Max Filippov,
	qemu-ppc, qemu-s390x

On 25/10/2024 15:12, Peter Maydell wrote:

> Set the NaN propagation rule explicitly in the float_status
> words we use.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   target/sparc/cpu.c             |  8 ++++++++
>   target/sparc/fop_helper.c      | 10 ++++++++--
>   fpu/softfloat-specialize.c.inc |  6 ++----
>   3 files changed, 18 insertions(+), 6 deletions(-)
> 
> diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
> index e7f4068a162..dd7af86de73 100644
> --- a/target/sparc/cpu.c
> +++ b/target/sparc/cpu.c
> @@ -26,6 +26,7 @@
>   #include "hw/qdev-properties.h"
>   #include "qapi/visitor.h"
>   #include "tcg/tcg.h"
> +#include "fpu/softfloat.h"
>   
>   //#define DEBUG_FEATURES
>   
> @@ -807,6 +808,13 @@ static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)
>       env->version |= env->def.nwindows - 1;
>   #endif
>   
> +    /*
> +     * Prefer SNaN over QNaN, order B then A. It's OK to do this in realize
> +     * rather than reset, because fp_status is after 'end_reset_fields' in
> +     * the CPU state struct so it won't get zeroed on reset.
> +     */
> +    set_float_2nan_prop_rule(float_2nan_prop_s_ba, &env->fp_status);
> +
>       cpu_exec_realizefn(cs, &local_err);
>       if (local_err != NULL) {
>           error_propagate(errp, local_err);
> diff --git a/target/sparc/fop_helper.c b/target/sparc/fop_helper.c
> index b6692382b3b..6f9ccc008a0 100644
> --- a/target/sparc/fop_helper.c
> +++ b/target/sparc/fop_helper.c
> @@ -497,7 +497,10 @@ uint32_t helper_flcmps(float32 src1, float32 src2)
>        * Perform the comparison with a dummy fp environment.
>        */
>       float_status discard = { };
> -    FloatRelation r = float32_compare_quiet(src1, src2, &discard);
> +    FloatRelation r;
> +
> +    set_float_2nan_prop_rule(float_2nan_prop_s_ba, &discard);
> +    r = float32_compare_quiet(src1, src2, &discard);
>   
>       switch (r) {
>       case float_relation_equal:
> @@ -518,7 +521,10 @@ uint32_t helper_flcmps(float32 src1, float32 src2)
>   uint32_t helper_flcmpd(float64 src1, float64 src2)
>   {
>       float_status discard = { };
> -    FloatRelation r = float64_compare_quiet(src1, src2, &discard);
> +    FloatRelation r;
> +
> +    set_float_2nan_prop_rule(float_2nan_prop_s_ba, &discard);
> +    r = float64_compare_quiet(src1, src2, &discard);
>   
>       switch (r) {
>       case float_relation_equal:
> diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
> index 226632a4d10..8bc95187178 100644
> --- a/fpu/softfloat-specialize.c.inc
> +++ b/fpu/softfloat-specialize.c.inc
> @@ -404,11 +404,9 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls,
>       || defined(TARGET_RISCV) || defined(TARGET_SH4) \
>       || defined(TARGET_TRICORE) || defined(TARGET_ARM) || defined(TARGET_MIPS) \
>       || defined(TARGET_LOONGARCH64) || defined(TARGET_HPPA) \
> -    || defined(TARGET_S390X) || defined(TARGET_PPC) || defined(TARGET_M68K)
> +    || defined(TARGET_S390X) || defined(TARGET_PPC) || defined(TARGET_M68K) \
> +    || defined(TARGET_SPARC)
>           g_assert_not_reached();
> -#elif defined(TARGET_SPARC)
> -        /* Prefer SNaN over QNaN, order B then A. */
> -        rule = float_2nan_prop_s_ba;
>   #elif defined(TARGET_XTENSA)
>           /*
>            * Xtensa has two NaN propagation modes.

Acked-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>


ATB,

Mark.



^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 01/21] softfloat: Allow 2-operand NaN propagation rule to be set at runtime
  2024-10-25 14:12 ` [PATCH 01/21] softfloat: Allow 2-operand NaN propagation rule to be set at runtime Peter Maydell
@ 2024-10-28 12:07   ` Richard Henderson
  0 siblings, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:07 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> IEEE 758 does not define a fixed rule for which NaN to pick as the
> result if both operands of a 2-operand operation are NaNs.  As a
> result different architectures have ended up with different rules for
> propagating NaNs.
> 
> QEMU currently hardcodes the NaN propagation logic into the binary
> because pickNaN() has an ifdef ladder for different targets.  We want
> to make the propagation rule instead be selectable at runtime,
> because:
>   * this will let us have multiple targets in one QEMU binary
>   * the Arm FEAT_AFP architectural feature includes letting
>     the guest select a NaN propagation rule at runtime
>   * x86 specifies different propagation rules for x87 FPU ops
>     and for SSE ops, and specifying the rule in the float_status
>     would let us emulate this, instead of wrongly using the
>     x87 rules everywhere
> 
> In this commit we add an enum for the propagation rule, the field in
> float_status, and the corresponding getters and setters.  We change
> pickNaN to honour this, but because all targets still leave this
> field at its default 0 value, the fallback logic will pick the rule
> type with the old ifdef ladder.
> 
> It's valid not to set a propagation rule if default_nan_mode is
> enabled, because in that case there's no need to pick a NaN; all the
> callers of pickNaN() catch this case and skip calling it.  So we can
> already assert that we don't get into the "no rule defined" codepath
> for our four targets which always set default_nan_mode: Hexagon,
> RiscV, SH4 and Tricore, and for the one target which does not have FP
> at all: avr.  These targets will not need to be updated to call
> set_float_2nan_prop_rule().
> 
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
> Reindent means a couple of slightly long lines in comments,
> but those will move again in a later patch, so seemed clearer to
> not re-wrap the comment and then re-rewrap it later.
> ---
>   include/fpu/softfloat-helpers.h |  11 ++
>   include/fpu/softfloat-types.h   |  42 ++++++
>   fpu/softfloat-specialize.c.inc  | 229 ++++++++++++++++++--------------
>   3 files changed, 185 insertions(+), 97 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 02/21] tests/fp: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 02/21] tests/fp: Explicitly set 2-NaN propagation rule Peter Maydell
  2024-10-25 19:27   ` Philippe Mathieu-Daudé
@ 2024-10-28 12:07   ` Richard Henderson
  1 sibling, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:07 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> Explicitly set a 2-NaN propagation rule in the softfloat tests.  In
> meson.build we put -DTARGET_ARM in fpcflags, and so we should select
> here the Arm propagation rule of float_2nan_prop_s_ab.
> 
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
>   tests/fp/fp-bench.c     | 2 ++
>   tests/fp/fp-test-log2.c | 1 +
>   tests/fp/fp-test.c      | 2 ++
>   3 files changed, 5 insertions(+)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 03/21] target/arm: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 03/21] target/arm: " Peter Maydell
@ 2024-10-28 12:10   ` Richard Henderson
  0 siblings, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:10 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> Set the 2-NaN propagation rule explicitly in the float_status words
> we use.  We wrap this plus the pre-existing setting of the
> tininess-before-rounding flag in a new function
> arm_set_default_fp_behaviours() to avoid repetition, since we have a
> lot of float_status words at this point.
> 
> The situation with FPA11 emulation in linux-user is a little odd, and
> arguably "correct" behaviour there would be to exactly match a real
> Linux kernel's FPA11 emulation.  However FPA11 emulation is
> essentially dead at this point and so it seems better to continue
> with QEMU's current behaviour and leave a comment describing the
> situation.
> 
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
>   linux-user/arm/nwfpe/fpa11.c   | 18 ++++++++++++++++++
>   target/arm/cpu.c               | 25 +++++++++++++++++--------
>   fpu/softfloat-specialize.c.inc | 13 ++-----------
>   3 files changed, 37 insertions(+), 19 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 05/21] target/loongarch: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 05/21] target/loongarch: " Peter Maydell
@ 2024-10-28 12:13   ` Richard Henderson
  0 siblings, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:13 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> Set the 2-NaN propagation rule explicitly in the float_status word we
> use.
> 
> (There are a couple of places in fpu_helper.c where we create a
> dummy float_status word with "float_status *s = { };", but these
> are only used for calling float*_is_quiet_nan() so it doesn't
> matter that we don't set a 2-NaN propagation rule there.)
> 
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
>   target/loongarch/tcg/fpu_helper.c | 1 +
>   fpu/softfloat-specialize.c.inc    | 6 +++---
>   2 files changed, 4 insertions(+), 3 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 06/21] target/hppa: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 06/21] target/hppa: " Peter Maydell
@ 2024-10-28 12:14   ` Richard Henderson
  0 siblings, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:14 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> Set the 2-NaN propagation rule explicitly in env->fp_status.
> 
> Really we only need to do this at CPU reset (after reset has zeroed
> out most of the CPU state struct, which typically includes fp_status
> fields).  However target/hppa does not currently implement CPU reset
> at all, so leave a TODO comment to note that this could be moved if
> we ever do implement reset.
> 
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
>   target/hppa/fpu_helper.c       | 6 ++++++
>   fpu/softfloat-specialize.c.inc | 4 ++--
>   2 files changed, 8 insertions(+), 2 deletions(-)

We could do this in hppa_cpu_init().  Anyway,

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 07/21] target/s390x: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 07/21] target/s390x: " Peter Maydell
  2024-10-25 17:45   ` Ilya Leoshkevich
  2024-10-26  4:40   ` Philippe Mathieu-Daudé
@ 2024-10-28 12:15   ` Richard Henderson
  2 siblings, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:15 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> Set the 2-NaN propagation rule explicitly in env->fpu_status.
> 
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
>   target/s390x/cpu.c             | 1 +
>   fpu/softfloat-specialize.c.inc | 5 ++---
>   2 files changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 08/21] target/ppc: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 08/21] target/ppc: " Peter Maydell
@ 2024-10-28 12:16   ` Richard Henderson
  0 siblings, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:16 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> Set the 2-NaN propagation rule explicitly in env->fp_status
> and env->vec_status.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


> ---
> As an aside, it looks a bit suspicious that we set
> tininess_before_rounding on fp_status but not vec_status...

Indeed.


r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 09/21] target/m68k: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 09/21] target/m68k: " Peter Maydell
  2024-10-26  4:36   ` Philippe Mathieu-Daudé
@ 2024-10-28 12:18   ` Richard Henderson
  2024-10-29 10:10   ` Peter Maydell
  2 siblings, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:18 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> Explicitly set the 2-NaN propagation rule on env->fp_status
> and on the temporary fp_status that we use in frem (since
> we pass that to a division operation function).
> ---
>   target/m68k/cpu.c              | 16 ++++++++++++++++
>   target/m68k/fpu_helper.c       |  1 +
>   fpu/softfloat-specialize.c.inc | 19 +------------------
>   3 files changed, 18 insertions(+), 18 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 10/21] target/m68k: Initialize float_status fields in gdb set/get functions
  2024-10-25 14:12 ` [PATCH 10/21] target/m68k: Initialize float_status fields in gdb set/get functions Peter Maydell
  2024-10-26  4:35   ` Philippe Mathieu-Daudé
@ 2024-10-28 12:19   ` Richard Henderson
  1 sibling, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:19 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> In cf_fpu_gdb_get_reg() and cf_fpu_gdb_set_reg() we use a temporary
> float_status variable to pass to floatx80_to_float64() and
> float64_to_floatx80(), but we don't initialize it, meaning that those
> functions could access uninitialized data.  Zero-init the structs.
> 
> (We don't need to set a NaN-propagation rule here because we
> don't use these with a 2-argument fpu operation.)
> 
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
> Spotted by code-inspection while I was doing the 2-NaN propagation
> patches.
> ---
>   target/m68k/helper.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 11/21] target/sparc: Move cpu_put_fsr(env, 0) call to reset
  2024-10-25 14:12 ` [PATCH 11/21] target/sparc: Move cpu_put_fsr(env, 0) call to reset Peter Maydell
  2024-10-26  4:32   ` Philippe Mathieu-Daudé
  2024-10-26 20:00   ` Mark Cave-Ayland
@ 2024-10-28 12:20   ` Richard Henderson
  2 siblings, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:20 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> Currently we call cpu_put_fsr(0) in sparc_cpu_realizefn(), which
> initializes various fields in the CPU struct:
>   * fsr_cexc_ftt
>   * fcc[]
>   * fsr_qne
>   * fsr
> It also sets the rounding mode in env->fp_status.
> 
> This is largely pointless, because when we later reset the CPU
> this will zero out all the fields up until the "end_reset_fields"
> label, which includes all of these (but not fp_status!)
> 
> Move the cpu_put_fsr(env, 0) call to reset, because that expresses
> the logical requirement: we want to reset FSR to 0 on every reset.
> This isn't a behaviour change because the fields are all zero anyway.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 12/21] target/sparc: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 12/21] target/sparc: Explicitly set 2-NaN propagation rule Peter Maydell
  2024-10-26 20:03   ` Mark Cave-Ayland
@ 2024-10-28 12:20   ` Richard Henderson
  1 sibling, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:20 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> Set the NaN propagation rule explicitly in the float_status
> words we use.
> 
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
>   target/sparc/cpu.c             |  8 ++++++++
>   target/sparc/fop_helper.c      | 10 ++++++++--
>   fpu/softfloat-specialize.c.inc |  6 ++----
>   3 files changed, 18 insertions(+), 6 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 13/21] target/xtensa: Factor out calls to set_use_first_nan()
  2024-10-25 14:12 ` [PATCH 13/21] target/xtensa: Factor out calls to set_use_first_nan() Peter Maydell
  2024-10-25 15:54   ` Max Filippov
@ 2024-10-28 12:21   ` Richard Henderson
  1 sibling, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:21 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> 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(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 14/21] target/xtensa: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 14/21] target/xtensa: Explicitly set 2-NaN propagation rule Peter Maydell
  2024-10-25 15:54   ` Max Filippov
  2024-10-26  4:38   ` Philippe Mathieu-Daudé
@ 2024-10-28 12:22   ` Richard Henderson
  2 siblings, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:22 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> Set the NaN propagation rule explicitly in xtensa_use_first_nan().
> 
> (When we convert the softfloat pickNaNMulAdd routine to also
> select a NaN propagation rule at runtime, we will be able to
> remove the use_first_nan flag because the propagation rules
> will handle everything.)
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   target/xtensa/fpu_helper.c     |  2 ++
>   fpu/softfloat-specialize.c.inc | 12 +-----------
>   2 files changed, 3 insertions(+), 11 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 15/21] target/i386: Set 2-NaN propagation rule explicitly
  2024-10-25 14:12 ` [PATCH 15/21] target/i386: Set 2-NaN propagation rule explicitly Peter Maydell
@ 2024-10-28 12:24   ` Richard Henderson
  0 siblings, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:24 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> Set the NaN propagation rule explicitly for the float_status words
> used in the x86 target.
> 
> This is a no-behaviour-change commit, so we retain the existing
> behaviour of using the x87-style "prefer QNaN over SNaN, then prefer
> the NaN with the larger significand" for MMX and SSE.  This is
> however not the documented hardware behaviour, so we leave a TODO
> note about what we should be doing instead.
> 
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
>   target/i386/cpu.h              |  3 +++
>   target/i386/cpu.c              |  4 ++++
>   target/i386/tcg/fpu_helper.c   | 40 ++++++++++++++++++++++++++++++++++
>   fpu/softfloat-specialize.c.inc |  3 ++-
>   4 files changed, 49 insertions(+), 1 deletion(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 16/21] target/alpha: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 16/21] target/alpha: Explicitly set 2-NaN propagation rule Peter Maydell
  2024-10-26  4:39   ` Philippe Mathieu-Daudé
@ 2024-10-28 12:25   ` Richard Henderson
  1 sibling, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:25 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> Set the NaN propagation rule explicitly for the float_status word
> used in this target.
> 
> This is a no-behaviour-change commit, so we retain the existing
> behaviour of x87-style pick-largest-significand NaN propagation.
> This is however not the architecturally correct handling, so we leave
> a TODO note to that effect.
> 
> We also leave a TODO note pointing out that all this code in the cpu
> initfn (including the existing setting up of env->flags and the FPCR)
> should be in a currently non-existent CPU reset function.
> 
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
>   target/alpha/cpu.c             | 11 +++++++++++
>   fpu/softfloat-specialize.c.inc |  2 +-
>   2 files changed, 12 insertions(+), 1 deletion(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 17/21] target/microblaze: Move setting of float rounding mode to reset
  2024-10-25 14:12 ` [PATCH 17/21] target/microblaze: Move setting of float rounding mode to reset Peter Maydell
@ 2024-10-28 12:25   ` Richard Henderson
  0 siblings, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:25 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> Although the floating point rounding mode for Microblaze is always
> nearest-even, we cannot set it just once in the CPU initfn.  This is
> because env->fp_status is in the part of the CPU state struct that is
> zeroed on reset.
> 
> Move the call to set_float_rounding_mode() into the reset fn.
> 
> (This had no guest-visible effects because it happens that the
> float_round_nearest_even enum value is 0, so when the struct was
> zeroed it didn't corrupt the setting.)
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   target/microblaze/cpu.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 18/21] target/microblaze: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 18/21] target/microblaze: Explicitly set 2-NaN propagation rule Peter Maydell
  2024-10-26  4:39   ` Philippe Mathieu-Daudé
@ 2024-10-28 12:26   ` Richard Henderson
  1 sibling, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:26 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> Set the NaN propagation rule explicitly for the float_status word
> used in the microblaze target.
> 
> This is probably not the architecturally correct behaviour,
> but since this is a no-behaviour-change patch, we leave a
> TODO note to that effect.
> 
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
>   target/microblaze/cpu.c        | 5 +++++
>   fpu/softfloat-specialize.c.inc | 3 ++-
>   2 files changed, 7 insertions(+), 1 deletion(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 19/21] target/openrisc: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 19/21] target/openrisc: " Peter Maydell
  2024-10-26  4:40   ` Philippe Mathieu-Daudé
@ 2024-10-28 12:26   ` Richard Henderson
  1 sibling, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:26 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> Set the NaN propagation rule explicitly for the float_status word
> used in the openrisc target.
> 
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
>   target/openrisc/cpu.c          | 6 ++++++
>   fpu/softfloat-specialize.c.inc | 2 +-
>   2 files changed, 7 insertions(+), 1 deletion(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 20/21] target/rx: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 20/21] target/rx: " Peter Maydell
  2024-10-26  4:29   ` Philippe Mathieu-Daudé
@ 2024-10-28 12:27   ` Richard Henderson
  1 sibling, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:27 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> Set the NaN propagation rule explicitly for the float_status word
> used in the rx target.
> 
> This not the architecturally correct behaviour, but since this is a
> no-behaviour-change patch, we leave a TODO note to that effect.
> 
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
>   target/rx/cpu.c                | 7 +++++++
>   fpu/softfloat-specialize.c.inc | 3 ++-
>   2 files changed, 9 insertions(+), 1 deletion(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 21/21] softfloat: Remove fallback rule from pickNaN()
  2024-10-25 14:12 ` [PATCH 21/21] softfloat: Remove fallback rule from pickNaN() Peter Maydell
  2024-10-26  4:31   ` Philippe Mathieu-Daudé
@ 2024-10-28 12:28   ` Richard Henderson
  1 sibling, 0 replies; 63+ messages in thread
From: Richard Henderson @ 2024-10-28 12:28 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Song Gao,
	Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On 10/25/24 15:12, Peter Maydell wrote:
> Now that all targets have been converted to explicitly set a NaN
> propagation rule, we can remove the set of target ifdefs (which now
> list every target) and clean up the references to fallback behaviour
> for float_2nan_prop_none.
> 
> The "default" case in the switch will catch any remaining places
> where status->float_2nan_prop_rule was not set by the target.
> 
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
>   include/fpu/softfloat-types.h  | 10 +++-------
>   fpu/softfloat-specialize.c.inc | 23 +++--------------------
>   2 files changed, 6 insertions(+), 27 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH 09/21] target/m68k: Explicitly set 2-NaN propagation rule
  2024-10-25 14:12 ` [PATCH 09/21] target/m68k: " Peter Maydell
  2024-10-26  4:36   ` Philippe Mathieu-Daudé
  2024-10-28 12:18   ` Richard Henderson
@ 2024-10-29 10:10   ` Peter Maydell
  2 siblings, 0 replies; 63+ messages in thread
From: Peter Maydell @ 2024-10-29 10:10 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

On Fri, 25 Oct 2024 at 15:13, Peter Maydell <peter.maydell@linaro.org> wrote:
>
> Explicitly set the 2-NaN propagation rule on env->fp_status
> and on the temporary fp_status that we use in frem (since
> we pass that to a division operation function).
> ---
>  target/m68k/cpu.c              | 16 ++++++++++++++++
>  target/m68k/fpu_helper.c       |  1 +
>  fpu/softfloat-specialize.c.inc | 19 +------------------
>  3 files changed, 18 insertions(+), 18 deletions(-)

Whoops, Laurent pointed out I forgot to add a signed-off-by
on this patch, so here it is:

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

-- PMM


^ permalink raw reply	[flat|nested] 63+ messages in thread

end of thread, other threads:[~2024-10-29 10:11 UTC | newest]

Thread overview: 63+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
2024-10-25 14:12 ` [PATCH 01/21] softfloat: Allow 2-operand NaN propagation rule to be set at runtime Peter Maydell
2024-10-28 12:07   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 02/21] tests/fp: Explicitly set 2-NaN propagation rule Peter Maydell
2024-10-25 19:27   ` Philippe Mathieu-Daudé
2024-10-28 12:07   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 03/21] target/arm: " Peter Maydell
2024-10-28 12:10   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 04/21] target/mips: " Peter Maydell
2024-10-25 19:46   ` Philippe Mathieu-Daudé
2024-10-25 14:12 ` [PATCH 05/21] target/loongarch: " Peter Maydell
2024-10-28 12:13   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 06/21] target/hppa: " Peter Maydell
2024-10-28 12:14   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 07/21] target/s390x: " Peter Maydell
2024-10-25 17:45   ` Ilya Leoshkevich
2024-10-26  4:40   ` Philippe Mathieu-Daudé
2024-10-28 12:15   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 08/21] target/ppc: " Peter Maydell
2024-10-28 12:16   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 09/21] target/m68k: " Peter Maydell
2024-10-26  4:36   ` Philippe Mathieu-Daudé
2024-10-28 12:18   ` Richard Henderson
2024-10-29 10:10   ` Peter Maydell
2024-10-25 14:12 ` [PATCH 10/21] target/m68k: Initialize float_status fields in gdb set/get functions Peter Maydell
2024-10-26  4:35   ` Philippe Mathieu-Daudé
2024-10-28 12:19   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 11/21] target/sparc: Move cpu_put_fsr(env, 0) call to reset Peter Maydell
2024-10-26  4:32   ` Philippe Mathieu-Daudé
2024-10-26 20:00   ` Mark Cave-Ayland
2024-10-28 12:20   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 12/21] target/sparc: Explicitly set 2-NaN propagation rule Peter Maydell
2024-10-26 20:03   ` Mark Cave-Ayland
2024-10-28 12:20   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 13/21] target/xtensa: Factor out calls to set_use_first_nan() Peter Maydell
2024-10-25 15:54   ` Max Filippov
2024-10-28 12:21   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 14/21] target/xtensa: Explicitly set 2-NaN propagation rule Peter Maydell
2024-10-25 15:54   ` Max Filippov
2024-10-26  4:38   ` Philippe Mathieu-Daudé
2024-10-28 12:22   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 15/21] target/i386: Set 2-NaN propagation rule explicitly Peter Maydell
2024-10-28 12:24   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 16/21] target/alpha: Explicitly set 2-NaN propagation rule Peter Maydell
2024-10-26  4:39   ` Philippe Mathieu-Daudé
2024-10-28 12:25   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 17/21] target/microblaze: Move setting of float rounding mode to reset Peter Maydell
2024-10-28 12:25   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 18/21] target/microblaze: Explicitly set 2-NaN propagation rule Peter Maydell
2024-10-26  4:39   ` Philippe Mathieu-Daudé
2024-10-28 12:26   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 19/21] target/openrisc: " Peter Maydell
2024-10-26  4:40   ` Philippe Mathieu-Daudé
2024-10-28 12:26   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 20/21] target/rx: " Peter Maydell
2024-10-26  4:29   ` Philippe Mathieu-Daudé
2024-10-28 12:27   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 21/21] softfloat: Remove fallback rule from pickNaN() Peter Maydell
2024-10-26  4:31   ` Philippe Mathieu-Daudé
2024-10-28 12:28   ` Richard Henderson
2024-10-25 14:49 ` [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Helge Deller
2024-10-25 14:59   ` Peter Maydell
2024-10-25 18:29     ` Helge Deller

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