This is a simple JIT-based VM that implements the following instruction set:
0x1— Increment the A register0x2— Increment the B register0x3— Decrement the A register0x4— Decrement the B register
The VM is implemented in vm.c and has both naive and JIT backends. The naive method is pure C and uses a switch statement to determine the appropriate action. The JIT backend compiles a program into x86 machine code using the definitions in the op-x86.s file.
The two vm_run_* functions have a "times" argument that specifies the number of times to repeat the program. This is a simple way of testing the performance increase gained by running JIT code while ignoring the overhead incurred from the JIT process itself. In a real JIT scenario, compiled code sections would be cached.
Here are two example runs of the following sources:
[188] aiadicicco@sphinx jit $ time ./jit naive 50000000
a = 0x00
b = 0x00
real 0m2.572s
user 0m2.564s
sys 0m0.000s
[189] aiadicicco@sphinx jit $ time ./jit jit 50000000
a = 0x00
b = 0x00
real 0m0.805s
user 0m0.800s
sys 0m0.000s
The program being tested increments and decrements the A register 4 times and the B register 3 times. This can be compiled on x86 and x86-64 systems with the following command:
$ gcc -o jit -m32 main.c vm.c op-x86.s