...unless the interpreter maps VM registers directly onto machine registers. With some VMs it's possible, and then you can get very good performance.
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.
If you think three-operand instructions aren't common in both hardware and interpreter design, you are simply misinformed.
None of this has anything to do with SSA. SSA IR can be reasonably constructed from any of stack, accumulator, two-operand register or three operand register bytecode. All of the usual optimizations follow from that.
> the VM speed is much faster than with two or multi word ops
While variable length encodings are best avoided, that doesn't rule out three operand instructions. For a good example of an extremely fast interpreter that uses such instructions, have a look at luajit.
> Nobody does that, it's not needed.
That's what the OP was suggesting, so that's what I was discussing.