From mboxrd@z Thu Jan 1 00:00:00 1970 Received: with ECARTIS (v1.0.0; list linux-mips); Tue, 14 Feb 2006 05:06:52 +0000 (GMT) Received: from ns.miraclelinux.com ([219.118.163.66]:41679 "EHLO mail01.miraclelinux.com") by ftp.linux-mips.org with ESMTP id S3458549AbWBNE6v (ORCPT ); Tue, 14 Feb 2006 04:58:51 +0000 Received: from mail01 (localhost.localdomain [127.0.0.1]) by mail01.miraclelinux.com (Postfix) with ESMTP id 138F731C335; Tue, 14 Feb 2006 14:04:47 +0900 (JST) Received: from localhost.localdomain (sshgate.miraclelinux.com []) by mail01.miraclelinux.com ([10.1.0.10]); Tue, 14 Feb 2006 05:04:46 +0000 Received: by localhost.localdomain (Postfix, from userid 1000) id 5FC4D42023A; Tue, 14 Feb 2006 14:04:44 +0900 (JST) Message-Id: <20060214050444.235416000@localhost.localdomain> References: <20060214050351.252615000@localhost.localdomain> Date: Tue, 14 Feb 2006 14:04:04 +0900 From: Akinobu Mita To: linux-kernel@vger.kernel.org Cc: akpm@osdl.org, Russell King , Ian Molton , dev-etrax@axis.com, David Howells , Yoshinori Sato , Linus Torvalds , linux-ia64@vger.kernel.org, Hirokazu Takata , linux-m68k@lists.linux-m68k.org, Greg Ungerer , linux-mips@linux-mips.org, parisc-linux@parisc-linux.org, linuxppc-dev@ozlabs.org, linux390@de.ibm.com, linuxsh-dev@lists.sourceforge.net, linuxsh-shmedia-dev@lists.sourceforge.net, sparclinux@vger.kernel.org, ultralinux@vger.kernel.org, Miles Bader , Andi Kleen , Chris Zankel , Akinobu Mita Subject: [patch 13/47] generic sched_find_first_bit() Content-Disposition: inline; filename=sched-bitops.patch Return-Path: X-Envelope-To: <"|/home/ecartis/ecartis -s linux-mips"> (uid 0) X-Orcpt: rfc822;linux-mips@linux-mips.org Original-Recipient: rfc822;linux-mips@linux-mips.org X-archive-position: 10443 X-ecartis-version: Ecartis v1.0.0 Sender: linux-mips-bounce@linux-mips.org Errors-to: linux-mips-bounce@linux-mips.org X-original-sender: mita@miraclelinux.com Precedence: bulk X-list: linux-mips This patch introduces the C-language equivalent of the function: int sched_find_first_bit(const unsigned long *b); In include/asm-generic/bitops/sched.h This code largely copied from: include/asm-powerpc/bitops.h Signed-off-by: Akinobu Mita include/asm-generic/bitops/sched.h | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+) Index: 2.6-rc/include/asm-generic/bitops/sched.h =================================================================== --- /dev/null +++ 2.6-rc/include/asm-generic/bitops/sched.h @@ -0,0 +1,36 @@ +#ifndef _ASM_GENERIC_BITOPS_SCHED_H_ +#define _ASM_GENERIC_BITOPS_SCHED_H_ + +#include /* unlikely() */ +#include + +/* + * Every architecture must define this function. It's the fastest + * way of searching a 140-bit bitmap where the first 100 bits are + * unlikely to be set. It's guaranteed that at least one of the 140 + * bits is cleared. + */ +static inline int sched_find_first_bit(const unsigned long *b) +{ +#if BITS_PER_LONG == 64 + if (unlikely(b[0])) + return __ffs(b[0]); + if (unlikely(b[1])) + return __ffs(b[1]) + 64; + return __ffs(b[2]) + 128; +#elif BITS_PER_LONG == 32 + if (unlikely(b[0])) + return __ffs(b[0]); + if (unlikely(b[1])) + return __ffs(b[1]) + 32; + if (unlikely(b[2])) + return __ffs(b[2]) + 64; + if (b[3]) + return __ffs(b[3]) + 96; + return __ffs(b[4]) + 128; +#else +#error BITS_PER_LONG not defined +#endif +} + +#endif /* _ASM_GENERIC_BITOPS_SCHED_H_ */ --