From 54570dc09a0de4c4773e9ca7a6fef80c3bcdfc2e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 4 May 2023 06:20:05 -0400 Subject: Fix MSVC build --- include/chilbert/detail/operations.hpp | 47 +++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'include/chilbert/detail/operations.hpp') diff --git a/include/chilbert/detail/operations.hpp b/include/chilbert/detail/operations.hpp index ba9971e..5dd59db 100644 --- a/include/chilbert/detail/operations.hpp +++ b/include/chilbert/detail/operations.hpp @@ -8,6 +8,11 @@ #include "chilbert/detail/traits.hpp" #include "chilbert/operators.hpp" +#ifdef _MSC_VER +# include +# include +#endif + #include #include #include @@ -86,25 +91,59 @@ set_bit(T& field, const size_t index, const bool value) field.set(index, value); } +#ifdef _MSC_VER + +inline uint32_t +pop_count(const uint32_t field) +{ + return __popcnt(field); +} + +inline uint64_t +pop_count(const uint64_t field) +{ + return __popcnt64(field); +} + +#else + /// Return 1 + the index of the least significant 1-bit of `field`, or zero template inline int -pop_count(const T& field); +pop_count(const T field); template<> inline int -pop_count(const unsigned long& field) +pop_count(const unsigned long field) { return __builtin_popcountl(field); } template<> inline int -pop_count(const unsigned long long& field) +pop_count(const unsigned long long field) { return __builtin_popcountll(field); } +#endif + +#ifdef _MSC_VER + +inline uint32_t +find_first(const uint32_t field) +{ + return field ? 1U + _tzcnt_u32(field) : 0U; +} + +inline uint64_t +find_first(const uint64_t field) +{ + return field ? 1U + _tzcnt_u64(field) : 0U; +} + +#else + /// Return 1 + the index of the least significant 1-bit of `field`, or zero template inline int @@ -124,6 +163,8 @@ find_first(const unsigned long long field) return __builtin_ffsll(static_cast(field)); } +#endif + /// Calculates the Gray Code of `value` in place template std::enable_if_t> -- cgit v1.2.1