From 3012c135cf39dc05b31d9223edc4772e4df108c4 Mon Sep 17 00:00:00 2001 From: Andrey Nefedov Date: Mon, 9 Dec 2024 17:55:18 +0000 Subject: [PATCH] Remove init_raw_base from zero-init big_mod --- .../multiprecision/modular/big_mod_impl.hpp | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/modular/big_mod_impl.hpp b/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/modular/big_mod_impl.hpp index 959c842bc7..57ceb6f657 100644 --- a/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/modular/big_mod_impl.hpp +++ b/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/modular/big_mod_impl.hpp @@ -45,6 +45,9 @@ namespace nil::crypto3::multiprecision { init_raw_base(m_raw_base, b, ops()); } + constexpr big_mod_impl(const modular_ops_storage_t& modular_ops_storage) + : m_modular_ops_storage(modular_ops_storage) {} + public: // Components @@ -105,12 +108,16 @@ namespace nil::crypto3::multiprecision { using typename base_type::modular_ops_storage_t; using typename base_type::modular_ops_t; - constexpr big_mod_ct_impl() : base_type(big_uint_t{}, {}) {} + constexpr big_mod_ct_impl() : base_type({}) {} template, int> = 0> constexpr big_mod_ct_impl(const T& b) : base_type(b, {}) {} // For generic code + + constexpr big_mod_ct_impl(const modular_ops_storage_t& ops_storage) + : base_type(ops_storage) {} + template, int> = 0> constexpr big_mod_ct_impl(const T& b, const modular_ops_storage_t& ops_storage) : base_type(b, ops_storage) {} @@ -127,11 +134,18 @@ namespace nil::crypto3::multiprecision { using typename base_type::modular_ops_storage_t; using typename base_type::modular_ops_t; + template, int> = 0> + constexpr big_mod_rt_impl(const T& m) : base_type(m) {} + template && detail::is_integral_v, int> = 0> + std::enable_if_t && detail::is_integral_v, int> = 0> constexpr big_mod_rt_impl(const T1& b, const T2& m) : base_type(b, m) {} // For generic code + + constexpr big_mod_rt_impl(const modular_ops_storage_t& ops_storage) + : base_type(ops_storage) {} + template, int> = 0> constexpr big_mod_rt_impl(const T& b, const modular_ops_storage_t& ops_storage) : base_type(b, ops_storage) {} @@ -229,7 +243,7 @@ namespace nil::crypto3::multiprecision { typename big_mod_t = std::conditional_t, T1, T2>> \ constexpr auto operator OP_(const T1& a, const T2& b) noexcept { \ const auto& ops_storage = detail::get_ops_storage_from_operands(a, b); \ - big_mod_t result(0u, ops_storage); \ + big_mod_t result(ops_storage); \ result.raw_base() = detail::convert_to_raw_base(a, ops_storage.ops()); \ ops_storage.ops().METHOD_(result.raw_base(), \ detail::convert_to_raw_base(b, ops_storage.ops())); \