popcount function

int popcount(
  1. int bb
)

Number of set bits. Kernighan's method; fine for eval-frequency use.

Implementation

int popcount(int bb) {
  var n = 0;
  while (bb != 0) {
    bb &= bb - 1;
    n++;
  }
  return n;
}