Summary
At the moment, constant registers are only supported in fairly limited ways. However, it would be useful to support arbitrary constant registers with an aim to simplifying the handling of constants in certain positions, such as for function calls and memory read/writes.
Example
Currently, certain vm.Instruction instances operate only over registers. This includes, for example, function calls. The following illustrates:
fn main() {
f(0)
}
fn f(x:u16) -> (r:u16) {
r = x
}
Here, main is currently translated as follows:
fn main() {
var $0:u16
[0] $0 = 0x0 ; f($0) ; ret
}
where $0 is a temporary register introduced to hold the constant value 0. Under this propose, we would change the translation to something like this:
fn main() {
const $0:u16 = 0x0
[0] f($0) ; ret
}
Here, we still have a register $0 but it is now a constant register. That is, a register which always holds a given constant value (0x0 in this case).
Approach
- Using constant registers could allow us to move all
W vm.Word[W] values out of the instructions altogether.
- We would want a zkc specific notion of register which as am internal field of type
W (replacing the existing padding field)
- This would in turn require changing
vm.Function[I] to become fm.Function[W,I].
Summary
At the moment, constant registers are only supported in fairly limited ways. However, it would be useful to support arbitrary constant registers with an aim to simplifying the handling of constants in certain positions, such as for function calls and memory read/writes.
Example
Currently, certain
vm.Instructioninstances operate only over registers. This includes, for example, function calls. The following illustrates:Here,
mainis currently translated as follows:where
$0is a temporary register introduced to hold the constant value0. Under this propose, we would change the translation to something like this:Here, we still have a register
$0but it is now a constant register. That is, a register which always holds a given constant value (0x0in this case).Approach
W vm.Word[W]values out of the instructions altogether.W(replacing the existingpaddingfield)vm.Function[I]to becomefm.Function[W,I].