From: Matthew Wilcox <willy@infradead.org>
To: linux-kernel@vger.kernel.org
Cc: Matthew Wilcox <mawilcox@microsoft.com>
Subject: [PATCH 4/5] Add memfill()
Date: Wed, 8 Mar 2017 12:24:05 -0800 [thread overview]
Message-ID: <20170308202406.27419-5-willy@infradead.org> (raw)
In-Reply-To: <20170308202406.27419-1-willy@infradead.org>
From: Matthew Wilcox <mawilcox@microsoft.com>
Similar to Lars Wirzenius' memfill(), this version has optimisations for
source sizes of 1, 2, 4 (and 8 on 64 bit architectures).
Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
---
include/linux/string.h | 3 +++
lib/string.c | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/include/linux/string.h b/include/linux/string.h
index 642a82290a25..f340e6fb309f 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -112,6 +112,9 @@ static inline void *memset_l(unsigned long *p, unsigned long v,
#endif
}
#endif
+#ifndef __HAVE_ARCH_MEMFILL
+extern void memfill(void *, __kernel_size_t, void *, __kernel_size_t);
+#endif
#ifndef __HAVE_ARCH_MEMCPY
extern void * memcpy(void *,const void *,__kernel_size_t);
#endif
diff --git a/lib/string.c b/lib/string.c
index 85628c8d3abd..d22711e6490a 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -741,6 +741,47 @@ EXPORT_SYMBOL(memset64);
#endif
#endif
+#ifndef __HAVE_ARCH_MEMFILL
+/**
+ * memfill() - Fill a region of memory with copies of another region
+ * @dst: Destination address
+ * @dsz: Size of destination area
+ * @src: Source address
+ * @ssz: Size of source area
+ */
+void memfill(void *dst, size_t dsz, void *src, size_t ssz)
+{
+ if (ssz == 1) {
+ memset(dst, *(unsigned char *)src, dsz);
+ return;
+ } else if (ssz == sizeof(short)) {
+ uint32_t v = *(unsigned short *)src;
+ v |= (v << 16);
+
+ memset32(dst, v, dsz / sizeof(uint32_t));
+ dst = (uint32_t *)dst + dsz / sizeof(uint32_t);
+ dsz %= sizeof(uint32_t);
+ } else if (ssz == sizeof(int)) {
+ memset32(dst, *(uint32_t *)src, dsz / sizeof(uint32_t));
+ dst = (uint32_t *)dst + dsz / sizeof(uint32_t);
+ dsz %= sizeof(int);
+ } else if (ssz == sizeof(long)) {
+ memset_l(dst, *(long *)src, dsz / sizeof(long));
+ dst = (long *)dst + dsz / sizeof(long);
+ dsz %= sizeof(long);
+ } else {
+ while (dsz >= ssz) {
+ memcpy(dst, src, ssz);
+ dsz -= ssz;
+ dst += ssz;
+ }
+ }
+ if (dsz)
+ memcpy(dst, src, dsz);
+}
+EXPORT_SYMBOL(memfill);
+#endif
+
#ifndef __HAVE_ARCH_MEMCPY
/**
* memcpy - Copy one area of memory to another
--
2.11.0
next prev parent reply other threads:[~2017-03-08 21:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-08 20:24 [RFC 0/5] memset_l and memfill Matthew Wilcox
2017-03-08 20:24 ` [PATCH 1/5] Add memset_l(), memset32() and memset64() Matthew Wilcox
2017-03-08 20:24 ` [PATCH 2/5] zram: Convert to using memset_l() Matthew Wilcox
2017-03-08 20:24 ` [PATCH 3/5] sym53c8xx_2: Convert to use memset32() Matthew Wilcox
2017-03-08 20:24 ` Matthew Wilcox [this message]
2017-03-08 20:24 ` [PATCH 5/5] Hacky testsuite for memfill() and memset_l() Matthew Wilcox
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=20170308202406.27419-5-willy@infradead.org \
--to=willy@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mawilcox@microsoft.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®