-
Notifications
You must be signed in to change notification settings - Fork 307
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
Put instruction immediate values in the instruction table #154
base: master
Are you sure you want to change the base?
Changes from all commits
99a8c27
c7f283e
c955152
daac250
d3e21b4
276dabe
4403727
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,25 +83,25 @@ class evm_memory | |
void resize(size_t new_size) { m_memory.resize(new_size); } | ||
}; | ||
|
||
struct instr_info; | ||
union instr_info; | ||
|
||
struct block_info | ||
{ | ||
/// The total base gas cost of all instructions in the block. | ||
/// This cannot overflow, see the static_assert() below. | ||
int32_t gas_cost = 0; | ||
int32_t gas_cost; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why removing initializer? |
||
|
||
static_assert( | ||
max_code_size * max_instruction_base_cost < std::numeric_limits<decltype(gas_cost)>::max(), | ||
"Potential block_info::gas_cost overflow"); | ||
|
||
/// The stack height required to execute the block. | ||
/// This MAY overflow. | ||
int16_t stack_req = 0; | ||
int16_t stack_req; | ||
|
||
/// The maximum stack height growth relative to the stack height at block start. | ||
/// This cannot overflow, see the static_assert() below. | ||
int16_t stack_max_growth = 0; | ||
int16_t stack_max_growth; | ||
|
||
static_assert(max_code_size * max_instruction_stack_increase < | ||
std::numeric_limits<decltype(stack_max_growth)>::max(), | ||
|
@@ -143,16 +143,6 @@ struct execution_state | |
} | ||
}; | ||
|
||
union instr_argument | ||
{ | ||
int number; | ||
const uint8_t* data; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was this |
||
const intx::uint256* push_value; | ||
uint64_t small_push_value; | ||
block_info block{}; | ||
}; | ||
|
||
static_assert(sizeof(instr_argument) == sizeof(void*), "Incorrect size of instr_argument"); | ||
|
||
using exec_fn = const instr_info* (*)(const instr_info*, execution_state&); | ||
|
||
|
@@ -180,13 +170,15 @@ struct op_table_entry | |
|
||
using op_table = std::array<op_table_entry, 256>; | ||
|
||
struct instr_info | ||
union instr_info | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe some comment for this union? |
||
{ | ||
exec_fn fn = nullptr; | ||
instr_argument arg; | ||
|
||
explicit constexpr instr_info(exec_fn f) noexcept : fn{f}, arg{} {}; | ||
exec_fn fn; | ||
int number; | ||
const intx::uint256* push_value; | ||
uint64_t small_push_value; | ||
block_info block; | ||
}; | ||
static_assert(sizeof(instr_info) == sizeof(void*), "Incorrect size of instr_info"); | ||
|
||
static_assert(sizeof(block_info) == 8); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -546,7 +546,7 @@ const instr_info* op_jumpi(const instr_info* instr, execution_state& state) noex | |
|
||
const instr_info* op_pc(const instr_info* instr, execution_state& state) noexcept | ||
{ | ||
state.stack.push(instr->arg.number); | ||
state.stack.push((++instr)->number); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just a thought, maybe helpers like these could improve clarity
|
||
return ++instr; | ||
} | ||
|
||
|
@@ -558,7 +558,7 @@ const instr_info* op_msize(const instr_info* instr, execution_state& state) noex | |
|
||
const instr_info* op_gas(const instr_info* instr, execution_state& state) noexcept | ||
{ | ||
const auto correction = state.current_block_cost - instr->arg.number; | ||
const auto correction = state.current_block_cost - (++instr)->number; | ||
const auto gas = static_cast<uint64_t>(state.gas_left + correction); | ||
state.stack.push(gas); | ||
return ++instr; | ||
|
@@ -693,13 +693,13 @@ const instr_info* op_gaslimit(const instr_info* instr, execution_state& state) n | |
|
||
const instr_info* op_push_small(const instr_info* instr, execution_state& state) noexcept | ||
{ | ||
state.stack.push(instr->arg.small_push_value); | ||
state.stack.push((++instr)->small_push_value); | ||
return ++instr; | ||
} | ||
|
||
const instr_info* op_push_full(const instr_info* instr, execution_state& state) noexcept | ||
{ | ||
state.stack.push(*instr->arg.push_value); | ||
state.stack.push(*(++instr)->push_value); | ||
return ++instr; | ||
} | ||
|
||
|
@@ -794,7 +794,7 @@ const instr_info* op_revert(const instr_info*, execution_state& state) noexcept | |
template <evmc_call_kind kind> | ||
const instr_info* op_call(const instr_info* instr, execution_state& state) noexcept | ||
{ | ||
const auto arg = instr->arg; | ||
const auto arg = *(++instr); | ||
auto gas = state.stack[0]; | ||
const auto dst = intx::be::trunc<evmc::address>(state.stack[1]); | ||
auto value = state.stack[2]; | ||
|
@@ -916,7 +916,7 @@ const instr_info* op_call(const instr_info* instr, execution_state& state) noexc | |
|
||
const instr_info* op_delegatecall(const instr_info* instr, execution_state& state) noexcept | ||
{ | ||
const auto arg = instr->arg; | ||
const auto arg = *(++instr); | ||
auto gas = state.stack[0]; | ||
const auto dst = intx::be::trunc<evmc::address>(state.stack[1]); | ||
auto input_offset = state.stack[2]; | ||
|
@@ -985,7 +985,7 @@ const instr_info* op_delegatecall(const instr_info* instr, execution_state& stat | |
|
||
const instr_info* op_staticcall(const instr_info* instr, execution_state& state) noexcept | ||
{ | ||
const auto arg = instr->arg; | ||
const auto arg = *(++instr); | ||
auto gas = state.stack[0]; | ||
const auto dst = intx::be::trunc<evmc::address>(state.stack[1]); | ||
auto input_offset = state.stack[2]; | ||
|
@@ -1052,7 +1052,7 @@ const instr_info* op_create(const instr_info* instr, execution_state& state) noe | |
if (state.msg->flags & EVMC_STATIC) | ||
return state.exit(EVMC_STATIC_MODE_VIOLATION); | ||
|
||
const auto arg = instr->arg; | ||
const auto arg = *(++instr); | ||
auto endowment = state.stack[0]; | ||
auto init_code_offset = state.stack[1]; | ||
auto init_code_size = state.stack[2]; | ||
|
@@ -1111,7 +1111,7 @@ const instr_info* op_create2(const instr_info* instr, execution_state& state) no | |
if (state.msg->flags & EVMC_STATIC) | ||
return state.exit(EVMC_STATIC_MODE_VIOLATION); | ||
|
||
const auto arg = instr->arg; | ||
const auto arg = *(++instr); | ||
auto endowment = state.stack[0]; | ||
auto init_code_offset = state.stack[1]; | ||
auto init_code_size = state.stack[2]; | ||
|
@@ -1202,7 +1202,8 @@ const instr_info* op_selfdestruct(const instr_info*, execution_state& state) noe | |
|
||
const instr_info* opx_beginblock(const instr_info* instr, execution_state& state) noexcept | ||
{ | ||
auto& block = instr->arg.block; | ||
// FIXME: Do not use reference, check assembly. | ||
const auto& block = (++instr)->block; | ||
|
||
if ((state.gas_left -= block.gas_cost) < 0) | ||
return state.exit(EVMC_OUT_OF_GAS); | ||
|
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.
comment why 2x ?