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