summaryrefslogtreecommitdiffstats
path: root/src/vppinfra
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2018-05-10 03:04:08 +0200
committerDave Barach <openvpp@barachs.net>2018-05-10 11:36:56 +0000
commit23e310a02520ca81b17f0ec1c9a04551550bb66c (patch)
tree0163c437339ae224121b77984970e44b61041bd1 /src/vppinfra
parent24793e3b4d3f23798390e5b399e8b9a7cc9ddabd (diff)
vppinfra: use popcnt instruction when available
Change-Id: Id02d613b8613a2d448840fe2d6a5e3b168a3c563 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra')
-rw-r--r--src/vppinfra/bitops.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/vppinfra/bitops.h b/src/vppinfra/bitops.h
index ab91b8ae443..17ad49ffb46 100644
--- a/src/vppinfra/bitops.h
+++ b/src/vppinfra/bitops.h
@@ -44,6 +44,13 @@
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. */