Skip to content

Commit

Permalink
Update instructions implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Jun 25, 2021
1 parent 889a4c2 commit e86db4b
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions lib/evmone/instructions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ inline evmc_status_code exp(ExecutionState& state) noexcept
auto& exponent = state.stack.top();

const auto exponent_significant_bytes =
static_cast<int>(intx::count_significant_words<uint8_t>(exponent));
static_cast<int>(intx::count_significant_bytes(exponent));
const auto exponent_cost = state.rev >= EVMC_SPURIOUS_DRAGON ? 50 : 10;
const auto additional_cost = exponent_significant_bytes * exponent_cost;
if ((state.gas_left -= additional_cost) < 0)
Expand Down Expand Up @@ -156,26 +156,19 @@ inline void lt(Stack& stack) noexcept
inline void gt(Stack& stack) noexcept
{
const auto x = stack.pop();
stack[0] = stack[0] < x; // TODO: Using < is faster than >.
stack[0] = stack[0] < x; // Arguments are swapped and < is used.
}

inline void slt(Stack& stack) noexcept
{
// TODO: Move this to intx.
const auto x = stack.pop();
auto& y = stack[0];
const auto x_neg = x.hi.hi >> 63;
const auto y_neg = y.hi.hi >> 63;
y = ((x_neg ^ y_neg) != 0) ? x_neg : x < y;
stack[0] = slt(x, stack[0]);
}

inline void sgt(Stack& stack) noexcept
{
const auto x = stack.pop();
auto& y = stack[0];
const auto x_neg = x.hi.hi >> 63;
const auto y_neg = y.hi.hi >> 63;
y = ((x_neg ^ y_neg) != 0) ? y_neg : y < x;
stack[0] = slt(stack[0], x); // Arguments are swapped and SLT is used.
}

inline void eq(Stack& stack) noexcept
Expand Down

0 comments on commit e86db4b

Please sign in to comment.