[parisc-linux] backport bitops.h stuff

James Bottomley James.Bottomley@steeleye.com
01 Aug 2003 12:33:24 -0500


On Fri, 2003-08-01 at 12:14, LaMont Jones wrote:
> ffs(0)==31
> ffs(1)==0
> ffs(2)==1
> ffs(3)==0
> ffs(4)==2
> ffs(80000000)==31

This is off by one.  The definition should say

ffs(0) == 0
ffs(1) == 1
ffs(2) == 2
ffs(4) == 3
...
ffs(0x80000000) == 32

i.e. it returns the first set bit starting counting at one. (Yes, I know
it's confusing, it's tripped me up, especially as ffz counts bits from
zero.  However, ffs is a BSD standard).

Most arch's start by defining an __ffs which is not defined for the zero
case and then build the real ffs from that.

James