^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___FFS_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define _ASM_GENERIC_BITOPS___FFS_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <asm/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * __ffs - find first bit in word.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * @word: The word to search
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Undefined if no bit exists, so code should check against 0 first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) static __always_inline unsigned long __ffs(unsigned long word)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) int num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #if BITS_PER_LONG == 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) if ((word & 0xffffffff) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) num += 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) word >>= 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) if ((word & 0xffff) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) num += 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) word >>= 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) if ((word & 0xff) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) num += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) word >>= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) if ((word & 0xf) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) num += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) word >>= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) if ((word & 0x3) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) num += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) word >>= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if ((word & 0x1) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) num += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #endif /* _ASM_GENERIC_BITOPS___FFS_H_ */