netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC, PATCH] IPV6 : add 64 bits components in struct in6_addr to speedup ipv6_addr_equal() & ipv6_addr_any()
@ 2007-04-30 14:28 Eric Dumazet
  2007-04-30 16:09 ` YOSHIFUJI Hideaki / 吉藤英明
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Eric Dumazet @ 2007-04-30 14:28 UTC (permalink / raw)
  To: yoshfuji Hideaki, David Miller; +Cc: netdev@vger.kernel.org

On 64bit arches, we can speedup some IPV6 addresses compares, using 64 bits fields in struct in6_addr.

I am not sure if this patch wont break some user ABI, maybe we should use some ifdef(KERNEL) ?

This patch saves some space, and also reduce number of conditional branches in ipv6_addr_equal()

# size vmlinux*
   text    data     bss     dec     hex filename
6257978  692044  660472 7610494  74207e vmlinux
6259178  692044  660472 7611694  74252e vmlinux.before_patch

Note : Maybe ipv6_addr_cmp() could be defined on top of ipv6_addr_equal() ?

Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
---
 include/linux/in6.h |    2 ++
 include/net/ipv6.h  |   17 +++++++++++++----
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/include/linux/in6.h b/include/linux/in6.h
index 2a61c82..a4241a6 100644
--- a/include/linux/in6.h
+++ b/include/linux/in6.h
@@ -34,10 +34,12 @@ struct in6_addr
 		__u8		u6_addr8[16];
 		__be16		u6_addr16[8];
 		__be32		u6_addr32[4];
+		__be64		u6_addr64[2];
 	} in6_u;
 #define s6_addr			in6_u.u6_addr8
 #define s6_addr16		in6_u.u6_addr16
 #define s6_addr32		in6_u.u6_addr32
+#define s6_addr64		in6_u.u6_addr64
 };
 
 /* IPv6 Wildcard Address (::) and Loopback Address (::1) defined in RFC2553
diff --git a/include/net/ipv6.h b/include/net/ipv6.h
index f70afef..6493ff6 100644
--- a/include/net/ipv6.h
+++ b/include/net/ipv6.h
@@ -343,10 +343,15 @@ #endif
 static inline int ipv6_addr_equal(const struct in6_addr *a1,
 				  const struct in6_addr *a2)
 {
-	return (a1->s6_addr32[0] == a2->s6_addr32[0] &&
-		a1->s6_addr32[1] == a2->s6_addr32[1] &&
-		a1->s6_addr32[2] == a2->s6_addr32[2] &&
-		a1->s6_addr32[3] == a2->s6_addr32[3]);
+#if defined(CONFIG_64BIT)
+	return (((a1->s6_addr64[0] ^ a2->s6_addr64[0]) |
+		(a1->s6_addr64[1] ^ a2->s6_addr64[1])) == 0);
+#else
+	return (((a1->s6_addr32[0] ^ a2->s6_addr32[0]) |
+		(a1->s6_addr32[1] ^ a2->s6_addr32[1]) |
+		(a1->s6_addr32[2] ^ a2->s6_addr32[2]) |
+		(a1->s6_addr32[3] ^ a2->s6_addr32[3])) == 0);
+#endif
 }
 
 static inline int __ipv6_prefix_equal(const __be32 *a1, const __be32 *a2,
@@ -377,8 +382,12 @@ static inline int ipv6_prefix_equal(cons
 
 static inline int ipv6_addr_any(const struct in6_addr *a)
 {
+#if defined(CONFIG_64BIT)
+	return ((a->s6_addr64[0] | a->s6_addr64[1]) == 0);
+#else
 	return ((a->s6_addr32[0] | a->s6_addr32[1] | 
 		 a->s6_addr32[2] | a->s6_addr32[3] ) == 0); 
+#endif
 }
 
 /*

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

end of thread, other threads:[~2007-04-30 20:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-30 14:28 [RFC, PATCH] IPV6 : add 64 bits components in struct in6_addr to speedup ipv6_addr_equal() & ipv6_addr_any() Eric Dumazet
2007-04-30 16:09 ` YOSHIFUJI Hideaki / 吉藤英明
2007-04-30 16:27 ` Brian Haley
2007-04-30 18:59   ` David Miller
2007-04-30 19:08     ` Eric Dumazet
2007-04-30 19:22       ` David Miller
2007-04-30 19:10 ` David Miller
2007-04-30 21:34   ` Andi Kleen
2007-04-30 20:37     ` 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).