This avoids a conflict with NetBSD's strings.h/libc.
(http://netbsd.gw.com/cgi-bin/man-cgi?popcount++NetBSD-current)
The new name is suggested by Ben Pfaff.
Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@gmail.com>
static int
miniflow_n_values(const struct miniflow *flow)
{
static int
miniflow_n_values(const struct miniflow *flow)
{
- return popcount(flow->map);
+ return count_1bits(flow->map);
static const uint32_t zero = 0;
return &zero;
}
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 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
/* Returns the number of 1-bits in 'x', between 0 and 32 inclusive. */
static unsigned int
+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
{
/* 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)
#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)
};
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
}
/* Returns the number of 1-bits in 'x', between 0 and 64 inclusive. */
unsigned int
- 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. */
}
/* Returns true if the 'n' bytes starting at 'p' are zeros. */
int log_2_floor(uint32_t);
int log_2_ceil(uint32_t);
int log_2_floor(uint32_t);
int log_2_ceil(uint32_t);
-unsigned int popcount(uint64_t);
+unsigned int count_1bits(uint64_t);
/* Returns the number of trailing 0-bits in 'n'. Undefined if 'n' == 0. */
#if __GNUC__ >= 4
/* Returns the number of trailing 0-bits in 'n'. Undefined if 'n' == 0. */
#if __GNUC__ >= 4
[[ctz],
[round_up_pow2],
[round_down_pow2],
[[ctz],
[round_up_pow2],
[round_down_pow2],
[log_2_floor],
[bitwise_copy],
[bitwise_zero],
[log_2_floor],
[bitwise_copy],
[bitwise_zero],
-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);
-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;
{
uint64_t bits[64];
int i;
bits[i] = UINT64_C(1) << i;
}
bits[i] = UINT64_C(1) << i;
}
+ check_count_1bits(0, 0);
for (i = 0; i < 1000; i++) {
uint64_t x = 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];
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];
}
assert(x == UINT64_MAX);
shuffle(bits, ARRAY_SIZE(bits));
for (j = 63; j >= 0; j--) {
x &= ~bits[j];
+ check_count_1bits(x, j);
{"ctz", 0, 0, test_ctz},
{"round_up_pow2", 0, 0, test_round_up_pow2},
{"round_down_pow2", 0, 0, test_round_down_pow2},
{"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},
{"log_2_floor", 0, 0, test_log_2_floor},
{"bitwise_copy", 0, 0, test_bitwise_copy},
{"bitwise_zero", 0, 0, test_bitwise_zero},