|
|
|
|
|
by gsg
4053 days ago
|
|
That would be very inefficient, because registers cannot be indexed. The dispatch you have to introduce to jump to code that references the right physical regs would murder you with mispredictions. Also, register VMs typically have three operands. Specialising each instruction for each possible register for three operands would result in a ridiculous volume of code. Special purpose instructions that access fixed registers would be fine, but general purpose operand references cannot be sanely implemented in this way. Existing register VMs use memory because it's faster. |
|
Wrong. Only SSA VMs (with an optimizing compiler) need three operands. Simple register VMs as well as hardware CPUs have two operands only, and you can easily fit them into one word then.
You cannot do better SSA based optimizations then, but the VM speed is much faster than with two or multi word ops, which blow up your instruction cache. lua has to use shorter ranges to get 3 operands into one word.
Writing a JIT with two-address ops is also trivial. It's a straightforward conversion using fixed registers.
Sample: https://github.com/perl11/potion
> Specialising each instruction for each possible register for three operands would result in a ridiculous volume of code.
Nobody does that, it's not needed.
> Special purpose instructions that access fixed registers would be fine, but general purpose operand references cannot be sanely implemented in this way. Existing register VMs use memory because it's faster.
No. You need general purpose operand insns for only one or two fixed registers (eax, edx typically). Nobody implements all possible combinations. And you use the stack to shuffle values around, not memory.