All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: remove tests on 64bit platforms
@ 2011-01-25  4:21 Changli Gao
  2011-01-25  4:28 ` Ben Hutchings
  2011-01-25  7:30 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Changli Gao @ 2011-01-25  4:21 UTC (permalink / raw)
  To: David S. Miller
  Cc: Alexey Kuznetsov, Pekka Savola (ipv6),
	James Morris, Hideaki YOSHIFUJI, Patrick McHardy, netdev,
	Changli Gao

On 64bit platforms, >31 bit shifting of a unsigned long variable is
valid, so we can remove the related boundary tests, which may slow
down the CPU if branch prediction fails.

The size of text becomes smaller:
before:
   text	   data	    bss	    dec	    hex	filename
  15721	     16	     16	  15753	   3d89	net/ipv4/fib_trie.o
after:
   text	   data	    bss	    dec	    hex	filename
  15656	     16	     16	  15688	   3d48	net/ipv4/fib_trie.o

Signed-off-by: Changli Gao <xiaosuo@gmail.com>
---
 net/ipv4/fib_trie.c |    8 ++++++++
 1 file changed, 8 insertions(+)
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 0f28034..95c8bb3 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -219,15 +219,23 @@ static inline int tnode_child_length(const struct tnode *tn)
 
 static inline t_key mask_pfx(t_key k, unsigned short l)
 {
+#if BITS_PER_LONG > 32
+	return ((u64)k) >> (KEYLENGTH-l) << (KEYLENGTH-l);
+#else
 	return (l == 0) ? 0 : k >> (KEYLENGTH-l) << (KEYLENGTH-l);
+#endif
 }
 
 static inline t_key tkey_extract_bits(t_key a, int offset, int bits)
 {
+#if BITS_PER_LONG > 32
+	return (t_key)((u64)a << offset) >> (KEYLENGTH - bits);
+#else
 	if (offset < KEYLENGTH)
 		return ((t_key)(a << offset)) >> (KEYLENGTH - bits);
 	else
 		return 0;
+#endif
 }
 
 static inline int tkey_equals(t_key a, t_key b)

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: remove tests on 64bit platforms
  2011-01-25  4:21 [PATCH] net: remove tests on 64bit platforms Changli Gao
@ 2011-01-25  4:28 ` Ben Hutchings
  2011-01-25  7:30 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Ben Hutchings @ 2011-01-25  4:28 UTC (permalink / raw)
  To: Changli Gao
  Cc: David S. Miller, Alexey Kuznetsov, Pekka Savola (ipv6),
	James Morris, Hideaki YOSHIFUJI, Patrick McHardy, netdev

On Tue, 2011-01-25 at 12:21 +0800, Changli Gao wrote:
> On 64bit platforms, >31 bit shifting of a unsigned long variable is
> valid, so we can remove the related boundary tests, which may slow
> down the CPU if branch prediction fails.
[...]

It seems like it would be better to define generic shift functions that
correctly handle the case of a shift count >= word size.  There are many
places these would be useful.

Ben.

-- 
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: remove tests on 64bit platforms
  2011-01-25  4:21 [PATCH] net: remove tests on 64bit platforms Changli Gao
  2011-01-25  4:28 ` Ben Hutchings
@ 2011-01-25  7:30 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2011-01-25  7:30 UTC (permalink / raw)
  To: xiaosuo; +Cc: kuznet, pekkas, jmorris, yoshfuji, kaber, netdev

From: Changli Gao <xiaosuo@gmail.com>
Date: Tue, 25 Jan 2011 12:21:38 +0800

> On 64bit platforms, >31 bit shifting of a unsigned long variable is
> valid, so we can remove the related boundary tests, which may slow
> down the CPU if branch prediction fails.

The key word is "may", you don't actually know if this kind of
change actually matters for performance in practice.

I'm not applying this.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-01-25  7:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-25  4:21 [PATCH] net: remove tests on 64bit platforms Changli Gao
2011-01-25  4:28 ` Ben Hutchings
2011-01-25  7:30 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.