Documentation for 5.2 VM instructions.

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Documentation for 5.2 VM instructions.

Lorenzo Donati-2
Hi all and especially KHMan!

Is there already a "No-Frills Introduction to Lua 5.1 VM Instructions"
for 5.2 VM [1] or any equivalent higher level documentation (higher than
browsing the source, I mean)?

Or at least a document describing the differences between 5.1 and 5.2
that can be found when browsing a VM listing?

Playing with luac listings in 5.2 I noticed a GETTABUP mnemonic. Any
more differences?

On a related note, out of curiosity I wonder if there is something like
an "assembler" targeting Lua VM. I know Lua VM specification is a Lua
implementation detail, but I'm curious to know if someone has tried this
way to enhance the performance of Lua in time-critical code (assuming
that hand-crafted Lua bytecode could squeeze some cycles out of the VM).

Any pointer appreciated!
Thanks.

-- Lorenzo

[1] I assume that at this stage (5.2 beta) the VM instruction set has
been frozen; of course if I'm wrong I understand it's too soon to look
for updated documentation.

Reply | Threaded
Open this post in threaded view
|

Re: Documentation for 5.2 VM instructions.

KHMan
On 9/21/2011 12:55 PM, Lorenzo Donati wrote:
> Is there already a "No-Frills Introduction to Lua 5.1 VM
> Instructions" for 5.2 VM [1] or any equivalent higher level
> documentation (higher than browsing the source, I mean)?

Nope, I plan to focus on LuaSrcDiet (via Yueliang). Probably after
the official 5.2 release...

I think a 5.2 update to No-Frills should switch back to luac.

Why don't you take it up? It seems to be a popular doc. I'll help
out and you put your name first. :-) :-)

> Or at least a document describing the differences between 5.1 and
> 5.2 that can be found when browsing a VM listing?

None that I know of.

> Playing with luac listings in 5.2 I noticed a GETTABUP mnemonic.
> Any more differences?

Better to look at the opcodes, then lvm, and trace calls to other
files from there.

> On a related note, out of curiosity I wonder if there is something
> like an "assembler" targeting Lua VM. I know Lua VM specification
> is a Lua implementation detail, but I'm curious to know if someone
> has tried this way to enhance the performance of Lua in
> time-critical code (assuming that hand-crafted Lua bytecode could
> squeeze some cycles out of the VM).

ChunkBake http://luaforge.net/projects/chunkbake/
and also something by Zed Shaw in the past, IIRC.

I don't think writing out bytecode assembly-style will give big
performance wins. It's still interpreting... Mike Pall's Lua
interpreter is already a lot faster, let alone the JIT. Most
things that people have thought of will probably need modification
of Lua source code (for example, a recent thread about reducing
lookups).

Maybe you want to try adding some super-instructions and see if
there is a significant performance change -- what I would be real
interested in right now is instruction traces and stats to show
which bytecode pair (or chain) is most frequent...

That said, I try to code a reasonable algorithm and that's it.
Silicon is too cheap and it has wiped out most extreme
optimization practices. All the same, as academic exercises, it's
an interesting area.

> Any pointer appreciated!
> Thanks.
[snip]

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia

Reply | Threaded
Open this post in threaded view
|

Re: Documentation for 5.2 VM instructions.

Lorenzo Donati-2
Sorry for the late reply and thank you for the prompt one!

On 21/09/2011 10.38, KHMan wrote:
[...]
>
> Why don't you take it up? It seems to be a popular doc. I'll help out
> and you put your name first. :-) :-)
>
Alas, although it's a tempting offer :-) I must decline. (Very kind of
you, anyway!) I've got very little free time and sadly I don't work as a
developer any longer, so Lua is just an hobby for me and a way to keep
my programming skills in good shape. I already do some basic beta
testing for Steve Donovan's LDoc (with a very lax schedule from my side
- given my time constraints) and that already saturated my "serious
commitment bandwidth".

I'm not really an "assembler geek" (most serious assembly stuff is high
over my head), but VM listings brings up some "ancient memories" to my
mind: ~20 yrs ago I did some x86 asm programming at the university, but
the real fun was programming a glorious Apple //e in machine language
(sic - using handmade lookup tables and pencil and paper memory layouts
- ahh! the pleasures of early youth :-) and debugging it using the
miniassembler and the monitor program (call -151 anyone ?!? :-). Well
the 6502 processor was so simple it was really fun, after all :-D

[...]
>
> Better to look at the opcodes, then lvm, and trace calls to other files
> from there.
>
Thanks for the pointer!

>> On a related note, out of curiosity I wonder if there is something
>> like an "assembler" targeting Lua VM. I know Lua VM specification
>> is a Lua implementation detail, but I'm curious to know if someone
>> has tried this way to enhance the performance of Lua in
>> time-critical code (assuming that hand-crafted Lua bytecode could
>> squeeze some cycles out of the VM).
>
> ChunkBake http://luaforge.net/projects/chunkbake/
> and also something by Zed Shaw in the past, IIRC.
>
> I don't think writing out bytecode assembly-style will give big
> performance wins. It's still interpreting... Mike Pall's Lua interpreter
> is already a lot faster, let alone the JIT.
Yes indeed! I never used it (I don't have the need for *that much*
speed), but I'm always amazed by the reports about the performance of
LuaJIT. The fact that it could beat pure C code in some cases is
something unreal (at least for an uninitiated in compiler design like
me)! I think I read somewhere (IIRC) it is deemed probably the most
performing JIT compiler for a (dynamic?) language ever!

Most things that people have

> thought of will probably need modification of Lua source code (for
> example, a recent thread about reducing lookups).
>
> Maybe you want to try adding some super-instructions and see if there is
> a significant performance change -- what I would be real interested in
> right now is instruction traces and stats to show which bytecode pair
> (or chain) is most frequent...
>
> That said, I try to code a reasonable algorithm and that's it. Silicon
> is too cheap and it has wiped out most extreme optimization practices.
> All the same, as academic exercises, it's an interesting area.
>

Thanks for all the insight and for satisfying my curiosity!

Cheers!
-- Lorenzo

Reply | Threaded
Open this post in threaded view
|

Re: Documentation for 5.2 VM instructions.

KHMan
On 9/22/2011 4:14 AM, Lorenzo Donati wrote:

> Sorry for the late reply and thank you for the prompt one!
>
> On 21/09/2011 10.38, KHMan wrote:
> [...]
>>
>> Why don't you take it up? It seems to be a popular doc. I'll
>> help out
>> and you put your name first. :-) :-)
>>
> Alas, although it's a tempting offer :-) I must decline. (Very
> kind of you, anyway!) [snip]

No problem, we are all trying to manage our time sinks too. I
limit myself to one MMPORG only -- FLOSS development. :-)

If someone on the list wants to take this up, please ping me
off-list. Basically, you study the sources, test some samples,
then write something up, with a version 5.1 doc to pave the way.
Only benefit: your name on the doc. It's true there is nothing
stopping anyone from writing something similar right now -- the
main barrier is the time and effort needed to complete the work.

It's a small corner in the Lua ecosystem, but I'm sure there will
be lots of people who'd want to read a primer on the Lua 5.2 VM in
the next few years... and... [marketing talk ensues] folks on the
list will be pointing to a document with _your_name_ on it. :-)

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia

Reply | Threaded
Open this post in threaded view
|

Interpreter vs JIT (Re: Documentation for 5.2 VM instructions.)

Dirk Laurie
In reply to this post by Lorenzo Donati-2
The following aside in a post of KHMan quoted by Lorenzo Donati exposes
a gap in my knowledge.

> > Mike Pall's Lua interpreter is already a lot faster, let alone the JIT.

I presume the remark means that the compile-to-bytecode part of LuaJIT
is faster than the corresponding part of Lua 5.1.

Now LuaJIT supplies a "luajit -jbc" control command, which lists the
bytecode but does not AFAICT offer an option to store it for later use.

I.e. there seems to be no LuaJIT equivalent of

    luac -o foo.lbc foo.lua
    lua foo.lbc

True?  And if so, surely debated on this list before my time?

Dirk

Reply | Threaded
Open this post in threaded view
|

Re: Interpreter vs JIT (Re: Documentation for 5.2 VM instructions.)

KHMan
On 9/22/2011 1:10 PM, Dirk Laurie wrote:
> The following aside in a post of KHMan quoted by Lorenzo Donati exposes
> a gap in my knowledge.
>
>>> Mike Pall's Lua interpreter is already a lot faster, let alone the JIT.
>
> I presume the remark means that the compile-to-bytecode part of LuaJIT
> is faster than the corresponding part of Lua 5.1.

I have been too lazy to study the LuaJIT sources, but AFAIK, IIRC,
the interpreter is written in assembly and is several times faster
than the standard Lua implementation. I'm sure others who are more
familiar with LuaJIT can fill in the details.

Here is a link: http://luajit.org/performance_x86.html

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia

Reply | Threaded
Open this post in threaded view
|

Re: Interpreter vs JIT (Re: Documentation for 5.2 VM instructions.)

Dirk Laurie
In reply to this post by Dirk Laurie
On Thu, Sep 22, 2011 at 07:10:24AM +0200, Dirk Laurie wrote:
> I.e. there seems to be no LuaJIT equivalent of
>
>     luac -o foo.lbc foo.lua
>     lua foo.lbc
>
> True?  And if so, surely debated on this list before my time?

KHMan's answer to another point in my post gives a link that
answers this one too.

    True for LuaJIT-2.0.0-beta7, but not for LuaJIT-2.0.0-beta8:
    the new -b command line option supplies the feature.

Dirk

Reply | Threaded
Open this post in threaded view
|

Re: Documentation for 5.2 VM instructions.

steve donovan
In reply to this post by KHMan
On Thu, Sep 22, 2011 at 4:18 AM, KHMan <[hidden email]> wrote:
> No problem, we are all trying to manage our time sinks too. I limit myself
> to one MMPORG only -- FLOSS development. :-)

Well said, sir!  No time for any other games!  I'm very grateful to
Lorenzo for testing, since he is very precise and thorough. Lua's
flexibility is a particular challenge for documentation tools that try
to do some rudimentary code analysis.

steve d.