IP6 FIB: Micro optimization in lookup 18/718/3
authorPierre Pfister <ppfister@cisco.com>
Fri, 8 Apr 2016 16:49:48 +0000 (17:49 +0100)
committerGerrit Code Review <gerrit@fd.io>
Tue, 12 Apr 2016 12:12:50 +0000 (12:12 +0000)
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>
vnet/vnet/ip/ip6_forward.c

index 27c776e..6c8d18d 100644 (file)
@@ -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)