This is the main thread about optimizing VM translation.
Generated code sizeA few posts into that thread is a table of VM instruction counts in the OS. That table and the length of code your translator generates will show you what instructions you need to optimize first.
If your translator is typical,
call is the top offender; its implementation is huge and there are lots of them.
Return is also huge, but there are not many instances of it.
Return is, however, really easy to optimize.
All
return instructions translate into exactly the same ASM code. The first time you write that code, give it a label like ($$RETURN), and all the remaining
return commands translate into 2 instructions:
@$$RETURN
0;JMP
This post shows how you can make an assembly language subroutine to handle the compare instructions.
Translating eq to asmThis technique reduces the compare commands from a dozen or so instructions to four instructions.
You can use a similar technique to make an ASM subroutine to handle
call instructions.
Use two of the temp registers (R13-15) and D register to pass the target function's address and number of parameters and return IP. This will reduce each
call command to 12 instructions.
This is more work because it involves making your VM translator two-pass, but really cuts down on ASM size.
Call tree analysis (in "Generated code size" thread.)
--Mark