From 9c066e964d2d3a2abd07e99d1406e8b2d975d909 Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Fri, 4 Nov 2022 15:52:48 +0000 Subject: [PATCH] Less use of CH-specific bit_cast() Converted usage of CH-custom bit_cast to std::bit_cast if possible, i.e. when sizeof(From) == sizeof(To). (The CH-custom bit_cast is able to deal with sizeof(From) != sizeof(To).) Motivation for this came from #42847 where it is not clear how the internal bit_cast should behave on big endian systems, so we better avoid that situation as much as possible. --- programs/library-bridge/ExternalDictionaryLibraryHandler.cpp | 3 +-- programs/library-bridge/ExternalDictionaryLibraryUtils.h | 1 - programs/obfuscator/Obfuscator.cpp | 5 ++--- src/AggregateFunctions/QuantileBFloat16Histogram.h | 5 ++--- src/Databases/MySQL/MaterializedMySQLSyncThread.cpp | 1 - src/Functions/FunctionsRound.h | 1 - src/Functions/isFinite.cpp | 5 ++--- src/Functions/isInfinite.cpp | 5 ++--- src/Functions/padString.cpp | 5 ++--- src/Interpreters/BloomFilterHash.h | 1 - .../MergeTree/MergeTreeIndexAggregatorBloomFilter.cpp | 1 - src/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp | 1 - src/Storages/MergeTree/MergeTreeIndexGranuleBloomFilter.cpp | 1 - 13 files changed, 11 insertions(+), 24 deletions(-) diff --git a/programs/library-bridge/ExternalDictionaryLibraryHandler.cpp b/programs/library-bridge/ExternalDictionaryLibraryHandler.cpp index 14850da2ebf..c60d4a4e5cc 100644 --- a/programs/library-bridge/ExternalDictionaryLibraryHandler.cpp +++ b/programs/library-bridge/ExternalDictionaryLibraryHandler.cpp @@ -1,7 +1,6 @@ #include "ExternalDictionaryLibraryHandler.h" #include -#include #include #include @@ -113,7 +112,7 @@ Block ExternalDictionaryLibraryHandler::loadAll() Block ExternalDictionaryLibraryHandler::loadIds(const std::vector & ids) { - const ExternalDictionaryLibraryAPI::VectorUInt64 ids_data{bit_cast(ids.data()), ids.size()}; + const ExternalDictionaryLibraryAPI::VectorUInt64 ids_data{std::bit_cast(ids.data()), ids.size()}; auto columns_holder = std::make_unique(attributes_names.size()); ExternalDictionaryLibraryAPI::CStrings columns_pass{static_cast(columns_holder.get()), attributes_names.size()}; diff --git a/programs/library-bridge/ExternalDictionaryLibraryUtils.h b/programs/library-bridge/ExternalDictionaryLibraryUtils.h index e813efab2a6..c9d03d27f75 100644 --- a/programs/library-bridge/ExternalDictionaryLibraryUtils.h +++ b/programs/library-bridge/ExternalDictionaryLibraryUtils.h @@ -2,7 +2,6 @@ #include #include -#include #include #include "ExternalDictionaryLibraryAPI.h" diff --git a/programs/obfuscator/Obfuscator.cpp b/programs/obfuscator/Obfuscator.cpp index 7fdc5a54d8a..b6952ad6cb0 100644 --- a/programs/obfuscator/Obfuscator.cpp +++ b/programs/obfuscator/Obfuscator.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -278,9 +277,9 @@ Float transformFloatMantissa(Float x, UInt64 seed) using UInt = std::conditional_t, UInt32, UInt64>; constexpr size_t mantissa_num_bits = std::is_same_v ? 23 : 52; - UInt x_uint = bit_cast(x); + UInt x_uint = std::bit_cast(x); x_uint = static_cast(feistelNetwork(x_uint, mantissa_num_bits, seed)); - return bit_cast(x_uint); + return std::bit_cast(x_uint); } diff --git a/src/AggregateFunctions/QuantileBFloat16Histogram.h b/src/AggregateFunctions/QuantileBFloat16Histogram.h index 8ec325e238d..de9f61e01a2 100644 --- a/src/AggregateFunctions/QuantileBFloat16Histogram.h +++ b/src/AggregateFunctions/QuantileBFloat16Histogram.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include @@ -104,13 +103,13 @@ private: /// Take the most significant 16 bits of the floating point number. BFloat16 toBFloat16(const Value & x) const { - return bit_cast(static_cast(x)) >> 16; + return std::bit_cast(static_cast(x)) >> 16; } /// Put the bits into most significant 16 bits of the floating point number and fill other bits with zeros. Float32 toFloat32(const BFloat16 & x) const { - return bit_cast(x << 16); + return std::bit_cast(x << 16); } using Pair = PairNoInit; diff --git a/src/Databases/MySQL/MaterializedMySQLSyncThread.cpp b/src/Databases/MySQL/MaterializedMySQLSyncThread.cpp index ed9199a359f..29f5719e3ed 100644 --- a/src/Databases/MySQL/MaterializedMySQLSyncThread.cpp +++ b/src/Databases/MySQL/MaterializedMySQLSyncThread.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include diff --git a/src/Functions/FunctionsRound.h b/src/Functions/FunctionsRound.h index 283f1ea5a43..2c7883cf471 100644 --- a/src/Functions/FunctionsRound.h +++ b/src/Functions/FunctionsRound.h @@ -16,7 +16,6 @@ #include #include #include -#include #include #include diff --git a/src/Functions/isFinite.cpp b/src/Functions/isFinite.cpp index 90185b64fff..612e7067bf5 100644 --- a/src/Functions/isFinite.cpp +++ b/src/Functions/isFinite.cpp @@ -1,6 +1,5 @@ #include #include -#include #include @@ -20,11 +19,11 @@ struct IsFiniteImpl static bool execute(const T t) { if constexpr (std::is_same_v) - return (bit_cast(t) + return (std::bit_cast(t) & 0b01111111100000000000000000000000) != 0b01111111100000000000000000000000; else if constexpr (std::is_same_v) - return (bit_cast(t) + return (std::bit_cast(t) & 0b0111111111110000000000000000000000000000000000000000000000000000) != 0b0111111111110000000000000000000000000000000000000000000000000000; else diff --git a/src/Functions/isInfinite.cpp b/src/Functions/isInfinite.cpp index e923e1461bc..ace2c334873 100644 --- a/src/Functions/isInfinite.cpp +++ b/src/Functions/isInfinite.cpp @@ -1,6 +1,5 @@ #include #include -#include #include @@ -16,11 +15,11 @@ struct IsInfiniteImpl static bool execute(const T t) { if constexpr (std::is_same_v) - return (bit_cast(t) + return (std::bit_cast(t) & 0b01111111111111111111111111111111) == 0b01111111100000000000000000000000; else if constexpr (std::is_same_v) - return (bit_cast(t) + return (std::bit_cast(t) & 0b0111111111111111111111111111111111111111111111111111111111111111) == 0b0111111111110000000000000000000000000000000000000000000000000000; else diff --git a/src/Functions/padString.cpp b/src/Functions/padString.cpp index c8ed920755c..486fa328fa0 100644 --- a/src/Functions/padString.cpp +++ b/src/Functions/padString.cpp @@ -5,7 +5,6 @@ #include #include #include -#include namespace DB { @@ -59,10 +58,10 @@ namespace { if (num_chars <= step) { - writeSlice(StringSource::Slice{bit_cast(pad_string.data()), numCharsToNumBytes(num_chars)}, res_sink); + writeSlice(StringSource::Slice{std::bit_cast(pad_string.data()), numCharsToNumBytes(num_chars)}, res_sink); break; } - writeSlice(StringSource::Slice{bit_cast(pad_string.data()), numCharsToNumBytes(step)}, res_sink); + writeSlice(StringSource::Slice{std::bit_cast(pad_string.data()), numCharsToNumBytes(step)}, res_sink); num_chars -= step; } } diff --git a/src/Interpreters/BloomFilterHash.h b/src/Interpreters/BloomFilterHash.h index 31532cc888a..b95abbfd770 100644 --- a/src/Interpreters/BloomFilterHash.h +++ b/src/Interpreters/BloomFilterHash.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include diff --git a/src/Storages/MergeTree/MergeTreeIndexAggregatorBloomFilter.cpp b/src/Storages/MergeTree/MergeTreeIndexAggregatorBloomFilter.cpp index b19080b5097..9bc0e4e6dc0 100644 --- a/src/Storages/MergeTree/MergeTreeIndexAggregatorBloomFilter.cpp +++ b/src/Storages/MergeTree/MergeTreeIndexAggregatorBloomFilter.cpp @@ -1,6 +1,5 @@ #include -#include #include #include #include diff --git a/src/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp b/src/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp index 33668b96a60..c2ed081ac00 100644 --- a/src/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp +++ b/src/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include diff --git a/src/Storages/MergeTree/MergeTreeIndexGranuleBloomFilter.cpp b/src/Storages/MergeTree/MergeTreeIndexGranuleBloomFilter.cpp index f80d40d2fa8..7efaf0866db 100644 --- a/src/Storages/MergeTree/MergeTreeIndexGranuleBloomFilter.cpp +++ b/src/Storages/MergeTree/MergeTreeIndexGranuleBloomFilter.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include