/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 | 34.2M | T unaligned_load(const void* address) { |
30 | 34.2M | T res {}; |
31 | 34.2M | memcpy(&res, address, sizeof(res)); |
32 | 34.2M | return res; |
33 | 34.2M | } _Z14unaligned_loadImET_PKv Line | Count | Source | 29 | 1.25M | T unaligned_load(const void* address) { | 30 | 1.25M | T res {}; | 31 | 1.25M | memcpy(&res, address, sizeof(res)); | 32 | 1.25M | return res; | 33 | 1.25M | } |
_Z14unaligned_loadIjET_PKv Line | Count | Source | 29 | 628k | T unaligned_load(const void* address) { | 30 | 628k | T res {}; | 31 | 628k | memcpy(&res, address, sizeof(res)); | 32 | 628k | return res; | 33 | 628k | } |
Unexecuted instantiation: _Z14unaligned_loadItET_PKv _Z14unaligned_loadIhET_PKv Line | Count | Source | 29 | 28 | T unaligned_load(const void* address) { | 30 | 28 | T res {}; | 31 | 28 | memcpy(&res, address, sizeof(res)); | 32 | 28 | return res; | 33 | 28 | } |
_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 | 10 | T unaligned_load(const void* address) { | 30 | 10 | T res {}; | 31 | 10 | memcpy(&res, address, sizeof(res)); | 32 | 10 | return res; | 33 | 10 | } |
_Z14unaligned_loadIdET_PKv Line | Count | Source | 29 | 3.69k | T unaligned_load(const void* address) { | 30 | 3.69k | T res {}; | 31 | 3.69k | memcpy(&res, address, sizeof(res)); | 32 | 3.69k | return res; | 33 | 3.69k | } |
_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 | 2.56k | T unaligned_load(const void* address) { | 30 | 2.56k | T res {}; | 31 | 2.56k | memcpy(&res, address, sizeof(res)); | 32 | 2.56k | return res; | 33 | 2.56k | } |
_Z14unaligned_loadIiET_PKv Line | Count | Source | 29 | 16.7M | T unaligned_load(const void* address) { | 30 | 16.7M | T res {}; | 31 | 16.7M | memcpy(&res, address, sizeof(res)); | 32 | 16.7M | return res; | 33 | 16.7M | } |
_Z14unaligned_loadInET_PKv Line | Count | Source | 29 | 902 | T unaligned_load(const void* address) { | 30 | 902 | T res {}; | 31 | 902 | memcpy(&res, address, sizeof(res)); | 32 | 902 | return res; | 33 | 902 | } |
_Z14unaligned_loadIfET_PKv Line | Count | Source | 29 | 244 | T unaligned_load(const void* address) { | 30 | 244 | T res {}; | 31 | 244 | memcpy(&res, address, sizeof(res)); | 32 | 244 | return res; | 33 | 244 | } |
_Z14unaligned_loadIN5doris8uint24_tEET_PKv Line | Count | Source | 29 | 8 | T unaligned_load(const void* address) { | 30 | 8 | T res {}; | 31 | 8 | memcpy(&res, address, sizeof(res)); | 32 | 8 | return res; | 33 | 8 | } |
_Z14unaligned_loadIN5doris9StringRefEET_PKv Line | Count | Source | 29 | 808 | T unaligned_load(const void* address) { | 30 | 808 | T res {}; | 31 | 808 | memcpy(&res, address, sizeof(res)); | 32 | 808 | return res; | 33 | 808 | } |
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 | } |
Unexecuted instantiation: _Z14unaligned_loadIN5doris10vectorized7DecimalIiEEET_PKv _Z14unaligned_loadIN5doris10vectorized7DecimalIlEEET_PKv Line | Count | Source | 29 | 6.75M | T unaligned_load(const void* address) { | 30 | 6.75M | T res {}; | 31 | 6.75M | memcpy(&res, address, sizeof(res)); | 32 | 6.75M | return res; | 33 | 6.75M | } |
Unexecuted instantiation: _Z14unaligned_loadIN5doris10vectorized7DecimalInEEET_PKv Unexecuted instantiation: _Z14unaligned_loadIN5doris10vectorized12Decimal128V3EET_PKv Unexecuted instantiation: _Z14unaligned_loadIN5doris10vectorized7DecimalIN4wide7integerILm256EiEEEEET_PKv Unexecuted instantiation: _Z14unaligned_loadIN4wide7integerILm128EjEEET_PKv |
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 | 23 | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { |
41 | 23 | static_assert(std::is_trivially_copyable_v<T>); |
42 | 23 | memcpy(address, &src, sizeof(src)); |
43 | 23 | } _Z15unaligned_storeIhEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 2 | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 2 | static_assert(std::is_trivially_copyable_v<T>); | 42 | 2 | memcpy(address, &src, sizeof(src)); | 43 | 2 | } |
Unexecuted instantiation: _Z15unaligned_storeItEvPvRKNSt9enable_ifILb1ET_E4typeE Unexecuted instantiation: _Z15unaligned_storeIjEvPvRKNSt9enable_ifILb1ET_E4typeE _Z15unaligned_storeImEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 12 | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 12 | static_assert(std::is_trivially_copyable_v<T>); | 42 | 12 | memcpy(address, &src, sizeof(src)); | 43 | 12 | } |
Unexecuted instantiation: _Z15unaligned_storeIN4wide7integerILm128EjEEEvPvRKNSt9enable_ifILb1ET_E4typeE Unexecuted instantiation: _Z15unaligned_storeIaEvPvRKNSt9enable_ifILb1ET_E4typeE Unexecuted instantiation: _Z15unaligned_storeIsEvPvRKNSt9enable_ifILb1ET_E4typeE _Z15unaligned_storeIiEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 6 | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 6 | static_assert(std::is_trivially_copyable_v<T>); | 42 | 6 | memcpy(address, &src, sizeof(src)); | 43 | 6 | } |
Unexecuted instantiation: _Z15unaligned_storeIlEvPvRKNSt9enable_ifILb1ET_E4typeE _Z15unaligned_storeInEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 2 | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 2 | static_assert(std::is_trivially_copyable_v<T>); | 42 | 2 | memcpy(address, &src, sizeof(src)); | 43 | 2 | } |
Unexecuted instantiation: _Z15unaligned_storeIfEvPvRKNSt9enable_ifILb1ET_E4typeE Unexecuted instantiation: _Z15unaligned_storeIdEvPvRKNSt9enable_ifILb1ET_E4typeE _Z15unaligned_storeIoEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 1 | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 1 | static_assert(std::is_trivially_copyable_v<T>); | 42 | 1 | memcpy(address, &src, sizeof(src)); | 43 | 1 | } |
|
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 |