diff --git a/include/vk_mem_alloc.h b/include/vk_mem_alloc.h index 256b654..98aa40f 100644 --- a/include/vk_mem_alloc.h +++ b/include/vk_mem_alloc.h @@ -2574,6 +2574,9 @@ VMA_CALL_PRE void VMA_CALL_POST vmaFreeStatsString( #ifdef _MSC_VER #include // For functions like __popcnt, _BitScanForward etc. #endif +#if __cplusplus >= 202002L || _MSVC_LANG >= 202002L // C++20 + #include // For std::popcount +#endif /******************************************************************************* CONFIGURATION SECTION @@ -3176,12 +3179,16 @@ But you need to check in runtime whether user's CPU supports these, as some old */ static inline uint32_t VmaCountBitsSet(uint32_t v) { +#if __cplusplus >= 202002L || _MSVC_LANG >= 202002L // C++20 + return std::popcount(v); +#else uint32_t c = v - ((v >> 1) & 0x55555555); c = ((c >> 2) & 0x33333333) + (c & 0x33333333); c = ((c >> 4) + c) & 0x0F0F0F0F; c = ((c >> 8) + c) & 0x00FF00FF; c = ((c >> 16) + c) & 0x0000FFFF; return c; +#endif } static inline uint8_t VmaBitScanLSB(uint64_t mask)