~percona-dev/percona-innodb-plugin/percona-innodb-1.0

« back to all changes in this revision

Viewing changes to include/ut0byte.h

  • Committer: Vadim Tkachenko
  • Date: 2008-12-01 02:05:57 UTC
  • Revision ID: vadim@percona.com-20081201020557-p7k2m94mjtdg1a83
New rw-locks

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**********************************************************************
 
2
Utilities for byte operations
 
3
 
 
4
(c) 1994, 1995 Innobase Oy
 
5
 
 
6
Created 1/20/1994 Heikki Tuuri
 
7
***********************************************************************/
 
8
 
 
9
#ifndef ut0byte_h
 
10
#define ut0byte_h
 
11
 
 
12
 
 
13
#include "univ.i"
 
14
 
 
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. */
 
19
 
 
20
typedef struct dulint_struct    dulint;
 
21
struct dulint_struct{
 
22
        ulint   high;   /* most significant 32 bits */
 
23
        ulint   low;    /* least significant 32 bits */
 
24
};
 
25
 
 
26
/* Zero value for a dulint */
 
27
extern const dulint     ut_dulint_zero;
 
28
 
 
29
/* Maximum value for a dulint */
 
30
extern const dulint     ut_dulint_max;
 
31
 
 
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_int64_t, which is a 64-bit
 
59
integer type. */
 
60
UNIV_INLINE
 
61
ib_int64_t
 
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. */
 
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
Rounds a dulint downward to a multiple of a power of 2. */
 
153
UNIV_INLINE
 
154
ib_uint64_t
 
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. */
 
163
UNIV_INLINE
 
164
ib_uint64_t
 
165
ut_uint64_align_up(
 
166
/*===============*/
 
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)\
 
174
{\
 
175
        if ((D).low == 0xFFFFFFFFUL) {\
 
176
                (D).high = (D).high + 1;\
 
177
                (D).low = 0;\
 
178
        } else {\
 
179
                (D).low = (D).low + 1;\
 
180
        }\
 
181
}
 
182
/***********************************************************
 
183
Tests if two dulints are equal. */
 
184
#define UT_DULINT_EQ(D1, D2)    (((D1).low == (D2).low)\
 
185
                                                && ((D1).high == (D2).high))
 
186
#ifdef notdefined
 
187
/****************************************************************
 
188
Sort function for dulint arrays. */
 
189
UNIV_INTERN
 
190
void
 
191
ut_dulint_sort(dulint* arr, dulint* aux_arr, ulint low, ulint high);
 
192
/*===============================================================*/
 
193
#endif /* notdefined */
 
194
 
 
195
/*************************************************************
 
196
The following function rounds up a pointer to the nearest aligned address. */
 
197
UNIV_INLINE
 
198
void*
 
199
ut_align(
 
200
/*=====*/
 
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
 
206
aligned address. */
 
207
UNIV_INLINE
 
208
void*
 
209
ut_align_down(
 
210
/*==========*/
 
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
 
217
aligned address. */
 
218
UNIV_INLINE
 
219
ulint
 
220
ut_align_offset(
 
221
/*============*/
 
222
                                        /* out: distance from aligned
 
223
                                        pointer */
 
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. */
 
229
UNIV_INLINE
 
230
ibool
 
231
ut_bit_get_nth(
 
232
/*===========*/
 
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. */
 
239
UNIV_INLINE
 
240
ulint
 
241
ut_bit_set_nth(
 
242
/*===========*/
 
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 */
 
247
 
 
248
#ifndef UNIV_NONINL
 
249
#include "ut0byte.ic"
 
250
#endif
 
251
 
 
252
#endif