@@ -491,52 +491,58 @@ BOOST_INT128_FORCE_INLINE constexpr T knuth_div(const T& dividend, const T& divi
491491
492492 BOOST_INT128_IF_CONSTEXPR (!std::numeric_limits<T>::is_signed)
493493 {
494- T remainder{};
495- return impl::div_mod_msvc<false >(dividend, divisor, remainder);
494+ if (!BOOST_INT128_IS_CONSTANT_EVALUATED (dividend))
495+ {
496+ T remainder{};
497+ return impl::div_mod_msvc<false >(dividend, divisor, remainder);
498+ }
496499 }
497- else
500+
498501 #endif
499- {
500- std::uint32_t u[4 ]{};
501- std::uint32_t v[4 ]{};
502- std::uint32_t q[4 ]{};
503502
504- const auto m{ impl::to_words (dividend, u) };
505- const auto n{ impl::to_words (divisor, v) };
503+ std::uint32_t u[4 ]{};
504+ std::uint32_t v[4 ]{};
505+ std::uint32_t q[4 ]{};
506506
507- impl::knuth_divide<false >(u, m, v, n, q);
507+ const auto m{impl::to_words (dividend, u)};
508+ const auto n{impl::to_words (divisor, v)};
509+
510+ impl::knuth_divide<false >(u, m, v, n, q);
511+
512+ return impl::from_words<T>(q);
508513
509- return impl::from_words<T>(q);
510- }
511514}
512515
513516template <typename T>
514517BOOST_INT128_FORCE_INLINE constexpr T knuth_div (const T& dividend, const T& divisor, T& remainder) noexcept
515518{
516519 BOOST_INT128_ASSUME (divisor != static_cast <T>(0 ));
517-
520+
518521 #if defined(_M_AMD64) && !defined(__GNUC__) && !defined(__clang__) && _MSC_VER >= 1920
519522
520523 BOOST_INT128_IF_CONSTEXPR (!std::numeric_limits<T>::is_signed)
521524 {
522- return impl::div_mod_msvc<true >(dividend, divisor, remainder);
525+ if (!BOOST_INT128_IS_CONSTANT_EVALUATED (dividend))
526+ {
527+ return impl::div_mod_msvc<true >(dividend, divisor, remainder);
528+ }
523529 }
524- else
530+
531+
525532 #endif
526- {
527- std::uint32_t u[4 ]{};
528- std::uint32_t v[4 ]{};
529- std::uint32_t q[4 ]{};
530533
531- const auto m{ impl::to_words (dividend, u) };
532- const auto n{ impl::to_words (divisor, v) };
534+ std::uint32_t u[4 ]{};
535+ std::uint32_t v[4 ]{};
536+ std::uint32_t q[4 ]{};
533537
534- impl::knuth_divide<true >(u, m, v, n, q);
538+ const auto m{impl::to_words (dividend, u)};
539+ const auto n{impl::to_words (divisor, v)};
535540
536- remainder = impl::from_words<T >(u);
541+ impl::knuth_divide< true >(u, m, v, n, q );
537542
538- return impl::from_words<T>(q);
539- }
543+ remainder = impl::from_words<T>(u);
544+
545+ return impl::from_words<T>(q);
540546}
541547
542548#ifdef _MSC_VER
0 commit comments