From: Yu-Jen Chang <arthurchang09@gmail.com>
To: andy@kernel.org, akinobu.mita@gmail.com
Cc: jserv@ccns.ncku.edu.tw, linux-kernel@vger.kernel.org,
Yu-Jen Chang <arthurchang09@gmail.com>
Subject: [PATCH 1/2] lib/string.c: Add a macro for memchr_inv()
Date: Sun, 10 Jul 2022 22:28:21 +0800 [thread overview]
Message-ID: <20220710142822.52539-2-arthurchang09@gmail.com> (raw)
In-Reply-To: <20220710142822.52539-1-arthurchang09@gmail.com>
We add a macro MEMCHR_MASK_GEN() so that both memchr_inv()
and memchr() can use it to generate a 8 bytes mask.
Signed-off-by: Yu-Jen Chang <arthurchang09@gmail.com>
Signed-off-by: Ching-Chun (Jim) Huang <jserv@ccns.ncku.edu.tw>
---
lib/string.c | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/lib/string.c b/lib/string.c
index 485777c9d..80469e6c3 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -879,6 +879,29 @@ char *strnstr(const char *s1, const char *s2, size_t len)
EXPORT_SYMBOL(strnstr);
#endif
+#if defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64
+
+#define MEMCHR_MASK_GEN(mask) (mask *= 0x0101010101010101ULL)
+
+#elif defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER)
+
+#define MEMCHR_MASK_GEN(mask) \
+ do { \
+ mask *= 0x01010101; \
+ mask |= mask << 32; \
+ } while (0)
+
+#else
+
+#define MEMCHR_MASK_GEN(mask) \
+ do { \
+ mask |= mask << 8; \
+ mask |= mask << 16; \
+ mask |= mask << 32; \
+ } while (0)
+
+#endif
+
#ifndef __HAVE_ARCH_MEMCHR
/**
* memchr - Find a character in an area of memory.
@@ -932,16 +955,7 @@ void *memchr_inv(const void *start, int c, size_t bytes)
return check_bytes8(start, value, bytes);
value64 = value;
-#if defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64
- value64 *= 0x0101010101010101ULL;
-#elif defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER)
- value64 *= 0x01010101;
- value64 |= value64 << 32;
-#else
- value64 |= value64 << 8;
- value64 |= value64 << 16;
- value64 |= value64 << 32;
-#endif
+ MEMCHR_MASK_GEN(value64);
prefix = (unsigned long)start % 8;
if (prefix) {
--
2.25.1
next prev parent reply other threads:[~2022-07-10 14:28 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-10 14:28 [PATCH 0/2] Optimize memchr() Yu-Jen Chang
2022-07-10 14:28 ` Yu-Jen Chang [this message]
2022-07-10 14:28 ` [PATCH 2/2] lib/string.c: " Yu-Jen Chang
2022-07-10 15:16 ` Joe Perches
2022-07-11 14:50 ` Yu-Jen Chang
2022-07-10 16:58 ` kernel test robot
2022-07-10 20:01 ` Andrey Semashev
2022-07-11 14:52 ` Yu-Jen Chang
2022-07-11 15:00 ` Andrey Semashev
2022-07-11 15:03 ` Andy Shevchenko
2022-07-12 14:58 ` Yu-Jen Chang
2022-07-12 15:08 ` Andy Shevchenko
2022-07-13 9:39 ` David Laight
2022-07-13 9:49 ` Andrey Semashev
2022-07-13 10:02 ` Andrey Semashev
2022-07-13 10:24 ` David Laight
2022-07-22 16:08 ` Yu-Jen Chang
[not found] ` <CAHp75Vfy6wYqzT-T9aEjVEAQCZ_k=0qN8S8OwG3knbrC-oOkMQ@mail.gmail.com>
2022-07-29 15:42 ` Yu-Jen Chang
2022-07-13 9:57 ` Andrey Semashev
2022-07-21 5:06 ` kernel test robot
2022-08-12 19:06 ` [PATCH 0/2] " Pavel Machek
2022-08-15 10:59 ` 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=20220710142822.52539-2-arthurchang09@gmail.com \
--to=arthurchang09@gmail.com \
--cc=akinobu.mita@gmail.com \
--cc=andy@kernel.org \
--cc=jserv@ccns.ncku.edu.tw \
--cc=linux-kernel@vger.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 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.