koute / polkavm

A fast and secure RISC-V based virtual machine
Apache License 2.0
234 stars 47 forks source link

Remove support for the `zero` register #74

Closed koute closed 8 months ago

koute commented 9 months ago

The zero register is a consistent thorn in our side in the recompiler, mostly because on amd64 we simply do not have any registers to spare to just permanently park a zero in it, so we have to work around this by special casing almost every instruction for when it uses the zero register.

It'd be better to just disallow the use of the zero register altogether, and handle this in the linker, translating every instruction which uses the zero register into a corresponding instruction which doesn't (e.g. by replacing it with an immediate).

For example, add a0, a1, zero and add a0, zero, a1 can just be turned into addi a0, a1, 0.