23constexpr inline void mul64x64_128(uint64_t a, uint64_t
b, uint64_t* lo, uint64_t* hi) {
24 if(!std::is_constant_evaluated()) {
25#if defined(BOTAN_BUILD_COMPILER_IS_MSVC) && defined(BOTAN_TARGET_ARCH_IS_X86_64)
26 *lo = _umul128(a,
b, hi);
29#elif defined(BOTAN_BUILD_COMPILER_IS_MSVC) && defined(BOTAN_TARGET_ARCH_IS_ARM64)
36#if defined(BOTAN_TARGET_HAS_NATIVE_UINT128)
37 const uint128_t r =
static_cast<uint128_t
>(a) *
b;
38 *hi = (r >> 64) & 0xFFFFFFFFFFFFFFFF;
39 *lo = (r) & 0xFFFFFFFFFFFFFFFF;
46 const size_t HWORD_BITS = 32;
47 const uint32_t HWORD_MASK = 0xFFFFFFFF;
49 const uint32_t a_hi = (a >> HWORD_BITS);
50 const uint32_t a_lo = (a & HWORD_MASK);
51 const uint32_t b_hi = (
b >> HWORD_BITS);
52 const uint32_t b_lo = (
b & HWORD_MASK);
54 const uint64_t x0 =
static_cast<uint64_t
>(a_hi) * b_hi;
55 const uint64_t x1 =
static_cast<uint64_t
>(a_lo) * b_hi;
56 const uint64_t x2 =
static_cast<uint64_t
>(a_hi) * b_lo;
57 const uint64_t x3 =
static_cast<uint64_t
>(a_lo) * b_lo;
60 const uint64_t middle = x2 + (x3 >> HWORD_BITS) + (x1 & HWORD_MASK);
63 *hi = x0 + (middle >> HWORD_BITS) + (x1 >> HWORD_BITS);
64 *lo = (middle << HWORD_BITS) + (x3 & HWORD_MASK);