From patchwork Wed Sep 12 21:12:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 1446861 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (unknown [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 5EC1F3FCFC for ; Wed, 12 Sep 2012 21:25:54 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TBuGE-0006Og-P0; Wed, 12 Sep 2012 21:14:14 +0000 Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TBuGA-0006JF-Ds for linux-arm-kernel@lists.infradead.org; Wed, 12 Sep 2012 21:14:12 +0000 Received: from arm.com (e102109-lin.cambridge.arm.com [10.1.69.68]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id q8CLDXE7023661; Wed, 12 Sep 2012 22:13:34 +0100 (BST) Date: Wed, 12 Sep 2012 22:12:59 +0100 From: Catalin Marinas To: Arnd Bergmann Subject: Re: [PATCH v3 26/31] arm64: Miscellaneous library functions Message-ID: <20120912211259.GA8252@arm.com> References: <1347035226-18649-1-git-send-email-catalin.marinas@arm.com> <1347035226-18649-27-git-send-email-catalin.marinas@arm.com> <201209071952.14309.arnd@arndb.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <201209071952.14309.arnd@arndb.de> User-Agent: Mutt/1.5.20 (2009-06-14) X-Spam-Note: CRM114 invocation failed X-Spam-Score: -7.3 (-------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-7.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [217.140.96.50 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.4 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: "linux-arch@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org On Fri, Sep 07, 2012 at 08:52:13PM +0100, Arnd Bergmann wrote: > On Friday 07 September 2012, Catalin Marinas wrote: > > +/* > > + * Use compiler builtins for simple inline operations. > > + */ > > +static inline unsigned long __ffs(unsigned long word) > > +{ > > + return __builtin_ffsl(word) - 1; > > +} > > + > > +static inline int ffs(int x) > > +{ > > + return __builtin_ffs(x); > > +} > > + > > +static inline unsigned long __fls(unsigned long word) > > +{ > > + return BITS_PER_LONG - 1 - __builtin_clzl(word); > > +} > > + > > +static inline int fls(int x) > > +{ > > + return x ? sizeof(x) * BITS_PER_BYTE - __builtin_clz(x) : 0; > > +} > > Still waiting for the generic version of these. What about these: From 64ec78a2fce931e0148db90747c69688f248a531 Mon Sep 17 00:00:00 2001 From: Catalin Marinas Date: Wed, 12 Sep 2012 22:00:53 +0100 Subject: [PATCH 1/2] Implement generic ffs/fls using __builtin_* functions This patch implements ffs, __ffs, fls, __fls using __builtin_* gcc functions. These header files can be used by other architectures that rely on the gcc builtins. Signed-off-by: Catalin Marinas Cc: Arnd Bergmann Acked-by: Arnd Bergmann --- include/asm-generic/bitops/builtin-__ffs.h | 15 +++++++++++++++ include/asm-generic/bitops/builtin-__fls.h | 15 +++++++++++++++ include/asm-generic/bitops/builtin-ffs.h | 17 +++++++++++++++++ include/asm-generic/bitops/builtin-fls.h | 16 ++++++++++++++++ 4 files changed, 63 insertions(+), 0 deletions(-) create mode 100644 include/asm-generic/bitops/builtin-__ffs.h create mode 100644 include/asm-generic/bitops/builtin-__fls.h create mode 100644 include/asm-generic/bitops/builtin-ffs.h create mode 100644 include/asm-generic/bitops/builtin-fls.h diff --git a/include/asm-generic/bitops/builtin-__ffs.h b/include/asm-generic/bitops/builtin-__ffs.h new file mode 100644 index 0000000..90041e3 --- /dev/null +++ b/include/asm-generic/bitops/builtin-__ffs.h @@ -0,0 +1,15 @@ +#ifndef _ASM_GENERIC_BITOPS_BUILTIN___FFS_H_ +#define _ASM_GENERIC_BITOPS_BUILTIN___FFS_H_ + +/** + * __ffs - find first bit in word. + * @word: The word to search + * + * Undefined if no bit exists, so code should check against 0 first. + */ +static __always_inline unsigned long __ffs(unsigned long word) +{ + return __builtin_ctzl(word); +} + +#endif diff --git a/include/asm-generic/bitops/builtin-__fls.h b/include/asm-generic/bitops/builtin-__fls.h new file mode 100644 index 0000000..0248f38 --- /dev/null +++ b/include/asm-generic/bitops/builtin-__fls.h @@ -0,0 +1,15 @@ +#ifndef _ASM_GENERIC_BITOPS_BUILTIN___FLS_H_ +#define _ASM_GENERIC_BITOPS_BUILTIN___FLS_H_ + +/** + * __fls - find last (most-significant) set bit in a long word + * @word: the word to search + * + * Undefined if no set bit exists, so code should check against 0 first. + */ +static __always_inline unsigned long __fls(unsigned long word) +{ + return (sizeof(word) * 8) - 1 - __builtin_clzl(word); +} + +#endif diff --git a/include/asm-generic/bitops/builtin-ffs.h b/include/asm-generic/bitops/builtin-ffs.h new file mode 100644 index 0000000..0648258 --- /dev/null +++ b/include/asm-generic/bitops/builtin-ffs.h @@ -0,0 +1,17 @@ +#ifndef _ASM_GENERIC_BITOPS_BUILTIN_FFS_H_ +#define _ASM_GENERIC_BITOPS_BUILTIN_FFS_H_ + +/** + * ffs - find first bit set + * @x: the word to search + * + * This is defined the same way as + * the libc and compiler builtin ffs routines, therefore + * differs in spirit from the above ffz (man ffs). + */ +static __always_inline int ffs(int x) +{ + return __builtin_ffs(x); +} + +#endif diff --git a/include/asm-generic/bitops/builtin-fls.h b/include/asm-generic/bitops/builtin-fls.h new file mode 100644 index 0000000..eda652d --- /dev/null +++ b/include/asm-generic/bitops/builtin-fls.h @@ -0,0 +1,16 @@ +#ifndef _ASM_GENERIC_BITOPS_BUILTIN_FLS_H_ +#define _ASM_GENERIC_BITOPS_BUILTIN_FLS_H_ + +/** + * fls - find last (most-significant) bit set + * @x: the word to search + * + * This is defined the same way as ffs. + * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32. + */ +static __always_inline int fls(int x) +{ + return x ? sizeof(x) * 8 - __builtin_clz(x) : 0; +} + +#endif From 542f0b34b5674d8472b820f1ce751118ecdf9470 Mon Sep 17 00:00:00 2001 From: Catalin Marinas Date: Wed, 12 Sep 2012 22:06:22 +0100 Subject: [PATCH 2/2] arm64: Use the generic builtin-* ffs/fls implementation This patch removes the arm64-specific ffs/fls implementation and includes the generic gcc builtins implementation. Signed-off-by: Catalin Marinas --- arch/arm64/include/asm/bitops.h | 31 +++++-------------------------- 1 files changed, 5 insertions(+), 26 deletions(-) diff --git a/arch/arm64/include/asm/bitops.h b/arch/arm64/include/asm/bitops.h index 67df4d2..5e69307 100644 --- a/arch/arm64/include/asm/bitops.h +++ b/arch/arm64/include/asm/bitops.h @@ -28,36 +28,15 @@ #define smp_mb__after_clear_bit() smp_mb() #endif -/* - * Use compiler builtins for simple inline operations. - */ -static inline unsigned long __ffs(unsigned long word) -{ - return __builtin_ffsl(word) - 1; -} - -static inline int ffs(int x) -{ - return __builtin_ffs(x); -} - -static inline unsigned long __fls(unsigned long word) -{ - return BITS_PER_LONG - 1 - __builtin_clzl(word); -} - -static inline int fls(int x) -{ - return x ? sizeof(x) * BITS_PER_BYTE - __builtin_clz(x) : 0; -} - -/* - * Mainly use the generic routines for now. - */ #ifndef _LINUX_BITOPS_H #error only can be included directly #endif +#include +#include +#include +#include + #include #include #include