blob: 604fab7031a62e2a8ae2f0cde8022362fd89c38b [file] [log] [blame]
Akinobu Mita6d29ea22006-03-26 01:39:12 -08001#ifndef _ASM_GENERIC_BITOPS_SCHED_H_
2#define _ASM_GENERIC_BITOPS_SCHED_H_
3
4#include <linux/compiler.h> /* unlikely() */
5#include <asm/types.h>
6
7/*
8 * Every architecture must define this function. It's the fastest
Mike Galbraithff80a772007-07-09 18:52:00 +02009 * way of searching a 100-bit bitmap. It's guaranteed that at least
10 * one of the 100 bits is cleared.
Akinobu Mita6d29ea22006-03-26 01:39:12 -080011 */
12static inline int sched_find_first_bit(const unsigned long *b)
13{
14#if BITS_PER_LONG == 64
Mike Galbraithff80a772007-07-09 18:52:00 +020015 if (b[0])
Akinobu Mita6d29ea22006-03-26 01:39:12 -080016 return __ffs(b[0]);
Mike Galbraithff80a772007-07-09 18:52:00 +020017 return __ffs(b[1]) + 64;
Akinobu Mita6d29ea22006-03-26 01:39:12 -080018#elif BITS_PER_LONG == 32
Mike Galbraithff80a772007-07-09 18:52:00 +020019 if (b[0])
Akinobu Mita6d29ea22006-03-26 01:39:12 -080020 return __ffs(b[0]);
Mike Galbraithff80a772007-07-09 18:52:00 +020021 if (b[1])
Akinobu Mita6d29ea22006-03-26 01:39:12 -080022 return __ffs(b[1]) + 32;
Mike Galbraithff80a772007-07-09 18:52:00 +020023 if (b[2])
Akinobu Mita6d29ea22006-03-26 01:39:12 -080024 return __ffs(b[2]) + 64;
Mike Galbraithff80a772007-07-09 18:52:00 +020025 return __ffs(b[3]) + 96;
Akinobu Mita6d29ea22006-03-26 01:39:12 -080026#else
27#error BITS_PER_LONG not defined
28#endif
29}
30
31#endif /* _ASM_GENERIC_BITOPS_SCHED_H_ */