^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef _ASM_GENERIC_BITOPS_SCHED_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define _ASM_GENERIC_BITOPS_SCHED_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/compiler.h> /* unlikely() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <asm/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Every architecture must define this function. It's the fastest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * way of searching a 100-bit bitmap. It's guaranteed that at least
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * one of the 100 bits is cleared.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) static inline int sched_find_first_bit(const unsigned long *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #if BITS_PER_LONG == 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) if (b[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) return __ffs(b[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) return __ffs(b[1]) + 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #elif BITS_PER_LONG == 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) if (b[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) return __ffs(b[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) if (b[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) return __ffs(b[1]) + 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) if (b[2])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) return __ffs(b[2]) + 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) return __ffs(b[3]) + 96;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #error BITS_PER_LONG not defined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #endif /* _ASM_GENERIC_BITOPS_SCHED_H_ */