From d27fe8a2293ce2957a2191e46d899beb65e15184 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Mon, 11 Oct 2021 13:15:11 -0700 Subject: [PATCH] util: fix consteval CountTrailingZeroes impl --- libraries/libvapours/include/vapours/util/util_bitutil.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/libvapours/include/vapours/util/util_bitutil.hpp b/libraries/libvapours/include/vapours/util/util_bitutil.hpp index f7acd98e8..f8be7402f 100644 --- a/libraries/libvapours/include/vapours/util/util_bitutil.hpp +++ b/libraries/libvapours/include/vapours/util/util_bitutil.hpp @@ -195,6 +195,7 @@ namespace ams::util { } static_assert(CountLeadingZeros(~static_cast(0)) == 0); + static_assert(CountLeadingZeros(static_cast(1) << 5) == BITSIZEOF(u64) - 1 - 5); static_assert(CountLeadingZeros(static_cast(0)) == BITSIZEOF(u64)); template requires std::integral @@ -202,6 +203,7 @@ namespace ams::util { if (std::is_constant_evaluated()) { auto count = 0; for (size_t i = 0; i < BITSIZEOF(T) && (x & 1) == 0; ++i) { + x >>= 1; ++count; } return count; @@ -226,6 +228,7 @@ namespace ams::util { } static_assert(CountTrailingZeros(~static_cast(0)) == 0); + static_assert(CountTrailingZeros(static_cast(1) << 5) == 5); static_assert(CountTrailingZeros(static_cast(0)) == BITSIZEOF(u64)); template requires std::integral