MySQL  8.0.19
Source Code Documentation
myisampack.h
Go to the documentation of this file.
1 #ifndef MYISAMPACK_INCLUDED
2 #define MYISAMPACK_INCLUDED
3 
4 /* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License, version 2.0,
8  as published by the Free Software Foundation.
9 
10  This program is also distributed with certain software (including
11  but not limited to OpenSSL) that is licensed under separate terms,
12  as designated in a particular file or component or in included license
13  documentation. The authors of MySQL hereby grant you an additional
14  permission to link the program and your derivative works with the
15  separately licensed software that they have included with MySQL.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License, version 2.0, for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25 
26 /**
27  @file include/myisampack.h
28  Storing of values in high byte first order.
29 
30  Integer keys and file pointers are stored with high byte first to get
31  better compression.
32 */
33 
34 #include "my_config.h"
35 
36 #ifdef HAVE_ENDIAN_H
37 #include <endian.h>
38 #endif
39 #include <sys/types.h>
40 
41 #include "my_inttypes.h"
42 
43 /* these two are for uniformity */
44 
45 static inline int8 mi_sint1korr(const uchar *A) { return *A; }
46 
47 static inline uint8 mi_uint1korr(const uchar *A) { return *A; }
48 
49 static inline int16 mi_sint2korr(const uchar *A) {
50  return (int16)((uint32)(A[1]) + ((uint32)(A[0]) << 8));
51 }
52 
53 static inline int32 mi_sint3korr(const uchar *A) {
54  return (int32)((A[0] & 128) ? ((255U << 24) | ((uint32)(A[0]) << 16) |
55  ((uint32)(A[1]) << 8) | ((uint32)A[2]))
56  : (((uint32)(A[0]) << 16) |
57  ((uint32)(A[1]) << 8) | ((uint32)(A[2]))));
58 }
59 
60 static inline int32 mi_sint4korr(const uchar *A) {
61  return (int32)((uint32)(A[3]) + ((uint32)(A[2]) << 8) +
62  ((uint32)(A[1]) << 16) + ((uint32)(A[0]) << 24));
63 }
64 
65 static inline uint16 mi_uint2korr(const uchar *A) {
66  return (uint16)((uint16)A[1]) + ((uint16)A[0] << 8);
67 }
68 
69 static inline uint32 mi_uint3korr(const uchar *A) {
70  return (uint32)((uint32)A[2] + ((uint32)A[1] << 8) + ((uint32)A[0] << 16));
71 }
72 
73 static inline uint32 mi_uint4korr(const uchar *A) {
74  return (uint32)((uint32)A[3] + ((uint32)A[2] << 8) + ((uint32)A[1] << 16) +
75  ((uint32)A[0] << 24));
76 }
77 
78 static inline ulonglong mi_uint5korr(const uchar *A) {
79  return (ulonglong)((uint32)A[4] + ((uint32)A[3] << 8) + ((uint32)A[2] << 16) +
80  ((uint32)A[1] << 24)) +
81  ((ulonglong)A[0] << 32);
82 }
83 
84 static inline ulonglong mi_uint6korr(const uchar *A) {
85  return (ulonglong)((uint32)A[5] + ((uint32)A[4] << 8) + ((uint32)A[3] << 16) +
86  ((uint32)A[2] << 24)) +
87  (((ulonglong)((uint32)A[1] + ((uint32)A[0] << 8))) << 32);
88 }
89 
90 static inline ulonglong mi_uint7korr(const uchar *A) {
91  return (ulonglong)((uint32)A[6] + ((uint32)A[5] << 8) + ((uint32)A[4] << 16) +
92  ((uint32)A[3] << 24)) +
93  (((ulonglong)((uint32)A[2] + ((uint32)A[1] << 8) +
94  ((uint32)A[0] << 16)))
95  << 32);
96 }
97 
98 static inline ulonglong mi_uint8korr(const uchar *A) {
99  return (ulonglong)((uint32)A[7] + ((uint32)A[6] << 8) + ((uint32)A[5] << 16) +
100  ((uint32)A[4] << 24)) +
101  (((ulonglong)((uint32)A[3] + ((uint32)A[2] << 8) +
102  ((uint32)A[1] << 16) + ((uint32)A[0] << 24)))
103  << 32);
104 }
105 
106 static inline longlong mi_sint8korr(const uchar *A) {
107  return (longlong)mi_uint8korr(A);
108 }
109 
110 /* This one is for uniformity */
111 #define mi_int1store(T, A) *((uchar *)(T)) = (uchar)(A)
112 
113 #define mi_int2store(T, A) \
114  { \
115  uint def_temp = (uint)(A); \
116  ((uchar *)(T))[1] = (uchar)(def_temp); \
117  ((uchar *)(T))[0] = (uchar)(def_temp >> 8); \
118  }
119 #define mi_int3store(T, A) \
120  { /*lint -save -e734 */ \
121  ulong def_temp = (ulong)(A); \
122  ((uchar *)(T))[2] = (uchar)(def_temp); \
123  ((uchar *)(T))[1] = (uchar)(def_temp >> 8); \
124  ((uchar *)(T))[0] = (uchar)(def_temp >> 16); \
125  /*lint -restore */}
126 #define mi_int4store(T, A) \
127  { \
128  ulong def_temp = (ulong)(A); \
129  ((uchar *)(T))[3] = (uchar)(def_temp); \
130  ((uchar *)(T))[2] = (uchar)(def_temp >> 8); \
131  ((uchar *)(T))[1] = (uchar)(def_temp >> 16); \
132  ((uchar *)(T))[0] = (uchar)(def_temp >> 24); \
133  }
134 #define mi_int5store(T, A) \
135  { \
136  ulong def_temp = (ulong)(A), def_temp2 = (ulong)((A) >> 32); \
137  ((uchar *)(T))[4] = (uchar)(def_temp); \
138  ((uchar *)(T))[3] = (uchar)(def_temp >> 8); \
139  ((uchar *)(T))[2] = (uchar)(def_temp >> 16); \
140  ((uchar *)(T))[1] = (uchar)(def_temp >> 24); \
141  ((uchar *)(T))[0] = (uchar)(def_temp2); \
142  }
143 #define mi_int6store(T, A) \
144  { \
145  ulong def_temp = (ulong)(A), def_temp2 = (ulong)((A) >> 32); \
146  ((uchar *)(T))[5] = (uchar)(def_temp); \
147  ((uchar *)(T))[4] = (uchar)(def_temp >> 8); \
148  ((uchar *)(T))[3] = (uchar)(def_temp >> 16); \
149  ((uchar *)(T))[2] = (uchar)(def_temp >> 24); \
150  ((uchar *)(T))[1] = (uchar)(def_temp2); \
151  ((uchar *)(T))[0] = (uchar)(def_temp2 >> 8); \
152  }
153 #define mi_int7store(T, A) \
154  { \
155  ulong def_temp = (ulong)(A), def_temp2 = (ulong)((A) >> 32); \
156  ((uchar *)(T))[6] = (uchar)(def_temp); \
157  ((uchar *)(T))[5] = (uchar)(def_temp >> 8); \
158  ((uchar *)(T))[4] = (uchar)(def_temp >> 16); \
159  ((uchar *)(T))[3] = (uchar)(def_temp >> 24); \
160  ((uchar *)(T))[2] = (uchar)(def_temp2); \
161  ((uchar *)(T))[1] = (uchar)(def_temp2 >> 8); \
162  ((uchar *)(T))[0] = (uchar)(def_temp2 >> 16); \
163  }
164 #define mi_int8store(T, A) \
165  { \
166  ulong def_temp3 = (ulong)(A), def_temp4 = (ulong)((A) >> 32); \
167  mi_int4store((uchar *)(T) + 0, def_temp4); \
168  mi_int4store((uchar *)(T) + 4, def_temp3); \
169  }
170 
171 #ifdef WORDS_BIGENDIAN
172 
173 #define mi_float4store(T, A) \
174  { \
175  ((uchar *)(T))[0] = ((uchar *)&A)[0]; \
176  ((uchar *)(T))[1] = ((uchar *)&A)[1]; \
177  ((uchar *)(T))[2] = ((uchar *)&A)[2]; \
178  ((uchar *)(T))[3] = ((uchar *)&A)[3]; \
179  }
180 
181 static inline float mi_float4get(const uchar *M) {
182  float def_temp;
183  ((uchar *)&def_temp)[0] = M[0];
184  ((uchar *)&def_temp)[1] = M[1];
185  ((uchar *)&def_temp)[2] = M[2];
186  ((uchar *)&def_temp)[3] = M[3];
187  return def_temp;
188 }
189 
190 #define mi_float8store(T, V) \
191  { \
192  ((uchar *)(T))[0] = ((uchar *)&V)[0]; \
193  ((uchar *)(T))[1] = ((uchar *)&V)[1]; \
194  ((uchar *)(T))[2] = ((uchar *)&V)[2]; \
195  ((uchar *)(T))[3] = ((uchar *)&V)[3]; \
196  ((uchar *)(T))[4] = ((uchar *)&V)[4]; \
197  ((uchar *)(T))[5] = ((uchar *)&V)[5]; \
198  ((uchar *)(T))[6] = ((uchar *)&V)[6]; \
199  ((uchar *)(T))[7] = ((uchar *)&V)[7]; \
200  }
201 
202 static inline double mi_float8get(const uchar *M) {
203  double def_temp;
204  ((uchar *)&def_temp)[0] = M[0];
205  ((uchar *)&def_temp)[1] = M[1];
206  ((uchar *)&def_temp)[2] = M[2];
207  ((uchar *)&def_temp)[3] = M[3];
208  ((uchar *)&def_temp)[4] = M[4];
209  ((uchar *)&def_temp)[5] = M[5];
210  ((uchar *)&def_temp)[6] = M[6];
211  ((uchar *)&def_temp)[7] = M[7];
212  return def_temp;
213 }
214 #else
215 
216 #define mi_float4store(T, A) \
217  { \
218  ((uchar *)(T))[0] = ((uchar *)&A)[3]; \
219  ((uchar *)(T))[1] = ((uchar *)&A)[2]; \
220  ((uchar *)(T))[2] = ((uchar *)&A)[1]; \
221  ((uchar *)(T))[3] = ((uchar *)&A)[0]; \
222  }
223 
224 static inline float mi_float4get(const uchar *M) {
225  float def_temp;
226  ((uchar *)&def_temp)[0] = M[3];
227  ((uchar *)&def_temp)[1] = M[2];
228  ((uchar *)&def_temp)[2] = M[1];
229  ((uchar *)&def_temp)[3] = M[0];
230  return def_temp;
231 }
232 
233 #if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
234 #define mi_float8store(T, V) \
235  { \
236  ((uchar *)(T))[0] = ((uchar *)&V)[3]; \
237  ((uchar *)(T))[1] = ((uchar *)&V)[2]; \
238  ((uchar *)(T))[2] = ((uchar *)&V)[1]; \
239  ((uchar *)(T))[3] = ((uchar *)&V)[0]; \
240  ((uchar *)(T))[4] = ((uchar *)&V)[7]; \
241  ((uchar *)(T))[5] = ((uchar *)&V)[6]; \
242  ((uchar *)(T))[6] = ((uchar *)&V)[5]; \
243  ((uchar *)(T))[7] = ((uchar *)&V)[4]; \
244  }
245 
246 static inline double mi_float8get(const uchar *M) {
247  double def_temp;
248  ((uchar *)&def_temp)[0] = M[3];
249  ((uchar *)&def_temp)[1] = M[2];
250  ((uchar *)&def_temp)[2] = M[1];
251  ((uchar *)&def_temp)[3] = M[0];
252  ((uchar *)&def_temp)[4] = M[7];
253  ((uchar *)&def_temp)[5] = M[6];
254  ((uchar *)&def_temp)[6] = M[5];
255  ((uchar *)&def_temp)[7] = M[4];
256  return def_temp;
257 }
258 
259 #else
260 #define mi_float8store(T, V) \
261  { \
262  ((uchar *)(T))[0] = ((uchar *)&V)[7]; \
263  ((uchar *)(T))[1] = ((uchar *)&V)[6]; \
264  ((uchar *)(T))[2] = ((uchar *)&V)[5]; \
265  ((uchar *)(T))[3] = ((uchar *)&V)[4]; \
266  ((uchar *)(T))[4] = ((uchar *)&V)[3]; \
267  ((uchar *)(T))[5] = ((uchar *)&V)[2]; \
268  ((uchar *)(T))[6] = ((uchar *)&V)[1]; \
269  ((uchar *)(T))[7] = ((uchar *)&V)[0]; \
270  }
271 
272 static inline double mi_float8get(const uchar *M) {
273  double def_temp;
274  ((uchar *)&def_temp)[0] = M[7];
275  ((uchar *)&def_temp)[1] = M[6];
276  ((uchar *)&def_temp)[2] = M[5];
277  ((uchar *)&def_temp)[3] = M[4];
278  ((uchar *)&def_temp)[4] = M[3];
279  ((uchar *)&def_temp)[5] = M[2];
280  ((uchar *)&def_temp)[6] = M[1];
281  ((uchar *)&def_temp)[7] = M[0];
282  return def_temp;
283 }
284 
285 #endif /* __FLOAT_WORD_ORDER */
286 #endif /* WORDS_BIGENDIAN */
287 
288 #define mi_rowstore(T, A) mi_int8store(T, A)
289 #define mi_rowkorr(T) mi_uint8korr(T)
290 
291 #define mi_sizestore(T, A) mi_int8store(T, A)
292 #define mi_sizekorr(T) mi_uint8korr(T)
293 
294 #endif /* MYISAMPACK_INCLUDED */
mi_uint4korr
static uint32 mi_uint4korr(const uchar *A)
Definition: myisampack.h:73
int32
int32_t int32
Definition: my_inttypes.h:65
mi_float4get
static float mi_float4get(const uchar *M)
Definition: myisampack.h:224
longlong
long long int longlong
Definition: my_inttypes.h:54
mi_uint5korr
static ulonglong mi_uint5korr(const uchar *A)
Definition: myisampack.h:78
mi_sint2korr
static int16 mi_sint2korr(const uchar *A)
Definition: myisampack.h:49
mi_sint1korr
static int8 mi_sint1korr(const uchar *A)
Definition: myisampack.h:45
mi_uint7korr
static ulonglong mi_uint7korr(const uchar *A)
Definition: myisampack.h:90
mi_uint6korr
static ulonglong mi_uint6korr(const uchar *A)
Definition: myisampack.h:84
mi_uint3korr
static uint32 mi_uint3korr(const uchar *A)
Definition: myisampack.h:69
U
Definition: dtoa.cc:603
my_inttypes.h
mi_uint8korr
static ulonglong mi_uint8korr(const uchar *A)
Definition: myisampack.h:98
int8
int8_t int8
Definition: my_inttypes.h:61
mi_sint8korr
static longlong mi_sint8korr(const uchar *A)
Definition: myisampack.h:106
uchar
unsigned char uchar
Definition: my_inttypes.h:51
mi_float8get
static double mi_float8get(const uchar *M)
Definition: myisampack.h:272
uint32
uint32_t uint32
Definition: my_inttypes.h:66
mi_uint2korr
static uint16 mi_uint2korr(const uchar *A)
Definition: myisampack.h:65
mi_sint4korr
static int32 mi_sint4korr(const uchar *A)
Definition: myisampack.h:60
mi_sint3korr
static int32 mi_sint3korr(const uchar *A)
Definition: myisampack.h:53
uint8
uint8_t uint8
Definition: my_inttypes.h:62
mi_uint1korr
static uint8 mi_uint1korr(const uchar *A)
Definition: myisampack.h:47
uint16
uint16_t uint16
Definition: my_inttypes.h:64
ulonglong
unsigned long long int ulonglong
Definition: my_inttypes.h:55
M
#define M
Definition: ctype-tis620.cc:73
int16
int16_t int16
Definition: my_inttypes.h:63
endian.h