83 constexpr auto r0 =
reduce0(DIVISOR);
84 if constexpr (r0.divisor == 1) {
86 constexpr uint32_t shift = r0.shift;
87 return [=](uint64_t dividend) {
88 return dividend >> shift;
91 constexpr uint32_t L = std::bit_width(r0.divisor);
92 constexpr uint64_t J = 0xffffffffffffffffULL % r0.divisor;
94 constexpr uint128 k = L64 / (0xffffffffffffffffULL - J);
95 constexpr uint128 m_low = L64 / r0.divisor;
96 constexpr uint128 m_high = (L64 + k) / r0.divisor;
97 constexpr auto r2 =
reduce2(m_low, m_high, L);
99 if constexpr (high64(r2.m_high) == 0) {
101 constexpr auto r1 =
reduce1(low64(r2.m_high), r0.shift + r2.l);
103 constexpr uint64_t mul = r1.m;
104 constexpr uint32_t shift = r1.s;
105 return [=](uint64_t dividend) {
106 return mla64(dividend, mul, 0) >> shift;
110 constexpr uint32_t
S = std::bit_width(r0.divisor) - 1;
112 constexpr uint128 dq = S64 / r0.divisor;
113 constexpr uint128 dr = S64 % r0.divisor;
114 constexpr uint64_t M = low64(dq) + (low64(dr) > (r0.divisor / 2));
115 constexpr auto r1 =
reduce1(M,
S + r0.shift);
117 constexpr uint64_t mul = r1.m;
118 constexpr uint32_t shift = r1.s;
119 return [=](uint64_t dividend) {
120 return mla64(dividend, mul, mul) >> shift;