~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
1
/*****************************************************************************
2
3
Copyright (c) 1994, 2009, Innobase Oy. 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 as published by the Free Software
7
Foundation; version 2 of the License.
8
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.
12
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., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
16
17
*****************************************************************************/
18
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
19
/******************************************************************//**
20
@file include/ut0byte.h
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
21
Utilities for byte operations
22
23
Created 1/20/1994 Heikki Tuuri
24
***********************************************************************/
25
26
#ifndef ut0byte_h
27
#define ut0byte_h
28
29
30
#include "univ.i"
31
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
32
/** Pair of ulint integers. */
33
typedef	struct dulint_struct	dulint;
34
/** Type definition for a 64-bit unsigned integer, which works also
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
35
in 32-bit machines. NOTE! Access the fields only with the accessor
36
functions. This definition appears here only for the compiler to
37
know the size of a dulint. */
38
struct dulint_struct{
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
39
	ulint	high;	/*!< most significant 32 bits */
40
	ulint	low;	/*!< least significant 32 bits */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
41
};
42
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
43
/** Zero value for a dulint */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
44
extern const dulint	ut_dulint_zero;
45
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
46
/** Maximum value for a dulint */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
47
extern const dulint	ut_dulint_max;
48
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
49
/*******************************************************//**
50
Creates a 64-bit dulint out of two ulints.
51
@return	created dulint */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
52
UNIV_INLINE
53
dulint
54
ut_dulint_create(
55
/*=============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
56
	ulint	high,	/*!< in: high-order 32 bits */
57
	ulint	low);	/*!< in: low-order 32 bits */
