Debian Codegraph @

storage/innobase/include/ut0byte.h

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.h
29 Utilities for byte operations
30
31 Created 1/20/1994 Heikki Tuuri
32 ***********************************************************************/
33
34 #ifndef ut0byte_h
35 #define ut0byte_h
36
37 #include "univ.i"
38 #include "ut0ut.h"
39
40 /** Creates a 64-bit integer out of two 32-bit integers.
41 @param[in] high high-order 32 bits
42 @param[in] low low-order 32 bits
43 @return created integer */
44 constexpr uint64_t ut_ull_create(uint32_t high, uint32_t low);
45
46 /** Rounds a 64-bit integer downward to a multiple of a power of 2.
47 @param[in] n number to be rounded
48 @param[in] align_no align by this number
49 @return rounded value */
50 static inline uint64_t ut_uint64_align_down(uint64_t n, ulint align_no);
51
52 /** Rounds uint64_t upward to a multiple of a power of 2.
53 @param[in] n number to be rounded
54 @param[in] align_no align by this number
55 @return rounded value */
56 static inline uint64_t ut_uint64_align_up(uint64_t n, ulint align_no);
57
58 /** The following function rounds up a pointer to the nearest aligned address.
59 @param[in] ptr pointer
60 @param[in] align_no align by this number
61 @return aligned pointer */
62 static inline void *ut_align(const void *ptr, ulint align_no);
63
64 /** The following function rounds down a pointer to the nearest aligned address.
65 @param[in] ptr pointer
66 @param[in] align_no align by this number
67 @return aligned pointer */
68 static inline void *ut_align_down(const void *ptr, ulint align_no);
69
70 /** The following function computes the offset of a pointer from the nearest
71 aligned address.
72 @param[in] ptr pointer
73 @param[in] align_no align by this number
74 @return distance from aligned pointer */
75 static inline ulint ut_align_offset(const void *ptr, ulint align_no);
76
77 /** Gets the nth bit of a ulint.
78 @param[in] a ulint
79 @param[in] n nth bit requested
80 @return true if nth bit is 1; 0th bit is defined to be the least significant */
81 static inline bool ut_bit_get_nth(ulint a, ulint n);
82
83 /** Sets the nth bit of a ulint.
84 @param[in] a ulint
85 @param[in] n nth bit requested
86 @param[in] val value for the bit to set
87 @return the ulint with the bit set as requested */
88 static inline ulint ut_bit_set_nth(ulint a, ulint n, bool val);
89
90 #include "ut0byte.ic"
91
92 #endif