Merge pull request #42968 from ClickHouse/bitcast

Less use of CH-specific bit_cast()
This commit is contained in:
Robert Schulze 2022-11-08 10:54:10 +01:00 committed by GitHub
commit 2c568df714
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 11 additions and 24 deletions

View File

@ -1,7 +1,6 @@
#include "ExternalDictionaryLibraryHandler.h" #include "ExternalDictionaryLibraryHandler.h"
#include <base/scope_guard.h> #include <base/scope_guard.h>
#include <base/bit_cast.h>
#include <base/find_symbols.h> #include <base/find_symbols.h>
#include <IO/ReadHelpers.h> #include <IO/ReadHelpers.h>
@ -113,7 +112,7 @@ Block ExternalDictionaryLibraryHandler::loadAll()
Block ExternalDictionaryLibraryHandler::loadIds(const std::vector<uint64_t> & ids) Block ExternalDictionaryLibraryHandler::loadIds(const std::vector<uint64_t> & ids)
{ {
const ExternalDictionaryLibraryAPI::VectorUInt64 ids_data{bit_cast<decltype(ExternalDictionaryLibraryAPI::VectorUInt64::data)>(ids.data()), ids.size()}; const ExternalDictionaryLibraryAPI::VectorUInt64 ids_data{std::bit_cast<decltype(ExternalDictionaryLibraryAPI::VectorUInt64::data)>(ids.data()), ids.size()};
auto columns_holder = std::make_unique<ExternalDictionaryLibraryAPI::CString[]>(attributes_names.size()); auto columns_holder = std::make_unique<ExternalDictionaryLibraryAPI::CString[]>(attributes_names.size());
ExternalDictionaryLibraryAPI::CStrings columns_pass{static_cast<decltype(ExternalDictionaryLibraryAPI::CStrings::data)>(columns_holder.get()), attributes_names.size()}; ExternalDictionaryLibraryAPI::CStrings columns_pass{static_cast<decltype(ExternalDictionaryLibraryAPI::CStrings::data)>(columns_holder.get()), attributes_names.size()};

View File

@ -2,7 +2,6 @@
#include <Common/StringUtils/StringUtils.h> #include <Common/StringUtils/StringUtils.h>
#include <Core/Block.h> #include <Core/Block.h>
#include <base/bit_cast.h>
#include <base/range.h> #include <base/range.h>
#include "ExternalDictionaryLibraryAPI.h" #include "ExternalDictionaryLibraryAPI.h"

View File

@ -32,7 +32,6 @@
#include <Core/Block.h> #include <Core/Block.h>
#include <base/StringRef.h> #include <base/StringRef.h>
#include <Common/DateLUT.h> #include <Common/DateLUT.h>
#include <base/bit_cast.h>
#include <IO/ReadBufferFromFileDescriptor.h> #include <IO/ReadBufferFromFileDescriptor.h>
#include <IO/WriteBufferFromFileDescriptor.h> #include <IO/WriteBufferFromFileDescriptor.h>
#include <IO/ReadBufferFromFile.h> #include <IO/ReadBufferFromFile.h>
@ -278,9 +277,9 @@ Float transformFloatMantissa(Float x, UInt64 seed)
using UInt = std::conditional_t<std::is_same_v<Float, Float32>, UInt32, UInt64>; using UInt = std::conditional_t<std::is_same_v<Float, Float32>, UInt32, UInt64>;
constexpr size_t mantissa_num_bits = std::is_same_v<Float, Float32> ? 23 : 52; constexpr size_t mantissa_num_bits = std::is_same_v<Float, Float32> ? 23 : 52;
UInt x_uint = bit_cast<UInt>(x); UInt x_uint = std::bit_cast<UInt>(x);
x_uint = static_cast<UInt>(feistelNetwork(x_uint, mantissa_num_bits, seed)); x_uint = static_cast<UInt>(feistelNetwork(x_uint, mantissa_num_bits, seed));
return bit_cast<Float>(x_uint); return std::bit_cast<Float>(x_uint);
} }

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <base/types.h> #include <base/types.h>
#include <base/bit_cast.h>
#include <base/sort.h> #include <base/sort.h>
#include <Common/HashTable/HashMap.h> #include <Common/HashTable/HashMap.h>
@ -104,13 +103,13 @@ private:
/// Take the most significant 16 bits of the floating point number. /// Take the most significant 16 bits of the floating point number.
BFloat16 toBFloat16(const Value & x) const BFloat16 toBFloat16(const Value & x) const
{ {
return bit_cast<UInt32>(static_cast<Float32>(x)) >> 16; return std::bit_cast<UInt32>(static_cast<Float32>(x)) >> 16;
} }
/// Put the bits into most significant 16 bits of the floating point number and fill other bits with zeros. /// 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 Float32 toFloat32(const BFloat16 & x) const
{ {
return bit_cast<Float32>(x << 16); return std::bit_cast<Float32>(x << 16);
} }
using Pair = PairNoInit<Float32, Weight>; using Pair = PairNoInit<Float32, Weight>;

