Skip to content

Commit

Permalink
fix bytes/bits
Browse files Browse the repository at this point in the history
  • Loading branch information
laisolizq committed May 18, 2022
1 parent 5fb4d14 commit 0ec2dda
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 47 deletions.
35 changes: 3 additions & 32 deletions main/opcodes.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,7 @@ opSHR:
SP - 1 => SP
$ => D :MLOAD(SP--)
$ => A :MLOAD(SP)
A => E
${exp(2,D)} => B
${B-1} => B
$ => C :AND
${exp(2,D)} => B
${A >> D} => A
0 => D
E :ARITH
:CALL(SHRarithBit)
A :MSTORE(SP++)
GAS-3 => GAS
:JMP(readCode)
Expand All @@ -350,30 +343,8 @@ opSHL:
SP - 1 => SP
$ => D :MLOAD(SP--)
$ => A :MLOAD(SP)
${A << D} => E
256 - D => D :JMPC(SHL0)
${exp(2,D)} => B
${B-1} => B
$ => C :GT
256 - D => D
${exp(2,D)} => B
0 - C :JMPC(SHLbig)
0 => D,C
E :ARITH
:JMP(SHLfinal)
SHL0:
0 :MSTORE(SP++)
GAS-3 => GAS
:JMP(readCode)
SHLbig:
256 - D => D
${exp(2,D)} => D
${A/D} => D
0 => C
E :ARITH

SHLfinal:
E :MSTORE(SP++)
:CALL(SHLarithBit)
A :MSTORE(SP++)
GAS-3 => GAS
:JMP(readCode)

Expand Down
72 changes: 57 additions & 15 deletions main/utils.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -515,28 +515,52 @@ storeTmp:
:JMP(RR)

;@in A - (A >> D)
;@in D - (A >> D)
;@in D - (A >> D) D bytes
;@out A - A >> D => A
SHRarith:
B :MSTORE(tmpVarB2)
C :MSTORE(tmpVarC2)
D :MSTORE(tmpVarD2)
E :MSTORE(tmpVarE2)
A => E
D => A
8 => B
0 => C
0 => D
${A*B} => D :ARITH
E => A
:JMP(SHRarithinit)

;@in A - (A >> D)
;@in D - (A >> D) D bits
;@out A - A >> D => A
SHRarithBit:
B :MSTORE(tmpVarB2)
C :MSTORE(tmpVarC2)
D :MSTORE(tmpVarD2)
E :MSTORE(tmpVarE2)

SHRarithinit:
0 => B
$ => B :EQ
0 - B :JMPC(SHRarithfinal)
A => E
${exp(2,D*8)} => B
D => A
255 => B
$ => B :GT
0 - B :JMPC(SHRarith0)
E => A
${exp(2,D)} => B
${B-1} => B
$ => C :AND
${exp(2,D*8)} => B
0 => A
$ => B :EQ
0 - B :JMPC(SHRarithfinal)
${exp(2,D*8)} => B
${exp(2,D)} => B
${E/B} => A
0 => D
E :ARITH
:JMP(SHRarithfinal)

SHRarith0:
0 => A

SHRarithfinal:
$ => B :MLOAD(tmpVarB2)
Expand All @@ -546,27 +570,45 @@ SHRarithfinal:
:JMP(RR)

;@in A - (A << D)
;@in D - (A << D)
;@in D - (A << D) D bytes
;@out A - A << D => A
SHLarith:
B :MSTORE(tmpVarB2)
C :MSTORE(tmpVarC2)
D :MSTORE(tmpVarD2)
E :MSTORE(tmpVarE2)
A => E
D => A
8 => B
0 => C
0 => D
${A*B} => D :ARITH
E => A
:JMP(SHLarithinit)
;@in A - (A << D)
;@in D - (A << D) D bits
;@out A - A << D => A
SHLarithBit:
B :MSTORE(tmpVarB2)
C :MSTORE(tmpVarC2)
D :MSTORE(tmpVarD2)
E :MSTORE(tmpVarE2)

SHLarithinit:
A => E
0 => A
D => B
$ => B :EQ
0 - B :JMPC(SHLarithfinal)
E => A
${exp(2,D*8)} => B
${exp(2,D)} => B
${A*B} => E
32 - D => D :JMPC(SHLarith0)
${exp(2,D*8)} => B
256 - D => D :JMPC(SHLarith0)
${exp(2,D)} => B
${B-1} => B
$ => C :GT
32 - D => D
${exp(2,D*8)} => B
256 - D => D
${exp(2,D)} => B
0 - C :JMPC(SHLarithBig)
0 => D,C
E :ARITH
Expand All @@ -577,8 +619,8 @@ SHLarith0:
:JMP(SHLarithfinal)

SHLarithBig:
32 - D => D
${exp(2,D*8)} => D
256 - D => D
${exp(2,D)} => D
${A/D} => D
0 => C
E :ARITH
Expand Down

0 comments on commit 0ec2dda

Please sign in to comment.