[ovs-dev] [PATCH 3/3] lib/bitmap: Faster bitmap_scan().

Ben Pfaff blp at nicira.com
Fri Sep 26 21:10:06 UTC 2014


On Wed, Sep 24, 2014 at 11:36:57AM -0700, Jarno Rajahalme wrote:
> Correcting myself:
> 
> On Sep 24, 2014, at 11:24 AM, Jarno Rajahalme <jrajahalme at nicira.com> wrote:
> > -unsigned long *bitmap_allocate1(size_t n_bits);
> > +/* Initializes bitmap to all-1-bits and returns the bitmap pointer. */
> > +static inline void
> > +bitmap_init1(unsigned long *bitmap, size_t n_bits)
> > +{
> > +    size_t n_longs = bitmap_n_longs(n_bits);
> > +    size_t n_bytes = bitmap_n_bytes(n_bits);
> > +    size_t r_bits = n_bits % BITMAP_ULONG_BITS;
> > +
> > +    memset(bitmap, 0xff, n_bytes);
> > +    if (r_bits) {
> > +        bitmap[n_longs - 1] >>= 64 - r_bits;
> 
> Should have used BITMAP_ULONG_BITS here, this would not work on a
> 32-bit build where unsigned long is 32 bits.

Or you could use the technique previously in bitmap_allocate1() that
didn't need to know the number of bits in the word.



More information about the dev mailing list