
So What is a Direct-Threaded, Register-Based, Bytecode Interpreter Anyway? - soundsop
http://blog.mozilla.com/dmandelin/2008/06/03/squirrelfish/
======
apu
It's quite impressive to read a blog post that analyzes a competitor's
announcement carefully (with no ill will), performs tests to show the validity
of the analysis, provides the source for the test, and is written cleanly and
concisely. I wish more posts on the internet were like this.

------
mojuba
Actually, direct threading can be done with C/C++: I just wrote a switch
statement with 256 case labels and made sure the switch control variable is
unsigned char. With -O3 it gave me exactly the code I wanted - no range
checking anymore, since the control variable is unsigned char anyway.

~~~
cwp
Not quite. If you're dispatching based on a sequence of opcodes, that's
indirect threading. Direct threading uses a sequence of pointers to the opcode
implementations, and jumps directly to them. Also, one of the key benefits of
threaded interpreters is that each opcode implementation ends by decoding the
next instruction and jumping to its implementation. This duplication of code
gives the processor more context for branch prediction, and can lead to fewer
pipeline stalls. With a switch statement, the decoding and branching all
happens at the top of the loop.

------
ntoshev
It seems you can't have direct threaded interpreter for JVM or CLR where the
opcodes conform to specification that can't change between versions of the
interpreter.

The SquirrelFish announcement's list for future developments
(<http://webkit.org/blog/189/announcing-squirrelfish/>) contains some more
codewords I wish I understood:

\- constant folding

\- aggressive copy propagation

\- type inference—both exact and speculative

\- specialization based on expression context—especially void and boolean
context

\- peephole optimization

\- constant pool instructions

\- superinstructions

\- instructions with implicit register operands

\- advanced dispatch techniques, like instruction duplication and context
threading

~~~
jeroen
This is probably a good start to get to know more about some of these
subjects: <http://en.wikipedia.org/wiki/Category:Compiler_optimizations>

