~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/ut0byte.h

  • Committer: Padraig O'Sullivan
  • Date: 2009-03-21 01:02:23 UTC
  • mto: (960.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 961.
  • Revision ID: osullivan.padraig@gmail.com-20090321010223-j8cph7eeyt1u3xol
Fixed function object to ensure it correctly returns a boolean type since
memcmp returns an integer. Added some more comments.

Show diffs side-by-side

added added

removed removed

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