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

Interpreter refactoring #5800

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Interpreter refactoring #5800

wants to merge 4 commits into from

Conversation

chfast
Copy link
Collaborator

@chfast chfast commented Oct 28, 2019

No description provided.

@chfast chfast marked this pull request as ready for review October 28, 2019 09:59
@codecov-io
Copy link

codecov-io commented Oct 28, 2019

Codecov Report

Merging #5800 into master will decrease coverage by <.01%.
The diff coverage is 26.53%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5800      +/-   ##
==========================================
- Coverage   64.02%   64.02%   -0.01%     
==========================================
  Files         359      359              
  Lines       30796    30772      -24     
  Branches     3417     3416       -1     
==========================================
- Hits        19718    19702      -16     
+ Misses       9855     9845      -10     
- Partials     1223     1225       +2

uint64_t s = (uint64_t)m_SP[1];
owning_bytes_ref output{std::move(m_mem), b, s};
throwRevertInstruction(std::move(output));
throwRevertInstruction((uint64_t)m_SP[0], (uint64_t)m_SP[1]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we static_cast here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better, yes. But I wanted to minimize number of changes.

if (size < _required)
BOOST_THROW_EXCEPTION(StackUnderflow() << RequirementError((bigint)_required, size));
if (m_stackEnd - m_SPP < _required)
throw EVMC_STACK_UNDERFLOW;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we include the stack information in the exception anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything is converted into a single evmc_status_code anyway.

void throwRevertInstruction(owning_bytes_ref&& _output);
void throwDisallowedStateChange();
void throwBufferOverrun(intx::uint512 const& _enfOfAccess);
static void throwOutOfGas();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to make them inline or/and free functions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe there's not much sense in these helpers at all, and we can just put throws inline

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was done previously for performance reasons. I plan to rework this in separate PR with benchmarks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did inlining. From quick benchmarks, the inlining commit gives ~3% improvement. In total the PR gives up to 13% improvement.

static void throwBadInstruction();
static void throwBadJumpDestination();
void throwBadStack(int _removed);
void throwRevertInstruction(uint64_t _offset, uint64_t _size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd fill m_output outside of the function and make it static as others

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_output can then stay private, too

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is accessed also in EVMC's execute() method. More refactoring is possible to clean up how EVMC result is created and reported.

libaleth-interpreter/VM.cpp Outdated Show resolved Hide resolved
Instead of using complex exception types from Aleth, throw EVMC status code in simple cases.
@chfast chfast force-pushed the interpreter branch 2 times, most recently from 6d81224 to 32b30d7 Compare November 3, 2019 18:02
Copy link
Member

@gumb0 gumb0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

many unnecessary whitespace changes


uint64_t dest = decodeJumpDest(_code, pc);

_pc += 1 + n * 2; // adust inout _pc to opcode after table
_pc += 1 + n * 2; // adust inout _pc to opcode after table
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_pc += 1 + n * 2; // adust inout _pc to opcode after table
_pc += 1 + n * 2; // adjust inout _pc to opcode after table

@@ -271,9 +239,9 @@ void VM::interpretCases()
{
ON_OP();
if (m_rev < EVMC_CONSTANTINOPLE)
throwBadInstruction();
throw EVMC_BAD_JUMP_DESTINATION;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw EVMC_BAD_JUMP_DESTINATION;
throw EVMC_UNDEFINED_INSTRUCTION;

@@ -387,7 +354,7 @@ void VM::interpretCases()
}
NEXT

CASE(MSTORE)
CASE(MSTORE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation here... Maybe let's put semicolon after NEXT to work around this?

CASE(BEGINDATA)
CASE(GETLOCAL)
CASE(PUTLOCAL)
CASE(JUMPTO) CASE(JUMPIF) CASE(JUMPV) CASE(JUMPSUB) CASE(JUMPSUBV) CASE(RETURNSUB)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱 here semicolon won't help, so I don't know what to do other that manually overriding it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I accidentally formatted whole file. I will have to revert the formatting changes somehow, but I didn't have time to do so so far.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants