diff options
author | Chris Robinson <[email protected]> | 2020-08-13 14:04:29 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2020-08-13 14:04:29 -0700 |
commit | 8e7199cbb60a4682a3d4c28d5746c1890c40e983 (patch) | |
tree | 7344fb64ad696c0f1252c8d0e06ad3305fd9b9f5 | |
parent | fd52c828a9c4f4bb7ed3a4dcfe4a5b4ed5664246 (diff) |
Avoid a cmake check for determining the size of long
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | common/alnumeric.h | 26 | ||||
-rw-r--r-- | config.h.in | 3 |
3 files changed, 19 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8fe3c8de..e7f2f460 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,6 @@ include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) include(CheckCSourceCompiles) include(CheckCXXSourceCompiles) -include(CheckTypeSize) include(CheckStructHasMember) include(GNUInstallDirs) @@ -128,9 +127,6 @@ set(LIB_VERSION_NUM ${LIB_MAJOR_VERSION},${LIB_MINOR_VERSION},${LIB_REVISION},0) set(EXPORT_DECL "") -check_type_size("long" SIZEOF_LONG) - - # Require C++14 set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 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<typename T> +struct NumericDetail64 { }; +template<> +struct NumericDetail64<unsigned long long> { + 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<unsigned long> { + 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<uint64_t>::popcnt64 +#define CTZ64 NumericDetail64<uint64_t>::ctz64 #else diff --git a/config.h.in b/config.h.in index 2de3640e..bd87f4fe 100644 --- a/config.h.in +++ b/config.h.in @@ -77,9 +77,6 @@ /* Define if we have the SDL2 backend */ #cmakedefine HAVE_SDL2 -/* Define to the size of a long int type */ -#cmakedefine SIZEOF_LONG ${SIZEOF_LONG} - /* Define if we have dlfcn.h */ #cmakedefine HAVE_DLFCN_H |