Skip to content

Commit 3a89b7a

Browse files
const output and better assignment for output2
1 parent 1264a94 commit 3a89b7a

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

ryu/d2s.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ static inline int to_chars(const floating_decimal_64 v, const bool sign, char* c
318318
result[index++] = '-';
319319
}
320320

321-
uint64_t output = v.mantissa;
321+
const uint64_t output = v.mantissa;
322322
const uint32_t olength = decimalLength17(output);
323323

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

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

349349
const uint32_t c = output2 % 10000;
350-
output2 /= 10000;
351-
const uint32_t d = output2 % 10000;
350+
const uint32_t d = (output2 / 10000) % 10000;
352351
const uint32_t c0 = (c % 100) << 1;
353352
const uint32_t c1 = (c / 100) << 1;
354353
const uint32_t d0 = (d % 100) << 1;
@@ -357,9 +356,9 @@ static inline int to_chars(const floating_decimal_64 v, const bool sign, char* c
357356
memcpy(result + index + olength - 3, DIGIT_TABLE + c1, 2);
358357
memcpy(result + index + olength - 5, DIGIT_TABLE + d0, 2);
359358
memcpy(result + index + olength - 7, DIGIT_TABLE + d1, 2);
359+
output2 = (uint32_t) q;
360360
i += 8;
361361
}
362-
uint32_t output2 = (uint32_t) output;
363362
while (output2 >= 10000) {
364363
#ifdef __clang__ // https://bugs.llvm.org/show_bug.cgi?id=38217
365364
const uint32_t c = output2 - 10000 * (output2 / 10000);

0 commit comments

Comments
 (0)