1 | #ifndef MYISAMPACK_INCLUDED |
2 | #define MYISAMPACK_INCLUDED |
3 | |
4 | /* Copyright (c) 2000-2002, 2004 MySQL AB, 2009 Sun Microsystems, Inc. |
5 | Use is subject to license terms. |
6 | |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; version 2 of the License. |
10 | |
11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
19 | |
20 | /* |
21 | Storing of values in high byte first order. |
22 | |
23 | integer keys and file pointers are stored with high byte first to get |
24 | better compression |
25 | */ |
26 | |
27 | /* these two are for uniformity */ |
28 | #define mi_sint1korr(A) ((int8)(*A)) |
29 | #define mi_uint1korr(A) ((uint8)(*A)) |
30 | |
31 | #define mi_sint2korr(A) ((int16) (((int16) (((const uchar*) (A))[1])) +\ |
32 | ((int16) ((int16) ((const char*) (A))[0]) << 8))) |
33 | #define mi_sint3korr(A) ((int32) (((((const uchar*) (A))[0]) & 128) ? \ |
34 | (((uint32) 255L << 24) | \ |
35 | (((uint32) ((const uchar*) (A))[0]) << 16) |\ |
36 | (((uint32) ((const uchar*) (A))[1]) << 8) | \ |
37 | ((uint32) ((const uchar*) (A))[2])) : \ |
38 | (((uint32) ((const uchar*) (A))[0]) << 16) |\ |
39 | (((uint32) ((const uchar*) (A))[1]) << 8) | \ |
40 | ((uint32) ((const uchar*) (A))[2]))) |
41 | #define mi_sint4korr(A) ((int32) (((int32) (((const uchar*) (A))[3])) +\ |
42 | ((int32) (((const uchar*) (A))[2]) << 8) +\ |
43 | ((int32) (((const uchar*) (A))[1]) << 16) +\ |
44 | ((int32) ((int16) ((const char*) (A))[0]) << 24))) |
45 | #define mi_sint8korr(A) ((longlong) mi_uint8korr(A)) |
46 | #define mi_uint2korr(A) ((uint16) (((uint16) (((const uchar*) (A))[1])) +\ |
47 | ((uint16) (((const uchar*) (A))[0]) << 8))) |
48 | #define mi_uint3korr(A) ((uint32) (((uint32) (((const uchar*) (A))[2])) +\ |
49 | (((uint32) (((const uchar*) (A))[1])) << 8) +\ |
50 | (((uint32) (((const uchar*) (A))[0])) << 16))) |
51 | #define mi_uint4korr(A) ((uint32) (((uint32) (((const uchar*) (A))[3])) +\ |
52 | (((uint32) (((const uchar*) (A))[2])) << 8) +\ |
53 | (((uint32) (((const uchar*) (A))[1])) << 16) +\ |
54 | (((uint32) (((const uchar*) (A))[0])) << 24))) |
55 | |
56 | #ifndef HAVE_mi_uint5korr |
57 | #define mi_uint5korr(A) ((ulonglong)(((uint32) (((const uchar*) (A))[4])) +\ |
58 | (((uint32) (((const uchar*) (A))[3])) << 8) +\ |
59 | (((uint32) (((const uchar*) (A))[2])) << 16) +\ |
60 | (((uint32) (((const uchar*) (A))[1])) << 24)) +\ |
61 | (((ulonglong) (((const uchar*) (A))[0])) << 32)) |
62 | #endif /* HAVE_mi_uint5korr */ |
63 | |
64 | #ifndef HAVE_mi_uint6korr |
65 | #define mi_uint6korr(A) ((ulonglong)(((uint32) (((const uchar*) (A))[5])) +\ |
66 | (((uint32) (((const uchar*) (A))[4])) << 8) +\ |
67 | (((uint32) (((const uchar*) (A))[3])) << 16) +\ |
68 | (((uint32) (((const uchar*) (A))[2])) << 24)) +\ |
69 | (((ulonglong) (((uint32) (((const uchar*) (A))[1])) +\ |
70 | (((uint32) (((const uchar*) (A))[0]) << 8)))) <<\ |
71 | 32)) |
72 | #endif /* HAVE_mi_uint6korr */ |
73 | |
74 | #ifndef HAVE_mi_uint7korr |
75 | #define mi_uint7korr(A) ((ulonglong)(((uint32) (((const uchar*) (A))[6])) +\ |
76 | (((uint32) (((const uchar*) (A))[5])) << 8) +\ |
77 | (((uint32) (((const uchar*) (A))[4])) << 16) +\ |
78 | (((uint32) (((const uchar*) (A))[3])) << 24)) +\ |
79 | (((ulonglong) (((uint32) (((const uchar*) (A))[2])) +\ |
80 | (((uint32) (((const uchar*) (A))[1])) << 8) +\ |
81 | (((uint32) (((const uchar*) (A))[0])) << 16))) <<\ |
82 | 32)) |
83 | #endif /* HAVE_mi_uint7korr */ |
84 | |
85 | #ifndef HAVE_mi_uint8korr |
86 | #define mi_uint8korr(A) ((ulonglong)(((uint32) (((const uchar*) (A))[7])) +\ |
87 | (((uint32) (((const uchar*) (A))[6])) << 8) +\ |
88 | (((uint32) (((const uchar*) (A))[5])) << 16) +\ |
89 | (((uint32) (((const uchar*) (A))[4])) << 24)) +\ |
90 | (((ulonglong) (((uint32) (((const uchar*) (A))[3])) +\ |
91 | (((uint32) (((const uchar*) (A))[2])) << 8) +\ |
92 | (((uint32) (((const uchar*) (A))[1])) << 16) +\ |
93 | (((uint32) (((const uchar*) (A))[0])) << 24))) <<\ |
94 | 32)) |
95 | #endif /* HAVE_mi_uint8korr */ |
96 | |
97 | /* This one is for uniformity */ |
98 | #define mi_int1store(T,A) *((uchar*)(T))= (uchar) (A) |
99 | |
100 | #define mi_int2store(T,A) { uint def_temp= (uint) (A) ;\ |
101 | ((uchar*) (T))[1]= (uchar) (def_temp);\ |
102 | ((uchar*) (T))[0]= (uchar) (def_temp >> 8); } |
103 | #define mi_int3store(T,A) { /*lint -save -e734 */\ |
104 | ulong def_temp= (ulong) (A);\ |
105 | ((uchar*) (T))[2]= (uchar) (def_temp);\ |
106 | ((uchar*) (T))[1]= (uchar) (def_temp >> 8);\ |
107 | ((uchar*) (T))[0]= (uchar) (def_temp >> 16);\ |
108 | /*lint -restore */} |
109 | #define mi_int4store(T,A) { ulong def_temp= (ulong) (A);\ |
110 | ((uchar*) (T))[3]= (uchar) (def_temp);\ |
111 | ((uchar*) (T))[2]= (uchar) (def_temp >> 8);\ |
112 | ((uchar*) (T))[1]= (uchar) (def_temp >> 16);\ |
113 | ((uchar*) (T))[0]= (uchar) (def_temp >> 24); } |
114 | #define mi_int5store(T,A) { ulong def_temp= (ulong) (A),\ |
115 | def_temp2= (ulong) ((A) >> 32);\ |
116 | ((uchar*) (T))[4]= (uchar) (def_temp);\ |
117 | ((uchar*) (T))[3]= (uchar) (def_temp >> 8);\ |
118 | ((uchar*) (T))[2]= (uchar) (def_temp >> 16);\ |
119 | ((uchar*) (T))[1]= (uchar) (def_temp >> 24);\ |
120 | ((uchar*) (T))[0]= (uchar) (def_temp2); } |
121 | #define mi_int6store(T,A) { ulong def_temp= (ulong) (A),\ |
122 | def_temp2= (ulong) ((A) >> 32);\ |
123 | ((uchar*) (T))[5]= (uchar) (def_temp);\ |
124 | ((uchar*) (T))[4]= (uchar) (def_temp >> 8);\ |
125 | ((uchar*) (T))[3]= (uchar) (def_temp >> 16);\ |
126 | ((uchar*) (T))[2]= (uchar) (def_temp >> 24);\ |
127 | ((uchar*) (T))[1]= (uchar) (def_temp2);\ |
128 | ((uchar*) (T))[0]= (uchar) (def_temp2 >> 8); } |
129 | #define mi_int7store(T,A) { ulong def_temp= (ulong) (A),\ |
130 | def_temp2= (ulong) ((A) >> 32);\ |
131 | ((uchar*) (T))[6]= (uchar) (def_temp);\ |
132 | ((uchar*) (T))[5]= (uchar) (def_temp >> 8);\ |
133 | ((uchar*) (T))[4]= (uchar) (def_temp >> 16);\ |
134 | ((uchar*) (T))[3]= (uchar) (def_temp >> 24);\ |
135 | ((uchar*) (T))[2]= (uchar) (def_temp2);\ |
136 | ((uchar*) (T))[1]= (uchar) (def_temp2 >> 8);\ |
137 | ((uchar*) (T))[0]= (uchar) (def_temp2 >> 16); } |
138 | #define mi_int8store(T,A) { ulong def_temp3= (ulong) (A),\ |
139 | def_temp4= (ulong) ((A) >> 32);\ |
140 | mi_int4store((uchar*) (T) + 0, def_temp4);\ |
141 | mi_int4store((uchar*) (T) + 4, def_temp3); } |
142 | |
143 | #ifdef WORDS_BIGENDIAN |
144 | |
145 | #define mi_float4store(T,A) { ((uchar*) (T))[0]= ((uchar*) &A)[0];\ |
146 | ((uchar*) (T))[1]= ((uchar*) &A)[1];\ |
147 | ((uchar*) (T))[2]= ((uchar*) &A)[2];\ |
148 | ((uchar*) (T))[3]= ((uchar*) &A)[3]; } |
149 | |
150 | #define mi_float4get(V,M) { float def_temp;\ |
151 | ((uchar*) &def_temp)[0]= ((const uchar*) (M))[0];\ |
152 | ((uchar*) &def_temp)[1]= ((const uchar*) (M))[1]; \ |
153 | ((uchar*) &def_temp)[2]= ((const uchar*) (M))[2];\ |
154 | ((uchar*) &def_temp)[3]= ((const uchar*) (M))[3];\ |
155 | (V)= def_temp; } |
156 | |
157 | #define mi_float8store(T,V) { ((uchar*) (T))[0]= ((const uchar*) &V)[0];\ |
158 | ((uchar*) (T))[1]= ((const uchar*) &V)[1];\ |
159 | ((uchar*) (T))[2]= ((const uchar*) &V)[2];\ |
160 | ((uchar*) (T))[3]= ((const uchar*) &V)[3];\ |
161 | ((uchar*) (T))[4]= ((const uchar*) &V)[4];\ |
162 | ((uchar*) (T))[5]= ((const uchar*) &V)[5];\ |
163 | ((uchar*) (T))[6]= ((const uchar*) &V)[6];\ |
164 | ((uchar*) (T))[7]= ((const uchar*) &V)[7]; } |
165 | |
166 | #define mi_float8get(V,M) { double def_temp;\ |
167 | ((uchar*) &def_temp)[0]= ((const uchar*) (M))[0];\ |
168 | ((uchar*) &def_temp)[1]= ((const uchar*) (M))[1];\ |
169 | ((uchar*) &def_temp)[2]= ((const uchar*) (M))[2];\ |
170 | ((uchar*) &def_temp)[3]= ((const uchar*) (M))[3];\ |
171 | ((uchar*) &def_temp)[4]= ((const uchar*) (M))[4];\ |
172 | ((uchar*) &def_temp)[5]= ((const uchar*) (M))[5];\ |
173 | ((uchar*) &def_temp)[6]= ((const uchar*) (M))[6];\ |
174 | ((uchar*) &def_temp)[7]= ((const uchar*) (M))[7]; \ |
175 | (V)= def_temp; } |
176 | #else |
177 | |
178 | #define mi_float4store(T,A) { ((uchar*) (T))[0]= ((const uchar*) &A)[3];\ |
179 | ((uchar*) (T))[1]= ((const uchar*) &A)[2];\ |
180 | ((uchar*) (T))[2]= ((const uchar*) &A)[1];\ |
181 | ((uchar*) (T))[3]= ((const uchar*) &A)[0]; } |
182 | |
183 | #define mi_float4get(V,M) { float def_temp;\ |
184 | ((uchar*) &def_temp)[0]= ((const uchar*) (M))[3];\ |
185 | ((uchar*) &def_temp)[1]= ((const uchar*) (M))[2];\ |
186 | ((uchar*) &def_temp)[2]= ((const uchar*) (M))[1];\ |
187 | ((uchar*) &def_temp)[3]= ((const uchar*) (M))[0];\ |
188 | (V)= def_temp; } |
189 | |
190 | #if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) |
191 | #define mi_float8store(T,V) { ((uchar*) (T))[0]= ((const uchar*) &V)[3];\ |
192 | ((uchar*) (T))[1]= ((const uchar*) &V)[2];\ |
193 | ((uchar*) (T))[2]= ((const uchar*) &V)[1];\ |
194 | ((uchar*) (T))[3]= ((const uchar*) &V)[0];\ |
195 | ((uchar*) (T))[4]= ((const uchar*) &V)[7];\ |
196 | ((uchar*) (T))[5]= ((const uchar*) &V)[6];\ |
197 | ((uchar*) (T))[6]= ((const uchar*) &V)[5];\ |
198 | ((uchar*) (T))[7]= ((const uchar*) &V)[4];} |
199 | |
200 | #define mi_float8get(V,M) { double def_temp;\ |
201 | ((uchar*) &def_temp)[0]= ((const uchar*) (M))[3];\ |
202 | ((uchar*) &def_temp)[1]= ((const uchar*) (M))[2];\ |
203 | ((uchar*) &def_temp)[2]= ((const uchar*) (M))[1];\ |
204 | ((uchar*) &def_temp)[3]= ((const uchar*) (M))[0];\ |
205 | ((uchar*) &def_temp)[4]= ((const uchar*) (M))[7];\ |
206 | ((uchar*) &def_temp)[5]= ((const uchar*) (M))[6];\ |
207 | ((uchar*) &def_temp)[6]= ((const uchar*) (M))[5];\ |
208 | ((uchar*) &def_temp)[7]= ((const uchar*) (M))[4];\ |
209 | (V)= def_temp; } |
210 | |
211 | #else |
212 | #define mi_float8store(T,V) { ((uchar*) (T))[0]= ((const uchar*) &V)[7];\ |
213 | ((uchar*) (T))[1]= ((const uchar*) &V)[6];\ |
214 | ((uchar*) (T))[2]= ((const uchar*) &V)[5];\ |
215 | ((uchar*) (T))[3]= ((const uchar*) &V)[4];\ |
216 | ((uchar*) (T))[4]= ((const uchar*) &V)[3];\ |
217 | ((uchar*) (T))[5]= ((const uchar*) &V)[2];\ |
218 | ((uchar*) (T))[6]= ((const uchar*) &V)[1];\ |
219 | ((uchar*) (T))[7]= ((const uchar*) &V)[0];} |
220 | |
221 | #define mi_float8get(V,M) { double def_temp;\ |
222 | ((uchar*) &def_temp)[0]= ((const uchar*) (M))[7];\ |
223 | ((uchar*) &def_temp)[1]= ((const uchar*) (M))[6];\ |
224 | ((uchar*) &def_temp)[2]= ((const uchar*) (M))[5];\ |
225 | ((uchar*) &def_temp)[3]= ((const uchar*) (M))[4];\ |
226 | ((uchar*) &def_temp)[4]= ((const uchar*) (M))[3];\ |
227 | ((uchar*) &def_temp)[5]= ((const uchar*) (M))[2];\ |
228 | ((uchar*) &def_temp)[6]= ((const uchar*) (M))[1];\ |
229 | ((uchar*) &def_temp)[7]= ((const uchar*) (M))[0];\ |
230 | (V)= def_temp; } |
231 | #endif /* __FLOAT_WORD_ORDER */ |
232 | #endif /* WORDS_BIGENDIAN */ |
233 | |
234 | /* Fix to avoid warnings when sizeof(ha_rows) == sizeof(long) */ |
235 | |
236 | #ifdef BIG_TABLES |
237 | #define mi_rowstore(T,A) mi_int8store(T, A) |
238 | #define mi_rowkorr(T) mi_uint8korr(T) |
239 | #else |
240 | #define mi_rowstore(T,A) { mi_int4store(T, 0);\ |
241 | mi_int4store(((uchar*) (T) + 4), A); } |
242 | #define mi_rowkorr(T) mi_uint4korr((const uchar*) (T) + 4) |
243 | #endif |
244 | |
245 | #if SIZEOF_OFF_T > 4 |
246 | #define mi_sizestore(T,A) mi_int8store(T, A) |
247 | #define mi_sizekorr(T) mi_uint8korr(T) |
248 | #else |
249 | #define mi_sizestore(T,A) { if ((A) == HA_OFFSET_ERROR)\ |
250 | bfill((char*) (T), 8, 255);\ |
251 | else { mi_int4store((T), 0);\ |
252 | mi_int4store(((T) + 4), A); }} |
253 | #define mi_sizekorr(T) mi_uint4korr((const uchar*) (T) + 4) |
254 | #endif |
255 | #endif /* MYISAMPACK_INCLUDED */ |
256 | |