diff --git a/core/Blob.hpp b/core/Blob.hpp index 004093ea9..20e11d86e 100644 --- a/core/Blob.hpp +++ b/core/Blob.hpp @@ -88,7 +88,7 @@ struct UniqueID { return reinterpret_cast(data); } ZT_INLINE unsigned long hashCode() const noexcept - { return (unsigned long)data[1]; } + { return (unsigned long)(data[0] ^ data[1]); } ZT_INLINE operator bool() const noexcept { return ((data[0] != 0) && (data[1] != 0)); } diff --git a/core/InetAddress.hpp b/core/InetAddress.hpp index 4af4f867b..50fb3490a 100644 --- a/core/InetAddress.hpp +++ b/core/InetAddress.hpp @@ -541,7 +541,7 @@ public: return UniqueID(0, 0); } else { // This should never be reached, but handle it somehow. - return UniqueID(Utils::fnv1a32(&as, sizeof(as)), 0); + return UniqueID(as.ss.ss_family, Utils::fnv1a32(&as, sizeof(as))); } } diff --git a/core/MAC.hpp b/core/MAC.hpp index 59e1a1017..3ed4ed6e7 100644 --- a/core/MAC.hpp +++ b/core/MAC.hpp @@ -219,30 +219,44 @@ public: } ZT_INLINE MAC &operator=(const uint64_t m) noexcept - { m_mac = m; return *this; } + { + m_mac = m; + return *this; + } ZT_INLINE bool operator==(const MAC &m) const noexcept { return (m_mac == m.m_mac); } + ZT_INLINE bool operator!=(const MAC &m) const noexcept { return (m_mac != m.m_mac); } + ZT_INLINE bool operator<(const MAC &m) const noexcept { return (m_mac < m.m_mac); } + ZT_INLINE bool operator<=(const MAC &m) const noexcept { return (m_mac <= m.m_mac); } + ZT_INLINE bool operator>(const MAC &m) const noexcept { return (m_mac > m.m_mac); } + ZT_INLINE bool operator>=(const MAC &m) const noexcept { return (m_mac >= m.m_mac); } + ZT_INLINE bool operator==(const uint64_t m) const noexcept { return (m_mac == m); } + ZT_INLINE bool operator!=(const uint64_t m) const noexcept { return (m_mac != m); } + ZT_INLINE bool operator<(const uint64_t m) const noexcept { return (m_mac < m); } + ZT_INLINE bool operator<=(const uint64_t m) const noexcept { return (m_mac <= m); } + ZT_INLINE bool operator>(const uint64_t m) const noexcept { return (m_mac > m); } + ZT_INLINE bool operator>=(const uint64_t m) const noexcept { return (m_mac >= m); } diff --git a/core/Utils.hpp b/core/Utils.hpp index 0af45de59..46afdc45f 100644 --- a/core/Utils.hpp +++ b/core/Utils.hpp @@ -707,14 +707,7 @@ static ZT_INLINE void copy(void *dest, const void *src) noexcept { #if defined(ZT_ARCH_X64) && defined(__GNUC__) unsigned long l = L; - asm volatile ("rep movsb" - : "=D" (dest), - "=S" (src), - "=c" (l) - : "0" (dest), - "1" (src), - "2" (l) - : "memory"); + asm volatile ("cld ; rep movsb" : "+c"(l), "+S"(src), "+D"(dest)); #else memcpy(dest, src, L); #endif @@ -730,14 +723,7 @@ static ZT_INLINE void copy(void *dest, const void *src) noexcept static ZT_INLINE void copy(void *dest, const void *src, unsigned long len) noexcept { #if defined(ZT_ARCH_X64) && defined(__GNUC__) - asm volatile ("rep movsb" - : "=D" (dest), - "=S" (src), - "=c" (len) - : "0" (dest), - "1" (src), - "2" (len) - : "memory"); + asm volatile ("cld ; rep movsb" : "+c"(len), "+S"(src), "+D"(dest)); #else memcpy(dest, src, len); #endif @@ -750,8 +736,15 @@ static ZT_INLINE void copy(void *dest, const void *src, unsigned long len) noexc * @param dest Memory to zero */ template< unsigned long L > -static ZT_INLINE void zero(void *const dest) noexcept -{ memset(dest, 0, L); } +static ZT_INLINE void zero(void *dest) noexcept +{ +#if defined(ZT_ARCH_X64) && defined(__GNUC__) + unsigned long l = L; + asm volatile ("cld ; rep stosb" :"+c" (l), "+D" (dest) : "a" (0)); +#else + memset(dest, 0, L); +#endif +} /** * Zero memory block whose size is known at run time @@ -759,8 +752,14 @@ static ZT_INLINE void zero(void *const dest) noexcept * @param dest Memory to zero * @param len Size in bytes */ -static ZT_INLINE void zero(void *const dest, const unsigned long len) noexcept -{ memset(dest, 0, len); } +static ZT_INLINE void zero(void *dest, unsigned long len) noexcept +{ +#if defined(ZT_ARCH_X64) && defined(__GNUC__) + asm volatile ("cld ; rep stosb" :"+c" (len), "+D" (dest) : "a" (0)); +#else + memset(dest, 0, len); +#endif +} } // namespace Utils