2 ms·
If you aim to ship your VM on machines with varying number of registers, and you pick a VM with R registers, you have to write code to make it run on machines w
by Someone 4y ago
If you aim to ship your VM on machines with varying number of registers, and you pick a VM with R registers, you have to write code to make it run on machines with fewer than R registers and code to make it run on machines with more than R registers.
Both are simple if you’re willing to give up performance (map VM registers to memory for the first case, don’t use more than R registers for the second case), but that means giving away a lot of performance. So, you’ll essentially be working on two different optimizers, with each only affecting some of your target CPUs.
If, on the other hand, your VM has zero registers, you only have to write the code for running efficiently on machines with more than zero registers. That’s conceptually easier, and (loosely) means every improvement you make will improve things on all target CPUs.
Also note that single static assignment as used in LLVM (not really a VM) somewhat uses the opposite approach: it assumes there are infinitely many registers, and then adds code to map that down to whatever is available on the target hardware.
Going back to the question: I think stack-based CPUs lost because all their instructions contend on access to the stack, making it hard for the hardware to pipeline instructions and/or execute them out of order.