kernel/3.18: update to version 3.18.25
[openwrt/openwrt.git] / target / linux / generic / patches-3.18 / 080-19-fib_trie-Use-index-0ul-n-bits-instead-of-index-n-bit.patch
1 From: Alexander Duyck <alexander.h.duyck@redhat.com>
2 Date: Thu, 22 Jan 2015 15:51:08 -0800
3 Subject: [PATCH] fib_trie: Use index & (~0ul << n->bits) instead of index >>
4 n->bits
5
6 In doing performance testing and analysis of the changes I recently found
7 that by shifting the index I had created an unnecessary dependency.
8
9 I have updated the code so that we instead shift a mask by bits and then
10 just test against that as that should save us about 2 CPU cycles since we
11 can generate the mask while the key and pos are being processed.
12
13 Signed-off-by: Alexander Duyck <alexander.h.duyck@redhat.com>
14 Signed-off-by: David S. Miller <davem@davemloft.net>
15 ---
16
17 --- a/net/ipv4/fib_trie.c
18 +++ b/net/ipv4/fib_trie.c
19 @@ -961,12 +961,12 @@ static struct tnode *fib_find_node(struc
20 * prefix plus zeros for the bits in the cindex. The index
21 * is the difference between the key and this value. From
22 * this we can actually derive several pieces of data.
23 - * if !(index >> bits)
24 - * we know the value is cindex
25 - * else
26 + * if (index & (~0ul << bits))
27 * we have a mismatch in skip bits and failed
28 + * else
29 + * we know the value is cindex
30 */
31 - if (index >> n->bits)
32 + if (index & (~0ul << n->bits))
33 return NULL;
34
35 /* we have found a leaf. Prefixes have already been compared */
36 @@ -1301,12 +1301,12 @@ int fib_table_lookup(struct fib_table *t
37 * prefix plus zeros for the "bits" in the prefix. The index
38 * is the difference between the key and this value. From
39 * this we can actually derive several pieces of data.
40 - * if !(index >> bits)
41 - * we know the value is child index
42 - * else
43 + * if (index & (~0ul << bits))
44 * we have a mismatch in skip bits and failed
45 + * else
46 + * we know the value is cindex
47 */
48 - if (index >> n->bits)
49 + if (index & (~0ul << n->bits))
50 break;
51
52 /* we have found a leaf. Prefixes have already been compared */