Skip to content

Commit ce01335

Browse files
committed
Reduce conditional compilation
1 parent 4f718c5 commit ce01335

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

zmij.cc

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,22 @@ constexpr auto pack8(uint8_t a, uint8_t b, uint8_t c, uint8_t d, //
526526
// the significand has length 16.
527527
auto write_significand17(char* buffer, uint64_t value,
528528
bool has17digits) noexcept -> char* {
529+
if (!ZMIJ_USE_NEON && !ZMIJ_USE_SSE) {
530+
char* start = buffer + 1;
531+
// Each digit is denoted by a letter so value is abbccddeeffgghhii.
532+
uint32_t abbccddee = uint32_t(value / 100'000'000);
533+
uint32_t ffgghhii = uint32_t(value % 100'000'000);
534+
buffer = write_if(start, abbccddee / 100'000'000, has17digits);
535+
uint64_t bcd = to_bcd8(abbccddee % 100'000'000);
536+
write8(buffer, bcd | zeros);
537+
if (ffgghhii == 0) {
538+
buffer += count_trailing_nonzeros(bcd);
539+
return buffer - int(buffer - start == 1);
540+
}
541+
bcd = to_bcd8(ffgghhii);
542+
write8(buffer + 8, bcd | zeros);
543+
return buffer + 8 + count_trailing_nonzeros(bcd);
544+
}
529545
#if ZMIJ_USE_NEON
530546
// An optimized version for NEON by Dougall Johnson.
531547
constexpr int32_t neg10k = -10000 + 0x10000;
@@ -677,22 +693,7 @@ auto write_significand17(char* buffer, uint64_t value,
677693

678694
_mm_storeu_si128(reinterpret_cast<__m128i*>(buffer), digits);
679695
return buffer + ((last_digit != 0) ? 17 : len - (len == 1));
680-
#else // !ZMIJ_USE_NEON && !ZMIJ_USE_SSE
681-
char* start = buffer + 1;
682-
// Each digit is denoted by a letter so value is abbccddeeffgghhii.
683-
uint32_t abbccddee = uint32_t(value / 100'000'000);
684-
uint32_t ffgghhii = uint32_t(value % 100'000'000);
685-
buffer = write_if(start, abbccddee / 100'000'000, has17digits);
686-
uint64_t bcd = to_bcd8(abbccddee % 100'000'000);
687-
write8(buffer, bcd | zeros);
688-
if (ffgghhii == 0) {
689-
buffer += count_trailing_nonzeros(bcd);
690-
return buffer - int(buffer - start == 1);
691-
}
692-
bcd = to_bcd8(ffgghhii);
693-
write8(buffer + 8, bcd | zeros);
694-
return buffer + 8 + count_trailing_nonzeros(bcd);
695-
#endif
696+
#endif // ZMIJ_USE_SSE
696697
}
697698

698699
// Writes a significand consisting of up to 9 decimal digits (7-9 for normals)

0 commit comments

Comments
 (0)