Add a POPCNT64 macro

To count the number of 1/on bits in a 64-bit value
This commit is contained in:
Chris Robinson 2018-11-24 21:16:53 -08:00
parent 71660df5e5
commit f5f2cdaaf3

View File

@ -135,13 +135,21 @@ typedef ALuint64SOFT ALuint64;
#ifdef __GNUC__
#if SIZEOF_LONG == 8
#define POPCNT64 __builtin_popcountl
#define CTZ64 __builtin_ctzl
#else
#define POPCNT64 __builtin_popcountll
#define CTZ64 __builtin_ctzll
#endif
#elif defined(HAVE_BITSCANFORWARD64_INTRINSIC)
inline int msvc64_popcnt64(ALuint64 v)
{
return __popcnt64(v);
}
#define POPCNT64 msvc64_popcnt64
inline int msvc64_ctz64(ALuint64 v)
{
unsigned long idx = 64;
@ -152,6 +160,12 @@ inline int msvc64_ctz64(ALuint64 v)
#elif defined(HAVE_BITSCANFORWARD_INTRINSIC)
inline int msvc_popcnt64(ALuint64 v)
{
return __popcnt((ALuint)v) + __popcnt((ALuint)(v>>32));
}
#define POPCNT64 msvc_popcnt64
inline int msvc_ctz64(ALuint64 v)
{
unsigned long idx = 64;
@ -180,6 +194,7 @@ inline int fallback_popcnt64(ALuint64 v)
v = (v + (v >> 4)) & U64(0x0f0f0f0f0f0f0f0f);
return (int)((v * U64(0x0101010101010101)) >> 56);
}
#define POPCNT64 fallback_popcnt64
inline int fallback_ctz64(ALuint64 value)
{