ctz() returns 32 for zero input, and we already have ctz64(),
so it makes sense to rename ctz() as ctz32().

Signed-off-by: Jarno Rajahalme <[email protected]>
---
 lib/packets.c     |    2 +-
 lib/util.h        |    6 +++---
 tests/test-util.c |   16 ++++++++--------
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/lib/packets.c b/lib/packets.c
index 5349d41..1149442 100644
--- a/lib/packets.c
+++ b/lib/packets.c
@@ -425,7 +425,7 @@ eth_addr_bitand(const uint8_t src[ETH_ADDR_LEN],
 int
 ip_count_cidr_bits(ovs_be32 netmask)
 {
-    return 32 - ctz(ntohl(netmask));
+    return 32 - ctz32(ntohl(netmask));
 }
 
 void
diff --git a/lib/util.h b/lib/util.h
index fbab74c..4f8a291 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -325,7 +325,7 @@ int raw_ctz(uint64_t n);
 
 /* 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;
 }
@@ -361,10 +361,10 @@ zero_rightmost_1bit(uintmax_t x)
 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. */
diff --git a/tests/test-util.c b/tests/test-util.c
index 7183f46..8dbc98b 100644
--- a/tests/test-util.c
+++ b/tests/test-util.c
@@ -61,11 +61,11 @@ test_log_2_floor(int argc OVS_UNUSED, char *argv[] 
OVS_UNUSED)
 }
 
 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();
     }
 }
@@ -87,13 +87,13 @@ test_ctz(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
 
     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);
     }
 
 
@@ -109,7 +109,7 @@ test_ctz(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
     }
 
     /* Check ctz(0). */
-    check_ctz(0, 32);
+    check_ctz32(0, 32);
     check_ctz64(0, 64);
 }
 
-- 
1.7.10.4

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

Reply via email to