From: David Laight <David.Laight@ACULAB.COM>
To: 'Noah Goldstein' <goldstein.w.n@gmail.com>,
'Eric Dumazet' <edumazet@google.com>
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>,
"'peterz@infradead.org'" <peterz@infradead.org>,
"'alexanderduyck@fb.com'" <alexanderduyck@fb.com>,
'open list' <linux-kernel@vger.kernel.org>,
'netdev' <netdev@vger.kernel.org>
Subject: [PATCH] lib/x86: Optimise csum_partial of buffers that are not multiples of 8 bytes.
Date: Mon, 13 Dec 2021 18:00:56 +0000 [thread overview]
Message-ID: <f1cd1a19878248f09e2e7cffe88c8191@AcuMS.aculab.com> (raw)
Add in the trailing bytes first so that there is no need to worry
about the sum exceeding 64 bits.
Signed-off-by: David Laight <david.laight@aculab.com>
---
This ought to be faster - because of all the removed 'adc $0'.
Guessing how fast x86 code will run is hard!
There are other ways of handing buffers that are shorter than 8 bytes,
but I'd rather hope they don't happen in any hot paths.
Note - I've not even compile tested it.
(But have tested an equivalent change before.)
arch/x86/lib/csum-partial_64.c | 55 ++++++++++++----------------------
1 file changed, 19 insertions(+), 36 deletions(-)
diff --git a/arch/x86/lib/csum-partial_64.c b/arch/x86/lib/csum-partial_64.c
index abf819dd8525..fbcc073fc2b5 100644
--- a/arch/x86/lib/csum-partial_64.c
+++ b/arch/x86/lib/csum-partial_64.c
@@ -37,6 +37,24 @@ __wsum csum_partial(const void *buff, int len, __wsum sum)
u64 temp64 = (__force u64)sum;
unsigned result;
+ if (len & 7) {
+ if (unlikely(len < 8)) {
+ /* Avoid falling off the start of the buffer */
+ if (len & 4) {
+ temp64 += *(u32 *)buff;
+ buff += 4;
+ }
+ if (len & 2) {
+ temp64 += *(u16 *)buff;
+ buff += 2;
+ }
+ if (len & 1)
+ temp64 += *(u8 *)buff;
+ goto reduce_to32;
+ }
+ temp64 += *(u64 *)(buff + len - 8) << (8 - (len & 7)) * 8;
+ }
+
while (unlikely(len >= 64)) {
asm("addq 0*8(%[src]),%[res]\n\t"
"adcq 1*8(%[src]),%[res]\n\t"
@@ -82,43 +100,8 @@ __wsum csum_partial(const void *buff, int len, __wsum sum)
: "memory");
buff += 8;
}
- if (len & 7) {
-#ifdef CONFIG_DCACHE_WORD_ACCESS
- unsigned int shift = (8 - (len & 7)) * 8;
- unsigned long trail;
-
- trail = (load_unaligned_zeropad(buff) << shift) >> shift;
- asm("addq %[trail],%[res]\n\t"
- "adcq $0,%[res]"
- : [res] "+r" (temp64)
- : [trail] "r" (trail));
-#else
- if (len & 4) {
- asm("addq %[val],%[res]\n\t"
- "adcq $0,%[res]"
- : [res] "+r" (temp64)
- : [val] "r" ((u64)*(u32 *)buff)
- : "memory");
- buff += 4;
- }
- if (len & 2) {
- asm("addq %[val],%[res]\n\t"
- "adcq $0,%[res]"
- : [res] "+r" (temp64)
- : [val] "r" ((u64)*(u16 *)buff)
- : "memory");
- buff += 2;
- }
- if (len & 1) {
- asm("addq %[val],%[res]\n\t"
- "adcq $0,%[res]"
- : [res] "+r" (temp64)
- : [val] "r" ((u64)*(u8 *)buff)
- : "memory");
- }
-#endif
- }
+reduce_to32:
result = add32_with_carry(temp64 >> 32, temp64 & 0xffffffff);
return (__force __wsum)result;
}
--
2.17.1
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next reply other threads:[~2021-12-13 18:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-13 18:00 David Laight [this message]
2021-12-13 18:40 ` [PATCH] lib/x86: Optimise csum_partial of buffers that are not multiples of 8 bytes Alexander Duyck
2021-12-13 22:52 ` David Laight
2021-12-13 18:45 ` Eric Dumazet
2021-12-13 19:23 ` Alexander Duyck
2021-12-14 12:36 ` David Laight
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=f1cd1a19878248f09e2e7cffe88c8191@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