diff --git a/src/util/mpz.cpp b/src/util/mpz.cpp index 9441d48617..38beee43a5 100644 --- a/src/util/mpz.cpp +++ b/src/util/mpz.cpp @@ -34,14 +34,14 @@ static bool mul_overflows(int64_t a, int64_t b, int64_t & result) { return std::ckd_mul(&result, a, b); #elif defined(__GNUC__) return __builtin_mul_overflow(a, b, &result); -#elif defined(_MSC_VER) && !defined(_M_ARM64) - // MSVC _mul128 intrinsic is unavailable when targeting ARM64. +#elif defined(_MSC_VER) && !defined(_M_ARM64) && !defined(_M_ARM64EC) + // MSVC _mul128 is available on the non-ARM64 targets that still use this path. __int64 high; result = _mul128(a, b, &high); // Overflow if high bits are not the sign extension of result return high != (result < 0 ? -1 : 0); #elif defined(_MSC_VER) - // `-(v + 1) + 1` computes |v| without ever evaluating -INT64_MIN. + // `-(v + 1) + 1` computes |v| even for INT64_MIN, where direct negation would overflow. uint64_t x = a < 0 ? static_cast(-(a + 1)) + 1 : static_cast(a); uint64_t y = b < 0 ? static_cast(-(b + 1)) + 1 : static_cast(b); bool is_neg = (a < 0) != (b < 0);