Skip to content

Commit

Permalink
Remove unneccesary specialization #312
Browse files Browse the repository at this point in the history
Removed macos specialization
  • Loading branch information
vo-nil committed Aug 22, 2024
1 parent e0df9de commit b6f7694
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -636,30 +636,11 @@ namespace nil {

/// https://zips.z.cash/protocol/protocol.pdf#concreteextractorjubjub
template<typename TIter>
static typename std::enable_if<
!std::is_same<bool, typename std::iterator_traits<TIter>::value_type>::value,
nil::marshalling::status_type>::type
static nil::marshalling::status_type
process(const group_value_type &point, TIter &iter) {
write_data<params_type::bit_length(), endianness>(
static_cast<typename group_value_type::field_type::integral_type>(point.to_affine().X.data),
iter);

return nil::marshalling::status_type::success;
}

// TODO: refactor
template<typename TIter>
static typename std::enable_if<
std::is_same<bool, typename std::iterator_traits<TIter>::value_type>::value,
nil::marshalling::status_type>::type
process(const group_value_type &point, TIter &iter) {
auto X_affine = static_cast<typename group_value_type::field_type::integral_type>(
point.to_affine().X.data);
for (std::size_t i = 0; i < params_type::bit_length(); ++i) {
*iter++ = bit_test(X_affine, 0);
X_affine >>= 1;
}

return nil::marshalling::status_type::success;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <limits>
#include <iterator>

#include <nil/crypto3/multiprecision/cpp_int_modular.hpp>
#include <nil/marshalling/endianness.hpp>

namespace nil {
Expand Down
2 changes: 1 addition & 1 deletion libs/marshalling/multiprecision/test/integral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ T generate_random() {
static boost::random::uniform_int_distribution<unsigned> ui(0, limbs);
static boost::random::mt19937 gen;
T val = gen();
unsigned lim = ui(gen);
unsigned lim = ui(gen);
for (unsigned i = 0; i < lim; ++i) {
val *= (gen.max)();
val += gen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <climits>
#include <cstring>

#include <boost/predef/os/macos.h>
#include <boost/multiprecision/traits/std_integer_traits.hpp>
#include <boost/multiprecision/detail/endian.hpp>
#include <boost/multiprecision/cpp_int/import_export.hpp> // For 'extract_bits'.
Expand All @@ -18,6 +17,10 @@ namespace boost {
namespace multiprecision {
namespace detail {

/* This specialization is used when assigning `chunk_bits`
* of `bits` into `val` at `bit_location` in case where `val`
* is larger than one limb (machine word).
*/
template<unsigned Bits, class Unsigned>
void assign_bits(boost::multiprecision::backends::cpp_int_modular_backend<Bits>& val,
Unsigned bits, std::size_t bit_location, std::size_t chunk_bits,
Expand All @@ -37,29 +40,23 @@ namespace boost {
val.limbs()[limb] |= value;
}

if (chunk_bits > sizeof(limb_type) * CHAR_BIT - shift) {
shift = sizeof(limb_type) * CHAR_BIT - shift;
chunk_bits -= shift;
bit_location += shift;
bits >>= shift;
if (bits)
assign_bits(val, bits, bit_location, chunk_bits, tag);
/* If some bits need to be assigned to the next limb */
if constexpr (!std::is_same<std::__bit_const_reference<std::vector<bool>>, Unsigned>::value) {
if (chunk_bits > sizeof(limb_type) * CHAR_BIT - shift) {
shift = sizeof(limb_type) * CHAR_BIT - shift;
chunk_bits -= shift;
bit_location += shift;
bits >>= shift;
if (bits)
assign_bits(val, bits, bit_location, chunk_bits, tag);
}
}
}

#ifdef BOOST_OS_MACOS_AVAILABLE
// Especially for mac, for the case when a vector<bool> is being converted to a number.
// When you dereference an iterator to std::vector<bool> you will receive
// std::__bit_const_reference<std::vector<bool>>>.
template<unsigned Bits>
void assign_bits(boost::multiprecision::backends::cpp_int_modular_backend<Bits>& val,
std::__bit_const_reference<std::vector<bool>> bits,
std::size_t bit_location, std::size_t chunk_bits,
const std::integral_constant<bool, false>& tag) {
assign_bits(val, static_cast<bool>(bits), bit_location, chunk_bits, tag);
}
#endif

/* This specialization is used when assigning `chunk_bits`
* of `bits` into `val` at `bit_location` in case where `val`
* fits into one limb (machine word).
*/
template<unsigned Bits, class Unsigned>
void assign_bits(boost::multiprecision::backends::cpp_int_modular_backend<Bits>& val,
Unsigned bits, std::size_t bit_location, std::size_t chunk_bits,
Expand Down

0 comments on commit b6f7694

Please sign in to comment.