linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Optimize memchr()
@ 2022-07-10 14:28 Yu-Jen Chang
  2022-07-10 14:28 ` [PATCH 1/2] lib/string.c: Add a macro for memchr_inv() Yu-Jen Chang
                   ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Yu-Jen Chang @ 2022-07-10 14:28 UTC (permalink / raw)
  To: andy, akinobu.mita; +Cc: jserv, linux-kernel, Yu-Jen Chang

*** BLURB HERE ***
This patche series optimized "memchr()" and add a macro for 
"memchr_inv()" so that both funtions can use it to generate bit mask.

The original implementaion of "memchr()" is based on byte-wise comparison,
which do not fully use 64-bit or 32-bit register in CPU. We implement a
word-wise comparison so that at least 4 bytes can be compared at the same
time. The optimized "memchr()" is nearly 4x faster than the original one
for long strings. In Linux Kernel, we find that the length of the string
searched by "memchr()" is up to 512 bytes in drivers/misc/lkdtm/heap.c.
In our test, the optimized version is about 20% faster if the target
character is at the end of the string when going through a 512-byte
string.

We recompile the 5.18 kernel with optimized "memchr()" in 32-bit and
64-bit. They run correctly.

Yu-Jen Chang (2):
  lib/string.c: Add a macro for memchr_inv()
  lib/string.c: Optimize memchr()

 lib/string.c | 62 ++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 45 insertions(+), 17 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2022-08-15 10:59 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-10 14:28 [PATCH 0/2] Optimize memchr() Yu-Jen Chang
2022-07-10 14:28 ` [PATCH 1/2] lib/string.c: Add a macro for memchr_inv() Yu-Jen Chang
2022-07-10 14:28 ` [PATCH 2/2] lib/string.c: Optimize memchr() 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).