1
/*****************************************************************************
3
Copyright (C) 1994, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
19
/**************************************************************//**
20
@file include/ut0byte.ic
21
Utilities for byte operations
23
Created 5/30/1994 Heikki Tuuri
24
*******************************************************************/
26
/*******************************************************//**
27
Creates a 64-bit integer out of two 32-bit integers.
28
@return created dulint */
33
ulint high, /*!< in: high-order 32 bits */
34
ulint low) /*!< in: low-order 32 bits */
36
ut_ad(high <= ULINT32_MASK);
37
ut_ad(low <= ULINT32_MASK);
38
return(((ib_uint64_t) high) << 32 | low);
41
/********************************************************//**
42
Rounds a 64-bit integer downward to a multiple of a power of 2.
43
@return rounded value */
48
ib_uint64_t n, /*!< in: number to be rounded */
49
ulint align_no) /*!< in: align by this number
50
which must be a power of 2 */
53
ut_ad(ut_is_2pow(align_no));
55
return(n & ~((ib_uint64_t) align_no - 1));
58
/********************************************************//**
59
Rounds ib_uint64_t upward to a multiple of a power of 2.
60
@return rounded value */
65
ib_uint64_t n, /*!< in: number to be rounded */
66
ulint align_no) /*!< in: align by this number
67
which must be a power of 2 */
69
ib_uint64_t align_1 = (ib_uint64_t) align_no - 1;
72
ut_ad(ut_is_2pow(align_no));
74
return((n + align_1) & ~align_1);
77
/*********************************************************//**
78
The following function rounds up a pointer to the nearest aligned address.
79
@return aligned pointer */
84
const void* ptr, /*!< in: pointer */
85
ulint align_no) /*!< in: align by this number */
88
ut_ad(((align_no - 1) & align_no) == 0);
91
ut_ad(sizeof(void*) == sizeof(ulint));
93
return((void*)((((ulint)ptr) + align_no - 1) & ~(align_no - 1)));
96
/*********************************************************//**
97
The following function rounds down a pointer to the nearest
99
@return aligned pointer */
104
const void* ptr, /*!< in: pointer */
105
ulint align_no) /*!< in: align by this number */
108
ut_ad(((align_no - 1) & align_no) == 0);
111
ut_ad(sizeof(void*) == sizeof(ulint));
113
return((void*)((((ulint)ptr)) & ~(align_no - 1)));
116
/*********************************************************//**
117
The following function computes the offset of a pointer from the nearest
119
@return distance from aligned pointer */
124
const void* ptr, /*!< in: pointer */
125
ulint align_no) /*!< in: align by this number */
128
ut_ad(((align_no - 1) & align_no) == 0);
131
ut_ad(sizeof(void*) == sizeof(ulint));
133
return(((ulint)ptr) & (align_no - 1));
136
/*****************************************************************//**
137
Gets the nth bit of a ulint.
138
@return TRUE if nth bit is 1; 0th bit is defined to be the least significant */
143
ulint a, /*!< in: ulint */
144
ulint n) /*!< in: nth bit requested */
146
ut_ad(n < 8 * sizeof(ulint));
150
return(1 & (a >> n));
153
/*****************************************************************//**
154
Sets the nth bit of a ulint.
155
@return the ulint with the bit set as requested */
160
ulint a, /*!< in: ulint */
161
ulint n, /*!< in: nth bit requested */
162
ibool val) /*!< in: value for the bit to set */
164
ut_ad(n < 8 * sizeof(ulint));
169
return(((ulint) 1 << n) | a);
171
return(~((ulint) 1 << n) & a);