From patchwork Mon Dec 27 19:05:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Engel X-Patchwork-Id: 1573517 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=danielengel.com header.i=@danielengel.com header.a=rsa-sha256 header.s=fm1 header.b=a1So6Avs; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm1 header.b=MGtAbGgE; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JN6lF6FK1z9sR4 for ; Tue, 28 Dec 2021 06:13:29 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5FFB53858015 for ; Mon, 27 Dec 2021 19:13:27 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) by sourceware.org (Postfix) with ESMTPS id C96A53858415 for ; Mon, 27 Dec 2021 19:08:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C96A53858415 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=danielengel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=danielengel.com Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 8F46632009E0; Mon, 27 Dec 2021 14:08:37 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 27 Dec 2021 14:08:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=danielengel.com; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=jlVVdXFH63kWB 2fEvaZxF4tvacQTQ/OVJqelsnxuMu4=; b=a1So6AvswQDDneGEx9Ajowfm9oSyw YKBzaV1YL3d6huMihY7k7ZSdK4pTD8pOKE4FgekhhsojDHfac5/2UE4uwsLdDAiI vG1Iu2xtM3EmPjVFa1SuMn+UUTnE/dTwK/WxW8vNqElIQqYHerAluUwbjKJmkQ9n NwoIBDHtjyTtL+Y4rs4ejiHMldyQ2XyLQUW5S0hnrR+uCTg6Ri9jJfOHlrTDf7QQ Y6yW2gs1cmdcX1EPH2pk9/OBiyqmMGCWe0QOkkWM2oGuZXe1GaKSaUFVosD5vVnU 7Yg8guGBiVQFJbd7pGA52m4Wkd/lunjW5XmVfLzakF1KbY7TDAWUhlfeA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=jlVVdXFH63kWB2fEvaZxF4tvacQTQ/OVJqelsnxuMu4=; b=MGtAbGgE 2vOuGq+MHyXdWOnpPk0Zy0is2Z1Bi7Pl/lMqVaYijRAEs4q0RnV95PCAJ9wm593r BAnrK1UyX2hg44LKwwMAwJDPDwP0IVDXSEACHG6e7mXh1P+d4srBwmq7g9O/Nqu1 gzA7rrEB7t+TenszD7rIrcapHz3CWHg0C1yquzR1dLcfHYJMY42M4+ybuANA/qbn 1H+uXBm1Gj6c1xteD+MMet1MFBOh3ciYYArxSWD3t+9kxBt2KOcdYljmg2tFHYCz sR2Obfwd85z4VCFncX6tQBn1u1DDU2erz/6AKOBxhhmz5i2wLetxXrKt8LmfaetE ZM/Hqq8cjnBwAQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddruddujedguddtlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepffgrnhhi vghlucfgnhhgvghluceoghhnuhesuggrnhhivghlvghnghgvlhdrtghomheqnecuggftrf grthhtvghrnhepieefvdejgedvjeehleffgeeljeekgeeukeejteehkeelvdfghfekueej gffhgeehnecuffhomhgrihhnpegtthiivddrshgsnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepghhnuhesuggrnhhivghlvghnghgvlhdrtgho mh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 27 Dec 2021 14:08:36 -0500 (EST) Received: from ubuntu.lorien.danielengel.com (ubuntu.lorien.danielengel.com [10.0.0.96]) by sendmail.lorien.danielengel.com (8.15.2/8.15.2) with ESMTP id 1BRJ8Y6o060950; Mon, 27 Dec 2021 11:08:34 -0800 (PST) (envelope-from gnu@danielengel.com) From: Daniel Engel To: Richard Earnshaw , gcc-patches@gcc.gnu.org Subject: [PATCH v6 13/34] Import 'ffs' functions from the CM0 library Date: Mon, 27 Dec 2021 11:05:09 -0800 Message-Id: <20211227190530.3136549-14-gnu@danielengel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211227190530.3136549-1-gnu@danielengel.com> References: <20211227190530.3136549-1-gnu@danielengel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Engel , Christophe Lyon Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This implementation provides an efficient tail call to __clzdi2(), making the functions rather smaller and faster than the C versions. gcc/libgcc/ChangeLog: 2021-01-13 Daniel Engel * config/arm/bits/ctz2.S (__ffssi2, __ffsdi2): New functions. * config/arm/t-elf (LIB1ASMFUNCS): Added _ffssi2 and _ffsdi2. --- libgcc/config/arm/ctz2.S | 77 +++++++++++++++++++++++++++++++++++++++- libgcc/config/arm/t-elf | 2 ++ 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/libgcc/config/arm/ctz2.S b/libgcc/config/arm/ctz2.S index dc436af3571..b9528a061a2 100644 --- a/libgcc/config/arm/ctz2.S +++ b/libgcc/config/arm/ctz2.S @@ -1,4 +1,4 @@ -/* ctz2.S: ARM optimized 'ctz' functions +/* ctz2.S: ARM optimized 'ctz' and related functions Copyright (C) 2020-2021 Free Software Foundation, Inc. Contributed by Daniel Engel (gnu@danielengel.com) @@ -238,3 +238,78 @@ FUNC_END ctzdi2 #endif /* L_ctzsi2 || L_ctzdi2 */ + +#ifdef L_ffsdi2 + +// int __ffsdi2(int) +// Return the index of the least significant 1-bit in $r1:r0, +// or zero if $r1:r0 is zero. The least significant bit is index 1. +// Returns the result in $r0. +// Uses $r2 and possibly $r3 as scratch space. +// Same section as __ctzsi2() for sake of the tail call branches. +FUNC_START_SECTION ffsdi2 .text.sorted.libgcc.ctz2.ffsdi2 + CFI_START_FUNCTION + + // Simplify branching by assuming a non-zero lower word. + // For all such, ffssi2(x) == ctzsi2(x) + 1. + movs r2, #(33 - CTZ_RESULT_OFFSET) + + #if defined(__ARMEB__) && __ARMEB__ + // HACK: Save the upper word in a scratch register. + movs r3, r0 + + // Test the lower word. + movs r0, r1 + bne SYM(__internal_ctzsi2) + + // Test the upper word. + movs r2, #(65 - CTZ_RESULT_OFFSET) + movs r0, r3 + bne SYM(__internal_ctzsi2) + + #else /* !__ARMEB__ */ + // Test the lower word. + cmp r0, #0 + bne SYM(__internal_ctzsi2) + + // Test the upper word. + movs r2, #(65 - CTZ_RESULT_OFFSET) + movs r0, r1 + bne SYM(__internal_ctzsi2) + + #endif /* !__ARMEB__ */ + + // Upper and lower words are both zero. + RET + + CFI_END_FUNCTION +FUNC_END ffsdi2 + +#endif /* L_ffsdi2 */ + + +#ifdef L_ffssi2 + +// int __ffssi2(int) +// Return the index of the least significant 1-bit in $r0, +// or zero if $r0 is zero. The least significant bit is index 1. +// Returns the result in $r0. +// Uses $r2 and possibly $r3 as scratch space. +// Same section as __ctzsi2() for sake of the tail call branches. +FUNC_START_SECTION ffssi2 .text.sorted.libgcc.ctz2.ffssi2 + CFI_START_FUNCTION + + // Simplify branching by assuming a non-zero argument. + // For all such, ffssi2(x) == ctzsi2(x) + 1. + movs r2, #(33 - CTZ_RESULT_OFFSET) + + // Test for zero, return unmodified. + cmp r0, #0 + bne SYM(__internal_ctzsi2) + RET + + CFI_END_FUNCTION +FUNC_END ffssi2 + +#endif /* L_ffssi2 */ + diff --git a/libgcc/config/arm/t-elf b/libgcc/config/arm/t-elf index 89071cebe45..346fc766f17 100644 --- a/libgcc/config/arm/t-elf +++ b/libgcc/config/arm/t-elf @@ -35,6 +35,8 @@ LIB1ASMFUNCS += \ _clrsbdi2 \ _clzdi2 \ _ctzdi2 \ + _ffssi2 \ + _ffsdi2 \ _dvmd_tls \ _divsi3 \ _modsi3 \