mirror of
https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git
synced 2024-11-22 07:04:34 +00:00
Optimized VmaCountBitsSets to use std::popcount when C++20 is enabled
Closes #251
This commit is contained in:
parent
2d2a9e3df3
commit
0c7ad4e859
@ -2574,6 +2574,9 @@ VMA_CALL_PRE void VMA_CALL_POST vmaFreeStatsString(
|
||||
#ifdef _MSC_VER
|
||||
#include <intrin.h> // For functions like __popcnt, _BitScanForward etc.
|
||||
#endif
|
||||
#if __cplusplus >= 202002L || _MSVC_LANG >= 202002L // C++20
|
||||
#include <bit> // 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)
|
||||
|
Loading…
Reference in New Issue
Block a user