[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Native Complex numbers for LuaJIT-2 [was Re: Benchmark shootout shows LuaJIT 2.0]
- From: Leo Razoumov <slonik.az@...>
- Date: Mon, 2 Nov 2009 17:50:37 -0500
On 2009-11-02, Mike Pall <email@example.com> wrote:
> Leo Razoumov wrote:
> > Well, the next step in functions like __add(z1,z2) or __mul(z1,z2)
> > will be to check that the second argument is indeed of the type
> > "complex". Typically it is done with luaL_checkudata which (1) pulls
> > object's metatable onto the stack (2) looks up the required metatable
> > in the REGISTRY with lua_getfield(L, LUA_REGISTRYINDEX, tname) by its
> > name string and (3) compares two metatables. It is a lot of overhead
> > for +-/* of complex numbers. I do not see how LuaJIT can help here,
> > for this overhead happens on the C-side of things outside of LuaJIT
> > control. Is a good solution possible?
> You are still thinking too much interpreter-centric. *None* of
> that involves calls to the C-side on the JIT side.
Well, I am new to JIT concept and still learning.
> The trace compiler records the _functionality_ of each bytecode,
> not the actual C code involved. In effect it does a complete
> simulation of every bytecode and all the associated metamethod
> stuff, before it's even run.
> So here's what happens, if the trace recorder sees the BC_ADD:
> - First it checks the runtime type of the two operands: since
> these are userdata it resolves their metamethods, recording
> every lookup on the way.
> - Then it records the call to the resolved metamethod: it sees
> that it's one of the special internal fast functions and runs
> the associated recording handler.
> - The recording handler checks that the arguments it got are
> indeed of the right userdata type (recording the functionality
> of the checks involved).
Does it mean that if I use lua_getfield(L, LUA_REGISTRYINDEX, tname)
in my implementation of __add(z1,z2) the hash lookup will be cached
for further invocation??
In general, how effective is LuaJIT-2 in minimizing run-time type
identification overhead? Is there LuaJIT-way different from
Are there any common Lua idioms *not* recommended when writing Lua
code and C-bindings targeting LuaJIT?
Thanks for the great work!!