From: Andrey Semashev <andrey.semashev@gmail.com>
To: David Laight <David.Laight@ACULAB.COM>,
'Yu-Jen Chang' <arthurchang09@gmail.com>
Cc: "andy@kernel.org" <andy@kernel.org>,
"akinobu.mita@gmail.com" <akinobu.mita@gmail.com>,
Ching-Chun Huang <jserv@ccns.ncku.edu.tw>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] lib/string.c: Optimize memchr()
Date: Wed, 13 Jul 2022 12:49:58 +0300 [thread overview]
Message-ID: <5d14cf64-46b7-dc37-bbb8-dd6be82d06af@gmail.com> (raw)
In-Reply-To: <49a8be9269ee47de9fc2d0d7f09eb0b1@AcuMS.aculab.com>
On 7/13/22 12:39, David Laight wrote:
> From: Yu-Jen Chang
>> Sent: 12 July 2022 15:59
> ...
>>> I think you're missing the point. Loads at unaligned addresses may not
>>> be allowed by hardware using conventional load instructions or may be
>>> inefficient. Given that this memchr implementation is used as a fallback
>>> when no hardware-specific version is available, you should be
>>> conservative wrt. hardware capabilities and behavior. You should
>>> probably have a pre-alignment loop.
>>
>> Got it. I add pre-alignment loop. It aligns the address to 8 or 4bytes.
>
> That should be predicated on !HAS_EFFICIENT_UNALIGNED_ACCESS.
>
> ...
>> for (; p <= end - 8; p += 8) {
>> val = *(u64*)p ^ mask;
>> if ((val + 0xfefefefefefefeffull)
>> & (~val & 0x8080808080808080ull))
>> break;
>
> I would add a couple of comments, like:
> // Convert to check for zero byte.
> // Standard check for a zero byte in a word.
> (But not the big 4 line explanation you had.
>
> It is also worth looking at how that code compiles
> on 32bit arch that don't have a carry flag.
> That is everything based on MIPS, including riscv.
It may be worth looking at how glibc does it:
https://sourceware.org/git/?p=glibc.git;a=blob;f=string/memchr.c;h=422bcd0cd646ea46711a57fa3cbdb8a3329fc302;hb=refs/heads/release/2.35/master#l46
They do use 32-bit words on 32-bit targets and 64-bit on 64-bit ones. I
think memchr in the kernel should follow this.
next prev parent reply other threads:[~2022-07-13 9:50 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 ` [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 [this message]
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=5d14cf64-46b7-dc37-bbb8-dd6be82d06af@gmail.com \
--to=andrey.semashev@gmail.com \
--cc=David.Laight@ACULAB.COM \
--cc=akinobu.mita@gmail.com \
--cc=andy@kernel.org \
--cc=arthurchang09@gmail.com \
--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