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 | | |
30 | 0 | PackedInt128(const __int128& value_) { value = value_; } |
31 | 2 | PackedInt128& operator=(const __int128& value_) { |
32 | 2 | value = value_; |
33 | 2 | return *this; |
34 | 2 | } |
35 | | PackedInt128& operator=(const PackedInt128& rhs) = default; |
36 | | |
37 | | __int128 value; |
38 | | } __attribute__((packed)); |
39 | | |
40 | | struct PackedUInt128 { |
41 | | PackedUInt128() = default; |
42 | | |
43 | 0 | PackedUInt128(const unsigned __int128& value_) { value = value_; } |
44 | 0 | PackedUInt128& operator=(const unsigned __int128& value_) { |
45 | 0 | value = value_; |
46 | 0 | return *this; |
47 | 0 | } |
48 | | PackedUInt128& operator=(const PackedUInt128& rhs) = default; |
49 | | |
50 | | uint128_t value; |
51 | | } __attribute__((packed)); |
52 | | |
53 | | // unalign address directly casted to int128 will core dump |
54 | 8 | inline int128_t get_int128_from_unalign(const void* address) { |
55 | 8 | int128_t value = 0; |
56 | 8 | memcpy(&value, address, sizeof(int128_t)); |
57 | 8 | return value; |
58 | 8 | } |
59 | | |
60 | | } // namespace doris |