Coverage Report

Created: 2025-03-12 00:38

/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
824k
T unaligned_load(const void* address) {
30
824k
    T res {};
31
824k
    memcpy(&res, address, sizeof(res));
32
824k
    return res;
33
824k
}
Unexecuted instantiation: _Z14unaligned_loadItET_PKv
_Z14unaligned_loadIhET_PKv
Line
Count
Source
29
168
T unaligned_load(const void* address) {
30
168
    T res {};
31
168
    memcpy(&res, address, sizeof(res));
32
168
    return res;
33
168
}
_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
3.90k
T unaligned_load(const void* address) {
30
3.90k
    T res {};
31
3.90k
    memcpy(&res, address, sizeof(res));
32
3.90k
    return res;
33
3.90k
}
_Z14unaligned_loadInET_PKv
Line
Count
Source
29
2.08k
T unaligned_load(const void* address) {
30
2.08k
    T res {};
31
2.08k
    memcpy(&res, address, sizeof(res));
32
2.08k
    return res;
33
2.08k
}
_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
580
T unaligned_load(const void* address) {
30
580
    T res {};
31
580
    memcpy(&res, address, sizeof(res));
32
580
    return res;
33
580
}
_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
_Z14unaligned_loadIN5doris10vectorized12Decimal128V3EET_PKv
Line
Count
Source
29
1.06k
T unaligned_load(const void* address) {
30
1.06k
    T res {};
31
1.06k
    memcpy(&res, address, sizeof(res));
32
1.06k
    return res;
33
1.06k
}
_Z14unaligned_loadIN5doris10vectorized7DecimalIN4wide7integerILm256EiEEEEET_PKv
Line
Count
Source
29
2.24k
T unaligned_load(const void* address) {
30
2.24k
    T res {};
31
2.24k
    memcpy(&res, address, sizeof(res));
32
2.24k
    return res;
33
2.24k
}
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
17.9k
void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) {
41
17.9k
    static_assert(std::is_trivially_copyable_v<T>);
42
17.9k
    memcpy(address, &src, sizeof(src));
43
17.9k
}
_Z15unaligned_storeIhEvPvRKNSt9enable_ifILb1ET_E4typeE
Line
Count
Source
40
142
void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) {
41
142
    static_assert(std::is_trivially_copyable_v<T>);
42
142
    memcpy(address, &src, sizeof(src));
43
142
}
Unexecuted instantiation: _Z15unaligned_storeItEvPvRKNSt9enable_ifILb1ET_E4typeE
_Z15unaligned_storeIjEvPvRKNSt9enable_ifILb1ET_E4typeE
Line
Count
Source
40
2.60k
void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) {
41
2.60k
    static_assert(std::is_trivially_copyable_v<T>);
42
2.60k
    memcpy(address, &src, sizeof(src));
43
2.60k
}
_Z15unaligned_storeImEvPvRKNSt9enable_ifILb1ET_E4typeE
Line
Count
Source
40
2.20k
void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) {
41
2.20k
    static_assert(std::is_trivially_copyable_v<T>);
42
2.20k
    memcpy(address, &src, sizeof(src));
43
2.20k
}
Unexecuted instantiation: _Z15unaligned_storeIN4wide7integerILm128EjEEEvPvRKNSt9enable_ifILb1ET_E4typeE
_Z15unaligned_storeIaEvPvRKNSt9enable_ifILb1ET_E4typeE
Line
Count
Source
40
1.78k
void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) {
41
1.78k
    static_assert(std::is_trivially_copyable_v<T>);
42
1.78k
    memcpy(address, &src, sizeof(src));
43
1.78k
}
_Z15unaligned_storeIsEvPvRKNSt9enable_ifILb1ET_E4typeE
Line
Count
Source
40
1.33k
void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) {
41
1.33k
    static_assert(std::is_trivially_copyable_v<T>);
42
1.33k
    memcpy(address, &src, sizeof(src));
43
1.33k
}
_Z15unaligned_storeIiEvPvRKNSt9enable_ifILb1ET_E4typeE
Line
Count
Source
40
1.51k
void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) {
41
1.51k
    static_assert(std::is_trivially_copyable_v<T>);
42
1.51k
    memcpy(address, &src, sizeof(src));
43
1.51k
}
_Z15unaligned_storeIlEvPvRKNSt9enable_ifILb1ET_E4typeE
Line
Count
Source
40
2.55k
void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) {
41
2.55k
    static_assert(std::is_trivially_copyable_v<T>);
42
2.55k
    memcpy(address, &src, sizeof(src));
43
2.55k
}
_Z15unaligned_storeInEvPvRKNSt9enable_ifILb1ET_E4typeE
Line
Count
Source
40
1.18k
void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) {
41
1.18k
    static_assert(std::is_trivially_copyable_v<T>);
42
1.18k
    memcpy(address, &src, sizeof(src));
43
1.18k
}
_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