From d8ce7744372fa24fe1da1d83a378b9c30fc724c6 Mon Sep 17 00:00:00 2001 From: Ilan Schnell Date: Mon, 20 Feb 2023 07:49:49 -0600 Subject: [PATCH] rename popcount64() -> popcnt_64(), fix issue #189 --- bitarray/_bitarray.c | 2 +- bitarray/_util.c | 32 ++++++++++++++++---------------- bitarray/bitarray.h | 4 ++-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/bitarray/_bitarray.c b/bitarray/_bitarray.c index ac71ef70..1f916533 100644 --- a/bitarray/_bitarray.c +++ b/bitarray/_bitarray.c @@ -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); } diff --git a/bitarray/_util.c b/bitarray/_util.c index 659b6a99..8482d597 100644 --- a/bitarray/_util.c +++ b/bitarray/_util.c @@ -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) @@ -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 */ @@ -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) { @@ -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); } @@ -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; } diff --git a/bitarray/bitarray.h b/bitarray/bitarray.h index 72c4a86b..d6f23a3e 100644 --- a/bitarray/bitarray.h +++ b/bitarray/bitarray.h @@ -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); @@ -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; }