Node:C Code Macros, Next:, Previous:Simple instructions, Up:Simple instructions



C Code Macros

Vmgen recognizes the following strings in the C code part of simple instructions:


SET_IP
As far as Vmgen is concerned, a VM instruction containing this ends a VM basic block (used in profiling to delimit profiled sequences). On the C level, this also sets the instruction pointer.
SUPER_END
This ends a basic block (for profiling), even if the instruction contains no SET_IP.
INST_TAIL;
Vmgen replaces INST_TAIL; with code for ending a VM instruction and dispatching the next VM instruction. Even without a INST_TAIL; this happens automatically when control reaches the end of the C code. If you want to have this in the middle of the C code, you need to use INST_TAIL;. A typical example is a conditional VM branch:
if (branch_condition) {
  SET_IP(target); INST_TAIL;
}
/* implicit tail follows here */

In this example, INST_TAIL; is not strictly necessary, because there is another one implicitly after the if-statement, but using it improves branch prediction accuracy slightly and allows other optimizations.

SUPER_CONTINUE
This indicates that the implicit tail at the end of the VM instruction dispatches the sequentially next VM instruction even if there is a SET_IP in the VM instruction. This enables an optimization that is not yet implemented in the vmgen-ex code (but in Gforth). The typical application is in conditional VM branches:
if (branch_condition) {
  SET_IP(target); INST_TAIL; /* now this INST_TAIL is necessary */
}
SUPER_CONTINUE;

Note that Vmgen is not smart about C-level tokenization, comments, strings, or conditional compilation, so it will interpret even a commented-out SUPER_END as ending a basic block (or, e.g., RESET_IP; as SET_IP;). Conversely, Vmgen requires the literal presence of these strings; Vmgen will not see them if they are hiding in a C preprocessor macro.