You will never obtain all the knowledge in the world. But you can absorb several small portions of it. In this article, we are describing how to register Transfer Language (RTL) for CRuby. Introducing a Register Transfer Language (RTL) to the CRuby VM turned out to be an even harder task than introducing the initial JIT compiler. The required changes to the VM are far more invasive than the ones needed for the JIT compiler.
First of all, what is RTL? The current CRuby VM uses stack instructions. Here is an example of stack instructions for the Ruby code
a = b + c, where
c are local variables.
Instructions in RTL are longer but there are fewer of them for the same code. Usually, RTL is interpreted faster because a smaller number of executed instructions results in less instruction-dispatching overhead and less memory traffic for operand values, which is more important for modern computers with a bigger gap in speeds of CPU and memory.
CRuby has a generational garbage collector, and every time we assign a value to a (non-temporary) variable, we should inform the garbage collector about this. So for the result of the RTL instruction, we should check that the result is not a temporary variable and call the garbage collector after that.
Although the check is small, it might considerably decrease RTL interpretation speed. I found that in most cases, the faster code can be generated for the interpreter if we use only temporaries as RTL instruction results and generate an additional move instruction if we need the final result to be stored in a local variable.
Feel free to explore more examples here.