brintos

brintos / linux-shallow public Read only

0
0
Text · 852 B · 2d94c1e Raw
46 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2#ifndef _TOOLS_LINUX_ASM_GENERIC_BITOPS___FFS_H_3#define _TOOLS_LINUX_ASM_GENERIC_BITOPS___FFS_H_4 5#include <asm/types.h>6#include <asm/bitsperlong.h>7 8/**9 * __ffs - find first bit in word.10 * @word: The word to search11 *12 * Undefined if no bit exists, so code should check against 0 first.13 */14static __always_inline unsigned int __ffs(unsigned long word)15{16	unsigned int num = 0;17 18#if __BITS_PER_LONG == 6419	if ((word & 0xffffffff) == 0) {20		num += 32;21		word >>= 32;22	}23#endif24	if ((word & 0xffff) == 0) {25		num += 16;26		word >>= 16;27	}28	if ((word & 0xff) == 0) {29		num += 8;30		word >>= 8;31	}32	if ((word & 0xf) == 0) {33		num += 4;34		word >>= 4;35	}36	if ((word & 0x3) == 0) {37		num += 2;38		word >>= 2;39	}40	if ((word & 0x1) == 0)41		num += 1;42	return num;43}44 45#endif /* _TOOLS_LINUX_ASM_GENERIC_BITOPS___FFS_H_ */46