>From: Mike Frysinger [mailto:[email protected]]
>
>On Wed, Nov 18, 2009 at 04:52,  <[email protected]> wrote:
>> Revision 7844 Author hennerich Date 2009-11-18 04:52:03 -0500 (Wed, 18
>Nov
>> 2009)
>>
>> Log Message
>>
>> Fix BFIN_DEPOSIT and BFIN_EXTRACT macros:
>> find first bit in word (__ffs) returns 0 in case the first bit in word
>> is set.
>>
>> Modified: trunk/arch/blackfin/include/asm/def_LPBlackfin.h (7843 =>
>7844)
>>
>> -#define BFIN_DEPOSIT(mask, x)       (((x) << (__ffs(mask) - 1)) &
>(mask))
>> -#define BFIN_EXTRACT(mask, x)       (((x) & (mask)) >> (__ffs(mask) -
>1))
>> +#define BFIN_DEPOSIT(mask, x)       (((x) << __ffs(mask)) & (mask))
>> +#define BFIN_EXTRACT(mask, x)       (((x) & (mask)) >> __ffs(mask))
>
>i was going by the documentation:
>/**
> * ffs - find first bit set
> * @x: the word to search
> *
> * This is defined the same way as
> * the libc and compiler builtin ffs routines
>
>and my C library does:
>$ cat test.c
>#include <strings.h>
>#include <stdio.h>
>main(){printf("%i\n", ffs(1));}
>$ gcc test.c && ./a.out
>1
>
>so if you give a mask of 0x3ff, ffs() should return 1, and you dont
>want to do any shifting.  i'll have to double check what the kernel
>does.
>-mike

This is what the kernel uses:
asm-geeneric/bitops/__ffs.h

/**
 * __ffs - find first bit in word.
 * @word: The word to search
 *
 * Undefined if no bit exists, so code should check against 0 first.
 */
static __always_inline unsigned long __ffs(unsigned long word)
{
        int num = 0;

#if BITS_PER_LONG == 64
        if ((word & 0xffffffff) == 0) {
                num += 32;
                word >>= 32;
        }
#endif
        if ((word & 0xffff) == 0) {
                num += 16;
                word >>= 16;
        }
        if ((word & 0xff) == 0) {
                num += 8;
                word >>= 8;
        }
        if ((word & 0xf) == 0) {
                num += 4;
                word >>= 4;
        }
        if ((word & 0x3) == 0) {
                num += 2;
                word >>= 2;
        }
        if ((word & 0x1) == 0)
                num += 1;
        return num;
}

-Michael
_______________________________________________
Linux-kernel-commits mailing list
[email protected]
https://blackfin.uclinux.org/mailman/listinfo/linux-kernel-commits

Reply via email to