From: Michael Wang <wangyun@linux.vnet.ibm.com>
To: Joe Perches <joe@perches.com>
Cc: Stephen Hemminger <shemminger@vyatta.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH] Avoid extra calculation in ip_route_input_common
Date: Wed, 21 Dec 2011 14:00:31 +0800 [thread overview]
Message-ID: <4EF175FF.70003@linux.vnet.ibm.com> (raw)
In-Reply-To: <1324446632.21340.4.camel@joe2Laptop>
On 12/21/2011 01:50 PM, Joe Perches wrote:
> On Wed, 2011-12-21 at 13:39 +0800, Michael Wang wrote:
>> On 12/21/2011 01:23 PM, Joe Perches wrote:
>>> On Wed, 2011-12-21 at 13:12 +0800, Michael Wang wrote:
>>>> From: Michael Wang <wangyun@linux.vnet.ibm.com>
>>>>
>>>> If previous condition doesn't meet, the later check will be cancelled.
>>>> So we don't need to do all the calculation.
> []
>>> commit c0b8c32b1c96afc9b32b717927330025cc1c501e
>>> Author: Stephen Hemminger <shemminger@vyatta.com>
>>> Date: Thu Apr 10 04:00:28 2008 -0700
>>>
>>> IPV4: use xor rather than multiple ands for route compare
>>>
>>> The comparison in ip_route_input is a hot path, by recoding the C
>>> "and" as bit operations, fewer conditional branches get generated
>>> so the code should be faster. Maybe someday Gcc will be smart
>>> enough to do this?
>> This is what confused me, why "fewer conditional branches get generated"
>> will make code faster?
>> In this example, I think the best condition when daddr is different, we
>> only need to go to one branch do compare then quit, won't this be faster?
>
> if (a && b)
> ...
> pseudo-codes to:
> if (!a)
> goto fail;
> if (!b)
> goto fail;
> ...
> fail:
>
> Each of those conditional branches has a cost.
> Combining tests of variables in the same cache lines
> has relatively little cost compared to the conditional
> branches.
>
That make sense :)
> That's the theory anyway.
>
> If you have tests that demonstrate otherwise, please
> provide them.
>
I think the previous patch should have done such test, otherwise they
won't do this change.
Thanks for your reply, that clear my confusion.
Regards,
Michael Wang
> cheers, Joe
>
next prev parent reply other threads:[~2011-12-21 6:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-21 5:12 [PATCH] Avoid extra calculation in ip_route_input_common Michael Wang
2011-12-21 5:19 ` Michael Wang
2011-12-21 5:23 ` Joe Perches
2011-12-21 5:39 ` Michael Wang
2011-12-21 5:50 ` Joe Perches
2011-12-21 6:00 ` Michael Wang [this message]
2011-12-21 5:57 ` David Miller
2011-12-21 6:04 ` Michael Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4EF175FF.70003@linux.vnet.ibm.com \
--to=wangyun@linux.vnet.ibm.com \
--cc=joe@perches.com \
--cc=netdev@vger.kernel.org \
--cc=shemminger@vyatta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).