All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [PULL 67/72] softfloat: Inline pickNaN
Date: Wed, 11 Dec 2024 16:19:59 +0000	[thread overview]
Message-ID: <20241211162004.2795499-68-peter.maydell@linaro.org> (raw)
In-Reply-To: <20241211162004.2795499-1-peter.maydell@linaro.org>

From: Richard Henderson <richard.henderson@linaro.org>

Inline pickNaN into its only caller.  This makes one assert
redundant with the immediately preceding IF.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-id: 20241203203949.483774-9-richard.henderson@linaro.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 fpu/softfloat-parts.c.inc      | 82 +++++++++++++++++++++++++----
 fpu/softfloat-specialize.c.inc | 96 ----------------------------------
 2 files changed, 73 insertions(+), 105 deletions(-)

diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc
index 5fcdbc87fd7..a1b148e90b9 100644
--- a/fpu/softfloat-parts.c.inc
+++ b/fpu/softfloat-parts.c.inc
@@ -39,24 +39,88 @@ static void partsN(return_nan)(FloatPartsN *a, float_status *s)
 static FloatPartsN *partsN(pick_nan)(FloatPartsN *a, FloatPartsN *b,
                                      float_status *s)
 {
+    int cmp, which;
+
     if (is_snan(a->cls) || is_snan(b->cls)) {
         float_raise(float_flag_invalid | float_flag_invalid_snan, s);
     }
 
     if (s->default_nan_mode) {
         parts_default_nan(a, s);
-    } else {
-        int cmp = frac_cmp(a, b);
-        if (cmp == 0) {
-            cmp = a->sign < b->sign;
-        }
+        return a;
+    }
 
-        if (pickNaN(a->cls, b->cls, cmp > 0, s)) {
-            a = b;
-        }
+    cmp = frac_cmp(a, b);
+    if (cmp == 0) {
+        cmp = a->sign < b->sign;
+    }
+
+    switch (s->float_2nan_prop_rule) {
+    case float_2nan_prop_s_ab:
         if (is_snan(a->cls)) {
-            parts_silence_nan(a, s);
+            which = 0;
+        } else if (is_snan(b->cls)) {
+            which = 1;
+        } else if (is_qnan(a->cls)) {
+            which = 0;
+        } else {
+            which = 1;
         }
+        break;
+    case float_2nan_prop_s_ba:
+        if (is_snan(b->cls)) {
+            which = 1;
+        } else if (is_snan(a->cls)) {
+            which = 0;
+        } else if (is_qnan(b->cls)) {
+            which = 1;
+        } else {
+            which = 0;
+        }
+        break;
+    case float_2nan_prop_ab:
+        which = is_nan(a->cls) ? 0 : 1;
+        break;
+    case float_2nan_prop_ba:
+        which = is_nan(b->cls) ? 1 : 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)) {
+                which = cmp > 0 ? 0 : 1;
+            } else {
+                which = is_qnan(b->cls) ? 1 : 0;
+            }
+        } else if (is_qnan(a->cls)) {
+            if (is_snan(b->cls) || !is_qnan(b->cls)) {
+                which = 0;
+            } else {
+                which = cmp > 0 ? 0 : 1;
+            }
+        } else {
+            which = 1;
+        }
+        break;
+    default:
+        g_assert_not_reached();
+    }
+
+    if (which) {
+        a = b;
+    }
+    if (is_snan(a->cls)) {
+        parts_silence_nan(a, s);
     }
     return a;
 }
diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
index f7a320f6ff9..cbbbab52ba3 100644
--- a/fpu/softfloat-specialize.c.inc
+++ b/fpu/softfloat-specialize.c.inc
@@ -352,102 +352,6 @@ bool float32_is_signaling_nan(float32 a_, float_status *status)
     }
 }
 
