/root/doris/be/src/vec/common/endian.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 | | |
18 | | #pragma once |
19 | | |
20 | | #include "olap/uint24.h" |
21 | | #include "vec/common/unaligned.h" |
22 | | #include "vec/core/extended_types.h" |
23 | | |
24 | | namespace doris { |
25 | | #include "common/compile_check_begin.h" |
26 | 412 | inline uint64_t gbswap_64(uint64_t host_int) { |
27 | 412 | #if defined(__GNUC__) && defined(__x86_64__) && !defined(__APPLE__) |
28 | | // Adapted from /usr/include/byteswap.h. Not available on Mac. |
29 | 412 | if (__builtin_constant_p(host_int)) { |
30 | 0 | return __bswap_constant_64(host_int); |
31 | 412 | } else { |
32 | 412 | uint64_t result; |
33 | 412 | __asm__("bswap %0" : "=r"(result) : "0"(host_int)); |
34 | 412 | return result; |
35 | 412 | } |
36 | | #elif defined(bswap_64) |
37 | | return bswap_64(host_int); |
38 | | #else |
39 | | return static_cast<uint64_t>(bswap_32(static_cast<uint32_t>(host_int >> 32))) | |
40 | | (static_cast<uint64_t>(bswap_32(static_cast<uint32_t>(host_int))) << 32); |
41 | | #endif // bswap_64 |
42 | 412 | } |
43 | | |
44 | 3.87M | inline unsigned __int128 gbswap_128(unsigned __int128 host_int) { |
45 | 3.87M | return static_cast<unsigned __int128>(bswap_64(static_cast<uint64_t>(host_int >> 64))) | |
46 | 3.87M | (static_cast<unsigned __int128>(bswap_64(static_cast<uint64_t>(host_int))) << 64); |
47 | 3.87M | } |
48 | | |
49 | 103 | inline wide::UInt256 gbswap_256(wide::UInt256 host_int) { |
50 | 103 | wide::UInt256 result {gbswap_64(host_int.items[3]), gbswap_64(host_int.items[2]), |
51 | 103 | gbswap_64(host_int.items[1]), gbswap_64(host_int.items[0])}; |
52 | 103 | return result; |
53 | 103 | } |
54 | | |
55 | | // Swap bytes of a 24-bit value. |
56 | 319 | inline uint32_t bswap_24(uint32_t x) { |
57 | 319 | return uint32_t((x & 0x0000ffULL) << 16) | ((x & 0x00ff00ULL)) | ((x & 0xff0000ULL) >> 16); |
58 | 319 | } |
59 | | |
60 | | // use std::byteswap after doris enable cpp23 |
61 | | template <typename T> |
62 | 5.45M | T byte_swap(T x) { |
63 | 5.45M | if constexpr (sizeof(T) == sizeof(wide::Int256)) { |
64 | 103 | return gbswap_256(x); |
65 | 3.87M | } else if constexpr (sizeof(T) == sizeof(__int128)) { |
66 | 3.87M | return gbswap_128(x); |
67 | 3.87M | } else if constexpr (sizeof(T) == sizeof(int64_t)) { |
68 | 605k | return bswap_64(x); |
69 | 979k | } else if constexpr (sizeof(T) == sizeof(int32_t)) { |
70 | 979k | return bswap_32(x); |
71 | 979k | } else if constexpr (sizeof(T) == sizeof(doris::uint24_t)) { |
72 | 319 | return bswap_24(x); |
73 | 352 | } else if constexpr (sizeof(T) == sizeof(int16_t)) { |
74 | 352 | return bswap_16(x); |
75 | 451 | } else { |
76 | 451 | static_assert(sizeof(T) == 1, "Unsupported type size for byte_swap"); |
77 | 451 | return x; // No byte swap needed for unsupported types |
78 | 451 | } |
79 | 5.45M | } _ZN5doris9byte_swapItEET_S1_ Line | Count | Source | 62 | 352 | T byte_swap(T x) { | 63 | | if constexpr (sizeof(T) == sizeof(wide::Int256)) { | 64 | | return gbswap_256(x); | 65 | | } else if constexpr (sizeof(T) == sizeof(__int128)) { | 66 | | return gbswap_128(x); | 67 | | } else if constexpr (sizeof(T) == sizeof(int64_t)) { | 68 | | return bswap_64(x); | 69 | | } else if constexpr (sizeof(T) == sizeof(int32_t)) { | 70 | | return bswap_32(x); | 71 | | } else if constexpr (sizeof(T) == sizeof(doris::uint24_t)) { | 72 | | return bswap_24(x); | 73 | 352 | } else if constexpr (sizeof(T) == sizeof(int16_t)) { | 74 | 352 | return bswap_16(x); | 75 | | } else { | 76 | | static_assert(sizeof(T) == 1, "Unsupported type size for byte_swap"); | 77 | | return x; // No byte swap needed for unsupported types | 78 | | } | 79 | 352 | } |
_ZN5doris9byte_swapIjEET_S1_ Line | Count | Source | 62 | 979k | T byte_swap(T x) { | 63 | | if constexpr (sizeof(T) == sizeof(wide::Int256)) { | 64 | | return gbswap_256(x); | 65 | | } else if constexpr (sizeof(T) == sizeof(__int128)) { | 66 | | return gbswap_128(x); | 67 | | } else if constexpr (sizeof(T) == sizeof(int64_t)) { | 68 | | return bswap_64(x); | 69 | 979k | } else if constexpr (sizeof(T) == sizeof(int32_t)) { | 70 | 979k | return bswap_32(x); | 71 | | } else if constexpr (sizeof(T) == sizeof(doris::uint24_t)) { | 72 | | return bswap_24(x); | 73 | | } else if constexpr (sizeof(T) == sizeof(int16_t)) { | 74 | | return bswap_16(x); | 75 | | } else { | 76 | | static_assert(sizeof(T) == 1, "Unsupported type size for byte_swap"); | 77 | | return x; // No byte swap needed for unsupported types | 78 | | } | 79 | 979k | } |
_ZN5doris9byte_swapImEET_S1_ Line | Count | Source | 62 | 72.9k | T byte_swap(T x) { | 63 | | if constexpr (sizeof(T) == sizeof(wide::Int256)) { | 64 | | return gbswap_256(x); | 65 | | } else if constexpr (sizeof(T) == sizeof(__int128)) { | 66 | | return gbswap_128(x); | 67 | 72.9k | } else if constexpr (sizeof(T) == sizeof(int64_t)) { | 68 | 72.9k | return bswap_64(x); | 69 | | } else if constexpr (sizeof(T) == sizeof(int32_t)) { | 70 | | return bswap_32(x); | 71 | | } else if constexpr (sizeof(T) == sizeof(doris::uint24_t)) { | 72 | | return bswap_24(x); | 73 | | } else if constexpr (sizeof(T) == sizeof(int16_t)) { | 74 | | return bswap_16(x); | 75 | | } else { | 76 | | static_assert(sizeof(T) == 1, "Unsupported type size for byte_swap"); | 77 | | return x; // No byte swap needed for unsupported types | 78 | | } | 79 | 72.9k | } |
_ZN5doris9byte_swapINS_8uint24_tEEET_S2_ Line | Count | Source | 62 | 319 | T byte_swap(T x) { | 63 | | if constexpr (sizeof(T) == sizeof(wide::Int256)) { | 64 | | return gbswap_256(x); | 65 | | } else if constexpr (sizeof(T) == sizeof(__int128)) { | 66 | | return gbswap_128(x); | 67 | | } else if constexpr (sizeof(T) == sizeof(int64_t)) { | 68 | | return bswap_64(x); | 69 | | } else if constexpr (sizeof(T) == sizeof(int32_t)) { | 70 | | return bswap_32(x); | 71 | 319 | } else if constexpr (sizeof(T) == sizeof(doris::uint24_t)) { | 72 | 319 | return bswap_24(x); | 73 | | } else if constexpr (sizeof(T) == sizeof(int16_t)) { | 74 | | return bswap_16(x); | 75 | | } else { | 76 | | static_assert(sizeof(T) == 1, "Unsupported type size for byte_swap"); | 77 | | return x; // No byte swap needed for unsupported types | 78 | | } | 79 | 319 | } |
_ZN5doris9byte_swapIoEET_S1_ Line | Count | Source | 62 | 520 | T byte_swap(T x) { | 63 | | if constexpr (sizeof(T) == sizeof(wide::Int256)) { | 64 | | return gbswap_256(x); | 65 | 520 | } else if constexpr (sizeof(T) == sizeof(__int128)) { | 66 | 520 | return gbswap_128(x); | 67 | | } else if constexpr (sizeof(T) == sizeof(int64_t)) { | 68 | | return bswap_64(x); | 69 | | } else if constexpr (sizeof(T) == sizeof(int32_t)) { | 70 | | return bswap_32(x); | 71 | | } else if constexpr (sizeof(T) == sizeof(doris::uint24_t)) { | 72 | | return bswap_24(x); | 73 | | } else if constexpr (sizeof(T) == sizeof(int16_t)) { | 74 | | return bswap_16(x); | 75 | | } else { | 76 | | static_assert(sizeof(T) == 1, "Unsupported type size for byte_swap"); | 77 | | return x; // No byte swap needed for unsupported types | 78 | | } | 79 | 520 | } |
_ZN5doris9byte_swapIN4wide7integerILm256EjEEEET_S4_ Line | Count | Source | 62 | 103 | T byte_swap(T x) { | 63 | 103 | if constexpr (sizeof(T) == sizeof(wide::Int256)) { | 64 | 103 | return gbswap_256(x); | 65 | | } else if constexpr (sizeof(T) == sizeof(__int128)) { | 66 | | return gbswap_128(x); | 67 | | } else if constexpr (sizeof(T) == sizeof(int64_t)) { | 68 | | return bswap_64(x); | 69 | | } else if constexpr (sizeof(T) == sizeof(int32_t)) { | 70 | | return bswap_32(x); | 71 | | } else if constexpr (sizeof(T) == sizeof(doris::uint24_t)) { | 72 | | return bswap_24(x); | 73 | | } else if constexpr (sizeof(T) == sizeof(int16_t)) { | 74 | | return bswap_16(x); | 75 | | } else { | 76 | | static_assert(sizeof(T) == 1, "Unsupported type size for byte_swap"); | 77 | | return x; // No byte swap needed for unsupported types | 78 | | } | 79 | 103 | } |
_ZN5doris9byte_swapIhEET_S1_ Line | Count | Source | 62 | 342 | T byte_swap(T x) { | 63 | | if constexpr (sizeof(T) == sizeof(wide::Int256)) { | 64 | | return gbswap_256(x); | 65 | | } else if constexpr (sizeof(T) == sizeof(__int128)) { | 66 | | return gbswap_128(x); | 67 | | } else if constexpr (sizeof(T) == sizeof(int64_t)) { | 68 | | return bswap_64(x); | 69 | | } else if constexpr (sizeof(T) == sizeof(int32_t)) { | 70 | | return bswap_32(x); | 71 | | } else if constexpr (sizeof(T) == sizeof(doris::uint24_t)) { | 72 | | return bswap_24(x); | 73 | | } else if constexpr (sizeof(T) == sizeof(int16_t)) { | 74 | | return bswap_16(x); | 75 | 342 | } else { | 76 | 342 | static_assert(sizeof(T) == 1, "Unsupported type size for byte_swap"); | 77 | 342 | return x; // No byte swap needed for unsupported types | 78 | 342 | } | 79 | 342 | } |
_ZN5doris9byte_swapIbEET_S1_ Line | Count | Source | 62 | 109 | T byte_swap(T x) { | 63 | | if constexpr (sizeof(T) == sizeof(wide::Int256)) { | 64 | | return gbswap_256(x); | 65 | | } else if constexpr (sizeof(T) == sizeof(__int128)) { | 66 | | return gbswap_128(x); | 67 | | } else if constexpr (sizeof(T) == sizeof(int64_t)) { | 68 | | return bswap_64(x); | 69 | | } else if constexpr (sizeof(T) == sizeof(int32_t)) { | 70 | | return bswap_32(x); | 71 | | } else if constexpr (sizeof(T) == sizeof(doris::uint24_t)) { | 72 | | return bswap_24(x); | 73 | | } else if constexpr (sizeof(T) == sizeof(int16_t)) { | 74 | | return bswap_16(x); | 75 | 109 | } else { | 76 | 109 | static_assert(sizeof(T) == 1, "Unsupported type size for byte_swap"); | 77 | 109 | return x; // No byte swap needed for unsupported types | 78 | 109 | } | 79 | 109 | } |
_ZN5doris9byte_swapIlEET_S1_ Line | Count | Source | 62 | 532k | T byte_swap(T x) { | 63 | | if constexpr (sizeof(T) == sizeof(wide::Int256)) { | 64 | | return gbswap_256(x); | 65 | | } else if constexpr (sizeof(T) == sizeof(__int128)) { | 66 | | return gbswap_128(x); | 67 | 532k | } else if constexpr (sizeof(T) == sizeof(int64_t)) { | 68 | 532k | return bswap_64(x); | 69 | | } else if constexpr (sizeof(T) == sizeof(int32_t)) { | 70 | | return bswap_32(x); | 71 | | } else if constexpr (sizeof(T) == sizeof(doris::uint24_t)) { | 72 | | return bswap_24(x); | 73 | | } else if constexpr (sizeof(T) == sizeof(int16_t)) { | 74 | | return bswap_16(x); | 75 | | } else { | 76 | | static_assert(sizeof(T) == 1, "Unsupported type size for byte_swap"); | 77 | | return x; // No byte swap needed for unsupported types | 78 | | } | 79 | 532k | } |
_ZN5doris9byte_swapInEET_S1_ Line | Count | Source | 62 | 3.87M | T byte_swap(T x) { | 63 | | if constexpr (sizeof(T) == sizeof(wide::Int256)) { | 64 | | return gbswap_256(x); | 65 | 3.87M | } else if constexpr (sizeof(T) == sizeof(__int128)) { | 66 | 3.87M | return gbswap_128(x); | 67 | | } else if constexpr (sizeof(T) == sizeof(int64_t)) { | 68 | | return bswap_64(x); | 69 | | } else if constexpr (sizeof(T) == sizeof(int32_t)) { | 70 | | return bswap_32(x); | 71 | | } else if constexpr (sizeof(T) == sizeof(doris::uint24_t)) { | 72 | | return bswap_24(x); | 73 | | } else if constexpr (sizeof(T) == sizeof(int16_t)) { | 74 | | return bswap_16(x); | 75 | | } else { | 76 | | static_assert(sizeof(T) == 1, "Unsupported type size for byte_swap"); | 77 | | return x; // No byte swap needed for unsupported types | 78 | | } | 79 | 3.87M | } |
Unexecuted instantiation: _ZN5doris9byte_swapIN4wide7integerILm256EiEEEET_S4_ Unexecuted instantiation: _ZN5doris9byte_swapIiEET_S1_ |
80 | | |
81 | | template <std::endian target, typename T> |
82 | 359M | T to_endian(T value) { |
83 | 359M | if constexpr (std::endian::native == target) { |
84 | 353M | return value; // No swap needed |
85 | 353M | } else { |
86 | 5.45M | static_assert(std::endian::native == std::endian::big || |
87 | 5.45M | std::endian::native == std::endian::little, |
88 | 5.45M | "Unsupported endianness"); |
89 | 5.45M | return byte_swap(value); |
90 | 5.45M | } |
91 | 359M | } _ZN5doris9to_endianILSt6endian1234EtEET0_S2_ Line | Count | Source | 82 | 48.5k | T to_endian(T value) { | 83 | 48.5k | if constexpr (std::endian::native == target) { | 84 | 48.5k | return value; // No swap needed | 85 | | } else { | 86 | | static_assert(std::endian::native == std::endian::big || | 87 | | std::endian::native == std::endian::little, | 88 | | "Unsupported endianness"); | 89 | | return byte_swap(value); | 90 | | } | 91 | 48.5k | } |
_ZN5doris9to_endianILSt6endian1234EjEET0_S2_ Line | Count | Source | 82 | 1.02M | T to_endian(T value) { | 83 | 1.02M | if constexpr (std::endian::native == target) { | 84 | 1.02M | return value; // No swap needed | 85 | | } else { | 86 | | static_assert(std::endian::native == std::endian::big || | 87 | | std::endian::native == std::endian::little, | 88 | | "Unsupported endianness"); | 89 | | return byte_swap(value); | 90 | | } | 91 | 1.02M | } |
_ZN5doris9to_endianILSt6endian1234EmEET0_S2_ Line | Count | Source | 82 | 352M | T to_endian(T value) { | 83 | 352M | if constexpr (std::endian::native == target) { | 84 | 352M | return value; // No swap needed | 85 | | } else { | 86 | | static_assert(std::endian::native == std::endian::big || | 87 | | std::endian::native == std::endian::little, | 88 | | "Unsupported endianness"); | 89 | | return byte_swap(value); | 90 | | } | 91 | 352M | } |
_ZN5doris9to_endianILSt6endian4321EtEET0_S2_ Line | Count | Source | 82 | 352 | T to_endian(T value) { | 83 | | if constexpr (std::endian::native == target) { | 84 | | return value; // No swap needed | 85 | 352 | } else { | 86 | 352 | static_assert(std::endian::native == std::endian::big || | 87 | 352 | std::endian::native == std::endian::little, | 88 | 352 | "Unsupported endianness"); | 89 | 352 | return byte_swap(value); | 90 | 352 | } | 91 | 352 | } |
_ZN5doris9to_endianILSt6endian4321EjEET0_S2_ Line | Count | Source | 82 | 979k | T to_endian(T value) { | 83 | | if constexpr (std::endian::native == target) { | 84 | | return value; // No swap needed | 85 | 979k | } else { | 86 | 979k | static_assert(std::endian::native == std::endian::big || | 87 | 979k | std::endian::native == std::endian::little, | 88 | 979k | "Unsupported endianness"); | 89 | 979k | return byte_swap(value); | 90 | 979k | } | 91 | 979k | } |
_ZN5doris9to_endianILSt6endian4321EmEET0_S2_ Line | Count | Source | 82 | 72.9k | T to_endian(T value) { | 83 | | if constexpr (std::endian::native == target) { | 84 | | return value; // No swap needed | 85 | 72.9k | } else { | 86 | 72.9k | static_assert(std::endian::native == std::endian::big || | 87 | 72.9k | std::endian::native == std::endian::little, | 88 | 72.9k | "Unsupported endianness"); | 89 | 72.9k | return byte_swap(value); | 90 | 72.9k | } | 91 | 72.9k | } |
_ZN5doris9to_endianILSt6endian1234EoEET0_S2_ Line | Count | Source | 82 | 48.8k | T to_endian(T value) { | 83 | 48.8k | if constexpr (std::endian::native == target) { | 84 | 48.8k | return value; // No swap needed | 85 | | } else { | 86 | | static_assert(std::endian::native == std::endian::big || | 87 | | std::endian::native == std::endian::little, | 88 | | "Unsupported endianness"); | 89 | | return byte_swap(value); | 90 | | } | 91 | 48.8k | } |
_ZN5doris9to_endianILSt6endian4321ENS_8uint24_tEEET0_S3_ Line | Count | Source | 82 | 319 | T to_endian(T value) { | 83 | | if constexpr (std::endian::native == target) { | 84 | | return value; // No swap needed | 85 | 319 | } else { | 86 | 319 | static_assert(std::endian::native == std::endian::big || | 87 | 319 | std::endian::native == std::endian::little, | 88 | 319 | "Unsupported endianness"); | 89 | 319 | return byte_swap(value); | 90 | 319 | } | 91 | 319 | } |
_ZN5doris9to_endianILSt6endian4321EoEET0_S2_ Line | Count | Source | 82 | 520 | T to_endian(T value) { | 83 | | if constexpr (std::endian::native == target) { | 84 | | return value; // No swap needed | 85 | 520 | } else { | 86 | 520 | static_assert(std::endian::native == std::endian::big || | 87 | 520 | std::endian::native == std::endian::little, | 88 | 520 | "Unsupported endianness"); | 89 | 520 | return byte_swap(value); | 90 | 520 | } | 91 | 520 | } |
_ZN5doris9to_endianILSt6endian4321EN4wide7integerILm256EjEEEET0_S5_ Line | Count | Source | 82 | 103 | T to_endian(T value) { | 83 | | if constexpr (std::endian::native == target) { | 84 | | return value; // No swap needed | 85 | 103 | } else { | 86 | 103 | static_assert(std::endian::native == std::endian::big || | 87 | 103 | std::endian::native == std::endian::little, | 88 | 103 | "Unsupported endianness"); | 89 | 103 | return byte_swap(value); | 90 | 103 | } | 91 | 103 | } |
_ZN5doris9to_endianILSt6endian4321EhEET0_S2_ Line | Count | Source | 82 | 342 | T to_endian(T value) { | 83 | | if constexpr (std::endian::native == target) { | 84 | | return value; // No swap needed | 85 | 342 | } else { | 86 | 342 | static_assert(std::endian::native == std::endian::big || | 87 | 342 | std::endian::native == std::endian::little, | 88 | 342 | "Unsupported endianness"); | 89 | 342 | return byte_swap(value); | 90 | 342 | } | 91 | 342 | } |
_ZN5doris9to_endianILSt6endian4321EbEET0_S2_ Line | Count | Source | 82 | 109 | T to_endian(T value) { | 83 | | if constexpr (std::endian::native == target) { | 84 | | return value; // No swap needed | 85 | 109 | } else { | 86 | 109 | static_assert(std::endian::native == std::endian::big || | 87 | 109 | std::endian::native == std::endian::little, | 88 | 109 | "Unsupported endianness"); | 89 | 109 | return byte_swap(value); | 90 | 109 | } | 91 | 109 | } |
_ZN5doris9to_endianILSt6endian4321ElEET0_S2_ Line | Count | Source | 82 | 532k | T to_endian(T value) { | 83 | | if constexpr (std::endian::native == target) { | 84 | | return value; // No swap needed | 85 | 532k | } else { | 86 | 532k | static_assert(std::endian::native == std::endian::big || | 87 | 532k | std::endian::native == std::endian::little, | 88 | 532k | "Unsupported endianness"); | 89 | 532k | return byte_swap(value); | 90 | 532k | } | 91 | 532k | } |
_ZN5doris9to_endianILSt6endian4321EnEET0_S2_ Line | Count | Source | 82 | 3.87M | T to_endian(T value) { | 83 | | if constexpr (std::endian::native == target) { | 84 | | return value; // No swap needed | 85 | 3.87M | } else { | 86 | 3.87M | static_assert(std::endian::native == std::endian::big || | 87 | 3.87M | std::endian::native == std::endian::little, | 88 | 3.87M | "Unsupported endianness"); | 89 | 3.87M | return byte_swap(value); | 90 | 3.87M | } | 91 | 3.87M | } |
Unexecuted instantiation: _ZN5doris9to_endianILSt6endian4321EN4wide7integerILm256EiEEEET0_S5_ Unexecuted instantiation: _ZN5doris9to_endianILSt6endian4321EiEET0_S2_ |
92 | | |
93 | | // Utilities to convert numbers between the current hosts's native byte |
94 | | // order and little-endian byte order |
95 | | // |
96 | | // Load/Store methods are alignment safe |
97 | | class LittleEndian { |
98 | | public: |
99 | | // Functions to do unaligned loads and stores in little-endian order. |
100 | 0 | static uint16_t Load16(const void* p) { |
101 | 0 | return to_endian<std::endian::little>(unaligned_load<uint16_t>(p)); |
102 | 0 | } |
103 | | |
104 | 0 | static void Store16(void* p, uint16_t v) { |
105 | 0 | unaligned_store<uint16_t>(p, to_endian<std::endian::little>(v)); |
106 | 0 | } |
107 | | |
108 | 256k | static uint32_t Load32(const void* p) { |
109 | 256k | return to_endian<std::endian::little>(unaligned_load<uint32_t>(p)); |
110 | 256k | } |
111 | | |
112 | 0 | static void Store32(void* p, uint32_t v) { |
113 | 0 | unaligned_store<uint32_t>(p, to_endian<std::endian::little>(v)); |
114 | 0 | } |
115 | | |
116 | 4.20k | static uint64_t Load64(const void* p) { |
117 | 4.20k | return to_endian<std::endian::little>(unaligned_load<uint64_t>(p)); |
118 | 4.20k | } |
119 | | |
120 | 0 | static void Store64(void* p, uint64_t v) { |
121 | 0 | unaligned_store<uint64_t>(p, to_endian<std::endian::little>(v)); |
122 | 0 | } |
123 | | }; |
124 | | |
125 | | // Utilities to convert numbers between the current hosts's native byte |
126 | | // order and big-endian byte order (same as network byte order) |
127 | | // |
128 | | // Load/Store methods are alignment safe |
129 | | class BigEndian { |
130 | | public: |
131 | | // Functions to do unaligned loads and stores in little-endian order. |
132 | 0 | static uint16_t Load16(const void* p) { |
133 | 0 | return to_endian<std::endian::big>(unaligned_load<uint16_t>(p)); |
134 | 0 | } |
135 | | |
136 | 0 | static void Store16(void* p, uint16_t v) { |
137 | 0 | unaligned_store<uint16_t>(p, to_endian<std::endian::big>(v)); |
138 | 0 | } |
139 | | |
140 | 0 | static uint32_t Load32(const void* p) { |
141 | 0 | return to_endian<std::endian::big>(unaligned_load<uint32_t>(p)); |
142 | 0 | } |
143 | | |
144 | 0 | static void Store32(void* p, uint32_t v) { |
145 | 0 | unaligned_store<uint32_t>(p, to_endian<std::endian::big>(v)); |
146 | 0 | } |
147 | | |
148 | 0 | static uint64_t Load64(const void* p) { |
149 | 0 | return to_endian<std::endian::big>(unaligned_load<uint64_t>(p)); |
150 | 0 | } |
151 | | |
152 | 0 | static void Store64(void* p, uint64_t v) { |
153 | 0 | unaligned_store<uint64_t>(p, to_endian<std::endian::big>(v)); |
154 | 0 | } |
155 | | }; // BigEndian |
156 | | #include "common/compile_check_end.h" |
157 | | } // namespace doris |