From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: mjguzik@gmail.com, linux-kernel@vger.kernel.org,
mingo@redhat.com, x86@kernel.org,
"Peter Zijlstra (Intel)" <peterz@infradead.org>
Subject: Re: [RFC PATCH] x86: prevent gcc from emitting rep movsq/stosq for inlined ops
Date: Wed, 2 Apr 2025 19:40:01 +0100 [thread overview]
Message-ID: <e0021746-d43c-4c45-83b6-bcf3982b2548@citrix.com> (raw)
In-Reply-To: <CAHk-=wg4syfXPBgQhq50ePOnB=zP9Jk1U+GmjXWmDMwcQ7X7WA@mail.gmail.com>
On 02/04/2025 7:29 pm, Linus Torvalds wrote:
> On Wed, 2 Apr 2025 at 11:17, Andrew Cooper <andrew.cooper3@citrix.com> wrote:
>> Taking a leaf out of the repoline book, the ideal library call(s) would be:
>>
>> CALL __x86_thunk_rep_{mov,stos}sb
>>
>> using the REP ABI (parameters in %rcx/%rdi/etc), rather than the SYSV ABI.
> Yes. That's basically what 'rep_movs_alternative' does so that we can
> basically do a
>
> ALTERNATIVE("rep movsb",
> "call rep_movs_alternative",
> ALT_NOT(X86_FEATURE_FSRM))
>
> but we only do this for user space copies exactly because we don't
> have a good way to do it for compiler-generated ones.
>
> If gcc just did an out-of-line call, but used the 'rep movs' "calling
> convention", we would be able to basically do the rewriting
> dynamically, replacing the call with an inlined "rep movsb" where
> appropriate.
You still want the compiler to be able to do a first-pass optimisation
over __builtin_mem*(), for elimination/merging/etc, but if it could stop
half way through what it currently does and just emit the library call,
that would be excellent.
~Andrew
next prev parent reply other threads:[~2025-04-02 18:40 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-02 13:42 [RFC PATCH] x86: prevent gcc from emitting rep movsq/stosq for inlined ops Mateusz Guzik
2025-04-02 16:21 ` Linus Torvalds
2025-04-02 16:27 ` Mateusz Guzik
2025-04-02 18:17 ` Andrew Cooper
2025-04-02 18:22 ` Peter Zijlstra
2025-04-02 18:29 ` Linus Torvalds
2025-04-02 18:40 ` Andrew Cooper [this message]
2025-04-02 18:56 ` Linus Torvalds
2025-04-02 23:39 ` Mateusz Guzik
2025-04-13 10:27 ` Mateusz Guzik
2025-04-13 18:20 ` David Laight
2025-04-13 18:58 ` Mateusz Guzik
2025-04-02 22:29 ` David Laight
2025-04-02 23:15 ` Mateusz Guzik
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=e0021746-d43c-4c45-83b6-bcf3982b2548@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mjguzik@gmail.com \
--cc=peterz@infradead.org \
--cc=torvalds@linux-foundation.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox