Coverage Report

Created: 2025-04-14 12:46

/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
366M
T unaligned_load(const void* address) {
30
366M
    T res {};
31
366M
    memcpy(&res, address, sizeof(res));
32
366M
    return res;
33
366M
}
_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
821k
T unaligned_load(const void* address) {
30
821k
    T res {};
31
821k
    memcpy(&res, address, sizeof(res));
32
821k
    return res;
33
821k
}
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
41
T unaligned_load(const void* address) {
30
41
    T res {};
31
41
    memcpy(&res, address, sizeof(res));
32
41
    return res;
33
41
}
_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.17k
T unaligned_load(const void* address) {
30
2.17k
    T res {};
31
2.17k
    memcpy(&res, address, sizeof(res));
32
2.17k
    return res;
33
2.17k
}
_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_loadInET_PKv
Line
Count
Source
29
502
T unaligned_load(const void* address) {
30
502
    T res {};
31
502
    memcpy(&res, address, sizeof(res));
32
502
    return res;
33
502
}
_Z14unaligned_loadIfET_PKv
Line
Count
Source
29
224
T unaligned_load(const void* address) {
30
224
    T res {};
31
224
    memcpy(&res, address, sizeof(res));
32
224
    return res;
33
224
}
_Z14unaligned_loadIdET_PKv
Line
Count
Source
29
465
T unaligned_load(const void* address) {
30
465
    T res {};
31
465
    memcpy(&res, address, sizeof(res));
32
465
    return res;
33
465
}
_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
}
_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
}
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
54
void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) {
41
54
    static_assert(std::is_trivially_copyable_v<T>);
42
54
    memcpy(address, &src, sizeof(src));
43
54
}
_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
32
void unaligned_store(void* address, const typename std::enable_if<true, T>::type& src) {
41
32
    static_assert(std::is_trivially_copyable_v<T>);
42
32
    memcpy(address, &src, sizeof(src));
43
32
}
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