From patchwork Fri May 1 00:38:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 283619 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 0F00DC47247 for ; Fri, 1 May 2020 00:40:24 +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 D472420757 for ; Fri, 1 May 2020 00:40:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D472420757 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]:54450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUJj4-0008UQ-Si for qemu-devel@archiver.kernel.org; Thu, 30 Apr 2020 20:40:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39274) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUJhS-0006gn-Lf for qemu-devel@nongnu.org; Thu, 30 Apr 2020 20:38:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jUJhO-0001PX-Kt for qemu-devel@nongnu.org; Thu, 30 Apr 2020 20:38:42 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:50663) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jUJhH-0000q2-Hb for qemu-devel@nongnu.org; Thu, 30 Apr 2020 20:38:31 -0400 IronPort-SDR: NzgG2ZN8FDdUKs5X1wc1tLbu1mJy/JuADaXL6FyxCuEb6/oQ3G9wAAV1og/dUVaZkm5MZPCJfa 0l/o9p+7UVlId4QhrtIUjX/QgrKXopSVOZdYAMrIk/mj/5jsoe2LSkDK2S4M2bJi2oEHGYk+55 CukxClcT7s7BmclxnhEnyoxd07yGPZ0q8QDTn5MBaP/t4qq0Z809Zuoof1KrKF2xP0rvT5bir7 0aZpQUxf6pmNQmV/as39VvAaLFw+7LMX1X4vd7FPeL8xIyY/LPm5dbFWEG7V9unuiz9U208TQ6 1IA= X-IronPort-AV: E=Sophos;i="5.73,337,1583222400"; d="scan'208";a="50425281" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 30 Apr 2020 16:38:22 -0800 IronPort-SDR: eLLb2kazPkwkSMag9soaFnpE8HLydlDe6PuRFzjfqGmidh67GQyR6VkpJMqe152lOUFdiSspHd Gy9YOpdr4SlMUXrpCzm/srkJDWXxaUXQY/pu/6WGLIXG0Qv3bksHaILJ/kU9OVHJDEbLkkUHjQ ZDsF00rvBMiSKQeKRx6cOI56xVlkkp+kX/m7vrk/okb8Krpj1GeWO2T9YaWopBg3wh5Mcy2xSM ocTSvfRcN6WTsIB/APouOM0BaEoL8eorRtaYlacS/q5CJv0DFVuolyBcaOvwwnRX+WRUtGJL5k hQ4= Date: Fri, 1 May 2020 00:38:17 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: Subject: [PATCH 2/4] softfloat: fix floatx80 pseudo-denormal addition / subtraction Message-ID: 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-02.mgc.mentorg.com (139.181.222.2) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) Received-SPF: pass client-ip=68.232.129.153; envelope-from=joseph_myers@mentor.com; helo=esa1.mentor.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/30 20:38:23 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Received-From: 68.232.129.153 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 softfloat function addFloatx80Sigs, used for addition of values with the same sign and subtraction of values with opposite sign, fails to handle the case where the two values both have biased exponent zero and there is a carry resulting from adding the significands, which can occur if one or both values are pseudo-denormals (biased exponent zero, explicit integer bit 1). Add a check for that case, so making the results match those seen on x86 hardware for pseudo-denormals. Signed-off-by: Joseph Myers --- fpu/softfloat.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index ac116c70b8..6094d267b5 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -5866,6 +5866,12 @@ static floatx80 addFloatx80Sigs(floatx80 a, floatx80 b, flag zSign, zSig1 = 0; zSig0 = aSig + bSig; if ( aExp == 0 ) { + if ((aSig | bSig) & UINT64_C(0x8000000000000000) && zSig0 < aSig) { + /* At least one of the values is a pseudo-denormal, + * and there is a carry out of the result. */ + zExp = 1; + goto shiftRight1; + } if (zSig0 == 0) { return packFloatx80(zSign, 0, 0); } From patchwork Fri May 1 00:39:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 283618 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 01A2CC4724C for ; Fri, 1 May 2020 00:42:29 +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 C862C20757 for ; Fri, 1 May 2020 00:42:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C862C20757 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]:58550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUJl5-0001sN-Vd for qemu-devel@archiver.kernel.org; Thu, 30 Apr 2020 20:42:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44812) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUJj7-0000TD-Ad for qemu-devel@nongnu.org; Thu, 30 Apr 2020 20:40:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jUJij-0004BV-8G for qemu-devel@nongnu.org; Thu, 30 Apr 2020 20:40:22 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:64093) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jUJie-0003sN-JL for qemu-devel@nongnu.org; Thu, 30 Apr 2020 20:39:57 -0400 IronPort-SDR: M5EV7SYg60fP9Ef37em9bQLxf97grpwBTJ1Lmjhw5/yxOd+1G5hLOR/GnWrip0o2c1HsHvOgoU bqLAp7vUFRUcVx1ouK1q3//6THtq+Vjl4ATV9jsHPeLvBacnlN2I0YcXvW0T91Xi4bK7zO4z+c se/104EqNjq60H6FzpB1wFWSoDYGBJAMub/fp0jTirfPBCPeeMhKKBNJivSW/SSDUenu/rbggB ba3hO4s1VyA73r6Kxq9RYoDVS39lNlSk9yhkq4MC0hEBmm4nFdaNi4acZukseRpgluJCDFsWbn yJw= X-IronPort-AV: E=Sophos;i="5.73,337,1583222400"; d="scan'208";a="50425318" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 30 Apr 2020 16:39:53 -0800 IronPort-SDR: SdFsOwrAIhY1otDszQsp5ZO2F12gB4UdYlCvQ9IWKrsptf7AihP2wRaSo/K+2xSU75jrZMmjDE 5ApwaGRAo3DaLIuHfmYPjWkXf2MI066qXPd17nZVo8JyYnbUnP46x8tItjejPkGfzmFMfXJFBv q9+T3UYpOKbZaNARYyV5CYOwo86BAhkWwPN4mHR+bUFE54AnigkdVlLUCZC9bnfk8rMJgSWFRa yqaef+AwhsNrPUPge45wpUa+lVolFnmjLVCulLrfZWkaa1msDFBkApY7Jpz2QLrCDaiztQq8r4 +TE= Date: Fri, 1 May 2020 00:39:47 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: Subject: [PATCH 4/4] softfloat: fix floatx80 pseudo-denormal round to integer Message-ID: 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-01.mgc.mentorg.com (139.181.222.1) Received-SPF: pass client-ip=68.232.129.153; envelope-from=joseph_myers@mentor.com; helo=esa1.mentor.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/30 20:38:23 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Received-From: 68.232.129.153 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 softfloat function floatx80_round_to_int incorrectly handles the case of a pseudo-denormal where only the high bit of the significand is set, ignoring that bit (treating the number as an exact zero) rather than treating the number as an alternative representation of +/- 2^-16382 (which may round to +/- 1 depending on the rounding mode) as hardware does. Fix this check (simplifying the code in the process). Signed-off-by: Joseph Myers --- fpu/softfloat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 8e9c714e6f..e29b07542a 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -5741,7 +5741,7 @@ floatx80 floatx80_round_to_int(floatx80 a, float_status *status) } if ( aExp < 0x3FFF ) { if ( ( aExp == 0 ) - && ( (uint64_t) ( extractFloatx80Frac( a )<<1 ) == 0 ) ) { + && ( (uint64_t) ( extractFloatx80Frac( a ) ) == 0 ) ) { return a; } status->float_exception_flags |= float_flag_inexact;