Some formatting and optimization.

This commit is contained in:
Adam Ierymenko 2020-06-30 22:23:57 -07:00
parent ad692b07c3
commit 6af39da61a
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
4 changed files with 36 additions and 23 deletions

View file

@ -88,7 +88,7 @@ struct UniqueID
{ return reinterpret_cast<const uint8_t *>(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)); }

View file

@ -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)));
}
}

View file

@ -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); }

View file

@ -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