From b5f4f2fc4b011dea486c27c9270e8499d8f4bc5c Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sun, 15 Apr 2018 00:10:38 +0200 Subject: [PATCH] Finish splitting m_core_clz into m_core_clz32 & m_core_clz64 --- README.md | 3 ++- m-array.h | 2 +- m-core.h | 4 ++-- m-string.h | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 22e7d5aa..148ff506 100644 --- a/README.md +++ b/README.md @@ -3764,7 +3764,8 @@ n shall be within 1 and the number of bits of the type minus 1. Round to the next highest power of 2. -##### unsigned int m_core_clz(unsigned long limb) +##### unsigned int m_core_clz32(uint32\_t limb) +##### unsigned int m_core_clz64(uint64\_t limb) Count the number of leading zero and return it. limb can be 0. diff --git a/m-array.h b/m-array.h index e219cdec..b817632f 100644 --- a/m-array.h +++ b/m-array.h @@ -641,7 +641,7 @@ assert (size > 1); \ /* Let's select the threshold of the pass 1 to be sure \ the final result is in tab.*/ \ - if (m_core_clz(size-1) & 1) \ + if (m_core_clz64(size-1) & 1) \ th += th; \ \ /* Pass 1: insertion sort (stable) */ \ diff --git a/m-core.h b/m-core.h index 6bc273dc..f788c4ae 100644 --- a/m-core.h +++ b/m-core.h @@ -1277,7 +1277,7 @@ static inline uint64_t m_core_roundpow2(uint64_t v) /* Return the count leading zero of the argument */ #if defined(__GNUC__) && (__GNUC__*100 + __GNUC_MINOR__) >= 304 -static inline unsigned int m_core_clz(uint32_t limb) +static inline unsigned int m_core_clz32(uint32_t limb) { return M_UNLIKELY (limb == 0) ? sizeof(uint32_t)*CHAR_BIT : __builtin_clzl(limb) - (sizeof(unsigned long) - sizeof(uint32_t)) * CHAR_BIT; } @@ -1288,7 +1288,7 @@ static inline unsigned int m_core_clz64(uint64_t limb) #else #define M_CORE_CLZ_TAB "\010\07\06\06\05\05\05\05\04\04\04\04\04\04\04\04\03\03\03\03\03\03\03\03\03\03\03\03\03\03\03\03\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00" -static inline unsigned int m_core_clz(uint32_t limb) +static inline unsigned int m_core_clz32(uint32_t limb) { unsigned int shift = 0; /* This code should be branchless on most targets */ diff --git a/m-string.h b/m-string.h index fa0a5038..f633d57c 100644 --- a/m-string.h +++ b/m-string.h @@ -861,7 +861,7 @@ typedef unsigned int string_unicode_t; static inline void stringi_utf8_decode(char c, stringi_utf8_state_e *state, string_unicode_t *unicode) { - const int type = m_core_clz((unsigned char)~c) - (sizeof(uint32_t) - 1) * CHAR_BIT; + const int type = m_core_clz32((unsigned char)~c) - (sizeof(uint32_t) - 1) * CHAR_BIT; const string_unicode_t mask1 = -(string_unicode_t)(*state != STRINGI_UTF8_STARTING); const string_unicode_t mask2 = (0xFFU >> type); *unicode = ((*unicode << 6) & mask1) | (c & mask2);