From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12190 Path: news.gmane.org!.POSTED!not-for-mail From: Andre McCurdy Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] arm: provide a_ctz_l and a_ctz_64 helper functions Date: Thu, 30 Nov 2017 16:00:12 -0800 Message-ID: <1512086412-30631-1-git-send-email-armccurdy@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1512086438 3254 195.159.176.226 (1 Dec 2017 00:00:38 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 1 Dec 2017 00:00:38 +0000 (UTC) Cc: Andre McCurdy To: musl@lists.openwall.com Original-X-From: musl-return-12206-gllmg-musl=m.gmane.org@lists.openwall.com Fri Dec 01 01:00:29 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1eKYkk-0000GA-SU for gllmg-musl@m.gmane.org; Fri, 01 Dec 2017 01:00:26 +0100 Original-Received: (qmail 30508 invoked by uid 550); 1 Dec 2017 00:00:32 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 30471 invoked from network); 1 Dec 2017 00:00:31 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=uJKFBHhd6Uwux6xulDw20+IYsiRTxii32HdsknvX8W4=; b=KOqvLb4u5Q1IjVja7+6ZC1fdbTmls+1EZm/uc4CCOl7SdMxbv72ckKIlLdKHCH1Rho vMz7sAYRKC+T/yVWXwYbk1Y0mtoLkcWutO9UqHsJ9Jz5pnSZQBK1zWWBAM+w6kx8V6GD tk3cGcXLjpjeUfIaeChM0RgCjzUlYWb/iWDDyxF4TwT1LLS9sfEjLLbkpaJsDXNcUJVX lUAyo2/g0tLw4+RqqqLXdV7v55aOlLOG2hHCgwZWNjZ82HuAtnXslBLeNn/DiT/rcLlj PXfoxH4pf9dSzCnAjkMJkraPw3PQGf0rXjy3lw+qYhdZkNV89dR4krkwOLCuwXx4ju9X gVTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=uJKFBHhd6Uwux6xulDw20+IYsiRTxii32HdsknvX8W4=; b=tIHTlFA1Wplz/EEQM4jgn786xDmLA1XZdW9QnInyYggXTWUDbw1HFzXM+96XWZG7J8 nX24i4+c8czNkDO1ttZ1ZiKp6MN3dwiEkswcsuP6dylU5DTr2Oq8L7xMntPlDgy0LJrc LjZ4cpQL7o5XtuAYz8VQ8Ogsvv6PuiYnZ0q379m/f1OYklzzFRl21R5jXar2i/kwGrHa AAd4mrtOfVa9UyxMUmEwttFecpS+efu/CERmnz/i20/xg4IFBzYezDPUkuqQfT6sfMBw UF6Ap/tiSM3I7FT7Pt6s0vKerY+FdgDDFx2dT39YemXyivDmFN1tC24Xk8d3ell00Nr+ Q1oA== X-Gm-Message-State: AJaThX5e4qQlMRVRD5ouoYeJsLA8l9rU/hDPg+eMMmXBZKA4gDmoFVvL 8H0uUZnPVkVZotvVVR4gueBv5g== X-Google-Smtp-Source: AGs4zMZYGLb0S0VFqG7J3ZdohnRtCwbns3syEL1nVzCSDgsPfedroPaHcuOI7Flfx9bUtroQd6TSLQ== X-Received: by 10.98.16.90 with SMTP id y87mr8424041pfi.116.1512086419446; Thu, 30 Nov 2017 16:00:19 -0800 (PST) X-Mailer: git-send-email 1.9.1 Xref: news.gmane.org gmane.linux.lib.musl.general:12190 Archived-At: Provide an ARM specific a_ctz_l helper function for architecture versions for which it can be implemented efficiently via the "rbit" instruction (ie all Thumb-2 capable versions of ARM v6 and above). Signed-off-by: Andre McCurdy --- arch/arm/atomic_arch.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/arm/atomic_arch.h b/arch/arm/atomic_arch.h index 6e2e3b4..9242df8 100644 --- a/arch/arm/atomic_arch.h +++ b/arch/arm/atomic_arch.h @@ -91,4 +91,26 @@ static inline int a_clz_32(uint32_t x) return x; } +#if __ARM_ARCH_6T2__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7 + +#define a_ctz_l a_ctz_l +static inline int a_ctz_l(unsigned long x) +{ + uint32_t xr; + __asm__ ("rbit %0, %1" : "=r"(xr) : "r"(x)); + return a_clz_32(xr); +} + +#define a_ctz_64 a_ctz_64 +static inline int a_ctz_64(uint64_t x) +{ + uint32_t y = x; + if (!y) { + y = x>>32; + return 32 + a_ctz_l(y); + } + return a_ctz_l(y); +} + +#endif #endif -- 1.9.1