from tappro: a better version of size_roundup_power2().
return oldbit;
}
-static inline
-int fls(int x)
-{
- int r = 32;
-
- if (!x)
- return 0;
- if (!(x & 0xffff0000u)) {
- x <<= 16;
- r -= 16;
- }
- if (!(x & 0xff000000u)) {
- x <<= 8;
- r -= 8;
- }
- if (!(x & 0xf0000000u)) {
- x <<= 4;
- r -= 4;
- }
- if (!(x & 0xc0000000u)) {
- x <<= 2;
- r -= 2;
- }
- if (!(x & 0x80000000u)) {
- x <<= 1;
- r -= 1;
- }
- return r;
-}
-
/* FIXME sys/capability will finally included linux/fs.h thus
* cause numerous trouble on x86-64. as temporary solution for
* build broken at Cray, we copy definition we need from capability.h
*/
static inline int size_roundup_power2(int size)
{
- int rc;
-
- LASSERT(size > 0);
- rc = 1 << (fls(size) - 1);
- if ((rc - 1) & size)
- rc <<= 1;
- LASSERT(rc > 0);
- return rc;
+ size--;
+ size |= size >> 1;
+ size |= size >> 2;
+ size |= size >> 4;
+ size |= size >> 8;
+ size |= size >> 16;
+ size++;
+ return size;
}
/*