public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
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 0/2] Optimize memchr()
Date: Sun, 10 Jul 2022 22:28:20 +0800	[thread overview]
Message-ID: <20220710142822.52539-1-arthurchang09@gmail.com> (raw)

*** 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


             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 Yu-Jen Chang [this message]
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

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-1-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox