18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _ASM_GENERIC_BITOPS_FLS64_H_ 38c2ecf20Sopenharmony_ci#define _ASM_GENERIC_BITOPS_FLS64_H_ 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <asm/types.h> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci/** 88c2ecf20Sopenharmony_ci * fls64 - find last set bit in a 64-bit word 98c2ecf20Sopenharmony_ci * @x: the word to search 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * This is defined in a similar way as the libc and compiler builtin 128c2ecf20Sopenharmony_ci * ffsll, but returns the position of the most significant set bit. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * fls64(value) returns 0 if value is 0 or the position of the last 158c2ecf20Sopenharmony_ci * set bit if value is nonzero. The last (most significant) bit is 168c2ecf20Sopenharmony_ci * at position 64. 178c2ecf20Sopenharmony_ci */ 188c2ecf20Sopenharmony_ci#if BITS_PER_LONG == 32 198c2ecf20Sopenharmony_cistatic __always_inline int fls64(__u64 x) 208c2ecf20Sopenharmony_ci{ 218c2ecf20Sopenharmony_ci __u32 h = x >> 32; 228c2ecf20Sopenharmony_ci if (h) 238c2ecf20Sopenharmony_ci return fls(h) + 32; 248c2ecf20Sopenharmony_ci return fls(x); 258c2ecf20Sopenharmony_ci} 268c2ecf20Sopenharmony_ci#elif BITS_PER_LONG == 64 278c2ecf20Sopenharmony_cistatic __always_inline int fls64(__u64 x) 288c2ecf20Sopenharmony_ci{ 298c2ecf20Sopenharmony_ci if (x == 0) 308c2ecf20Sopenharmony_ci return 0; 318c2ecf20Sopenharmony_ci return __fls(x) + 1; 328c2ecf20Sopenharmony_ci} 338c2ecf20Sopenharmony_ci#else 348c2ecf20Sopenharmony_ci#error BITS_PER_LONG not 32 or 64 358c2ecf20Sopenharmony_ci#endif 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#endif /* _ASM_GENERIC_BITOPS_FLS64_H_ */ 38