Skip to content

Commit

Permalink
Replace mod_inv_25 by explicit value (#3450)
Browse files Browse the repository at this point in the history
  • Loading branch information
florimond-collette authored May 18, 2023
1 parent 4ce086f commit d60b907
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1131,11 +1131,8 @@ bool is_left_endpoint_integer_shorter_interval(int exponent) noexcept {
FMT_INLINE int remove_trailing_zeros(uint32_t& n, int s = 0) noexcept {
FMT_ASSERT(n != 0, "");
// Modular inverse of 5 (mod 2^32): (mod_inv_5 * 5) mod 2^32 = 1.
// See https://github.com/fmtlib/fmt/issues/3163 for more details.
const uint32_t mod_inv_5 = 0xcccccccd;
// Casts are needed to workaround a bug in MSVC 19.22 and older.
const uint32_t mod_inv_25 =
static_cast<uint32_t>(uint64_t(mod_inv_5) * mod_inv_5);
constexpr uint32_t mod_inv_5 = 0xcccccccd;
constexpr uint32_t mod_inv_25 = 0xc28f5c29; // = mod_inv_5 * mod_inv_5

while (true) {
auto q = rotr(n * mod_inv_25, 2);
Expand Down Expand Up @@ -1170,8 +1167,8 @@ FMT_INLINE int remove_trailing_zeros(uint64_t& n) noexcept {
}

// If n is not divisible by 10^8, work with n itself.
const uint64_t mod_inv_5 = 0xcccccccccccccccd;
const uint64_t mod_inv_25 = mod_inv_5 * mod_inv_5;
constexpr uint64_t mod_inv_5 = 0xcccccccccccccccd;
constexpr uint64_t mod_inv_25 = 0x8f5c28f5c28f5c29; // = mod_inv_5 * mod_inv_5

int s = 0;
while (true) {
Expand Down

0 comments on commit d60b907

Please sign in to comment.