lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Leo Razoumov wrote:
> How difficult it is to add native Complex numbers to LuaJIT (C-99 compatible)?
> By native I mean as little overhead over lua_Number as possible.

Without causing undue trouble to the VM, they would have to be
boxed (in a userdata or an even smaller container). And one would
have to add a special kind of array type to store them, because
storing boxed values in a table is just too much overhead for
numerical programs.

That would be pretty slow in the interpreter (one allocation for
every arithmetic result). But the JIT compiler could do transparent
boxing/unboxing to reduce the overhead in many (but not all) cases.
To be really effective this also needs allocation sinking, but
that's planned anyway.

If you want to embark on that adventure yourself, I suggest to
wait until LJ2 has gained support for both allocation sinking and
arrays holding low-level data types (a Complex would just be a
"struct { double re, im; }").

--Mike