cvs commit: src/sys/libkern ffs.c ffsl.c fls.c flsl.c

Alex Lyashkov shadow at psoft.net
Tue Jan 13 20:54:06 PST 2004


On Tuesday 13 January 2004 21:33, Stefan Farfeleder wrote:
> On Tue, Jan 13, 2004 at 08:02:20AM -0800, Dag-Erling Smorgrav wrote:
> > des         2004/01/13 08:02:20 PST
> >
> >   FreeBSD src repository
> >
> >   Modified files:
> >     sys/libkern          ffs.c ffsl.c fls.c flsl.c
> >   Log:
> >   Cast to unsigned to avoid sign-extension problems.
> >
> >   Revision  Changes    Path
> >   1.9       +1 -1      src/sys/libkern/ffs.c
> >   1.2       +1 -1      src/sys/libkern/ffsl.c
> >   1.2       +1 -1      src/sys/libkern/fls.c
> >   1.2       +1 -1      src/sys/libkern/flsl.c
>
> @@ -47,6 +47,6 @@ ffs(int mask)
>  	if (mask == 0)
>  		return (0);
>  	for (bit = 1; !(mask & 1); bit++)
> -		mask >>= 1;
> +		(unsigned int)mask >>= 1;
>  	return (bit);
>  }
>
> This is an ugly GCC extension.  Might I suggest using the portable
>
> mask = (unsigned int)mask >> 1;
>
> instead?
>
can be use asm inline instred this circle ?

/**
 * find_next_bit - find the first set bit in a memory region
 * @addr: The address to base the search on
 * @offset: The bitnumber to start searching at
 * @size: The maximum size to search
 */
static __inline__ int find_next_bit (void * addr, int size, int offset)
{
        unsigned long * p = ((unsigned long *) addr) + (offset >> 5);
        int set = 0, bit = offset & 31, res;

        if (bit) {
                /*
                 * Look for nonzero in the first 32 bits:
                 */
                __asm__("bsfl %1,%0\n\t"
                        "jne 1f\n\t"
                        "movl $32, %0\n"
                        "1:"
                        : "=r" (set)
                        : "r" (*p >> bit));
                if (set < (32 - bit))
                        return set + offset;
                set = 32 - bit;
                p++;
        }
        /*
         * No set bit yet, search remaining full words for a bit
         */
        res = find_first_bit (p, size - 32 * (p - (unsigned long *) addr));
        return (offset + set + res);
}


-- 
With best regards,
Alex


More information about the cvs-src mailing list