MySQL 8.0.30
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, 2022, Oracle and/or its affiliates.
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#include <sys/types.h>
37
38#include "my_inttypes.h"
39
40/* these two are for uniformity */
41
42static inline int8 mi_sint1korr(const uchar *A) { return *A; }
43
44static inline uint8 mi_uint1korr(const uchar *A) { return *A; }
45
46static inline int16 mi_sint2korr(const uchar *A) {
47 return (int16)((uint32)(A[1]) + ((uint32)(A[0]) << 8));
48}
49
50static inline int32 mi_sint3korr(const uchar *A) {
51 return (int32)((A[0] & 128) ? ((255U << 24) | ((uint32)(A[0]) << 16) |
52 ((uint32)(A[1]) << 8) | ((uint32)A[2]))
53 : (((uint32)(A[0]) << 16) |
54 ((uint32)(A[1]) << 8) | ((uint32)(A[2]))));
55}
56
57static inline int32 mi_sint4korr(const uchar *A) {
58 return (int32)((uint32)(A[3]) + ((uint32)(A[2]) << 8) +
59 ((uint32)(A[1]) << 16) + ((uint32)(A[0]) << 24));
60}
61
62static inline uint16 mi_uint2korr(const uchar *A) {
63 return (uint16)((uint16)A[1]) + ((uint16)A[0] << 8);
64}
65
66static inline uint32 mi_uint3korr(const uchar *A) {
67 return (uint32)((uint32)A[2] + ((uint32)A[1] << 8) + ((uint32)A[0] << 16));
68}
69
70static inline uint32 mi_uint4korr(const uchar *A) {
71 return (uint32)((uint32)A[3] + ((uint32)A[2] << 8) + ((uint32)A[1] << 16) +
72 ((uint32)A[0] << 24));
73}
74
75static inline ulonglong mi_uint5korr(const uchar *A) {
76 return (ulonglong)((uint32)A[4] + ((uint32)A[3] << 8) + ((uint32)A[2] << 16) +
77 ((uint32)A[1] << 24)) +
78 ((ulonglong)A[0] << 32);
79}
80
81static inline ulonglong mi_uint6korr(const uchar *A) {
82 return (ulonglong)((uint32)A[5] + ((uint32)A[4] << 8) + ((uint32)A[3] << 16) +
83 ((uint32)A[2] << 24)) +
84 (((ulonglong)((uint32)A[1] + ((uint32)A[0] << 8))) << 32);
85}
86
87static inline ulonglong mi_uint7korr(const uchar *A) {
88 return (ulonglong)((uint32)A[6] + ((uint32)A[5] << 8) + ((uint32)A[4] << 16) +
89 ((uint32)A[3] << 24)) +
90 (((ulonglong)((uint32)A[2] + ((uint32)A[1] << 8) +
91 ((uint32)A[0] << 16)))
92 << 32);
93}
94
95static inline ulonglong mi_uint8korr(const uchar *A) {
96 return (ulonglong)((uint32)A[7] + ((uint32)A[6] << 8) + ((uint32)A[5] << 16) +
97 ((uint32)A[4] << 24)) +
98 (((ulonglong)((uint32)A[3] + ((uint32)A[2] << 8) +
99 ((uint32)A[1] << 16) + ((uint32)A[0] << 24)))
100 << 32);
101}
102
103static inline longlong mi_sint8korr(const uchar *A) {
104 return (longlong)mi_uint8korr(A);
105}
106
107/* This one is for uniformity */
108#define mi_int1store(T, A) *((uchar *)(T)) = (uchar)(A)
109
110#define mi_int2store(T, A) \
111 { \
112 uint def_temp = (uint)(A); \
113 ((uchar *)(T))[1] = (uchar)(def_temp); \
114 ((uchar *)(T))[0] = (uchar)(def_temp >> 8); \
115 }
116#define mi_int3store(T, A) \
117 { /*lint -save -e734 */ \
118 ulong def_temp = (ulong)(A); \
119 ((uchar *)(T))[2] = (uchar)(def_temp); \
120 ((uchar *)(T))[1] = (uchar)(def_temp >> 8); \
121 ((uchar *)(T))[0] = (uchar)(def_temp >> 16); \
122 /*lint -restore */}
123#define mi_int4store(T, A) \
124 { \
125 ulong def_temp = (ulong)(A); \
126 ((uchar *)(T))[3] = (uchar)(def_temp); \
127 ((uchar *)(T))[2] = (uchar)(def_temp >> 8); \
128 ((uchar *)(T))[1] = (uchar)(def_temp >> 16); \
129 ((uchar *)(T))[0] = (uchar)(def_temp >> 24); \
130 }
131#define mi_int5store(T, A) \
132 { \
133 ulong def_temp = (ulong)(A), def_temp2 = (ulong)((A) >> 32); \
134 ((uchar *)(T))[4] = (uchar)(def_temp); \
135 ((uchar *)(T))[3] = (uchar)(def_temp >> 8); \
136 ((uchar *)(T))[2] = (uchar)(def_temp >> 16); \
137 ((uchar *)(T))[1] = (uchar)(def_temp >> 24); \
138 ((uchar *)(T))[0] = (uchar)(def_temp2); \
139 }
140#define mi_int6store(T, A) \
141 { \
142 ulong def_temp = (ulong)(A), def_temp2 = (ulong)((A) >> 32); \
143 ((uchar *)(T))[5] = (uchar)(def_temp); \
144 ((uchar *)(T))[4] = (uchar)(def_temp >> 8); \
145 ((uchar *)(T))[3] = (uchar)(def_temp >> 16); \
146 ((uchar *)(T))[2] = (uchar)(def_temp >> 24); \
147 ((uchar *)(T))[1] = (uchar)(def_temp2); \
148 ((uchar *)(T))[0] = (uchar)(def_temp2 >> 8); \
149 }
150#define mi_int7store(T, A) \
151 { \
152 ulong def_temp = (ulong)(A), def_temp2 = (ulong)((A) >> 32); \
153 ((uchar *)(T))[6] = (uchar)(def_temp); \
154 ((uchar *)(T))[5] = (uchar)(def_temp >> 8); \
155 ((uchar *)(T))[4] = (uchar)(def_temp >> 16); \
156 ((uchar *)(T))[3] = (uchar)(def_temp >> 24); \
157 ((uchar *)(T))[2] = (uchar)(def_temp2); \
158 ((uchar *)(T))[1] = (uchar)(def_temp2 >> 8); \
159 ((uchar *)(T))[0] = (uchar)(def_temp2 >> 16); \
160 }
161#define mi_int8store(T, A) \
162 { \
163 ulong def_temp3 = (ulong)(A), def_temp4 = (ulong)((A) >> 32); \
164 mi_int4store((uchar *)(T) + 0, def_temp4); \
165 mi_int4store((uchar *)(T) + 4, def_temp3); \
166 }
167
168#ifdef WORDS_BIGENDIAN
169
170#define mi_float4store(T, A) \
171 { \
172 ((uchar *)(T))[0] = ((uchar *)&A)[0]; \
173 ((uchar *)(T))[1] = ((uchar *)&A)[1]; \
174 ((uchar *)(T))[2] = ((uchar *)&A)[2]; \
175 ((uchar *)(T))[3] = ((uchar *)&A)[3]; \
176 }
177
178static inline float mi_float4get(const uchar *M) {
179 float def_temp;
180 ((uchar *)&def_temp)[0] = M[0];
181 ((uchar *)&def_temp)[1] = M[1];
182 ((uchar *)&def_temp)[2] = M[2];
183 ((uchar *)&def_temp)[3] = M[3];
184 return def_temp;
185}
186
187#define mi_float8store(T, V) \
188 { \
189 ((uchar *)(T))[0] = ((uchar *)&V)[0]; \
190 ((uchar *)(T))[1] = ((uchar *)&V)[1]; \
191 ((uchar *)(T))[2] = ((uchar *)&V)[2]; \
192 ((uchar *)(T))[3] = ((uchar *)&V)[3]; \
193 ((uchar *)(T))[4] = ((uchar *)&V)[4]; \
194 ((uchar *)(T))[5] = ((uchar *)&V)[5]; \
195 ((uchar *)(T))[6] = ((uchar *)&V)[6]; \
196 ((uchar *)(T))[7] = ((uchar *)&V)[7]; \
197 }
198
199static inline double mi_float8get(const uchar *M) {
200 double def_temp;
201 ((uchar *)&def_temp)[0] = M[0];
202 ((uchar *)&def_temp)[1] = M[1];
203 ((uchar *)&def_temp)[2] = M[2];
204 ((uchar *)&def_temp)[3] = M[3];
205 ((uchar *)&def_temp)[4] = M[4];
206 ((uchar *)&def_temp)[5] = M[5];
207 ((uchar *)&def_temp)[6] = M[6];
208 ((uchar *)&def_temp)[7] = M[7];
209 return def_temp;
210}
211#else
212
213#define mi_float4store(T, A) \
214 { \
215 ((uchar *)(T))[0] = ((uchar *)&A)[3]; \
216 ((uchar *)(T))[1] = ((uchar *)&A)[2]; \
217 ((uchar *)(T))[2] = ((uchar *)&A)[1]; \
218 ((uchar *)(T))[3] = ((uchar *)&A)[0]; \
219 }
220
221static inline float mi_float4get(const uchar *M) {
222 float def_temp;
223 ((uchar *)&def_temp)[0] = M[3];
224 ((uchar *)&def_temp)[1] = M[2];
225 ((uchar *)&def_temp)[2] = M[1];
226 ((uchar *)&def_temp)[3] = M[0];
227 return def_temp;
228}
229
230#if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
231#define mi_float8store(T, V) \
232 { \
233 ((uchar *)(T))[0] = ((uchar *)&V)[3]; \
234 ((uchar *)(T))[1] = ((uchar *)&V)[2]; \
235 ((uchar *)(T))[2] = ((uchar *)&V)[1]; \
236 ((uchar *)(T))[3] = ((uchar *)&V)[0]; \
237 ((uchar *)(T))[4] = ((uchar *)&V)[7]; \
238 ((uchar *)(T))[5] = ((uchar *)&V)[6]; \
239 ((uchar *)(T))[6] = ((uchar *)&V)[5]; \
240 ((uchar *)(T))[7] = ((uchar *)&V)[4]; \
241 }
242
243static inline double mi_float8get(const uchar *M) {
244 double def_temp;
245 ((uchar *)&def_temp)[0] = M[3];
246 ((uchar *)&def_temp)[1] = M[2];
247 ((uchar *)&def_temp)[2] = M[1];
248 ((uchar *)&def_temp)[3] = M[0];
249 ((uchar *)&def_temp)[4] = M[7];
250 ((uchar *)&def_temp)[5] = M[6];
251 ((uchar *)&def_temp)[6] = M[5];
252 ((uchar *)&def_temp)[7] = M[4];
253 return def_temp;
254}
255
256#else
257#define mi_float8store(T, V) \
258 { \
259 ((uchar *)(T))[0] = ((uchar *)&V)[7]; \
260 ((uchar *)(T))[1] = ((uchar *)&V)[6]; \
261 ((uchar *)(T))[2] = ((uchar *)&V)[5]; \
262 ((uchar *)(T))[3] = ((uchar *)&V)[4]; \
263 ((uchar *)(T))[4] = ((uchar *)&V)[3]; \
264 ((uchar *)(T))[5] = ((uchar *)&V)[2]; \
265 ((uchar *)(T))[6] = ((uchar *)&V)[1]; \
266 ((uchar *)(T))[7] = ((uchar *)&V)[0]; \
267 }
268
269static inline double mi_float8get(const uchar *M) {
270 double def_temp;
271 ((uchar *)&def_temp)[0] = M[7];
272 ((uchar *)&def_temp)[1] = M[6];
273 ((uchar *)&def_temp)[2] = M[5];
274 ((uchar *)&def_temp)[3] = M[4];
275 ((uchar *)&def_temp)[4] = M[3];
276 ((uchar *)&def_temp)[5] = M[2];
277 ((uchar *)&def_temp)[6] = M[1];
278 ((uchar *)&def_temp)[7] = M[0];
279 return def_temp;
280}
281
282#endif /* __FLOAT_WORD_ORDER */
283#endif /* WORDS_BIGENDIAN */
284
285#define mi_rowstore(T, A) mi_int8store(T, A)
286#define mi_rowkorr(T) mi_uint8korr(T)
287
288#define mi_sizestore(T, A) mi_int8store(T, A)
289#define mi_sizekorr(T) mi_uint8korr(T)
290
291#endif /* MYISAMPACK_INCLUDED */
#define M
Definition: ctype-tis620.cc:73
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
uint8_t uint8
Definition: my_inttypes.h:62
unsigned char uchar
Definition: my_inttypes.h:51
long long int longlong
Definition: my_inttypes.h:54
int16_t int16
Definition: my_inttypes.h:63
int8_t int8
Definition: my_inttypes.h:61
int32_t int32
Definition: my_inttypes.h:65
uint16_t uint16
Definition: my_inttypes.h:64
uint32_t uint32
Definition: my_inttypes.h:66
static int8 mi_sint1korr(const uchar *A)
Definition: myisampack.h:42
static uint32 mi_uint4korr(const uchar *A)
Definition: myisampack.h:70
static ulonglong mi_uint6korr(const uchar *A)
Definition: myisampack.h:81
static int16 mi_sint2korr(const uchar *A)
Definition: myisampack.h:46
static ulonglong mi_uint5korr(const uchar *A)
Definition: myisampack.h:75
static longlong mi_sint8korr(const uchar *A)
Definition: myisampack.h:103
static uint16 mi_uint2korr(const uchar *A)
Definition: myisampack.h:62
static ulonglong mi_uint8korr(const uchar *A)
Definition: myisampack.h:95
static int32 mi_sint3korr(const uchar *A)
Definition: myisampack.h:50
static uint8 mi_uint1korr(const uchar *A)
Definition: myisampack.h:44
static float mi_float4get(const uchar *M)
Definition: myisampack.h:221
static double mi_float8get(const uchar *M)
Definition: myisampack.h:269
static int32 mi_sint4korr(const uchar *A)
Definition: myisampack.h:57
static uint32 mi_uint3korr(const uchar *A)
Definition: myisampack.h:66
static ulonglong mi_uint7korr(const uchar *A)
Definition: myisampack.h:87