/root/doris/be/src/vec/common/uint128.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/src/Common/Uint128.h |
19 | | // and modified by Doris |
20 | | |
21 | | #pragma once |
22 | | |
23 | | #include <cstdint> |
24 | | #include <iomanip> |
25 | | #include <sstream> |
26 | | #include <tuple> |
27 | | |
28 | | #include "gutil/hash/city.h" |
29 | | #include "util/sse_util.hpp" |
30 | | #include "vec/core/types.h" |
31 | | #include "vec/core/wide_integer.h" |
32 | | |
33 | | namespace doris::vectorized { |
34 | | |
35 | | using UInt128 = wide::UInt128; |
36 | | |
37 | | template <> |
38 | | inline constexpr bool IsNumber<UInt128> = true; |
39 | | template <> |
40 | | struct TypeName<UInt128> { |
41 | 0 | static const char* get() { return "UInt128"; } |
42 | | }; |
43 | | |
44 | | #if defined(__SSE4_2__) || defined(__aarch64__) |
45 | | |
46 | | struct UInt128HashCRC32 { |
47 | 45.5k | size_t operator()(const UInt128& x) const { |
48 | 45.5k | UInt64 crc = -1ULL; |
49 | 45.5k | crc = _mm_crc32_u64(crc, x.low()); |
50 | 45.5k | crc = _mm_crc32_u64(crc, x.high()); |
51 | 45.5k | return crc; |
52 | 45.5k | } |
53 | | }; |
54 | | |
55 | | #else |
56 | | |
57 | | /// On other platforms we do not use CRC32. NOTE This can be confusing. |
58 | | struct UInt128HashCRC32 : public UInt128Hash {}; |
59 | | |
60 | | #endif |
61 | | |
62 | | struct UInt128TrivialHash { |
63 | 0 | size_t operator()(UInt128 x) const { return x.low(); } |
64 | | }; |
65 | | |
66 | | using UInt256 = wide::UInt256; |
67 | | |
68 | | #pragma pack(1) |
69 | | struct UInt136 { |
70 | | UInt8 a; |
71 | | UInt64 b; |
72 | | UInt64 c; |
73 | | |
74 | 1 | bool operator==(const UInt136& rhs) const { return a == rhs.a && b == rhs.b && c == rhs.c; } |
75 | | }; |
76 | | #pragma pack() |
77 | | |
78 | | } // namespace doris::vectorized |
79 | | |
80 | | /// Overload hash for type casting |
81 | | template <> |
82 | | struct std::hash<doris::vectorized::UInt128> { |
83 | 12 | size_t operator()(const doris::vectorized::UInt128& u) const { |
84 | 12 | return util_hash::HashLen16(u.low(), u.high()); |
85 | 12 | } |
86 | | }; |
87 | | |
88 | | template <> |
89 | | struct std::is_signed<doris::vectorized::UInt128> { |
90 | | static constexpr bool value = false; |
91 | | }; |
92 | | |
93 | | template <> |
94 | | struct std::is_unsigned<doris::vectorized::UInt128> { |
95 | | static constexpr bool value = true; |
96 | | }; |
97 | | |
98 | | template <> |
99 | | struct std::is_integral<doris::vectorized::UInt128> { |
100 | | static constexpr bool value = true; |
101 | | }; |
102 | | |
103 | | // Operator +, -, /, *, % aren't implemented, so it's not an arithmetic type |
104 | | template <> |
105 | | struct std::is_arithmetic<doris::vectorized::UInt128> { |
106 | | static constexpr bool value = false; |
107 | | }; |