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