Skip to content

Commit

Permalink
Removed macos specialization
Browse files Browse the repository at this point in the history
  • Loading branch information
aleasims committed Aug 22, 2024
1 parent d029523 commit 9aa861a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
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 9aa861a

Please sign in to comment.