Browse Source

SIGNEXTEND opcode.

cl-refactor
Christian 10 years ago
parent
commit
7c517e6338
  1. 14
      libevm/VM.h
  2. 2
      libevmface/Instruction.cpp
  3. 1
      libevmface/Instruction.h
  4. 5
      libserpent/opcodes.h

14
libevm/VM.h

@ -261,6 +261,7 @@ template <class Ext> dev::bytesConstRef dev::eth::VM::go(Ext& _ext, OnOpFunc con
case Instruction::OR:
case Instruction::XOR:
case Instruction::BYTE:
case Instruction::SIGNEXTEND:
case Instruction::JUMPI:
require(2);
break;
@ -420,6 +421,19 @@ template <class Ext> dev::bytesConstRef dev::eth::VM::go(Ext& _ext, OnOpFunc con
m_stack.pop_back();
m_stack.pop_back();
break;
case Instruction::SIGNEXTEND:
if (m_stack.back() < 255)
{
unsigned const bit(m_stack.back());
u256& number = m_stack[m_stack.size() - 2];
u256 mask = ((u256(1) << bit) - 1);
if (boost::multiprecision::bit_test(number, bit))
number |= ~mask;
else
number &= mask;
}
m_stack.pop_back();
break;
case Instruction::SHA3:
{
unsigned inOff = (unsigned)m_stack.back();

2
libevmface/Instruction.cpp

@ -52,6 +52,7 @@ const std::map<std::string, Instruction> dev::eth::c_instructions =
{ "BYTE", Instruction::BYTE },
{ "ADDMOD", Instruction::ADDMOD },
{ "MULMOD", Instruction::MULMOD },
{ "SIGNEXTEND", Instruction::SIGNEXTEND },
{ "SHA3", Instruction::SHA3 },
{ "ADDRESS", Instruction::ADDRESS },
{ "BALANCE", Instruction::BALANCE },
@ -179,6 +180,7 @@ static const std::map<Instruction, InstructionInfo> c_instructionInfo =
{ Instruction::BYTE, { "BYTE", 0, 2, 1 } },
{ Instruction::ADDMOD, { "ADDMOD", 0, 3, 1 } },
{ Instruction::MULMOD, { "MULMOD", 0, 3, 1 } },
{ Instruction::SIGNEXTEND, { "SIGNEXTEND", 0, 2, 1 } },
{ Instruction::SHA3, { "SHA3", 0, 2, 1 } },
{ Instruction::ADDRESS, { "ADDRESS", 0, 0, 1 } },
{ Instruction::BALANCE, { "BALANCE", 0, 1, 1 } },

1
libevmface/Instruction.h

@ -58,6 +58,7 @@ enum class Instruction: uint8_t
BYTE, ///< retrieve single byte from word
ADDMOD, ///< unsigned modular addition
MULMOD, ///< unsigned modular multiplication
SIGNEXTEND, ///< perform sign extension starting at given bit
SHA3 = 0x20, ///< compute SHA3-256 hash
ADDRESS = 0x30, ///< get address of currently executing account

5
libserpent/opcodes.h

@ -42,8 +42,9 @@ Mapping mapping[] = {
Mapping("XOR", 0x12, 2, 1),
Mapping("BYTE", 0x13, 2, 1),
Mapping("ADDMOD", 0x14, 3, 1),
Mapping("MULMOD", 0x15, 3, 1),
Mapping("SHA3", 0x20, 2, 1),
Mapping("MULMOD", 0x15, 3, 1),
Mapping("SIGNEXTEND", 0x16, 2, 1),
Mapping("SHA3", 0x20, 2, 1),
Mapping("ADDRESS", 0x30, 0, 1),
Mapping("BALANCE", 0x31, 1, 1),
Mapping("ORIGIN", 0x32, 0, 1),

Loading…
Cancel
Save