Implement CompilerUtils::memoryCopy using inline assembly

This commit is contained in:
Alex Beregszaszi 2016-11-30 22:44:33 +00:00 committed by chriseth
parent 4abc8ab5a9
commit 1bf412d9fd

View File

@ -304,7 +304,32 @@ void CompilerUtils::memoryCopy(bool _useIdentityPrecompile)
if (!_useIdentityPrecompile)
{
// FIXME
m_context.appendInlineAssembly(R"(
{
// expects three locals: src, dst, len
// 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 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" }
);
m_context << Instruction::POP;
m_context << Instruction::POP;
m_context << Instruction::POP;
return;
}