1"""Misc integer tools.""" 2 3from __future__ import print_function, absolute_import, division 4from fontTools.misc.py23 import * 5 6__all__ = ['popCount'] 7 8 9def popCount(v): 10 """Return number of 1 bits in an integer.""" 11 12 if v > 0xFFFFFFFF: 13 return popCount(v >> 32) + popCount(v & 0xFFFFFFFF) 14 15 # HACKMEM 169 16 y = (v >> 1) & 0xDB6DB6DB 17 y = v - y - ((y >> 1) & 0xDB6DB6DB) 18 return (((y + (y >> 3)) & 0xC71C71C7) % 0x3F) 19