Debian Codegraph @

storage/innobase/include/ut0byte.ic

raw
1 /*****************************************************************************
2
3 Copyright (c) 1994, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27
28 /** @file include/ut0byte.ic
29 Utilities for byte operations
30
31 Created 5/30/1994 Heikki Tuuri
32 *******************************************************************/
33
34 constexpr uint64_t ut_ull_create(uint32_t high, uint32_t low) {
35 return (uint64_t{high} << 32) | low;
36 }
37
38 static inline uint64_t ut_uint64_align_down(uint64_t n, ulint align_no) {
39 ut_ad(align_no > 0);
40 ut_ad(ut_is_2pow(align_no));
41
42 return (n & ~((uint64_t)align_no - 1));
43 }
44
45 static inline uint64_t ut_uint64_align_up(uint64_t n, ulint align_no) {
46 const uint64_t align_1 = (uint64_t)align_no - 1;
47
48 ut_ad(align_no > 0);
49 ut_ad(ut_is_2pow(align_no));
50
51 return (n + align_1) & ~align_1;
52 }
53
54 static inline void *ut_align(const void *ptr, ulint align_no) {
55 ut_ad(align_no > 0);
56 ut_ad(((align_no - 1) & align_no) == 0);
57 ut_ad(ptr);
58
59 static_assert(sizeof(void *) == sizeof(ulint));
60
61 return ((void *)((((ulint)ptr) + align_no - 1) & ~(align_no - 1)));
62 }
63
64 static inline void *ut_align_down(const void *ptr, ulint align_no) {
65 ut_ad(align_no > 0);
66 ut_ad(((align_no - 1) & align_no) == 0);
67 ut_ad(ptr);
68
69 static_assert(sizeof(void *) == sizeof(ulint));
70
71 return ((void *)((((ulint)ptr)) & ~(align_no - 1)));
72 }
73
74 static inline ulint ut_align_offset(const void *ptr, ulint align_no) {
75 ut_ad(align_no > 0);
76 ut_ad(((align_no - 1) & align_no) == 0);
77 ut_ad(ptr);
78
79 static_assert(sizeof(void *) == sizeof(ulint));
80
81 return (((ulint)ptr) & (align_no - 1));
82 }
83
84 static inline bool ut_bit_get_nth(ulint a, ulint n) {
85 ut_ad(n < 8 * sizeof(ulint));
86 return (1 & (a >> n));
87 }
88
89 static inline ulint ut_bit_set_nth(ulint a, ulint n, bool val) {
90 ut_ad(n < 8 * sizeof(ulint));
91 if (val) {
92 return (((ulint)1 << n) | a);
93 } else {
94 return (~((ulint)1 << n) & a);
95 }
96 }