/* SPDX-License-Identifier: GPL-2.0 */1#ifndef _ASM_GENERIC_BITOPS_FFS_H_2#define _ASM_GENERIC_BITOPS_FFS_H_34/**5* generic_ffs - find first bit set6* @x: the word to search7*8* This is defined the same way as9* the libc and compiler builtin ffs routines, therefore10* differs in spirit from ffz (man ffs).11*/12static inline int generic_ffs(int x)13{14int r = 1;1516if (!x)17return 0;18if (!(x & 0xffff)) {19x >>= 16;20r += 16;21}22if (!(x & 0xff)) {23x >>= 8;24r += 8;25}26if (!(x & 0xf)) {27x >>= 4;28r += 4;29}30if (!(x & 3)) {31x >>= 2;32r += 2;33}34if (!(x & 1)) {35x >>= 1;36r += 1;37}38return r;39}4041#ifndef __HAVE_ARCH_FFS42#define ffs(x) generic_ffs(x)43#endif4445#endif /* _ASM_GENERIC_BITOPS_FFS_H_ */464748