netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <shemminger@linux-foundation.org>
To: "David S. Miller" <davem@davemloft.net>
Cc: Adrian Bunk <bunk@stusta.de>,
	Robert Olsson <Robert.Olsson@data.slu.se>,
	Andrew Morton <akpm@linux-foundation.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Ingo Molnar <mingo@elte.hu>, Josh Triplett <josh@kernel.org>,
	netdev@vger.kernel.org
Subject: [RFT] fib_trie: macro cleanup
Date: Thu, 26 Jul 2007 11:43:34 +0100	[thread overview]
Message-ID: <20070726114334.1e3e446c@oldman.hamilton.local> (raw)
In-Reply-To: <20070726094648.3b7301ae@oldman>

This patch converts the messy macro for MASK_PFX to inline function
and expands TKEY_GET_MASK in the one place it is used.


--- a/net/ipv4/fib_trie.c	2007-07-26 09:26:19.000000000 +0100
+++ b/net/ipv4/fib_trie.c	2007-07-26 10:17:21.000000000 +0100
@@ -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;
 
@@ -192,6 +190,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)
@@ -676,7 +679,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);
@@ -1364,7 +1367,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);
 
@@ -1450,8 +1454,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;
 
@@ -2327,7 +2331,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",

  parent reply	other threads:[~2007-07-26 10:44 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20070725040304.111550f4.akpm@linux-foundation.org>
2007-07-25 13:36 ` [-mm patch] one e1000 driver should be enough for everyone Adrian Bunk
2007-07-25 13:48   ` Jeff Garzik
2007-07-25 14:46     ` Adrian Bunk
2007-07-25 15:05       ` Jeff Garzik
2007-07-25 15:21         ` Kok, Auke
2007-07-25 15:23           ` Jeff Garzik
2007-07-25 20:50           ` Andrew Morton
2007-07-25 18:15 ` 2.6.23-rc1-mm1: net/ipv4/fib_trie.c compile error Adrian Bunk
2007-07-26  8:46   ` [RFT] fib_trie: cleanup Stephen Hemminger
2007-07-26  8:49     ` David Miller
2007-07-26 10:32       ` Robert Olsson
2007-07-26  9:04     ` Andrew Morton
2007-07-26  9:15       ` Stephen Hemminger
2007-07-26 10:49       ` [RFC] fib_trie: whitespace cleanup Stephen Hemminger
2007-07-26 15:44         ` Paul E. McKenney
2007-07-27  4:56           ` Andrew Morton
2007-07-30 17:07             ` Paul E. McKenney
2007-07-26 10:43     ` Stephen Hemminger [this message]
2007-07-26 10:54       ` [RFT] fib_trie: macro cleanup Andrew Morton
2007-07-28 15:44 ` NETPOLL=y , NETDEVICES=n compile error ( Re: 2.6.23-rc1-mm1 ) Gabriel C
2007-07-28 17:26   ` Andrew Morton
2007-07-28 18:42     ` Gabriel C
2007-07-31  8:32       ` Jarek Poplawski
2007-07-31 10:14         ` Gabriel C
2007-07-31 11:44           ` Jason Wessel
2007-07-31 12:47             ` Jarek Poplawski
2007-07-31 12:17           ` Jarek Poplawski
2007-07-31 15:05             ` Gabriel C
2007-08-01  9:59               ` Jarek Poplawski
2007-08-02  2:02                 ` Matt Mackall
2007-08-02  9:00                   ` Jarek Poplawski
2007-08-02 15:59                     ` Matt Mackall
2007-08-03  7:30                       ` Jarek Poplawski
2007-08-02  9:36                   ` Sam Ravnborg
2007-08-02 10:32                     ` Satyam Sharma
2007-08-02 11:40                       ` Satyam Sharma
2007-08-02 11:40                       ` Jarek Poplawski
2007-08-02 11:56                         ` Satyam Sharma
2007-08-02 12:52                           ` Jarek Poplawski
2007-08-06 11:51                     ` [PATCH] docs: note about select in kconfig-language.txt Jarek Poplawski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070726114334.1e3e446c@oldman.hamilton.local \
    --to=shemminger@linux-foundation.org \
    --cc=Robert.Olsson@data.slu.se \
    --cc=akpm@linux-foundation.org \
    --cc=bunk@stusta.de \
    --cc=davem@davemloft.net \
    --cc=josh@kernel.org \
    --cc=mingo@elte.hu \
    --cc=netdev@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).