blob: 86470cfcef60bf73d6b924577b37decde39315d0 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Akinobu Mita6d29ea22006-03-26 01:39:12 -08002#ifndef _ASM_GENERIC_BITOPS_SCHED_H_
3#define _ASM_GENERIC_BITOPS_SCHED_H_
4
5#include <linux/compiler.h> /* unlikely() */
6#include <asm/types.h>
7
8/*
9 * Every architecture must define this function. It's the fastest
Mike Galbraithff80a772007-07-09 18:52:00 +020010 * way of searching a 100-bit bitmap. It's guaranteed that at least
11 * one of the 100 bits is cleared.
Akinobu Mita6d29ea22006-03-26 01:39:12 -080012 */
13static inline int sched_find_first_bit(const unsigned long *b)
14{
15#if BITS_PER_LONG == 64
Mike Galbraithff80a772007-07-09 18:52:00 +020016 if (b[0])
Akinobu Mita6d29ea22006-03-26 01:39:12 -080017 return __ffs(b[0]);
Mike Galbraithff80a772007-07-09 18:52:00 +020018 return __ffs(b[1]) + 64;
Akinobu Mita6d29ea22006-03-26 01:39:12 -080019#elif BITS_PER_LONG == 32
Mike Galbraithff80a772007-07-09 18:52:00 +020020 if (b[0])
Akinobu Mita6d29ea22006-03-26 01:39:12 -080021 return __ffs(b[0]);
Mike Galbraithff80a772007-07-09 18:52:00 +020022 if (b[1])
Akinobu Mita6d29ea22006-03-26 01:39:12 -080023 return __ffs(b[1]) + 32;
Mike Galbraithff80a772007-07-09 18:52:00 +020024 if (b[2])
Akinobu Mita6d29ea22006-03-26 01:39:12 -080025 return __ffs(b[2]) + 64;
Mike Galbraithff80a772007-07-09 18:52:00 +020026 return __ffs(b[3]) + 96;
Akinobu Mita6d29ea22006-03-26 01:39:12 -080027#else
28#error BITS_PER_LONG not defined
29#endif
30}
31
32#endif /* _ASM_GENERIC_BITOPS_SCHED_H_ */