[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Lua 5.3 alignment issue
- From: Gé Weijers <ge@...>
- Date: Wed, 24 Jul 2019 14:52:31 -0700
I ran into an issue interfacing code that uses multimedia extensions
(Intel SSE2) with Lua 5.3 on 64-bit Linux and macOS.
In short: some instructions loading/storing 128-bit multimedia
registers expect 16-byte alignment. malloc will provide memory aligned
to work with that, and the C compiler will align the non-portable
__m128i type at at 16-byte boundary in structures.
Trying to use these SSE2 instructions with Lua is a bit difficult,
because lua_newuserdata does not return a pointer with the same
alignment constraints as malloc, I've found that the pointer returned
is consistently aligned on an 8-byte boundary, but not on a 16-byte
Digging into the Lua implementation I found that defining
LUAI_USER_ALIGNMENT_T can override the standard alignment of the
pointer returned by lua_newuserdata. Is this 'officially' supported?
(I know this introduces memory overhead on all userdata structures).
It's not overly difficult to write code that works with an unmodified
Lua interpreter, but shouldn't lua_newuserdata return pointers that
can be used in the same way as 'malloc' generated pointers?