From patchwork Mon Sep 2 09:42:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Brodkin X-Patchwork-Id: 1156541 X-Patchwork-Delegate: alexey.brodkin@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=synopsys.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=synopsys.com header.i=@synopsys.com header.b="I6leSOlB"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46MQB10QwTz9sN1 for ; Mon, 2 Sep 2019 19:43:04 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 9AB64C21DF9; Mon, 2 Sep 2019 09:42:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=RDNS_NONE,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 6DFC7C21CB6; Mon, 2 Sep 2019 09:42:56 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D7112C21CB6; Mon, 2 Sep 2019 09:42:55 +0000 (UTC) Received: from smtprelay-out1.synopsys.com (unknown [198.182.61.142]) by lists.denx.de (Postfix) with ESMTPS id 22CF4C21CB1 for ; Mon, 2 Sep 2019 09:42:55 +0000 (UTC) Received: from mailhost.synopsys.com (mdc-mailhost1.synopsys.com [10.225.0.209]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id B172BC0127; Mon, 2 Sep 2019 09:42:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1567417373; bh=jVNmAUD5Cwbt2ozMcB/EflTSILfqR7k2Dnn2VWyr7Y4=; h=From:To:Cc:Subject:Date:From; b=I6leSOlB09VC/BhbLRRPSjfyC0RgT5Nw2SeD4kyGiR6vmvhWYYEOg9/uUsbqi49+b HHMv9vf2lJHuFFukRFbz86pstKsLO0+/cO61+Tt+/SfDonLGBCl1ONvcDegrvjQMvf lfZcmcpM8dLTL5nwSxfJ1GFNfsfC9HrU7FjLBnoSK7cp7HgnQ1OIe3NwCM8fjwScMc vW5ARfbvwq/IFGv5sMKzoCA/WMv9BoIB3aLgM1gkw8Fx+7wPAci+9mC7FDkgaSp5BW KFLwbbyxSaLh4LreIa/fdStN018KT6NWDc8kDlNxK+T5YsdxZb8KI/kzNSgbZ290U0 WFP5A+sDoq4iQ== Received: from ru20arcgnu1.internal.synopsys.com (ru20arcgnu1.internal.synopsys.com [10.121.9.48]) by mailhost.synopsys.com (Postfix) with ESMTP id C1B4DA005E; Mon, 2 Sep 2019 09:42:49 +0000 (UTC) From: Alexey Brodkin To: u-boot@lists.denx.de Date: Mon, 2 Sep 2019 12:42:44 +0300 Message-Id: <20190902094244.486-1-abrodkin@synopsys.com> X-Mailer: git-send-email 2.16.2 Cc: linux-snps-arc@lists.infradead.org, Alexey Brodkin , uboot-snps-arc@synopsys.com Subject: [U-Boot] [PATCH] arc: libgcc: Import __udivdi3 & __udivmoddi4 to allow 64-bit division X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" As reported by Kever here [1] we were unable to compile 64-bit division code due to missing definition of __udivdi3(). Import its implementation and __udivmoddi4() as its direct dependency from today's libgcc [2]. [1] https://patchwork.ozlabs.org/patch/1146845/ [2] https://github.com/gcc-mirror/gcc/commit/5d8723600bc0eed41226b5a6785bc02a053b45d5 Signed-off-by: Alexey Brodkin Cc: Kever Yang --- arch/arc/lib/libgcc2.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/arch/arc/lib/libgcc2.c b/arch/arc/lib/libgcc2.c index b92a841a37..ab1dbe1c13 100644 --- a/arch/arc/lib/libgcc2.c +++ b/arch/arc/lib/libgcc2.c @@ -158,3 +158,78 @@ __umodsi3(long a, long b) { return udivmodsi4(a, b, 1); } + +UDWtype +__udivmoddi4(UDWtype n, UDWtype d, UDWtype *rp) +{ + UDWtype q = 0, r = n, y = d; + UWtype lz1, lz2, i, k; + + /* + * Implements align divisor shift dividend method. This algorithm + * aligns the divisor under the dividend and then perform number of + * test-subtract iterations which shift the dividend left. Number of + * iterations is k + 1 where k is the number of bit positions the + * divisor must be shifted left to align it under the dividend. + * quotient bits can be saved in the rightmost positions of the + * dividend as it shifts left on each test-subtract iteration. + */ + + if (y <= r) { + lz1 = __builtin_clzll(d); + lz2 = __builtin_clzll(n); + + k = lz1 - lz2; + y = (y << k); + + /* + * Dividend can exceed 2 ^ (width - 1) - 1 but still be less + * than the aligned divisor. Normal iteration can drops the + * high order bit of the dividend. Therefore, first + * test-subtract iteration is a special case, saving its + * quotient bit in a separate location and not shifting + * the dividend. + */ + + if (r >= y) { + r = r - y; + q = (1ULL << k); + } + + if (k > 0) { + y = y >> 1; + + /* + * k additional iterations where k regular test + * subtract shift dividend iterations are done. + */ + i = k; + do { + if (r >= y) + r = ((r - y) << 1) + 1; + else + r = (r << 1); + i = i - 1; + } while (i != 0); + + /* + * First quotient bit is combined with the quotient + * bits resulting from the k regular iterations. + */ + q = q + r; + r = r >> k; + q = q - (r << k); + } + } + + if (rp) + *rp = r; + + return q; +} + +UDWtype +__udivdi3(UDWtype n, UDWtype d) +{ + return __udivmoddi4(n, d, (UDWtype *)0); +}