From: David Laight <david.laight.linux@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Kees Cook <kees@kernel.org>,
linux-kernel@vger.kernel.org,
Andrey Konovalov <andreyknvl@gmail.com>,
Andy Shevchenko <andy@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Nathan Chancellor <nathan@kernel.org>,
Peter Collingbourne <pcc@google.com>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
Will Deacon <will@kernel.org>
Subject: Re: [GIT PULL] string fixes for v6.15-rc1
Date: Mon, 7 Apr 2025 21:23:10 +0100 [thread overview]
Message-ID: <20250407212310.0a934bad@pumpkin> (raw)
In-Reply-To: <CAHk-=wijG2dSOOFr8CCYygwxZQxdTUj73rfB8=tyZP-3G-8-og@mail.gmail.com>
On Sun, 6 Apr 2025 19:04:29 -0700
Linus Torvalds <torvalds@linux-foundation.org> wrote:
...
> For something like wcslen() the answer is "DON'T DO THIS". Because
> there is absolutely zero upside to trying to recognize this pattern,
> and there is real downside.
gcc also has a nasty habit of converting:
for (i = 0; i < len; i++)
dst[i] = src[i];
into a call to memcpy().
If I wanted a memcpy() call I'd write one - so will most people.
But if 'len' is very small (may even known to be less than, say, 4)
you really want the loop - which is why it was written.
I've even seen (not gcc) it converted to a 'rep movsw' 'rep movsb'
pair at a time when a P4 might have been a likely target cpu.
The 0 to 3 byte 'rep movsb' had a setup cost of IIRC 150 clocks.
David
prev parent reply other threads:[~2025-04-07 20:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-06 17:54 [GIT PULL] string fixes for v6.15-rc1 Kees Cook
2025-04-06 19:04 ` Linus Torvalds
2025-04-06 19:31 ` Linus Torvalds
2025-04-07 1:32 ` Kees Cook
2025-04-07 2:04 ` Linus Torvalds
2025-04-07 17:37 ` Nathan Chancellor
2025-04-07 19:02 ` Linus Torvalds
2025-04-07 19:25 ` Nathan Chancellor
2025-04-07 20:25 ` Linus Torvalds
2025-04-07 21:01 ` Nathan Chancellor
2025-04-07 20:23 ` David Laight [this message]
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=20250407212310.0a934bad@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=andreyknvl@gmail.com \
--cc=andy@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=pcc@google.com \
--cc=torvalds@linux-foundation.org \
--cc=vincenzo.frascino@arm.com \
--cc=will@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.