From: Pierre Pfister Date: Fri, 8 Apr 2016 16:49:48 +0000 (+0100) Subject: IP6 FIB: Micro optimization in lookup X-Git-Tag: v16.06-rc1~166 X-Git-Url: https://gerrit.fd.io/r/gitweb?a=commitdiff_plain;h=b3e80947dce184a922ab479dbab911a7709a60eb;p=vpp.git 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 --- 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)