Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Implement shift opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Apr 23, 2017
1 parent 0942f70 commit 14b8515
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions libevm/VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,50 @@ void VM::interpretCases()
++m_pc;
CASE_END

#ifdef EVM_USE_BITSHIFT
CASE_BEGIN(SHL)
ON_OP();
updateIOGas();

/// TODO: confirm shift >= 256 results in 0
*(m_sp - 1) = *m_sp << *(m_sp - 1);
--m_sp;
++m_pc;
CASE_END

CASE_BEGIN(SHR)
ON_OP();
updateIOGas();

/// TODO: confirm shift >= 256 results in 0
*(m_sp - 1) = *m_sp >> *(m_sp - 1);
--m_sp;
++m_pc;
CASE_END

CASE_BEGIN(SAR)
{
ON_OP();
updateIOGas();

s256 value = u2s(*m_sp);
u256 shift = *(m_sp - 1);
if (shift >= 256)
{
if (value >= 0)
*(m_sp - 1) = 0;
else
*(m_sp - 1) = s2u(-1);
}
else
*(m_sp - 1) = s2u(divWorkaround(value, exp256(2, shift)));

--m_sp;
++m_pc;
}
CASE_END
#endif

CASE_BEGIN(BYTE)
ON_OP();
updateIOGas();
Expand Down

0 comments on commit 14b8515

Please sign in to comment.