Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 Jan 2004 06:51:43 +0200
From:      Alex Lyashkov <shadow@psoft.net>
To:        Stefan Farfeleder <stefan@fafoe.narf.at>
Cc:        cvs-src@FreeBSD.org
Subject:   Re: cvs commit: src/sys/libkern ffs.c ffsl.c fls.c flsl.c
Message-ID:  <200401140651.45971.shadow@psoft.net>
In-Reply-To: <20040113193300.GB626@wombat.fafoe.narf.at>
References:  <200401131602.i0DG2Khx064321@repoman.freebsd.org> <20040113193300.GB626@wombat.fafoe.narf.at>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200401140651.45971.shadow>