From nobody Sun Apr 28 17:17:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518047161775961.0241096307285; Wed, 7 Feb 2018 15:46:01 -0800 (PST) Received: from localhost ([::1]:45299 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejZPc-00009G-Nx for importer@patchew.org; Wed, 07 Feb 2018 18:46:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47123) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejZOT-0007vu-Li for qemu-devel@nongnu.org; Wed, 07 Feb 2018 18:44:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ejZOQ-0001kt-If for qemu-devel@nongnu.org; Wed, 07 Feb 2018 18:44:49 -0500 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:35244) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ejZOQ-0001jw-B8 for qemu-devel@nongnu.org; Wed, 07 Feb 2018 18:44:46 -0500 Received: by mail-pf0-x243.google.com with SMTP id y9so1031874pfl.2 for ; Wed, 07 Feb 2018 15:44:46 -0800 (PST) Received: from localhost.localdomain (125-237-39-90.jetstream.xtra.co.nz. [125.237.39.90]) by smtp.gmail.com with ESMTPSA id q20sm5595630pfh.178.2018.02.07.15.44.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Feb 2018 15:44:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id; bh=38Hvr/IjuE/y5IorxUtq3wdh8SbKo4nBqaxSG01GcKc=; b=VbLnpSqFcmU4sEWSN0AS+IOH94KeEqfSuP/eT8mn/9uoY9OUG3t6R+ixWGwkJxSXSR v8OljZWeGLFshYnfM5IeL3Rit1/d85Aw9Y9rGE0IHfROpETg168IvYPxbTkPjTyIwt6W KY+s4Dv3UHNOaVbmkx3AaQsS/aJfw8SPW3EahYDbIbEOPl8oRlbYMgJGSx7SDolu7U2W PO+1JCY8z9aEZ/zm4bKxx6UlytK/c9Ck2poit67tbPA2ZpLj8oZg6UqXsIKfdeJO0/6X X4d+MeOEkmppCou4cpiWmAHE0bYmvjGaEt+AQD4+/54dAAOcN7CHKpCGAAH+5mQTmFp1 KxDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=38Hvr/IjuE/y5IorxUtq3wdh8SbKo4nBqaxSG01GcKc=; b=sF9sCu98W6Du04TvtKFYQiyMUvbwvLigvAEREeqHC7sV+s8Rk8J1Cmc4RP2fs3eGEp qLGVLCZmei5rv4Q4UVppvjXm+NlN4neB8BLimEXpLvy07AzGUODNdBoM/PU1yQSPuiEr nuhFeiBHSmVSmjnoSZDnWJx0OoCV6/10MHJXuy1JmD5oCZgW8b3ixEfxZ5soPLcqNdyf LsUELo4jzc1s4nCGTYSLTx0zeDrfI2sIAEgmwjG5bzS9bNV/eWF4qhA8c3h2cpqOuz1Y 3UDJnD7qgPmkLTKLeryRcbIKDTlBJ4dD+5bByuP824Mix2RmzieXmItZACjg0+IIFhbw DaYA== X-Gm-Message-State: APf1xPBsdSjQDFmAhc73nzNtGiyFyherbT4Rw3s9jpjtNvscRjYB/HLV tWbppHkPTtSHbitl04pJiU4ud45QX1w= X-Google-Smtp-Source: AH8x226bKaDKaMKCNHeU05lW7ldKTuk9TdddigNCNYMcJ/kbpl9V4+AVlQjzO80g43QJG1qJbdhCQg== X-Received: by 10.99.99.198 with SMTP id x189mr6330245pgb.248.1518047084994; Wed, 07 Feb 2018 15:44:44 -0800 (PST) From: Michael Clark To: qemu-devel@nongnu.org, Aurelien Jarno , Peter Maydell Date: Thu, 8 Feb 2018 12:43:17 +1300 Message-Id: <1518046997-22714-1-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::243 Subject: [Qemu-devel] [PATCH v1] Implement support for IEEE 754-201x minimumNumber/maximumNumber X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Clark Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" QEMU currently implements IEEE 754-2008 minNum/maxNum. This patch adds support for IEEE 754-201x minimumNumber/maximumNumber which is required by the RISC-V port. minNum(x, y) is defined as - min(x, y) if neither is NaN - if one of x and y is a number and one is qNaN, return the number - if both are qNaN, or either is sNaN, return NaN minimumNumber(x, y) is defined as - min(x, y) if neither is NaN - if one of x and y is a number and one is qNaN or sNaN, return the number - if both are NaN, return the number Both functions signal the invalid exception on sNaN inputs. Signed-off-by: Michael Clark --- fpu/softfloat.c | 41 +++++++++++++++++++++++++++++++++++------ include/fpu/softfloat.h | 4 ++++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 433c5da..5793cc9 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -7675,6 +7675,9 @@ int float128_compare_quiet(float128 a, float128 b, fl= oat_status *status) * minnummag() and maxnummag() functions correspond to minNumMag() * and minNumMag() from the IEEE-754 2008. */ + +enum { ieee2008 =3D 1, ieee201x =3D 2 }; + #define MINMAX(s) \ static inline float ## s float ## s ## _minmax(float ## s a, float ## s b,= \ int ismin, int isieee, \ @@ -7687,12 +7690,26 @@ static inline float ## s float ## s ## _minmax(floa= t ## s a, float ## s b, \ b =3D float ## s ## _squash_input_denormal(b, status); \ if (float ## s ## _is_any_nan(a) || \ float ## s ## _is_any_nan(b)) { \ - if (isieee) { \ + if (isieee =3D=3D ieee2008) { = \ if (float ## s ## _is_quiet_nan(a, status) && \ !float ## s ##_is_any_nan(b)) { \ return b; \ } else if (float ## s ## _is_quiet_nan(b, status) && \ - !float ## s ## _is_any_nan(a)) { \ + !float ## s ## _is_any_nan(a)) { \ + return a; \ + } \ + } else if (isieee =3D=3D ieee201x) { = \ + if (float ## s ## _is_any_nan(a) && \ + !float ## s ##_is_any_nan(b)) { \ + if (!float ## s ## _is_quiet_nan(a, status)) { \ + float_raise(float_flag_invalid, status); \ + } \ + return b; \ + } else if (float ## s ## _is_any_nan(b) && \ + !float ## s ## _is_any_nan(a)) { \ + if (!float ## s ## _is_quiet_nan(b, status)) { \ + float_raise(float_flag_invalid, status); \ + } \ return a; \ } \ } \ @@ -7743,25 +7760,37 @@ float ## s float ## s ## _max(float ## s a, float #= # s b, \ float ## s float ## s ## _minnum(float ## s a, float ## s b, \ float_status *status) \ { \ - return float ## s ## _minmax(a, b, 1, 1, 0, status); \ + return float ## s ## _minmax(a, b, 1, ieee2008, 0, status); \ } \ \ float ## s float ## s ## _maxnum(float ## s a, float ## s b, \ float_status *status) \ { \ - return float ## s ## _minmax(a, b, 0, 1, 0, status); \ + return float ## s ## _minmax(a, b, 0, ieee2008, 0, status); \ +} \ + \ +float ## s float ## s ## _minimumnumber(float ## s a, float ## s b, \ + float_status *status) \ +{ \ + return float ## s ## _minmax(a, b, 1, ieee201x, 0, status); \ +} \ + \ +float ## s float ## s ## _maximumnumber(float ## s a, float ## s b, \ + float_status *status) \ +{ \ + return float ## s ## _minmax(a, b, 0, ieee201x, 0, status); \ } \ \ float ## s float ## s ## _minnummag(float ## s a, float ## s b, \ float_status *status) \ { \ - return float ## s ## _minmax(a, b, 1, 1, 1, status); \ + return float ## s ## _minmax(a, b, 1, ieee2008, 1, status); \ } \ \ float ## s float ## s ## _maxnummag(float ## s a, float ## s b, \ float_status *status) \ { \ - return float ## s ## _minmax(a, b, 0, 1, 1, status); \ + return float ## s ## _minmax(a, b, 0, ieee2008, 1, status); \ } =20 MINMAX(32) diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h index 0f96a0e..e0d0259 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -424,6 +424,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_minimumnumber(float32, float32, float_status *status); +float32 float32_maximumnumber(float32, float32, float_status *status); float32 float32_minnummag(float32, float32, float_status *status); float32 float32_maxnummag(float32, float32, float_status *status); int float32_is_quiet_nan(float32, float_status *status); @@ -536,6 +538,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_minimumnumber(float64, float64, float_status *status); +float64 float64_maximumnumber(float64, float64, float_status *status); float64 float64_minnummag(float64, float64, float_status *status); float64 float64_maxnummag(float64, float64, float_status *status); int float64_is_quiet_nan(float64 a, float_status *status); --=20 2.7.0