From: Damjan Marion Date: Thu, 10 May 2018 01:04:08 +0000 (+0200) Subject: vppinfra: use popcnt instruction when available X-Git-Tag: v18.07-rc1~362 X-Git-Url: https://gerrit.fd.io/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F11%2F12511%2F2;p=vpp.git vppinfra: use popcnt instruction when available Change-Id: Id02d613b8613a2d448840fe2d6a5e3b168a3c563 Signed-off-by: Damjan Marion --- 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. */