mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Charlie Jenkins' <charlie@rivosinc.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Conor Dooley <conor@kernel.org>,
	Samuel Holland <samuel.holland@sifive.com>,
	"linux-riscv@lists.infradead.org"
	<linux-riscv@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Paul Walmsley <paul.walmsley@sifive.com>,
	Albert Ou <aou@eecs.berkeley.edu>
Subject: RE: [PATCH v5 1/4] asm-generic: Improve csum_fold
Date: Fri, 15 Sep 2023 07:29:23 +0000	[thread overview]
Message-ID: <b6bd38541255470b97bbaf3e6cdb4265@AcuMS.aculab.com> (raw)
In-Reply-To: <20230914-optimize_checksum-v5-1-c95b82a2757e@rivosinc.com>

From: Charlie Jenkins
> Sent: 15 September 2023 04:50
> 
> This csum_fold implementation introduced into arch/arc by Vineet Gupta
> is better than the default implementation on at least arc, x86, arm, and
> riscv. Using GCC trunk and compiling non-inlined version, this
> implementation has 41.6667%, 25%, 16.6667% fewer instructions on
> riscv64, x86-64, and arm64 respectively with -O3 optimization.

Nit-picking the commit message...
Some of those architectures have their own asm implementation.
The arm one is better than the C code below, the x86 ones aren't.

I think that only sparc32 (carry flag but no rotate) and
arm/arm64 (barrel shifter on every instruction) have versions
that are better than the one here.

Since I suggested it to Charlie:

Reviewed-by: David Laight <david.laight@aculab.com>

> 
> Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
> ---
>  include/asm-generic/checksum.h | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/include/asm-generic/checksum.h b/include/asm-generic/checksum.h
> index 43e18db89c14..adab9ac4312c 100644
> --- a/include/asm-generic/checksum.h
> +++ b/include/asm-generic/checksum.h
> @@ -30,10 +30,7 @@ extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
>   */
>  static inline __sum16 csum_fold(__wsum csum)
>  {
> -	u32 sum = (__force u32)csum;

You'll need to re-instate that line to stop sparse complaining.

> -	sum = (sum & 0xffff) + (sum >> 16);
> -	sum = (sum & 0xffff) + (sum >> 16);
> -	return (__force __sum16)~sum;
> +	return (__force __sum16)((~csum - ror32(csum, 16)) >> 16);
>  }
>  #endif
> 
> 
> --
> 2.42.0

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

  reply	other threads:[~2023-09-15  7:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-15  3:49 [PATCH v5 0/4] riscv: Add fine-tuned checksum functions Charlie Jenkins
2023-09-15  3:49 ` [PATCH v5 1/4] asm-generic: Improve csum_fold Charlie Jenkins
2023-09-15  7:29   ` David Laight [this message]
2023-09-15 15:45     ` Charlie Jenkins
2023-09-15  3:49 ` [PATCH v5 2/4] riscv: Checksum header Charlie Jenkins
2023-09-15 10:07   ` Emil Renner Berthing
2023-09-15 15:25     ` Charlie Jenkins
2023-09-15  3:49 ` [PATCH v5 3/4] riscv: Add checksum library Charlie Jenkins
2023-09-15  3:49 ` [PATCH v5 4/4] 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=b6bd38541255470b97bbaf3e6cdb4265@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=charlie@rivosinc.com \
    --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 \
    --cc=samuel.holland@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

all inboxes | Powered by JetHome®