Merge pull request #54095 from ClibMouse/feature/siphash128-reference-big-endian

Fix SipHash128 reference for big-endian platforms
This commit is contained in:
Alexey Milovidov 2023-09-01 17:34:08 +03:00 committed by GitHub
commit 0c8a6b9bbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -200,11 +200,7 @@ public:
ALWAYS_INLINE UInt128 get128()
{
UInt128 res;
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
get128(res.items[1], res.items[0]);
#else
get128(res.items[0], res.items[1]);
#endif
get128(res.items[UInt128::_impl::little(0)], res.items[UInt128::_impl::little(1)]);
return res;
}
@ -214,20 +210,13 @@ public:
throw DB::Exception(
DB::ErrorCodes::LOGICAL_ERROR, "Logical error: can't call get128Reference when is_reference_128 is not set");
finalize();
auto lo = v0 ^ v1 ^ v2 ^ v3;
const auto lo = v0 ^ v1 ^ v2 ^ v3;
v1 ^= 0xdd;
SIPROUND;
SIPROUND;
SIPROUND;
SIPROUND;
auto hi = v0 ^ v1 ^ v2 ^ v3;
if constexpr (std::endian::native == std::endian::big)
{
lo = std::byteswap(lo);
hi = std::byteswap(hi);
std::swap(lo, hi);
}
const auto hi = v0 ^ v1 ^ v2 ^ v3;
UInt128 res = hi;
res <<= 64;