diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 908999ab5f5d4..c52be81ca6ba1 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -558,6 +558,22 @@ inline void write_digit2_separated(char* buf, unsigned a, unsigned b, auto usep = static_cast(sep); // Add ASCII '0' to each digit byte and insert separators. digits |= 0x3030003030003030 | (usep << 16) | (usep << 40); +#ifndef _WIN32 +# if defined(__GNUC__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + digits = __builtin_bswap64(digits); +# else + if (is_big_endian()) { + digits = ((digits & 0xff00000000000000ull) >> 56) | + ((digits & 0x00ff000000000000ull) >> 40) | + ((digits & 0x0000ff0000000000ull) >> 24) | + ((digits & 0x000000ff00000000ull) >> 8) | + ((digits & 0x00000000ff000000ull) << 8) | + ((digits & 0x0000000000ff0000ull) << 24) | + ((digits & 0x000000000000ff00ull) << 40) | + ((digits & 0x00000000000000ffull) << 56); + } +# endif +#endif memcpy(buf, &digits, 8); }