[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250407212310.0a934bad@pumpkin>
Date: Mon, 7 Apr 2025 21:23:10 +0100
From: David Laight <david.laight.linux@...il.com>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Kees Cook <kees@...nel.org>, linux-kernel@...r.kernel.org, Andrey
Konovalov <andreyknvl@...il.com>, Andy Shevchenko <andy@...nel.org>,
Catalin Marinas <catalin.marinas@....com>, Nathan Chancellor
<nathan@...nel.org>, Peter Collingbourne <pcc@...gle.com>, Vincenzo
Frascino <vincenzo.frascino@....com>, Will Deacon <will@...nel.org>
Subject: Re: [GIT PULL] string fixes for v6.15-rc1
On Sun, 6 Apr 2025 19:04:29 -0700
Linus Torvalds <torvalds@...ux-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
Powered by blists - more mailing lists