From nobody Sun May 19 04:55:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634281134423158.59417694418778; Thu, 14 Oct 2021 23:58:54 -0700 (PDT) Received: from localhost ([::1]:35078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mbHB7-0003ZW-7j for importer@patchew.org; Fri, 15 Oct 2021 02:58:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mbH7Z-0006LV-BP for qemu-devel@nongnu.org; Fri, 15 Oct 2021 02:55:13 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]:44019) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mbH7X-0000LV-G3 for qemu-devel@nongnu.org; Fri, 15 Oct 2021 02:55:13 -0400 Received: by mail-pg1-x534.google.com with SMTP id r2so7736761pgl.10 for ; Thu, 14 Oct 2021 23:55:11 -0700 (PDT) Received: from localhost.localdomain (123-193-74-252.dynamic.kbronet.com.tw. [123.193.74.252]) by smtp.gmail.com with ESMTPSA id d6sm4105059pfa.39.2021.10.14.23.55.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Oct 2021 23:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v1dzdQt6RGRlpojPozE1ubvGZgEhFPMxtksE+j35cvI=; b=cbvseZBmrxpnYcbX9J6iM+2PnRe8FyBvQhGZoandgW5f6vCqPjDIu5MEMLLqo8/SbL v7kxzJ5FsYoJ+3z8Qheq5RO26hbCHl7obJ4apuQzAXpPZ6kwRHmjQBApxUbP1+EswNnl usJKqebAm/2+vtvlI8MKISNNmEib5PHvyz5DrYkjWLHAK3EhZDb+cTj3jXlJBlbw0ZlG YDDfA4Yncuyn1UH0i8761SBxu7LwHlDPQxI++qV0nQRd+ephUzufTXcoMdVzsUGyi2mU qgGj2nQ7L4MuOmVtraDvd/9cPqsMT4/58+Um2TXIKzX80ausGhfQ7yLl9Ax0K9CFvAi4 hzIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v1dzdQt6RGRlpojPozE1ubvGZgEhFPMxtksE+j35cvI=; b=JW+BdMxvVbqL/G3MmCB7GOIv+vkfv3SMqC9dhKPQ6Dw5epQQacvk5KOF/NrgJ4UY6j rqQcBMqI/GBNyEa/3NQEAtX0SdLySZSgn/xsT/gdvdYHIpwAOzzkOzG/tEFOG+Bg9g7I BPVbCHT+xKfC3r0pSjdHkSjSAjTklgJwOCwshlOgKZThH/ik1O3q/S3ss+ToNtshQWr3 1DWBsbXD2pIe9aviS6Su3zaez65+jOg1QqfIl1OKLWUJ0CqQuWI47Zw4V4OLh/VWvR1Z K6KG01ffyyQsk01tkn34/wiOWytnsVB18TSSXFaBCFL9BOlURu8pNR+YxIVFGjTDDDwZ ZC5g== X-Gm-Message-State: AOAM532CQE2YxZCYr5Fu5yNqvNKwuiSeK8S6lSce7Te4T5GoEuC8StgO 1oj0LAZnOXtNsFhzYxyPdL+pXCItRJj7cmMd X-Google-Smtp-Source: ABdhPJwE/NjaKq7MtJhe/jfui8ONnzbs95etATKZkyD6AOhFp2OUxh6SaIcwCAzBzdq91R2v+t+DcA== X-Received: by 2002:aa7:9ede:0:b0:44d:13c7:14a7 with SMTP id r30-20020aa79ede000000b0044d13c714a7mr9991621pfq.18.1634280909908; Thu, 14 Oct 2021 23:55:09 -0700 (PDT) From: frank.chang@sifive.com To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 1/2] softfloat: add APIs to handle alternative sNaN propagation for fmax/fmin Date: Fri, 15 Oct 2021 14:54:56 +0800 Message-Id: <20211015065500.3850513-2-frank.chang@sifive.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211015065500.3850513-1-frank.chang@sifive.com> References: <20211015065500.3850513-1-frank.chang@sifive.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::534; envelope-from=frank.chang@sifive.com; helo=mail-pg1-x534.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Frank Chang , Chih-Min Chao , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Aurelien Jarno , Peter Maydell Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1634281136297100001 Content-Type: text/plain; charset="utf-8" From: Chih-Min Chao For "fmax/fmin ft0, ft1, ft2" and if one of the inputs is sNaN, The original logic: Return NaN and set invalid flag if ft1 =3D=3D sNaN || ft2 =3D=3D sNan. The alternative path: Set invalid flag if ft1 =3D=3D sNaN || ft2 =3D=3D sNaN. Return NaN only if ft1 =3D=3D NaN && ft2 =3D=3D NaN. The IEEE 754 spec allows both implementation and some architecture such as riscv choose different defintions in two spec versions. (riscv-spec-v2.2 use original version, riscv-spec-20191213 changes to alternative) Signed-off-by: Chih-Min Chao Signed-off-by: Frank Chang --- fpu/softfloat-parts.c.inc | 19 +++++++++++++++++++ fpu/softfloat.c | 18 +++++++++++++----- include/fpu/softfloat.h | 10 ++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index dddee92d6ee..a8d74624f5a 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -1227,6 +1227,25 @@ static FloatPartsN *partsN(minmax)(FloatPartsN *a, F= loatPartsN *b, && (ab_mask & ~float_cmask_qnan)) { return is_nan(a->cls) ? b : a; } + + /* + * In IEEE 754-2019, minNum, maxNum, minNumMag and maxNumMag + * are removed and replaced with minimum, minimumNumber, maximum + * and maximumNumber. + * minimumNumber/maximumNumber behavior for SNaN is changed to: + * If both operands are NaNs, a QNaN is returned. + * If either operand is a SNaN, + * an invalid operation exception is signaled, + * but unless both operands are NaNs, + * the SNaN is otherwise ignored and not converted to a QNaN. + */ + if (!(~flags & (minmax_isnum | minmax_snan_noprop)) + && (ab_mask & float_cmask_snan) + && (ab_mask & ~float_cmask_anynan)) { + float_raise(float_flag_invalid, s); + return is_nan(a->cls) ? b : a; + } + return parts_pick_nan(a, b, s); } =20 diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 6e769f990c2..eee65e9934c 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -436,6 +436,11 @@ enum { minmax_isnum =3D 2, /* Set for the IEEE 754-2008 minNumMag() and minNumMag() operations. */ minmax_ismag =3D 4, + /* + * Set for the IEEE 754-2019 minimumNumber() maximumNumber() operation= s, + * without sNaN propagation. + */ + minmax_snan_noprop =3D 8, }; =20 /* Simple helpers for checking if, or what kind of, NaN we have */ @@ -3927,11 +3932,14 @@ static float128 float128_minmax(float128 a, float12= 8 b, { return type##_minmax(a, b, s, flags); } =20 #define MINMAX_2(type) \ - MINMAX_1(type, max, 0) \ - MINMAX_1(type, maxnum, minmax_isnum) \ - MINMAX_1(type, maxnummag, minmax_isnum | minmax_ismag) \ - MINMAX_1(type, min, minmax_ismin) \ - MINMAX_1(type, minnum, minmax_ismin | minmax_isnum) \ + MINMAX_1(type, max, 0) \ + MINMAX_1(type, maxnum, minmax_isnum) \ + MINMAX_1(type, maxnum_noprop, minmax_isnum | minmax_snan_noprop) \ + MINMAX_1(type, maxnummag, minmax_isnum | minmax_ismag) \ + MINMAX_1(type, min, minmax_ismin) \ + MINMAX_1(type, minnum, minmax_ismin | minmax_isnum) \ + MINMAX_1(type, minnum_noprop, minmax_ismin | minmax_isnum | \ + minmax_snan_noprop) \ MINMAX_1(type, minnummag, minmax_ismin | minmax_isnum | minmax_ismag) =20 MINMAX_2(float16) diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h index ec7dca09606..b77917ea661 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -241,6 +241,8 @@ float16 float16_min(float16, float16, float_status *sta= tus); float16 float16_max(float16, float16, float_status *status); float16 float16_minnum(float16, float16, float_status *status); float16 float16_maxnum(float16, float16, float_status *status); +float16 float16_minnum_noprop(float16, float16, float_status *status); +float16 float16_maxnum_noprop(float16, float16, float_status *status); float16 float16_minnummag(float16, float16, float_status *status); float16 float16_maxnummag(float16, float16, float_status *status); float16 float16_sqrt(float16, float_status *status); @@ -420,6 +422,8 @@ bfloat16 bfloat16_min(bfloat16, bfloat16, float_status = *status); bfloat16 bfloat16_max(bfloat16, bfloat16, float_status *status); bfloat16 bfloat16_minnum(bfloat16, bfloat16, float_status *status); bfloat16 bfloat16_maxnum(bfloat16, bfloat16, float_status *status); +bfloat16 bfloat16_minnum_noprop(bfloat16, bfloat16, float_status *status); +bfloat16 bfloat16_maxnum_noprop(bfloat16, bfloat16, float_status *status); bfloat16 bfloat16_minnummag(bfloat16, bfloat16, float_status *status); bfloat16 bfloat16_maxnummag(bfloat16, bfloat16, float_status *status); bfloat16 bfloat16_sqrt(bfloat16, float_status *status); @@ -587,6 +591,8 @@ float32 float32_min(float32, float32, float_status *sta= tus); float32 float32_max(float32, float32, float_status *status); float32 float32_minnum(float32, float32, float_status *status); float32 float32_maxnum(float32, float32, float_status *status); +float32 float32_minnum_noprop(float32, float32, float_status *status); +float32 float32_maxnum_noprop(float32, float32, float_status *status); float32 float32_minnummag(float32, float32, float_status *status); float32 float32_maxnummag(float32, float32, float_status *status); bool float32_is_quiet_nan(float32, float_status *status); @@ -776,6 +782,8 @@ float64 float64_min(float64, float64, float_status *sta= tus); float64 float64_max(float64, float64, float_status *status); float64 float64_minnum(float64, float64, float_status *status); float64 float64_maxnum(float64, float64, float_status *status); +float64 float64_minnum_noprop(float64, float64, float_status *status); +float64 float64_maxnum_noprop(float64, float64, float_status *status); float64 float64_minnummag(float64, float64, float_status *status); float64 float64_maxnummag(float64, float64, float_status *status); bool float64_is_quiet_nan(float64 a, float_status *status); @@ -1208,6 +1216,8 @@ float128 float128_min(float128, float128, float_statu= s *status); float128 float128_max(float128, float128, float_status *status); float128 float128_minnum(float128, float128, float_status *status); float128 float128_maxnum(float128, float128, float_status *status); +float128 float128_minnum_noprop(float128, float128, float_status *status); +float128 float128_maxnum_noprop(float128, float128, float_status *status); float128 float128_minnummag(float128, float128, float_status *status); float128 float128_maxnummag(float128, float128, float_status *status); bool float128_is_quiet_nan(float128, float_status *status); --=20 2.25.1 From nobody Sun May 19 04:55:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634281022216374.39728250668713; Thu, 14 Oct 2021 23:57:02 -0700 (PDT) Received: from localhost ([::1]:58258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mbH9J-0000B4-8A for importer@patchew.org; Fri, 15 Oct 2021 02:57:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mbH7j-0006Oc-A3 for qemu-devel@nongnu.org; Fri, 15 Oct 2021 02:55:27 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]:38525) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mbH7d-0000PW-Ja for qemu-devel@nongnu.org; Fri, 15 Oct 2021 02:55:21 -0400 Received: by mail-pf1-x435.google.com with SMTP id k26so7587449pfi.5 for ; Thu, 14 Oct 2021 23:55:15 -0700 (PDT) Received: from localhost.localdomain (123-193-74-252.dynamic.kbronet.com.tw. [123.193.74.252]) by smtp.gmail.com with ESMTPSA id d6sm4105059pfa.39.2021.10.14.23.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Oct 2021 23:55:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LA3n51aVlEgbwHV98iyYH55ZjkabaHWokae08NAPXHA=; b=kyQoCT0TAJagFQOf23Sx9PN0Rj/bFKMd4hmjJq9HGbAOz7teW0Jn/PedjuQyF9OKsY lxob2xI5fZKhc692Wvu8M1eTURYjgS/TKScnDO2mBJnaXNcA0f7jViBSeNDsUAUa4iCP W8oDHzaPOwCleX4qQ2keWcYk+VrgAUlp7gQARpNn+m43YOKxCsK8T71j41YP4MsSXUTC VbBAjdkNyr7XvQoKEtCyFxH37LdvuLwxXQpb6ViQl5sy/LDlK8or8euQNQFHfPKfqJ1b SM4YUQ9dtXr1Ht/swGm57K2icf7iT+apzMyHM+E55b12iwl7rWdlorYn8uZi/g3KafU3 gv2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LA3n51aVlEgbwHV98iyYH55ZjkabaHWokae08NAPXHA=; b=0GAjOj5NnL09JayDhJfJKoWojjCod4mW9xceix/acYBJ6fzQ2buDPXHZv7YuzphW7X 8CYrS2nwScj3ZI+8C2KDIz23o0yQ7t4kytzZJdvswbR6fK9GWalfFapwlN76N6oVVL8u 0HDigUIdS8Q6jqmnC3JAW5QO6Y+EGpcHAVB6wmoweME7bQ0+soC1d5CUSndB44Jjk5R+ hNGenpFEd/8nF0ZBHPpqXe9QMmEpxXYMaLz9tdNZ7Vdt294QcW57NHQD+Pf/HT7+9q0s YF0w94DJkuG70RjRkl2jPwJ6oNS1guMi7v1ZQwiAAi3WSEups47oZq4+QpLVdVdEEMK4 XdoQ== X-Gm-Message-State: AOAM531bodOKgMwzd8bsow81NS+g2A2qfeppY3OsIv8nFMjjUhlYHXnx 4pMkS/bNgb4KCjnlOtyQk9v6/l8hDeXh1+XZ X-Google-Smtp-Source: ABdhPJz+lHJyW6xnnrzt16HZPKqrCgFH0S+Ledj5yEh6ELuNLd9VigKYY+k06yba/VyF9j7TZE92mg== X-Received: by 2002:a63:d60a:: with SMTP id q10mr7900175pgg.335.1634280914272; Thu, 14 Oct 2021 23:55:14 -0700 (PDT) From: frank.chang@sifive.com To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 2/2] target/riscv: change the api for single/double fmin/fmax Date: Fri, 15 Oct 2021 14:54:57 +0800 Message-Id: <20211015065500.3850513-3-frank.chang@sifive.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211015065500.3850513-1-frank.chang@sifive.com> References: <20211015065500.3850513-1-frank.chang@sifive.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=frank.chang@sifive.com; helo=mail-pf1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Chih-Min Chao , Alistair Francis , Bin Meng , Palmer Dabbelt Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1634281023055100001 Content-Type: text/plain; charset="utf-8" From: Chih-Min Chao The sNaN propagation behavior has been changed since cd20cee7 in https://github.com/riscv/riscv-isa-manual Signed-off-by: Chih-Min Chao --- target/riscv/fpu_helper.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/target/riscv/fpu_helper.c b/target/riscv/fpu_helper.c index 8700516a14c..1472ead2528 100644 --- a/target/riscv/fpu_helper.c +++ b/target/riscv/fpu_helper.c @@ -174,14 +174,14 @@ uint64_t helper_fmin_s(CPURISCVState *env, uint64_t r= s1, uint64_t rs2) { float32 frs1 =3D check_nanbox_s(rs1); float32 frs2 =3D check_nanbox_s(rs2); - return nanbox_s(float32_minnum(frs1, frs2, &env->fp_status)); + return nanbox_s(float32_minnum_noprop(frs1, frs2, &env->fp_status)); } =20 uint64_t helper_fmax_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2) { float32 frs1 =3D check_nanbox_s(rs1); float32 frs2 =3D check_nanbox_s(rs2); - return nanbox_s(float32_maxnum(frs1, frs2, &env->fp_status)); + return nanbox_s(float32_maxnum_noprop(frs1, frs2, &env->fp_status)); } =20 uint64_t helper_fsqrt_s(CPURISCVState *env, uint64_t rs1) @@ -283,12 +283,12 @@ uint64_t helper_fdiv_d(CPURISCVState *env, uint64_t f= rs1, uint64_t frs2) =20 uint64_t helper_fmin_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2) { - return float64_minnum(frs1, frs2, &env->fp_status); + return float64_minnum_noprop(frs1, frs2, &env->fp_status); } =20 uint64_t helper_fmax_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2) { - return float64_maxnum(frs1, frs2, &env->fp_status); + return float64_maxnum_noprop(frs1, frs2, &env->fp_status); } =20 uint64_t helper_fcvt_s_d(CPURISCVState *env, uint64_t rs1) --=20 2.25.1