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

Multiprecision refactoring: inverse mod and big_int improvements, checked big_uint operations #214

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
557af00
multiprecision: big_uint: clean up wnaf
ioxid Dec 16, 2024
7c7e82a
marshalling::multiprecision: remove boost includes
ioxid Dec 17, 2024
4f197c6
marshalling::multiprecision: clean up tests
ioxid Dec 17, 2024
fe86a97
multiprecision: big_uint: rename limbs_count
ioxid Dec 17, 2024
a1e31c5
multiprecision: big_uint: remove carry field, make operators checked …
ioxid Dec 17, 2024
4aa79bb
multiprecision: make benchmarks optimize correctly
ioxid Dec 17, 2024
c0e35fb
multiprecision: big_uint: optimize comparison
ioxid Dec 17, 2024
aac7947
multiprecision: add inverse benchmarks
ioxid Dec 17, 2024
b8ef425
multiprecision: refactor big_int and inverse_extended_euclidean_algor…
ioxid Dec 17, 2024
f86790e
multiprecision: throw on overflowing import
ioxid Dec 18, 2024
934a333
multiprecision: move import and export to class definition
ioxid Dec 18, 2024
eca8b41
multiprecision: simplify intrinsics logic
ioxid Dec 18, 2024
9b220cf
multiprecision: remove detail/type_traits and clean up
ioxid Dec 18, 2024
c4fc2bb
multiprecision: replace custom asserts with boost
ioxid Dec 18, 2024
29f2fd2
multiprecision: clean up formatting
ioxid Dec 18, 2024
9f3eefb
multiprecision: move more function inside classes
ioxid Dec 18, 2024
5d4901b
multiprecision: make internal methods private
ioxid Dec 18, 2024
62809e2
multiprecision: disable exception in import which fires in tests
ioxid Dec 18, 2024
d5122c3
multiprecision: move boost backend tests into a subdirectory
ioxid Dec 18, 2024
7affc91
multiprecision: rename tests
ioxid Dec 18, 2024
32714e1
multiprecision: remove examples
ioxid Dec 18, 2024
09d0221
multiprecision: add tests and fix bugs
ioxid Dec 18, 2024
81f11dd
multiprecision: update and fix copyrights
ioxid Dec 19, 2024
b8adb34
multiprecision: add custom and boost tests and fix bugs
ioxid Dec 19, 2024
5f977d3
multiprecision: rename tests
ioxid Dec 19, 2024
6e9889f
multiprecision: make casting to smaller type explicit
ioxid Dec 19, 2024
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
74 changes: 46 additions & 28 deletions crypto3/benchmarks/multiprecision/big_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <nil/crypto3/multiprecision/literals.hpp>
#include <nil/crypto3/multiprecision/big_mod.hpp>

#include <nil/crypto3/multiprecision/detail/big_mod/test_support.hpp>

#include <nil/crypto3/bench/benchmark.hpp>

using namespace nil::crypto3::multiprecision::literals;
Expand Down Expand Up @@ -51,15 +53,14 @@ BOOST_AUTO_TEST_SUITE(runtime_odd_tests)

// This directly calls montgomery mul from modular_ops.hpp.
BOOST_AUTO_TEST_CASE(montgomery_mul_perf_test) {
auto raw_base = x_mod_rt_odd.raw_base();
auto mod_ops = x_mod_rt_odd.ops();
auto raw_base = nil::crypto3::multiprecision::detail::get_raw_base(x_mod_rt_odd);
const auto &mod_ops = x_mod_rt_odd.ops_storage().ops();

nil::crypto3::bench::run_benchmark<>(
"[odd modulus][runtime] montgomery mul (direct call)",
[&]() {
mod_ops.mul(raw_base, y_mod_rt_odd.raw_base());
return raw_base;
});
"[odd modulus][runtime] montgomery mul (direct call)", [&]() {
mod_ops.mul(raw_base, nil::crypto3::multiprecision::detail::get_raw_base(y_mod_rt_odd));
return raw_base;
});

