From: "Jan Beulich" Subject: [PATCH] bitmap_*() should cope with zero size bitmaps Date: Mon, 03 Jun 2013 14:33:24 +0100 Message-ID: <51ACB74402000078000DA8F0@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part3A0ACA34.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Keir Fraser List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part3A0ACA34.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline ... to match expectations set by memset()/memcpy(). Similarly for find_{first,next}_{,zero_}_bit() on x86. __bitmap_shift_{left,right}() would also need fixing (they more generally can't cope with the shift count being larger than the bitmap size, and they perform undefined operations by possibly shifting an unsigned long value by BITS_PER_LONG bits), but since these functions aren't really used anywhere I wonder if we wouldn't better simply get rid of them. Signed-off-by: Jan Beulich --- a/xen/include/asm-x86/bitops.h +++ b/xen/include/asm-x86/bitops.h @@ -327,10 +327,7 @@ static inline unsigned int __scanbit(uns * Returns the bit-number of the first set bit, not the number of the = byte * containing a bit. */ -#define find_first_bit(addr,size) \ -((__builtin_constant_p(size) && (size) <=3D BITS_PER_LONG ? \ - (__scanbit(*(const unsigned long *)addr, size)) : \ - __find_first_bit(addr,size))) +#define find_first_bit(addr, size) find_next_bit(addr, size, 0) =20 /** * find_next_bit - find the first set bit in a memory region @@ -338,10 +335,24 @@ static inline unsigned int __scanbit(uns * @offset: The bitnumber to start searching at * @size: The maximum size to search */ -#define find_next_bit(addr,size,off) = \ -((__builtin_constant_p(size) && (size) <=3D BITS_PER_LONG ? = \ - ((off) + (__scanbit((*(const unsigned long *)addr) >> (off), size))) : = \ - __find_next_bit(addr,size,off))) +#define find_next_bit(addr, size, off) ({ \ + unsigned int r__ =3D (size); \ + unsigned int o__ =3D (off); \ + switch ( -!__builtin_constant_p(size) | r__ ) \ + { \ + case 0: (void)(addr); break; \ + case 1 ... BITS_PER_LONG: \ + r__ =3D o__ + __scanbit(*(const unsigned long *)(addr) >> o__, = r__); \ + break; \ + default: \ + if ( __builtin_constant_p(off) && !o__ ) \ + r__ =3D __find_first_bit(addr, r__); \ + else \ + r__ =3D __find_next_bit(addr, r__, o__); \ + break; \ + } \ + r__; \ +}) =20 /** * find_first_zero_bit - find the first zero bit in a memory region @@ -351,10 +362,7 @@ static inline unsigned int __scanbit(uns * Returns the bit-number of the first zero bit, not the number of the = byte * containing a bit. */ -#define find_first_zero_bit(addr,size) \ -((__builtin_constant_p(size) && (size) <=3D BITS_PER_LONG ? \ - (__scanbit(~*(const unsigned long *)addr, size)) : \ - __find_first_zero_bit(addr,size))) +#define find_first_zero_bit(addr, size) find_next_zero_bit(addr, size, 0) =20 /** * find_next_zero_bit - find the first zero bit in a memory region @@ -362,10 +370,24 @@ static inline unsigned int __scanbit(uns * @offset: The bitnumber to start searching at * @size: The maximum size to search */ -#define find_next_zero_bit(addr,size,off) = \ -((__builtin_constant_p(size) && (size) <=3D BITS_PER_LONG ? = \ - ((off)+(__scanbit(~(((*(const unsigned long *)addr)) >> (off)), size))) = : \ - __find_next_zero_bit(addr,size,off))) +#define find_next_zero_bit(addr, size, off) ({ \ + unsigned int r__ =3D (size); \ + unsigned int o__ =3D (off); \ + switch ( -!__builtin_constant_p(size) | r__ ) \ + { \ + case 0: (void)(addr); break; \ + case 1 ... BITS_PER_LONG: \ + r__ =3D o__ + __scanbit(~*(const unsigned long *)(addr) >> o__, = r__); \ + break; \ + default: \ + if ( __builtin_constant_p(off) && !o__ ) \ + r__ =3D __find_first_zero_bit(addr, r__); \ + else \ + r__ =3D __find_next_zero_bit(addr, r__, o__); \ + break; \ + } \ + r__; \ +}) =20 /** * find_first_set_bit - find the first set bit in @word --- a/xen/include/xen/bitmap.h +++ b/xen/include/xen/bitmap.h @@ -108,123 +108,122 @@ extern int bitmap_allocate_region(unsign (1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \ ) =20 +#define bitmap_bytes(nbits) (BITS_TO_LONGS(nbits) * sizeof(unsigned = long)) + +#define bitmap_switch(nbits, zero_ret, small, large) \ + switch (-!__builtin_constant_p(nbits) | (nbits)) { \ + case 0: return zero_ret; \ + case 1 ... BITS_PER_LONG: \ + small; break; \ + default: \ + large; break; \ + } + static inline void bitmap_zero(unsigned long *dst, int nbits) { - if (nbits <=3D BITS_PER_LONG) - *dst =3D 0UL; - else { - int len =3D BITS_TO_LONGS(nbits) * sizeof(unsigned long); - memset(dst, 0, len); - } + bitmap_switch(nbits,, + *dst =3D 0UL, + memset(dst, 0, bitmap_bytes(nbits))); } =20 static inline void bitmap_fill(unsigned long *dst, int nbits) { size_t nlongs =3D BITS_TO_LONGS(nbits); - if (nlongs > 1) { - int len =3D (nlongs - 1) * sizeof(unsigned long); - memset(dst, 0xff, len); + + switch (nlongs) { + default: + memset(dst, -1, (nlongs - 1) * sizeof(unsigned long)); + /* fall through */ + case 1: + dst[nlongs - 1] =3D BITMAP_LAST_WORD_MASK(nbits); + break; } - dst[nlongs - 1] =3D BITMAP_LAST_WORD_MASK(nbits); } =20 static inline void bitmap_copy(unsigned long *dst, const unsigned long = *src, int nbits) { - if (nbits <=3D BITS_PER_LONG) - *dst =3D *src; - else { - int len =3D BITS_TO_LONGS(nbits) * sizeof(unsigned long); - memcpy(dst, src, len); - } + bitmap_switch(nbits,, + *dst =3D *src, + memcpy(dst, src, bitmap_bytes(nbits))); } =20 static inline void bitmap_and(unsigned long *dst, const unsigned long = *src1, const unsigned long *src2, int nbits) { - if (nbits <=3D BITS_PER_LONG) - *dst =3D *src1 & *src2; - else - __bitmap_and(dst, src1, src2, nbits); + bitmap_switch(nbits,, + *dst =3D *src1 & *src2, + __bitmap_and(dst, src1, src2, nbits)); } =20 static inline void bitmap_or(unsigned long *dst, const unsigned long = *src1, const unsigned long *src2, int nbits) { - if (nbits <=3D BITS_PER_LONG) - *dst =3D *src1 | *src2; - else - __bitmap_or(dst, src1, src2, nbits); + bitmap_switch(nbits,, + *dst =3D *src1 | *src2, + __bitmap_or(dst, src1, src2, nbits)); } =20 static inline void bitmap_xor(unsigned long *dst, const unsigned long = *src1, const unsigned long *src2, int nbits) { - if (nbits <=3D BITS_PER_LONG) - *dst =3D *src1 ^ *src2; - else - __bitmap_xor(dst, src1, src2, nbits); + bitmap_switch(nbits,, + *dst =3D *src1 ^ *src2, + __bitmap_xor(dst, src1, src2, nbits)); } =20 static inline void bitmap_andnot(unsigned long *dst, const unsigned long = *src1, const unsigned long *src2, int nbits) { - if (nbits <=3D BITS_PER_LONG) - *dst =3D *src1 & ~(*src2); - else - __bitmap_andnot(dst, src1, src2, nbits); + bitmap_switch(nbits,, + *dst =3D *src1 & ~*src2, + __bitmap_andnot(dst, src1, src2, nbits)); } =20 static inline void bitmap_complement(unsigned long *dst, const unsigned = long *src, int nbits) { - if (nbits <=3D BITS_PER_LONG) - *dst =3D ~(*src) & BITMAP_LAST_WORD_MASK(nbits); - else - __bitmap_complement(dst, src, nbits); + bitmap_switch(nbits,, + *dst =3D ~*src & BITMAP_LAST_WORD_MASK(nbits), + __bitmap_complement(dst, src, nbits)); } =20 static inline int bitmap_equal(const unsigned long *src1, const unsigned long *src2, int nbits) { - if (nbits <=3D BITS_PER_LONG) - return ! ((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits)); - else - return __bitmap_equal(src1, src2, nbits); + bitmap_switch(nbits, -1, + return !((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits)), + return __bitmap_equal(src1, src2, nbits)); } =20 static inline int bitmap_intersects(const unsigned long *src1, const unsigned long *src2, int nbits) { - if (nbits <=3D BITS_PER_LONG) - return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) = !=3D 0; - else - return __bitmap_intersects(src1, src2, nbits); + bitmap_switch(nbits, -1, + return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) = !=3D 0, + return __bitmap_intersects(src1, src2, nbits)); } =20 static inline int bitmap_subset(const unsigned long *src1, const unsigned long *src2, int nbits) { - if (nbits <=3D BITS_PER_LONG) - return ! ((*src1 & ~(*src2)) & BITMAP_LAST_WORD_MASK(nbits)= ); - else - return __bitmap_subset(src1, src2, nbits); + bitmap_switch(nbits, -1, + return !((*src1 & ~*src2) & BITMAP_LAST_WORD_MASK(nbits)), + return __bitmap_subset(src1, src2, nbits)); } =20 static inline int bitmap_empty(const unsigned long *src, int nbits) { - if (nbits <=3D BITS_PER_LONG) - return ! (*src & BITMAP_LAST_WORD_MASK(nbits)); - else - return __bitmap_empty(src, nbits); + bitmap_switch(nbits, -1, + return !(*src & BITMAP_LAST_WORD_MASK(nbits)), + return __bitmap_empty(src, nbits)); } =20 static inline int bitmap_full(const unsigned long *src, int nbits) { - if (nbits <=3D BITS_PER_LONG) - return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits)); - else - return __bitmap_full(src, nbits); + bitmap_switch(nbits, -1, + return !(~*src & BITMAP_LAST_WORD_MASK(nbits)), + return __bitmap_full(src, nbits)); } =20 static inline int bitmap_weight(const unsigned long *src, int nbits) @@ -235,21 +234,22 @@ static inline int bitmap_weight(const un static inline void bitmap_shift_right(unsigned long *dst, const unsigned long *src, int n, int nbits) { - if (nbits <=3D BITS_PER_LONG) - *dst =3D *src >> n; - else - __bitmap_shift_right(dst, src, n, nbits); + bitmap_switch(nbits,, + *dst =3D *src >> n, + __bitmap_shift_right(dst, src, n, nbits)); } =20 static inline void bitmap_shift_left(unsigned long *dst, const unsigned long *src, int n, int nbits) { - if (nbits <=3D BITS_PER_LONG) - *dst =3D (*src << n) & BITMAP_LAST_WORD_MASK(nbits); - else - __bitmap_shift_left(dst, src, n, nbits); + bitmap_switch(nbits,, + *dst =3D (*src << n) & BITMAP_LAST_WORD_MASK(nbits), + __bitmap_shift_left(dst, src, n, nbits)); } =20 +#undef bitmap_switch +#undef bitmap_bytes + void bitmap_long_to_byte(uint8_t *bp, const unsigned long *lp, int = nbits); void bitmap_byte_to_long(unsigned long *lp, const uint8_t *bp, int = nbits); =20 --=__Part3A0ACA34.0__= Content-Type: text/plain; name="bitmap-ops.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="bitmap-ops.patch" bitmap_*() should cope with zero size bitmaps=0A=0A... to match expectation= s set by memset()/memcpy().=0A=0ASimilarly for find_{first,next}_{,zero_}_b= it() on x86.=0A=0A__bitmap_shift_{left,right}() would also need fixing = (they more=0Agenerally can't cope with the shift count being larger than = the bitmap=0Asize, and they perform undefined operations by possibly = shifting an=0Aunsigned long value by BITS_PER_LONG bits), but since these = functions=0Aaren't really used anywhere I wonder if we wouldn't better = simply get=0Arid of them.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- a/xen/include/asm-x86/bitops.h=0A+++ b/xen/include/asm-x86/bito= ps.h=0A@@ -327,10 +327,7 @@ static inline unsigned int __scanbit(uns=0A * = Returns the bit-number of the first set bit, not the number of the byte=0A = * containing a bit.=0A */=0A-#define find_first_bit(addr,size) = \=0A-((__builtin_constant_p(size) && (size) <=3D = BITS_PER_LONG ? \=0A- (__scanbit(*(const unsigned long *)addr, = size)) : \=0A- __find_first_bit(addr,size)))=0A+#define = find_first_bit(addr, size) find_next_bit(addr, size, 0)=0A =0A /**=0A * = find_next_bit - find the first set bit in a memory region=0A@@ -338,10 = +335,24 @@ static inline unsigned int __scanbit(uns=0A * @offset: The = bitnumber to start searching at=0A * @size: The maximum size to search=0A = */=0A-#define find_next_bit(addr,size,off) = \=0A-((__builtin_constant_p(size) && (size) <=3D BITS_PER_LONG ? = \=0A- ((off) + (__scanbit((*(const unsigned long *)addr) >> = (off), size))) : \=0A- __find_next_bit(addr,size,off)))=0A+#define = find_next_bit(addr, size, off) ({ \=0A+ unsigned int r__ =3D (size); = \=0A+ unsigned int o__ =3D (off); \=0A+ switch ( -!__builtin_constant= _p(size) | r__ ) \=0A+ { \=0A+ case 0: (void)(addr); break; \=0A+ = case 1 ... BITS_PER_LONG: \=0A+ r__ =3D o__ + __scanbit(*(const = unsigned long *)(addr) >> o__, r__); \=0A+ break; \=0A+ default: = \=0A+ if ( __builtin_constant_p(off) && !o__ ) \=0A+ r__ = =3D __find_first_bit(addr, r__); \=0A+ else \=0A+ r__ = =3D __find_next_bit(addr, r__, o__); \=0A+ break; \=0A+ } \=0A+ = r__; \=0A+})=0A =0A /**=0A * find_first_zero_bit - find the first zero = bit in a memory region=0A@@ -351,10 +362,7 @@ static inline unsigned int = __scanbit(uns=0A * Returns the bit-number of the first zero bit, not the = number of the byte=0A * containing a bit.=0A */=0A-#define find_first_zer= o_bit(addr,size) \=0A-((__builtin_constant_p(size)= && (size) <=3D BITS_PER_LONG ? \=0A- (__scanbit(~*(const unsigned = long *)addr, size)) : \=0A- __find_first_zero_bit(addr,size)))= =0A+#define find_first_zero_bit(addr, size) find_next_zero_bit(addr, size, = 0)=0A =0A /**=0A * find_next_zero_bit - find the first zero bit in a = memory region=0A@@ -362,10 +370,24 @@ static inline unsigned int __scanbit(= uns=0A * @offset: The bitnumber to start searching at=0A * @size: The = maximum size to search=0A */=0A-#define find_next_zero_bit(addr,size,off) = \=0A-((__builtin_constant_p(size) && = (size) <=3D BITS_PER_LONG ? \=0A- ((off)+(__scanbit(~(((= *(const unsigned long *)addr)) >> (off)), size))) : \=0A- __find_next_zero= _bit(addr,size,off)))=0A+#define find_next_zero_bit(addr, size, off) ({ = \=0A+ unsigned int r__ =3D (size); \=0A+ unsigned int o__ =3D (off); = \=0A+ switch ( -!__builtin_constant_p(size) | r__ ) \=0A+ { \=0A+ = case 0: (void)(addr); break; \=0A+ case 1 ... BITS_PER_LONG: \=0A+ = r__ =3D o__ + __scanbit(~*(const unsigned long *)(addr) >> o__, r__); = \=0A+ break; \=0A+ default: \=0A+ if ( __builtin_constant_= p(off) && !o__ ) \=0A+ r__ =3D __find_first_zero_bit(addr, = r__); \=0A+ else \=0A+ r__ =3D __find_next_zero_bit(addr,= r__, o__); \=0A+ break; \=0A+ } \=0A+ r__; \=0A+})=0A =0A = /**=0A * find_first_set_bit - find the first set bit in @word=0A--- = a/xen/include/xen/bitmap.h=0A+++ b/xen/include/xen/bitmap.h=0A@@ -108,123 = +108,122 @@ extern int bitmap_allocate_region(unsign=0A = (1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \=0A )=0A = =0A+#define bitmap_bytes(nbits) (BITS_TO_LONGS(nbits) * sizeof(unsigned = long))=0A+=0A+#define bitmap_switch(nbits, zero_ret, small, large) = \=0A+ switch (-!__builtin_constant_p(nbits) | (nbits)) { = \=0A+ case 0: return zero_ret; = \=0A+ case 1 ... BITS_PER_LONG: = \=0A+ small; break; = \=0A+ default: = \=0A+ large; break; = \=0A+ }=0A+=0A static inline void bitmap_zero(unsigned long *dst, int = nbits)=0A {=0A- if (nbits <=3D BITS_PER_LONG)=0A- *dst =3D = 0UL;=0A- else {=0A- int len =3D BITS_TO_LONGS(nbits) * = sizeof(unsigned long);=0A- memset(dst, 0, len);=0A- = }=0A+ bitmap_switch(nbits,,=0A+ *dst =3D 0UL,=0A+ = memset(dst, 0, bitmap_bytes(nbits)));=0A }=0A =0A static inline void = bitmap_fill(unsigned long *dst, int nbits)=0A {=0A size_t nlongs =3D = BITS_TO_LONGS(nbits);=0A- if (nlongs > 1) {=0A- int len = =3D (nlongs - 1) * sizeof(unsigned long);=0A- memset(dst, 0xff, = len);=0A+=0A+ switch (nlongs) {=0A+ default:=0A+ memset(dst,= -1, (nlongs - 1) * sizeof(unsigned long));=0A+ /* fall through = */=0A+ case 1:=0A+ dst[nlongs - 1] =3D BITMAP_LAST_WORD_MASK(n= bits);=0A+ break;=0A }=0A- dst[nlongs - 1] =3D = BITMAP_LAST_WORD_MASK(nbits);=0A }=0A =0A static inline void bitmap_copy(un= signed long *dst, const unsigned long *src,=0A int = nbits)=0A {=0A- if (nbits <=3D BITS_PER_LONG)=0A- *dst =3D = *src;=0A- else {=0A- int len =3D BITS_TO_LONGS(nbits) * = sizeof(unsigned long);=0A- memcpy(dst, src, len);=0A- = }=0A+ bitmap_switch(nbits,,=0A+ *dst =3D *src,=0A+ = memcpy(dst, src, bitmap_bytes(nbits)));=0A }=0A =0A static inline void = bitmap_and(unsigned long *dst, const unsigned long *src1,=0A = const unsigned long *src2, int nbits)=0A {=0A- if (nbits <=3D BITS_PER_LON= G)=0A- *dst =3D *src1 & *src2;=0A- else=0A- = __bitmap_and(dst, src1, src2, nbits);=0A+ bitmap_switch(nbits,,=0A+ = *dst =3D *src1 & *src2,=0A+ __bitmap_and(dst, src1, = src2, nbits));=0A }=0A =0A static inline void bitmap_or(unsigned long = *dst, const unsigned long *src1,=0A const unsigned = long *src2, int nbits)=0A {=0A- if (nbits <=3D BITS_PER_LONG)=0A- = *dst =3D *src1 | *src2;=0A- else=0A- __bitmap_or(dst, = src1, src2, nbits);=0A+ bitmap_switch(nbits,,=0A+ *dst =3D = *src1 | *src2,=0A+ __bitmap_or(dst, src1, src2, nbits));=0A = }=0A =0A static inline void bitmap_xor(unsigned long *dst, const unsigned = long *src1,=0A const unsigned long *src2, int nbits)=0A = {=0A- if (nbits <=3D BITS_PER_LONG)=0A- *dst =3D *src1 ^ = *src2;=0A- else=0A- __bitmap_xor(dst, src1, src2, = nbits);=0A+ bitmap_switch(nbits,,=0A+ *dst =3D *src1 ^ = *src2,=0A+ __bitmap_xor(dst, src1, src2, nbits));=0A }=0A =0A = static inline void bitmap_andnot(unsigned long *dst, const unsigned long = *src1,=0A const unsigned long *src2, int nbits)=0A = {=0A- if (nbits <=3D BITS_PER_LONG)=0A- *dst =3D *src1 & = ~(*src2);=0A- else=0A- __bitmap_andnot(dst, src1, src2, = nbits);=0A+ bitmap_switch(nbits,,=0A+ *dst =3D *src1 & = ~*src2,=0A+ __bitmap_andnot(dst, src1, src2, nbits));=0A }=0A = =0A static inline void bitmap_complement(unsigned long *dst, const = unsigned long *src,=0A int nbits)=0A {=0A- if (nbits = <=3D BITS_PER_LONG)=0A- *dst =3D ~(*src) & BITMAP_LAST_WORD_MASK(nb= its);=0A- else=0A- __bitmap_complement(dst, src, = nbits);=0A+ bitmap_switch(nbits,,=0A+ *dst =3D ~*src & = BITMAP_LAST_WORD_MASK(nbits),=0A+ __bitmap_complement(dst, = src, nbits));=0A }=0A =0A static inline int bitmap_equal(const unsigned = long *src1,=0A const unsigned long *src2, int nbits)=0A = {=0A- if (nbits <=3D BITS_PER_LONG)=0A- return ! ((*src1 ^ = *src2) & BITMAP_LAST_WORD_MASK(nbits));=0A- else=0A- = return __bitmap_equal(src1, src2, nbits);=0A+ bitmap_switch(nbits, = -1,=0A+ return !((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits)),= =0A+ return __bitmap_equal(src1, src2, nbits));=0A }=0A =0A = static inline int bitmap_intersects(const unsigned long *src1,=0A = const unsigned long *src2, int nbits)=0A {=0A- if (nbits <=3D = BITS_PER_LONG)=0A- return ((*src1 & *src2) & BITMAP_LAST_WORD_= MASK(nbits)) !=3D 0;=0A- else=0A- return __bitmap_int= ersects(src1, src2, nbits);=0A+ bitmap_switch(nbits, -1,=0A+ = return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) !=3D 0,=0A+ = return __bitmap_intersects(src1, src2, nbits));=0A }=0A =0A static inline = int bitmap_subset(const unsigned long *src1,=0A = const unsigned long *src2, int nbits)=0A {=0A- if (nbits <=3D BITS_PER_LON= G)=0A- return ! ((*src1 & ~(*src2)) & BITMAP_LAST_WORD_MASK(nbits)= );=0A- else=0A- return __bitmap_subset(src1, src2, = nbits);=0A+ bitmap_switch(nbits, -1,=0A+ return !((*src1 & = ~*src2) & BITMAP_LAST_WORD_MASK(nbits)),=0A+ return __bitmap_sub= set(src1, src2, nbits));=0A }=0A =0A static inline int bitmap_empty(const = unsigned long *src, int nbits)=0A {=0A- if (nbits <=3D BITS_PER_LONG)=0A- = return ! (*src & BITMAP_LAST_WORD_MASK(nbits));=0A- else=0A- = return __bitmap_empty(src, nbits);=0A+ bitmap_switch(nbits, = -1,=0A+ return !(*src & BITMAP_LAST_WORD_MASK(nbits)),=0A+ = return __bitmap_empty(src, nbits));=0A }=0A =0A static inline int = bitmap_full(const unsigned long *src, int nbits)=0A {=0A- if (nbits = <=3D BITS_PER_LONG)=0A- return ! (~(*src) & BITMAP_LAST_WORD_MASK(n= bits));=0A- else=0A- return __bitmap_full(src, = nbits);=0A+ bitmap_switch(nbits, -1,=0A+ return !(~*src & = BITMAP_LAST_WORD_MASK(nbits)),=0A+ return __bitmap_full(src, = nbits));=0A }=0A =0A static inline int bitmap_weight(const unsigned long = *src, int nbits)=0A@@ -235,21 +234,22 @@ static inline int bitmap_weight(co= nst un=0A static inline void bitmap_shift_right(unsigned long *dst,=0A = const unsigned long *src, int n, int nbits)=0A {=0A- if (nbits = <=3D BITS_PER_LONG)=0A- *dst =3D *src >> n;=0A- else=0A- = __bitmap_shift_right(dst, src, n, nbits);=0A+ bitmap_switch(nbits,,=0A+ = *dst =3D *src >> n,=0A+ __bitmap_shift_right(dst, src, n, = nbits));=0A }=0A =0A static inline void bitmap_shift_left(unsigned long = *dst,=0A const unsigned long *src, int n, int = nbits)=0A {=0A- if (nbits <=3D BITS_PER_LONG)=0A- *dst =3D = (*src << n) & BITMAP_LAST_WORD_MASK(nbits);=0A- else=0A- = __bitmap_shift_left(dst, src, n, nbits);=0A+ bitmap_switch(nbits,,=0A+ = *dst =3D (*src << n) & BITMAP_LAST_WORD_MASK(nbits),=0A+ = __bitmap_shift_left(dst, src, n, nbits));=0A }=0A =0A+#undef bitmap_switch= =0A+#undef bitmap_bytes=0A+=0A void bitmap_long_to_byte(uint8_t *bp, const = unsigned long *lp, int nbits);=0A void bitmap_byte_to_long(unsigned long = *lp, const uint8_t *bp, int nbits);=0A =0A --=__Part3A0ACA34.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part3A0ACA34.0__=--