From 6fb4ac73f94636d19fcac143472b84f9d91985c9 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 15 Oct 2017 16:00:09 +0200 Subject: [PATCH] Add popcount for 64bit ints --- src/hb-private.hh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/hb-private.hh b/src/hb-private.hh index ea6a8fa47..7f5cd697b 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -333,6 +333,18 @@ _hb_popcount32 (uint32_t mask) return (((y + (y >> 3)) & 030707070707) % 077); #endif } +static inline HB_CONST_FUNC unsigned int +_hb_popcount64 (uint64_t mask) +{ +#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) + return __builtin_popcountl (mask); +#else + return _hb_popcount32 (mask) + _hb_popcount32 (mask >> 32); +#endif +} +template static inline unsigned int _hb_popcount (T mask); +template <> inline unsigned int _hb_popcount (uint32_t mask) { return _hb_popcount32 (mask); } +template <> inline unsigned int _hb_popcount (uint64_t mask) { return _hb_popcount64 (mask); } /* Returns the number of bits needed to store number */ static inline HB_CONST_FUNC unsigned int