From cbc46d9e78f6935b83ca233f6f2c2fff533ab1ef Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 21 Feb 2015 06:21:29 -0800 Subject: [PATCH] Use __builtin_clz whenever it is available --- format.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/format.h b/format.h index cfad735f..7a71ddc1 100644 --- a/format.h +++ b/format.h @@ -581,13 +581,6 @@ inline unsigned count_digits(uint64_t n) { unsigned t = (64 - FMT_BUILTIN_CLZLL(n | 1)) * 1233 >> 12; return t - (n < Data::POWERS_OF_10_64[t]) + 1; } -# ifdef FMT_BUILTIN_CLZ -// Optional version of count_digits for better performance on 32-bit platforms. -inline unsigned count_digits(uint32_t n) { - uint32_t t = (32 - FMT_BUILTIN_CLZ(n | 1)) * 1233 >> 12; - return t - (n < Data::POWERS_OF_10_32[t]) + 1; -} -# endif #else // Fallback version of count_digits used when __builtin_clz is not available. inline unsigned count_digits(uint64_t n) { @@ -606,6 +599,14 @@ inline unsigned count_digits(uint64_t n) { } #endif +#ifdef FMT_BUILTIN_CLZ +// Optional version of count_digits for better performance on 32-bit platforms. +inline unsigned count_digits(uint32_t n) { + uint32_t t = (32 - FMT_BUILTIN_CLZ(n | 1)) * 1233 >> 12; + return t - (n < Data::POWERS_OF_10_32[t]) + 1; +} +#endif + // Formats a decimal unsigned integer value writing into buffer. template inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) {