Date: Thu, 15 Jul 2010 01:17:41 +0000 (UTC) From: Jeff Roberson <jeff@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r210094 - projects/ofed/head/sys/ofed/include/linux Message-ID: <201007150117.o6F1HfIu036330@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jeff Date: Thu Jul 15 01:17:40 2010 New Revision: 210094 URL: http://svn.freebsd.org/changeset/base/210094 Log: - Add more bitops for zero, fill, full, etc. Sponsored by: Isilon Systems, iX Systems, and Panasas. Modified: projects/ofed/head/sys/ofed/include/linux/bitops.h Modified: projects/ofed/head/sys/ofed/include/linux/bitops.h ============================================================================== --- projects/ofed/head/sys/ofed/include/linux/bitops.h Thu Jul 15 01:17:07 2010 (r210093) +++ projects/ofed/head/sys/ofed/include/linux/bitops.h Thu Jul 15 01:17:40 2010 (r210094) @@ -153,6 +153,82 @@ find_next_bit(unsigned long *addr, unsig return (bit); } +static inline unsigned long +find_next_zero_bit(unsigned long *addr, unsigned long size, + unsigned long offset) +{ + int mask; + int offs; + int bit; + int pos; + + pos = offset / BITS_PER_LONG; + offs = size % BITS_PER_LONG; + bit = BITS_PER_LONG * pos; + addr += pos; + if (offs) { + mask = ~(*addr) & ~BIT_MASK(offs); + if (mask) + return (bit + __ffsl(mask)); + bit += BITS_PER_LONG; + addr++; + } + for (size -= bit; size >= BITS_PER_LONG; + size -= BITS_PER_LONG, bit += BITS_PER_LONG, addr++) { + if (~(*addr) == 0) + continue; + return (bit + __ffsl(~(*addr))); + } + if (size) { + mask = ~(*addr) & BIT_MASK(size); + if (mask) + bit += __ffsl(mask); + else + bit += size; + } + return (bit); +} + +static inline void +bitmap_zero(unsigned long *addr, int size) +{ + int len; + + len = BITS_TO_LONGS(size) * sizeof(*addr); + memset(addr, 0, len); +} + +static inline void +bitmap_fill(unsigned long *addr, int size) +{ + int tail; + int len; + + len = BITS_TO_LONGS(size) * sizeof(*addr); + memset(addr, 0xff, len); + tail = size & (BITS_PER_LONG - 1); + if (tail) + addr[len - 1] = ((unsigned long)-1) >> (BITS_PER_LONG - tail); +} + +static inline int +bitmap_full(unsigned long *addr, int size) +{ + int tail; + int len; + int i; + + len = size / BITS_PER_LONG; + for (i = 0; i < len; i++) + if (addr[i] != (unsigned long)-1) + return (0); + tail = size & (BITS_PER_LONG - 1); + if (tail) + if (addr[i] != ((unsigned long)-1) >> (BITS_PER_LONG - tail)) + return (0); + return (1); +} + #define NBINT (NBBY * sizeof(int)) #define set_bit(i, a) \
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201007150117.o6F1HfIu036330>