From: Heiko Carstens <hca@linux.ibm.com>
To: Alexander Gordeev <agordeev@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Juergen Christ <jchrist@linux.ibm.com>
Cc: linux-s390@vger.kernel.org
Subject: [PATCH v3 8/9] s390/memmove: Optimize backward copy case
Date: Tue, 9 Jun 2026 12:33:42 +0200 [thread overview]
Message-ID: <20260609103343.107325-9-hca@linux.ibm.com> (raw)
In-Reply-To: <20260609103343.107325-1-hca@linux.ibm.com>
memmove() copies byte wise for the backward copy case, when the mvc
instruction cannot be used. This is quite slow, but can be optimized
with the mvcrl instruction, which is available since z15.
Some numbers (measured on a shared z16 LPAR) show that the new
implementation is nearly always faster, except for the non realistic
one and two byte cases:
size old new
1 2ns 3ns
2 4ns 5ns
4 5ns 5ns
8 8ns 5ns
16 12ns 6ns
32 8ns 7ns
64 15ns 7ns
128 31ns 9ns
256 64ns 10ns
512 129ns 18ns
1024 250ns 19ns
2048 498ns 38ns
Reviewed-by: Juergen Christ <jchrist@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/lib/string.c | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/arch/s390/lib/string.c b/arch/s390/lib/string.c
index 2f9e9e886016..e93e1acd2ade 100644
--- a/arch/s390/lib/string.c
+++ b/arch/s390/lib/string.c
@@ -15,6 +15,7 @@
#include <linux/types.h>
#include <linux/string.h>
#include <linux/export.h>
+#include <asm/facility.h>
#include <asm/asm.h>
#define SYMBOL_FUNCTION_ALIAS(alias, name) \
@@ -51,8 +52,29 @@ noinstr void *__memmove(void *dest, const void *src, size_t n)
: [d] "a" (d), [s] "a" (s), [n] "a" (n - 1)
: "memory");
}
+ return dest;
+ }
+ /* Backward copy */
+ if (test_facility(61)) {
+ /* Use mvcrl instruction if available */
+ while (n >= 256) {
+ asm volatile(
+ " lghi %%r0,255\n"
+ " .insn sse,0xe50a00000000,%[d],%[s]\n"
+ : [d] "=Q" (*(d + n - 256))
+ : [s] "Q" (*(s + n - 256))
+ : "0", "memory");
+ n -= 256;
+ }
+ if (n) {
+ asm volatile(
+ " lgr %%r0,%[n]\n"
+ " .insn sse,0xe50a00000000,%[d],%[s]\n"
+ : [d] "=Q" (*d)
+ : [s] "Q" (*s), [n] "d" (n - 1)
+ : "0", "memory");
+ }
} else {
- /* Backward copy */
while (n--)
d[n] = s[n];
}
--
2.53.0
next prev parent reply other threads:[~2026-06-09 10:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 10:33 [PATCH v3 0/9] s390/string: Convert various functions to C Heiko Carstens
2026-06-09 10:33 ` [PATCH v3 1/9] s390/purgatory: Enforce z10 minimum architecture level Heiko Carstens
2026-06-09 10:33 ` [PATCH v3 2/9] s390: Add .noinstr.text to boot and purgatory linker scripts Heiko Carstens
2026-06-09 10:33 ` [PATCH v3 3/9] s390/string: Add -ffreestanding compile option to string.o Heiko Carstens
2026-06-09 12:23 ` Juergen Christ
2026-06-09 13:39 ` Heiko Carstens
2026-06-09 10:33 ` [PATCH v3 4/9] s390/string: Convert memmove() to C Heiko Carstens
2026-06-09 10:33 ` [PATCH v3 5/9] s390/string: Convert memset() " Heiko Carstens
2026-06-09 10:33 ` [PATCH v3 6/9] s390/string: Convert memcpy() " Heiko Carstens
2026-06-09 10:33 ` [PATCH v3 7/9] s390/string: Convert memset(16|32|64)() " Heiko Carstens
2026-06-09 10:33 ` Heiko Carstens [this message]
2026-06-09 10:33 ` [PATCH v3 9/9] s390/tishift: Convert __ashlti3(), __ashrti3(), __lshrti3() " Heiko Carstens
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=20260609103343.107325-9-hca@linux.ibm.com \
--to=hca@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=jchrist@linux.ibm.com \
--cc=linux-s390@vger.kernel.org \
--cc=svens@linux.ibm.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.