1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-25 12:12:50 +01:00

Implement std::countl_zero and friends

Trying to fix macos build.
This commit is contained in:
Nekotekina 2020-05-17 21:33:36 +03:00
parent 201d54ee08
commit ae519200ed

View File

@ -126,6 +126,53 @@ using s16 = std::int16_t;
using s32 = std::int32_t;
using s64 = std::int64_t;
#if __APPLE__
namespace std
{
template <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
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 <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
constexpr int countr_one(T x) noexcept
{
return countr_zero<T>(~x);
}
template <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
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 <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
constexpr int countl_one(T x) noexcept
{
return countl_zero<T>(~x);
}
}
#endif
using steady_clock = std::conditional<
std::chrono::high_resolution_clock::is_steady,
std::chrono::high_resolution_clock, std::chrono::steady_clock>::type;