Skip to content

Commit

Permalink
Add optimized reverse overloads using MSVC bswap intrinsics
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Oct 24, 2024
1 parent 127e192 commit 6a4f161
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions include/boost/hash2/detail/reverse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,41 @@ inline void reverse( unsigned char (&d)[ 16 ], void const* s )
std::memcpy( d, tmp2, 16 );
}

#elif defined(_MSC_VER)

inline void reverse( unsigned char (&d)[ 2 ], void const* s )
{
unsigned short tmp;
std::memcpy( &tmp, s, 2 );
tmp = _byteswap_ushort( tmp );
std::memcpy( d, &tmp, 2 );
}

inline void reverse( unsigned char (&d)[ 4 ], void const* s )
{
unsigned long tmp;
std::memcpy( &tmp, s, 4 );
tmp = _byteswap_ulong( tmp );
std::memcpy( d, &tmp, 4 );
}

inline void reverse( unsigned char (&d)[ 8 ], void const* s )
{
unsigned long long tmp;
std::memcpy( &tmp, s, 8 );
tmp = _byteswap_uint64( tmp );
std::memcpy( d, &tmp, 8 );
}

inline void reverse( unsigned char (&d)[ 16 ], void const* s )
{
unsigned long long tmp[ 2 ];
std::memcpy( tmp, s, 16 );

unsigned long long tmp2[ 2 ] = { _byteswap_uint64( tmp[1] ), _byteswap_uint64( tmp[0] ) };
std::memcpy( d, tmp2, 16 );
}

#endif

} // namespace detail
Expand Down

0 comments on commit 6a4f161

Please sign in to comment.