xref: /linux/include/asm-generic/bitops/sched.h (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
26d29ea23SAkinobu Mita #ifndef _ASM_GENERIC_BITOPS_SCHED_H_
36d29ea23SAkinobu Mita #define _ASM_GENERIC_BITOPS_SCHED_H_
46d29ea23SAkinobu Mita 
56d29ea23SAkinobu Mita #include <linux/compiler.h>	/* unlikely() */
66d29ea23SAkinobu Mita #include <asm/types.h>
76d29ea23SAkinobu Mita 
86d29ea23SAkinobu Mita /*
96d29ea23SAkinobu Mita  * Every architecture must define this function. It's the fastest
10ff80a77fSMike Galbraith  * way of searching a 100-bit bitmap.  It's guaranteed that at least
11ff80a77fSMike Galbraith  * one of the 100 bits is cleared.
126d29ea23SAkinobu Mita  */
sched_find_first_bit(const unsigned long * b)136d29ea23SAkinobu Mita static inline int sched_find_first_bit(const unsigned long *b)
146d29ea23SAkinobu Mita {
156d29ea23SAkinobu Mita #if BITS_PER_LONG == 64
16ff80a77fSMike Galbraith 	if (b[0])
176d29ea23SAkinobu Mita 		return __ffs(b[0]);
186d29ea23SAkinobu Mita 	return __ffs(b[1]) + 64;
196d29ea23SAkinobu Mita #elif BITS_PER_LONG == 32
20ff80a77fSMike Galbraith 	if (b[0])
216d29ea23SAkinobu Mita 		return __ffs(b[0]);
22ff80a77fSMike Galbraith 	if (b[1])
236d29ea23SAkinobu Mita 		return __ffs(b[1]) + 32;
24ff80a77fSMike Galbraith 	if (b[2])
256d29ea23SAkinobu Mita 		return __ffs(b[2]) + 64;
266d29ea23SAkinobu Mita 	return __ffs(b[3]) + 96;
276d29ea23SAkinobu Mita #else
286d29ea23SAkinobu Mita #error BITS_PER_LONG not defined
296d29ea23SAkinobu Mita #endif
306d29ea23SAkinobu Mita }
316d29ea23SAkinobu Mita 
326d29ea23SAkinobu Mita #endif /* _ASM_GENERIC_BITOPS_SCHED_H_ */
33