]> mj.ucw.cz Git - libucw.git/blobdiff - lib/log2.c
indexer rewritten to generate redirect brackets
[libucw.git] / lib / log2.c
index dc0a92975fa750f4edad78ae08db5d5403b4f137..08b27bcf8dc95aedfe70f17a1bdc45c3c8b045dc 100644 (file)
@@ -1,26 +1,27 @@
 /*
  *     Sherlock Library -- Binary Logarithm
  *
- *     (c) 1997 Martin Mares, <mj@atrey.karlin.mff.cuni.cz>
+ *     (c) 1997 Martin Mares <mj@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
  */
 
-#include <stdio.h>
-
-#include "lib.h"
+#include "lib/lib.h"
 
 int
-ffs(ulg x)
+fls(u32 x)
 {
-  ulg l;
+  uns l;
 
   if (!x)
        return 0;
 
   l = 0;
-  if (x & 0xffff0000) l += 16;
-  if (x & 0xff00ff00) l += 8;
-  if (x & 0xf0f0f0f0) l += 4;
-  if (x & 0xcccccccc) l += 2;
+  if (x & 0xffff0000) { l += 16; x &= 0xffff0000; }
+  if (x & 0xff00ff00) { l += 8;  x &= 0xff00ff00; }
+  if (x & 0xf0f0f0f0) { l += 4;  x &= 0xf0f0f0f0; }
+  if (x & 0xcccccccc) { l += 2;  x &= 0xcccccccc; }
   if (x & 0xaaaaaaaa) l++;
   return l;
 }