be/src/core/packed_int128.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 "storage/olap_common.h" |
21 | | |
22 | | namespace doris { |
23 | | |
24 | | // Because __int128 in memory is not aligned, but GCC7 will generate SSE instruction |
25 | | // for __int128 load/store. This will cause segment fault. |
26 | | struct PackedInt128 { |
27 | | // PackedInt128() : value(0) {} |
28 | | PackedInt128() = default; |
29 | | PackedInt128(const PackedInt128&) = default; |
30 | | |
31 | 0 | PackedInt128(const __int128& value_) { value = value_; } |
32 | 0 | PackedInt128& operator=(const __int128& value_) { |
33 | 0 | value = value_; |
34 | 0 | return *this; |
35 | 0 | } |
36 | | PackedInt128& operator=(const PackedInt128& rhs) = default; |
37 | | |
38 | | __int128 value; |
39 | | } __attribute__((packed)); |
40 | | |
41 | | struct PackedUInt128 { |
42 | | PackedUInt128() = default; |
43 | | PackedUInt128(const PackedUInt128&) = default; |
44 | | |
45 | 0 | PackedUInt128(const unsigned __int128& value_) { value = value_; } |
46 | 0 | PackedUInt128& operator=(const unsigned __int128& value_) { |
47 | 0 | value = value_; |
48 | 0 | return *this; |
49 | 0 | } |
50 | | PackedUInt128& operator=(const PackedUInt128& rhs) = default; |
51 | | |
52 | | uint128_t value; |
53 | | } __attribute__((packed)); |
54 | | |
55 | | // unalign address directly casted to int128 will core dump |
56 | 0 | inline int128_t get_int128_from_unalign(const void* address) { |
57 | 0 | int128_t value = 0; |
58 | 0 | memcpy(&value, address, sizeof(int128_t)); |
59 | 0 | return value; |
60 | 0 | } |
61 | | |
62 | | } // namespace doris |