From: David Laight <david.laight.linux@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>, Borislav Petkov <bp@alien8.de>,
Usama Arif <usama.arif@linux.dev>,
dave.hansen@linux.intel.com, dsterba@suse.com,
linux-kernel@vger.kernel.org, mingo@redhat.com, terrelln@fb.com,
tglx@kernel.org, x86@kernel.org, kas@kernel.org,
hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev,
kernel-team@meta.com
Subject: Re: [PATCH v3 2/2] x86/lib: Use REP MOVSB for large memcpy() on ERMS CPUs without FSRM
Date: Sun, 15 Nov 2026 12:42:05 +0000 [thread overview]
Message-ID: <20261115124205.076cdd63@pumpkin> (raw)
In-Reply-To: <CAHk-=wj0MtJpBbwNr=NGh4kFPM__Wf9Hq+LZ1Qv1Yv1SCpjaLQ@mail.gmail.com>
On Sat, 14 Nov 2026 16:56:16 -0800
Linus Torvalds <torvalds@linux-foundation.org> wrote:
> On Sat, 14 Nov 2026 at 14:45, David Laight <david.laight.linux@gmail.com> 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
next prev parent reply other threads:[~2026-11-15 12:42 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 13:20 [PATCH v3 0/2] x86/lib: Use REP MOVSB for large memcpy() on ERMS CPUs without FSRM Usama Arif
2026-11-11 13:20 ` [PATCH v3 1/2] x86/lib: Keep the scalar memcpy() count in RCX Usama Arif
2026-11-11 13:20 ` [PATCH v3 2/2] x86/lib: Use REP MOVSB for large memcpy() on ERMS CPUs without FSRM Usama Arif
2026-11-11 13:56 ` Peter Zijlstra
2026-11-11 23:46 ` Borislav Petkov
2026-11-12 9:37 ` David Laight
2026-11-13 14:31 ` Usama Arif
2026-11-13 14:11 ` Usama Arif
2026-11-13 16:03 ` David Laight
2026-11-13 17:34 ` Linus Torvalds
2026-11-13 18:36 ` H. Peter Anvin
2026-11-13 23:37 ` Borislav Petkov
2026-11-14 2:21 ` H. Peter Anvin
2026-11-14 22:45 ` David Laight
2026-11-15 0:56 ` Linus Torvalds
2026-11-15 12:42 ` David Laight [this message]
2026-11-13 19:42 ` David Laight
2026-11-11 18:19 ` [PATCH v3 0/2] " Kiryl Shutsemau
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=20261115124205.076cdd63@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=dsterba@suse.com \
--cc=hannes@cmpxchg.org \
--cc=hpa@zytor.com \
--cc=kas@kernel.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=riel@surriel.com \
--cc=shakeel.butt@linux.dev \
--cc=terrelln@fb.com \
--cc=tglx@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=usama.arif@linux.dev \
--cc=x86@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.