58
/*******************************************************//**
59
Gets the high-order 32 bits of a dulint.
60
@return	32 bits in ulint */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
61
UNIV_INLINE
62
ulint
63
ut_dulint_get_high(
64
/*===============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
65
	dulint	d);	/*!< in: dulint */
66
/*******************************************************//**
67
Gets the low-order 32 bits of a dulint.
68
@return	32 bits in ulint */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
69
UNIV_INLINE
70
ulint
71
ut_dulint_get_low(
72
/*==============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
73
	dulint	d);	/*!< in: dulint */
74
/*******************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
75
Converts a dulint (a struct of 2 ulints) to ib_int64_t, which is a 64-bit
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
76
integer type.
77
@return	value in ib_int64_t type */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
78
UNIV_INLINE
79
ib_int64_t
80
ut_conv_dulint_to_longlong(
81
/*=======================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
82
	dulint	d);	/*!< in: dulint */
83
/*******************************************************//**
84
Tests if a dulint is zero.
85
@return	TRUE if zero */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
86
UNIV_INLINE
87
ibool
88
ut_dulint_is_zero(
89
/*==============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
90
	dulint	a);	/*!< in: dulint */
91
/*******************************************************//**
92
Compares two dulints.
93
@return	-1 if a < b, 0 if a == b, 1 if a > b */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
94
UNIV_INLINE
95
int
96
ut_dulint_cmp(
97
/*==========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
98
	dulint	a,	/*!< in: dulint */
99
	dulint	b);	/*!< in: dulint */
100
/*******************************************************//**
101
Calculates the max of two dulints.
102
@return	max(a, b) */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
103
UNIV_INLINE
104
dulint
105
ut_dulint_get_max(
106
/*==============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
107
	dulint	a,	/*!< in: dulint */
108
	dulint	b);	/*!< in: dulint */
109
/*******************************************************//**
110
Calculates the min of two dulints.
111
@return	min(a, b) */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
112
UNIV_INLINE
113
dulint
114
ut_dulint_get_min(
115
/*==============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
116
	dulint	a,	/*!< in: dulint */
117
	dulint	b);	/*!< in: dulint */
118
/*******************************************************//**
119
Adds a ulint to a dulint.
120
@return	sum a + b */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
121
UNIV_INLINE
122
dulint
123
ut_dulint_add(
124
/*==========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
125
	dulint	a,	/*!< in: dulint */
126
	ulint	b);	/*!< in: ulint */
127
/*******************************************************//**
128
Subtracts a ulint from a dulint.
129
@return	a - b */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
130
UNIV_INLINE
131
dulint
132
ut_dulint_subtract(
133
/*===============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
134
	dulint	a,	/*!< in: dulint */
135
	ulint	b);	/*!< in: ulint, b <= a */
136
/*******************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
137
Subtracts a dulint from another. NOTE that the difference must be positive
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
138
and smaller that 4G.
139
@return	a - b */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
140
UNIV_INLINE
141
ulint
142
ut_dulint_minus(
143
/*============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
144
	dulint	a,	/*!< in: dulint; NOTE a must be >= b and at most
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
145
			2 to power 32 - 1 greater */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
146
	dulint	b);	/*!< in: dulint */
147
/********************************************************//**
148
Rounds a dulint downward to a multiple of a power of 2.
149
@return	rounded value */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
150
UNIV_INLINE
151
dulint
152
ut_dulint_align_down(
153
/*=================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
154
	dulint	 n,		/*!< in: number to be rounded */
155
	ulint	 align_no);	/*!< in: align by this number which must be a
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
156
				power of 2 */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
157
/********************************************************//**
158
Rounds a dulint upward to a multiple of a power of 2.
159
@return	rounded value */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
160
UNIV_INLINE
161
dulint
162
ut_dulint_align_up(
163
/*===============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
164
	dulint	 n,		/*!< in: number to be rounded */
165
	ulint	 align_no);	/*!< in: align by this number which must be a
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
166
				power of 2 */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
167
/********************************************************//**
168
Rounds a dulint downward to a multiple of a power of 2.
169
@return	rounded value */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
170
UNIV_INLINE
171
ib_uint64_t
172
ut_uint64_align_down(
173
/*=================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
174
	ib_uint64_t	 n,		/*!< in: number to be rounded */
175
	ulint		 align_no);	/*!< in: align by this number
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
176
					which must be a power of 2 */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
177
/********************************************************//**
178
Rounds ib_uint64_t upward to a multiple of a power of 2.
179
@return	rounded value */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
180
UNIV_INLINE
181
ib_uint64_t
182
ut_uint64_align_up(
183
/*===============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
184
	ib_uint64_t	 n,		/*!< in: number to be rounded */
185
	ulint		 align_no);	/*!< in: align by this number
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
186
					which must be a power of 2 */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
187
/*******************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
188
Increments a dulint variable by 1. */
189
#define UT_DULINT_INC(D)\
190
{\
191
	if ((D).low == 0xFFFFFFFFUL) {\
192
		(D).high = (D).high + 1;\
193
		(D).low = 0;\
194
	} else {\
195
		(D).low = (D).low + 1;\
196
	}\
197
}
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
198
/*******************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
199
Tests if two dulints are equal. */
200
#define UT_DULINT_EQ(D1, D2)	(((D1).low == (D2).low)\
201
						&& ((D1).high == (D2).high))
202
#ifdef notdefined
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
203
/************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
204
Sort function for dulint arrays. */
205
UNIV_INTERN
206
void
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
207
ut_dulint_sort(
208
/*===========*/
209
	dulint*	arr,	/*!< in/out: array to be sorted */
210
	dulint*	aux_arr,/*!< in/out: auxiliary array (same size as arr) */
211
	ulint	low,	/*!< in: low bound of sort interval, inclusive */
212
	ulint	high);	/*!< in: high bound of sort interval, noninclusive */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
213
#endif /* notdefined */
214
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
215
/*********************************************************//**
216
The following function rounds up a pointer to the nearest aligned address.
217
@return	aligned pointer */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
218
UNIV_INLINE
219
void*
220
ut_align(
221
/*=====*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
222
	void*	ptr,		/*!< in: pointer */
223
	ulint	align_no);	/*!< in: align by this number */
224
/*********************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
225
The following function rounds down a pointer to the nearest
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
226
aligned address.
227
@return	aligned pointer */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
228
UNIV_INLINE
229
void*
230
ut_align_down(
231
/*==========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
232
	const void*	ptr,		/*!< in: pointer */
233
	ulint		align_no)	/*!< in: align by this number */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
234
		__attribute__((const));
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
235
/*********************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
236
The following function computes the offset of a pointer from the nearest
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
237
aligned address.
238
@return	distance from aligned pointer */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
239
UNIV_INLINE
240
ulint
241
ut_align_offset(
242
/*============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
243
	const void*	ptr,		/*!< in: pointer */
244
	ulint		align_no)	/*!< in: align by this number */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
245
			__attribute__((const));
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
246
/*****************************************************************//**
247
Gets the nth bit of a ulint.
248
@return	TRUE if nth bit is 1; 0th bit is defined to be the least significant */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
249
UNIV_INLINE
250
ibool
251
ut_bit_get_nth(
252
/*===========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
253
	ulint	a,	/*!< in: ulint */
254
	ulint	n);	/*!< in: nth bit requested */
255
/*****************************************************************//**
256
Sets the nth bit of a ulint.
257
@return	the ulint with the bit set as requested */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
258
UNIV_INLINE
259
ulint
260
ut_bit_set_nth(
261
/*===========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
262
	ulint	a,	/*!< in: ulint */
263
	ulint	n,	/*!< in: nth bit requested */
264
	ibool	val);	/*!< in: value for the bit to set */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
265
266
#ifndef UNIV_NONINL
267
#include "ut0byte.ic"
268
#endif
269
270
#endif