From patchwork Mon Jun 8 16:55:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 281137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24F53C433DF for ; Mon, 8 Jun 2020 16:58:33 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EF6FF2053B for ; Mon, 8 Jun 2020 16:58:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EF6FF2053B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jiL6W-0006il-5r for qemu-devel@archiver.kernel.org; Mon, 08 Jun 2020 12:58:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45630) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jiL42-0002UF-KH for qemu-devel@nongnu.org; Mon, 08 Jun 2020 12:55:58 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:56090) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jiL41-0001IK-GV for qemu-devel@nongnu.org; Mon, 08 Jun 2020 12:55:58 -0400 IronPort-SDR: ql57E+003yQnaPJp0GhTgwqKR/82inqOjDDiXo7VNsOCmjoxYvbQlF18j+/Bnh8VGm60lrgbrs p+mudAD6ffs++kgonyPLiWNu6CVQDONGiE08vJUJlrxElXCTjzP03x1HqFhTUdjsqi2gvL2hCL DLt8XSnU1rZD1cZZG46HDgLKjbHEEE0OWXvQ0c9zQWRvnszNpmXpNTq6ccUYaIHOdTdB+yMUlN pN2ckEjGx0a6mmsKaZnfur/TWbD20lK/HEkNteDC7zDMFAtaaisF/rEDdv88O13UOo5Fs87/Qi wFQ= X-IronPort-AV: E=Sophos;i="5.73,487,1583222400"; d="scan'208";a="49575512" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 08 Jun 2020 08:55:55 -0800 IronPort-SDR: w3EuSRjwLbHZ0RpVgydBxcPqqLrcNp8pw1m0G74JWBYGMqk1hSmlf/lHCstxe8jA9H7z3cX694 haGnyxTFP3I7AdebymYWA+jWHAa+EUns8iGa9+kgB8EdcwEA1W1MCq6trN1fU4GOaF24/mMKMs Dojz9J8NAvae2nQKKla0j15WptbhGTSZoKtyRIgIUtZRce7A0vLQcVEf20ZW/CoIsFcABWup8a ZvFHxlJdfDJ+h21iUbBbB39Et2YrwGVkx4vgsM3fUsmnySu4qEY/gViXjNoSRzj3v+vdRMLHWM YqI= Date: Mon, 8 Jun 2020 16:55:49 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: , , , , , , , Subject: [PATCH v2 2/6] softfloat: fix floatx80 remainder pseudo-denormal check for zero In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-03.mgc.mentorg.com (139.181.222.3) To svr-ies-mbx-02.mgc.mentorg.com (139.181.222.2) Received-SPF: pass client-ip=68.232.141.98; envelope-from=joseph_myers@mentor.com; helo=esa2.mentor.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/08 12:55:55 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The floatx80 remainder implementation ignores the high bit of the significand when checking whether an operand (numerator) with zero exponent is zero. This means it mishandles a pseudo-denormal representation of 0x1p-16382L by treating it as zero. Fix this by checking the whole significand instead. Signed-off-by: Joseph Myers Reviewed-by: Richard Henderson --- fpu/softfloat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 7b1ce7664f..091847beb9 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -5726,7 +5726,7 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod, normalizeFloatx80Subnormal( bSig, &bExp, &bSig ); } if ( aExp == 0 ) { - if ( (uint64_t) ( aSig0<<1 ) == 0 ) return a; + if ( aSig0 == 0 ) return a; normalizeFloatx80Subnormal( aSig0, &aExp, &aSig0 ); } bSig |= UINT64_C(0x8000000000000000); From patchwork Mon Jun 8 16:57:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 281135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2CB6C433E0 for ; Mon, 8 Jun 2020 17:03:20 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 973022053B for ; Mon, 8 Jun 2020 17:03:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 973022053B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:58974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jiLB9-0004FF-NF for qemu-devel@archiver.kernel.org; Mon, 08 Jun 2020 13:03:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jiL5R-0004sP-DY for qemu-devel@nongnu.org; Mon, 08 Jun 2020 12:57:25 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:9046) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jiL5Q-0001VG-6K for qemu-devel@nongnu.org; Mon, 08 Jun 2020 12:57:25 -0400 IronPort-SDR: L4DFM5pBJVnOB5D7ux5GBWd1sfxK9BQH5qL2ZPXOUbi4Xn45Z3U+ABpXPs72FSnohYBVblpSvZ b3r/wuigSkgehlKVJ3vZjH18QKypIYAvUxGIAxDq4qAbKw4htqlMw2IxDg8c8pWTosN5LxsqXj zwWkSu2kyVO8uD2uDwtXVI0eJ4h/ujOCYs0fQqHOlrW5nFFx6n4oh7SrVGajornb8et66+r/zh Yjxkzo7sH3Pqc88nr1uAm/UHR9x0gG+PIz0voFsXKxeiY/1/ezDVq/HOjr2xl2ZVJ/j5ViKZyV nuo= X-IronPort-AV: E=Sophos;i="5.73,487,1583222400"; d="scan'208";a="49689901" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 08 Jun 2020 08:57:22 -0800 IronPort-SDR: jke4R6POX1Lkh23iXyL1UHrNr7WeIOj7VOuSqAsu+rgZJhvPd1lKb1T9K/IzZkt/4N+3x8dY2K lGdRYAWTqol/lQe+lawd4N1QEsW9XuEeYUhMl4FIMekqMwSrWzpi+jqHEygtt1jIzpTDangcBH s9n/SME9uOQMrjM6vHAeQMVDaftvTu6Ly8giqpg0ifaFKV6vIxSUpUAslsGGwVKPB+Y0LBlBRL dMtaUIOXJq1TFj6Yrgd4UXIG96MPiWXAyAKb8IMeWftQte//hhR9WXcuDKKxbWfpy+a9GlIbaU WO8= Date: Mon, 8 Jun 2020 16:57:16 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: , , , , , , , Subject: [PATCH v2 5/6] softfloat: return low bits of quotient from floatx80_modrem In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) To svr-ies-mbx-02.mgc.mentorg.com (139.181.222.2) Received-SPF: pass client-ip=68.232.137.252; envelope-from=joseph_myers@mentor.com; helo=esa4.mentor.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/08 12:55:19 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Both x87 and m68k need the low parts of the quotient for their remainder operations. Arrange for floatx80_modrem to track those bits and return them via a pointer. The architectures using float32_rem and float64_rem do not appear to need this information, so the *_rem interface is left unchanged and the information returned only from floatx80_modrem. The logic used to determine the low 7 bits of the quotient for m68k (target/m68k/fpu_helper.c:make_quotient) appears completely bogus (it looks at the result of converting the remainder to integer, the quotient having been discarded by that point); this patch does not change that, but the m68k maintainers may wish to do so. Signed-off-by: Joseph Myers Reviewed-by: Richard Henderson --- fpu/softfloat.c | 23 ++++++++++++++++++----- include/fpu/softfloat.h | 3 ++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 1552241b5e..72f45b0103 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -5684,10 +5684,11 @@ floatx80 floatx80_div(floatx80 a, floatx80 b, float_status *status) | `a' with respect to the corresponding value `b'. The operation is performed | according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic, | if 'mod' is false; if 'mod' is true, return the remainder based on truncating -| the quotient toward zero instead. +| the quotient toward zero instead. '*quotient' is set to the low 64 bits of +| the absolute value of the integer quotient. *----------------------------------------------------------------------------*/ -floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod, +floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod, uint64_t *quotient, float_status *status) { bool aSign, zSign; @@ -5695,6 +5696,7 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod, uint64_t aSig0, aSig1, bSig; uint64_t q, term0, term1, alternateASig0, alternateASig1; + *quotient = 0; if (floatx80_invalid_encoding(a) || floatx80_invalid_encoding(b)) { float_raise(float_flag_invalid, status); return floatx80_default_nan(status); @@ -5753,7 +5755,7 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod, shift128Right( aSig0, 0, 1, &aSig0, &aSig1 ); expDiff = 0; } - q = ( bSig <= aSig0 ); + *quotient = q = ( bSig <= aSig0 ); if ( q ) aSig0 -= bSig; expDiff -= 64; while ( 0 < expDiff ) { @@ -5763,6 +5765,8 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod, sub128( aSig0, aSig1, term0, term1, &aSig0, &aSig1 ); shortShift128Left( aSig0, aSig1, 62, &aSig0, &aSig1 ); expDiff -= 62; + *quotient <<= 62; + *quotient += q; } expDiff += 64; if ( 0 < expDiff ) { @@ -5776,6 +5780,12 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod, ++q; sub128( aSig0, aSig1, term0, term1, &aSig0, &aSig1 ); } + if (expDiff < 64) { + *quotient <<= expDiff; + } else { + *quotient = 0; + } + *quotient += q; } else { term1 = 0; @@ -5790,6 +5800,7 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod, aSig0 = alternateASig0; aSig1 = alternateASig1; zSign = ! zSign; + ++*quotient; } } return @@ -5806,7 +5817,8 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod, floatx80 floatx80_rem(floatx80 a, floatx80 b, float_status *status) { - return floatx80_modrem(a, b, false, status); + uint64_t quotient; + return floatx80_modrem(a, b, false, "ient, status); } /*---------------------------------------------------------------------------- @@ -5817,7 +5829,8 @@ floatx80 floatx80_rem(floatx80 a, floatx80 b, float_status *status) floatx80 floatx80_mod(floatx80 a, floatx80 b, float_status *status) { - return floatx80_modrem(a, b, true, status); + uint64_t quotient; + return floatx80_modrem(a, b, true, "ient, status); } /*---------------------------------------------------------------------------- diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h index bff6934d09..ff4e2605b1 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -687,7 +687,8 @@ floatx80 floatx80_add(floatx80, floatx80, float_status *status); floatx80 floatx80_sub(floatx80, floatx80, float_status *status); floatx80 floatx80_mul(floatx80, floatx80, float_status *status); floatx80 floatx80_div(floatx80, floatx80, float_status *status); -floatx80 floatx80_modrem(floatx80, floatx80, bool, float_status *status); +floatx80 floatx80_modrem(floatx80, floatx80, bool, uint64_t *, + float_status *status); floatx80 floatx80_mod(floatx80, floatx80, float_status *status); floatx80 floatx80_rem(floatx80, floatx80, float_status *status); floatx80 floatx80_sqrt(floatx80, float_status *status);