mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
Merge pull request #46495 from HarryLeeIBM/hlee-s390x-xxhash
Fix hash endian issue for s390x
This commit is contained in:
commit
8d804d8823
@ -55,7 +55,7 @@
|
|||||||
#include <base/IPv4andIPv6.h>
|
#include <base/IPv4andIPv6.h>
|
||||||
#include <base/range.h>
|
#include <base/range.h>
|
||||||
#include <base/bit_cast.h>
|
#include <base/bit_cast.h>
|
||||||
|
#include <base/unaligned.h>
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
@ -1026,16 +1026,37 @@ private:
|
|||||||
if constexpr (Impl::use_int_hash_for_pods)
|
if constexpr (Impl::use_int_hash_for_pods)
|
||||||
{
|
{
|
||||||
if constexpr (std::is_same_v<ToType, UInt64>)
|
if constexpr (std::is_same_v<ToType, UInt64>)
|
||||||
h = IntHash64Impl::apply(bit_cast<UInt64>(vec_from[i]));
|
{
|
||||||
|
UInt64 v = bit_cast<UInt64>(vec_from[i]);
|
||||||
|
|
||||||
|
/// Consider using std::byteswap(c++23) in the future
|
||||||
|
if constexpr (std::endian::native == std::endian::big)
|
||||||
|
v = __builtin_bswap64(v);
|
||||||
|
h = IntHash64Impl::apply(v);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
h = IntHash32Impl::apply(bit_cast<UInt32>(vec_from[i]));
|
{
|
||||||
|
UInt32 v = bit_cast<UInt32>(vec_from[i]);
|
||||||
|
if constexpr (std::endian::native == std::endian::big)
|
||||||
|
v = __builtin_bswap32(v);
|
||||||
|
h = IntHash32Impl::apply(v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (std::is_same_v<Impl, JavaHashImpl>)
|
if constexpr (std::is_same_v<Impl, JavaHashImpl>)
|
||||||
h = JavaHashImpl::apply(vec_from[i]);
|
h = JavaHashImpl::apply(vec_from[i]);
|
||||||
else
|
else
|
||||||
h = apply(key, reinterpret_cast<const char *>(&vec_from[i]), sizeof(vec_from[i]));
|
{
|
||||||
|
FromType v = vec_from[i];
|
||||||
|
if constexpr (std::endian::native == std::endian::big)
|
||||||
|
{
|
||||||
|
FromType tmp_v;
|
||||||
|
reverseMemcpy(&tmp_v, &v, sizeof(v));
|
||||||
|
v = tmp_v;
|
||||||
|
}
|
||||||
|
h = apply(key, reinterpret_cast<const char *>(&v), sizeof(v));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if constexpr (first)
|
if constexpr (first)
|
||||||
@ -1049,9 +1070,19 @@ private:
|
|||||||
auto value = col_from_const->template getValue<FromType>();
|
auto value = col_from_const->template getValue<FromType>();
|
||||||
ToType hash;
|
ToType hash;
|
||||||
if constexpr (std::is_same_v<ToType, UInt64>)
|
if constexpr (std::is_same_v<ToType, UInt64>)
|
||||||
hash = IntHash64Impl::apply(bit_cast<UInt64>(value));
|
{
|
||||||
|
UInt64 v = bit_cast<UInt64>(value);
|
||||||
|
if constexpr (std::endian::native == std::endian::big)
|
||||||
|
v = __builtin_bswap64(v);
|
||||||
|
hash = IntHash64Impl::apply(v);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
hash = IntHash32Impl::apply(bit_cast<UInt32>(value));
|
{
|
||||||
|
UInt32 v = bit_cast<UInt32>(value);
|
||||||
|
if constexpr (std::endian::native == std::endian::big)
|
||||||
|
v = __builtin_bswap32(v);
|
||||||
|
hash = IntHash32Impl::apply(v);
|
||||||
|
}
|
||||||
|
|
||||||
size_t size = vec_to.size();
|
size_t size = vec_to.size();
|
||||||
if constexpr (first)
|
if constexpr (first)
|
||||||
@ -1080,8 +1111,17 @@ private:
|
|||||||
size_t size = vec_from.size();
|
size_t size = vec_from.size();
|
||||||
for (size_t i = 0; i < size; ++i)
|
for (size_t i = 0; i < size; ++i)
|
||||||
{
|
{
|
||||||
ToType h = apply(key, reinterpret_cast<const char *>(&vec_from[i]), sizeof(vec_from[i]));
|
ToType h;
|
||||||
|
if constexpr (std::endian::native == std::endian::little)
|
||||||
|
{
|
||||||
|
h = apply(key, reinterpret_cast<const char *>(&vec_from[i]), sizeof(vec_from[i]));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char tmp_buffer[sizeof(vec_from[i])];
|
||||||
|
reverseMemcpy(tmp_buffer, &vec_from[i], sizeof(vec_from[i]));
|
||||||
|
h = apply(key, reinterpret_cast<const char *>(tmp_buffer), sizeof(vec_from[i]));
|
||||||
|
}
|
||||||
if constexpr (first)
|
if constexpr (first)
|
||||||
vec_to[i] = h;
|
vec_to[i] = h;
|
||||||
else
|
else
|
||||||
@ -1092,8 +1132,17 @@ private:
|
|||||||
{
|
{
|
||||||
auto value = col_from_const->template getValue<FromType>();
|
auto value = col_from_const->template getValue<FromType>();
|
||||||
|
|
||||||
ToType h = apply(key, reinterpret_cast<const char *>(&value), sizeof(value));
|
ToType h;
|
||||||
|
if constexpr (std::endian::native == std::endian::little)
|
||||||
|
{
|
||||||
|
h = apply(key, reinterpret_cast<const char *>(&value), sizeof(value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char tmp_buffer[sizeof(value)];
|
||||||
|
reverseMemcpy(tmp_buffer, &value, sizeof(value));
|
||||||
|
h = apply(key, reinterpret_cast<const char *>(tmp_buffer), sizeof(value));
|
||||||
|
}
|
||||||
size_t size = vec_to.size();
|
size_t size = vec_to.size();
|
||||||
if constexpr (first)
|
if constexpr (first)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user