/*
- * Sherlock Library -- Binary Logarithm
+ * UCW 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;
}