From b6e554d661cfef8e7de68b54872fea2f9348bfce Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Mon, 9 Sep 2019 11:23:48 -0700 Subject: [PATCH] Common header file change not directly applicable to open-vm-tools. --- open-vm-tools/lib/include/vm_basic_asm.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/open-vm-tools/lib/include/vm_basic_asm.h b/open-vm-tools/lib/include/vm_basic_asm.h index eadf00e5f..7e49f7d23 100644 --- a/open-vm-tools/lib/include/vm_basic_asm.h +++ b/open-vm-tools/lib/include/vm_basic_asm.h @@ -1194,6 +1194,9 @@ RoundUpPow2_32(uint32 value) static INLINE unsigned PopCount32(uint32 value) { +#if defined(__GNUC__) && !defined(FEWER_BUILTINS) && defined(__POPCNT__) + return __builtin_popcount(value); +#else /* * Attribution: * This algorithm was copied from: @@ -1237,6 +1240,7 @@ PopCount32(uint32 value) value += (value >> 8); value += (value >> 16); return value & 0x0000003f; +#endif } @@ -1259,6 +1263,13 @@ PopCount32(uint32 value) static INLINE unsigned PopCount64(uint64 value) { +#if defined(__GNUC__) && !defined(FEWER_BUILTINS) && defined(__POPCNT__) +#if defined(VM_X86_64) + return __builtin_popcountll(value); +#else + return PopCount32(value) + PopCount32(value >> 32); +#endif +#else value -= (value >> 1) & 0x5555555555555555ULL; value = ((value >> 2) & 0x3333333333333333ULL) + (value & 0x3333333333333333ULL); @@ -1267,6 +1278,7 @@ PopCount64(uint64 value) value += value >> 16; value += value >> 32; return (unsigned) (value & 0xff); +#endif } -- 2.47.3