From: David Laight <David.Laight@ACULAB.COM>
To: 'Eric Dumazet' <edumazet@google.com>,
'Peter Zijlstra' <peterz@infradead.org>
Cc: "'tglx@linutronix.de'" <tglx@linutronix.de>,
"'mingo@redhat.com'" <mingo@redhat.com>,
'Borislav Petkov' <bp@alien8.de>,
"'dave.hansen@linux.intel.com'" <dave.hansen@linux.intel.com>,
'X86 ML' <x86@kernel.org>, "'hpa@zytor.com'" <hpa@zytor.com>,
"'alexanderduyck@fb.com'" <alexanderduyck@fb.com>,
'open list' <linux-kernel@vger.kernel.org>,
'netdev' <netdev@vger.kernel.org>,
"'Noah Goldstein'" <goldstein.w.n@gmail.com>
Subject: [PATCH ] x86/lib: Optimise copy loop for long buffers in csum-partial_64.c
Date: Thu, 6 Jan 2022 16:19:54 +0000 [thread overview]
Message-ID: <04c41a96f4eb4fe782d10ae2691ad93e@AcuMS.aculab.com> (raw)
gcc converts the loop into one that only increments the pointer
but makes a mess of calculating the limit and gcc 9.1+ completely
refuses to use the final value of 'buff' from the last iteration.
Explicitly code a pointer comparison and don't bother changing len.
Signed-off-by: David Laight <david.laight@aculab.com>
---
The asm("" : "+r" (buff)); forces gcc to use the loop-updated
value of 'buff' and removes at least 6 instructions.
The gcc folk really ought to look at why gcc 9.1 onwards is so
much worse that gcc 8.
See https://godbolt.org/z/T39PcnvfE
arch/x86/lib/csum-partial_64.c | 33 ++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/arch/x86/lib/csum-partial_64.c b/arch/x86/lib/csum-partial_64.c
index edd3e579c2a7..342de5f24fcb 100644
--- a/arch/x86/lib/csum-partial_64.c
+++ b/arch/x86/lib/csum-partial_64.c
@@ -27,21 +27,24 @@ __wsum csum_partial(const void *buff, int len, __wsum sum)
u64 temp64 = (__force u64)sum;
unsigned result;
- while (unlikely(len >= 64)) {
- asm("addq 0*8(%[src]),%[res]\n\t"
- "adcq 1*8(%[src]),%[res]\n\t"
- "adcq 2*8(%[src]),%[res]\n\t"
- "adcq 3*8(%[src]),%[res]\n\t"
- "adcq 4*8(%[src]),%[res]\n\t"
- "adcq 5*8(%[src]),%[res]\n\t"
- "adcq 6*8(%[src]),%[res]\n\t"
- "adcq 7*8(%[src]),%[res]\n\t"
- "adcq $0,%[res]"
- : [res] "+r" (temp64)
- : [src] "r" (buff)
- : "memory");
- buff += 64;
- len -= 64;
+ if (unlikely(len >= 64)) {
+ const void *lim = buff + (len & ~63u);
+ do {
+ asm("addq 0*8(%[src]),%[res]\n\t"
+ "adcq 1*8(%[src]),%[res]\n\t"
+ "adcq 2*8(%[src]),%[res]\n\t"
+ "adcq 3*8(%[src]),%[res]\n\t"
+ "adcq 4*8(%[src]),%[res]\n\t"
+ "adcq 5*8(%[src]),%[res]\n\t"
+ "adcq 6*8(%[src]),%[res]\n\t"
+ "adcq 7*8(%[src]),%[res]\n\t"
+ "adcq $0,%[res]"
+ : [res] "+r" (temp64)
+ : [src] "r" (buff)
+ : "memory");
+ asm("" : "+r" (buff));
+ buff += 64;
+ } while (buff < lim);
}
if (len & 32) {
--
2.17.1
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
reply other threads:[~2022-01-06 16:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=04c41a96f4eb4fe782d10ae2691ad93e@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=alexanderduyck@fb.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=edumazet@google.com \
--cc=goldstein.w.n@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=x86@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
all inboxes | Powered by JetHome®