View File

@ -24,7 +24,6 @@
#include <Common/quoteString.h> #include <Common/quoteString.h>
#include <Common/setThreadName.h> #include <Common/setThreadName.h>
#include <base/sleep.h> #include <base/sleep.h>
#include <base/bit_cast.h>
#include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/trim.hpp> #include <boost/algorithm/string/trim.hpp>
#include <Parsers/CommonParsers.h> #include <Parsers/CommonParsers.h>

View File

@ -16,7 +16,6 @@
#include <cmath> #include <cmath>
#include <type_traits> #include <type_traits>
#include <array> #include <array>
#include <base/bit_cast.h>
#include <base/sort.h> #include <base/sort.h>
#include <algorithm> #include <algorithm>

View File

@ -1,6 +1,5 @@
#include <Functions/FunctionNumericPredicate.h> #include <Functions/FunctionNumericPredicate.h>
#include <Functions/FunctionFactory.h> #include <Functions/FunctionFactory.h>
#include <base/bit_cast.h>
#include <type_traits> #include <type_traits>
@ -20,11 +19,11 @@ struct IsFiniteImpl
static bool execute(const T t) static bool execute(const T t)
{ {
if constexpr (std::is_same_v<T, float>) if constexpr (std::is_same_v<T, float>)
return (bit_cast<uint32_t>(t) return (std::bit_cast<uint32_t>(t)
& 0b01111111100000000000000000000000) & 0b01111111100000000000000000000000)
!= 0b01111111100000000000000000000000; != 0b01111111100000000000000000000000;
else if constexpr (std::is_same_v<T, double>) else if constexpr (std::is_same_v<T, double>)
return (bit_cast<uint64_t>(t) return (std::bit_cast<uint64_t>(t)
& 0b0111111111110000000000000000000000000000000000000000000000000000) & 0b0111111111110000000000000000000000000000000000000000000000000000)
!= 0b0111111111110000000000000000000000000000000000000000000000000000; != 0b0111111111110000000000000000000000000000000000000000000000000000;
else else

View File

@ -1,6 +1,5 @@
#include <Functions/FunctionNumericPredicate.h> #include <Functions/FunctionNumericPredicate.h>
#include <Functions/FunctionFactory.h> #include <Functions/FunctionFactory.h>
#include <base/bit_cast.h>
#include <type_traits> #include <type_traits>
@ -16,11 +15,11 @@ struct IsInfiniteImpl
static bool execute(const T t) static bool execute(const T t)
{ {
if constexpr (std::is_same_v<T, float>) if constexpr (std::is_same_v<T, float>)
return (bit_cast<uint32_t>(t) return (std::bit_cast<uint32_t>(t)
& 0b01111111111111111111111111111111) & 0b01111111111111111111111111111111)
== 0b01111111100000000000000000000000; == 0b01111111100000000000000000000000;
else if constexpr (std::is_same_v<T, double>) else if constexpr (std::is_same_v<T, double>)
return (bit_cast<uint64_t>(t) return (std::bit_cast<uint64_t>(t)
& 0b0111111111111111111111111111111111111111111111111111111111111111) & 0b0111111111111111111111111111111111111111111111111111111111111111)
== 0b0111111111110000000000000000000000000000000000000000000000000000; == 0b0111111111110000000000000000000000000000000000000000000000000000;
else else

View File

@ -5,7 +5,6 @@
#include <Functions/GatherUtils/Algorithms.h> #include <Functions/GatherUtils/Algorithms.h>
#include <Functions/GatherUtils/Sinks.h> #include <Functions/GatherUtils/Sinks.h>
#include <Functions/GatherUtils/Sources.h> #include <Functions/GatherUtils/Sources.h>
#include <base/bit_cast.h>
namespace DB namespace DB
{ {
@ -59,10 +58,10 @@ namespace
{ {
if (num_chars <= step) if (num_chars <= step)
{ {
writeSlice(StringSource::Slice{bit_cast<const UInt8 *>(pad_string.data()), numCharsToNumBytes(num_chars)}, res_sink); writeSlice(StringSource::Slice{std::bit_cast<const UInt8 *>(pad_string.data()), numCharsToNumBytes(num_chars)}, res_sink);
break; break;
} }
writeSlice(StringSource::Slice{bit_cast<const UInt8 *>(pad_string.data()), numCharsToNumBytes(step)}, res_sink); writeSlice(StringSource::Slice{std::bit_cast<const UInt8 *>(pad_string.data()), numCharsToNumBytes(step)}, res_sink);
num_chars -= step; num_chars -= step;
} }
} }

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include <base/bit_cast.h>
#include <Common/HashTable/Hash.h> #include <Common/HashTable/Hash.h>
#include <Columns/IColumn.h> #include <Columns/IColumn.h>
#include <Columns/ColumnArray.h> #include <Columns/ColumnArray.h>

View File

@ -1,6 +1,5 @@
#include <Storages/MergeTree/MergeTreeIndexAggregatorBloomFilter.h> #include <Storages/MergeTree/MergeTreeIndexAggregatorBloomFilter.h>
#include <base/bit_cast.h>
#include <Columns/ColumnString.h> #include <Columns/ColumnString.h>
#include <Columns/ColumnsNumber.h> #include <Columns/ColumnsNumber.h>
#include <Columns/ColumnFixedString.h> #include <Columns/ColumnFixedString.h>

View File

@ -3,7 +3,6 @@
#include <Interpreters/TreeRewriter.h> #include <Interpreters/TreeRewriter.h>
#include <Interpreters/ExpressionAnalyzer.h> #include <Interpreters/ExpressionAnalyzer.h>
#include <base/types.h> #include <base/types.h>
#include <base/bit_cast.h>
#include <DataTypes/DataTypeNullable.h> #include <DataTypes/DataTypeNullable.h>
#include <Storages/MergeTree/MergeTreeIndexConditionBloomFilter.h> #include <Storages/MergeTree/MergeTreeIndexConditionBloomFilter.h>
#include <Columns/ColumnConst.h> #include <Columns/ColumnConst.h>

View File

@ -5,7 +5,6 @@
#include <Columns/ColumnFixedString.h> #include <Columns/ColumnFixedString.h>
#include <DataTypes/DataTypeNullable.h> #include <DataTypes/DataTypeNullable.h>
#include <Common/HashTable/Hash.h> #include <Common/HashTable/Hash.h>
#include <base/bit_cast.h>
#include <Interpreters/BloomFilterHash.h> #include <Interpreters/BloomFilterHash.h>
#include <IO/WriteHelpers.h> #include <IO/WriteHelpers.h>