diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:17 +0300 |
commit | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch) | |
tree | dd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/pop_count/popcount.h | |
parent | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff) | |
download | ydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/pop_count/popcount.h')
-rw-r--r-- | library/cpp/pop_count/popcount.h | 92 |
1 files changed, 46 insertions, 46 deletions
diff --git a/library/cpp/pop_count/popcount.h b/library/cpp/pop_count/popcount.h index 9833f039ff..3d67737ed2 100644 --- a/library/cpp/pop_count/popcount.h +++ b/library/cpp/pop_count/popcount.h @@ -6,11 +6,11 @@ #include <util/system/hi_lo.h> #include <util/system/platform.h> -#if defined(_MSC_VER) -#include <intrin.h> +#if defined(_MSC_VER) +#include <intrin.h> #endif -static inline ui32 PopCountImpl(ui8 n) { +static inline ui32 PopCountImpl(ui8 n) { #if defined(_ppc64_) ui32 r; __asm__("popcntb %0, %1" @@ -19,35 +19,35 @@ static inline ui32 PopCountImpl(ui8 n) { :); return r; #else - extern ui8 const* PopCountLUT8; - return PopCountLUT8[n]; + extern ui8 const* PopCountLUT8; + return PopCountLUT8[n]; #endif -} +} -static inline ui32 PopCountImpl(ui16 n) { -#if defined(_MSC_VER) - return __popcnt16(n); +static inline ui32 PopCountImpl(ui16 n) { +#if defined(_MSC_VER) + return __popcnt16(n); #else - extern ui8 const* PopCountLUT16; - return PopCountLUT16[n]; + extern ui8 const* PopCountLUT16; + return PopCountLUT16[n]; #endif -} +} -static inline ui32 PopCountImpl(ui32 n) { -#if defined(_MSC_VER) - return __popcnt(n); +static inline ui32 PopCountImpl(ui32 n) { +#if defined(_MSC_VER) + return __popcnt(n); #else -#if defined(_x86_64_) +#if defined(_x86_64_) if (NX86::CachedHavePOPCNT()) { - ui32 r; - - __asm__("popcnt %1, %0;" - : "=r"(r) - : "r"(n) - :); - - return r; - } + ui32 r; + + __asm__("popcnt %1, %0;" + : "=r"(r) + : "r"(n) + :); + + return r; + } #else #if defined(_ppc64_) ui32 r; @@ -58,28 +58,28 @@ static inline ui32 PopCountImpl(ui32 n) { :); return r; -#endif #endif - +#endif + return PopCountImpl((ui16)Lo16(n)) + PopCountImpl((ui16)Hi16(n)); #endif -} +} -static inline ui32 PopCountImpl(ui64 n) { +static inline ui32 PopCountImpl(ui64 n) { #if defined(_MSC_VER) && !defined(_i386_) - return __popcnt64(n); + return __popcnt64(n); #else -#if defined(_x86_64_) +#if defined(_x86_64_) if (NX86::CachedHavePOPCNT()) { - ui64 r; - - __asm__("popcnt %1, %0;" - : "=r"(r) - : "r"(n) - :); - - return r; - } + ui64 r; + + __asm__("popcnt %1, %0;" + : "=r"(r) + : "r"(n) + :); + + return r; + } #else #if defined(_ppc64_) ui32 r; @@ -90,16 +90,16 @@ static inline ui32 PopCountImpl(ui64 n) { :); return r; -#endif #endif - +#endif + return PopCountImpl((ui32)Lo32(n)) + PopCountImpl((ui32)Hi32(n)); #endif -} +} -template <class T> -static inline ui32 PopCount(T n) { +template <class T> +static inline ui32 PopCount(T n) { using TCvt = TFixedWidthUnsignedInt<T>; - return PopCountImpl((TCvt)n); + return PopCountImpl((TCvt)n); } |