From 498486b1e56cd017fe7e122586bc13032f06964c Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Sat, 20 Jan 2024 23:49:24 +0100 Subject: [PATCH] Added usage of std::countr_zero, std::countl_zero from C++20 when available --- include/vk_mem_alloc.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/include/vk_mem_alloc.h b/include/vk_mem_alloc.h index 3d32608..4b224fb 100644 --- a/include/vk_mem_alloc.h +++ b/include/vk_mem_alloc.h @@ -2700,7 +2700,7 @@ VMA_CALL_PRE void VMA_CALL_POST vmaFreeStatsString( #include // For functions like __popcnt, _BitScanForward etc. #endif #if VMA_CPP20 - #include // For std::popcount + #include #endif #if VMA_STATS_STRING_ENABLED @@ -3352,6 +3352,10 @@ static inline uint8_t VmaBitScanLSB(uint64_t mask) if (_BitScanForward64(&pos, mask)) return static_cast(pos); return UINT8_MAX; +#elif VMA_CPP20 + if(mask) + return static_cast(std::countr_zero(mask)); + return UINT8_MAX; #elif defined __GNUC__ || defined __clang__ return static_cast(__builtin_ffsll(mask)) - 1U; #else @@ -3374,6 +3378,10 @@ static inline uint8_t VmaBitScanLSB(uint32_t mask) if (_BitScanForward(&pos, mask)) return static_cast(pos); return UINT8_MAX; +#elif VMA_CPP20 + if(mask) + return static_cast(std::countr_zero(mask)); + return UINT8_MAX; #elif defined __GNUC__ || defined __clang__ return static_cast(__builtin_ffs(mask)) - 1U; #else @@ -3395,6 +3403,9 @@ static inline uint8_t VmaBitScanMSB(uint64_t mask) unsigned long pos; if (_BitScanReverse64(&pos, mask)) return static_cast(pos); +#elif VMA_CPP20 + if(mask) + return 63 - static_cast(std::countl_zero(mask)); #elif defined __GNUC__ || defined __clang__ if (mask) return 63 - static_cast(__builtin_clzll(mask)); @@ -3417,6 +3428,9 @@ static inline uint8_t VmaBitScanMSB(uint32_t mask) unsigned long pos; if (_BitScanReverse(&pos, mask)) return static_cast(pos); +#elif VMA_CPP20 + if(mask) + return 31 - static_cast(std::countl_zero(mask)); #elif defined __GNUC__ || defined __clang__ if (mask) return 31 - static_cast(__builtin_clz(mask));