Patchwork [net-next] net: ipv4: optimize tkey_mismatch

login
register
mail settings
Submitter Igor Maravić
Date Aug. 28, 2012, 8:52 a.m.
Message ID <1346143938-17167-2-git-send-email-igorm@etf.rs>
Download mbox | patch
Permalink /patch/180385/
State Rejected
Delegated to: David Miller
Headers show

Comments

Igor Maravić - Aug. 28, 2012, 8:52 a.m.
From: Igor Maravic <igorm@etf.rs>

Optimize tkey_mismatch function by using __fls function.

Signed-off-by: Igor Maravic <igorm@etf.rs>
---
 net/ipv4/fib_trie.c |   10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
David Miller - Aug. 28, 2012, 6:56 p.m.
From: igorm@etf.rs
Date: Tue, 28 Aug 2012 10:52:18 +0200

> From: Igor Maravic <igorm@etf.rs>
> 
> Optimize tkey_mismatch function by using __fls function.
> 
> Signed-off-by: Igor Maravic <igorm@etf.rs>

This will actually run slower on architectures like sparc that
don't have special instructions for __fls.

Your TOS "optimization" isn't very useful either since having
TOS routes is very rare.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index ec45621..b4b126c 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -265,14 +265,8 @@  static inline int tkey_sub_equals(t_key a, int offset, int bits, t_key b)
 
 static inline int tkey_mismatch(t_key a, int offset, t_key b)
 {
-	t_key diff = a ^ b;
-	int i = offset;
-
-	if (!diff)
-		return 0;
-	while ((diff << i) >> (KEYLENGTH-1) == 0)
-		i++;
-	return i;
+	t_key diff = (a ^ b) & (~((t_key)0) << offset >> offset);
+	return diff ? (KEYLENGTH - __fls(diff) - 1) : 0;
 }
 
 /*