The world's most popular open source database
00001 /********************************************************************** 00002 Utilities for byte operations 00003 00004 (c) 1994, 1995 Innobase Oy 00005 00006 Created 1/20/1994 Heikki Tuuri 00007 ***********************************************************************/ 00008 00009 #ifndef ut0byte_h 00010 #define ut0byte_h 00011 00012 00013 #include "univ.i" 00014 00015 /* Type definition for a 64-bit unsigned integer, which works also 00016 in 32-bit machines. NOTE! Access the fields only with the accessor 00017 functions. This definition appears here only for the compiler to 00018 know the size of a dulint. */ 00019 00020 typedef struct dulint_struct dulint; 00021 struct dulint_struct{ 00022 ulint high; /* most significant 32 bits */ 00023 ulint low; /* least significant 32 bits */ 00024 }; 00025 00026 /* Zero value for a dulint */ 00027 extern dulint ut_dulint_zero; 00028 00029 /* Maximum value for a dulint */ 00030 extern dulint ut_dulint_max; 00031 00032 /*********************************************************** 00033 Creates a 64-bit dulint out of two ulints. */ 00034 UNIV_INLINE 00035 dulint 00036 ut_dulint_create( 00037 /*=============*/ 00038 /* out: created dulint */ 00039 ulint high, /* in: high-order 32 bits */ 00040 ulint low); /* in: low-order 32 bits */ 00041 /*********************************************************** 00042 Gets the high-order 32 bits of a dulint. */ 00043 UNIV_INLINE 00044 ulint 00045 ut_dulint_get_high( 00046 /*===============*/ 00047 /* out: 32 bits in ulint */ 00048 dulint d); /* in: dulint */ 00049 /*********************************************************** 00050 Gets the low-order 32 bits of a dulint. */ 00051 UNIV_INLINE 00052 ulint 00053 ut_dulint_get_low( 00054 /*==============*/ 00055 /* out: 32 bits in ulint */ 00056 dulint d); /* in: dulint */ 00057 /*********************************************************** 00058 Converts a dulint (a struct of 2 ulints) to ib_longlong, which is a 64-bit 00059 integer type. */ 00060 UNIV_INLINE 00061 ib_longlong 00062 ut_conv_dulint_to_longlong( 00063 /*=======================*/ 00064 /* out: value in ib_longlong type */ 00065 dulint d); /* in: dulint */ 00066 /*********************************************************** 00067 Tests if a dulint is zero. */ 00068 UNIV_INLINE 00069 ibool 00070 ut_dulint_is_zero( 00071 /*==============*/ 00072 /* out: TRUE if zero */ 00073 dulint a); /* in: dulint */ 00074 /*********************************************************** 00075 Compares two dulints. */ 00076 UNIV_INLINE 00077 int 00078 ut_dulint_cmp( 00079 /*==========*/ 00080 /* out: -1 if a < b, 0 if a == b, 00081 1 if a > b */ 00082 dulint a, /* in: dulint */ 00083 dulint b); /* in: dulint */ 00084 /*********************************************************** 00085 Calculates the max of two dulints. */ 00086 UNIV_INLINE 00087 dulint 00088 ut_dulint_get_max( 00089 /*==============*/ 00090 /* out: max(a, b) */ 00091 dulint a, /* in: dulint */ 00092 dulint b); /* in: dulint */ 00093 /*********************************************************** 00094 Calculates the min of two dulints. */ 00095 UNIV_INLINE 00096 dulint 00097 ut_dulint_get_min( 00098 /*==============*/ 00099 /* out: min(a, b) */ 00100 dulint a, /* in: dulint */ 00101 dulint b); /* in: dulint */ 00102 /*********************************************************** 00103 Adds a ulint to a dulint. */ 00104 UNIV_INLINE 00105 dulint 00106 ut_dulint_add( 00107 /*==========*/ 00108 /* out: sum a + b */ 00109 dulint a, /* in: dulint */ 00110 ulint b); /* in: ulint */ 00111 /*********************************************************** 00112 Subtracts a ulint from a dulint. */ 00113 UNIV_INLINE 00114 dulint 00115 ut_dulint_subtract( 00116 /*===============*/ 00117 /* out: a - b */ 00118 dulint a, /* in: dulint */ 00119 ulint b); /* in: ulint, b <= a */ 00120 /*********************************************************** 00121 Subtracts a dulint from another. NOTE that the difference must be positive 00122 and smaller that 4G. */ 00123 UNIV_INLINE 00124 ulint 00125 ut_dulint_minus( 00126 /*============*/ 00127 /* out: a - b */ 00128 dulint a, /* in: dulint; NOTE a must be >= b and at most 00129 2 to power 32 - 1 greater */ 00130 dulint b); /* in: dulint */ 00131 /************************************************************ 00132 Rounds a dulint downward to a multiple of a power of 2. */ 00133 UNIV_INLINE 00134 dulint 00135 ut_dulint_align_down( 00136 /*=================*/ 00137 /* out: rounded value */ 00138 dulint n, /* in: number to be rounded */ 00139 ulint align_no); /* in: align by this number which must be a 00140 power of 2 */ 00141 /************************************************************ 00142 Rounds a dulint upward to a multiple of a power of 2. */ 00143 UNIV_INLINE 00144 dulint 00145 ut_dulint_align_up( 00146 /*===============*/ 00147 /* out: rounded value */ 00148 dulint n, /* in: number to be rounded */ 00149 ulint align_no); /* in: align by this number which must be a 00150 power of 2 */ 00151 /*********************************************************** 00152 Increments a dulint variable by 1. */ 00153 #define UT_DULINT_INC(D)\ 00154 {\ 00155 if ((D).low == 0xFFFFFFFFUL) {\ 00156 (D).high = (D).high + 1;\ 00157 (D).low = 0;\ 00158 } else {\ 00159 (D).low = (D).low + 1;\ 00160 }\ 00161 } 00162 /*********************************************************** 00163 Tests if two dulints are equal. */ 00164 #define UT_DULINT_EQ(D1, D2) (((D1).low == (D2).low)\ 00165 && ((D1).high == (D2).high)) 00166 /**************************************************************** 00167 Sort function for dulint arrays. */ 00168 void 00169 ut_dulint_sort(dulint* arr, dulint* aux_arr, ulint low, ulint high); 00170 /*===============================================================*/ 00171 /************************************************************ 00172 The following function calculates the value of an integer n rounded 00173 to the least product of align_no which is >= n. align_no has to be a 00174 power of 2. */ 00175 UNIV_INLINE 00176 ulint 00177 ut_calc_align( 00178 /*==========*/ 00179 /* out: rounded value */ 00180 ulint n, /* in: number to be rounded */ 00181 ulint align_no); /* in: align by this number */ 00182 /************************************************************ 00183 The following function calculates the value of an integer n rounded 00184 to the biggest product of align_no which is <= n. align_no has to be a 00185 power of 2. */ 00186 UNIV_INLINE 00187 ulint 00188 ut_calc_align_down( 00189 /*===============*/ 00190 /* out: rounded value */ 00191 ulint n, /* in: number to be rounded */ 00192 ulint align_no); /* in: align by this number */ 00193 /************************************************************* 00194 The following function rounds up a pointer to the nearest aligned address. */ 00195 UNIV_INLINE 00196 void* 00197 ut_align( 00198 /*=====*/ 00199 /* out: aligned pointer */ 00200 void* ptr, /* in: pointer */ 00201 ulint align_no); /* in: align by this number */ 00202 /************************************************************* 00203 The following function rounds down a pointer to the nearest 00204 aligned address. */ 00205 UNIV_INLINE 00206 void* 00207 ut_align_down( 00208 /*==========*/ 00209 /* out: aligned pointer */ 00210 void* ptr, /* in: pointer */ 00211 ulint align_no) /* in: align by this number */ 00212 __attribute__((const)); 00213 /************************************************************* 00214 The following function computes the offset of a pointer from the nearest 00215 aligned address. */ 00216 UNIV_INLINE 00217 ulint 00218 ut_align_offset( 00219 /*============*/ 00220 /* out: distance from aligned 00221 pointer */ 00222 const void* ptr, /* in: pointer */ 00223 ulint align_no) /* in: align by this number */ 00224 __attribute__((const)); 00225 /********************************************************************* 00226 Gets the nth bit of a ulint. */ 00227 UNIV_INLINE 00228 ibool 00229 ut_bit_get_nth( 00230 /*===========*/ 00231 /* out: TRUE if nth bit is 1; 0th bit is defined to 00232 be the least significant */ 00233 ulint a, /* in: ulint */ 00234 ulint n); /* in: nth bit requested */ 00235 /********************************************************************* 00236 Sets the nth bit of a ulint. */ 00237 UNIV_INLINE 00238 ulint 00239 ut_bit_set_nth( 00240 /*===========*/ 00241 /* out: the ulint with the bit set as requested */ 00242 ulint a, /* in: ulint */ 00243 ulint n, /* in: nth bit requested */ 00244 ibool val); /* in: value for the bit to set */ 00245 00246 #ifndef UNIV_NONINL 00247 #include "ut0byte.ic" 00248 #endif 00249 00250 #endif
1.4.7