-/*----------------------------------------------------------------------------
-| Select which NaN to propagate for a two-input operation.
-| IEEE754 doesn't specify all the details of this, so the
-| algorithm is target-specific.
-| The routine is passed various bits of information about the
-| two NaNs and should return 0 to select NaN a and 1 for NaN b.
-| Note that signalling NaNs are always squashed to quiet NaNs
-| by the caller, by calling floatXX_silence_nan() before
-| returning them.
-|
-| aIsLargerSignificand is only valid if both a and b are NaNs
-| of some kind, and is true if a has the larger significand,
-| or if both a and b have the same significand but a is
-| positive but b is negative. It is only needed for the x87
-| tie-break rule.
-*----------------------------------------------------------------------------*/
-
-static int pickNaN(FloatClass a_cls, FloatClass b_cls,
-                   bool aIsLargerSignificand, float_status *status)
-{
-    /*
-     * 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);
-
-    switch (status->float_2nan_prop_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;
-        }
-        break;
-    case float_2nan_prop_ba:
-        if (is_nan(b_cls)) {
-            return 1;
-        } else {
-            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 1;
-        }
-    default:
-        g_assert_not_reached();
-    }
-}
-
 /*----------------------------------------------------------------------------
 | Returns 1 if the double-precision floating-point value `a' is a quiet
 | NaN; otherwise returns 0.
-- 
2.34.1



  parent reply	other threads:[~2024-12-11 16:29 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-11 16:18 [PULL 00/72] target-arm queue Peter Maydell
2024-12-11 16:18 ` [PULL 01/72] hw/net/lan9118: Extract lan9118_phy Peter Maydell
2024-12-11 16:18 ` [PULL 02/72] hw/net/lan9118_phy: Reuse in imx_fec and consolidate implementations Peter Maydell
2024-12-11 16:18 ` [PULL 03/72] hw/net/lan9118_phy: Fix off-by-one error in MII_ANLPAR register Peter Maydell
2024-12-11 16:18 ` [PULL 04/72] hw/net/lan9118_phy: Reuse MII constants Peter Maydell
2024-12-11 16:18 ` [PULL 05/72] hw/net/lan9118_phy: Add missing 100 mbps full duplex advertisement Peter Maydell
2024-12-11 16:18 ` [PULL 06/72] fpu: handle raising Invalid for infzero in pick_nan_muladd Peter Maydell
2024-12-11 16:18 ` [PULL 07/72] fpu: Check for default_nan_mode before calling pickNaNMulAdd Peter Maydell
2024-12-11 16:19 ` [PULL 08/72] softfloat: Allow runtime choice of inf * 0 + NaN result Peter Maydell
2024-12-11 16:19 ` [PULL 09/72] tests/fp: Explicitly set inf-zero-nan rule Peter Maydell
2024-12-11 16:19 ` [PULL 10/72] target/arm: Set FloatInfZeroNaNRule explicitly Peter Maydell
2024-12-11 16:19 ` [PULL 11/72] target/s390: " Peter Maydell
2024-12-11 16:19 ` [PULL 12/72] target/ppc: " Peter Maydell
2024-12-11 16:19 ` [PULL 13/72] target/mips: " Peter Maydell
2024-12-11 16:19 ` [PULL 14/72] target/sparc: " Peter Maydell
2024-12-11 16:19 ` [PULL 15/72] target/xtensa: " Peter Maydell
2024-12-11 16:19 ` [PULL 16/72] target/x86: " Peter Maydell
2024-12-11 16:19 ` [PULL 17/72] target/loongarch: " Peter Maydell
2024-12-11 16:19 ` [PULL 18/72] target/hppa: " Peter Maydell
2024-12-11 16:19 ` [PULL 19/72] softfloat: Pass have_snan to pickNaNMulAdd Peter Maydell
2024-12-11 16:19 ` [PULL 20/72] softfloat: Allow runtime choice of NaN propagation for muladd Peter Maydell
2024-12-11 16:19 ` [PULL 21/72] tests/fp: Explicitly set 3-NaN propagation rule Peter Maydell
2024-12-11 16:19 ` [PULL 22/72] target/arm: Set Float3NaNPropRule explicitly Peter Maydell
2024-12-11 16:19 ` [PULL 23/72] target/loongarch: " Peter Maydell
2024-12-11 16:19 ` [PULL 24/72] target/ppc: " Peter Maydell
2024-12-11 16:19 ` [PULL 25/72] target/s390x: " Peter Maydell
2024-12-11 16:19 ` [PULL 26/72] target/sparc: " Peter Maydell
2024-12-11 16:19 ` [PULL 27/72] target/mips: " Peter Maydell
2024-12-11 16:19 ` [PULL 28/72] target/xtensa: " Peter Maydell
2024-12-11 16:19 ` [PULL 29/72] target/i386: " Peter Maydell
2024-12-11 16:19 ` [PULL 30/72] target/hppa: " Peter Maydell
2024-12-11 16:19 ` [PULL 31/72] fpu: Remove use_first_nan field from float_status Peter Maydell
2024-12-11 16:19 ` [PULL 32/72] target/m68k: Don't pass NULL float_status to floatx80_default_nan() Peter Maydell
2024-12-11 16:19 ` [PULL 33/72] softfloat: Create floatx80 default NaN from parts64_default_nan Peter Maydell
2024-12-11 16:19 ` [PULL 34/72] target/loongarch: Use normal float_status in fclass_s and fclass_d helpers Peter Maydell
2024-12-11 16:19 ` [PULL 35/72] target/m68k: In frem helper, initialize local float_status from env->fp_status Peter Maydell
2024-12-11 16:19 ` [PULL 36/72] target/m68k: Init local float_status from env fp_status in gdb get/set reg Peter Maydell
2024-12-11 16:19 ` [PULL 37/72] target/sparc: Initialize local scratch float_status from env->fp_status Peter Maydell
2024-12-11 16:19 ` [PULL 38/72] target/ppc: Use env->fp_status in helper_compute_fprf functions Peter Maydell
2024-12-11 16:19 ` [PULL 39/72] target/arm: Copy entire float_status in is_ebf Peter Maydell
2024-12-11 16:19 ` [PULL 40/72] fpu: Allow runtime choice of default NaN value Peter Maydell
2024-12-11 16:19 ` [PULL 41/72] tests/fp: Set default NaN pattern explicitly Peter Maydell
2024-12-11 16:19 ` [PULL 42/72] target/microblaze: " Peter Maydell
2024-12-11 16:19 ` [PULL 43/72] target/i386: " Peter Maydell
2024-12-11 16:19 ` [PULL 44/72] target/hppa: " Peter Maydell
2024-12-11 16:19 ` [PULL 45/72] target/alpha: " Peter Maydell
2024-12-11 16:19 ` [PULL 46/72] target/arm: " Peter Maydell
2024-12-11 16:19 ` [PULL 47/72] target/loongarch: " Peter Maydell
2024-12-11 16:19 ` [PULL 48/72] target/m68k: " Peter Maydell
2024-12-11 16:19 ` [PULL 49/72] target/mips: " Peter Maydell
2024-12-11 16:19 ` [PULL 50/72] target/openrisc: " Peter Maydell
2024-12-11 16:19 ` [PULL 51/72] target/ppc: " Peter Maydell
2024-12-11 16:19 ` [PULL 52/72] target/sh4: " Peter Maydell
2024-12-11 16:19 ` [PULL 53/72] target/rx: " Peter Maydell
2024-12-11 16:19 ` [PULL 54/72] target/s390x: " Peter Maydell
2024-12-11 16:19 ` [PULL 55/72] target/sparc: " Peter Maydell
2024-12-11 16:19 ` [PULL 56/72] target/xtensa: " Peter Maydell
2024-12-11 16:19 ` [PULL 57/72] target/hexagon: " Peter Maydell
2024-12-11 16:19 ` [PULL 58/72] target/riscv: " Peter Maydell
2024-12-11 16:19 ` [PULL 59/72] target/tricore: " Peter Maydell
2024-12-11 16:19 ` [PULL 60/72] fpu: Remove default handling for dnan_pattern Peter Maydell
2024-12-11 16:19 ` [PULL 61/72] softfloat: Inline pickNaNMulAdd Peter Maydell
2024-12-11 16:19 ` [PULL 62/72] softfloat: Use goto for default nan case in pick_nan_muladd Peter Maydell
2024-12-11 16:19 ` [PULL 63/72] softfloat: Remove which from parts_pick_nan_muladd Peter Maydell
2024-12-11 16:19 ` [PULL 64/72] softfloat: Pad array size in pick_nan_muladd Peter Maydell
2024-12-11 16:19 ` [PULL 65/72] softfloat: Move propagateFloatx80NaN to softfloat.c Peter Maydell
2024-12-11 16:19 ` [PULL 66/72] softfloat: Use parts_pick_nan in propagateFloatx80NaN Peter Maydell
2024-12-11 16:19 ` Peter Maydell [this message]
2024-12-11 16:20 ` [PULL 68/72] softfloat: Share code between parts_pick_nan cases Peter Maydell
2024-12-11 16:20 ` [PULL 69/72] softfloat: Sink frac_cmp in parts_pick_nan until needed Peter Maydell
2024-12-11 16:20 ` [PULL 70/72] softfloat: Replace WHICH with RET in parts_pick_nan Peter Maydell
2024-12-11 16:20 ` [PULL 71/72] MAINTAINERS: update email address for Leif Lindholm Peter Maydell
2024-12-11 16:20 ` [PULL 72/72] MAINTAINERS: Add correct email address for Vikram Garhwal Peter Maydell
2024-12-13  1:20 ` [PULL 00/72] target-arm queue Stefan Hajnoczi
2024-12-13 10:44   ` Peter Maydell

Reply instructions:

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

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

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

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

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

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

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.