Skip to content

Commit

Permalink
Add option to disable "computed goto" dispatch
Browse files Browse the repository at this point in the history
Add EVMC option cgoto=no to disable the "computed goto" dispatch
in Baseline.
  • Loading branch information
chfast committed Aug 23, 2022
1 parent 995ff38 commit 0f01455
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/evmone/baseline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,11 @@ evmc_result execute(const VM& vm, ExecutionState& state, const CodeAnalysis& ana
else
{
#if EVMONE_CGOTO_SUPPORTED
dispatch_cgoto(cost_table, state);
#else
dispatch<false>(cost_table, state, tracer);
if (vm.cgoto)
dispatch_cgoto(cost_table, state);
else
#endif
dispatch<false>(cost_table, state, tracer);
}

const auto gas_left =
Expand Down
13 changes: 13 additions & 0 deletions lib/evmone/vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ evmc_set_option_result set_option(evmc_vm* c_vm, char const* c_name, char const*
}
return EVMC_SET_OPTION_INVALID_VALUE;
}
else if (name == "cgoto")
{
#if EVMONE_CGOTO_SUPPORTED
if (value == "no")
{
vm.cgoto = false;
return EVMC_SET_OPTION_SUCCESS;
}
return EVMC_SET_OPTION_INVALID_VALUE;
#else
return EVMC_SET_OPTION_INVALID_NAME;
#endif
}
else if (name == "trace")
{
vm.add_tracer(create_instruction_tracer(std::cerr));
Expand Down
4 changes: 4 additions & 0 deletions lib/evmone/vm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ namespace evmone
/// The evmone EVMC instance.
class VM : public evmc_vm
{
public:
bool cgoto = EVMONE_CGOTO_SUPPORTED;

private:
std::unique_ptr<Tracer> m_first_tracer;

public:
Expand Down
12 changes: 12 additions & 0 deletions test/bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,13 @@ void register_benchmarks(const std::vector<BenchmarkCase>& benchmark_cases)
{
evmc::VM* advanced_vm = nullptr;
evmc::VM* baseline_vm = nullptr;
evmc::VM* basel_cg_vm = nullptr;
if (const auto it = registered_vms.find("advanced"); it != registered_vms.end())
advanced_vm = &it->second;
if (const auto it = registered_vms.find("baseline"); it != registered_vms.end())
baseline_vm = &it->second;
if (const auto it = registered_vms.find("bnocgoto"); it != registered_vms.end())
basel_cg_vm = &it->second;

for (const auto& b : benchmark_cases)
{
Expand Down Expand Up @@ -193,6 +196,14 @@ void register_benchmarks(const std::vector<BenchmarkCase>& benchmark_cases)
})->Unit(kMicrosecond);
}

if (basel_cg_vm != nullptr)
{
const auto name = "bnocgoto/execute/" + case_name;
RegisterBenchmark(name.c_str(), [&vm = *basel_cg_vm, &b, &input](State& state) {
bench_baseline_execute(state, vm, b.code, input.input, input.expected_output);
})->Unit(kMicrosecond);
}

for (auto& [vm_name, vm] : registered_vms)
{
const auto name = std::string{vm_name} + "/total/" + case_name;
Expand Down Expand Up @@ -308,6 +319,7 @@ int main(int argc, char** argv)

registered_vms["advanced"] = evmc::VM{evmc_create_evmone(), {{"O", "2"}}};
registered_vms["baseline"] = evmc::VM{evmc_create_evmone(), {{"O", "0"}}};
registered_vms["bnocgoto"] = evmc::VM{evmc_create_evmone(), {{"O", "0"}, {"cgoto", "no"}}};
register_benchmarks(benchmark_cases);
register_synthetic_benchmarks();
RunSpecifiedBenchmarks();
Expand Down
6 changes: 5 additions & 1 deletion test/unittests/evm_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ namespace
{
evmc::VM advanced_vm{evmc_create_evmone(), {{"O", "2"}}};
evmc::VM baseline_vm{evmc_create_evmone(), {{"O", "0"}}};
evmc::VM bnocgoto_vm{evmc_create_evmone(), {{"O", "0"}, {"cgoto", "no"}}};

const char* print_vm_name(const testing::TestParamInfo<evmc::VM*>& info) noexcept
{
if (info.param == &advanced_vm)
return "advanced";
if (info.param == &baseline_vm)
return "baseline";
if (info.param == &bnocgoto_vm)
return "bnocgoto";
return "unknown";
}
} // namespace

INSTANTIATE_TEST_SUITE_P(evmone, evm, testing::Values(&advanced_vm, &baseline_vm), print_vm_name);
INSTANTIATE_TEST_SUITE_P(
evmone, evm, testing::Values(&advanced_vm, &baseline_vm, &bnocgoto_vm), print_vm_name);
} // namespace evmone::test

0 comments on commit 0f01455

Please sign in to comment.