/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 | | template <> |
44 | | struct TypeId<UInt128> { |
45 | | static constexpr const TypeIndex value = TypeIndex::UInt128; |
46 | | }; |
47 | | |
48 | | #if defined(__SSE4_2__) || defined(__aarch64__) |
49 | | |
50 | | struct UInt128HashCRC32 { |
51 | 0 | size_t operator()(const UInt128& x) const { |
52 | 0 | UInt64 crc = -1ULL; |
53 | 0 | crc = _mm_crc32_u64(crc, x.low()); |
54 | 0 | crc = _mm_crc32_u64(crc, x.high()); |
55 | 0 | return crc; |
56 | 0 | } |
57 | | }; |
58 | | |
59 | | #else |
60 | | |
61 | | /// On other platforms we do not use CRC32. NOTE This can be confusing. |
62 | | struct UInt128HashCRC32 : public UInt128Hash {}; |
63 | | |
64 | | #endif |
65 | | |
66 | | struct UInt128TrivialHash { |
67 | 0 | size_t operator()(UInt128 x) const { return x.low(); } |
68 | | }; |
69 | | |
70 | | using UInt256 = wide::UInt256; |
71 | | |
72 | | #pragma pack(1) |
73 | | struct UInt136 { |
74 | | UInt8 a; |
75 | | UInt64 b; |
76 | | UInt64 c; |
77 | | |
78 | 0 | bool operator==(const UInt136& rhs) const { return a == rhs.a && b == rhs.b && c == rhs.c; } |
79 | | }; |
80 | | #pragma pack() |
81 | | |
82 | | } // namespace doris::vectorized |
83 | | |
84 | | /// Overload hash for type casting |
85 | | template <> |
86 | | struct std::hash<doris::vectorized::UInt128> { |
87 | 0 | size_t operator()(const doris::vectorized::UInt128& u) const { |
88 | 0 | return util_hash::HashLen16(u.low(), u.high()); |
89 | 0 | } |
90 | | }; |
91 | | |
92 | | template <> |
93 | | struct std::is_signed<doris::vectorized::UInt128> { |
94 | | static constexpr bool value = false; |
95 | | }; |
96 | | |
97 | | template <> |
98 | | struct std::is_unsigned<doris::vectorized::UInt128> { |
99 | | static constexpr bool value = true; |
100 | | }; |
101 | | |
102 | | template <> |
103 | | struct std::is_integral<doris::vectorized::UInt128> { |
104 | | static constexpr bool value = true; |
105 | | }; |
106 | | |
107 | | // Operator +, -, /, *, % aren't implemented, so it's not an arithmetic type |
108 | | template <> |
109 | | struct std::is_arithmetic<doris::vectorized::UInt128> { |
110 | | static constexpr bool value = false; |
111 | | }; |