Skip to content

Commit

Permalink
A small optimization turning mul into lea
Browse files Browse the repository at this point in the history
  • Loading branch information
jk-jeon committed Feb 22, 2022
1 parent 6bf0140 commit a84c11e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions source/dragonbox_to_chars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,20 +243,20 @@ namespace jkj::dragonbox {
if (exponent >= 100) {
// d1 = exponent / 10; d2 = exponent % 10;
// 6554 = ceil(2^16 / 10)
auto prod = std::uint32_t(exponent) * 6554;
auto prod = std::uint32_t(exponent) * std::uint32_t(6554);
auto d1 = prod >> 16;
prod = std::uint16_t(prod) * 10;
auto d2 = prod >> 16;
prod = std::uint16_t(prod) * std::uint32_t(5); // * 10
auto d2 = prod >> 15; // >> 16
std::memcpy(buffer, &radix_100_table[d1 * 2], 2);
buffer[2] = (char)('0' + d2);
buffer[2] = char('0' + d2);
buffer += 3;
}
else if (exponent >= 10) {
std::memcpy(buffer, &radix_100_table[exponent * 2], 2);
buffer += 2;
}
else {
buffer[0] = (char)('0' + exponent);
buffer[0] = char('0' + exponent);
buffer += 1;
}

Expand Down

0 comments on commit a84c11e

Please sign in to comment.