Skip to content

Commit

Permalink
Merge pull request #387 from 0xPolygonHermez/feature/optimize-lenb-plus
Browse files Browse the repository at this point in the history
add optimization to get-len-bytes
  • Loading branch information
ignasirv authored May 24, 2024
2 parents 4bbe44e + a2b6342 commit 25e5f53
Showing 1 changed file with 34 additions and 40 deletions.
74 changes: 34 additions & 40 deletions main/utils/get-len-bytes.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,53 @@ getLenBytes:
;[7], [6], [5], [4], [3], [2], [1], [0]
;[6], [5], [4], [3], [2], [1], [0], [7] -> ROTL_C
B => C
ROTL_C :JMPZ(checkSlot6) ; length less than 29 bytes
ROTL_C - 0x00000100 :JMPN(lenBytes29)
ROTL_C - 0x00010000 :JMPN(lenBytes30)
ROTL_C - 0x01000000 :JMPN(lenBytes31, lenBytes32)

checkSlot6:
ROTL_C => C
ROTL_C :JMPZ(checkSlot5)
ROTL_C - 0x00000100 :JMPN(lenBytes25)
ROTL_C - 0x00010000 :JMPN(lenBytes26)
ROTL_C - 0x01000000 :JMPN(lenBytes27, lenBytes28)
ROTL_C => C,B :JMPZ(checkSlot6) ; length less than 29 bytes
B - 0x00000100 :JMPN(lenBytes29)
B - 0x00010000 :JMPN(lenBytes30)
B - 0x01000000 :JMPN(lenBytes31, lenBytes32)

checkSlot6:
ROTL_C => C,B :JMPZ(checkSlot5)
B - 0x00000100 :JMPN(lenBytes25)
B - 0x00010000 :JMPN(lenBytes26)
B - 0x01000000 :JMPN(lenBytes27, lenBytes28)

checkSlot5:
ROTL_C => C
ROTL_C :JMPZ(checkSlot4)
ROTL_C - 0x00000100 :JMPN(lenBytes21)
ROTL_C - 0x00010000 :JMPN(lenBytes22)
ROTL_C - 0x01000000 :JMPN(lenBytes23, lenBytes24)
ROTL_C => C,B :JMPZ(checkSlot4)
B - 0x00000100 :JMPN(lenBytes21)
B - 0x00010000 :JMPN(lenBytes22)
B - 0x01000000 :JMPN(lenBytes23, lenBytes24)

checkSlot4:
ROTL_C => C
ROTL_C :JMPZ(checkSlot3)
ROTL_C - 0x00000100 :JMPN(lenBytes17)
ROTL_C - 0x00010000 :JMPN(lenBytes18)
ROTL_C - 0x01000000 :JMPN(lenBytes19, lenBytes20)
ROTL_C => C,B :JMPZ(checkSlot3)
B - 0x00000100 :JMPN(lenBytes17)
B - 0x00010000 :JMPN(lenBytes18)
B - 0x01000000 :JMPN(lenBytes19, lenBytes20)

checkSlot3:
ROTL_C => C
ROTL_C :JMPZ(checkSlot2)
ROTL_C - 0x00000100 :JMPN(lenBytes13)
ROTL_C - 0x00010000 :JMPN(lenBytes14)
ROTL_C - 0x01000000 :JMPN(lenBytes15, lenBytes16)
ROTL_C => C,B :JMPZ(checkSlot2)
B - 0x00000100 :JMPN(lenBytes13)
B - 0x00010000 :JMPN(lenBytes14)
B - 0x01000000 :JMPN(lenBytes15, lenBytes16)

checkSlot2:
ROTL_C => C
ROTL_C :JMPZ(checkSlot1)
ROTL_C - 0x00000100 :JMPN(lenBytes9)
ROTL_C - 0x00010000 :JMPN(lenBytes10)
ROTL_C - 0x01000000 :JMPN(lenBytes11, lenBytes12)
ROTL_C => C,B :JMPZ(checkSlot1)
B - 0x00000100 :JMPN(lenBytes9)
B - 0x00010000 :JMPN(lenBytes10)
B - 0x01000000 :JMPN(lenBytes11, lenBytes12)

checkSlot1:
ROTL_C => C
ROTL_C :JMPZ(checkSlot0)
ROTL_C - 0x00000100 :JMPN(lenBytes5)
ROTL_C - 0x00010000 :JMPN(lenBytes6)
ROTL_C - 0x01000000 :JMPN(lenBytes7, lenBytes8)
ROTL_C => C,B :JMPZ(checkSlot0)
B - 0x00000100 :JMPN(lenBytes5)
B - 0x00010000 :JMPN(lenBytes6)
B - 0x01000000 :JMPN(lenBytes7, lenBytes8)

checkSlot0:
ROTL_C => C
ROTL_C :JMPZ(lenBytes0)
ROTL_C - 0x00000100 :JMPN(lenBytes1)
ROTL_C - 0x00010000 :JMPN(lenBytes2)
ROTL_C - 0x01000000 :JMPN(lenBytes3, lenBytes4)
ROTL_C => C,B :JMPZ(lenBytes0)
B - 0x00000100 :JMPN(lenBytes1)
B - 0x00010000 :JMPN(lenBytes2)
B - 0x01000000 :JMPN(lenBytes3, lenBytes4)

lenBytes32:
32 => A :RESTORE, RETURN
Expand Down

0 comments on commit 25e5f53

Please sign in to comment.