Re: Threaded Interpreter

dave@mips.complang.tuwien.ac.at (David Gregg)
27 Nov 2005 00:37:53 -0500

          From comp.compilers

Related articles
Threaded Interpreter acampbellb@hotmail.com (Avatar) (2005-11-19)
Re: Threaded Interpreter anton@mips.complang.tuwien.ac.at (2005-11-21)
Re: Threaded Interpreter egagnon@sablevm.org (Etienne Gagnon) (2005-11-21)
Re: Threaded Interpreter jeffrey.kenton@comcast.net (Jeff Kenton) (2005-11-21)
Re: Threaded Interpreter gowrikumar_ch@yahoo.com (chandramouli gowrikumar) (2005-11-21)
Re: Threaded Interpreter ian.rogers@manchester.ac.uk (Ian Rogers) (2005-11-21)
Re: Threaded Interpreter dave@mips.complang.tuwien.ac.at (2005-11-27)
| List of all articles for this month |
From: dave@mips.complang.tuwien.ac.at (David Gregg)
Newsgroups: comp.compilers
Date: 27 Nov 2005 00:37:53 -0500
Organization: Compilers Central
References: 05-11-091 05-11-110
Keywords: interpreter
Posted-Date: 27 Nov 2005 00:37:53 EST

Ian Rogers (ian.rogers@manchester.ac.uk) wrote:


: the idea behind threaded interpreters is that certain sequences of
: instructions are more common. For example a compare is usual before a
: branch. The threaded interpreter beats regular interpretation with a
: switch statement as the branch predictor can predict where the next
: instruction will be


It's possibly worth pointing out that threaded code has been used
since long before indirect branch predictors became widely
available. Bell's original paper on threaded code appeared in
1973. The original advantage of threaded code over using a switch
statement would have been a saving of a couple of instructions in each
dispatch in the interpreter. The behaviour of threaded code on branch
predictors was just a nice side effect that people noticed much later.


It's possible to capture the same effect without using threaded code,
although you still need to use GNU C's labels-as-values extension (or
program in Fortran or assembly). Just dispatch through a table of
labels. Something like:
goto *(dispatch_table[opcode]);


Just make sure that there is a separate goto at the end of the code
that implements each VM instruction. This gets a large chunk of the
benefits of using direct threaded code without all the pesky
translation of the bytecode to a new format.


David.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.