1*4882a593Smuzhiyun #ifndef _ASM_GENERIC_BITOPS_FFS_H_ 2*4882a593Smuzhiyun #define _ASM_GENERIC_BITOPS_FFS_H_ 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun /** 5*4882a593Smuzhiyun * ffs - find first bit set 6*4882a593Smuzhiyun * @x: the word to search 7*4882a593Smuzhiyun * 8*4882a593Smuzhiyun * This is defined the same way as 9*4882a593Smuzhiyun * the libc and compiler builtin ffs routines, therefore 10*4882a593Smuzhiyun * differs in spirit from the above ffz (man ffs). 11*4882a593Smuzhiyun */ ffs(int x)12*4882a593Smuzhiyunstatic inline int ffs(int x) 13*4882a593Smuzhiyun { 14*4882a593Smuzhiyun int r = 1; 15*4882a593Smuzhiyun 16*4882a593Smuzhiyun if (!x) 17*4882a593Smuzhiyun return 0; 18*4882a593Smuzhiyun if (!(x & 0xffff)) { 19*4882a593Smuzhiyun x >>= 16; 20*4882a593Smuzhiyun r += 16; 21*4882a593Smuzhiyun } 22*4882a593Smuzhiyun if (!(x & 0xff)) { 23*4882a593Smuzhiyun x >>= 8; 24*4882a593Smuzhiyun r += 8; 25*4882a593Smuzhiyun } 26*4882a593Smuzhiyun if (!(x & 0xf)) { 27*4882a593Smuzhiyun x >>= 4; 28*4882a593Smuzhiyun r += 4; 29*4882a593Smuzhiyun } 30*4882a593Smuzhiyun if (!(x & 3)) { 31*4882a593Smuzhiyun x >>= 2; 32*4882a593Smuzhiyun r += 2; 33*4882a593Smuzhiyun } 34*4882a593Smuzhiyun if (!(x & 1)) { 35*4882a593Smuzhiyun x >>= 1; 36*4882a593Smuzhiyun r += 1; 37*4882a593Smuzhiyun } 38*4882a593Smuzhiyun return r; 39*4882a593Smuzhiyun } 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun #endif /* _ASM_GENERIC_BITOPS_FFS_H_ */ 42