~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2009-03-04 02:48:12 UTC
  • mto: (917.1.2 mordred)
  • mto: This revision was merged to the branch mainline in revision 918.
  • Revision ID: mordred@inaugust.com-20090304024812-5wb6wpye5c1iitbq
Applied atomic patch to current tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
4
 
 
5
 
This program is free software; you can redistribute it and/or modify it under
6
 
the terms of the GNU General Public License as published by the Free Software
7
 
Foundation; version 2 of the License.
8
 
 
9
 
This program is distributed in the hope that it will be useful, but WITHOUT
10
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
 
 
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
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/******************************************************************//**
20
 
@file include/ut0byte.h
 
1
/**********************************************************************
21
2
Utilities for byte operations
22
3
 
 
4
(c) 1994, 1995 Innobase Oy
 
5
 
23
6
Created 1/20/1994 Heikki Tuuri
24
7
***********************************************************************/
25
8
 
27
10
#define ut0byte_h
28
11
 
29
12
 
30
 
 
31
13
#include "univ.i"
32
14
 
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 */
 
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. */
47
153
UNIV_INLINE
48
154
ib_uint64_t
49
155
ut_uint64_align_down(
50
156
/*=================*/
51
 
        ib_uint64_t      n,             /*!< in: number to be rounded */
52
 
        ulint            align_no);     /*!< in: align by this number
 
157
                                        /* out: rounded value */
 
158
        ib_uint64_t      n,             /* in: number to be rounded */
 
159
        ulint            align_no);     /* in: align by this number
53
160
                                        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 */
 
161
/************************************************************
 
162
Rounds ib_uint64_t upward to a multiple of a power of 2. */
57
163
UNIV_INLINE
58
164
ib_uint64_t
59
165
ut_uint64_align_up(
60
166
/*===============*/
61
 
        ib_uint64_t      n,             /*!< in: number to be rounded */
62
 
        ulint            align_no);     /*!< in: align by this number
 
167
                                        /* out: rounded value */
 
168
        ib_uint64_t      n,             /* in: number to be rounded */
 
169
        ulint            align_no);     /* in: align by this number
63
170
                                        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 */
 
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. */
67
197
UNIV_INLINE
68
198
void*
69
199
ut_align(
70
200
/*=====*/
71
 
        const void*     ptr,            /*!< in: pointer */
72
 
        ulint           align_no);      /*!< in: align by this number */
73
 
/*********************************************************//**
 
201
                                /* out: aligned pointer */
 
202
        void*   ptr,            /* in: pointer */
 
203
        ulint   align_no);      /* in: align by this number */
 
204
/*************************************************************
74
205
The following function rounds down a pointer to the nearest
75
 
aligned address.
76
 
@return aligned pointer */
 
206
aligned address. */
77
207
UNIV_INLINE
78
208
void*
79
209
ut_align_down(
80
210
/*==========*/
81
 
        const void*     ptr,            /*!< in: pointer */
82
 
        ulint           align_no)       /*!< in: align by this number */
83
 
                __attribute__((const));
84
 
/*********************************************************//**
 
211
                                        /* out: aligned pointer */
 
212
        const void*     ptr,            /* in: pointer */
 
213
        ulint           align_no)       /* in: align by this number */
 
214
                __attribute__((__const__));
 
215
/*************************************************************
85
216
The following function computes the offset of a pointer from the nearest
86
 
aligned address.
87
 
@return distance from aligned pointer */
 
217
aligned address. */
88
218
UNIV_INLINE
89
219
ulint
90
220
ut_align_offset(
91
221
/*============*/
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 */
 
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. */
98
229
UNIV_INLINE
99
230
ibool
100
231
ut_bit_get_nth(
101
232
/*===========*/
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 */
 
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. */
107
239
UNIV_INLINE
108
240
ulint
109
241
ut_bit_set_nth(
110
242
/*===========*/
111
 
        ulint   a,      /*!< in: ulint */
112
 
        ulint   n,      /*!< in: nth bit requested */
113
 
        ibool   val);   /*!< in: value for the bit to set */
 
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 */
114
247
 
115
248
#ifndef UNIV_NONINL
116
249
#include "ut0byte.ic"