mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Simplify and optimise stack rotation.
This commit is contained in:
parent
e9c7837c15
commit
35b310cfaf
@ -695,18 +695,31 @@ void CompilerUtils::copyToStackTop(unsigned _stackDepth, unsigned _itemSize)
|
|||||||
|
|
||||||
void CompilerUtils::moveToStackTop(unsigned _stackDepth, unsigned _itemSize)
|
void CompilerUtils::moveToStackTop(unsigned _stackDepth, unsigned _itemSize)
|
||||||
{
|
{
|
||||||
solAssert(_stackDepth <= 15, "Stack too deep, try removing local variables.");
|
moveIntoStack(_itemSize, _stackDepth);
|
||||||
for (unsigned j = 0; j < _itemSize; ++j)
|
|
||||||
for (unsigned i = 0; i < _stackDepth + _itemSize - 1; ++i)
|
|
||||||
m_context << eth::swapInstruction(1 + i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerUtils::moveIntoStack(unsigned _stackDepth, unsigned _itemSize)
|
void CompilerUtils::moveIntoStack(unsigned _stackDepth, unsigned _itemSize)
|
||||||
{
|
{
|
||||||
solAssert(_stackDepth <= 16, "Stack too deep, try removing local variables.");
|
if (_stackDepth <= _itemSize)
|
||||||
for (unsigned j = 0; j < _itemSize; ++j)
|
for (unsigned i = 0; i < _stackDepth; ++i)
|
||||||
for (unsigned i = _stackDepth; i > 0; --i)
|
rotateStackDown(_stackDepth + _itemSize);
|
||||||
m_context << eth::swapInstruction(i + _itemSize - 1);
|
else
|
||||||
|
for (unsigned i = 0; i < _itemSize; ++i)
|
||||||
|
rotateStackUp(_stackDepth + _itemSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompilerUtils::rotateStackUp(unsigned _items)
|
||||||
|
{
|
||||||
|
solAssert(_items - 1 <= 16, "Stack too deep, try removing local variables.");
|
||||||
|
for (unsigned i = 1; i < _items; ++i)
|
||||||
|
m_context << eth::swapInstruction(_items - i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompilerUtils::rotateStackDown(unsigned _items)
|
||||||
|
{
|
||||||
|
solAssert(_items - 1 <= 16, "Stack too deep, try removing local variables.");
|
||||||
|
for (unsigned i = 1; i < _items; ++i)
|
||||||
|
m_context << eth::swapInstruction(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerUtils::popStackElement(Type const& _type)
|
void CompilerUtils::popStackElement(Type const& _type)
|
||||||
|
@ -134,6 +134,12 @@ public:
|
|||||||
void moveToStackTop(unsigned _stackDepth, unsigned _itemSize = 1);
|
void moveToStackTop(unsigned _stackDepth, unsigned _itemSize = 1);
|
||||||
/// Moves @a _itemSize elements past @a _stackDepth other stack elements
|
/// Moves @a _itemSize elements past @a _stackDepth other stack elements
|
||||||
void moveIntoStack(unsigned _stackDepth, unsigned _itemSize = 1);
|
void moveIntoStack(unsigned _stackDepth, unsigned _itemSize = 1);
|
||||||
|
/// Rotates the topmost @a _items items on the stack, such that the previously topmost element
|
||||||
|
/// is bottom-most.
|
||||||
|
void rotateStackUp(unsigned _items);
|
||||||
|
/// Rotates the topmost @a _items items on the stack, such that the previously bottom-most element
|
||||||
|
/// is now topmost.
|
||||||
|
void rotateStackDown(unsigned _items);
|
||||||
/// Removes the current value from the top of the stack.
|
/// Removes the current value from the top of the stack.
|
||||||
void popStackElement(Type const& _type);
|
void popStackElement(Type const& _type);
|
||||||
/// Removes element from the top of the stack _amount times.
|
/// Removes element from the top of the stack _amount times.
|
||||||
|
Loading…
Reference in New Issue
Block a user