diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-06-27 05:39:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-27 05:39:30 +0800 |
commit | b0ab9aaee0b4629b08ba2ada7e67b4c5d728fd8c (patch) | |
tree | 25f8cac9db13ee06802ca8465fce5d116a9bf295 /libsolidity/codegen/CompilerUtils.cpp | |
parent | 751ba701bca0fbcae6d74cfdc23a4ac4a1c3dfab (diff) | |
parent | ab15040caa0b2b401f9bebc8d8247e8e6b6d1540 (diff) | |
download | dexon-solidity-b0ab9aaee0b4629b08ba2ada7e67b4c5d728fd8c.tar.gz dexon-solidity-b0ab9aaee0b4629b08ba2ada7e67b4c5d728fd8c.tar.zst dexon-solidity-b0ab9aaee0b4629b08ba2ada7e67b4c5d728fd8c.zip |
Merge pull request #2453 from ethereum/memcopyAsForLoop
Use for loop for assembly memcopy.
Diffstat (limited to 'libsolidity/codegen/CompilerUtils.cpp')
-rw-r--r-- | libsolidity/codegen/CompilerUtils.cpp | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 7fed1975..4edec155 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -305,15 +305,9 @@ void CompilerUtils::memoryCopy32() m_context.appendInlineAssembly(R"( { - jumpi(end, eq(len, 0)) - start: - mstore(dst, mload(src)) - jumpi(end, iszero(gt(len, 32))) - dst := add(dst, 32) - src := add(src, 32) - len := sub(len, 32) - jump(start) - end: + for { let i := 0 } lt(i, len) { i := add(i, 32) } { + mstore(add(dst, i), mload(add(src, i))) + } } )", { "len", "dst", "src" } @@ -327,21 +321,22 @@ void CompilerUtils::memoryCopy() m_context.appendInlineAssembly(R"( { - // copy 32 bytes at once - start32: - jumpi(end32, lt(len, 32)) - mstore(dst, mload(src)) - dst := add(dst, 32) - src := add(src, 32) - len := sub(len, 32) - jump(start32) - end32: + // copy 32 bytes at once + for + {} + iszero(lt(len, 32)) + { + dst := add(dst, 32) + src := add(src, 32) + len := sub(len, 32) + } + { mstore(dst, mload(src)) } - // copy the remainder (0 < len < 32) - let mask := sub(exp(256, sub(32, len)), 1) - let srcpart := and(mload(src), not(mask)) - let dstpart := and(mload(dst), mask) - mstore(dst, or(srcpart, dstpart)) + // copy the remainder (0 < len < 32) + let mask := sub(exp(256, sub(32, len)), 1) + let srcpart := and(mload(src), not(mask)) + let dstpart := and(mload(dst), mask) + mstore(dst, or(srcpart, dstpart)) } )", { "len", "dst", "src" } |