Re: [PATCH] Struct-by-value support for x86-64 and ARM64

Stas Boukarev <[email protected]>
Newsgroups gmane.lisp.steel-bank.devel
Message-ID <CAF63=13VgYcYUfBas1SZoXNFp06hra3wk0EYFOy3VDqn66MuDA@mail.gmail.com>
I merged this, but haven't reviewed it much. (I had to change it to
compile on unsupported targets).
And the callback-struct-return-large test fails on x86-64.
How hard would it be to add win32 support during this release cycle?


On Wed, Jan 14, 2026 at 2:58 AM Jesse Bouwman via Sbcl-devel
<[email protected]> wrote:
>
> Hi,
>
> here is a patch that adds support for passing and returning structs by value on unix-like x86-64 and ARM64.
>
> Briefly, src/code/c-call.lisp dispatches to architecture-specific struct classifiers; classifiers determine whether a struct should be passed in registers or memory, per ABI rules: For x86-64, structs less than 16 bytes are classified into "eightbytes" that map to int or SSE register classes. Larger structs are passed via hidden pointer in RDI, and returned in RAX. ARM64 supports HFA: structs of up to 4 same-type floats are passed/returned in floating-point registers. Non-HFA structs less than 16 bytes use x0/x1; larger structs use a hidden pointer in x8. The alien-funcall IR1 transform handles both small struct returns (unpacking register to heap) and large struct returns (hidden pointer as synthetic first argument).
>
> There are no changes to the FFI interface.
>
> Other notes:
>
> Implementation owes a lot to the work done a year ago by Rongcui Dong and reviewers, documented on the launchpad thread at https://bugs.launchpad.net/sbcl/+bug/313202
>
> What I would deem pretty thorough testing is included: variously sized structs, nested structs, structs containing arrays, unions, etc. I've been debugging this with a binding to libclang, this has shaken out some serioous bugs, and I think it's now usable. I would welcome feedback about any aspects, especially relating to bad assumptions, missing functionality, or non-sbcl-idiomatic code.
>
> The branch is at: https://github.com/jbouwman/sbcl/tree/struct-by-value-final
>
> As the code is a result of bouncing between arm/darwin and x86/linux to try to get reasonably clean abstractions, it was squashed into a few big commits, but can be retroactively broken up in order to get something a little more bisectable for future debugging ergonomics.
>
> Windows is blocked by a non-SysV ABI which is not familiar to me, but looks pretty easy. Famous last words!
>
> Cheers,
> Jesse
>
>
> _______________________________________________
> Sbcl-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sbcl-devel


_______________________________________________
Sbcl-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sbcl-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.