Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 14 additions & 1 deletion include/boost/int128/detail/int128_imp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2052,12 +2052,20 @@ namespace detail {

BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr int128_t default_mul(const int128_t lhs, const std::uint64_t rhs) noexcept
{
#if defined(BOOST_INT128_HAS_INT128) && !defined(__s390__) && !defined(__s390x__)

return int128_t{static_cast<detail::builtin_u128>(lhs) * static_cast<detail::builtin_u128>(rhs)};

#else

return low_word_mul<int128_t>(lhs, rhs);

#endif
}

BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr int128_t default_mul(const int128_t lhs, const std::uint32_t rhs) noexcept
{
return low_word_mul<int128_t>(lhs, rhs);
return default_mul(lhs, static_cast<std::uint64_t>(rhs));
}

#if defined(_M_AMD64) && !defined(__GNUC__)
Expand Down Expand Up @@ -2131,6 +2139,11 @@ BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr int128_t default_mu
return msvc_amd64_mul(lhs, rhs);
}

#elif defined(BOOST_INT128_HAS_INT128) && !defined(__s390__) && !defined(__s390x__)

// Multiply in the unsigned domain to avoid signed-overflow UB, then reinterpret the bits.
return int128_t{static_cast<detail::builtin_u128>(lhs) * static_cast<detail::builtin_u128>(rhs)};

#else

return low_word_mul<int128_t>(lhs, rhs);
Expand Down
9 changes: 9 additions & 0 deletions include/boost/int128/detail/uint128_imp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,10 @@ BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr uint128_t default_a

return res;

#elif (defined(__x86_64__) || (defined(__aarch64__) && !defined(__APPLE__))) && !defined(_MSC_VER) && defined(BOOST_INT128_HAS_INT128)

return static_cast<uint128_t>(static_cast<detail::builtin_u128>(lhs) + static_cast<detail::builtin_u128>(rhs));

#else

uint128_t temp {lhs.high + rhs.high, lhs.low + rhs.low};
Expand Down Expand Up @@ -2306,6 +2310,11 @@ BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr uint128_t default_m
return msvc_mul(lhs, rhs);
}

#elif defined(BOOST_INT128_HAS_INT128) && !defined(__s390__) && !defined(__s390x__)
# define BOOST_INT128_HIDE_MUL

return static_cast<uint128_t>(static_cast<detail::builtin_u128>(lhs) * static_cast<detail::builtin_u128>(rhs));

#endif

// We need to hide this if we use a non-const eval method above to avoid a litany of cross-platform warnings
Expand Down
Loading