/root/doris/be/src/vec/common/unaligned.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // This file is copied from |
18 | | // https://github.com/ClickHouse/ClickHouse/blob/master/base/base/unaligned.h |
19 | | // and modified by Doris |
20 | | |
21 | | #pragma once |
22 | | |
23 | | #include <bit> |
24 | | #include <cstdint> |
25 | | #include <cstring> |
26 | | #include <type_traits> |
27 | | |
28 | | template <typename T> |
29 | 367M | T unaligned_load(const void* address) { |
30 | 367M | T res {}; |
31 | 367M | memcpy(&res, address, sizeof(res)); |
32 | 367M | return res; |
33 | 367M | } _Z14unaligned_loadImET_PKv Line | Count | Source | 29 | 333M | T unaligned_load(const void* address) { | 30 | 333M | T res {}; | 31 | 333M | memcpy(&res, address, sizeof(res)); | 32 | 333M | return res; | 33 | 333M | } |
_Z14unaligned_loadIjET_PKv Line | Count | Source | 29 | 825k | T unaligned_load(const void* address) { | 30 | 825k | T res {}; | 31 | 825k | memcpy(&res, address, sizeof(res)); | 32 | 825k | return res; | 33 | 825k | } |
_Z14unaligned_loadItET_PKv Line | Count | Source | 29 | 333 | T unaligned_load(const void* address) { | 30 | 333 | T res {}; | 31 | 333 | memcpy(&res, address, sizeof(res)); | 32 | 333 | return res; | 33 | 333 | } |
_Z14unaligned_loadIhET_PKv Line | Count | Source | 29 | 186 | T unaligned_load(const void* address) { | 30 | 186 | T res {}; | 31 | 186 | memcpy(&res, address, sizeof(res)); | 32 | 186 | return res; | 33 | 186 | } |
_Z14unaligned_loadIlET_PKv Line | Count | Source | 29 | 6.76M | T unaligned_load(const void* address) { | 30 | 6.76M | T res {}; | 31 | 6.76M | memcpy(&res, address, sizeof(res)); | 32 | 6.76M | return res; | 33 | 6.76M | } |
_Z14unaligned_loadIoET_PKv Line | Count | Source | 29 | 1.56k | T unaligned_load(const void* address) { | 30 | 1.56k | T res {}; | 31 | 1.56k | memcpy(&res, address, sizeof(res)); | 32 | 1.56k | return res; | 33 | 1.56k | } |
_Z14unaligned_loadIiET_PKv Line | Count | Source | 29 | 16.8M | T unaligned_load(const void* address) { | 30 | 16.8M | T res {}; | 31 | 16.8M | memcpy(&res, address, sizeof(res)); | 32 | 16.8M | return res; | 33 | 16.8M | } |
_Z14unaligned_loadIdET_PKv Line | Count | Source | 29 | 5.31k | T unaligned_load(const void* address) { | 30 | 5.31k | T res {}; | 31 | 5.31k | memcpy(&res, address, sizeof(res)); | 32 | 5.31k | return res; | 33 | 5.31k | } |
_Z14unaligned_loadIaET_PKv Line | Count | Source | 29 | 2.10M | T unaligned_load(const void* address) { | 30 | 2.10M | T res {}; | 31 | 2.10M | memcpy(&res, address, sizeof(res)); | 32 | 2.10M | return res; | 33 | 2.10M | } |
_Z14unaligned_loadIsET_PKv Line | Count | Source | 29 | 4.28k | T unaligned_load(const void* address) { | 30 | 4.28k | T res {}; | 31 | 4.28k | memcpy(&res, address, sizeof(res)); | 32 | 4.28k | return res; | 33 | 4.28k | } |
_Z14unaligned_loadInET_PKv Line | Count | Source | 29 | 2.43k | T unaligned_load(const void* address) { | 30 | 2.43k | T res {}; | 31 | 2.43k | memcpy(&res, address, sizeof(res)); | 32 | 2.43k | return res; | 33 | 2.43k | } |
_Z14unaligned_loadIfET_PKv Line | Count | Source | 29 | 1.71k | T unaligned_load(const void* address) { | 30 | 1.71k | T res {}; | 31 | 1.71k | memcpy(&res, address, sizeof(res)); | 32 | 1.71k | return res; | 33 | 1.71k | } |
_Z14unaligned_loadIN5doris8uint24_tEET_PKv Line | Count | Source | 29 | 12 | T unaligned_load(const void* address) { | 30 | 12 | T res {}; | 31 | 12 | memcpy(&res, address, sizeof(res)); | 32 | 12 | return res; | 33 | 12 | } |
Unexecuted instantiation: _Z14unaligned_loadIN4wide7integerILm128EjEEET_PKv _Z14unaligned_loadIN5doris9StringRefEET_PKv Line | Count | Source | 29 | 8.83k | T unaligned_load(const void* address) { | 30 | 8.83k | T res {}; | 31 | 8.83k | memcpy(&res, address, sizeof(res)); | 32 | 8.83k | return res; | 33 | 8.83k | } |
Unexecuted instantiation: _Z14unaligned_loadIN4wide7integerILm256EiEEET_PKv _Z14unaligned_loadIN5doris11decimal12_tEET_PKv Line | Count | Source | 29 | 4 | T unaligned_load(const void* address) { | 30 | 4 | T res {}; | 31 | 4 | memcpy(&res, address, sizeof(res)); | 32 | 4 | return res; | 33 | 4 | } |
Unexecuted instantiation: _Z14unaligned_loadIbET_PKv _Z14unaligned_loadI10Elf64_NhdrET_PKv Line | Count | Source | 29 | 31 | T unaligned_load(const void* address) { | 30 | 31 | T res {}; | 31 | 31 | memcpy(&res, address, sizeof(res)); | 32 | 31 | return res; | 33 | 31 | } |
_Z14unaligned_loadIN5doris10vectorized7DecimalIiEEET_PKv Line | Count | Source | 29 | 1.23k | T unaligned_load(const void* address) { | 30 | 1.23k | T res {}; | 31 | 1.23k | memcpy(&res, address, sizeof(res)); | 32 | 1.23k | return res; | 33 | 1.23k | } |
_Z14unaligned_loadIN5doris10vectorized7DecimalIlEEET_PKv Line | Count | Source | 29 | 6.76M | T unaligned_load(const void* address) { | 30 | 6.76M | T res {}; | 31 | 6.76M | memcpy(&res, address, sizeof(res)); | 32 | 6.76M | return res; | 33 | 6.76M | } |
_Z14unaligned_loadIN5doris10vectorized7DecimalInEEET_PKv Line | Count | Source | 29 | 4.69k | T unaligned_load(const void* address) { | 30 | 4.69k | T res {}; | 31 | 4.69k | memcpy(&res, address, sizeof(res)); | 32 | 4.69k | return res; | 33 | 4.69k | } |
_Z14unaligned_loadIN5doris10vectorized12Decimal128V3EET_PKv Line | Count | Source | 29 | 5.48k | T unaligned_load(const void* address) { | 30 | 5.48k | T res {}; | 31 | 5.48k | memcpy(&res, address, sizeof(res)); | 32 | 5.48k | return res; | 33 | 5.48k | } |
_Z14unaligned_loadIN5doris10vectorized7DecimalIN4wide7integerILm256EiEEEEET_PKv Line | Count | Source | 29 | 4.37k | T unaligned_load(const void* address) { | 30 | 4.37k | T res {}; | 31 | 4.37k | memcpy(&res, address, sizeof(res)); | 32 | 4.37k | return res; | 33 | 4.37k | } |
|
34 | | |
35 | | /// We've had troubles before with wrong store size due to integral promotions |
36 | | /// (e.g., unaligned_store(dest, uint16_t + uint16_t) stores an uint32_t). |
37 | | /// To prevent this, make the caller specify the stored type explicitly. |
38 | | /// To disable deduction of T, wrap the argument type with std::enable_if. |
39 | | template <typename T> |
40 | 18.7k | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { |
41 | 18.7k | static_assert(std::is_trivially_copyable_v<T>); |
42 | 18.7k | memcpy(address, &src, sizeof(src)); |
43 | 18.7k | } _Z15unaligned_storeIhEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 146 | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 146 | static_assert(std::is_trivially_copyable_v<T>); | 42 | 146 | memcpy(address, &src, sizeof(src)); | 43 | 146 | } |
_Z15unaligned_storeItEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 74 | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 74 | static_assert(std::is_trivially_copyable_v<T>); | 42 | 74 | memcpy(address, &src, sizeof(src)); | 43 | 74 | } |
_Z15unaligned_storeIjEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 2.71k | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 2.71k | static_assert(std::is_trivially_copyable_v<T>); | 42 | 2.71k | memcpy(address, &src, sizeof(src)); | 43 | 2.71k | } |
_Z15unaligned_storeImEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 2.33k | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 2.33k | static_assert(std::is_trivially_copyable_v<T>); | 42 | 2.33k | memcpy(address, &src, sizeof(src)); | 43 | 2.33k | } |
Unexecuted instantiation: _Z15unaligned_storeIN4wide7integerILm128EjEEEvPvRKNSt9enable_ifILb1ET_E4typeE _Z15unaligned_storeIaEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 1.86k | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 1.86k | static_assert(std::is_trivially_copyable_v<T>); | 42 | 1.86k | memcpy(address, &src, sizeof(src)); | 43 | 1.86k | } |
_Z15unaligned_storeIsEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 1.41k | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 1.41k | static_assert(std::is_trivially_copyable_v<T>); | 42 | 1.41k | memcpy(address, &src, sizeof(src)); | 43 | 1.41k | } |
_Z15unaligned_storeIiEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 1.59k | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 1.59k | static_assert(std::is_trivially_copyable_v<T>); | 42 | 1.59k | memcpy(address, &src, sizeof(src)); | 43 | 1.59k | } |
_Z15unaligned_storeIlEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 2.67k | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 2.67k | static_assert(std::is_trivially_copyable_v<T>); | 42 | 2.67k | memcpy(address, &src, sizeof(src)); | 43 | 2.67k | } |
_Z15unaligned_storeInEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 1.26k | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 1.26k | static_assert(std::is_trivially_copyable_v<T>); | 42 | 1.26k | memcpy(address, &src, sizeof(src)); | 43 | 1.26k | } |
_Z15unaligned_storeIfEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 1.47k | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 1.47k | static_assert(std::is_trivially_copyable_v<T>); | 42 | 1.47k | memcpy(address, &src, sizeof(src)); | 43 | 1.47k | } |
_Z15unaligned_storeIdEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 1.62k | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 1.62k | static_assert(std::is_trivially_copyable_v<T>); | 42 | 1.62k | memcpy(address, &src, sizeof(src)); | 43 | 1.62k | } |
_Z15unaligned_storeIoEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 1.54k | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 1.54k | static_assert(std::is_trivially_copyable_v<T>); | 42 | 1.54k | memcpy(address, &src, sizeof(src)); | 43 | 1.54k | } |
|
44 | | |
45 | 0 | inline void reverse_memcpy(void* dst, const void* src, size_t size) { |
46 | 0 | uint8_t* uint_dst = reinterpret_cast<uint8_t*>(dst) + size; // Perform addition here |
47 | 0 | const uint8_t* uint_src = reinterpret_cast<const uint8_t*>(src); |
48 | 0 |
|
49 | 0 | while (size) { |
50 | 0 | --uint_dst; |
51 | 0 | *uint_dst = *uint_src; |
52 | 0 | ++uint_src; |
53 | 0 | --size; |
54 | 0 | } |
55 | 0 | } |
56 | | |
57 | | template <std::endian endian, typename T> |
58 | 15 | inline T unaligned_load_endian(const void* address) { |
59 | 15 | T res {}; |
60 | 15 | if constexpr (std::endian::native == endian) { |
61 | 15 | memcpy(&res, address, sizeof(res)); |
62 | 15 | } else { |
63 | 15 | reverse_memcpy(&res, address, sizeof(res)); |
64 | 15 | } |
65 | 15 | return res; |
66 | 15 | } _Z21unaligned_load_endianILSt6endian1234EmET0_PKv Line | Count | Source | 58 | 15 | inline T unaligned_load_endian(const void* address) { | 59 | 15 | T res {}; | 60 | 15 | if constexpr (std::endian::native == endian) { | 61 | 15 | memcpy(&res, address, sizeof(res)); | 62 | 15 | } else { | 63 | 15 | reverse_memcpy(&res, address, sizeof(res)); | 64 | 15 | } | 65 | 15 | return res; | 66 | 15 | } |
Unexecuted instantiation: _Z21unaligned_load_endianILSt6endian1234EjET0_PKv |
67 | | |
68 | | template <typename T> |
69 | 15 | inline T unaligned_load_little_endian(const void* address) { |
70 | 15 | return unaligned_load_endian<std::endian::little, T>(address); |
71 | 15 | } _Z28unaligned_load_little_endianImET_PKv Line | Count | Source | 69 | 15 | inline T unaligned_load_little_endian(const void* address) { | 70 | 15 | return unaligned_load_endian<std::endian::little, T>(address); | 71 | 15 | } |
Unexecuted instantiation: _Z28unaligned_load_little_endianIjET_PKv |