Skip to content

feat: apply register allocation in zkasm #1388

@letypequividelespoubelles

Description

Actual not optimized

pub fn useless(INST, INPUT u128,) -> (OUTPUT u1){
   if INST = 0      goto doNothing
   if INST==5      goto instGt5
   if INST==13    goto instLt13
fail

doNothing
OUTPUT = 0
return

instGt5:
 var tmpInputMinus5 u128
OUTPUT, tmpInputMinus5 = INPUT - 5
return

instGt5:
var tmp13MinustInput u128
OUTPUT, tmp13MinustInput = 13 -INPUT
return
}

=> we create two columns for the two tmps, they can't have same name etc ... when we have lots of b/c u1 columns we end up with var b6 u1 ...

Actual "hand optimized":

pub fn useless(INST = 5, INPUT u128,) -> (OUTPUT u1){
    var tmp u128

   if INST==5      goto instGt5
   if INST==13    goto instLt13
fail

doNothing
tmp = 0 ;; useless constraint
OUTPUT = 0
return

instGt5:
OUTPUT, tmp = INPUT - 5
return

instGt5:
OUTPUT, tmp = 13 -INPUT
return
}

hand made :(

Improved:

pub fn useless(INST = 5, INPUT u128,) -> (OUTPUT u1){
   if INST==5      goto instGt5
   if INST==13    goto instLt13
fail


doNothing
OUTPUT = 0
return

instGt5:
 var loc tmp u128
OUTPUT, tmp = INPUT - 5
return

instGt5:
var loc tmp u128
OUTPUT, tmp = 13 -INPUT
return
}

=> we can create "loc variables" that could share the same name, can be put in same register, we don't have to declare shared tmp columns where a sub inst doesn't require it etc ...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions