Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

const output and better assignment for output2 #221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions ryu/d2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ static inline int to_chars(const floating_decimal_64 v, const bool sign, char* c
result[index++] = '-';
}

uint64_t output = v.mantissa;
const uint64_t output = v.mantissa;
const uint32_t olength = decimalLength17(output);

#ifdef RYU_DEBUG
Expand All @@ -336,19 +336,18 @@ static inline int to_chars(const floating_decimal_64 v, const bool sign, char* c
// result[index] = '0' + output % 10;

uint32_t i = 0;
uint32_t output2 = (uint32_t) output;
// We prefer 32-bit operations, even on 64-bit platforms.
// We have at most 17 digits, and uint32_t can store 9 digits.
// If output doesn't fit into uint32_t, we cut off 8 digits,
// so the rest will fit into uint32_t.
if ((output >> 32) != 0) {
// Expensive 64-bit division.
const uint64_t q = div1e8(output);
uint32_t output2 = ((uint32_t) output) - 100000000 * ((uint32_t) q);
output = q;
output2 = ((uint32_t) output) - 100000000 * ((uint32_t) q);

const uint32_t c = output2 % 10000;
output2 /= 10000;
const uint32_t d = output2 % 10000;
const uint32_t d = (output2 / 10000) % 10000;
const uint32_t c0 = (c % 100) << 1;
const uint32_t c1 = (c / 100) << 1;
const uint32_t d0 = (d % 100) << 1;
Expand All @@ -357,9 +356,9 @@ static inline int to_chars(const floating_decimal_64 v, const bool sign, char* c
memcpy(result + index + olength - 3, DIGIT_TABLE + c1, 2);
memcpy(result + index + olength - 5, DIGIT_TABLE + d0, 2);
memcpy(result + index + olength - 7, DIGIT_TABLE + d1, 2);
output2 = (uint32_t) q;
i += 8;
}
uint32_t output2 = (uint32_t) output;
while (output2 >= 10000) {
#ifdef __clang__ // https://bugs.llvm.org/show_bug.cgi?id=38217
const uint32_t c = output2 - 10000 * (output2 / 10000);
Expand Down
Loading