1
/**********************************************************************
2
Utilities for byte operations
4
(c) 1994, 1995 Innobase Oy
6
Created 1/20/1994 Heikki Tuuri
7
***********************************************************************/
15
/* Type definition for a 64-bit unsigned integer, which works also
16
in 32-bit machines. NOTE! Access the fields only with the accessor
17
functions. This definition appears here only for the compiler to
18
know the size of a dulint. */
20
typedef struct dulint_struct dulint;
22
ulint high; /* most significant 32 bits */
23
ulint low; /* least significant 32 bits */
26
/* Zero value for a dulint */
27
extern const dulint ut_dulint_zero;
29
/* Maximum value for a dulint */
30
extern const dulint ut_dulint_max;
32
/***********************************************************
33
Creates a 64-bit dulint out of two ulints. */
38
/* out: created dulint */
39
ulint high, /* in: high-order 32 bits */
40
ulint low); /* in: low-order 32 bits */
41
/***********************************************************
42
Gets the high-order 32 bits of a dulint. */
47
/* out: 32 bits in ulint */
48
dulint d); /* in: dulint */
49
/***********************************************************
50
Gets the low-order 32 bits of a dulint. */
55
/* out: 32 bits in ulint */
56
dulint d); /* in: dulint */
57
/***********************************************************
58
Converts a dulint (a struct of 2 ulints) to ib_int64_t, which is a 64-bit
62
ut_conv_dulint_to_longlong(
63
/*=======================*/
64
/* out: value in ib_int64_t type */
65
dulint d); /* in: dulint */
66
/***********************************************************
67
Tests if a dulint is zero. */
72
/* out: TRUE if zero */
73
dulint a); /* in: dulint */
74
/***********************************************************
75
Compares two dulints. */
80
/* out: -1 if a < b, 0 if a == b,
82
dulint a, /* in: dulint */
83
dulint b); /* in: dulint */
84
/***********************************************************
85
Calculates the max of two dulints. */
91
dulint a, /* in: dulint */
92
dulint b); /* in: dulint */
93
/***********************************************************
94
Calculates the min of two dulints. */
100
dulint a, /* in: dulint */
101
dulint b); /* in: dulint */
102
/***********************************************************
103
Adds a ulint to a dulint. */
109
dulint a, /* in: dulint */
110
ulint b); /* in: ulint */
111
/***********************************************************
112
Subtracts a ulint from a dulint. */
118
dulint a, /* in: dulint */
119
ulint b); /* in: ulint, b <= a */
120
/***********************************************************
121
Subtracts a dulint from another. NOTE that the difference must be positive
122
and smaller that 4G. */
128
dulint a, /* in: dulint; NOTE a must be >= b and at most
129
2 to power 32 - 1 greater */
130
dulint b); /* in: dulint */
131
/************************************************************
132
Rounds a dulint downward to a multiple of a power of 2. */
135
ut_dulint_align_down(
136
/*=================*/
137
/* out: rounded value */
138
dulint n, /* in: number to be rounded */
139
ulint align_no); /* in: align by this number which must be a
141
/************************************************************
142
Rounds a dulint upward to a multiple of a power of 2. */
147
/* out: rounded value */
148
dulint n, /* in: number to be rounded */
149
ulint align_no); /* in: align by this number which must be a
151
/************************************************************
152
Rounds a dulint downward to a multiple of a power of 2. */
155
ut_uint64_align_down(
156
/*=================*/
157
/* out: rounded value */
158
ib_uint64_t n, /* in: number to be rounded */
159
ulint align_no); /* in: align by this number
160
which must be a power of 2 */
161
/************************************************************
162
Rounds ib_uint64_t upward to a multiple of a power of 2. */
167
/* out: rounded value */
168
ib_uint64_t n, /* in: number to be rounded */
169
ulint align_no); /* in: align by this number
170
which must be a power of 2 */
171
/***********************************************************
172
Increments a dulint variable by 1. */
173
#define UT_DULINT_INC(D)\
175
if ((D).low == 0xFFFFFFFFUL) {\
176
(D).high = (D).high + 1;\
179
(D).low = (D).low + 1;\
182
/***********************************************************
183
Tests if two dulints are equal. */
184
#define UT_DULINT_EQ(D1, D2) (((D1).low == (D2).low)\
185
&& ((D1).high == (D2).high))
187
/****************************************************************
188
Sort function for dulint arrays. */
191
ut_dulint_sort(dulint* arr, dulint* aux_arr, ulint low, ulint high);
192
/*===============================================================*/
193
#endif /* notdefined */
195
/*************************************************************
196
The following function rounds up a pointer to the nearest aligned address. */
201
/* out: aligned pointer */
202
void* ptr, /* in: pointer */
203
ulint align_no); /* in: align by this number */
204
/*************************************************************
205
The following function rounds down a pointer to the nearest
211
/* out: aligned pointer */
212
const void* ptr, /* in: pointer */
213
ulint align_no) /* in: align by this number */
214
__attribute__((__const__));
215
/*************************************************************
216
The following function computes the offset of a pointer from the nearest
222
/* out: distance from aligned
224
const void* ptr, /* in: pointer */
225
ulint align_no) /* in: align by this number */
226
__attribute__((__const__));
227
/*********************************************************************
228
Gets the nth bit of a ulint. */
233
/* out: TRUE if nth bit is 1; 0th bit is defined to
234
be the least significant */
235
ulint a, /* in: ulint */
236
ulint n); /* in: nth bit requested */
237
/*********************************************************************
238
Sets the nth bit of a ulint. */
243
/* out: the ulint with the bit set as requested */
244
ulint a, /* in: ulint */
245
ulint n, /* in: nth bit requested */
246
ibool val); /* in: value for the bit to set */
249
#include "ut0byte.ic"