Whamcloud - gitweb
branch: b_new_cmd
authorericm <ericm>
Fri, 13 Oct 2006 03:10:24 +0000 (03:10 +0000)
committerericm <ericm>
Fri, 13 Oct 2006 03:10:24 +0000 (03:10 +0000)
from tappro: a better version of size_roundup_power2().

lustre/include/liblustre.h
lustre/include/lustre_sec.h

index 290accd..17dbceb 100644 (file)
@@ -760,36 +760,6 @@ int test_and_clear_bit(int nr, unsigned long *addr)
         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
index ced9bea..c99af98 100644 (file)
@@ -416,14 +416,14 @@ extern struct proc_dir_entry *sptlrpc_proc_root;
  */
 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;
 }
 
 /*