From: Alexander Duyck <alexander.duyck@gmail.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Alexander Duyck <alexander.h.duyck@redhat.com>,
netdev@vger.kernel.org, davem@davemloft.net
Subject: Re: [PATCH 1/3] etherdev: Avoid unnecessary byte swap in check for Ethertype
Date: Thu, 30 Apr 2015 17:41:04 -0700 [thread overview]
Message-ID: <5542CBA0.2030907@gmail.com> (raw)
In-Reply-To: <1430439180.3711.110.camel@edumazet-glaptop2.roam.corp.google.com>
On 04/30/2015 05:13 PM, Eric Dumazet wrote:
> On Thu, 2015-04-30 at 16:24 -0700, Alexander Duyck wrote:
>
>> Actually a byte operation itself is not faster. Note in the next line
>> we are returning the value. So what you typically end up with by doing
>> it that way would be 2 reads, one for the u8 and one for the u16 return
>> value. That is actually what I am trying to address in the second patch
>> in the set since we were doing a 8b test on the first byte of the
>> address followed by a 64b read.
>>
>> The advantage with the way I wrote this is that the compiler itself
>> should be able to sort out how it wants to test the value while
>> accessing it in a 16b size. So at worst case it is a mask and compare,
>> followed by a return of the value. From what I have seen the compiler
>> seems to be smart enough on x86 anyway to just convert this into a one
>> byte compare on AL and then return the result in AX. I would suspect
>> that for bit-endian systems it would likely just perform the compare.
>>
>
> My compiler (4.8.2 (Ubuntu 4.8.2-19ubuntu1)) does the following :
>
> 62d: 0f b7 42 0c movzwl 0xc(%rdx),%eax
> 631: 0f b6 d0 movzbl %al,%edx
> 634: 83 fa 05 cmp $0x5,%edx
> 637: 7e 02 jle 63b <eth_type_trans+0x8b>
> 639: c9 leaveq
> 63a: c3 retq
>
> Presumably this would be possible
>
> movzwl 0xc(%rdx),%eax
> cmp $0x5,%al
> jle 63b <eth_type_trans+0x8b>
> leaveq
> retq
>
>
My compiler (5.0.1 (Red Hat 5.0.1-0.1)) does like what you have in the
"would be possible" example. What I end up with is something like this:
648: 0f b7 42 0c movzwl 0xc(%rdx),%eax
64c: 3c 05 cmp $0x5,%al
64e: 76 40 jbe 690 <eth_type_trans+0xc0>
The assembler before my patch was:
652: 0f b7 40 0c movzwl 0xc(%rax),%eax
656: 89 c2 mov %eax,%edx
658: 66 c1 c2 08 rol $0x8,%dx
65c: 0f b7 d2 movzwl %dx,%edx
65f: 81 fa ff 05 00 00 cmp $0x5ff,%edx
665: 7e 41 jle 6a8 <eth_type_trans+0xd8>
The savings isn't meant to be anything huge for the patch, maybe a cycle
or two. I suspect the before on your system is probably something
similar to what I had so we are still probably dropping at least 2
instructions.
- Alex
next prev parent reply other threads:[~2015-05-01 0:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-30 21:53 [PATCH 0/3] A few minor clean-ups to eth_type_trans Alexander Duyck
2015-04-30 21:53 ` [PATCH 1/3] etherdev: Avoid unnecessary byte swap in check for Ethertype Alexander Duyck
2015-04-30 23:03 ` Eric Dumazet
2015-04-30 23:24 ` Alexander Duyck
2015-05-01 0:13 ` Eric Dumazet
2015-05-01 0:41 ` Alexander Duyck [this message]
2015-04-30 21:53 ` [PATCH 2/3] etherdev: Process is_multicast_ether_addr at same size as other operations Alexander Duyck
2015-04-30 21:53 ` [PATCH 3/3] etherdev: Use skb->data to retrieve Ethernet header instead of eth_hdr Alexander Duyck
2015-04-30 22:35 ` [PATCH 0/3] A few minor clean-ups to eth_type_trans Alexei Starovoitov
2015-04-30 23:11 ` Alexander Duyck
2015-05-01 11:30 ` David Laight
2015-05-01 15:34 ` Alexander Duyck
2015-05-04 2:47 ` David Miller
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=5542CBA0.2030907@gmail.com \
--to=alexander.duyck@gmail.com \
--cc=alexander.h.duyck@redhat.com \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=netdev@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.