Re: [PATCH v3 2/2] x86/lib: Use REP MOVSB for large memcpy() on ERMS CPUs without FSRM
From: David Laight
Date: Sun Nov 15 2026 - 07:42:18 EST
On Sat, 14 Nov 2026 16:56:16 -0800
Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
> On Sat, 14 Nov 2026 at 14:45, David Laight <david.laight.linux@xxxxxxxxx> wrote:
> >
> > Otherwise you'll need to spill to stack for even a simple byte copy loop.
>
> I think the optimization should be for the inline case.
>
> Once you do a call, having a couple of push/pop instructions in the
> target is a complete no-op.
You certainly don't want to have a lot of available registers.
But even with a call I'd have thought a push/pop would be noticeable
for short copies.
If you need extra registers to unroll a longer copy loop, then I agree
that the push/pop will be noise.
> But having extra registers free could help at the call-site,
There isn't much you can put at the call site instead of a 5 byte call.
> and if the 'rep movs' is inlined you only modify rcx/rsi/rdi.
> I think the calling convention should mirror that.
I think I'd go for rax/rdx being scratch and the final values
of rcx/tsi/rdi being undefined.
What you don't want to do is have to preserve the destination address.
That is always better done at the call site.
I'd guess the compiler option could have a option to say whether ax/dx
are scratch or not.
I'm not sure whether the loop I posted runs as fast as I hoped.
It might need interleaving to get a read and write executed on the
same clock - but the AVX xor loop didn't need it.
All needs some real experiments.
David
>
> Linus