From eb44fdf7a8372003527a1b5e15290a780d76f6df Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 3 Jun 2014 19:57:42 -0400 Subject: [PATCH] 64-bits alignment for RoutingKey --- Identity.cpp | 9 ++++----- Identity.h | 11 ++++++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Identity.cpp b/Identity.cpp index c4782e05..756eaec3 100644 --- a/Identity.cpp +++ b/Identity.cpp @@ -98,12 +98,11 @@ namespace data XORMetric operator^(const RoutingKey& key1, const RoutingKey& key2) { - // TODO: implementation depends on CPU XORMetric m; - ((uint64_t *)m.metric)[0] = ((uint64_t *)key1.hash)[0] ^ ((uint64_t *)key2.hash)[0]; - ((uint64_t *)m.metric)[1] = ((uint64_t *)key1.hash)[1] ^ ((uint64_t *)key2.hash)[1]; - ((uint64_t *)m.metric)[2] = ((uint64_t *)key1.hash)[2] ^ ((uint64_t *)key2.hash)[2]; - ((uint64_t *)m.metric)[3] = ((uint64_t *)key1.hash)[3] ^ ((uint64_t *)key2.hash)[3]; + m.metric_ll[0] = key1.hash_ll[0] ^ key2.hash_ll[0]; + m.metric_ll[1] = key1.hash_ll[1] ^ key2.hash_ll[1]; + m.metric_ll[2] = key1.hash_ll[2] ^ key2.hash_ll[2]; + m.metric_ll[3] = key1.hash_ll[3] ^ key2.hash_ll[3]; return m; } } diff --git a/Identity.h b/Identity.h index b2d593b0..9c91e9e6 100644 --- a/Identity.h +++ b/Identity.h @@ -78,7 +78,7 @@ namespace data bool operator== (const IdentHash& other) const { return !memcmp (m_Hash, other.m_Hash, 32); }; bool operator< (const IdentHash& other) const { return memcmp (m_Hash, other.m_Hash, 32) < 0; }; - bool FromBase32(const std::string&); + bool FromBase32(const std::string&); private: @@ -89,14 +89,19 @@ namespace data void CreateRandomDHKeysPair (DHKeysPair * keys); // for transport sessions // kademlia - struct RoutingKey + union RoutingKey { uint8_t hash[32]; + uint64_t hash_ll[4]; }; struct XORMetric { - uint8_t metric[32]; + union + { + uint8_t metric[32]; + uint64_t metric_ll[4]; + }; void SetMin () { memset (metric, 0, 32); }; void SetMax () { memset (metric, 0xFF, 32); };