-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use new BE API from intx #131
Conversation
Codecov Report
@@ Coverage Diff @@
## master #131 +/- ##
=========================================
Coverage ? 87.87%
=========================================
Files ? 19
Lines ? 2054
Branches ? 218
=========================================
Hits ? 1805
Misses ? 224
Partials ? 25 |
05d3dbe
to
3bb2b01
Compare
Added benchmark results |
Anyone wants to review this? |
lib/evmone/instructions.cpp
Outdated
@@ -103,7 +106,7 @@ void op_div(execution_state& state, instr_argument) noexcept | |||
void op_sdiv(execution_state& state, instr_argument) noexcept | |||
{ | |||
auto& v = state.stack[1]; | |||
v = v != 0 ? intx::sdivrem(state.stack[0], v).quot : 0; | |||
v = v != 0 ? sdivrem(state.stack[0], v).quot : 0; |
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 actually like the explicit namespace because it improves readability in many places.
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.
Me too, especially for things like be::store(..., ...)
it would be clearer, that some conversion is going on
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 brought back the be::...
but intx::be::load<intx::uint256>
seems a bit too much...
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.
The intx::sdivrem()
is never needed, because of ADL. I can bring it back in similar cases, but I cannot promise it will stay consistent over time.
lib/evmone/instructions.cpp
Outdated
@@ -139,7 +139,7 @@ void op_mulmod(execution_state& state, instr_argument) noexcept | |||
const auto y = state.stack.pop(); | |||
auto& m = state.stack.top(); | |||
|
|||
m = m != 0 ? ((uint512{x} * uint512{y}) % uint512{m}).lo : 0; | |||
m = m != 0 ? mulmod(x, y, m) : 0; |
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.
Is there any speed change with these?
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.
Looks like there is.
lib/evmone/instructions.cpp
Outdated
@@ -629,17 +599,15 @@ void op_blockhash(execution_state& state, instr_argument) noexcept | |||
auto upper_bound = state.host.get_tx_context().block_number; | |||
auto lower_bound = std::max(upper_bound - 256, decltype(upper_bound){0}); | |||
auto n = static_cast<int64_t>(number); | |||
auto header = evmc_bytes32{}; | |||
auto header = evmc::bytes32{}; |
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.
Seems to be a somewhat irrelevant change?
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.
Removed.
lib/evmone/instructions.cpp
Outdated
@@ -1066,16 +1018,12 @@ void op_create(execution_state& state, instr_argument arg) noexcept | |||
|
|||
msg.sender = state.msg->destination; | |||
msg.depth = state.msg->depth + 1; | |||
intx::be::store(msg.value.bytes, endowment); | |||
msg.value = store<evmc::uint256be>(endowment); |
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.
In other places you do it like store(msg.value.bytes, value);
I like this assignment form better, maybe change other places for consistency?
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.
Fixed.
Ok, I pushed a version which is much more verbose, but still ok in my opinion. We still keep using short |
This is to see new intx API in usage. The intx PR: chfast/intx#107.
It also uses
intx::addmod()
andintx::mulmod()
. Closes #110.I didn't expect it to perform any better, but it does.
Skylake CPU:
Haswell CPU: