From 59fb676e401fc67b72b92aa8f232e996e5f65664 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 16 Nov 2024 03:34:17 +0200 Subject: [PATCH] Remove detail/reverse.hpp --- include/boost/hash2/detail/reverse.hpp | 105 ------------------------- test/Jamfile | 1 - test/detail_reverse.cpp | 40 ---------- 3 files changed, 146 deletions(-) delete mode 100644 include/boost/hash2/detail/reverse.hpp delete mode 100644 test/detail_reverse.cpp diff --git a/include/boost/hash2/detail/reverse.hpp b/include/boost/hash2/detail/reverse.hpp deleted file mode 100644 index bfab480..0000000 --- a/include/boost/hash2/detail/reverse.hpp +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef BOOST_HASH2_DETAIL_REVERSE_HPP_INCLUDED -#define BOOST_HASH2_DETAIL_REVERSE_HPP_INCLUDED - -// Copyright 2024 Peter Dimov. -// Distributed under the Boost Software License, Version 1.0. -// https://www.boost.org/LICENSE_1_0.txt - -#include -#include -#include - -namespace boost -{ -namespace hash2 -{ -namespace detail -{ - -template void reverse( unsigned char (&d)[ N ], void const* s ) -{ - unsigned char const* s2 = static_cast( s ); - - for( std::size_t i = 0; i < N; ++i ) - { - d[ i ] = s2[ N-1-i ]; - } -} - -#if defined(__GNUC__) || defined(__clang__) - -inline void reverse( unsigned char (&d)[ 2 ], void const* s ) -{ - std::uint16_t tmp; - std::memcpy( &tmp, s, 2 ); - tmp = __builtin_bswap16( tmp ); - std::memcpy( d, &tmp, 2 ); -} - -inline void reverse( unsigned char (&d)[ 4 ], void const* s ) -{ - std::uint32_t tmp; - std::memcpy( &tmp, s, 4 ); - tmp = __builtin_bswap32( tmp ); - std::memcpy( d, &tmp, 4 ); -} - -inline void reverse( unsigned char (&d)[ 8 ], void const* s ) -{ - std::uint64_t tmp; - std::memcpy( &tmp, s, 8 ); - tmp = __builtin_bswap64( tmp ); - std::memcpy( d, &tmp, 8 ); -} - -inline void reverse( unsigned char (&d)[ 16 ], void const* s ) -{ - std::uint64_t tmp[ 2 ]; - std::memcpy( tmp, s, 16 ); - - std::uint64_t tmp2[ 2 ] = { __builtin_bswap64( tmp[1] ), __builtin_bswap64( tmp[0] ) }; - 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 -} // namespace hash2 -} // namespace boost - -#endif // #ifndef BOOST_HASH2_DETAIL_REVERSE_HPP_INCLUDED diff --git a/test/Jamfile b/test/Jamfile index 166a3b3..b7036d1 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -41,7 +41,6 @@ run detail_read.cpp ; run detail_write.cpp ; run detail_write_2.cpp ; run detail_rot.cpp ; -run detail_reverse.cpp ; run detail_has_tag_invoke.cpp ; # hash_append diff --git a/test/detail_reverse.cpp b/test/detail_reverse.cpp deleted file mode 100644 index 93f252e..0000000 --- a/test/detail_reverse.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2024 Peter Dimov. -// Distributed under the Boost Software License, Version 1.0. -// https://www.boost.org/LICENSE_1_0.txt - -#include -#include - -template void test() -{ - unsigned char v[ N ] = {}; - for( std::size_t i = 0; i < N; ++i ) v[ i ] = static_cast( i + 1 ); - - unsigned char w[ N ] = {}; - boost::hash2::detail::reverse( w, v ); - - for( std::size_t i = 0; i < N; ++i ) BOOST_TEST_EQ( w[ i ], v[ N - 1 - i ] ); -} - -int main() -{ - test<1>(); - test<2>(); - test<3>(); - test<4>(); - test<5>(); - test<6>(); - test<7>(); - test<8>(); - test<9>(); - test<10>(); - test<11>(); - test<12>(); - test<13>(); - test<14>(); - test<15>(); - test<16>(); - test<17>(); - - return boost::report_errors(); -}