mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Fix Endian issue in SipHash for s390x
This commit is contained in:
parent
b1f014f9a6
commit
cc73b53116
@ -2,7 +2,39 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <type_traits>
|
||||
#include <bit>
|
||||
|
||||
inline void reverseMemcpy(void *dst, const void *src, int length)
|
||||
{
|
||||
uint8_t *d = reinterpret_cast<uint8_t*>(dst);
|
||||
const uint8_t *s = reinterpret_cast<const uint8_t*>(src);
|
||||
|
||||
d += length;
|
||||
while (length--)
|
||||
*--d = *s++;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T unalignedLoadLE(const void * address)
|
||||
{
|
||||
T res {};
|
||||
if constexpr (std::endian::native == std::endian::little)
|
||||
memcpy(&res, address, sizeof(res));
|
||||
else
|
||||
reverseMemcpy(&res, address, sizeof(res));
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void unalignedStoreLE(void * address,
|
||||
const typename std::enable_if<true, T>::type & src)
|
||||
{
|
||||
static_assert(std::is_trivially_copyable_v<T>);
|
||||
if constexpr (std::endian::native == std::endian::little)
|
||||
memcpy(address, &src, sizeof(src));
|
||||
else
|
||||
reverseMemcpy(address, &src, sizeof(src));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T unalignedLoad(const void * address)
|
||||
|
@ -111,7 +111,7 @@ public:
|
||||
|
||||
while (data + 8 <= end)
|
||||
{
|
||||
current_word = unalignedLoad<UInt64>(data);
|
||||
current_word = unalignedLoadLE<UInt64>(data);
|
||||
|
||||
v3 ^= current_word;
|
||||
SIPROUND;
|
||||
@ -157,8 +157,8 @@ public:
|
||||
void get128(char * out)
|
||||
{
|
||||
finalize();
|
||||
unalignedStore<UInt64>(out, v0 ^ v1);
|
||||
unalignedStore<UInt64>(out + 8, v2 ^ v3);
|
||||
unalignedStoreLE<UInt64>(out, v0 ^ v1);
|
||||
unalignedStoreLE<UInt64>(out + 8, v2 ^ v3);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
Loading…
Reference in New Issue
Block a user