Skip to content
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

EVMMAX: Base C++ API for prototyping #673

Merged
merged 3 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
bench: Add evmmax/ModArith benchmarks for uint256
  • Loading branch information
chfast committed Jul 31, 2023
commit 7f8d549104a6314dbb131c1385506eb393f92c98
3 changes: 2 additions & 1 deletion test/internal_benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

add_executable(
evmone-bench-internal
evmmax_bench.cpp
find_jumpdest_bench.cpp
memory_allocation.cpp
)

target_link_libraries(evmone-bench-internal PRIVATE benchmark::benchmark)
target_link_libraries(evmone-bench-internal PRIVATE evmone::evmmax benchmark::benchmark)
63 changes: 63 additions & 0 deletions test/internal_benchmarks/evmmax_bench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2023 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

#include <benchmark/benchmark.h>
#include <evmmax/evmmax.hpp>

using namespace intx;

namespace
{
constexpr auto bn254 = 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47_u256;
constexpr auto secp256k1 = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f_u256;

template <typename UintT, const UintT& Mod>
void evmmax_add(benchmark::State& state)
{
const evmmax::ModArith<UintT> m{Mod};
auto a = Mod / 2;
auto b = Mod / 3;

while (state.KeepRunningBatch(2))
{
a = m.add(a, b);
b = m.add(b, a);
}
}

template <typename UintT, const UintT& Mod>
void evmmax_sub(benchmark::State& state)
{
const evmmax::ModArith<UintT> m{Mod};
auto a = Mod / 2;
auto b = Mod / 3;

while (state.KeepRunningBatch(2))
{
a = m.sub(a, b);
b = m.sub(b, a);
}
}

template <typename UintT, const UintT& Mod>
void evmmax_mul(benchmark::State& state)
{
const evmmax::ModArith<UintT> m{Mod};
auto a = m.to_mont(Mod / 2);
auto b = m.to_mont(Mod / 3);

while (state.KeepRunningBatch(2))
{
a = m.mul(a, b);
b = m.mul(b, a);
}
}
} // namespace

BENCHMARK_TEMPLATE(evmmax_add, uint256, bn254);
BENCHMARK_TEMPLATE(evmmax_add, uint256, secp256k1);
BENCHMARK_TEMPLATE(evmmax_sub, uint256, bn254);
BENCHMARK_TEMPLATE(evmmax_sub, uint256, secp256k1);
BENCHMARK_TEMPLATE(evmmax_mul, uint256, bn254);
BENCHMARK_TEMPLATE(evmmax_mul, uint256, secp256k1);