From: Charlie Jenkins <charlie@rivosinc.com>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: Palmer Dabbelt <palmer@dabbelt.com>,
Conor Dooley <conor@kernel.org>,
Samuel Holland <samuel.holland@sifive.com>,
David Laight <David.Laight@aculab.com>,
Xiao Wang <xiao.w.wang@intel.com>, Evan Green <evan@rivosinc.com>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-arch@vger.kernel.org,
Paul Walmsley <paul.walmsley@sifive.com>,
Albert Ou <aou@eecs.berkeley.edu>, Arnd Bergmann <arnd@arndb.de>
Subject: Re: [PATCH v8 1/5] asm-generic: Improve csum_fold
Date: Fri, 27 Oct 2023 17:04:45 -0700 [thread overview]
Message-ID: <ZTxQHVplimd4tquE@ghost> (raw)
In-Reply-To: <20231027231036.GM800259@ZenIV>
On Sat, Oct 28, 2023 at 12:10:36AM +0100, Al Viro wrote:
> On Fri, Oct 27, 2023 at 03:43:51PM -0700, Charlie Jenkins wrote:
> > /*
> > * computes the checksum of a memory block at buff, length len,
> > * and adds in "sum" (32-bit)
> > @@ -31,9 +33,7 @@ extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
> > static inline __sum16 csum_fold(__wsum csum)
> > {
> > u32 sum = (__force u32)csum;
> > - sum = (sum & 0xffff) + (sum >> 16);
> > - sum = (sum & 0xffff) + (sum >> 16);
> > - return (__force __sum16)~sum;
> > + return (__force __sum16)((~sum - ror32(sum, 16)) >> 16);
> > }
>
> Will (~(sum + ror32(sum, 16))>>16 produce worse code than that?
> Because at least with recent gcc this will generate the exact thing
> you get from arm inline asm...
Yes that will produce worse code because an out-of-order processor will be able to
leverage that ~sum and ror32(sum, 16) can be computed independently of
each other. There are more strict data dependencies in (~(sum +
ror32(sum, 16))>>16.
- Charlie
WARNING: multiple messages have this Message-ID (diff)
From: Charlie Jenkins <charlie@rivosinc.com>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: Palmer Dabbelt <palmer@dabbelt.com>,
Conor Dooley <conor@kernel.org>,
Samuel Holland <samuel.holland@sifive.com>,
David Laight <David.Laight@aculab.com>,
Xiao Wang <xiao.w.wang@intel.com>, Evan Green <evan@rivosinc.com>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-arch@vger.kernel.org,
Paul Walmsley <paul.walmsley@sifive.com>,
Albert Ou <aou@eecs.berkeley.edu>, Arnd Bergmann <arnd@arndb.de>
Subject: Re: [PATCH v8 1/5] asm-generic: Improve csum_fold
Date: Fri, 27 Oct 2023 17:04:45 -0700 [thread overview]
Message-ID: <ZTxQHVplimd4tquE@ghost> (raw)
In-Reply-To: <20231027231036.GM800259@ZenIV>
On Sat, Oct 28, 2023 at 12:10:36AM +0100, Al Viro wrote:
> On Fri, Oct 27, 2023 at 03:43:51PM -0700, Charlie Jenkins wrote:
> > /*
> > * computes the checksum of a memory block at buff, length len,
> > * and adds in "sum" (32-bit)
> > @@ -31,9 +33,7 @@ extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
> > static inline __sum16 csum_fold(__wsum csum)
> > {
> > u32 sum = (__force u32)csum;
> > - sum = (sum & 0xffff) + (sum >> 16);
> > - sum = (sum & 0xffff) + (sum >> 16);
> > - return (__force __sum16)~sum;
> > + return (__force __sum16)((~sum - ror32(sum, 16)) >> 16);
> > }
>
> Will (~(sum + ror32(sum, 16))>>16 produce worse code than that?
> Because at least with recent gcc this will generate the exact thing
> you get from arm inline asm...
Yes that will produce worse code because an out-of-order processor will be able to
leverage that ~sum and ror32(sum, 16) can be computed independently of
each other. There are more strict data dependencies in (~(sum +
ror32(sum, 16))>>16.
- Charlie
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2023-10-28 0:04 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-27 22:43 [PATCH v8 0/5] riscv: Add fine-tuned checksum functions Charlie Jenkins
2023-10-27 22:43 ` Charlie Jenkins
2023-10-27 22:43 ` [PATCH v8 1/5] asm-generic: Improve csum_fold Charlie Jenkins
2023-10-27 22:43 ` Charlie Jenkins
2023-10-27 23:10 ` Al Viro
2023-10-27 23:10 ` Al Viro
2023-10-28 0:04 ` Charlie Jenkins [this message]
2023-10-28 0:04 ` Charlie Jenkins
2023-10-27 22:43 ` [PATCH v8 2/5] riscv: Add static key for misaligned accesses Charlie Jenkins
2023-10-27 22:43 ` Charlie Jenkins
2023-10-27 22:43 ` [PATCH v8 3/5] riscv: Checksum header Charlie Jenkins
2023-10-27 22:43 ` Charlie Jenkins
2023-10-31 9:11 ` Wang, Xiao W
2023-10-31 9:11 ` Wang, Xiao W
2023-10-31 22:53 ` Charlie Jenkins
2023-10-31 22:53 ` Charlie Jenkins
2023-10-27 22:43 ` [PATCH v8 4/5] riscv: Add checksum library Charlie Jenkins
2023-10-27 22:43 ` Charlie Jenkins
2023-10-31 9:51 ` Wang, Xiao W
2023-10-31 9:51 ` Wang, Xiao W
2023-10-31 22:59 ` Charlie Jenkins
2023-10-31 22:59 ` Charlie Jenkins
2023-10-27 22:43 ` [PATCH v8 5/5] riscv: Test checksum functions Charlie Jenkins
2023-10-27 22:43 ` Charlie Jenkins
2023-10-31 7:57 ` [PATCH v8 0/5] riscv: Add fine-tuned " Conor Dooley
2023-10-31 7:57 ` Conor Dooley
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=ZTxQHVplimd4tquE@ghost \
--to=charlie@rivosinc.com \
--cc=David.Laight@aculab.com \
--cc=aou@eecs.berkeley.edu \
--cc=arnd@arndb.de \
--cc=conor@kernel.org \
--cc=evan@rivosinc.com \
--cc=linux-arch@vger.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 \
--cc=viro@zeniv.linux.org.uk \
--cc=xiao.w.wang@intel.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 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.