vppinfra: use popcnt instruction when available 11/12511/2
authorDamjan Marion <damarion@cisco.com>
Thu, 10 May 2018 01:04:08 +0000 (03:04 +0200)
committerDave Barach <openvpp@barachs.net>
Thu, 10 May 2018 11:36:56 +0000 (11:36 +0000)
Change-Id: Id02d613b8613a2d448840fe2d6a5e3b168a3c563
Signed-off-by: Damjan Marion <damarion@cisco.com>
src/vppinfra/bitops.h

index ab91b8a..17ad49f 100644 (file)
 always_inline uword
 count_set_bits (uword x)
 {
+#ifdef __POPCNT__
+#if uword_bits == 64
+  return __builtin_popcountll (x);
+#else
+  return __builtin_popcount (x);
+#endif
+#else
 #if uword_bits == 64
   const uword c1 = 0x5555555555555555;
   const uword c2 = 0x3333333333333333;
@@ -71,6 +78,7 @@ count_set_bits (uword x)
 #endif
 
   return x & (2 * BITS (uword) - 1);
+#endif
 }
 
 /* Based on "Hacker's Delight" code from GLS. */