From: Martin Mares Date: Wed, 3 Dec 1997 08:11:25 +0000 (+0000) Subject: ffs _cannot_ be used as a substitute for log2, because it scans in the X-Git-Tag: holmes-import~1685 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=a048770f41b23fdba09e2a70a9711f48152e6778;p=libucw.git ffs _cannot_ be used as a substitute for log2, because it scans in the opposite direction :-( Fixed our own log2 (it hadn't any chance to work before). --- diff --git a/lib/config.h b/lib/config.h index 62ef1af3..e9b84fc3 100644 --- a/lib/config.h +++ b/lib/config.h @@ -39,7 +39,3 @@ typedef unsigned int uns; /* at least 32 bits */ #define NONRET #endif - -#ifdef linux -#define HAVE_FFS -#endif diff --git a/lib/lib.h b/lib/lib.h index 24d7e352..59cb6621 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -74,11 +74,7 @@ int match_ct_filter(struct ct_filter *, byte *); /* Binary log */ -#ifdef HAVE_FFS -#define log2(x) (ffs(x) - 1) -#else int log2(ulg); -#endif /* obj.c */ diff --git a/lib/log2.c b/lib/log2.c index dc0a9297..3cd98335 100644 --- a/lib/log2.c +++ b/lib/log2.c @@ -8,8 +8,10 @@ #include "lib.h" +#undef log2 + int -ffs(ulg x) +log2(ulg x) { ulg l; @@ -17,10 +19,10 @@ ffs(ulg 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; }