linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Charlie Jenkins <charlie@rivosinc.com>
To: David Laight <David.Laight@aculab.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Conor Dooley <conor@kernel.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	"linux-riscv@lists.infradead.org"
	<linux-riscv@lists.infradead.org>
Subject: Re: [PATCH v2 1/5] riscv: Checksum header
Date: Mon, 11 Sep 2023 11:16:46 -0700	[thread overview]
Message-ID: <ZP9ZjoFk1GV8gcW1@ghost> (raw)
In-Reply-To: <cec0f23506a54b9aaaef054ea949e4aa@AcuMS.aculab.com>

On Sun, Sep 10, 2023 at 09:20:33PM +0000, David Laight wrote:
> ...
> > > > +/*
> > > > + *	Fold a partial checksum without adding pseudo headers
> > > > + */
> > > > +static inline __sum16 csum_fold(__wsum sum)
> > > > +{
> > > > +	sum += (sum >> 16) | (sum << 16);
> > > > +	return (__force __sum16)(~(sum >> 16));
> > > > +}
> 
> I'm intrigued, gcc normally compiler that quite well.
> The very similar (from arch/arc):
> 	return (~sum - rol32(sum, 16)) >> 16;
> is slightly better on most architectures.
> (Especially if the ~sum and rol() can be executed together.)
Oh wow that solves the problem of needing to zero extend the result
after taking the not. Taking the shift after the not both zero-extends
and places the result in the correct spot. It is a very interesting
property that it is possible to change the order of the operations if
the addition becomes a subtraction. I will make the change. Thank you!

- Charlie
> 
> The only odd archs I saw were sparc32 (carry flag bug no rotate)
> and arm (barrel shifter on all instructions).
> 
> It is better than the current asm for a lot of archs including x64.
> 
> 	David
> 
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
> 

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2023-09-11 18:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-06  4:46 [PATCH v2 0/5] riscv: Add fine-tuned checksum functions Charlie Jenkins
2023-09-06  4:46 ` [PATCH v2 1/5] riscv: Checksum header Charlie Jenkins
2023-09-07  9:40   ` Conor Dooley
2023-09-07 17:44     ` Charlie Jenkins
2023-09-10 21:20       ` David Laight
2023-09-11 18:16         ` Charlie Jenkins [this message]
2023-09-06  4:46 ` [PATCH v2 2/5] riscv: Add checksum library Charlie Jenkins
2023-09-07  9:52   ` Conor Dooley
2023-09-07 17:47     ` Charlie Jenkins
2023-09-06  4:46 ` [PATCH v2 3/5] riscv: Vector checksum header Charlie Jenkins
2023-09-07  9:47   ` Conor Dooley
2023-09-07 17:43     ` Charlie Jenkins
2023-09-07  9:58   ` Conor Dooley
2023-09-07 17:41     ` Charlie Jenkins
2023-09-06  4:46 ` [PATCH v2 4/5] riscv: Vector checksum library Charlie Jenkins
2023-09-06  4:46 ` [PATCH v2 5/5] riscv: Test checksum functions Charlie Jenkins

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=ZP9ZjoFk1GV8gcW1@ghost \
    --to=charlie@rivosinc.com \
    --cc=David.Laight@aculab.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=conor@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.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).