Why align all pinned array payloads on 16 bytes?

Sven Panne svenpanne at gmail.com
Wed Oct 17 07:28:58 UTC 2018

Am Di., 16. Okt. 2018 um 23:18 Uhr schrieb Simon Marlow <marlowsd at gmail.com

> I vaguely recall that this was because 16 byte alignment is the minimum
> you need for certain foreign types, and it's what malloc() does.  Perhaps
> check the FFI spec and the guarantees that mallocForeignPtrBytes and
> friends provide?

mallocForeignPtrBytes is defined in terms of malloc (
which in turn has the following guarantee (

   "... All storage allocated by functions that allocate based on a size in
bytes must be sufficiently aligned for any of the basic foreign types that
fits into the newly allocated storage. ..."

The largest basic foreign types are Word64/Double and probably
Ptr/FunPtr/StablePtr (
so per spec you need at least an 8-byte alignement. But in an SSE-world I
would be *very* reluctant to use an alignment less strict than 16 bytes,
otherwise people will probably hate you... :-]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20181017/d2512424/attachment.html>

More information about the ghc-devs mailing list