lua-users home
lua-l archive

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


On Sun, Feb 13, 2011 at 10:18, Mike Pall <mikelu-1102@mike.de> wrote:
> Leo Razoumov wrote:
>> > In Lua we can do the same: specialize the Lua code at runtime for
>> > the number of dimensions, memoize the code in a table and dispatch
>> > based on the dimension. I.e. string.format + loadstring +
>> > memoization table.
>>
>> It would be great if this specialize/memoize/dispatch optimization for
>> small number of dimensions could make it into LuaJIT-2.0 release.
>
> Umm, you misunderstood: this out of the scope of what a compiler
> automatically can or should do for you. C++ compilers don't write
> templates for you, either. :-) It's pretty easy to do it yourself
> in Lua, far easier than writing C++ templates.
>

Sorry for my misunderstanding but I thought that LuaJIT-2 can unroll
fixed length loops like for i=1,3 do ... end.
It is a pity that Lua does not have a concept of a constant variable
so that when I write  for i=1,n do ... end I really mean that value of
n cannot change. Is there any room to hint LuaJIT about certain
logical constrains of the executing code to assist it in
optimizations?

--Leo--