diff options
author | YOSHIFUJI Hideaki / 吉藤英明 <yoshfuji@linux-ipv6.org> | 2013-01-14 02:09:54 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-01-14 13:17:00 -0500 |
commit | 9f2e73345ad9466618edfec35d98c074f2e0570d (patch) | |
tree | 504a464901e3a7b5054a288b8e86874f267fae47 /include/net/ipv6.h | |
parent | 25d46f43a911b08c5aa8c8fd4fe7fa9b36445068 (diff) |
ipv6: 64bit version of ipv6_addr_diff().
Introduce __ipv6_addr_diff64() to to find the first different
bit between two addresses on 64bit architectures.
32bit version is still available as __ipv6_addr_diff32(),
and __ipv6_addr_diff() automatically selects appropriate
version.
Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/ipv6.h')
-rw-r--r-- | include/net/ipv6.h | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/include/net/ipv6.h b/include/net/ipv6.h index ed672080c690..ace1113bef85 100644 --- a/include/net/ipv6.h +++ b/include/net/ipv6.h | |||
@@ -507,7 +507,7 @@ static inline void ipv6_addr_set_v4mapped(const __be32 addr, | |||
507 | * find the first different bit between two addresses | 507 | * find the first different bit between two addresses |
508 | * length of address must be a multiple of 32bits | 508 | * length of address must be a multiple of 32bits |
509 | */ | 509 | */ |
510 | static inline int __ipv6_addr_diff(const void *token1, const void *token2, int addrlen) | 510 | static inline int __ipv6_addr_diff32(const void *token1, const void *token2, int addrlen) |
511 | { | 511 | { |
512 | const __be32 *a1 = token1, *a2 = token2; | 512 | const __be32 *a1 = token1, *a2 = token2; |
513 | int i; | 513 | int i; |
@@ -539,6 +539,33 @@ static inline int __ipv6_addr_diff(const void *token1, const void *token2, int a | |||
539 | return addrlen << 5; | 539 | return addrlen << 5; |
540 | } | 540 | } |
541 | 541 | ||
542 | #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 | ||
543 | static inline int __ipv6_addr_diff64(const void *token1, const void *token2, int addrlen) | ||
544 | { | ||
545 | const __be64 *a1 = token1, *a2 = token2; | ||
546 | int i; | ||
547 | |||
548 | addrlen >>= 3; | ||
549 | |||
550 | for (i = 0; i < addrlen; i++) { | ||
551 | __be64 xb = a1[i] ^ a2[i]; | ||
552 | if (xb) | ||
553 | return i * 64 + 63 - __fls(be64_to_cpu(xb)); | ||
554 | } | ||
555 | |||
556 | return addrlen << 6; | ||
557 | } | ||
558 | #endif | ||
559 | |||
560 | static inline int __ipv6_addr_diff(const void *token1, const void *token2, int addrlen) | ||
561 | { | ||
562 | #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 | ||
563 | if (__builtin_constant_p(addrlen) && !(addrlen & 7)) | ||
564 | return __ipv6_addr_diff64(token1, token2, addrlen); | ||
565 | #endif | ||
566 | return __ipv6_addr_diff32(token1, token2, addrlen); | ||
567 | } | ||
568 | |||
542 | static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_addr *a2) | 569 | static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_addr *a2) |
543 | { | 570 | { |
544 | return __ipv6_addr_diff(a1, a2, sizeof(struct in6_addr)); | 571 | return __ipv6_addr_diff(a1, a2, sizeof(struct in6_addr)); |