[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220710142822.52539-2-arthurchang09@gmail.com>
Date: Sun, 10 Jul 2022 22:28:21 +0800
From: Yu-Jen Chang <arthurchang09@...il.com>
To: andy@...nel.org, akinobu.mita@...il.com
Cc: jserv@...s.ncku.edu.tw, linux-kernel@...r.kernel.org,
Yu-Jen Chang <arthurchang09@...il.com>
Subject: [PATCH 1/2] lib/string.c: Add a macro for memchr_inv()
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@...il.com>
Signed-off-by: Ching-Chun (Jim) Huang <jserv@...s.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
Powered by blists - more mailing lists