Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use mstore_32bytes to optimize decode_int_given_len #1413

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 13 additions & 31 deletions evm/src/cpu/kernel/asm/rlp/decode.asm
Original file line number Diff line number Diff line change
Expand Up @@ -131,37 +131,19 @@ decode_rlp_list_len_big:
// Pre stack: pos, len, retdest
// Post stack: pos', int
global decode_int_given_len:
%stack (pos, len, retdest) -> (pos, len, pos, retdest)
DUP2 ISZERO %jumpi(empty_int)
%stack (pos, len, retdest) -> (pos, len, pos, len, retdest)
ADD
// stack: end_pos, pos, retdest
SWAP1
// stack: pos, end_pos, retdest
PUSH 0 // initial accumulator state
// stack: acc, pos, end_pos, retdest

decode_int_given_len_loop:
// stack: acc, pos, end_pos, retdest
DUP3
DUP3
EQ
// stack: pos == end_pos, acc, pos, end_pos, retdest
%jumpi(decode_int_given_len_finish)
// stack: acc, pos, end_pos, retdest
%shl_const(8)
// stack: acc << 8, pos, end_pos, retdest
DUP2
// stack: pos, acc << 8, pos, end_pos, retdest
%mload_kernel(@SEGMENT_RLP_RAW)
// stack: byte, acc << 8, pos, end_pos, retdest
ADD
// stack: acc', pos, end_pos, retdest
// Increment pos.
SWAP1
%increment
SWAP1
// stack: acc', pos', end_pos, retdest
%jump(decode_int_given_len_loop)
%stack(pos_two, pos, len, retdest) -> (pos, len, pos_two, retdest)
PUSH @SEGMENT_RLP_RAW
PUSH 0 //context
MLOAD_32BYTES
// stack: int, pos', retdest
%stack(int, pos, retdest) -> (retdest, pos, int)
JUMP

decode_int_given_len_finish:
%stack (acc, pos, end_pos, retdest) -> (retdest, pos, acc)
empty_int:
// stack: pos, len, retdest
%stack(pos, len, retdest) -> (retdest, pos, 0)
JUMP

Loading