* [patch 13/28] fib_trie: macro cleanup
@ 2007-08-10 21:11 akpm
2007-08-10 22:23 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: akpm @ 2007-08-10 21:11 UTC (permalink / raw)
To: davem; +Cc: netdev, akpm, shemminger
From: Stephen Hemminger <shemminger@linux-foundation.org>
This patch converts the messy macro for MASK_PFX to inline function
and expands TKEY_GET_MASK in the one place it is used.
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
net/ipv4/fib_trie.c | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 deletions(-)
diff -puN net/ipv4/fib_trie.c~fib_trie-macro-cleanup net/ipv4/fib_trie.c
--- a/net/ipv4/fib_trie.c~fib_trie-macro-cleanup
+++ a/net/ipv4/fib_trie.c
@@ -85,8 +85,6 @@
#define MAX_STAT_DEPTH 32
#define KEYLENGTH (8*sizeof(t_key))
-#define MASK_PFX(k, l) (((l)==0)?0:(k >> (KEYLENGTH-l)) << (KEYLENGTH-l))
-#define TKEY_GET_MASK(offset, bits) (((bits)==0)?0:((t_key)(-1) << (KEYLENGTH - bits) >> offset))
typedef unsigned int t_key;
@@ -195,6 +193,11 @@ static inline int tnode_child_length(con
return 1 << tn->bits;
}
+static inline t_key mask_pfx(t_key k, unsigned short l)
+{
+ return (l == 0) ? 0 : k >> (KEYLENGTH-l) << (KEYLENGTH-l);
+}
+
static inline t_key tkey_extract_bits(t_key a, int offset, int bits)
{
if (offset < KEYLENGTH)
@@ -679,7 +682,7 @@ static struct tnode *inflate(struct trie
inode->pos == oldtnode->pos + oldtnode->bits &&
inode->bits > 1) {
struct tnode *left, *right;
- t_key m = TKEY_GET_MASK(inode->pos, 1);
+ t_key m = ~0U << (KEYLENGTH - 1) >> inode->pos;
left = tnode_new(inode->key&(~m), inode->pos + 1,
inode->bits - 1);
@@ -1367,7 +1370,8 @@ fn_trie_lookup(struct fib_table *tb, con
bits = pn->bits;
if (!chopped_off)
- cindex = tkey_extract_bits(MASK_PFX(key, current_prefix_length), pos, bits);
+ cindex = tkey_extract_bits(mask_pfx(key, current_prefix_length),
+ pos, bits);
n = tnode_get_child(pn, cindex);
@@ -1453,8 +1457,8 @@ fn_trie_lookup(struct fib_table *tb, con
* to find a matching prefix.
*/
- node_prefix = MASK_PFX(cn->key, cn->pos);
- key_prefix = MASK_PFX(key, cn->pos);
+ node_prefix = mask_pfx(cn->key, cn->pos);
+ key_prefix = mask_pfx(key, cn->pos);
pref_mismatch = key_prefix^node_prefix;
mp = 0;
@@ -2330,7 +2334,7 @@ static int fib_trie_seq_show(struct seq_
if (IS_TNODE(n)) {
struct tnode *tn = (struct tnode *) n;
- __be32 prf = htonl(MASK_PFX(tn->key, tn->pos));
+ __be32 prf = htonl(mask_pfx(tn->key, tn->pos));
seq_indent(seq, iter->depth-1);
seq_printf(seq, " +-- %d.%d.%d.%d/%d %d %d %d\n",
_
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [patch 13/28] fib_trie: macro cleanup
2007-08-10 21:11 [patch 13/28] fib_trie: macro cleanup akpm
@ 2007-08-10 22:23 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2007-08-10 22:23 UTC (permalink / raw)
To: akpm; +Cc: netdev, shemminger
From: akpm@linux-foundation.org
Date: Fri, 10 Aug 2007 14:11:57 -0700
> From: Stephen Hemminger <shemminger@linux-foundation.org>
>
> This patch converts the messy macro for MASK_PFX to inline function
> and expands TKEY_GET_MASK in the one place it is used.
>
> Cc: "David S. Miller" <davem@davemloft.net>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Applied to net-2.6.24, thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-08-10 22:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-10 21:11 [patch 13/28] fib_trie: macro cleanup akpm
2007-08-10 22:23 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).