#define BOOST_MP_ADD_UNSIGNED_ADDC_32_HPP
#include <boost/multiprecision/cpp_int/intel_intrinsics.hpp>
+#include <boost/multiprecision/detail/assert.hpp>
namespace boost { namespace multiprecision { namespace backends {
template <class CppInt1, class CppInt2, class CppInt3>
-inline BOOST_MP_CXX14_CONSTEXPR void add_unsigned_constexpr(CppInt1& result, const CppInt2& a, const CppInt3& b) BOOST_MP_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
+inline BOOST_MP_CXX14_CONSTEXPR void add_unsigned_constexpr(CppInt1& result, const CppInt2& a, const CppInt3& b) noexcept(is_non_throwing_cpp_int<CppInt1>::value)
{
using ::boost::multiprecision::std_constexpr::swap;
//
// Nothing fancy, just let uintmax_t take the strain:
//
double_limb_type carry = 0;
- unsigned m(0), x(0);
- unsigned as = a.size();
- unsigned bs = b.size();
+ std::size_t m(0), x(0);
+ std::size_t as = a.size();
+ std::size_t bs = b.size();
minmax(as, bs, m, x);
if (x == 1)
{
// Core subtraction routine for all non-trivial cpp_int's:
//
template <class CppInt1, class CppInt2, class CppInt3>
-inline BOOST_MP_CXX14_CONSTEXPR void subtract_unsigned_constexpr(CppInt1& result, const CppInt2& a, const CppInt3& b) BOOST_MP_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
+inline BOOST_MP_CXX14_CONSTEXPR void subtract_unsigned_constexpr(CppInt1& result, const CppInt2& a, const CppInt3& b) noexcept(is_non_throwing_cpp_int<CppInt1>::value)
{
using ::boost::multiprecision::std_constexpr::swap;
//
// Nothing fancy, just let uintmax_t take the strain:
//
double_limb_type borrow = 0;
- unsigned m(0), x(0);
+ std::size_t m(0), x(0);
minmax(a.size(), b.size(), m, x);
//
// special cases for small limb counts:
return;
}
- unsigned i = 0;
+ std::size_t i = 0;
// First where a and b overlap:
while (i < m)
{
// Any remaining digits are the same as those in pa:
if ((x != i) && (pa != pr))
std_constexpr::copy(pa + i, pa + x, pr + i);
- BOOST_ASSERT(0 == borrow);
+ BOOST_MP_ASSERT(0 == borrow);
//
// We may have lost digits, if so update limb usage count:
// are required to support these intrinsics.
//
template <class CppInt1, class CppInt2, class CppInt3>
-inline BOOST_MP_CXX14_CONSTEXPR void add_unsigned(CppInt1& result, const CppInt2& a, const CppInt3& b) BOOST_MP_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
+inline BOOST_MP_CXX14_CONSTEXPR void add_unsigned(CppInt1& result, const CppInt2& a, const CppInt3& b) noexcept(is_non_throwing_cpp_int<CppInt1>::value)
{
#ifndef BOOST_MP_NO_CONSTEXPR_DETECTION
if (BOOST_MP_IS_CONST_EVALUATED(a.size()))
using std::swap;
// Nothing fancy, just let uintmax_t take the strain:
- unsigned m(0), x(0);
- unsigned as = a.size();
- unsigned bs = b.size();
+ std::size_t m(0), x(0);
+ std::size_t as = a.size();
+ std::size_t bs = b.size();
minmax(as, bs, m, x);
if (x == 1)
{
if (as < bs)
swap(pa, pb);
// First where a and b overlap:
- unsigned i = 0;
+ std::size_t i = 0;
unsigned char carry = 0;
#if defined(BOOST_MSVC) && !defined(BOOST_HAS_INT128) && defined(_M_X64)
//
for (; i < m; ++i)
carry = ::boost::multiprecision::detail::addcarry_limb(carry, pa[i], pb[i], pr + i);
for (; i < x && carry; ++i)
- carry = ::boost::multiprecision::detail::addcarry_limb(carry, pa[i], 0, pr + i);
+ // We know carry is 1, so we just need to increment pa[i] (ie add a literal 1) and capture the carry:
+ carry = ::boost::multiprecision::detail::addcarry_limb(0, pa[i], 1, pr + i);
if (i == x && carry)
{
// We overflowed, need to add one more limb:
if (result.size() > x)
result.limbs()[x] = static_cast<limb_type>(1u);
}
- else
- std::copy(pa + i, pa + x, pr + i);
+ else if ((x != i) && (pa != pr))
+ // Copy remaining digits only if we need to:
+ std_constexpr::copy(pa + i, pa + x, pr + i);
result.normalize();
result.sign(a.sign());
}
}
template <class CppInt1, class CppInt2, class CppInt3>
-inline BOOST_MP_CXX14_CONSTEXPR void subtract_unsigned(CppInt1& result, const CppInt2& a, const CppInt3& b) BOOST_MP_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
+inline BOOST_MP_CXX14_CONSTEXPR void subtract_unsigned(CppInt1& result, const CppInt2& a, const CppInt3& b) noexcept(is_non_throwing_cpp_int<CppInt1>::value)
{
#ifndef BOOST_MP_NO_CONSTEXPR_DETECTION
if (BOOST_MP_IS_CONST_EVALUATED(a.size()))
using std::swap;
// Nothing fancy, just let uintmax_t take the strain:
- unsigned m(0), x(0);
+ std::size_t m(0), x(0);
minmax(a.size(), b.size(), m, x);
//
// special cases for small limb counts:
return;
}
- unsigned i = 0;
+ std::size_t i = 0;
unsigned char borrow = 0;
// First where a and b overlap:
#if defined(BOOST_MSVC) && !defined(BOOST_HAS_INT128) && defined(_M_X64)
// Any remaining digits are the same as those in pa:
if ((x != i) && (pa != pr))
std_constexpr::copy(pa + i, pa + x, pr + i);
- BOOST_ASSERT(0 == borrow);
+ BOOST_MP_ASSERT(0 == borrow);
//
// We may have lost digits, if so update limb usage count:
#else
template <class CppInt1, class CppInt2, class CppInt3>
-inline BOOST_MP_CXX14_CONSTEXPR void add_unsigned(CppInt1& result, const CppInt2& a, const CppInt3& b) BOOST_MP_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
+inline BOOST_MP_CXX14_CONSTEXPR void add_unsigned(CppInt1& result, const CppInt2& a, const CppInt3& b) noexcept(is_non_throwing_cpp_int<CppInt1>::value)
{
add_unsigned_constexpr(result, a, b);
}
template <class CppInt1, class CppInt2, class CppInt3>
-inline BOOST_MP_CXX14_CONSTEXPR void subtract_unsigned(CppInt1& result, const CppInt2& a, const CppInt3& b) BOOST_MP_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
+inline BOOST_MP_CXX14_CONSTEXPR void subtract_unsigned(CppInt1& result, const CppInt2& a, const CppInt3& b) noexcept(is_non_throwing_cpp_int<CppInt1>::value)
{
subtract_unsigned_constexpr(result, a, b);
}