From nobody Sun May 19 11:31:01 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=1591635502; cv=none; d=zohomail.com; s=zohoarc; b=HNaT7URb9QqNMstISyoGQrjEtiZ2rnCwDSFUfRdJz3JzVtsoRWxO6qJtWfFvcSifsuR+Xr9py12cvmWBx6hDX7QCCGCj9bGFJ8EpdA+4StkRrTRsl3YzhENgBHij+VQVTbCn0fYtXsO9q0u0fT5XnZsSjTux9M1z0358y6gVt8k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591635502; 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=8CmLu7q6/DzkOxM0eGk2L9PanswjI6hDWJAjde5j27s=; b=S2hfET0epGWlM0CdNFxfse49mk6NYjBffcP9ODcVh2LI10QYu/0prMXJI12zEYYE1V1LKW8px1PLG7lALp7wQQmk1UOnphRviE9S4ZQEMr7DxWkOd80OkIBl5yox1y1dvHOXU05+ZqeWnjg0K7ZmLv2Bx5ULdXFpulWKXLA80SM= 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 1591635502432506.4557656721554; Mon, 8 Jun 2020 09:58:22 -0700 (PDT) Received: from localhost ([::1]:45030 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jiL6L-0006Ds-2Z for importer@patchew.org; Mon, 08 Jun 2020 12:58:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45528) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jiL3V-0001Yl-8k for qemu-devel@nongnu.org; Mon, 08 Jun 2020 12:55:25 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:8930) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jiL3Q-0000yK-GV for qemu-devel@nongnu.org; Mon, 08 Jun 2020 12:55:24 -0400 Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 08 Jun 2020 08:55:17 -0800 IronPort-SDR: Khmbr5fiZqI6t24vgc6puH3jNWBnRnTSx1gJfTQcMe9/CO+dqeqkI2fEK/2BaOMQnrkP3ambwc eRPed7mxWkO587DYyl+eGoy/TKNAtURc5KsgkTwbrAviEkOdKDQUCu9LMm0wlPj40EEAanQHtk ieUWPw64QTAC+9GtfCQGVCaj2mJlzHnYE/2cIDG8c0Oa83vTZ/jSq6lZpp7teT5b4Bn/WWL1bH Pu3iU1djgpx6W5HYcGISEDsLYdmD1K9Rcqdu+Yzl0Bc7yih1CLKGYVRtAIMEdkf4Y4WMZzkIZb 9lE= X-IronPort-AV: E=Sophos;i="5.73,487,1583222400"; d="scan'208";a="49689833" IronPort-SDR: fduFEj/KvJtcW19ZwVW2A2cJDBiphUnRo/1Adt8HUYpAEUvgwKDG7BAknr61WOtkXPEWQ3rYk8 UQ7+RuDzAfPU6YPd9Od0lAvtjnuQtMdt/6QMIubySVQkIBkJgZW4jlc073FPiRiJhistiQCdIi SDr4suwAsbIEexOOyWN/RcF0w24jJEHegTPOoLWfTBZlE6qaeXOJxDX6opf4sSzses6x5W5S9Q ArHJ3ykQfPhJ+M4coTI1o6V25GNqIhBLhY2xsmLBNUQPcimyD66r2hOaKn0g6RKmqD75bsed2Q ZUs= Date: Mon, 8 Jun 2020 16:55:11 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: , , , , , , , Subject: [PATCH v2 1/6] softfloat: merge floatx80_mod and floatx80_rem 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-02.mgc.mentorg.com (139.181.222.2) 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/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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The m68k-specific softfloat code includes a function floatx80_mod that is extremely similar to floatx80_rem, but computing the remainder based on truncating the quotient toward zero rather than rounding it to nearest integer. This is also useful for emulating the x87 fprem and fprem1 instructions. Change the floatx80_rem implementation into floatx80_modrem that can perform either operation, with both floatx80_rem and floatx80_mod as thin wrappers available for all targets. There does not appear to be any use for the _mod operation for other floating-point formats in QEMU (the only other architectures using _rem at all are linux-user/arm/nwfpe, for FPA emulation, and openrisc, for instructions that have been removed in the latest version of the architecture), so no change is made to the code for other formats. Signed-off-by: Joseph Myers Reviewed-by: Richard Henderson --- fpu/softfloat.c | 49 ++++++++++++++++++------ include/fpu/softfloat.h | 2 + target/m68k/softfloat.c | 83 ----------------------------------------- target/m68k/softfloat.h | 1 - 4 files changed, 40 insertions(+), 95 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 6c8f2d597a..7b1ce7664f 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -5682,10 +5682,13 @@ floatx80 floatx80_div(floatx80 a, floatx80 b, float= _status *status) /*------------------------------------------------------------------------= ---- | Returns the remainder of the extended double-precision floating-point va= lue | `a' with respect to the corresponding value `b'. The operation is perfo= rmed -| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. +| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic, +| if 'mod' is false; if 'mod' is true, return the remainder based on trunc= ating +| the quotient toward zero instead. *-------------------------------------------------------------------------= ---*/ =20 -floatx80 floatx80_rem(floatx80 a, floatx80 b, float_status *status) +floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod, + float_status *status) { bool aSign, zSign; int32_t aExp, bExp, expDiff; @@ -5731,7 +5734,7 @@ floatx80 floatx80_rem(floatx80 a, floatx80 b, float_s= tatus *status) expDiff =3D aExp - bExp; aSig1 =3D 0; if ( expDiff < 0 ) { - if ( expDiff < -1 ) return a; + if ( mod || expDiff < -1 ) return a; shift128Right( aSig0, 0, 1, &aSig0, &aSig1 ); expDiff =3D 0; } @@ -5763,14 +5766,16 @@ floatx80 floatx80_rem(floatx80 a, floatx80 b, float= _status *status) term1 =3D 0; term0 =3D bSig; } - sub128( term0, term1, aSig0, aSig1, &alternateASig0, &alternateASig1 ); - if ( lt128( alternateASig0, alternateASig1, aSig0, aSig1 ) - || ( eq128( alternateASig0, alternateASig1, aSig0, aSig1 ) - && ( q & 1 ) ) - ) { - aSig0 =3D alternateASig0; - aSig1 =3D alternateASig1; - zSign =3D ! zSign; + if (!mod) { + sub128( term0, term1, aSig0, aSig1, &alternateASig0, &alternateASi= g1 ); + if ( lt128( alternateASig0, alternateASig1, aSig0, aSig1 ) + || ( eq128( alternateASig0, alternateASig1, aSig0, aSig= 1 ) + && ( q & 1 ) ) + ) { + aSig0 =3D alternateASig0; + aSig1 =3D alternateASig1; + zSign =3D ! zSign; + } } return normalizeRoundAndPackFloatx80( @@ -5778,6 +5783,28 @@ floatx80 floatx80_rem(floatx80 a, floatx80 b, float_= status *status) =20 } =20 +/*------------------------------------------------------------------------= ---- +| Returns the remainder of the extended double-precision floating-point va= lue +| `a' with respect to the corresponding value `b'. The operation is perfo= rmed +| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*-------------------------------------------------------------------------= ---*/ + +floatx80 floatx80_rem(floatx80 a, floatx80 b, float_status *status) +{ + return floatx80_modrem(a, b, false, status); +} + +/*------------------------------------------------------------------------= ---- +| Returns the remainder of the extended double-precision floating-point va= lue +| `a' with respect to the corresponding value `b', with the quotient trunc= ated +| toward zero. +*-------------------------------------------------------------------------= ---*/ + +floatx80 floatx80_mod(floatx80 a, floatx80 b, float_status *status) +{ + return floatx80_modrem(a, b, true, status); +} + /*------------------------------------------------------------------------= ---- | Returns the square root of the extended double-precision floating-point | value `a'. The operation is performed according to the IEC/IEEE Standard diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h index 16ca697a73..bff6934d09 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -687,6 +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_mod(floatx80, floatx80, float_status *status); floatx80 floatx80_rem(floatx80, floatx80, float_status *status); floatx80 floatx80_sqrt(floatx80, float_status *status); FloatRelation floatx80_compare(floatx80, floatx80, float_status *status); diff --git a/target/m68k/softfloat.c b/target/m68k/softfloat.c index 9f120cf15e..b6d0ed7acf 100644 --- a/target/m68k/softfloat.c +++ b/target/m68k/softfloat.c @@ -42,89 +42,6 @@ static floatx80 propagateFloatx80NaNOneArg(floatx80 a, f= loat_status *status) return a; } =20 -/* - * Returns the modulo remainder of the extended double-precision floating-= point - * value `a' with respect to the corresponding value `b'. - */ - -floatx80 floatx80_mod(floatx80 a, floatx80 b, float_status *status) -{ - bool aSign, zSign; - int32_t aExp, bExp, expDiff; - uint64_t aSig0, aSig1, bSig; - uint64_t qTemp, term0, term1; - - aSig0 =3D extractFloatx80Frac(a); - aExp =3D extractFloatx80Exp(a); - aSign =3D extractFloatx80Sign(a); - bSig =3D extractFloatx80Frac(b); - bExp =3D extractFloatx80Exp(b); - - if (aExp =3D=3D 0x7FFF) { - if ((uint64_t) (aSig0 << 1) - || ((bExp =3D=3D 0x7FFF) && (uint64_t) (bSig << 1))) { - return propagateFloatx80NaN(a, b, status); - } - goto invalid; - } - if (bExp =3D=3D 0x7FFF) { - if ((uint64_t) (bSig << 1)) { - return propagateFloatx80NaN(a, b, status); - } - return a; - } - if (bExp =3D=3D 0) { - if (bSig =3D=3D 0) { - invalid: - float_raise(float_flag_invalid, status); - return floatx80_default_nan(status); - } - normalizeFloatx80Subnormal(bSig, &bExp, &bSig); - } - if (aExp =3D=3D 0) { - if ((uint64_t) (aSig0 << 1) =3D=3D 0) { - return a; - } - normalizeFloatx80Subnormal(aSig0, &aExp, &aSig0); - } - bSig |=3D UINT64_C(0x8000000000000000); - zSign =3D aSign; - expDiff =3D aExp - bExp; - aSig1 =3D 0; - if (expDiff < 0) { - return a; - } - qTemp =3D (bSig <=3D aSig0); - if (qTemp) { - aSig0 -=3D bSig; - } - expDiff -=3D 64; - while (0 < expDiff) { - qTemp =3D estimateDiv128To64(aSig0, aSig1, bSig); - qTemp =3D (2 < qTemp) ? qTemp - 2 : 0; - mul64To128(bSig, qTemp, &term0, &term1); - sub128(aSig0, aSig1, term0, term1, &aSig0, &aSig1); - shortShift128Left(aSig0, aSig1, 62, &aSig0, &aSig1); - expDiff -=3D 62; - } - expDiff +=3D 64; - if (0 < expDiff) { - qTemp =3D estimateDiv128To64(aSig0, aSig1, bSig); - qTemp =3D (2 < qTemp) ? qTemp - 2 : 0; - qTemp >>=3D 64 - expDiff; - mul64To128(bSig, qTemp << (64 - expDiff), &term0, &term1); - sub128(aSig0, aSig1, term0, term1, &aSig0, &aSig1); - shortShift128Left(0, bSig, 64 - expDiff, &term0, &term1); - while (le128(term0, term1, aSig0, aSig1)) { - ++qTemp; - sub128(aSig0, aSig1, term0, term1, &aSig0, &aSig1); - } - } - return - normalizeRoundAndPackFloatx80( - 80, zSign, bExp + expDiff, aSig0, aSig1, status); -} - /* * Returns the mantissa of the extended double-precision floating-point * value `a'. diff --git a/target/m68k/softfloat.h b/target/m68k/softfloat.h index 365ef6ac7a..4bb9567134 100644 --- a/target/m68k/softfloat.h +++ b/target/m68k/softfloat.h @@ -23,7 +23,6 @@ #define TARGET_M68K_SOFTFLOAT_H #include "fpu/softfloat.h" =20 -floatx80 floatx80_mod(floatx80 a, floatx80 b, float_status *status); floatx80 floatx80_getman(floatx80 a, float_status *status); floatx80 floatx80_getexp(floatx80 a, float_status *status); floatx80 floatx80_scale(floatx80 a, floatx80 b, float_status *status); --=20 2.17.1 --=20 Joseph S. Myers joseph@codesourcery.com From nobody Sun May 19 11:31:01 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=1591635523; cv=none; d=zohomail.com; s=zohoarc; b=gnjRiph7ynYYVOyv/Qgte4CAsgCDhF6I5N77enqFVy9b0hLsJlkzMTYk69HbiKAFvayS24fxWD+1Po2HjP8fbZyilDOgaqqY9jhbj9HRrcjgCkNc+Ev9nNA9ozvi3IGBhF+wFLbZavhoB/GTRScUaBkXchFS3NC/WhNVKPjGvV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591635523; 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=GmGGuPNvarOnqJbda1bJ0yt1g2bAvLNz8ggTTeUeR5Q=; b=mULv/aLGyfoU6n8mlNp+EKchPx5ay04Q/DNOr2bBn8bsDbEkeBSDxkLdKsLJAo6S1x7fhujOjQs/8dckcam8Htsn9sfl5IR7CBniN6dUsd+j9Iz90nCVwOC/W6FbkG8vwdjvYodOivd1FnkAWgOyhrVxLBtoHKrrdeQQsg5cyHk= 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 1591635523073148.48787060862412; Mon, 8 Jun 2020 09:58:43 -0700 (PDT) Received: from localhost ([::1]:46178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jiL6f-0006il-Sm for importer@patchew.org; Mon, 08 Jun 2020 12:58:41 -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 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: 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" 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 (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/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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D=3D 0 ) { - if ( (uint64_t) ( aSig0<<1 ) =3D=3D 0 ) return a; + if ( aSig0 =3D=3D 0 ) return a; normalizeFloatx80Subnormal( aSig0, &aExp, &aSig0 ); } bSig |=3D UINT64_C(0x8000000000000000); --=20 2.17.1 --=20 Joseph S. Myers joseph@codesourcery.com From nobody Sun May 19 11:31:01 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=1591635698; cv=none; d=zohomail.com; s=zohoarc; b=X8ja9HU7DOoo8nyen2W/lvshds4JzX0nAzr9PJzmN54tySikMLesb0UjrBpdkoaLNGXzon8UwYCW8D+h3YhyZQ/8GC1pTefSSRP5z8Q827PWiUKbS54GnCRntTOHUP73ZNAmd/uXGRClIvtrCbYukwG3JgBXR4IuK4HQzZRNXoc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591635698; 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=ai5kGEZXPslFDlk7OhlxqULt+o2RFGEpWWzu2/1Xoyc=; b=iW7H5jerOTiBfmhHuqZhOisWfKEq0qSTS0uWBRkAWu2kyjpskb4a/nJZ2YkJnvt9vaOT9eQEVsrxE8kpc80ZY57QfpHi69FnOO1yvh0tq+46tH8blUkQX8wvjr+nr1hqt4ZN8+kNA1jsbeqCEPK7IN0oz9/IGtLkgcbmBRDzxBM= 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 1591635698989678.1716454750888; Mon, 8 Jun 2020 10:01:38 -0700 (PDT) Received: from localhost ([::1]:52734 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jiL9V-0001fq-EL for importer@patchew.org; Mon, 08 Jun 2020 13:01:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45678) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jiL4X-0003Kd-UB for qemu-devel@nongnu.org; Mon, 08 Jun 2020 12:56:30 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:48649) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jiL4X-0001LY-00 for qemu-devel@nongnu.org; Mon, 08 Jun 2020 12:56:29 -0400 Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 08 Jun 2020 08:56:26 -0800 IronPort-SDR: kl0vj6Mr8xlsqc0ZPewTID8PjHyUVN5Bm0VuSHKD9aTHIFDsUxxwumKi1+j741QL8Z6GujWbI3 Q9e8ABmBkVexa79LKrXOyk3bFyRY+Iz7ILFNcqUFTuLsPSeEkodOstO5RB+e8vddT8AK6iSgal VCMxO6EJxtE/ou5SSedK3U35fuP0bbgw+ipOwSsY2OvZBPgKENOH2g4PBZQ7fZpIbMS8JXxje6 GQwtqdQMNJQOKomTqWf9bCwTwFt57B1vhlF7neMiRocUJjMSP840oKuX2xl9Tuhg2cXTDqsxeG OZw= X-IronPort-AV: E=Sophos;i="5.73,487,1583222400"; d="scan'208";a="51690305" IronPort-SDR: +JtsbNUMQ1IT1m9Bp/ebcLXS3sI9oApZzrdNE5NNsOeKnbs1RVjviWzI7Xw6hXMgsrMA4/u1cw L4gToIW2LUVJEi2jm2LSyeVJbAvX2EL6h75NDZziarCbqf7vtLm8ZgFuXCJpMrorStt/+YBJmL NkOvv9k3Q0yx2G5ILwU40ePW3YaNplSWTdLPkPKFzwQL8XejcYqkXzw3Sf5P9hqgZF2e58bT5L 55LH+rxTlKp+5EbzCSDUXLThKcfdxPyF4xGU/xLyfaDpwDEf4bNgEoLRkktTpP0iObFoeQPcY4 ve0= Date: Mon, 8 Jun 2020 16:56:20 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: , , , , , , , Subject: [PATCH v2 3/6] softfloat: do not return pseudo-denormal from floatx80 remainder 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 (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/06/08 12:51:54 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The floatx80 remainder implementation sometimes returns the numerator unchanged when the denominator is sufficiently larger than the numerator. But if the value to be returned unchanged is a pseudo-denormal, that is incorrect. Fix it to normalize the numerator in that case. Signed-off-by: Joseph Myers Reviewed-by: Richard Henderson --- fpu/softfloat.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 091847beb9..9d43868e4c 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -5691,7 +5691,7 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool= mod, float_status *status) { bool aSign, zSign; - int32_t aExp, bExp, expDiff; + int32_t aExp, bExp, expDiff, aExpOrig; uint64_t aSig0, aSig1, bSig; uint64_t q, term0, term1, alternateASig0, alternateASig1; =20 @@ -5700,7 +5700,7 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool= mod, return floatx80_default_nan(status); } aSig0 =3D extractFloatx80Frac( a ); - aExp =3D extractFloatx80Exp( a ); + aExpOrig =3D aExp =3D extractFloatx80Exp( a ); aSign =3D extractFloatx80Sign( a ); bSig =3D extractFloatx80Frac( b ); bExp =3D extractFloatx80Exp( b ); @@ -5715,6 +5715,13 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, boo= l mod, if ((uint64_t)(bSig << 1)) { return propagateFloatx80NaN(a, b, status); } + if (aExp =3D=3D 0 && aSig0 >> 63) { + /* + * Pseudo-denormal argument must be returned in normalized + * form. + */ + return packFloatx80(aSign, 1, aSig0); + } return a; } if ( bExp =3D=3D 0 ) { @@ -5734,7 +5741,16 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, boo= l mod, expDiff =3D aExp - bExp; aSig1 =3D 0; if ( expDiff < 0 ) { - if ( mod || expDiff < -1 ) return a; + if ( mod || expDiff < -1 ) { + if (aExp =3D=3D 1 && aExpOrig =3D=3D 0) { + /* + * Pseudo-denormal argument must be returned in + * normalized form. + */ + return packFloatx80(aSign, aExp, aSig0); + } + return a; + } shift128Right( aSig0, 0, 1, &aSig0, &aSig1 ); expDiff =3D 0; } --=20 2.17.1 --=20 Joseph S. Myers joseph@codesourcery.com From nobody Sun May 19 11:31:01 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=1591635658; cv=none; d=zohomail.com; s=zohoarc; b=a1/YukObD52HOrixXlYbOt/97oZuSDD49ecqbs/XVXS2mD0Vp2/AVKkOuaIJWtpllNwQAil0M/q0i08C2dK0BZfGQ7FC9BOIW7BqItZbA0k7QV7te4crnxZstaIqRrb7bpe+LsZtzYuQxxTTlCPfxQEnJ3WV0ADmNKexc17/2mk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591635658; 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=mAxbXMaa3hu960+0a4GNSY3NMIa43/nICqBf6WIakSY=; b=NoeXM2U9Faao9sXcHH0xU8/C0D4EozxkZ7pH5ld2QR4hP68+YJVlvWqXbB70tpiJ6M3ZysPJCLWAyh1jHHAjPQOw+clplGifZhZ7XmFbtGo4T+wo06C6FshCZlzwVZ0yDgqUWGNPwWw3BAvfbNwVlLMmQuVZRhFjxGfyz0iB4So= 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 1591635658366300.84747277051906; Mon, 8 Jun 2020 10:00:58 -0700 (PDT) Received: from localhost ([::1]:50874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jiL8q-0000Wf-1f for importer@patchew.org; Mon, 08 Jun 2020 13:00:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45782) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jiL4z-00043B-1S for qemu-devel@nongnu.org; Mon, 08 Jun 2020 12:56:57 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:45679) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jiL4x-0001Os-1o for qemu-devel@nongnu.org; Mon, 08 Jun 2020 12:56:56 -0400 Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 08 Jun 2020 08:56:53 -0800 IronPort-SDR: r2mWtAkwymmgt6cyHei4YDntnWQx26ProPtKOCoULTAjkhxKvZ1q60A7Cv062uvwUGdEcPDYrB jbXGkAzfm8XG+whRUMzzmybNmPxdV8ZUHvkUvyT3PFxtvP53hsuIMhbdZNOjySk9MipSV03fwS sUWmoG2gFms/LFJ+tH444l0NuvLCYoUyo4D3zYVG1cpuEOsPZNp5tywHwzr7NOxEvv82pQvz6X ngmEoKm8bAqkBGbgkQqRfW07Ky4eA9AUcXAKob155gHELwquSO4JpNqluvZFGpxuVxgFN1CrHV Ers= X-IronPort-AV: E=Sophos;i="5.73,487,1583222400"; d="scan'208";a="49617203" IronPort-SDR: VpGolUg+nL79sI7ZVR/jja5Ucoapp4Xzfme8IAxy1jrdJUwWa7a1OHw8TUdpDDy4ouwyr+RBVn f4ycK2EvPwTUNnuQTWBB+uNVxjqf6FU/va2ErU1o9Kwk/XxkTL1awuevt80n1paxhbA+bCAZkE pvf64vkPaWMhj5QIb6My2OTJszxo1lyb+PEZCOCllnP1cQagXH+6lhInjkYM6YnFXdmpHlP/bn 2RTrJ9YOZzim4psq7Qo0pIPhcU6BtHqgYQspuI4dK8qDHd8ryjazb4heHuC1enD3vt5ImkXRWj los= Date: Mon, 8 Jun 2020 16:56:47 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: , , , , , , , Subject: [PATCH v2 4/6] softfloat: do not set denominator high bit for floatx80 remainder 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-02.mgc.mentorg.com (139.181.222.2) 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.180; envelope-from=joseph_myers@mentor.com; helo=esa3.mentor.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/08 12:54:23 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The floatx80 remainder implementation unnecessarily sets the high bit of bSig explicitly. By that point in the function, arguments that are invalid, zero, infinity or NaN have already been handled and subnormals have been through normalizeFloatx80Subnormal, so the high bit will already be set. Remove the unnecessary code. Signed-off-by: Joseph Myers Reviewed-by: Richard Henderson --- fpu/softfloat.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 9d43868e4c..1552241b5e 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -5736,7 +5736,6 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool= mod, if ( aSig0 =3D=3D 0 ) return a; normalizeFloatx80Subnormal( aSig0, &aExp, &aSig0 ); } - bSig |=3D UINT64_C(0x8000000000000000); zSign =3D aSign; expDiff =3D aExp - bExp; aSig1 =3D 0; --=20 2.17.1 --=20 Joseph S. Myers joseph@codesourcery.com From nobody Sun May 19 11:31:01 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=1591635814; cv=none; d=zohomail.com; s=zohoarc; b=EoOCT+5eC8UQUr/BYpo0wBvKsSIEuUkKz4mZE9SURByjEg9ckwQ+gPRLgK5kUiAvtqCDD1FHTGzrnsYDq59xEELrzMZOeO2HdoAyxFYB2d5vAcWvxjIEJ+UcExdeO4d8/23v/xN15oEJfAfO8VOrTKF3b2zpMxLEXKOr+q30F6U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591635814; 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=rUlB8Icl4Pbs5LLsBiqFdw9H6+Hxf/5Gn4g3dDTxnPQ=; b=aer2fbL2Qrxtl6AtxUYBBL0Ho5Rgb3Qj9ol4XW42tgNrQm0nPAhgCPimEkTXfduhmAr4igCV3hH2L6hnCPeyQs09XiE9mkik64SbAp7x0ANm/PUd8DjknPuZ7cHGGKxYYmNjjMskI7VAE19LFXNKR/mKIGxXaDp0KtnZTrvklmw= 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 1591635814163531.42611211357; Mon, 8 Jun 2020 10:03:34 -0700 (PDT) Received: from localhost ([::1]:58974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jiLBM-0004FF-NO for importer@patchew.org; Mon, 08 Jun 2020 13:03:32 -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 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: 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" 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 (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/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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 perfo= rmed | according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic, | if 'mod' is false; if 'mod' is true, return the remainder based on trunc= ating -| 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. *-------------------------------------------------------------------------= ---*/ =20 -floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod, +floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod, uint64_t *quoti= ent, 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; =20 + *quotient =3D 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 =3D 0; } - q =3D ( bSig <=3D aSig0 ); + *quotient =3D q =3D ( bSig <=3D aSig0 ); if ( q ) aSig0 -=3D bSig; expDiff -=3D 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 -=3D 62; + *quotient <<=3D 62; + *quotient +=3D q; } expDiff +=3D 64; if ( 0 < expDiff ) { @@ -5776,6 +5780,12 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, boo= l mod, ++q; sub128( aSig0, aSig1, term0, term1, &aSig0, &aSig1 ); } + if (expDiff < 64) { + *quotient <<=3D expDiff; + } else { + *quotient =3D 0; + } + *quotient +=3D q; } else { term1 =3D 0; @@ -5790,6 +5800,7 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool= mod, aSig0 =3D alternateASig0; aSig1 =3D alternateASig1; zSign =3D ! zSign; + ++*quotient; } } return @@ -5806,7 +5817,8 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool= mod, =20 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); } =20 /*------------------------------------------------------------------------= ---- @@ -5817,7 +5829,8 @@ floatx80 floatx80_rem(floatx80 a, floatx80 b, float_s= tatus *status) =20 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); } =20 /*------------------------------------------------------------------------= ---- 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); --=20 2.17.1 --=20 Joseph S. Myers joseph@codesourcery.com From nobody Sun May 19 11:31:01 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=1591635980; cv=none; d=zohomail.com; s=zohoarc; b=GBWZydhPTpHbgEneG4uyOA3PzY6F4DBgSLg3F9W//juFZw49bT3h7VUgX+SG68FW3hKsht2xTP8XBKPx0nGt0OVlyJ+8Txnu5uItM3mW5KUQP0+iVWbSjVQ/on9NmryNCP8C4JP/+4C/3ojHG1tlpIdyxa7eQ3r4CdIMMwJvp4c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591635980; 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=FbiLF2h83o9p0roItfL5xP4l9qRBiUvTXoytfGYF4Rs=; b=B4OyyiO6ePdH5LRG3xapc4tt6/BQRmGM4IvMdOF1wkzObnMv3I0VfbjAXJbGz8u+iUS8Ogvi6dEuKI7MF8zIjEZLPjV1k6/LqW2Pi1WA2BVEtl0+5nFQ9P8/7R1iNT4xplKgHVvYqXHZjZq9mw1nx3fyLbL2pLNY5Vue90smU2w= 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 1591635980066893.3964245184414; Mon, 8 Jun 2020 10:06:20 -0700 (PDT) Received: from localhost ([::1]:37530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jiLE2-0007Aw-6k for importer@patchew.org; Mon, 08 Jun 2020 13:06:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46160) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jiL6W-00077p-C6 for qemu-devel@nongnu.org; Mon, 08 Jun 2020 12:58:32 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:48779) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jiL6U-0001dy-Oj for qemu-devel@nongnu.org; Mon, 08 Jun 2020 12:58:32 -0400 Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 08 Jun 2020 08:58:29 -0800 IronPort-SDR: JRVnId0x6zgtSZmxeTfmum1hEz6nDKfzoyjXqMxExNHwgG4Oyg9x5sPUECSAYK6DOYCbtr2Kwn f8TRHgsy5JmTf1xEMES6yG/GpWku+OCq1p+Ki3GFOD/gC9lxwR5dEJQKgdHJ1kM/xY4zSSuKdD UJgMIWTA3og1iX0GuRULI2psBkURfECljL+T4yhnPNBwEkHG7gtcWk2p47dilRyIuxmb1R8Yjo OFOZcvPDKiAhGHx4vUsa3+WKz/fkyxQNrQBczo9/fgpd58TDS4O6GLkBJr4/Oe9YdGbo6nynY3 r3s= X-IronPort-AV: E=Sophos;i="5.73,487,1583222400"; d="scan'208";a="51690378" IronPort-SDR: Q2sJPuVBdSjIhnG12ydreMFqNJUZUnfWr0u4XzRXnsLZaBJbu+ZQQ2JK1jMx2Bl4q8zmfJl2GV XiwB73losVr5kOQocHu7N7zYxy7qlbrzezjpCJx6Z+FMMz/otUSZPVm2jqoRhcJG8DSz1z5WG1 +AwJ7RszjnarGrBsQYjoSJWiWCpslpR55gbRNw8uAiulRyHf8kYcfjXjXZeHMzsd7Qe8tTPD4T Xg7FHqa7N5RS5o1qAcFpClGxXhAckTlQiFNQ+OzHe8wlK9YFhJeWc3Vf49L8qGuVGZ244WLTm5 1Xw= Date: Mon, 8 Jun 2020 16:58:23 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: , , , , , , , Subject: [PATCH v2 6/6] target/i386: reimplement fprem, fprem1 using floatx80 operations 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 (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/06/08 12:51:54 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The x87 fprem and fprem1 emulation is currently based around conversion to double, which is inherently unsuitable for a good emulation of any floatx80 operation. Reimplement using the soft-float floatx80 remainder operations. Signed-off-by: Joseph Myers Reviewed-by: Richard Henderson --- target/i386/fpu_helper.c | 156 ++++++++++++--------------------------- 1 file changed, 48 insertions(+), 108 deletions(-) diff --git a/target/i386/fpu_helper.c b/target/i386/fpu_helper.c index 8ef5b463ea..0e531e3821 100644 --- a/target/i386/fpu_helper.c +++ b/target/i386/fpu_helper.c @@ -934,124 +934,64 @@ void helper_fxtract(CPUX86State *env) merge_exception_flags(env, old_flags); } =20 -void helper_fprem1(CPUX86State *env) +static void helper_fprem_common(CPUX86State *env, bool mod) { - double st0, st1, dblq, fpsrcop, fptemp; - CPU_LDoubleU fpsrcop1, fptemp1; - int expdif; - signed long long int q; - - st0 =3D floatx80_to_double(env, ST0); - st1 =3D floatx80_to_double(env, ST1); - - if (isinf(st0) || isnan(st0) || isnan(st1) || (st1 =3D=3D 0.0)) { - ST0 =3D double_to_floatx80(env, 0.0 / 0.0); /* NaN */ - env->fpus &=3D ~0x4700; /* (C3,C2,C1,C0) <-- 0000 */ - return; - } - - fpsrcop =3D st0; - fptemp =3D st1; - fpsrcop1.d =3D ST0; - fptemp1.d =3D ST1; - expdif =3D EXPD(fpsrcop1) - EXPD(fptemp1); - - if (expdif < 0) { - /* optimisation? taken from the AMD docs */ - env->fpus &=3D ~0x4700; /* (C3,C2,C1,C0) <-- 0000 */ - /* ST0 is unchanged */ - return; - } + uint8_t old_flags =3D save_exception_flags(env); + uint64_t quotient; + CPU_LDoubleU temp0, temp1; + int exp0, exp1, expdiff; =20 - if (expdif < 53) { - dblq =3D fpsrcop / fptemp; - /* round dblq towards nearest integer */ - dblq =3D rint(dblq); - st0 =3D fpsrcop - fptemp * dblq; + temp0.d =3D ST0; + temp1.d =3D ST1; + exp0 =3D EXPD(temp0); + exp1 =3D EXPD(temp1); =20 - /* convert dblq to q by truncating towards zero */ - if (dblq < 0.0) { - q =3D (signed long long int)(-dblq); + env->fpus &=3D ~0x4700; /* (C3,C2,C1,C0) <-- 0000 */ + if (floatx80_is_zero(ST0) || floatx80_is_zero(ST1) || + exp0 =3D=3D 0x7fff || exp1 =3D=3D 0x7fff || + floatx80_invalid_encoding(ST0) || floatx80_invalid_encoding(ST1)) { + ST0 =3D floatx80_modrem(ST0, ST1, mod, "ient, &env->fp_status); + } else { + if (exp0 =3D=3D 0) { + exp0 =3D 1 - clz64(temp0.l.lower); + } + if (exp1 =3D=3D 0) { + exp1 =3D 1 - clz64(temp1.l.lower); + } + expdiff =3D exp0 - exp1; + if (expdiff < 64) { + ST0 =3D floatx80_modrem(ST0, ST1, mod, "ient, &env->fp_sta= tus); + env->fpus |=3D (quotient & 0x4) << (8 - 2); /* (C0) <-- q2 */ + env->fpus |=3D (quotient & 0x2) << (14 - 1); /* (C3) <-- q1 */ + env->fpus |=3D (quotient & 0x1) << (9 - 0); /* (C1) <-- q0 */ } else { - q =3D (signed long long int)dblq; + /* + * Partial remainder. This choice of how many bits to + * process at once is specified in AMD instruction set + * manuals, and empirically is followed by Intel + * processors as well; it ensures that the final remainder + * operation in a loop does produce the correct low three + * bits of the quotient. AMD manuals specify that the + * flags other than C2 are cleared, and empirically Intel + * processors clear them as well. + */ + int n =3D 32 + (expdiff % 32); + temp1.d =3D floatx80_scalbn(temp1.d, expdiff - n, &env->fp_sta= tus); + ST0 =3D floatx80_mod(ST0, temp1.d, &env->fp_status); + env->fpus |=3D 0x400; /* C2 <-- 1 */ } - - env->fpus &=3D ~0x4700; /* (C3,C2,C1,C0) <-- 0000 */ - /* (C0,C3,C1) <-- (q2,q1,q0) */ - env->fpus |=3D (q & 0x4) << (8 - 2); /* (C0) <-- q2 */ - env->fpus |=3D (q & 0x2) << (14 - 1); /* (C3) <-- q1 */ - env->fpus |=3D (q & 0x1) << (9 - 0); /* (C1) <-- q0 */ - } else { - env->fpus |=3D 0x400; /* C2 <-- 1 */ - fptemp =3D pow(2.0, expdif - 50); - fpsrcop =3D (st0 / st1) / fptemp; - /* fpsrcop =3D integer obtained by chopping */ - fpsrcop =3D (fpsrcop < 0.0) ? - -(floor(fabs(fpsrcop))) : floor(fpsrcop); - st0 -=3D (st1 * fpsrcop * fptemp); } - ST0 =3D double_to_floatx80(env, st0); + merge_exception_flags(env, old_flags); } =20 -void helper_fprem(CPUX86State *env) +void helper_fprem1(CPUX86State *env) { - double st0, st1, dblq, fpsrcop, fptemp; - CPU_LDoubleU fpsrcop1, fptemp1; - int expdif; - signed long long int q; - - st0 =3D floatx80_to_double(env, ST0); - st1 =3D floatx80_to_double(env, ST1); - - if (isinf(st0) || isnan(st0) || isnan(st1) || (st1 =3D=3D 0.0)) { - ST0 =3D double_to_floatx80(env, 0.0 / 0.0); /* NaN */ - env->fpus &=3D ~0x4700; /* (C3,C2,C1,C0) <-- 0000 */ - return; - } - - fpsrcop =3D st0; - fptemp =3D st1; - fpsrcop1.d =3D ST0; - fptemp1.d =3D ST1; - expdif =3D EXPD(fpsrcop1) - EXPD(fptemp1); - - if (expdif < 0) { - /* optimisation? taken from the AMD docs */ - env->fpus &=3D ~0x4700; /* (C3,C2,C1,C0) <-- 0000 */ - /* ST0 is unchanged */ - return; - } - - if (expdif < 53) { - dblq =3D fpsrcop / fptemp; /* ST0 / ST1 */ - /* round dblq towards zero */ - dblq =3D (dblq < 0.0) ? ceil(dblq) : floor(dblq); - st0 =3D fpsrcop - fptemp * dblq; /* fpsrcop is ST0 */ - - /* convert dblq to q by truncating towards zero */ - if (dblq < 0.0) { - q =3D (signed long long int)(-dblq); - } else { - q =3D (signed long long int)dblq; - } - - env->fpus &=3D ~0x4700; /* (C3,C2,C1,C0) <-- 0000 */ - /* (C0,C3,C1) <-- (q2,q1,q0) */ - env->fpus |=3D (q & 0x4) << (8 - 2); /* (C0) <-- q2 */ - env->fpus |=3D (q & 0x2) << (14 - 1); /* (C3) <-- q1 */ - env->fpus |=3D (q & 0x1) << (9 - 0); /* (C1) <-- q0 */ - } else { - int N =3D 32 + (expdif % 32); /* as per AMD docs */ + helper_fprem_common(env, false); +} =20 - env->fpus |=3D 0x400; /* C2 <-- 1 */ - fptemp =3D pow(2.0, (double)(expdif - N)); - fpsrcop =3D (st0 / st1) / fptemp; - /* fpsrcop =3D integer obtained by chopping */ - fpsrcop =3D (fpsrcop < 0.0) ? - -(floor(fabs(fpsrcop))) : floor(fpsrcop); - st0 -=3D (st1 * fpsrcop * fptemp); - } - ST0 =3D double_to_floatx80(env, st0); +void helper_fprem(CPUX86State *env) +{ + helper_fprem_common(env, true); } =20 void helper_fyl2xp1(CPUX86State *env) --=20 2.17.1 --=20 Joseph S. Myers joseph@codesourcery.com