Skip to content

Commit dabfb9b

Browse files
committed
Add ARM64 128 x 128 mul impl
1 parent ebb9b68 commit dabfb9b

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

include/boost/int128/detail/uint128_imp.hpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,7 +2316,28 @@ BOOST_INT128_FORCE_INLINE uint128_t msvc_mul(const uint128_t lhs, const std::uin
23162316
return result;
23172317
}
23182318

2319-
#endif
2319+
#elif defined(_M_ARM64)
2320+
2321+
BOOST_INT128_FORCE_INLINE uint128_t msvc_mul(const uint128_t lhs, const uint128_t rhs) noexcept
2322+
{
2323+
const auto low_low{lhs.low * rhs.low};
2324+
const auto high_low{__umulh(lhs.low, rhs.low)};
2325+
2326+
const auto low_high{lhs.low * rhs.high};
2327+
const auto high_low{lhs.high * rhs.low};
2328+
2329+
const auto high{high_low + low_hi + hi_low};
2330+
2331+
return {high, low_low};
2332+
}
2333+
2334+
BOOST_INT128_FORCE_INLINE uint128_t msvc_mul(const uint128_t lhs, const std::uint64_t rhs) noexcept
2335+
{
2336+
const auto low{lhs.low * rhs};
2337+
2338+
}
2339+
2340+
#endif // MSVC implementations
23202341

23212342
template <typename UnsignedInteger>
23222343
BOOST_INT128_FORCE_INLINE constexpr uint128_t default_mul(const uint128_t lhs, const UnsignedInteger rhs) noexcept
@@ -2354,7 +2375,7 @@ BOOST_INT128_FORCE_INLINE constexpr uint128_t default_mul(const uint128_t lhs, c
23542375

23552376
return static_cast<uint128_t>(static_cast<builtin_u128>(lhs) * static_cast<builtin_u128>(rhs));
23562377

2357-
#elif defined(_M_AMD64) && !defined(__GNUC__) && !defined(BOOST_INT128_NO_CONSTEVAL_DETECTION)
2378+
#elif ((defined(_M_AMD64) && !defined(__GNUC__)) || defined(_M_ARM64)) && !defined(BOOST_INT128_NO_CONSTEVAL_DETECTION)
23582379

23592380
if (!BOOST_INT128_IS_CONSTANT_EVALUATED(lhs))
23602381
{

0 commit comments

Comments
 (0)