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 dulint ut_dulint_zero;
29
/* Maximum value for a dulint */
30
extern 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_longlong, which is a 64-bit
62
ut_conv_dulint_to_longlong(
63
/*=======================*/
64
/* out: value in ib_longlong 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
Increments a dulint variable by 1. */
153
#define UT_DULINT_INC(D)\
155
if ((D).low == 0xFFFFFFFFUL) {\
156
(D).high = (D).high + 1;\
159
(D).low = (D).low + 1;\
162
/***********************************************************
163
Tests if two dulints are equal. */
164
#define UT_DULINT_EQ(D1, D2) (((D1).low == (D2).low)\
165
&& ((D1).high == (D2).high))
166
/****************************************************************
167
Sort function for dulint arrays. */
169
ut_dulint_sort(dulint* arr, dulint* aux_arr, ulint low, ulint high);
170
/*===============================================================*/
171
/************************************************************
172
The following function calculates the value of an integer n rounded
173
to the least product of align_no which is >= n. align_no has to be a
179
/* out: rounded value */
180
ulint n, /* in: number to be rounded */
181
ulint align_no); /* in: align by this number */
182
/************************************************************
183
The following function calculates the value of an integer n rounded
184
to the biggest product of align_no which is <= n. align_no has to be a
190
/* out: rounded value */
191
ulint n, /* in: number to be rounded */
192
ulint align_no); /* in: align by this number */
193
/*************************************************************
194
The following function rounds up a pointer to the nearest aligned address. */
199
/* out: aligned pointer */
200
void* ptr, /* in: pointer */
201
ulint align_no); /* in: align by this number */
202
/*************************************************************
203
The following function rounds down a pointer to the nearest
209
/* out: aligned pointer */
210
void* ptr, /* in: pointer */
211
ulint align_no) /* in: align by this number */
212
__attribute__((const));
213
/*************************************************************
214
The following function computes the offset of a pointer from the nearest
220
/* out: distance from aligned
222
const void* ptr, /* in: pointer */
223
ulint align_no) /* in: align by this number */
224
__attribute__((const));
225
/*********************************************************************
226
Gets the nth bit of a ulint. */
231
/* out: TRUE if nth bit is 1; 0th bit is defined to
232
be the least significant */
233
ulint a, /* in: ulint */
234
ulint n); /* in: nth bit requested */
235
/*********************************************************************
236
Sets the nth bit of a ulint. */
241
/* out: the ulint with the bit set as requested */
242
ulint a, /* in: ulint */
243
ulint n, /* in: nth bit requested */
244
ibool val); /* in: value for the bit to set */
247
#include "ut0byte.ic"