Re: FFI + JIT alignment limit

  • From: Mike Pall <mike-1301@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Fri, 18 Jan 2013 01:35:34 +0100

Simon Cooke wrote:
> According to the manual JIT compilation fails currently for:
> 
>   * Allocations of C types with a size > 128 bytes or an alignment > 8 bytes.
> 
> Is the alignment constraint a fundamental limitation of the
> implementation, or would it be possible to extend JIT support to
> include 16-byte alignment?

The current memory allocator only guarantees 8 byte alignment.
That necessitates some contorted code for aligning cdata types and
their headers to make the GC happy (compare lj_cdata_newv with the
inlined lj_cdata_new). I haven't added the messy code required to
do this from JIT-compiled code. It'll be all much simpler with the
new GC, which offers 16 byte alignment right away.

A temporary workaround for you would be to get a chunk of memory
plus 16 extra bytes, compute an aligned pointer to it and then use
that for passing data to the library.

BTW: Passing or returning structs by value isn't compiled, either.

--Mike

Other related posts: