diff --git a/Utilities/types.h b/Utilities/types.h index 0c75b6e9d8..1f0121d491 100644 --- a/Utilities/types.h +++ b/Utilities/types.h @@ -126,6 +126,53 @@ using s16 = std::int16_t; using s32 = std::int32_t; using s64 = std::int64_t; +#if __APPLE__ +namespace std +{ + template >> + constexpr int countr_zero(T x) noexcept + { + if (x == 0) + return sizeof(T) * 8; + if constexpr (sizeof(T) <= sizeof(uint)) + return __builtin_ctz(x); + else if constexpr (sizeof(T) <= sizeof(ulong)) + return __builtin_ctzl(x); + else if constexpr (sizeof(T) <= sizeof(ullong)) + return __builtin_ctzll(x); + else + static_assert(sizeof(T) <= sizeof(ullong)); + } + + template >> + constexpr int countr_one(T x) noexcept + { + return countr_zero(~x); + } + + template >> + constexpr int countl_zero(T x) noexcept + { + if (x == 0) + return sizeof(T) * 8; + if constexpr (sizeof(T) <= sizeof(uint)) + return __builtin_clz(x) - (sizeof(uint) - sizeof(T)) * 8; + else if constexpr (sizeof(T) <= sizeof(ulong)) + return __builtin_clzl(x) - (sizeof(ulong) - sizeof(T)) * 8; + else if constexpr (sizeof(T) <= sizeof(ullong)) + return __builtin_clzll(x) - (sizeof(ullong) - sizeof(T)) * 8; + else + static_assert(sizeof(T) <= sizeof(ullong)); + } + + template >> + constexpr int countl_one(T x) noexcept + { + return countl_zero(~x); + } +} +#endif + using steady_clock = std::conditional< std::chrono::high_resolution_clock::is_steady, std::chrono::high_resolution_clock, std::chrono::steady_clock>::type;