lib/hash.h: add hash_uint64()
authorAndy Zhou <azhou@nicira.com>
Fri, 28 Mar 2014 02:38:04 +0000 (19:38 -0700)
committerAndy Zhou <azhou@nicira.com>
Fri, 28 Mar 2014 19:51:57 +0000 (12:51 -0700)
Add hash_uint64() and apply it when appropriate.

Signed-off-by: Andy Zhou <azhou@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
lib/cfm.c
lib/classifier.c
lib/hash.h
lib/packets.c
ofproto/ofproto.c

index ff46019..48556cf 100644 (file)
--- a/lib/cfm.c
+++ b/lib/cfm.c
@@ -285,7 +285,7 @@ ms_to_ccm_interval(int interval_ms)
 static uint32_t
 hash_mpid(uint64_t mpid)
 {
-    return hash_bytes(&mpid, sizeof mpid, 0);
+    return hash_uint64(mpid);
 }
 
 static bool
index 30a91b7..55ca5ea 100644 (file)
@@ -312,7 +312,7 @@ static uint32_t
 hash_metadata(ovs_be64 metadata_)
 {
     uint64_t metadata = (OVS_FORCE uint64_t) metadata_;
-    return hash_2words(metadata, metadata >> 32);
+    return hash_uint64(metadata);
 }
 
 static struct cls_partition *
index 0e8edf3..979214a 100644 (file)
@@ -37,6 +37,7 @@ uint32_t hash_bytes(const void *, size_t n_bytes, uint32_t basis);
 
 static inline uint32_t hash_int(uint32_t x, uint32_t basis);
 static inline uint32_t hash_2words(uint32_t, uint32_t);
+static inline uint32_t hash_uint64(uint64_t);
 uint32_t hash_3words(uint32_t, uint32_t, uint32_t);
 
 static inline uint32_t hash_boolean(bool x, uint32_t basis);
@@ -118,6 +119,11 @@ static inline uint32_t hash_2words(uint32_t x, uint32_t y)
     return mhash_finish(mhash_add(mhash_add(x, 0), y), 8);
 }
 
+static inline uint32_t hash_uint64(const uint64_t x)
+{
+    return hash_2words((uint32_t)(x >> 32), (uint32_t)x);
+}
+
 #ifdef __cplusplus
 }
 #endif
index 3edfe01..f8edb02 100644 (file)
@@ -112,15 +112,13 @@ eth_addr_is_reserved(const uint8_t ea[ETH_ADDR_LEN])
     if (ovsthread_once_start(&once)) {
         hmap_init(&addrs);
         for (node = nodes; node < &nodes[ARRAY_SIZE(nodes)]; node++) {
-            hmap_insert(&addrs, &node->hmap_node,
-                        hash_2words(node->ea64, node->ea64 >> 32));
+            hmap_insert(&addrs, &node->hmap_node, hash_uint64(node->ea64));
         }
         ovsthread_once_done(&once);
     }
 
     ea64 = eth_addr_to_uint64(ea);
-    HMAP_FOR_EACH_IN_BUCKET (node, hmap_node, hash_2words(ea64, ea64 >> 32),
-                             &addrs) {
+    HMAP_FOR_EACH_IN_BUCKET (node, hmap_node, hash_uint64(ea64), &addrs) {
         if (node->ea64 == ea64) {
             return true;
         }
index 277c1d7..b2d6526 100644 (file)
@@ -3192,8 +3192,7 @@ handle_port_desc_stats_request(struct ofconn *ofconn,
 static uint32_t
 hash_cookie(ovs_be64 cookie)
 {
-    return hash_2words((OVS_FORCE uint64_t)cookie >> 32,
-                       (OVS_FORCE uint64_t)cookie);
+    return hash_uint64((OVS_FORCE uint64_t)cookie);
 }
 
 static void