1221420Sdes#ifndef _ASM_GENERIC_BITOPS_FLS64_H_
2162852Sdes#define _ASM_GENERIC_BITOPS_FLS64_H_
3162852Sdes
4162852Sdes#include <asm/types.h>
5162852Sdes
6162852Sdes/**
7162852Sdes * fls64 - find last set bit in a 64-bit word
8162852Sdes * @x: the word to search
9162852Sdes *
10162852Sdes * This is defined in a similar way as the libc and compiler builtin
11162852Sdes * ffsll, but returns the position of the most significant set bit.
12162852Sdes *
13162852Sdes * fls64(value) returns 0 if value is 0 or the position of the last
14162852Sdes * set bit if value is nonzero. The last (most significant) bit is
15162852Sdes * at position 64.
16162852Sdes */
17162852Sdes#if BITS_PER_LONG == 32
18162852Sdesstatic __always_inline int fls64(__u64 x)
19162852Sdes{
20162852Sdes	__u32 h = x >> 32;
21162852Sdes	if (h)
22162852Sdes		return fls(h) + 32;
23162852Sdes	return fls(x);
24162852Sdes}
25162852Sdes#elif BITS_PER_LONG == 64
26162852Sdesstatic __always_inline int fls64(__u64 x)
27162852Sdes{
28162852Sdes	if (x == 0)
29162852Sdes		return 0;
30162852Sdes	return __fls(x) + 1;
31162852Sdes}
32162852Sdes#else
33162852Sdes#error BITS_PER_LONG not 32 or 64
34162852Sdes#endif
35162852Sdes
36162852Sdes#endif /* _ASM_GENERIC_BITOPS_FLS64_H_ */
37162852Sdes