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