From nobody Sun May 19 19:01:00 2024 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=1588635977; cv=none; d=zohomail.com; s=zohoarc; b=afzuAS5zmt7mmh5oq7OyulqndoMNhOQvfZSVEjpo4BAUVabOnM03sgCjqqS/u8kv7XYohrS7pSjDs5QzAdyzmig+GRy3h3xh5LIN34lihYx0/Fsswt8GHqI3KAH6A72xv0+kTD1zkaSywcmnGt+70UVxYUkKIzQcXE4mPk5DUIg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588635977; 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=0ILu1U7iP+90fpkV/yX0TrhTmY6pIvgHcAXFZB0ChlI=; b=LvcDWW2nMfbX+u0IqbmDQZivjHYQcIYznIa85qohh1r3YGzQDo5xVqAKEp9Oe/uiCOHOq2/61Mmi43uqpQ47by0KV4Aj2Cy9L69a1OXgkhgvOTmLTOMFZomhVzX2B1UfkEpTvb/H+yOWXUmW2K+i+ILREHCzsp1e3NucGNO7qtY= 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 15886359777672.652315827665575; Mon, 4 May 2020 16:46:17 -0700 (PDT) Received: from localhost ([::1]:46054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jVkmu-0002eN-8t for importer@patchew.org; Mon, 04 May 2020 19:46:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35524) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jVkey-0002oU-8r for qemu-devel@nongnu.org; Mon, 04 May 2020 19:38:04 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:10519) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jVkew-00024f-PW for qemu-devel@nongnu.org; Mon, 04 May 2020 19:38:03 -0400 Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 04 May 2020 15:38:01 -0800 IronPort-SDR: nAh6sP4TPIm9nS5MKcwbMOafW913chdfPbrGtzBhznTnOzliNd0fQGJglExnHmNF7rjbOqmDB5 SGWJAJoeJlKlO3DQ3i1ffcO0eU+ZJbo6wozgPcny4HUkPSBolhTC4KUU2c6cyNrqqdKn+WkM/g i9ydgmLEIn3b1rBuvslBSf+V3YqCjAevq+Ys9tbmSgRJj5i8vMqvJAaq/K8cJl4UCtLpQCL9Nl jfJzhU9xTj+ZOy9R/2VTJII8LVWtKZ/1G/g7L0TyC4P+01DiNQfCobwVacxBevxf1gnb2U1SUv IW4= X-IronPort-AV: E=Sophos;i="5.73,353,1583222400"; d="scan'208";a="48579956" IronPort-SDR: 7pEs3fV6ef80FDW+xwh4O5yI1+IQvk+TKlpMZQBxFZL5lqQILaX7QouL3JnDgCI1v/WpziYkYC 5yvaJ2WuvS/E+zR+eD+3o8ek/6lHNnwSJFqBDsLjFMZiBIkL2I2NurN1immjwVb4HdjmQpDlqH LSya+4fgadhOr/7ajwusavMzXXvp0eySdw5GpsjYIlR4a9fZB96FDsWBFeprz4vcktuwYf9A6u +sHPNUbjiAv61/S4K+KNx5DDiIrFakK07dlCML90zHVbj3CB682cCGxr6dFtv+Knutw1EZPiNY KPQ= Date: Mon, 4 May 2020 23:37:54 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: , , , , , , Subject: [PATCH v2 1/4] softfloat: silence sNaN for conversions to/from floatx80 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-08.mgc.mentorg.com (139.181.222.8) 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.137.252; envelope-from=joseph_myers@mentor.com; helo=esa4.mentor.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/04 19:36: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_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" Conversions between IEEE floating-point formats should convert signaling NaNs to quiet NaNs. Most of those in QEMU's softfloat code do so, but those for floatx80 fail to. Fix those conversions to silence signaling NaNs as well. Signed-off-by: Joseph Myers --- fpu/softfloat.c | 24 +++++++--- tests/tcg/i386/test-i386-snan-convert.c | 63 +++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 tests/tcg/i386/test-i386-snan-convert.c diff --git a/fpu/softfloat.c b/fpu/softfloat.c index ae6ba71854..ac116c70b8 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -4498,7 +4498,9 @@ floatx80 float32_to_floatx80(float32 a, float_status = *status) aSign =3D extractFloat32Sign( a ); if ( aExp =3D=3D 0xFF ) { if (aSig) { - return commonNaNToFloatx80(float32ToCommonNaN(a, status), stat= us); + floatx80 res =3D commonNaNToFloatx80(float32ToCommonNaN(a, sta= tus), + status); + return floatx80_silence_nan(res, status); } return packFloatx80(aSign, floatx80_infinity_high, @@ -5016,7 +5018,9 @@ floatx80 float64_to_floatx80(float64 a, float_status = *status) aSign =3D extractFloat64Sign( a ); if ( aExp =3D=3D 0x7FF ) { if (aSig) { - return commonNaNToFloatx80(float64ToCommonNaN(a, status), stat= us); + floatx80 res =3D commonNaNToFloatx80(float64ToCommonNaN(a, sta= tus), + status); + return floatx80_silence_nan(res, status); } return packFloatx80(aSign, floatx80_infinity_high, @@ -5618,7 +5622,9 @@ float32 floatx80_to_float32(floatx80 a, float_status = *status) aSign =3D extractFloatx80Sign( a ); if ( aExp =3D=3D 0x7FFF ) { if ( (uint64_t) ( aSig<<1 ) ) { - return commonNaNToFloat32(floatx80ToCommonNaN(a, status), stat= us); + float32 res =3D commonNaNToFloat32(floatx80ToCommonNaN(a, stat= us), + status); + return float32_silence_nan(res, status); } return packFloat32( aSign, 0xFF, 0 ); } @@ -5650,7 +5656,9 @@ float64 floatx80_to_float64(floatx80 a, float_status = *status) aSign =3D extractFloatx80Sign( a ); if ( aExp =3D=3D 0x7FFF ) { if ( (uint64_t) ( aSig<<1 ) ) { - return commonNaNToFloat64(floatx80ToCommonNaN(a, status), stat= us); + float64 res =3D commonNaNToFloat64(floatx80ToCommonNaN(a, stat= us), + status); + return float64_silence_nan(res, status); } return packFloat64( aSign, 0x7FF, 0 ); } @@ -5681,7 +5689,9 @@ float128 floatx80_to_float128(floatx80 a, float_statu= s *status) aExp =3D extractFloatx80Exp( a ); aSign =3D extractFloatx80Sign( a ); if ( ( aExp =3D=3D 0x7FFF ) && (uint64_t) ( aSig<<1 ) ) { - return commonNaNToFloat128(floatx80ToCommonNaN(a, status), status); + float128 res =3D commonNaNToFloat128(floatx80ToCommonNaN(a, status= ), + status); + return float128_silence_nan(res, status); } shift128Right( aSig<<1, 0, 16, &zSig0, &zSig1 ); return packFloat128( aSign, aExp, zSig0, zSig1 ); @@ -6959,7 +6969,9 @@ floatx80 float128_to_floatx80(float128 a, float_statu= s *status) aSign =3D extractFloat128Sign( a ); if ( aExp =3D=3D 0x7FFF ) { if ( aSig0 | aSig1 ) { - return commonNaNToFloatx80(float128ToCommonNaN(a, status), sta= tus); + floatx80 res =3D commonNaNToFloatx80(float128ToCommonNaN(a, st= atus), + status); + return floatx80_silence_nan(res, status); } return packFloatx80(aSign, floatx80_infinity_high, floatx80_infinity_low); diff --git a/tests/tcg/i386/test-i386-snan-convert.c b/tests/tcg/i386/test-= i386-snan-convert.c new file mode 100644 index 0000000000..ed6d535ce2 --- /dev/null +++ b/tests/tcg/i386/test-i386-snan-convert.c @@ -0,0 +1,63 @@ +/* Test conversions of signaling NaNs to and from long double. */ + +#include +#include + +volatile float f_res; +volatile double d_res; +volatile long double ld_res; + +volatile float f_snan =3D __builtin_nansf(""); +volatile double d_snan =3D __builtin_nans(""); +volatile long double ld_snan =3D __builtin_nansl(""); + +int issignaling_f(float x) +{ + union { float f; uint32_t u; } u =3D { .f =3D x }; + return (u.u & 0x7fffffff) > 0x7f800000 && (u.u & 0x400000) =3D=3D 0; +} + +int issignaling_d(double x) +{ + union { double d; uint64_t u; } u =3D { .d =3D x }; + return (((u.u & UINT64_C(0x7fffffffffffffff)) > + UINT64_C(0x7ff0000000000000)) && + (u.u & UINT64_C(0x8000000000000)) =3D=3D 0); +} + +int issignaling_ld(long double x) +{ + union { + long double ld; + struct { uint64_t sig; uint16_t sign_exp; } s; + } u =3D { .ld =3D x }; + return ((u.s.sign_exp & 0x7fff) =3D=3D 0x7fff && + (u.s.sig >> 63) !=3D 0 && + (u.s.sig & UINT64_C(0x4000000000000000)) =3D=3D 0); +} + +int main(void) +{ + int ret =3D 0; + ld_res =3D f_snan; + if (issignaling_ld(ld_res)) { + printf("FAIL: float -> long double\n"); + ret =3D 1; + } + ld_res =3D d_snan; + if (issignaling_ld(ld_res)) { + printf("FAIL: double -> long double\n"); + ret =3D 1; + } + f_res =3D ld_snan; + if (issignaling_d(f_res)) { + printf("FAIL: long double -> float\n"); + ret =3D 1; + } + d_res =3D ld_snan; + if (issignaling_d(d_res)) { + printf("FAIL: long double -> double\n"); + ret =3D 1; + } + return ret; +} --=20 2.17.1 --=20 Joseph S. Myers joseph@codesourcery.com From nobody Sun May 19 19:01:00 2024 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 From nobody Sun May 19 19:01:00 2024 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=1588636132; cv=none; d=zohomail.com; s=zohoarc; b=k+qT1NKnMXZlSf3tladsrBEdJEHKABXlAcaxUAfBw9msRxNmfKbM+i2orY5uFdYXDUuOvQ70nlruILSNvKh9aZm0BciJyDhgPbbwHil5VliJ31DKVxbBsNxEmEyJ0wCK9LDJI+hrQUtfZTNwctEAUKxhyHzmkLiSjIhB0Tge160= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588636132; 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=YLgB2u+K/01spa79+PG5lQcPaJ4fbBP3IKWrYhbl44Y=; b=jYis+C7ms/xolXZHj8NbD5pQ/iJqPOZ7bsbRFl90plN2wJENjqXqYpfqrj6Do4vqTLZpVzyeL2ttyU7QaRsMhr+Q176HT9+xqC/GJrdazuRpOZxUHw2oxHymH82z/1ZRtEGspwvdySi6dWAy6l5VB/F/1o6HfSY+QBejeHWKU50= 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 1588636132807644.7526732777541; Mon, 4 May 2020 16:48:52 -0700 (PDT) Received: from localhost ([::1]:52350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jVkpO-0005gU-51 for importer@patchew.org; Mon, 04 May 2020 19:48:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41170) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jVkgl-0004qK-ET for qemu-devel@nongnu.org; Mon, 04 May 2020 19:39:55 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:10580) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jVkgd-0004B2-QH for qemu-devel@nongnu.org; Mon, 04 May 2020 19:39:53 -0400 Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 04 May 2020 15:39:46 -0800 IronPort-SDR: m3gDoFHOE7zhNlO4alM3Gug4FpmcatEE09XYUP2NOpEKiOfB/jvh3Z8JIMJBojnckMKH2Z53Km 1+XXsfZ9ti1JQaHb7rfxzdWvsDuKbMSavUyi3N537r0+Zran838fl7eyu257ehIb8hRhnNt2X4 X+HbABVpdEeXDvr1NsbjuzSBHxELG5N3it/do9pkAWdxrJIZwcWWaIrLjNcecuOo1GK7YbKIAI dZ4LsJArWXS4yeIphJ3u2qIem2duh5OQKJIvJ30cxGhl2YtBOJFhwnxIgBz3J9b/5rAi6ul4m4 3qM= X-IronPort-AV: E=Sophos;i="5.73,353,1583222400"; d="scan'208";a="48579981" IronPort-SDR: o2hG4PvUtA+T6GMgu8uQs4Vqn9bhkL0je1kI4+gPFfZCsMGta42yPkBD//Elogr7lNQ4Y/nyJq Y8PA/369hrPhDDZAYyCsepqbxLIAurht7fFW861ZlHmTeVbFv42ncVNkAzInyy+0gtSMqtB5uH oH8Tzt6LIQIcuynyKEja9GJ6Bo3J0jAdzTkfiqBRI+ppXCve9DVH6X0I+EW6NMAOsrNxL0bDHq f6IDllGfd5SVDUKHTSvGFYSTWLQXJxpKf+fLCL1GwjC11Nnlwo9JpQB52tA8US7P5bqXyW1KEz lJQ= Date: Mon, 4 May 2020 23:39:39 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: , , , , , , Subject: [PATCH v2 3/4] softfloat: fix floatx80 pseudo-denormal comparisons 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-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.137.252; envelope-from=joseph_myers@mentor.com; helo=esa4.mentor.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/04 19:36: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_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 floatx80 comparisons fail to allow for pseudo-denormals, which should compare equal to corresponding values with biased exponent 1 rather than 0. Add an adjustment for that case when comparing numbers with the same sign. Note that this fix only changes floatx80_compare_internal, not the other more specific comparison operations. That is the only comparison function for floatx80 used in the i386 port, which is the only supported port with these pseudo-denormal semantics. Signed-off-by: Joseph Myers --- fpu/softfloat.c | 5 +++++ tests/tcg/i386/test-i386-pseudo-denormal.c | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 6094d267b5..8e9c714e6f 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -7966,6 +7966,11 @@ static inline int floatx80_compare_internal(floatx80= a, floatx80 b, return 1 - (2 * aSign); } } else { + /* Normalize pseudo-denormals before comparison. */ + if ((a.high & 0x7fff) =3D=3D 0 && a.low & UINT64_C(0x8000000000000= 000)) + ++a.high; + if ((b.high & 0x7fff) =3D=3D 0 && b.low & UINT64_C(0x8000000000000= 000)) + ++b.high; if (a.low =3D=3D b.low && a.high =3D=3D b.high) { return float_relation_equal; } else { diff --git a/tests/tcg/i386/test-i386-pseudo-denormal.c b/tests/tcg/i386/te= st-i386-pseudo-denormal.c index cfa2a500b0..acf2b9cf03 100644 --- a/tests/tcg/i386/test-i386-pseudo-denormal.c +++ b/tests/tcg/i386/test-i386-pseudo-denormal.c @@ -20,5 +20,9 @@ int main(void) printf("FAIL: pseudo-denormal add\n"); ret =3D 1; } + if (ld_pseudo_m16382.ld !=3D 0x1p-16382L) { + printf("FAIL: pseudo-denormal compare\n"); + ret =3D 1; + } return ret; } --=20 2.17.1 --=20 Joseph S. Myers joseph@codesourcery.com From nobody Sun May 19 19:01:00 2024 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=1588636252; cv=none; d=zohomail.com; s=zohoarc; b=M25hmp+z0eihCInriFsuLGDcCpdLh9O2WrooEYJyeswqA4YOJ+0PyUvqdbqPXMEk09TuM3lVgnEvHn/eK2uWLkAgbgzRf1kdsKi6ajyJRkIq0kG8AaTQ7RoaDxvXwq+vmpVyJYyqMF+kA9SG9FlzzTEHPYeWWKwhe+ifHVK5aJE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588636252; 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=jXF4/AeEsfFoZgffxl7cMkbufn/4aQWC2xDrxRU7hI4=; b=LR+UwX7K1CBw1tBbeUKxlvxAWVRzQIhLpaK1IbucQl2+S4IbGMULF0U/fUpbQFOrHbivdTPf/y02fNoD4AjXbGB2FhzVQjDsG2C4bQBlQNITC8zlPKP/tIUNwFdntp6AfQyC9IYebuYTC2TKTEa62xZhKmXpJzbCnpf8hEa0ug0= 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 1588636252290206.28462670624754; Mon, 4 May 2020 16:50:52 -0700 (PDT) Received: from localhost ([::1]:58556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jVkrK-0008OQ-Tm for importer@patchew.org; Mon, 04 May 2020 19:50:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jVkhK-0005W6-PA for qemu-devel@nongnu.org; Mon, 04 May 2020 19:40:30 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:56982) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jVkhJ-00051P-26 for qemu-devel@nongnu.org; Mon, 04 May 2020 19:40:30 -0400 Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 04 May 2020 15:40:26 -0800 IronPort-SDR: k+6E3kast7bqw+SHecXMvVr4wWD4b4dJI6r8/fhKPYPn2KgziKNNdUwTZHfm5E27g9ZbiRZPBR jUPkPdqqCKBsEvBQ6gXNym/GNmdBRvCfnFVwxoKnbWFvJTHbA4eup0Dw2fQ44E5pzI2xyc1BpC sL7N4I60gOj854FghIL2QFIGjeeyAdKNQLnhv1bqgGwSlKs2ctAM1uNI75XrXG8Daw1G9Fxwn3 rhp9DTDjWFWu4GeXYJegHazWfNM7i8OdeAz/P3byY+nFoHFau/WcJ1mERUeuGDJPDkWqLuRPFx 0VY= X-IronPort-AV: E=Sophos;i="5.73,353,1583222400"; d="scan'208";a="48455809" IronPort-SDR: oitUw0oqvz3OL0p7M1vIxWB6mSbIRwBsAJAB0o7C2Bxy0+564SwnyqImluokHjYAuieeDIcWZR G/CyBsU5FJ9F83v6yKTJ0suZYh/LnASLaMzhRfVDfaj0qhD+3j5X/kHMpw7IgTaWwJ6BQwifwt cYCtnhbU78nzWdb6QGte/gW92AlN13Z+nWcJaNUwa1eixlrEdvsgtvFX3+3cwKkpnmQsCcscV4 gWR+7pdKUFgeUL17HtKcFup9BDB457a6tBNZODNtON/BgFY6DHeuBAqpHno8buZWHHxQV15dCB xQI= Date: Mon, 4 May 2020 23:40:20 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: , , , , , , Subject: [PATCH v2 4/4] softfloat: fix floatx80 pseudo-denormal round to integer 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-07.mgc.mentorg.com (139.181.222.7) 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.141.98; envelope-from=joseph_myers@mentor.com; helo=esa2.mentor.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/04 19:40:26 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 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 +- tests/tcg/i386/test-i386-pseudo-denormal.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 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_stat= us *status) } if ( aExp < 0x3FFF ) { if ( ( aExp =3D=3D 0 ) - && ( (uint64_t) ( extractFloatx80Frac( a )<<1 ) =3D=3D 0 ) ) { + && ( (uint64_t) ( extractFloatx80Frac( a ) ) =3D=3D 0 ) ) { return a; } status->float_exception_flags |=3D float_flag_inexact; diff --git a/tests/tcg/i386/test-i386-pseudo-denormal.c b/tests/tcg/i386/te= st-i386-pseudo-denormal.c index acf2b9cf03..00d510cf4a 100644 --- a/tests/tcg/i386/test-i386-pseudo-denormal.c +++ b/tests/tcg/i386/test-i386-pseudo-denormal.c @@ -14,6 +14,7 @@ volatile long double ld_res; =20 int main(void) { + short cw; int ret =3D 0; ld_res =3D ld_pseudo_m16382.ld + ld_pseudo_m16382.ld; if (ld_res !=3D 0x1p-16381L) { @@ -24,5 +25,14 @@ int main(void) printf("FAIL: pseudo-denormal compare\n"); ret =3D 1; } + /* Set round-upward. */ + __asm__ volatile ("fnstcw %0" : "=3Dm" (cw)); + cw =3D (cw & ~0xc00) | 0x800; + __asm__ volatile ("fldcw %0" : : "m" (cw)); + __asm__ ("frndint" : "=3Dt" (ld_res) : "0" (ld_pseudo_m16382.ld)); + if (ld_res !=3D 1.0L) { + printf("FAIL: pseudo-denormal round-to-integer\n"); + ret =3D 1; + } return ret; } --=20 2.17.1 --=20 Joseph S. Myers joseph@codesourcery.com