static int
miniflow_n_values(const struct miniflow *flow)
{
- return popcount(flow->map);
+ return count_1bits(flow->map);
}
static uint32_t *
static const uint32_t zero = 0;
return &zero;
}
- return flow->values + popcount(flow->map & ((UINT64_C(1) << u32_ofs) - 1));
+ return flow->values +
+ count_1bits(flow->map & ((UINT64_C(1) << u32_ofs) - 1));
}
/* Returns the uint32_t that would be at byte offset '4 * u32_ofs' if 'flow'
/* Returns the number of 1-bits in 'x', between 0 and 32 inclusive. */
static unsigned int
-popcount32(uint32_t x)
+count_1bits_32(uint32_t x)
{
/* In my testing, this implementation is over twice as fast as any other
* portable implementation that I tried, including GCC 4.4
#define INIT32(X) INIT16(X), INIT16((X) + 16)
#define INIT64(X) INIT32(X), INIT32((X) + 32)
- static const uint8_t popcount8[256] = {
+ static const uint8_t count_1bits_8[256] = {
INIT64(0), INIT64(64), INIT64(128), INIT64(192)
};
- return (popcount8[x & 0xff] +
- popcount8[(x >> 8) & 0xff] +
- popcount8[(x >> 16) & 0xff] +
- popcount8[x >> 24]);
+ return (count_1bits_8[x & 0xff] +
+ count_1bits_8[(x >> 8) & 0xff] +
+ count_1bits_8[(x >> 16) & 0xff] +
+ count_1bits_8[x >> 24]);
}
/* Returns the number of 1-bits in 'x', between 0 and 64 inclusive. */
unsigned int
-popcount(uint64_t x)
+count_1bits(uint64_t x)
{
- return popcount32(x) + popcount32(x >> 32);
+ return count_1bits_32(x) + count_1bits_32(x >> 32);
}
/* Returns true if the 'n' bytes starting at 'p' are zeros. */
}
static void
-check_popcount(uint64_t x, int n)
+check_count_1bits(uint64_t x, int n)
{
- if (popcount(x) != n) {
- fprintf(stderr, "popcount(%#"PRIx64") is %d but should be %d\n",
- x, popcount(x), n);
+ if (count_1bits(x) != n) {
+ fprintf(stderr, "count_1bits(%#"PRIx64") is %d but should be %d\n",
+ x, count_1bits(x), n);
abort();
}
}
static void
-test_popcount(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+test_count_1bits(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
{
uint64_t bits[64];
int i;
bits[i] = UINT64_C(1) << i;
}
- check_popcount(0, 0);
+ check_count_1bits(0, 0);
for (i = 0; i < 1000; i++) {
uint64_t x = 0;
shuffle(bits, ARRAY_SIZE(bits));
for (j = 0; j < 64; j++) {
x |= bits[j];
- check_popcount(x, j + 1);
+ check_count_1bits(x, j + 1);
}
assert(x == UINT64_MAX);
shuffle(bits, ARRAY_SIZE(bits));
for (j = 63; j >= 0; j--) {
x &= ~bits[j];
- check_popcount(x, j);
+ check_count_1bits(x, j);
}
assert(x == 0);
}
{"ctz", 0, 0, test_ctz},
{"round_up_pow2", 0, 0, test_round_up_pow2},
{"round_down_pow2", 0, 0, test_round_down_pow2},
- {"popcount", 0, 0, test_popcount},
+ {"count_1bits", 0, 0, test_count_1bits},
{"log_2_floor", 0, 0, test_log_2_floor},
{"bitwise_copy", 0, 0, test_bitwise_copy},
{"bitwise_zero", 0, 0, test_bitwise_zero},