Commit 37d54111 authored by Akinobu Mita's avatar Akinobu Mita Committed by Linus Torvalds

[PATCH] bitops: hweight() related cleanup

By defining generic hweight*() routines

- hweight64() will be defined on all architectures
- hweight_long() will use architecture optimized hweight32() or hweight64()

I found two possible cleanups by these reasons.
Signed-off-by: default avatarAkinobu Mita <mita@miraclelinux.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent e9bebd6f
...@@ -306,8 +306,7 @@ u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl, ...@@ -306,8 +306,7 @@ u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl,
u64 align_mask = ~(alignment - 1); u64 align_mask = ~(alignment - 1);
if ((alignment & 3) || (alignment > 0x800000000000ULL) || if ((alignment & 3) || (alignment > 0x800000000000ULL) ||
((hweight32(alignment >> 32) + (hweight64(alignment) != 1)) {
hweight32(alignment & 0xffffffff) != 1))) {
HPSB_ERR("%s called with invalid alignment: 0x%048llx", HPSB_ERR("%s called with invalid alignment: 0x%048llx",
__FUNCTION__, (unsigned long long)alignment); __FUNCTION__, (unsigned long long)alignment);
return retval; return retval;
......
...@@ -253,33 +253,18 @@ int __bitmap_subset(const unsigned long *bitmap1, ...@@ -253,33 +253,18 @@ int __bitmap_subset(const unsigned long *bitmap1,
} }
EXPORT_SYMBOL(__bitmap_subset); EXPORT_SYMBOL(__bitmap_subset);
#if BITS_PER_LONG == 32
int __bitmap_weight(const unsigned long *bitmap, int bits) int __bitmap_weight(const unsigned long *bitmap, int bits)
{ {
int k, w = 0, lim = bits/BITS_PER_LONG; int k, w = 0, lim = bits/BITS_PER_LONG;
for (k = 0; k < lim; k++) for (k = 0; k < lim; k++)
w += hweight32(bitmap[k]); w += hweight_long(bitmap[k]);
if (bits % BITS_PER_LONG) if (bits % BITS_PER_LONG)
w += hweight32(bitmap[k] & BITMAP_LAST_WORD_MASK(bits)); w += hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits));
return w; return w;
} }
#else
int __bitmap_weight(const unsigned long *bitmap, int bits)
{
int k, w = 0, lim = bits/BITS_PER_LONG;
for (k = 0; k < lim; k++)
w += hweight64(bitmap[k]);
if (bits % BITS_PER_LONG)
w += hweight64(bitmap[k] & BITMAP_LAST_WORD_MASK(bits));
return w;
}
#endif
EXPORT_SYMBOL(__bitmap_weight); EXPORT_SYMBOL(__bitmap_weight);
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment