From 965607c850bb14e24905c46845d050f14105d923 Mon Sep 17 00:00:00 2001 From: Andy Zhou Date: Thu, 27 Mar 2014 19:38:04 -0700 Subject: [PATCH] lib/hash.h: add hash_uint64() Add hash_uint64() and apply it when appropriate. Signed-off-by: Andy Zhou Acked-by: Ben Pfaff --- lib/cfm.c | 2 +- lib/classifier.c | 2 +- lib/hash.h | 6 ++++++ lib/packets.c | 6 ++---- ofproto/ofproto.c | 3 +-- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/cfm.c b/lib/cfm.c index ff460195b..48556cf1a 100644 --- 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 diff --git a/lib/classifier.c b/lib/classifier.c index 30a91b755..55ca5eabe 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -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 * diff --git a/lib/hash.h b/lib/hash.h index 0e8edf395..979214af0 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -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 diff --git a/lib/packets.c b/lib/packets.c index 3edfe01a7..f8edb0205 100644 --- a/lib/packets.c +++ b/lib/packets.c @@ -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; } diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 277c1d7ce..b2d6526c6 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -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 -- 2.43.0