From 8e7199cbb60a4682a3d4c28d5746c1890c40e983 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 13 Aug 2020 14:04:29 -0700 Subject: Avoid a cmake check for determining the size of long --- common/alnumeric.h | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'common/alnumeric.h') diff --git a/common/alnumeric.h b/common/alnumeric.h index df05b966..61bfff8b 100644 --- a/common/alnumeric.h +++ b/common/alnumeric.h @@ -96,15 +96,27 @@ inline size_t RoundUp(size_t value, size_t r) noexcept */ #ifdef __GNUC__ +template +struct NumericDetail64 { }; +template<> +struct NumericDetail64 { + constexpr static inline auto popcnt64(unsigned long long val) noexcept + { return __builtin_popcountll(val); } + constexpr static inline auto ctz64(unsigned long long val) noexcept + { return __builtin_ctzll(val); } +}; +template<> +struct NumericDetail64 { + constexpr static inline auto popcnt64(unsigned long val) noexcept + { return __builtin_popcountl(val); } + constexpr static inline auto ctz64(unsigned long val) noexcept + { return __builtin_ctzl(val); } +}; + #define POPCNT32 __builtin_popcount #define CTZ32 __builtin_ctz -#if SIZEOF_LONG == 8 -#define POPCNT64 __builtin_popcountl -#define CTZ64 __builtin_ctzl -#else -#define POPCNT64 __builtin_popcountll -#define CTZ64 __builtin_ctzll -#endif +#define POPCNT64 NumericDetail64::popcnt64 +#define CTZ64 NumericDetail64::ctz64 #else -- cgit v1.2.3