summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Pfister <ppfister@cisco.com>2016-04-08 17:49:48 +0100
committerGerrit Code Review <gerrit@fd.io>2016-04-12 12:12:50 +0000
commitb3e80947dce184a922ab479dbab911a7709a60eb (patch)
treea3d170e8eaa2b3678beaf6a3f7a977c8c28b3cc6
parentc42552d4e0f358c5c473b64aafe3057a4914f71a (diff)
IP6 FIB: Micro optimization in lookup
The mask is increasingly small. This saves a few cycles and becomes significant when there are many prefix lengths. Change-Id: Ibd0c9331f675697bb4e90e8ad617994f83edec9c Signed-off-by: Pierre Pfister <ppfister@cisco.com>
-rw-r--r--vnet/vnet/ip/ip6_forward.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/vnet/vnet/ip/ip6_forward.c b/vnet/vnet/ip/ip6_forward.c
index 27c776e3d44..6c8d18d6d58 100644
--- a/vnet/vnet/ip/ip6_forward.c
+++ b/vnet/vnet/ip/ip6_forward.c
@@ -64,19 +64,24 @@ ip6_fib_lookup_with_table (ip6_main_t * im, u32 fib_index, ip6_address_t * dst)
int i, len;
int rv;
BVT(clib_bihash_kv) kv, value;
+ u64 fib;
len = vec_len (im->prefix_lengths_in_search_order);
+ kv.key[0] = dst->as_u64[0];
+ kv.key[1] = dst->as_u64[1];
+ fib = ((u64)((fib_index))<<32);
+
for (i = 0; i < len; i++)
{
int dst_address_length = im->prefix_lengths_in_search_order[i];
ip6_address_t * mask = &im->fib_masks[dst_address_length];
ASSERT(dst_address_length >= 0 && dst_address_length <= 128);
-
- kv.key[0] = dst->as_u64[0] & mask->as_u64[0];
- kv.key[1] = dst->as_u64[1] & mask->as_u64[1];
- kv.key[2] = ((u64)((fib_index))<<32) | dst_address_length;
+ //As lengths are decreasing, masks are increasingly specific.
+ kv.key[0] &= mask->as_u64[0];
+ kv.key[1] &= mask->as_u64[1];
+ kv.key[2] = fib | dst_address_length;
rv = BV(clib_bihash_search_inline_2)(&im->ip6_lookup_table, &kv, &value);
if (rv == 0)