mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / innobase / include / ut0byte.h
blob6533f1166ca645ac33f31969260a575cc5e3691a
1 /**********************************************************************
2 Utilities for byte operations
4 (c) 1994, 1995 Innobase Oy
6 Created 1/20/1994 Heikki Tuuri
7 ***********************************************************************/
9 #ifndef ut0byte_h
10 #define ut0byte_h
13 #include "univ.i"
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;
21 struct dulint_struct{
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. */
34 UNIV_INLINE
35 dulint
36 ut_dulint_create(
37 /*=============*/
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. */
43 UNIV_INLINE
44 ulint
45 ut_dulint_get_high(
46 /*===============*/
47 /* out: 32 bits in ulint */
48 dulint d); /* in: dulint */
49 /***********************************************************
50 Gets the low-order 32 bits of a dulint. */
51 UNIV_INLINE
52 ulint
53 ut_dulint_get_low(
54 /*==============*/
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
59 integer type. */
60 UNIV_INLINE
61 ib_longlong
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. */
68 UNIV_INLINE
69 ibool
70 ut_dulint_is_zero(
71 /*==============*/
72 /* out: TRUE if zero */
73 dulint a); /* in: dulint */
74 /***********************************************************
75 Compares two dulints. */
76 UNIV_INLINE
77 int
78 ut_dulint_cmp(
79 /*==========*/
80 /* out: -1 if a < b, 0 if a == b,
81 1 if a > b */
82 dulint a, /* in: dulint */
83 dulint b); /* in: dulint */
84 /***********************************************************
85 Calculates the max of two dulints. */
86 UNIV_INLINE
87 dulint
88 ut_dulint_get_max(
89 /*==============*/
90 /* out: max(a, b) */
91 dulint a, /* in: dulint */
92 dulint b); /* in: dulint */
93 /***********************************************************
94 Calculates the min of two dulints. */
95 UNIV_INLINE
96 dulint
97 ut_dulint_get_min(
98 /*==============*/
99 /* out: min(a, b) */
100 dulint a, /* in: dulint */
101 dulint b); /* in: dulint */
102 /***********************************************************
103 Adds a ulint to a dulint. */
104 UNIV_INLINE
105 dulint
106 ut_dulint_add(
107 /*==========*/
108 /* out: sum a + b */
109 dulint a, /* in: dulint */
110 ulint b); /* in: ulint */
111 /***********************************************************
112 Subtracts a ulint from a dulint. */
113 UNIV_INLINE
114 dulint
115 ut_dulint_subtract(
116 /*===============*/
117 /* out: a - b */
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. */
123 UNIV_INLINE
124 ulint
125 ut_dulint_minus(
126 /*============*/
127 /* out: a - b */
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. */
133 UNIV_INLINE
134 dulint
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
140 power of 2 */
141 /************************************************************
142 Rounds a dulint upward to a multiple of a power of 2. */
143 UNIV_INLINE
144 dulint
145 ut_dulint_align_up(
146 /*===============*/
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
150 power of 2 */
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;\
157 (D).low = 0;\
158 } else {\
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. */
168 void
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
174 power of 2. */
175 UNIV_INLINE
176 ulint
177 ut_calc_align(
178 /*==========*/
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
185 power of 2. */
186 UNIV_INLINE
187 ulint
188 ut_calc_align_down(
189 /*===============*/
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. */
195 UNIV_INLINE
196 void*
197 ut_align(
198 /*=====*/
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
204 aligned address. */
205 UNIV_INLINE
206 void*
207 ut_align_down(
208 /*==========*/
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
215 aligned address. */
216 UNIV_INLINE
217 ulint
218 ut_align_offset(
219 /*============*/
220 /* out: distance from aligned
221 pointer */
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. */
227 UNIV_INLINE
228 ibool
229 ut_bit_get_nth(
230 /*===========*/
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. */
237 UNIV_INLINE
238 ulint
239 ut_bit_set_nth(
240 /*===========*/
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 */
246 #ifndef UNIV_NONINL
247 #include "ut0byte.ic"
248 #endif
250 #endif