Next: Store Optimization, Previous: Simple instructions, Up: Input File Format [Contents][Index]
Note: don’t invest too much work in (static) superinstructions; a future version of Vmgen will support dynamic superinstructions (see Ian Piumarta and Fabio Riccardi, Optimizing Direct Threaded Code by Selective Inlining, PLDI’98), and static superinstructions have much less benefit in that context (preliminary results indicate only a factor 1.1 speedup).
Here is an example of a superinstruction definition:
lit_sub = lit sub
lit_sub
is the name of the superinstruction, and lit
and
sub
are its components. This superinstruction performs the same
action as the sequence lit
and sub
. It is generated
automatically by the VM code generation functions whenever that sequence
occurs, so if you want to use this superinstruction, you just need to add
this definition (and even that can be partially automatized, see VM profiler).
Vmgen requires that the component instructions are simple instructions defined before superinstructions using the components. Currently, Vmgen also requires that all the subsequences at the start of a superinstruction (prefixes) must be defined as superinstruction before the superinstruction. I.e., if you want to define a superinstruction
foo4 = load add sub mul
you first have to define load
, add
, sub
and mul
,
plus
foo2 = load add foo3 = load add sub
Here, sumof4
is the longest prefix of sumof5
, and
sumof3
is the longest prefix of sumof4
.
Note that Vmgen assumes that only the code it generates accesses stack pointers, the instruction pointer, and various stack items, and it performs optimizations based on this assumption. Therefore, VM instructions where your C code changes the instruction pointer should only be used as last component; a VM instruction where your C code accesses a stack pointer should not be used as component at all. Vmgen does not check these restrictions, they just result in bugs in your interpreter.
The Vmgen flag include-skipped-insts
influences superinstruction code
generation. Currently there is no support in the peephole optimizer for
both variations, so leave this flag alone for now.
Next: Store Optimization, Previous: Simple instructions, Up: Input File Format [Contents][Index]