Skip to content

Commit

Permalink
rename popcount64() -> popcnt_64(), fix issue #189
Browse files Browse the repository at this point in the history
  • Loading branch information
ilanschnell committed Feb 20, 2023
1 parent 2db5357 commit d8ce774
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bitarray/_bitarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ count(bitarrayobject *self, Py_ssize_t a, Py_ssize_t b)
uint64_t tmp = 0;
/* copy bytes we want to count into tmp word */
memcpy((char *) &tmp, self->ob_item + byte_a, byte_b - byte_a);
cnt += popcount64(tmp);
cnt += popcnt_64(tmp);
}
cnt += count(self, 8 * byte_b, b);
}
Expand Down
32 changes: 16 additions & 16 deletions bitarray/_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ count_n_core(bitarrayobject *a, Py_ssize_t n, int vi)
#undef BLOCK_BITS

while (i + 64 < nbits) { /* count blocks of single (64-bit) words */
m = popcount64(wbuff[i / 64]);
m = popcnt_64(wbuff[i / 64]);
if (!vi)
m = 64 - m;
if (t + m >= n)
Expand Down Expand Up @@ -320,23 +320,23 @@ binary_function(PyObject *args, const char *format, const char oper)
switch (oper) {
case '&': /* count and */
for (i = 0; i < cwords; i++)
cnt += popcount64(wbuff_a[i] & wbuff_b[i]);
cnt += popcnt_64(wbuff_a[i] & wbuff_b[i]);
if (rbits)
cnt += popcount64(zlw(a) & zlw(b));
cnt += popcnt_64(zlw(a) & zlw(b));
break;

case '|': /* count or */
for (i = 0; i < cwords; i++)
cnt += popcount64(wbuff_a[i] | wbuff_b[i]);
cnt += popcnt_64(wbuff_a[i] | wbuff_b[i]);
if (rbits)
cnt += popcount64(zlw(a) | zlw(b));
cnt += popcnt_64(zlw(a) | zlw(b));
break;

case '^': /* count xor */
for (i = 0; i < cwords; i++)
cnt += popcount64(wbuff_a[i] ^ wbuff_b[i]);
cnt += popcnt_64(wbuff_a[i] ^ wbuff_b[i]);
if (rbits)
cnt += popcount64(zlw(a) ^ zlw(b));
cnt += popcnt_64(zlw(a) ^ zlw(b));
break;

case 'a': /* any and */
Expand Down Expand Up @@ -426,10 +426,10 @@ correspond_all(PyObject *module, PyObject *args)
v = WBUFF(b)[i];
not_u = ~u;
not_v = ~v;
nff += popcount64(not_u & not_v);
nft += popcount64(not_u & v);
ntf += popcount64(u & not_v);
ntt += popcount64(u & v);
nff += popcnt_64(not_u & not_v);
nft += popcnt_64(not_u & v);
ntf += popcnt_64(u & not_v);
ntt += popcnt_64(u & v);
}

if (rbits) {
Expand All @@ -438,10 +438,10 @@ correspond_all(PyObject *module, PyObject *args)
not_u = ~u;
not_v = ~v;
/* for nff we need to substract the number of unused 1 bits */
nff += popcount64(not_u & not_v) - (64 - rbits);
nft += popcount64(not_u & v);
ntf += popcount64(u & not_v);
ntt += popcount64(u & v);
nff += popcnt_64(not_u & not_v) - (64 - rbits);
nft += popcnt_64(not_u & v);
ntf += popcnt_64(u & not_v);
ntt += popcnt_64(u & v);
}
return Py_BuildValue("nnnn", nff, nft, ntf, ntt);
}
Expand Down Expand Up @@ -1040,7 +1040,7 @@ count_from_word(bitarrayobject *a, Py_ssize_t i)
return 0;
cnt += popcount_words(WBUFF(a) + i, nbits / 64 - i);
if (nbits % 64)
cnt += popcount64(zlw(a));
cnt += popcnt_64(zlw(a));
return cnt;
}

Expand Down
4 changes: 2 additions & 2 deletions bitarray/bitarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ set_padbits(bitarrayobject *self)

/* Population count: count the number of 1's in 'x'. */
static inline int
popcount64(uint64_t x)
popcnt_64(uint64_t x)
{
#if (defined(__clang__) || defined(__GNUC__))
return __builtin_popcountll(x);
Expand All @@ -211,7 +211,7 @@ popcount_words(uint64_t *w, Py_ssize_t n)

assert(n >= 0);
while (n--)
cnt += popcount64(*w++);
cnt += popcnt_64(*w++);
return cnt;
}

Expand Down

0 comments on commit d8ce774

Please sign in to comment.