[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250221214501.11b76aa8@pumpkin>
Date: Fri, 21 Feb 2025 21:45:01 +0000
From: David Laight <david.laight.linux@...il.com>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Jan Engelhardt <ej@...i.de>, "H. Peter Anvin" <hpa@...or.com>, Greg KH
<gregkh@...uxfoundation.org>, Boqun Feng <boqun.feng@...il.com>, Miguel
Ojeda <miguel.ojeda.sandonis@...il.com>, Christoph Hellwig
<hch@...radead.org>, rust-for-linux <rust-for-linux@...r.kernel.org>, David
Airlie <airlied@...il.com>, linux-kernel@...r.kernel.org,
ksummit@...ts.linux.dev
Subject: Re: C aggregate passing (Rust kernel policy)
On Fri, 21 Feb 2025 11:12:27 -0800
Linus Torvalds <torvalds@...ux-foundation.org> wrote:
> On Fri, 21 Feb 2025 at 10:34, David Laight <david.laight.linux@...il.com> wrote:
> >
> > As Linus said, most modern ABI pass short structures in one or two registers
> > (or stack slots).
> > But aggregate returns are always done by passing a hidden pointer argument.
> >
> > It is annoying that double-sized integers (u64 on 32bit and u128 on 64bit)
> > are returned in a register pair - but similar sized structures have to be
> > returned by value.
>
> No, they really don't. At least not on x86 and arm64 with our ABI.
> Two-register structures get returned in registers too.
>
> Try something like this:
>
> struct a {
> unsigned long val1, val2;
> } function(void)
> { return (struct a) { 5, 100 }; }
>
> and you'll see both gcc and clang generate
>
> movl $5, %eax
> movl $100, %edx
> retq
>
> (and you'll similar code on other architectures).
Humbug, I'm sure it didn't do that the last time I tried it.
David
>
> But it really is just that the two-register case is special.
> Immediately when it grows past that size then yes, it ends up being
> returned through indirect memory.
>
> Linus
Powered by blists - more mailing lists