Skip to content

feat: support constant registers #1838

@DavePearce

Description

@DavePearce

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].

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestzkcIssues related to ZkC language

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions