From a048770f41b23fdba09e2a70a9711f48152e6778 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Wed, 3 Dec 1997 08:11:25 +0000 Subject: [PATCH] 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). --- lib/config.h | 4 ---- lib/lib.h | 4 ---- lib/log2.c | 12 +++++++----- 3 files changed, 7 insertions(+), 13 deletions(-) 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; } -- 2.39.2