lua-users home
lua-l archive

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


On 2009-11-02, Mike Pall <mikelu-0911@mike.de> wrote:
> 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.
>
> [..snip..]
>  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

Mike,
I would like to give it a try. I implemented complex numbers as
userdata for the Lua interpreter. But userdata is allocated on the
heap and, thus, is too slow for tight loops commonly found in
numerics.
Bringing down box/unbox overhead could save the day.

Also I am a bit worried about function dispatch. Adding two doubles is
a native Lua opcode and it does not go through the trouble of
metamethods. Using __add, __mul, etc metamethods dispatch for complex
numbers is slow. Could it be avoided?

--Leo--