xref: /netbsd-src/external/gpl3/gdb/dist/libiberty/ffs.c (revision 98b9484c67cdf05a7e01fa6a65d1f4f959a3633e)
1*98b9484cSchristos /* ffs -- Find the first bit set in the parameter
2*98b9484cSchristos 
3*98b9484cSchristos @deftypefn Supplemental int ffs (int @var{valu})
4*98b9484cSchristos 
5*98b9484cSchristos Find the first (least significant) bit set in @var{valu}.  Bits are
6*98b9484cSchristos numbered from right to left, starting with bit 1 (corresponding to the
7*98b9484cSchristos value 1).  If @var{valu} is zero, zero is returned.
8*98b9484cSchristos 
9*98b9484cSchristos @end deftypefn
10*98b9484cSchristos 
11*98b9484cSchristos */
12*98b9484cSchristos 
13*98b9484cSchristos int
ffs(register int valu)14*98b9484cSchristos ffs (register int valu)
15*98b9484cSchristos {
16*98b9484cSchristos   register int bit;
17*98b9484cSchristos 
18*98b9484cSchristos   if (valu == 0)
19*98b9484cSchristos     return 0;
20*98b9484cSchristos 
21*98b9484cSchristos   for (bit = 1; !(valu & 1); bit++)
22*98b9484cSchristos   	valu >>= 1;
23*98b9484cSchristos 
24*98b9484cSchristos   return bit;
25*98b9484cSchristos }
26*98b9484cSchristos 
27