public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Alexander Duyck <aduyck@mirantis.com>,
	netdev@vger.kernel.org, davem@davemloft.net
Subject: Re: [net-next PATCH] csum: Update csum_block_add to use rotate instead of byteswap
Date: Tue, 08 Mar 2016 15:25:57 -0800	[thread overview]
Message-ID: <1457479557.4067.9.camel@perches.com> (raw)
In-Reply-To: <20160308224238.16551.73881.stgit@localhost.localdomain>

On Tue, 2016-03-08 at 14:42 -0800, Alexander Duyck wrote:
> The code for csum_block_add was doing a funky byteswap to swap the even and
> odd bytes of the checksum if the offset was odd.  Instead of doing this we
> can save ourselves some trouble and just shift by 8 as this should have the
> same effect in terms of the final checksum value and only requires one
> instruction.

3 instructions?

> In addition we can update csum_block_sub to just use csum_block_add with a
> inverse value for csum2.  This way we follow the same code path as
> csum_block_add without having to duplicate it.
> 
> Signed-off-by: Alexander Duyck <aduyck@mirantis.com>
> ---
>  include/net/checksum.h |   11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/include/net/checksum.h b/include/net/checksum.h
> index 10a16b5bd1c7..f9fac66c0e66 100644
> --- a/include/net/checksum.h
> +++ b/include/net/checksum.h
> @@ -88,8 +88,10 @@ static inline __wsum
>  csum_block_add(__wsum csum, __wsum csum2, int offset)
>  {
>  	u32 sum = (__force u32)csum2;
> -	if (offset&1)
> -		sum = ((sum&0xFF00FF)<<8)+((sum>>8)&0xFF00FF);
> +
> +	if (offset & 1)
> +		sum = (sum << 24) + (sum >> 8);

Maybe use ror32(sum, 8);

or maybe something like:

{
	u32 sum;

	/* rotated csum2 of odd offset will be the right checksum */
	if (offset & 1)
		sum = ror32((__force u32)csum2, 8);
	else
		sum = (__force u32)csum2;

  reply	other threads:[~2016-03-08 23:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-08 22:42 [net-next PATCH] csum: Update csum_block_add to use rotate instead of byteswap Alexander Duyck
2016-03-08 23:25 ` Joe Perches [this message]
2016-03-09  5:23   ` Alexander Duyck
2016-03-09  5:50     ` Joe Perches
2016-03-09  6:08       ` Alexander Duyck
2016-03-09  6:31         ` Tom Herbert
2016-03-09 16:08           ` Alexander Duyck
2016-03-10  0:18             ` Joe Perches
2016-03-10  0:58               ` Tom Herbert
2016-03-09 10:54   ` David Laight
2016-03-09 16:03     ` Alexander Duyck

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=1457479557.4067.9.camel@perches.com \
    --to=joe@perches.com \
    --cc=aduyck@mirantis.com \
    --cc=davem@davemloft.net \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox