summaryrefslogtreecommitdiffstats
path: root/lib/bitops.c
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2009-03-31 12:55:57 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2009-03-31 12:55:57 +0200
commitb1a597e0c3821c791a41278454e74261cf1b95fb (patch)
treefec1fdf523429e3afdcdaec6b0a96ef297723729 /lib/bitops.c
parent1733d080c9f60de69e843f22e138f27240a8176c (diff)
downloadbird-b1a597e0c3821c791a41278454e74261cf1b95fb.tar
bird-b1a597e0c3821c791a41278454e74261cf1b95fb.zip
Reimplementation of prefix sets.
Prefix sets were broken beyond any repair and have to be reimplemented. They are reimplemented using a trie with bitmasks in nodes. There is also change in the interpretation of minus prefix pattern, but the old interpretation was already inconsistent with the documentation and broken. There is also some bugfixes in filter code related to set variables.
Diffstat (limited to 'lib/bitops.c')
-rw-r--r--lib/bitops.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/bitops.c b/lib/bitops.c
index 6ca0505..88cef78 100644
--- a/lib/bitops.c
+++ b/lib/bitops.c
@@ -45,3 +45,24 @@ u32_masklen(u32 x)
if (x & 0xaaaaaaaa) l++;
return l;
}
+
+/**
+ * u32_log2 - compute a binary logarithm.
+ * @v: number
+ *
+ * This function computes a integral part of binary logarithm of given
+ * integer @v and returns it. The computed value is also an index of the
+ * first non-zero bit position.
+ */
+
+u32
+u32_log2(u32 v)
+{
+ u32 r, shift;
+ r = (v > 0xFFFF) << 4; v >>= r;
+ shift = (v > 0xFF ) << 3; v >>= shift; r |= shift;
+ shift = (v > 0xF ) << 2; v >>= shift; r |= shift;
+ shift = (v > 0x3 ) << 1; v >>= shift; r |= shift;
+ r |= (v >> 1);
+ return r;
+}