From patchwork Thu Nov 23 16:35:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 840839 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yjQ7Z2k8hz9ryk for ; Fri, 24 Nov 2017 03:41:14 +1100 (AEDT) Received: from localhost ([::1]:45148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHuYq-0002hg-Iq for incoming@patchwork.ozlabs.org; Thu, 23 Nov 2017 11:41:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46948) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHuU3-0007se-Da for qemu-devel@nongnu.org; Thu, 23 Nov 2017 11:36:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eHuU1-0003XQ-Bv for qemu-devel@nongnu.org; Thu, 23 Nov 2017 11:36:15 -0500 Received: from mout.kundenserver.de ([212.227.126.134]:59268) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eHuU1-0003W5-0O for qemu-devel@nongnu.org; Thu, 23 Nov 2017 11:36:13 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue007 [212.227.15.167]) with ESMTPSA (Nemesis) id 0Ljxqo-1esc4L3Fgw-00cAoB; Thu, 23 Nov 2017 17:35:44 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Thu, 23 Nov 2017 17:35:34 +0100 Message-Id: <20171123163538.31411-2-laurent@vivier.eu> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171123163538.31411-1-laurent@vivier.eu> References: <20171123163538.31411-1-laurent@vivier.eu> X-Provags-ID: V03:K0:pBdHk8ZL5Cyo9YH0/8CXV8jYCFXESAJnbnt/usPjT2c9XfSQhtx Flij4oYItk1k/NaAVz9dNdDUeTpAiqHKLx/N97kA8wkEDebq6qfWKWV6/2XXXfq9uclsCnh yQUaHrmccOZ6fOFXyoWG35OboMc2n8zdVSxSvY+jjcTEum2UKH7H7hCvo9Jusdum/95aBRO 77rQ77keICyWHNUGM8Y1Q== X-UI-Out-Filterresults: notjunk:1; V01:K0:1YIGVydC38g=:WXC4opWq5/gcBHYWwgSNr1 LZ2vrYOURhwhIBcK7TAyvibHo4jECPiBpUQu1kbQJ1mZupT9nVYC7h0/G9VqA3QesVr0RY/uZ ucls/aKVVQu873RfL448ct/nhhMduMAXqUIUIrEc8XIBibBWcibzkdZBwk+4eFXy0XECe3sCg 9S4lwRUw7I90k3W675MpGlc0T97BOM8dnCJXle5U5HtCDKvQoY6G8GR3b+5kfLJHR6RbEHi8/ caT/1ahF60LhgLlhRS4fht9U5Ag1Z+H9TY1LK+JIxPx0of7isqwR4b4nEsGoVydVYzC9rXDz4 Hc6H6yNaDaWdnHsiPFeuvL0GRo/vfS9Bw+KQ4GMXXvIki8C8TlJD6O86oevsckrtYJidZ27Tg Yt8QQEl2biDtFxaKfi/VvqhmHWLyRKA+162lYHxi2wcGSXZvblR7d1jLii3F6JrZOwQP+Rq0H 5ZagoDBQC+okXH6M1UmAHgWemHyouMduHIPHwvGYcMx6+z7gg2BHsV0rXMpt0OacAxfnEJxcn hVY3C14LBexxBZfZ5rhUf3jBhz+c2Hmpq24HK2J0p4AsO84stEO/oTCRY2lpviULu0sL1VQUN w+FXwt05FaiWB+cbIPHEtRhUX9FgrtRBvlV6mJPXXh/zGWaBgPpRWKwAKhjopdL4nRm/dN6ZS 1HuDbhSZK6Ovh1PyE3vJTOw8r5vWwpfcnSffs7uGymj0zQx+7iE+mKuC+tGgIOmJ4B574za0q LOfsdS8dKlgV1HQUFf15lfGYf9WZEeQP3Nmkuw== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.126.134 Subject: [Qemu-devel] [PATCH v2 1/5] softfloat: add floatx80_mod() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , Laurent Vivier , Aurelien Jarno , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" copied from previous: Written by Andreas Grabher for Previous, NeXT Computer Emulator. Signed-off-by: Laurent Vivier --- fpu/softfloat.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++ include/fpu/softfloat.h | 1 + 2 files changed, 89 insertions(+) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 433c5dad2d..36e67e50a3 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -5701,6 +5701,94 @@ floatx80 floatx80_sqrt(floatx80 a, float_status *status) 0, zExp, zSig0, zSig1, status); } +#if defined(TARGET_M68K) +/* This part is copied from previous: + * Written by Andreas Grabher for Previous, NeXT Computer Emulator. + */ + +/*---------------------------------------------------------------------------- + | 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) +{ + flag aSign, zSign; + int32_t aExp, bExp, expDiff; + uint64_t aSig0, aSig1, bSig; + uint64_t qTemp, term0, term1; + + aSig0 = extractFloatx80Frac(a); + aExp = extractFloatx80Exp(a); + aSign = extractFloatx80Sign(a); + bSig = extractFloatx80Frac(b); + bExp = extractFloatx80Exp(b); + + if (aExp == 0x7FFF) { + if ((uint64_t) (aSig0 << 1) + || ((bExp == 0x7FFF) && (uint64_t) (bSig << 1))) { + return propagateFloatx80NaN(a, b, status); + } + goto invalid; + } + if (bExp == 0x7FFF) { + if ((uint64_t) (bSig << 1)) { + return propagateFloatx80NaN(a, b, status); + } + return a; + } + if (bExp == 0) { + if (bSig == 0) { + invalid: + float_raise(float_flag_invalid, status); + return floatx80_default_nan(status); + } + normalizeFloatx80Subnormal(bSig, &bExp, &bSig); + } + if (aExp == 0) { + if ((uint64_t) (aSig0 << 1) == 0) { + return a; + } + normalizeFloatx80Subnormal(aSig0, &aExp, &aSig0); + } + bSig |= LIT64(0x8000000000000000); + zSign = aSign; + expDiff = aExp - bExp; + aSig1 = 0; + if (expDiff < 0) { + return a; + } + qTemp = (bSig <= aSig0); + if (qTemp) { + aSig0 -= bSig; + } + expDiff -= 64; + while (0 < expDiff) { + qTemp = estimateDiv128To64(aSig0, aSig1, bSig); + qTemp = (2 < qTemp) ? qTemp - 2 : 0; + mul64To128(bSig, qTemp, &term0, &term1); + sub128(aSig0, aSig1, term0, term1, &aSig0, &aSig1); + shortShift128Left(aSig0, aSig1, 62, &aSig0, &aSig1); + } + expDiff += 64; + if (0 < expDiff) { + qTemp = estimateDiv128To64(aSig0, aSig1, bSig); + qTemp = (2 < qTemp) ? qTemp - 2 : 0; + qTemp >>= 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); +} +#endif /* TARGET_M68K */ + /*---------------------------------------------------------------------------- | Returns 1 if the extended double-precision floating-point value `a' is equal | to the corresponding value `b', and 0 otherwise. The invalid exception is diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h index 0f96a0edd1..ad6249b3df 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -623,6 +623,7 @@ 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_rem(floatx80, floatx80, float_status *status); +floatx80 floatx80_mod(floatx80 a, floatx80 b, float_status *status); floatx80 floatx80_sqrt(floatx80, float_status *status); int floatx80_eq(floatx80, floatx80, float_status *status); int floatx80_le(floatx80, floatx80, float_status *status);