/root/doris/be/src/util/unaligned.h
Line | Count | Source |
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 <cstring> |
24 | | #include <type_traits> |
25 | | |
26 | | namespace doris { |
27 | | |
28 | | template <typename T> |
29 | 1.77G | T unaligned_load(const void* address) { |
30 | 1.77G | T res {}; |
31 | 1.77G | memcpy(&res, address, sizeof(res)); |
32 | 1.77G | return res; |
33 | 1.77G | } _ZN5doris14unaligned_loadItEET_PKv Line | Count | Source | 29 | 946 | T unaligned_load(const void* address) { | 30 | 946 | T res {}; | 31 | 946 | memcpy(&res, address, sizeof(res)); | 32 | 946 | return res; | 33 | 946 | } |
_ZN5doris14unaligned_loadIjEET_PKv Line | Count | Source | 29 | 115M | T unaligned_load(const void* address) { | 30 | 115M | T res {}; | 31 | 115M | memcpy(&res, address, sizeof(res)); | 32 | 115M | return res; | 33 | 115M | } |
_ZN5doris14unaligned_loadImEET_PKv Line | Count | Source | 29 | 1.59G | T unaligned_load(const void* address) { | 30 | 1.59G | T res {}; | 31 | 1.59G | memcpy(&res, address, sizeof(res)); | 32 | 1.59G | return res; | 33 | 1.59G | } |
_ZN5doris14unaligned_loadIhEET_PKv Line | Count | Source | 29 | 7.71M | T unaligned_load(const void* address) { | 30 | 7.71M | T res {}; | 31 | 7.71M | memcpy(&res, address, sizeof(res)); | 32 | 7.71M | return res; | 33 | 7.71M | } |
_ZN5doris14unaligned_loadINS_16TimestampTzValueEEET_PKv Line | Count | Source | 29 | 2 | T unaligned_load(const void* address) { | 30 | 2 | T res {}; | 31 | 2 | memcpy(&res, address, sizeof(res)); | 32 | 2 | return res; | 33 | 2 | } |
_ZN5doris14unaligned_loadIfEET_PKv Line | Count | Source | 29 | 210k | T unaligned_load(const void* address) { | 30 | 210k | T res {}; | 31 | 210k | memcpy(&res, address, sizeof(res)); | 32 | 210k | return res; | 33 | 210k | } |
_ZN5doris14unaligned_loadIlEET_PKv Line | Count | Source | 29 | 12.2M | T unaligned_load(const void* address) { | 30 | 12.2M | T res {}; | 31 | 12.2M | memcpy(&res, address, sizeof(res)); | 32 | 12.2M | return res; | 33 | 12.2M | } |
_ZN5doris14unaligned_loadIaEET_PKv Line | Count | Source | 29 | 2.38M | T unaligned_load(const void* address) { | 30 | 2.38M | T res {}; | 31 | 2.38M | memcpy(&res, address, sizeof(res)); | 32 | 2.38M | return res; | 33 | 2.38M | } |
_ZN5doris14unaligned_loadIiEET_PKv Line | Count | Source | 29 | 24.9M | T unaligned_load(const void* address) { | 30 | 24.9M | T res {}; | 31 | 24.9M | memcpy(&res, address, sizeof(res)); | 32 | 24.9M | return res; | 33 | 24.9M | } |
_ZN5doris14unaligned_loadIdEET_PKv Line | Count | Source | 29 | 2.86M | T unaligned_load(const void* address) { | 30 | 2.86M | T res {}; | 31 | 2.86M | memcpy(&res, address, sizeof(res)); | 32 | 2.86M | return res; | 33 | 2.86M | } |
_ZN5doris14unaligned_loadINS_11DateV2ValueINS_15DateV2ValueTypeEEEEET_PKv Line | Count | Source | 29 | 118k | T unaligned_load(const void* address) { | 30 | 118k | T res {}; | 31 | 118k | memcpy(&res, address, sizeof(res)); | 32 | 118k | return res; | 33 | 118k | } |
_ZN5doris14unaligned_loadINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEEET_PKv Line | Count | Source | 29 | 74.7k | T unaligned_load(const void* address) { | 30 | 74.7k | T res {}; | 31 | 74.7k | memcpy(&res, address, sizeof(res)); | 32 | 74.7k | return res; | 33 | 74.7k | } |
_ZN5doris14unaligned_loadIoEET_PKv Line | Count | Source | 29 | 17.3k | T unaligned_load(const void* address) { | 30 | 17.3k | T res {}; | 31 | 17.3k | memcpy(&res, address, sizeof(res)); | 32 | 17.3k | return res; | 33 | 17.3k | } |
_ZN5doris14unaligned_loadIsEET_PKv Line | Count | Source | 29 | 105k | T unaligned_load(const void* address) { | 30 | 105k | T res {}; | 31 | 105k | memcpy(&res, address, sizeof(res)); | 32 | 105k | return res; | 33 | 105k | } |
_ZN5doris14unaligned_loadInEET_PKv Line | Count | Source | 29 | 364k | T unaligned_load(const void* address) { | 30 | 364k | T res {}; | 31 | 364k | memcpy(&res, address, sizeof(res)); | 32 | 364k | return res; | 33 | 364k | } |
_ZN5doris14unaligned_loadINS_16VecDateTimeValueEEET_PKv Line | Count | Source | 29 | 3.19M | T unaligned_load(const void* address) { | 30 | 3.19M | T res {}; | 31 | 3.19M | memcpy(&res, address, sizeof(res)); | 32 | 3.19M | return res; | 33 | 3.19M | } |
_ZN5doris14unaligned_loadI10Elf64_NhdrEET_PKv Line | Count | Source | 29 | 516 | T unaligned_load(const void* address) { | 30 | 516 | T res {}; | 31 | 516 | memcpy(&res, address, sizeof(res)); | 32 | 516 | return res; | 33 | 516 | } |
_ZN5doris14unaligned_loadINS_8uint24_tEEET_PKv Line | Count | Source | 29 | 991k | T unaligned_load(const void* address) { | 30 | 991k | T res {}; | 31 | 991k | memcpy(&res, address, sizeof(res)); | 32 | 991k | return res; | 33 | 991k | } |
_ZN5doris14unaligned_loadIbEET_PKv Line | Count | Source | 29 | 665k | T unaligned_load(const void* address) { | 30 | 665k | T res {}; | 31 | 665k | memcpy(&res, address, sizeof(res)); | 32 | 665k | return res; | 33 | 665k | } |
_ZN5doris14unaligned_loadIN4wide7integerILm256EiEEEET_PKv Line | Count | Source | 29 | 625 | T unaligned_load(const void* address) { | 30 | 625 | T res {}; | 31 | 625 | memcpy(&res, address, sizeof(res)); | 32 | 625 | return res; | 33 | 625 | } |
_ZN5doris14unaligned_loadINS_7DecimalIiEEEET_PKv Line | Count | Source | 29 | 4.20k | T unaligned_load(const void* address) { | 30 | 4.20k | T res {}; | 31 | 4.20k | memcpy(&res, address, sizeof(res)); | 32 | 4.20k | return res; | 33 | 4.20k | } |
_ZN5doris14unaligned_loadINS_7DecimalIlEEEET_PKv Line | Count | Source | 29 | 7.23M | T unaligned_load(const void* address) { | 30 | 7.23M | T res {}; | 31 | 7.23M | memcpy(&res, address, sizeof(res)); | 32 | 7.23M | return res; | 33 | 7.23M | } |
_ZN5doris14unaligned_loadINS_14DecimalV2ValueEEET_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 | } |
_ZN5doris14unaligned_loadINS_12Decimal128V3EEET_PKv Line | Count | Source | 29 | 5.68k | T unaligned_load(const void* address) { | 30 | 5.68k | T res {}; | 31 | 5.68k | memcpy(&res, address, sizeof(res)); | 32 | 5.68k | return res; | 33 | 5.68k | } |
_ZN5doris14unaligned_loadINS_7DecimalIN4wide7integerILm256EiEEEEEET_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 | } |
_ZN5doris14unaligned_loadINS_9StringRefEEET_PKv Line | Count | Source | 29 | 4.64M | T unaligned_load(const void* address) { | 30 | 4.64M | T res {}; | 31 | 4.64M | memcpy(&res, address, sizeof(res)); | 32 | 4.64M | return res; | 33 | 4.64M | } |
_ZN5doris14unaligned_loadINS_11decimal12_tEEET_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 | } |
|
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 | 2.71M | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { |
41 | 2.71M | static_assert(std::is_trivially_copyable_v<T>); |
42 | 2.71M | memcpy(address, &src, sizeof(src)); |
43 | 2.71M | } _ZN5doris15unaligned_storeItEEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 25.5k | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 25.5k | static_assert(std::is_trivially_copyable_v<T>); | 42 | 25.5k | memcpy(address, &src, sizeof(src)); | 43 | 25.5k | } |
_ZN5doris15unaligned_storeIjEEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 29.4k | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 29.4k | static_assert(std::is_trivially_copyable_v<T>); | 42 | 29.4k | memcpy(address, &src, sizeof(src)); | 43 | 29.4k | } |
_ZN5doris15unaligned_storeImEEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 1.86M | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 1.86M | static_assert(std::is_trivially_copyable_v<T>); | 42 | 1.86M | memcpy(address, &src, sizeof(src)); | 43 | 1.86M | } |
_ZN5doris15unaligned_storeIbEEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 661k | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 661k | static_assert(std::is_trivially_copyable_v<T>); | 42 | 661k | memcpy(address, &src, sizeof(src)); | 43 | 661k | } |
_ZN5doris15unaligned_storeIiEEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 11.2k | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 11.2k | static_assert(std::is_trivially_copyable_v<T>); | 42 | 11.2k | memcpy(address, &src, sizeof(src)); | 43 | 11.2k | } |
_ZN5doris15unaligned_storeIfEEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 91.1k | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 91.1k | static_assert(std::is_trivially_copyable_v<T>); | 42 | 91.1k | memcpy(address, &src, sizeof(src)); | 43 | 91.1k | } |
_ZN5doris15unaligned_storeIdEEvPvRKNSt9enable_ifILb1ET_E4typeE Line | Count | Source | 40 | 25.5k | void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) { | 41 | 25.5k | static_assert(std::is_trivially_copyable_v<T>); | 42 | 25.5k | memcpy(address, &src, sizeof(src)); | 43 | 25.5k | } |
|
44 | | } // namespace doris |