]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Common header file change not directly applicable to open-vm-tools.
authorOliver Kurth <okurth@vmware.com>
Mon, 9 Sep 2019 18:23:48 +0000 (11:23 -0700)
committerOliver Kurth <okurth@vmware.com>
Mon, 9 Sep 2019 18:23:48 +0000 (11:23 -0700)
open-vm-tools/lib/include/vm_basic_asm.h

index eadf00e5fca31e67fb447c396256dd243b4243a8..7e49f7d23af0493291dfca5deb717a4fe0c74a9f 100644 (file)
@@ -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
 }