I have programmed a registry based bytecode interpreter/virtual machine. The purpose of this, is to make it possible to run (interpreted) programs which can be edited from the Serial Monitor.
I started with a simple stackbased virtual machine (not yet all bytecodes are implemented). I have improved the execution speed 4 to 5 times. But it still is 24 times slower than native code. (All this is meassured calculating fibonaccia n=(n-2)+(n-1).) So I am looking for further improvements to execution speed. Attached the sketch, which completes in 101ms on a Arduino Uno 16Mhz.
I noticed / implemented the following (in the order below) which improved execution speed:
- Replaced byte-code switch tree with gotos
- Register based instead of stack based
- Local vars and no class construct
- Bytes as datatypes instead of ints
- Bytecodes (and number of arguments) equal to the AVR instruction set
What did not make any difference was set GCC-argument to -O3.
Any ideas how to further improve the speed?
Interpreter_RegBased.ino (13.1 KB)