int
ip_count_cidr_bits(ovs_be32 netmask)
{
- return 32 - ctz(ntohl(netmask));
+ return 32 - ctz32(ntohl(netmask));
}
void
/* Returns the number of trailing 0-bits in 'n', or 32 if 'n' is 0. */
static inline int
-ctz(uint32_t n)
+ctz32(uint32_t n)
{
return n ? raw_ctz(n) : 32;
}
static inline uint32_t
rightmost_1bit_idx(uint32_t x)
{
- return x ? ctz(x) : 32;
+ return ctz32(x);
}
-/* Returns the index of the rightmost 1-bit in 'x' (e.g. 01011000 => 6), or 32
+/* Returns the index of the leftmost 1-bit in 'x' (e.g. 01011000 => 6), or 32
* if 'x' is 0.
*
* This function only works with 32-bit integers. */
}
static void
-check_ctz(uint32_t x, int n)
+check_ctz32(uint32_t x, int n)
{
- if (ctz(x) != n) {
- fprintf(stderr, "ctz(%"PRIu32") is %d but should be %d\n",
- x, ctz(x), n);
+ if (ctz32(x) != n) {
+ fprintf(stderr, "ctz32(%"PRIu32") is %d but should be %d\n",
+ x, ctz32(x), n);
abort();
}
}
for (n = 0; n < 32; n++) {
/* Check minimum x such that f(x) == n. */
- check_ctz(1 << n, n);
+ check_ctz32(1 << n, n);
/* Check maximum x such that f(x) == n. */
- check_ctz(UINT32_MAX << n, n);
+ check_ctz32(UINT32_MAX << n, n);
/* Check a random value in the middle. */
- check_ctz((random_uint32() | 1) << n, n);
+ check_ctz32((random_uint32() | 1) << n, n);
}
}
/* Check ctz(0). */
- check_ctz(0, 32);
+ check_ctz32(0, 32);
check_ctz64(0, 64);
}