MySQL  8.0.20
Source Code Documentation
ut0byte.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1994, 2018, Oracle and/or its affiliates. All Rights Reserved.
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 also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 
25 *****************************************************************************/
26 
27 /** @file include/ut0byte.h
28  Utilities for byte operations
29 
30  Created 1/20/1994 Heikki Tuuri
31  ***********************************************************************/
32 
33 #ifndef ut0byte_h
34 #define ut0byte_h
35 
36 #include "univ.i"
37 #include "ut0ut.h"
38 
39 /** Creates a 64-bit integer out of two 32-bit integers.
40  @return created integer */
41 UNIV_INLINE
42 ib_uint64_t ut_ull_create(ulint high, /*!< in: high-order 32 bits */
43  ulint low) /*!< in: low-order 32 bits */
44  MY_ATTRIBUTE((const));
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 UNIV_INLINE
51 ib_uint64_t ut_uint64_align_down(ib_uint64_t n, ulint align_no);
52 
53 /** Rounds ib_uint64_t upward to a multiple of a power of 2.
54 @param[in] n number to be rounded
55 @param[in] align_no align by this number
56 @return rounded value */
57 UNIV_INLINE
58 ib_uint64_t ut_uint64_align_up(ib_uint64_t n, ulint align_no);
59 
60 /** The following function rounds up a pointer to the nearest aligned address.
61 @param[in] ptr pointer
62 @param[in] align_no align by this number
63 @return aligned pointer */
64 UNIV_INLINE
65 void *ut_align(const void *ptr, ulint align_no);
66 
67 /** The following function rounds down a pointer to the nearest
68  aligned address.
69  @return aligned pointer */
70 UNIV_INLINE
71 void *ut_align_down(const void *ptr, /*!< in: pointer */
72  ulint align_no) /*!< in: align by this number */
73  MY_ATTRIBUTE((const));
74 /** The following function computes the offset of a pointer from the nearest
75  aligned address.
76  @return distance from aligned pointer */
77 UNIV_INLINE
78 ulint ut_align_offset(const void *ptr, /*!< in: pointer */
79  ulint align_no) /*!< in: align by this number */
80  MY_ATTRIBUTE((const));
81 
82 /** Gets the nth bit of a ulint.
83 @param[in] a ulint
84 @param[in] n nth bit requested
85 @return true if nth bit is 1; 0th bit is defined to be the least significant */
86 UNIV_INLINE
87 ibool ut_bit_get_nth(ulint a, ulint n);
88 
89 /** Sets the nth bit of a ulint.
90 @param[in] a ulint
91 @param[in] n nth bit requested
92 @param[in] val value for the bit to set
93 @return the ulint with the bit set as requested */
94 UNIV_INLINE
95 ulint ut_bit_set_nth(ulint a, ulint n, ibool val);
96 
97 #include "ut0byte.ic"
98 
99 #endif
UNIV_INLINE ibool ut_bit_get_nth(ulint a, ulint n)
Gets the nth bit of a ulint.
Various utilities.
UNIV_INLINE void * ut_align_down(const void *ptr, ulint align_no)
The following function rounds down a pointer to the nearest aligned address.
UNIV_INLINE ulint ut_align_offset(const void *ptr, ulint align_no)
The following function computes the offset of a pointer from the nearest aligned address.
UNIV_INLINE void * ut_align(const void *ptr, ulint align_no)
The following function rounds up a pointer to the nearest aligned address.
UNIV_INLINE ib_uint64_t ut_uint64_align_up(ib_uint64_t n, ulint align_no)
Rounds ib_uint64_t upward to a multiple of a power of 2.
UNIV_INLINE ib_uint64_t ut_uint64_align_down(ib_uint64_t n, ulint align_no)
Rounds a 64-bit integer downward to a multiple of a power of 2.
UNIV_INLINE ib_uint64_t ut_ull_create(ulint high, ulint low)
Creates a 64-bit integer out of two 32-bit integers.
int n
Definition: xcom_base.c:425
UNIV_INLINE ulint ut_bit_set_nth(ulint a, ulint n, ibool val)
Sets the nth bit of a ulint.