Skip to content

Commit

Permalink
lib/hash.h: add hash_uint64()
Browse files Browse the repository at this point in the history
Add hash_uint64() and apply it when appropriate.

Signed-off-by: Andy Zhou <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
azhou-nicira committed Mar 28, 2014
1 parent 17041b1 commit 965607c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/cfm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/classifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
6 changes: 6 additions & 0 deletions lib/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions lib/packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions ofproto/ofproto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 965607c

Please sign in to comment.