-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Interpreter refactoring #5800
base: master
Are you sure you want to change the base?
Interpreter refactoring #5800
Conversation
Codecov Report
@@ 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 |
libaleth-interpreter/VM.cpp
Outdated
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]); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
libaleth-interpreter/VMCalls.cpp
Outdated
if (size < _required) | ||
BOOST_THROW_EXCEPTION(StackUnderflow() << RequirementError((bigint)_required, size)); | ||
if (m_stackEnd - m_SPP < _required) | ||
throw EVMC_STACK_UNDERFLOW; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
libaleth-interpreter/VM.h
Outdated
void throwRevertInstruction(owning_bytes_ref&& _output); | ||
void throwDisallowedStateChange(); | ||
void throwBufferOverrun(intx::uint512 const& _enfOfAccess); | ||
static void throwOutOfGas(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 throw
s inline
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
libaleth-interpreter/VM.h
Outdated
static void throwBadInstruction(); | ||
static void throwBadJumpDestination(); | ||
void throwBadStack(int _removed); | ||
void throwRevertInstruction(uint64_t _offset, uint64_t _size); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Instead of using complex exception types from Aleth, throw EVMC status code in simple cases.
6d81224
to
32b30d7
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw EVMC_BAD_JUMP_DESTINATION; | |
throw EVMC_UNDEFINED_INSTRUCTION; |
@@ -387,7 +354,7 @@ void VM::interpretCases() | |||
} | |||
NEXT | |||
|
|||
CASE(MSTORE) | |||
CASE(MSTORE) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
No description provided.