18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _ASM_GENERIC_BITOPS_FLS_H_ 38c2ecf20Sopenharmony_ci#define _ASM_GENERIC_BITOPS_FLS_H_ 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci/** 68c2ecf20Sopenharmony_ci * fls - find last (most-significant) bit set 78c2ecf20Sopenharmony_ci * @x: the word to search 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * This is defined the same way as ffs. 108c2ecf20Sopenharmony_ci * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32. 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cistatic __always_inline int fls(unsigned int x) 148c2ecf20Sopenharmony_ci{ 158c2ecf20Sopenharmony_ci int r = 32; 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci if (!x) 188c2ecf20Sopenharmony_ci return 0; 198c2ecf20Sopenharmony_ci if (!(x & 0xffff0000u)) { 208c2ecf20Sopenharmony_ci x <<= 16; 218c2ecf20Sopenharmony_ci r -= 16; 228c2ecf20Sopenharmony_ci } 238c2ecf20Sopenharmony_ci if (!(x & 0xff000000u)) { 248c2ecf20Sopenharmony_ci x <<= 8; 258c2ecf20Sopenharmony_ci r -= 8; 268c2ecf20Sopenharmony_ci } 278c2ecf20Sopenharmony_ci if (!(x & 0xf0000000u)) { 288c2ecf20Sopenharmony_ci x <<= 4; 298c2ecf20Sopenharmony_ci r -= 4; 308c2ecf20Sopenharmony_ci } 318c2ecf20Sopenharmony_ci if (!(x & 0xc0000000u)) { 328c2ecf20Sopenharmony_ci x <<= 2; 338c2ecf20Sopenharmony_ci r -= 2; 348c2ecf20Sopenharmony_ci } 358c2ecf20Sopenharmony_ci if (!(x & 0x80000000u)) { 368c2ecf20Sopenharmony_ci x <<= 1; 378c2ecf20Sopenharmony_ci r -= 1; 388c2ecf20Sopenharmony_ci } 398c2ecf20Sopenharmony_ci return r; 408c2ecf20Sopenharmony_ci} 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#endif /* _ASM_GENERIC_BITOPS_FLS_H_ */ 43