std::cout << raw_base << std::endl;
}
Expand Down Expand Up @@ -112,15 +113,14 @@ BOOST_AUTO_TEST_SUITE(compile_time_odd_tests)

// This directly calls montgomery mul from modular_ops.hpp.
BOOST_AUTO_TEST_CASE(montgomery_mul_perf_test) {
auto raw_base = x_mod_ct_odd.raw_base();
auto mod_ops = x_mod_ct_odd.ops();
auto raw_base = nil::crypto3::multiprecision::detail::get_raw_base(x_mod_ct_odd);
const auto &mod_ops = x_mod_ct_odd.ops_storage().ops(); // NOLINT

nil::crypto3::bench::run_benchmark<>(
"[odd modulus][compile time] montgomery mul (direct call)",
[&]() {
mod_ops.mul(raw_base, y_mod_ct_odd.raw_base());
return raw_base;
});
"[odd modulus][compile time] montgomery mul (direct call)", [&]() {
mod_ops.mul(raw_base, nil::crypto3::multiprecision::detail::get_raw_base(y_mod_ct_odd));
return raw_base;
});

std::cout << raw_base << std::endl;
}
Expand Down Expand Up @@ -173,15 +173,15 @@ BOOST_AUTO_TEST_SUITE(runtime_even_tests)

// This directly calls barrett mul from modular_ops.hpp.
BOOST_AUTO_TEST_CASE(barrett_mul_perf_test) {
auto raw_base = x_mod_rt_even.raw_base();
auto mod_ops = x_mod_rt_even.ops();
auto raw_base = nil::crypto3::multiprecision::detail::get_raw_base(x_mod_rt_even);
const auto &mod_ops = x_mod_rt_even.ops_storage().ops();

nil::crypto3::bench::run_benchmark<>(
"[even modulus][runtime] barrett mul (direct call)",
[&]() {
mod_ops.mul(raw_base, y_mod_rt_even.raw_base());
return raw_base;
});
"[even modulus][runtime] barrett mul (direct call)", [&]() {
mod_ops.mul(raw_base,
nil::crypto3::multiprecision::detail::get_raw_base(y_mod_rt_even));
return raw_base;
});

std::cout << raw_base << std::endl;
}
Expand Down Expand Up @@ -234,15 +234,15 @@ BOOST_AUTO_TEST_SUITE(compile_time_even_tests)

// This directly calls mul from modular_ops.hpp.
BOOST_AUTO_TEST_CASE(barrett_mul_perf_test) {
auto raw_base = x_mod_ct_even.raw_base();
auto mod_ops = x_mod_ct_even.ops();
auto raw_base = nil::crypto3::multiprecision::detail::get_raw_base(x_mod_ct_even);
const auto &mod_ops = x_mod_ct_even.ops_storage().ops(); // NOLINT

nil::crypto3::bench::run_benchmark<>(
"[even modulus][compile time] barrett mul (direct call)",
[&]() {
mod_ops.mul(raw_base, y_mod_ct_even.raw_base());
return raw_base;
});
"[even modulus][compile time] barrett mul (direct call)", [&]() {
mod_ops.mul(raw_base,
nil::crypto3::multiprecision::detail::get_raw_base(y_mod_ct_even));
return raw_base;
});

std::cout << raw_base << std::endl;
}
Expand Down Expand Up @@ -290,3 +290,21 @@ BOOST_AUTO_TEST_CASE(big_mod_mul_perf_test) {
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(compile_time_inverse_tests)

BOOST_AUTO_TEST_CASE(inverse_extended_euclidean_algorithm_test) {
auto x_modular = x_mod_ct_odd;

nil::crypto3::bench::run_benchmark<>(
"[odd modulus][compile time] inverse with extended euclidean algorithm", [&]() {
x_modular = inverse(x_modular);
++x_modular;
return x_modular;
});

// Print something so the whole computation is not optimized out.
std::cout << x_modular << std::endl;
}

BOOST_AUTO_TEST_SUITE_END()
Loading
Loading