From nobody Mon Feb 9 11:51:45 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 ARC-Seal: i=1; a=rsa-sha256; t=1588635706; cv=none; d=zohomail.com; s=zohoarc; b=CuBEgCnsr1hioDL1NK0OTf1hUK5Pd/67iz6hQgVoEFdOvw+4kxqYwb+/7A2xxUDWPAr7tC7XMb6e22BXJu65BMZmkucPgPdgprPZQwP7WvwOJI95rfmJGqjmUdvhnzGLvrh/K8vKY3PCq0lE/Aaxfxbro56TUr8hM02dFVTThNw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588635706; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NvTzfxLO+s1QPGGMzPdqp46E6e+zZS5S116HfvQ++TE=; b=bLOdsBimXlzkx8MGGXzLC5J63JbAFgy3oocLoznlVfDpmXp1wtCRqr8HeZHs8Oc622V0JMUsi6Y9fqbNlZlLjC3RalRX0YIxs8Jzlh2LzgJl9FYif7JKiAEeBNTYH8Wjz3pElSA1UkVCodvwmUj1dUItJZ1hzbwDNDOwCHxmAO4= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 158863570672416.789967846018044; Mon, 4 May 2020 16:41:46 -0700 (PDT) Received: from localhost ([::1]:35108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jVkiX-0006R7-7y for importer@patchew.org; Mon, 04 May 2020 19:41:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37998) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jVkfv-0003lm-IC for qemu-devel@nongnu.org; Mon, 04 May 2020 19:39:03 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:20501) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jVkfn-000324-BC for qemu-devel@nongnu.org; Mon, 04 May 2020 19:39:03 -0400 Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 04 May 2020 15:38:50 -0800 IronPort-SDR: sU5Xav6K+YF3Ftch3aBOSo6n8UJFKcJ0uadN9LiwqlfG4Tnw5KDYTW+qwbvHFTSLPULjEYCHn+ 9bYvhvBkkBbMPTp3EreGopwhuiMT9qqyvns2mHDnWd3a2zEWzw2W6RHNIEH/QH0/IF6QztTEPW SNFhwC3cLCw0MHRnZg/HPysj7q7m4s2+tJ+FdqViMlPDEJSsJiDpIrPztAibITu4STQU3xhdnd bciXTrRNF/FAjEy2UYG9bBighCGitSf7w760wRevbhqUq8NxFuGaByGdVHc1l9MS0tayVc2p9o 8v4= X-IronPort-AV: E=Sophos;i="5.73,353,1583222400"; d="scan'208";a="50530968" IronPort-SDR: r736D0AQBFRcBlWteS2D8ILqvW3m1g6/1TovYKeOEz914osYYhnptdI3hyS+qGpVbqxEeCLVyX dL3r/9CcHFhjqip9ZGikRritSx4vxDEvBqY0KKe2a8hH9b5TYR74/B+E8nxUGzii+vKuP81tWm HV/2MOXU46d6UVCv7qsQgAhjrbU4yKeot3d+SiaQONW7svcrgPtlBHSwMpiza7CBE1uPEOl+Hp BOdz3OFL/ewp5ZP01g+/IujqO1zqiIRBbhNFRpNxdbpRtE7ykBXx1Epud4nOzlmYAqwe+fs/CN 94k= Date: Mon, 4 May 2020 23:38:44 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: , , , , , , Subject: [PATCH v2 2/4] softfloat: fix floatx80 pseudo-denormal addition / subtraction 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-01.mgc.mentorg.com (139.181.222.1) 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=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/05/04 19:38:51 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_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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 ++++++ tests/tcg/i386/test-i386-pseudo-denormal.c | 24 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/tcg/i386/test-i386-pseudo-denormal.c 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 =3D 0; zSig0 =3D aSig + bSig; if ( aExp =3D=3D 0 ) { + if ((aSig | bSig) & UINT64_C(0x8000000000000000) && zSig0 < aS= ig) { + /* At least one of the values is a pseudo-denormal, + * and there is a carry out of the result. */ + zExp =3D 1; + goto shiftRight1; + } if (zSig0 =3D=3D 0) { return packFloatx80(zSign, 0, 0); } diff --git a/tests/tcg/i386/test-i386-pseudo-denormal.c b/tests/tcg/i386/te= st-i386-pseudo-denormal.c new file mode 100644 index 0000000000..cfa2a500b0 --- /dev/null +++ b/tests/tcg/i386/test-i386-pseudo-denormal.c @@ -0,0 +1,24 @@ +/* Test pseudo-denormal operations. */ + +#include +#include + +union u { + struct { uint64_t sig; uint16_t sign_exp; } s; + long double ld; +}; + +volatile union u ld_pseudo_m16382 =3D { .s =3D { UINT64_C(1) << 63, 0 } }; + +volatile long double ld_res; + +int main(void) +{ + int ret =3D 0; + ld_res =3D ld_pseudo_m16382.ld + ld_pseudo_m16382.ld; + if (ld_res !=3D 0x1p-16381L) { + printf("FAIL: pseudo-denormal add\n"); + ret =3D 1; + } + return ret; +} --=20 2.17.1 --=20 Joseph S. Myers joseph@codesourcery.com