From: Linkui Xiao <xiaolinkui@gmail.com>
To: David Laight <David.Laight@ACULAB.COM>,
"pmenzel@molgen.mpg.de" <pmenzel@molgen.mpg.de>,
"jesse.brandeburg@intel.com" <jesse.brandeburg@intel.com>,
"anthony.l.nguyen@intel.com" <anthony.l.nguyen@intel.com>
Cc: "davem@davemloft.net" <davem@davemloft.net>,
"edumazet@google.com" <edumazet@google.com>,
"kuba@kernel.org" <kuba@kernel.org>,
"pabeni@redhat.com" <pabeni@redhat.com>,
"intel-wired-lan@lists.osuosl.org"
<intel-wired-lan@lists.osuosl.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
Linkui Xiao <xiaolinkui@kylinos.cn>
Subject: Re: [PATCH] igb: Convert a series of if statements to switch case
Date: Thu, 12 May 2022 21:31:58 +0800 [thread overview]
Message-ID: <8e7ccd70-78df-64f8-678f-968ad38eae50@gmail.com> (raw)
In-Reply-To: <3a5a6467b24a46ce8e05fb8a422baa51@AcuMS.aculab.com>
Dear David,
Thanks for your reply
Logically the two versions are equivalent, hw->mac.type is defined as
follows:
enum e1000_mac_type {
e1000_undefined = 0,
e1000_82575,
e1000_82576,
e1000_82580,
e1000_i350,
e1000_i354,
e1000_i210,
e1000_i211,
e1000_num_macs /* List is 1-based, so subtract 1 for true
count. */
};
Therefore, hw->mac.type < e1000_82576 has only two cases:
e1000_undefined or e1000_82575.
On 5/12/22 21:14, David Laight wrote:
>> From: Linkui Xiao <xiaolinkui@kylinos.cn>
>>
>> Convert a series of if statements that handle different events to a switch
>> case statement to simplify the code.
>>
>> V2: fix patch description and email format.
>>
>> Signed-off-by: Linkui Xiao <xiaolinkui@kylinos.cn>
>> ---
>> drivers/net/ethernet/intel/igb/igb_main.c | 12 ++++++++----
>> 1 file changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
>> index 34b33b21e0dc..4ce0718eeff6 100644
>> --- a/drivers/net/ethernet/intel/igb/igb_main.c
>> +++ b/drivers/net/ethernet/intel/igb/igb_main.c
>> @@ -4588,13 +4588,17 @@ static inline void igb_set_vf_vlan_strip(struct igb_adapter *adapter,
>> struct e1000_hw *hw = &adapter->hw;
>> u32 val, reg;
>>
>> - if (hw->mac.type < e1000_82576)
>> + switch (hw->mac.type) {
>> + case e1000_undefined:
>> + case e1000_82575:
>> return;
>> -
>> - if (hw->mac.type == e1000_i350)
>> + case e1000_i350:
>> reg = E1000_DVMOLR(vfn);
>> - else
>> + break;
>> + default:
>> reg = E1000_VMOLR(vfn);
>> + break;
>> + }
>>
>> val = rd32(reg);
>> if (enable)
>> --
>> 2.17.1
> Are you sure that generates reasonable code?
> The compiler could generate something completely different
> for the two versions.
>
> It isn't even obvious they are equivalent.
>
> David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
>
next prev parent reply other threads:[~2022-05-12 13:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-11 9:20 [PATCH] igb: Convert a series of if statements to switch case xiaolinkui
2022-05-12 13:14 ` David Laight
2022-05-12 13:31 ` Linkui Xiao [this message]
2022-05-12 18:47 ` Tony Nguyen
-- strict thread matches above, loose matches on Subject: below --
2022-05-10 2:57 xiaolinkui
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=8e7ccd70-78df-64f8-678f-968ad38eae50@gmail.com \
--to=xiaolinkui@gmail.com \
--cc=David.Laight@ACULAB.COM \
--cc=anthony.l.nguyen@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=jesse.brandeburg@intel.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pmenzel@molgen.mpg.de \
--cc=xiaolinkui@kylinos.cn \
/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).