Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_GENERIC_BITOPS_FFS_H_
0003 #define _ASM_GENERIC_BITOPS_FFS_H_
0004 
0005 /**
0006  * ffs - find first bit set
0007  * @x: the word to search
0008  *
0009  * This is defined the same way as
0010  * the libc and compiler builtin ffs routines, therefore
0011  * differs in spirit from ffz (man ffs).
0012  */
0013 static inline int ffs(int x)
0014 {
0015     int r = 1;
0016 
0017     if (!x)
0018         return 0;
0019     if (!(x & 0xffff)) {
0020         x >>= 16;
0021         r += 16;
0022     }
0023     if (!(x & 0xff)) {
0024         x >>= 8;
0025         r += 8;
0026     }
0027     if (!(x & 0xf)) {
0028         x >>= 4;
0029         r += 4;
0030     }
0031     if (!(x & 3)) {
0032         x >>= 2;
0033         r += 2;
0034     }
0035     if (!(x & 1)) {
0036         x >>= 1;
0037         r += 1;
0038     }
0039     return r;
0040 }
0041 
0042 #endif /* _ASM_GENERIC_BITOPS_FFS_H_ */